Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incremental compilation with literals in 3.4 #1474

Closed
izeye opened this issue Feb 28, 2017 · 7 comments
Closed

Incremental compilation with literals in 3.4 #1474

izeye opened this issue Feb 28, 2017 · 7 comments

Comments

@izeye
Copy link
Contributor

izeye commented Feb 28, 2017

Incremental Compilation, the Java Library Plugin, and other performance features in Gradle 3.4 said as follows:

Similarly, if the constant is changed, but that the dependents didn’t have a literal in their bytecode of the old value, we don’t need to recompile them: we would only recompile the classes that have candidate literals.

To find the usage of a literal, using its old value doesn't work if it is used for calculation and the result is inlined.

This was originally asked on the blog: https://blog.gradle.org/incremental-compiler-avoidance#comment-3178668770

/cc @melix

@melix
Copy link
Contributor

melix commented Feb 28, 2017

Thanks @izeye

@melix
Copy link
Contributor

melix commented Feb 28, 2017

Actually it seems we don't have the problem. Even if Java inlines the constant, class A is still visible in the constant pool table.

I made a simple test, and changing the constant value in A triggers a recompilation of B:

Incremental compilation of 2 classes completed in 0.034 secs.

@melix
Copy link
Contributor

melix commented Feb 28, 2017

I'm not sure why, but it doesn't appear to be that simple (maybe it depends on the compiler version). The test case linked above fails.

@bjkail
Copy link

bjkail commented Feb 28, 2017

As of JDK-7153958, which was included in Java 8, javac includes a reference to the the constant field in the dependent class' constant pool. So, I think this bug seems to be valid for javac <7, and the constant tracking infrastructure seems unnecessary for javac >=8.

@melix
Copy link
Contributor

melix commented Feb 28, 2017

It doesn't seem to be the case on all versions of Java 8, at least. I ran 8u91 and the test case still fails. Which is strange considering that it's supposed to be fixed in b68.

@melix
Copy link
Contributor

melix commented Feb 28, 2017

So it's actually a combination of 2 bugs:

  • with Java < 8, we don't recognize that A was referenced
  • the compile classpath snapshotter, which computes the ABI of a component, ignores the constant values of API members

The latter is pretty serious.

@melix
Copy link
Contributor

melix commented Feb 28, 2017

See #1476

@oehme oehme added this to the 3.4.1 milestone Mar 1, 2017
melix added a commit that referenced this issue Mar 1, 2017
This commit fixes #1474, by not relying on the analysis of literals (which still exists),
but rather recompiling everything whenever we detect that a constant effectively changed in a class.
This doesn't prevent us from using a smarter strategy later (say, using a compiler plugin).

The commit also changes the hash that is used to store constants, so that the name of the constant is used.
This prevents another bug which was that if a class has multiple variants of the same value, or that values
of several constants are switched, we wouldn't detect the change.
melix added a commit that referenced this issue Mar 2, 2017
This commit fixes #1474, by not relying on the analysis of literals (which still exists),
but rather recompiling everything whenever we detect that a constant effectively changed in a class.
This doesn't prevent us from using a smarter strategy later (say, using a compiler plugin).

The commit also changes the hash that is used to store constants, so that the name of the constant is used.
This prevents another bug which was that if a class has multiple variants of the same value, or that values
of several constants are switched, we wouldn't detect the change.
@melix melix closed this as completed Mar 3, 2017
@lacasseio lacasseio modified the milestones: 3.4.1 RC1, 3.4.1 Mar 3, 2017
@jjohannes jjohannes modified the milestones: 3.4.1, 3.4.1 RC1 Jun 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants