-
Notifications
You must be signed in to change notification settings - Fork 2k
Java: Make Virtual Dispatch Global, but keep SSA local. #20357
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -253,17 +253,18 @@ class SsaImplicitUpdate extends SsaUpdate { | |||||||||||||
| or | ||||||||||||||
| if this.hasImplicitQualifierUpdate() | ||||||||||||||
| then | ||||||||||||||
| if exists(this.getANonLocalUpdate()) | ||||||||||||||
| if isNonNonLocal(this) | ||||||||||||||
| then result = "nonlocal + nonlocal qualifier" | ||||||||||||||
| else result = "nonlocal qualifier" | ||||||||||||||
| else ( | ||||||||||||||
| exists(this.getANonLocalUpdate()) and result = "nonlocal" | ||||||||||||||
| isNonNonLocal(this) and result = "nonlocal" | ||||||||||||||
| ) | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| /** | ||||||||||||||
| * Gets a reachable `FieldWrite` that might represent this ssa update, if any. | ||||||||||||||
| */ | ||||||||||||||
| overlay[global] | ||||||||||||||
| FieldWrite getANonLocalUpdate() { | ||||||||||||||
| exists(SsaSourceField f, Callable setter | | ||||||||||||||
| relevantFieldUpdate(setter, f.getField(), result) and | ||||||||||||||
|
|
@@ -287,6 +288,11 @@ class SsaImplicitUpdate extends SsaUpdate { | |||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| overlay[global] | ||||||||||||||
| private predicate isNonNonLocalImpl(SsaImplicitUpdate su) { exists(su.getANonLocalUpdate()) } | ||||||||||||||
|
|
||||||||||||||
| private predicate isNonNonLocal(SsaImplicitUpdate su) = forceLocal(isNonNonLocalImpl/1)(su) | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
|
|
||||||||||||||
| /** | ||||||||||||||
| * An SSA variable that represents an uncertain implicit update of the value. | ||||||||||||||
| * This is a `Call` that might reach a non-local update of the field or one of | ||||||||||||||
|
|
||||||||||||||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -157,15 +157,20 @@ private predicate hasEntryDef(TrackedVar v, BasicBlock b) { | |
| } | ||
|
|
||
| /** Holds if `n` might update the locally tracked variable `v`. */ | ||
| overlay[global] | ||
| pragma[nomagic] | ||
| private predicate uncertainVariableUpdate(TrackedVar v, ControlFlowNode n, BasicBlock b, int i) { | ||
| private predicate uncertainVariableUpdateImpl(TrackedVar v, ControlFlowNode n, BasicBlock b, int i) { | ||
| exists(Call c | c = n.asCall() | updatesNamedField(c, v, _)) and | ||
| b.getNode(i) = n and | ||
| hasDominanceInformation(b) | ||
| or | ||
| uncertainVariableUpdate(v.getQualifier(), n, b, i) | ||
| uncertainVariableUpdateImpl(v.getQualifier(), n, b, i) | ||
| } | ||
|
|
||
| /** Holds if `n` might update the locally tracked variable `v`. */ | ||
| predicate uncertainVariableUpdate(TrackedVar v, ControlFlowNode n, BasicBlock b, int i) = | ||
| forceLocal(uncertainVariableUpdateImpl/4)(v, n, b, i) | ||
|
|
||
| private module SsaInput implements SsaImplCommon::InputSig<Location, BasicBlock> { | ||
| class SourceVariable = SsaSourceVariable; | ||
|
|
||
|
|
@@ -335,6 +340,7 @@ private module Cached { | |
| * Constructor --(intraInstanceCallEdge)-->+ Method(setter of this.f) | ||
| * ``` | ||
| */ | ||
| overlay[global] | ||
| private predicate intraInstanceCallEdge(Callable c1, Method m2) { | ||
| exists(MethodCall ma, RefType t1 | | ||
| ma.getCaller() = c1 and | ||
|
|
@@ -355,6 +361,7 @@ private module Cached { | |
| ) | ||
| } | ||
|
|
||
| overlay[global] | ||
| private Callable tgt(Call c) { | ||
| result = viableImpl_v2(c) | ||
| or | ||
|
|
@@ -364,11 +371,13 @@ private module Cached { | |
| } | ||
|
|
||
| /** Holds if `(c1,c2)` is an edge in the call graph. */ | ||
| overlay[global] | ||
| private predicate callEdge(Callable c1, Callable c2) { | ||
| exists(Call c | c.getCaller() = c1 and c2 = tgt(c)) | ||
| } | ||
|
|
||
| /** Holds if `(c1,c2)` is an edge in the call graph excluding `intraInstanceCallEdge`. */ | ||
| overlay[global] | ||
| private predicate crossInstanceCallEdge(Callable c1, Callable c2) { | ||
| callEdge(c1, c2) and not intraInstanceCallEdge(c1, c2) | ||
| } | ||
|
|
@@ -382,6 +391,7 @@ private module Cached { | |
| relevantFieldUpdate(_, f.getField(), _) | ||
| } | ||
|
|
||
| overlay[global] | ||
| private predicate source(Call call, TrackedField f, Field field, Callable c, boolean fresh) { | ||
| relevantCall(call, f) and | ||
| field = f.getField() and | ||
|
|
@@ -395,9 +405,11 @@ private module Cached { | |
| * `fresh` indicates whether the instance `this` in `c` has been freshly | ||
| * allocated along the call-chain. | ||
| */ | ||
| overlay[global] | ||
| private newtype TCallableNode = | ||
| MkCallableNode(Callable c, boolean fresh) { source(_, _, _, c, fresh) or edge(_, c, fresh) } | ||
|
|
||
| overlay[global] | ||
| private predicate edge(TCallableNode n, Callable c2, boolean f2) { | ||
| exists(Callable c1, boolean f1 | n = MkCallableNode(c1, f1) | | ||
| intraInstanceCallEdge(c1, c2) and f2 = f1 | ||
|
|
@@ -407,13 +419,15 @@ private module Cached { | |
| ) | ||
| } | ||
|
|
||
| overlay[global] | ||
| private predicate edge(TCallableNode n1, TCallableNode n2) { | ||
| exists(Callable c2, boolean f2 | | ||
| edge(n1, c2, f2) and | ||
| n2 = MkCallableNode(c2, f2) | ||
| ) | ||
| } | ||
|
|
||
| overlay[global] | ||
| pragma[noinline] | ||
| private predicate source(Call call, TrackedField f, Field field, TCallableNode n) { | ||
| exists(Callable c, boolean fresh | | ||
|
|
@@ -422,31 +436,36 @@ private module Cached { | |
| ) | ||
| } | ||
|
|
||
| overlay[global] | ||
| private predicate sink(Callable c, Field f, TCallableNode n) { | ||
| setsOwnField(c, f) and n = MkCallableNode(c, false) | ||
| or | ||
| setsOtherField(c, f) and n = MkCallableNode(c, _) | ||
| } | ||
|
|
||
| overlay[global] | ||
| private predicate prunedNode(TCallableNode n) { | ||
| sink(_, _, n) | ||
| or | ||
| exists(TCallableNode mid | edge(n, mid) and prunedNode(mid)) | ||
| } | ||
|
|
||
| overlay[global] | ||
| private predicate prunedEdge(TCallableNode n1, TCallableNode n2) { | ||
| prunedNode(n1) and | ||
| prunedNode(n2) and | ||
| edge(n1, n2) | ||
| } | ||
|
|
||
| overlay[global] | ||
| private predicate edgePlus(TCallableNode c1, TCallableNode c2) = fastTC(prunedEdge/2)(c1, c2) | ||
|
|
||
| /** | ||
| * Holds if there exists a call-chain originating in `call` that can update `f` on some instance | ||
| * where `f` and `call` share the same enclosing callable in which a | ||
| * `FieldRead` of `f` is reachable from `call`. | ||
| */ | ||
| overlay[global] | ||
| pragma[noopt] | ||
| private predicate updatesNamedFieldImpl(Call call, TrackedField f, Callable setter) { | ||
| exists(TCallableNode src, TCallableNode sink, Field field | | ||
|
|
@@ -457,11 +476,13 @@ private module Cached { | |
| } | ||
|
|
||
| bindingset[call, f] | ||
| overlay[global] | ||
| pragma[inline_late] | ||
| private predicate updatesNamedField0(Call call, TrackedField f, Callable setter) { | ||
| updatesNamedField(call, f, setter) | ||
| } | ||
|
|
||
| overlay[global] | ||
| cached | ||
| predicate defUpdatesNamedField(SsaImplicitUpdate def, TrackedField f, Callable setter) { | ||
| f = def.getSourceVariable() and | ||
|
|
@@ -534,6 +555,7 @@ private module Cached { | |
| Impl::phiHasInputFromBlock(phi, inp, bb) | ||
| } | ||
|
|
||
| overlay[global] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be local? It's very local in nature. |
||
| cached | ||
| module DataFlowIntegration { | ||
| import DataFlowIntegrationImpl | ||
|
|
||
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
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
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
2 changes: 0 additions & 2 deletions
2
java/ql/lib/semmle/code/java/dispatch/internal/Unification.qll
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not explicitly make them global with
overlay[global] module;? That seems a lot better to me.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that's because the 2.23.0 compiler would warn that it's a redundant annotation. This warning is going to be removed in 2.23.1, but we'd like to merge this PR now and get it into 2.23.1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's correct