Skip to content

Commit d00618f

Browse files
committed
Java: Improve performance of virtual dispatch calculation.
1 parent 0c970b5 commit d00618f

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

java/ql/src/semmle/code/java/dataflow/internal/DataFlowDispatch.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ private module DispatchImpl {
106106
mayBenefitFromCallContext(ma, c, i) and
107107
c = viableCallable(ctx) and
108108
contextArgHasType(ctx, i, t, exact) and
109-
ma.getMethod() = def
109+
ma.getMethod().getSourceDeclaration() = def
110110
|
111111
exact = true and result = VirtualDispatch::exactMethodImpl(def, t.getSourceDeclaration())
112112
or

java/ql/src/semmle/code/java/dispatch/VirtualDispatch.qll

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,12 @@ Callable viableCallable(Call c) {
3939
c instanceof ConstructorCall and result = c.getCallee().getSourceDeclaration()
4040
}
4141

42-
/** A method that is the target of a call. */
43-
class CalledMethod extends Method {
44-
CalledMethod() { exists(MethodAccess ma | ma.getMethod() = this) }
42+
/** The source declaration of a method that is the target of a virtual call. */
43+
class VirtCalledSrcMethod extends SrcMethod {
44+
pragma[nomagic]
45+
VirtCalledSrcMethod() {
46+
exists(VirtualMethodAccess ma | ma.getMethod().getSourceDeclaration() = this)
47+
}
4548
}
4649

4750
cached
@@ -185,8 +188,8 @@ private module Dispatch {
185188
not result.isAbstract() and
186189
if source instanceof VirtualMethodAccess
187190
then
188-
exists(CalledMethod def, RefType t, boolean exact |
189-
source.getMethod() = def and
191+
exists(VirtCalledSrcMethod def, RefType t, boolean exact |
192+
source.getMethod().getSourceDeclaration() = def and
190193
hasQualifierType(source, t, exact)
191194
|
192195
exact = true and result = exactMethodImpl(def, t.getSourceDeclaration())
@@ -301,14 +304,14 @@ private module Dispatch {
301304

302305
/** Gets the implementation of `top` present on a value of precisely type `t`. */
303306
cached
304-
Method exactMethodImpl(CalledMethod top, SrcRefType t) {
307+
Method exactMethodImpl(VirtCalledSrcMethod top, SrcRefType t) {
305308
hasSrcMethod(t, result) and
306-
top.getAPossibleImplementation() = result
309+
top.getAPossibleImplementationOfSrcMethod() = result
307310
}
308311

309312
/** Gets the implementations of `top` present on viable subtypes of `t`. */
310313
cached
311-
Method viableMethodImpl(CalledMethod top, SrcRefType tsrc, RefType t) {
314+
Method viableMethodImpl(VirtCalledSrcMethod top, SrcRefType tsrc, RefType t) {
312315
exists(SrcRefType sub |
313316
result = exactMethodImpl(top, sub) and
314317
tsrc = t.getSourceDeclaration() and

0 commit comments

Comments
 (0)