Merge pull request #5941 from aschackmull/java/virt-disp-perf

Java: Improve performance of virtual dispatch calculation.
This commit is contained in:
Anders Schack-Mulligen
2021-05-25 14:44:51 +02:00
committed by GitHub
2 changed files with 13 additions and 10 deletions

View File

@@ -106,7 +106,7 @@ private module DispatchImpl {
mayBenefitFromCallContext(ma, c, i) and
c = viableCallable(ctx) and
contextArgHasType(ctx, i, t, exact) and
ma.getMethod() = def
ma.getMethod().getSourceDeclaration() = def
|
exact = true and result = VirtualDispatch::exactMethodImpl(def, t.getSourceDeclaration())
or

View File

@@ -39,9 +39,12 @@ Callable viableCallable(Call c) {
c instanceof ConstructorCall and result = c.getCallee().getSourceDeclaration()
}
/** A method that is the target of a call. */
class CalledMethod extends Method {
CalledMethod() { exists(MethodAccess ma | ma.getMethod() = this) }
/** The source declaration of a method that is the target of a virtual call. */
class VirtCalledSrcMethod extends SrcMethod {
pragma[nomagic]
VirtCalledSrcMethod() {
exists(VirtualMethodAccess ma | ma.getMethod().getSourceDeclaration() = this)
}
}
cached
@@ -73,7 +76,7 @@ private module Dispatch {
(
exists(Method def, RefType t, boolean exact |
qualType(ma, t, exact) and
def = ma.getMethod()
def = ma.getMethod().getSourceDeclaration()
|
exact = true and result = exactMethodImpl(def, t.getSourceDeclaration())
or
@@ -185,8 +188,8 @@ private module Dispatch {
not result.isAbstract() and
if source instanceof VirtualMethodAccess
then
exists(CalledMethod def, RefType t, boolean exact |
source.getMethod() = def and
exists(VirtCalledSrcMethod def, RefType t, boolean exact |
source.getMethod().getSourceDeclaration() = def and
hasQualifierType(source, t, exact)
|
exact = true and result = exactMethodImpl(def, t.getSourceDeclaration())
@@ -301,14 +304,14 @@ private module Dispatch {
/** Gets the implementation of `top` present on a value of precisely type `t`. */
cached
Method exactMethodImpl(CalledMethod top, SrcRefType t) {
Method exactMethodImpl(VirtCalledSrcMethod top, SrcRefType t) {
hasSrcMethod(t, result) and
top.getAPossibleImplementation() = result
top.getAPossibleImplementationOfSrcMethod() = result
}
/** Gets the implementations of `top` present on viable subtypes of `t`. */
cached
Method viableMethodImpl(CalledMethod top, SrcRefType tsrc, RefType t) {
Method viableMethodImpl(VirtCalledSrcMethod top, SrcRefType tsrc, RefType t) {
exists(SrcRefType sub |
result = exactMethodImpl(top, sub) and
tsrc = t.getSourceDeclaration() and