Browse Source

fix for forName selector: use the CHA in getRelevantParameters to resolve

the declared target of the call site.  This is needed to make sure
forName targets loaded with the Application loader get resolved to point
to the real metod reference for forName.

this issue actually manifested itself in the Kawa Chess program, and so
I have added an assertion to make sure this resolution is done properly.
master
Julian Dolby 4 years ago
parent
commit
38c5de6160
  1. 7
      com.ibm.wala.core.tests/src/com/ibm/wala/core/tests/callGraph/KawaCallGraphTest.java
  2. 3
      com.ibm.wala.core/src/com/ibm/wala/analysis/reflection/ClassFactoryContextSelector.java

7
com.ibm.wala.core.tests/src/com/ibm/wala/core/tests/callGraph/KawaCallGraphTest.java

@ -58,6 +58,9 @@ public class KawaCallGraphTest extends DynamicCallGraphTestBase {
Set<CGNode> append$v = getNodes(CG, "Lkawa/lang/Quote", "append$V", "([Ljava/lang/Object;)Ljava/lang/Object;");
assert ! append$v.isEmpty();
Set<CGNode> clinit = getNodes(CG, "Lkawa/lib/kawa/base", "<clinit>", "()V");
assert ! clinit.isEmpty();
}
@Test
@ -91,7 +94,9 @@ public class KawaCallGraphTest extends DynamicCallGraphTestBase {
MethodHandles.analyzeMethodHandles(options, builder);
return builder.makeCallGraph(options, null);
CallGraph cg = builder.makeCallGraph(options, null);
return cg;
}
}

3
com.ibm.wala.core/src/com/ibm/wala/analysis/reflection/ClassFactoryContextSelector.java

@ -131,7 +131,8 @@ class ClassFactoryContextSelector implements ContextSelector {
@Override
public IntSet getRelevantParameters(CGNode caller, CallSiteReference site) {
if (isClassFactory(site.getDeclaredTarget())) {
IMethod resolved = caller.getMethod().getClassHierarchy().resolveMethod(site.getDeclaredTarget());
if (isClassFactory(resolved != null? resolved.getReference(): site.getDeclaredTarget())) {
SSAAbstractInvokeInstruction[] invokeInstructions = caller.getIR().getCalls(site);
if (invokeInstructions.length >= 1) {
if (invokeInstructions[0].isStatic()) {

Loading…
Cancel
Save