Impl of IMethod.is(Wala)Synthetic and IClass.isSynthetic (#359)
* Impl of IMethod isSynthetic and isWalaSynthetic So far IMethod.isSynthetic referred to WALA-generated helper functions and there was no equivalent to check whether an IMethod is synthetic in terms of compiler-generated. To make naming consistent this patch first renames the isSynthetic to isWalaSynthetic to clearly indicate that a given IMethod was generated by WALA. Then, we re-introduce isSynthetic that from now on checks whether an IMethod is synthetic/compiler-generated (referring to the synthetic flag in bytecode) * Implementation of IClass.isSynthetic Complementary to IMethod.isSynthetic, this method checks whether an IClass is compiler-generated. * updated JavaDoc
This commit is contained in:
parent
751444a656
commit
ee13713c4d
|
@ -256,7 +256,7 @@ public class AstJavaSSAPropagationCallGraphBuilder extends AstSSAPropagationCall
|
|||
|
||||
System.err.println(("class is " + klass + ", enclosing is " + enclosingClass + ", method is " + node.getMethod()));
|
||||
|
||||
if (node.getMethod().isSynthetic()) {
|
||||
if (node.getMethod().isWalaSynthetic()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -85,6 +85,11 @@ abstract public class AstClass implements IClass, ClassConstants {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSynthetic() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getModifiers() {
|
||||
return modifiers;
|
||||
|
|
|
@ -91,6 +91,11 @@ abstract public class AstFunctionClass implements IClass, ClassConstants {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSynthetic() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getModifiers() {
|
||||
return ACC_PUBLIC;
|
||||
|
|
|
@ -267,6 +267,11 @@ public abstract class AstMethod implements IMethod {
|
|||
return qualifiers.contains(CAstQualifier.NATIVE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWalaSynthetic() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSynthetic() {
|
||||
return false;
|
||||
|
|
|
@ -141,7 +141,7 @@ public class FactoryBypassInterpreter extends AbstractReflectionInterpreter {
|
|||
if (node == null) {
|
||||
throw new IllegalArgumentException("node is null");
|
||||
}
|
||||
if (node.getMethod().isSynthetic()) {
|
||||
if (node.getMethod().isWalaSynthetic()) {
|
||||
SyntheticMethod s = (SyntheticMethod) node.getMethod();
|
||||
if (s.isFactoryMethod()) {
|
||||
return getTypesForContext(node.getContext()) != null;
|
||||
|
|
|
@ -38,7 +38,7 @@ class FactoryContextSelector implements ContextSelector {
|
|||
if (callee == null) {
|
||||
throw new IllegalArgumentException("callee is null");
|
||||
}
|
||||
if (callee.isSynthetic()) {
|
||||
if (callee.isWalaSynthetic()) {
|
||||
SyntheticMethod s = (SyntheticMethod) callee;
|
||||
if (s.isFactoryMethod()) {
|
||||
return new CallStringContext(new CallString(site, caller.getMethod()));
|
||||
|
|
|
@ -371,6 +371,11 @@ public class ArrayClass implements IClass, Constants {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSynthetic() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Reader getSource() {
|
||||
return null;
|
||||
|
|
|
@ -46,7 +46,7 @@ public class CodeScanner {
|
|||
if (m == null) {
|
||||
throw new IllegalArgumentException("m is null");
|
||||
}
|
||||
if (m.isSynthetic()) {
|
||||
if (m.isWalaSynthetic()) {
|
||||
SyntheticMethod sm = (SyntheticMethod) m;
|
||||
return getCallSites(sm.getStatements());
|
||||
} else {
|
||||
|
@ -62,7 +62,7 @@ public class CodeScanner {
|
|||
if (m == null) {
|
||||
throw new IllegalArgumentException("m is null");
|
||||
}
|
||||
if (m.isSynthetic()) {
|
||||
if (m.isWalaSynthetic()) {
|
||||
SyntheticMethod sm = (SyntheticMethod) m;
|
||||
return getFieldsRead(sm.getStatements());
|
||||
} else {
|
||||
|
@ -78,7 +78,7 @@ public class CodeScanner {
|
|||
if (m == null) {
|
||||
throw new IllegalArgumentException("m is null");
|
||||
}
|
||||
if (m.isSynthetic()) {
|
||||
if (m.isWalaSynthetic()) {
|
||||
SyntheticMethod sm = (SyntheticMethod) m;
|
||||
return getFieldsWritten(sm.getStatements());
|
||||
} else {
|
||||
|
@ -95,7 +95,7 @@ public class CodeScanner {
|
|||
if (m == null) {
|
||||
throw new IllegalArgumentException("m is null");
|
||||
}
|
||||
if (m.isSynthetic()) {
|
||||
if (m.isWalaSynthetic()) {
|
||||
SyntheticMethod sm = (SyntheticMethod) m;
|
||||
return getArraysWritten(sm.getStatements());
|
||||
} else {
|
||||
|
@ -111,7 +111,7 @@ public class CodeScanner {
|
|||
if (m == null) {
|
||||
throw new IllegalArgumentException("m is null");
|
||||
}
|
||||
if (m.isSynthetic()) {
|
||||
if (m.isWalaSynthetic()) {
|
||||
SyntheticMethod sm = (SyntheticMethod) m;
|
||||
return getNewSites(sm.getStatements());
|
||||
} else {
|
||||
|
@ -123,7 +123,7 @@ public class CodeScanner {
|
|||
if (m == null) {
|
||||
throw new IllegalArgumentException("m is null");
|
||||
}
|
||||
if (m.isSynthetic()) {
|
||||
if (m.isWalaSynthetic()) {
|
||||
SyntheticMethod sm = (SyntheticMethod) m;
|
||||
return hasObjectArrayLoad(sm.getStatements());
|
||||
} else {
|
||||
|
@ -135,7 +135,7 @@ public class CodeScanner {
|
|||
if (m == null) {
|
||||
throw new IllegalArgumentException("m is null");
|
||||
}
|
||||
if (m.isSynthetic()) {
|
||||
if (m.isWalaSynthetic()) {
|
||||
SyntheticMethod sm = (SyntheticMethod) m;
|
||||
return hasObjectArrayStore(sm.getStatements());
|
||||
} else {
|
||||
|
@ -147,7 +147,7 @@ public class CodeScanner {
|
|||
if (m == null) {
|
||||
throw new IllegalArgumentException("m is null");
|
||||
}
|
||||
if (m.isSynthetic()) {
|
||||
if (m.isWalaSynthetic()) {
|
||||
SyntheticMethod sm = (SyntheticMethod) m;
|
||||
return getCaughtExceptions(sm.getStatements());
|
||||
} else {
|
||||
|
@ -166,7 +166,7 @@ public class CodeScanner {
|
|||
if (m == null) {
|
||||
throw new IllegalArgumentException("m is null");
|
||||
}
|
||||
if (m.isSynthetic()) {
|
||||
if (m.isWalaSynthetic()) {
|
||||
SyntheticMethod sm = (SyntheticMethod) m;
|
||||
return iterateCastTypes(sm.getStatements());
|
||||
} else {
|
||||
|
|
|
@ -54,6 +54,11 @@ public interface IClass extends IClassHierarchyDweller {
|
|||
*/
|
||||
boolean isPrivate();
|
||||
|
||||
/**
|
||||
* @return true iff this class is synthetic, i.e., compiler-generated
|
||||
*/
|
||||
boolean isSynthetic();
|
||||
|
||||
/**
|
||||
* Return the integer that encodes the class's modifiers, as defined by the JVM specification
|
||||
*
|
||||
|
|
|
@ -43,7 +43,14 @@ public interface IMethod extends IMember, ContextItem {
|
|||
boolean isNative();
|
||||
|
||||
/**
|
||||
* Did someone synthesize this method? (As opposed to reading it from a class file)
|
||||
* Is the implementation of this method a model generated by WALA?
|
||||
* For compiler-generated synthetic methods, refer to {@link #isSynthetic()}
|
||||
*/
|
||||
boolean isWalaSynthetic();
|
||||
|
||||
/**
|
||||
* Is this method synthetic, i.e., compiler-generated (this refers to the
|
||||
* synthetic flag in java/dex bytecode)
|
||||
*/
|
||||
boolean isSynthetic();
|
||||
|
||||
|
|
|
@ -65,6 +65,15 @@ public abstract class JVMClass<T extends IClassLoader> extends BytecodeClass<T>
|
|||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see com.ibm.wala.classLoader.IClass#isSynthetic()
|
||||
*/
|
||||
@Override
|
||||
public boolean isSynthetic() {
|
||||
boolean result = ((modifiers & Constants.ACC_SYNTHETIC) != 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.ibm.wala.classLoader.IClass#getClassInitializer()
|
||||
*/
|
||||
|
|
|
@ -441,7 +441,10 @@ public abstract class ShrikeBTMethod implements IMethod, BytecodeConstants {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isSynthetic() {
|
||||
public boolean isSynthetic() { return ((getModifiers() & Constants.ACC_SYNTHETIC) != 0); }
|
||||
|
||||
@Override
|
||||
public boolean isWalaSynthetic() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -95,6 +95,16 @@ public abstract class SyntheticClass implements IClass {
|
|||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* These classes are generated by WALA, not by any
|
||||
* compiler, therefore it always returns false
|
||||
* @see com.ibm.wala.classLoader.IClass#isSynthetic()
|
||||
*/
|
||||
@Override
|
||||
public boolean isSynthetic() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see com.ibm.wala.classLoader.IClass#getReference()
|
||||
*/
|
||||
|
@ -123,7 +133,7 @@ public abstract class SyntheticClass implements IClass {
|
|||
public boolean isArrayClass() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IClassHierarchy getClassHierarchy() {
|
||||
return cha;
|
||||
|
|
|
@ -153,12 +153,20 @@ public class SyntheticMethod implements IMethod {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.ibm.wala.classLoader.IMethod#isWalaSynthetic()
|
||||
*/
|
||||
@Override
|
||||
public boolean isWalaSynthetic() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.ibm.wala.classLoader.IMethod#isSynthetic()
|
||||
*/
|
||||
@Override
|
||||
public boolean isSynthetic() {
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -102,7 +102,7 @@ public class SimpleMemoryAccessMap implements MemoryAccessMap {
|
|||
private void populate(CGNode n) {
|
||||
// we analyze bytecodes to avoid the cost of IR construction, except
|
||||
// for synthetic methods, where we must use the synthetic IR
|
||||
if (ALWAYS_BUILD_IR || n.getMethod().isSynthetic()) {
|
||||
if (ALWAYS_BUILD_IR || n.getMethod().isWalaSynthetic()) {
|
||||
if (DEBUG) {
|
||||
System.err.println("synthetic method");
|
||||
}
|
||||
|
|
|
@ -184,7 +184,7 @@ public abstract class BasicCallGraph<T> extends AbstractNumberedGraph<CGNode> im
|
|||
protected NodeImpl(IMethod method, Context C) {
|
||||
this.method = method;
|
||||
this.context = C;
|
||||
if (method != null && !method.isSynthetic() && method.isAbstract()) {
|
||||
if (method != null && !method.isWalaSynthetic() && method.isAbstract()) {
|
||||
assert !method.isAbstract() : "Abstract method " + method;
|
||||
}
|
||||
assert C != null;
|
||||
|
|
|
@ -297,7 +297,7 @@ public class ExplicitCallGraph extends BasicCallGraph<SSAContextInterpreter> imp
|
|||
|
||||
@Override
|
||||
public IR getIR() {
|
||||
if (getMethod().isSynthetic()) {
|
||||
if (getMethod().isWalaSynthetic()) {
|
||||
// disable local cache in this case, as context interpreters
|
||||
// do weird things like mutate IRs
|
||||
return getCallGraph().getInterpreter(this).getIR(this);
|
||||
|
@ -312,7 +312,7 @@ public class ExplicitCallGraph extends BasicCallGraph<SSAContextInterpreter> imp
|
|||
|
||||
@Override
|
||||
public DefUse getDU() {
|
||||
if (getMethod().isSynthetic()) {
|
||||
if (getMethod().isWalaSynthetic()) {
|
||||
// disable local cache in this case, as context interpreters
|
||||
// do weird things like mutate IRs
|
||||
return getCallGraph().getInterpreter(this).getDU(this);
|
||||
|
|
|
@ -40,7 +40,7 @@ public class DefaultIRFactory implements IRFactory<IMethod> {
|
|||
if (method == null) {
|
||||
throw new IllegalArgumentException("method cannot be null");
|
||||
}
|
||||
if (method.isSynthetic()) {
|
||||
if (method.isWalaSynthetic()) {
|
||||
return syntheticFactory.makeCFG((SyntheticMethod) method);
|
||||
} else if (method instanceof IBytecodeMethod) {
|
||||
@SuppressWarnings("unchecked")
|
||||
|
@ -61,7 +61,7 @@ public class DefaultIRFactory implements IRFactory<IMethod> {
|
|||
if (method == null) {
|
||||
throw new IllegalArgumentException("method cannot be null");
|
||||
}
|
||||
if (method.isSynthetic()) {
|
||||
if (method.isWalaSynthetic()) {
|
||||
return syntheticFactory.makeIR((SyntheticMethod) method, c, options);
|
||||
} else if (method instanceof IBytecodeMethod) {
|
||||
@SuppressWarnings("unchecked")
|
||||
|
@ -81,7 +81,7 @@ public class DefaultIRFactory implements IRFactory<IMethod> {
|
|||
if (method == null) {
|
||||
throw new IllegalArgumentException("null method");
|
||||
}
|
||||
if (method.isSynthetic()) {
|
||||
if (method.isWalaSynthetic()) {
|
||||
return syntheticFactory.contextIsIrrelevant((SyntheticMethod) method);
|
||||
} else if (method instanceof ShrikeCTMethod) {
|
||||
// we know ShrikeFactory contextIsIrrelevant
|
||||
|
|
|
@ -63,9 +63,9 @@ public class JVMLDalvikComparisonTest extends DalvikCallGraphTestBase {
|
|||
private static Set<Pair<CGNode,CGNode>> edgeDiff(CallGraph from, CallGraph to, boolean userOnly) {
|
||||
Set<Pair<CGNode,CGNode>> result = HashSetFactory.make();
|
||||
for(CGNode f : from) {
|
||||
if (! f.getMethod().isSynthetic()) {
|
||||
if (! f.getMethod().isWalaSynthetic()) {
|
||||
outer: for(CGNode t : from) {
|
||||
if (!t.getMethod().isSynthetic() &&
|
||||
if (!t.getMethod().isWalaSynthetic() &&
|
||||
from.hasEdge(f, t) &&
|
||||
(!userOnly ||
|
||||
!t.getMethod().getDeclaringClass().getClassLoader().getReference().equals(ClassLoaderReference.Primordial)))
|
||||
|
|
|
@ -51,6 +51,7 @@ import static org.jf.dexlib2.AccessFlags.ABSTRACT;
|
|||
import static org.jf.dexlib2.AccessFlags.INTERFACE;
|
||||
import static org.jf.dexlib2.AccessFlags.PRIVATE;
|
||||
import static org.jf.dexlib2.AccessFlags.PUBLIC;
|
||||
import static org.jf.dexlib2.AccessFlags.SYNTHETIC;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
@ -229,6 +230,13 @@ public class DexIClass extends BytecodeClass<IClassLoader> {
|
|||
return (modifiers & ABSTRACT.getValue()) != 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see com.ibm.wala.classLoader.IClass#isAbstract()
|
||||
*/
|
||||
@Override
|
||||
public boolean isSynthetic() {
|
||||
return (modifiers & SYNTHETIC.getValue()) != 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
|
|
|
@ -59,6 +59,7 @@ import static org.jf.dexlib2.AccessFlags.PROTECTED;
|
|||
import static org.jf.dexlib2.AccessFlags.PUBLIC;
|
||||
import static org.jf.dexlib2.AccessFlags.STATIC;
|
||||
import static org.jf.dexlib2.AccessFlags.VOLATILE;
|
||||
import static org.jf.dexlib2.AccessFlags.SYNTHETIC;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
@ -508,13 +509,20 @@ public class DexIMethod implements IBytecodeMethod<Instruction> {
|
|||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see com.ibm.wala.classLoader.IMethod#isSynthetic()
|
||||
* @see com.ibm.wala.classLoader.IMethod#isWalaSynthetic()
|
||||
*/
|
||||
@Override
|
||||
public boolean isSynthetic() {
|
||||
public boolean isWalaSynthetic() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see com.ibm.wala.classLoader.IMethod#isSynthetic()
|
||||
*/
|
||||
@Override
|
||||
public boolean isSynthetic() { return (eMethod.getAccessFlags() & SYNTHETIC.getValue()) != 0; }
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see com.ibm.wala.classLoader.IMember#isStatic()
|
||||
|
|
|
@ -436,7 +436,7 @@ implements IFlowFunctionMap<BasicBlockInContext<E>> {
|
|||
final SSAInvokeInstruction instruction = (SSAInvokeInstruction) src.getLastInstruction();
|
||||
|
||||
// String signature = dest.getMethod().getSignature();
|
||||
// if ( dest.getMethod().isSynthetic() ) {
|
||||
// if ( dest.getMethod().isWalaSynthetic() ) {
|
||||
// System.out.println("Synthetic: "+signature);
|
||||
// } else {
|
||||
// System.err.println(signature);
|
||||
|
@ -448,7 +448,7 @@ implements IFlowFunctionMap<BasicBlockInContext<E>> {
|
|||
// System.out.println("Call to system: "+signature);
|
||||
// }
|
||||
|
||||
// if (! dest.getMethod().isSynthetic()
|
||||
// if (! dest.getMethod().isWalaSynthetic()
|
||||
// && LoaderUtils.fromLoader(dest.getNode(), ClassLoaderReference.Primordial)) {
|
||||
//
|
||||
// MyLogger.log(DEBUG,"Primordial and No Summary! (getCallFlowFunction) - " + dest.getMethod().getReference());
|
||||
|
|
|
@ -195,7 +195,7 @@ public class CGAnalysisContext<E extends ISSABasicBlock> {
|
|||
Warnings.clear();
|
||||
|
||||
pa = cgb.getPointerAnalysis();
|
||||
partialGraph = GraphSlicer.prune(cg, node -> LoaderUtils.fromLoader(node, ClassLoaderReference.Application) || node.getMethod().isSynthetic());
|
||||
partialGraph = GraphSlicer.prune(cg, node -> LoaderUtils.fromLoader(node, ClassLoaderReference.Application) || node.getMethod().isWalaSynthetic());
|
||||
if (options.includeLibrary()) {
|
||||
graph = (ISupergraph) ICFGSupergraph.make(cg);
|
||||
} else {
|
||||
|
@ -271,7 +271,7 @@ public class CGAnalysisContext<E extends ISSABasicBlock> {
|
|||
}
|
||||
}
|
||||
for (CGNode node : Iterator2Iterable.make(cg.iterator())) {
|
||||
if (node.getMethod().isSynthetic()) {
|
||||
if (node.getMethod().isWalaSynthetic()) {
|
||||
SSACFG ssaCFG = node.getIR().getControlFlowGraph();
|
||||
int totalBlocks = ssaCFG.getNumberOfNodes();
|
||||
for (int i = 0; i < totalBlocks; i++) {
|
||||
|
|
|
@ -464,6 +464,8 @@ public interface Constants {
|
|||
|
||||
public static final short ACC_STRICT = 0x800;
|
||||
|
||||
public static final short ACC_SYNTHETIC = 0x1000;
|
||||
|
||||
public static final byte CONSTANT_Utf8 = 1;
|
||||
|
||||
public static final byte CONSTANT_Integer = 3;
|
||||
|
|
Loading…
Reference in New Issue