mirror of
https://github.com/github/codeql.git
synced 2025-12-24 04:36:35 +01:00
Merge pull request #5941 from aschackmull/java/virt-disp-perf
Java: Improve performance of virtual dispatch calculation.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user