Track Java->Java dependencies on inlined constants (#145)#1721
Open
jozanek wants to merge 1 commit into
Open
Conversation
59b6d15 to
bf5718d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #145.
Scope (resolves the issue's "TBD: is there some mention in the classfile?")
Checked with
javap: ordinary constant uses (field initializers, method bodies,import staticin expressions) keep the owning class as aCONSTANT_Classentry and are already tracked. The owner is erased entirely only when the constant is used as an annotation value (@Anno(B.MAX)) or a switch-case label (case B.MAX:). And it only causes staleness across a compilation boundary — within a modulecompileAllJavarecompiles all Java together, and pipelining recompiles all Java each cycle. So the real gap: a Java class depending on a separately-compiled Java class only through a constant in an annotation value or switch-case label.Approach
Recover the edges from javac's attributed AST, which keeps the resolved symbol the bytecode dropped.
LocalJavaCompilerregisters aTaskListener; atANALYZEaTreePathScannerrecords, for each compile-time-constant reference, an edge from the enclosing class to (a) the declaring class and (b) the type named at the reference site — the member-select qualifier (Sub.K) or a contributing static import incl. wildcards. (b) matters for inherited constants, so a later change to the named subtype also recompiles the dependent. The map is returned fromrunWithConstantDeps(no shared mutable state) and fed into the existingJavaAnalyzemember-ref path, so in-project owners become class deps and classpath owners become binary deps.com.sun.source.*is exported byjdk.compiler— no--add-exports/--add-opensneeded.Limitation
Only in-process (local) javac is hooked; forked / custom
JavaCompilerclients don't get this tracking.