more migration to Java assertions

git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@3559 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
sjfink 2009-05-01 17:42:28 +00:00
parent 17c2aa7588
commit de6adbc4d7
115 changed files with 1051 additions and 1904 deletions

View File

@ -20,16 +20,12 @@ import com.ibm.wala.ssa.SSAInstruction;
import com.ibm.wala.ssa.SSAInstructionFactory;
import com.ibm.wala.ssa.SSAInvokeInstruction;
import com.ibm.wala.types.TypeReference;
import com.ibm.wala.util.debug.Assertions;
/**
* This is a normal Java invoke instruction as generated by the
* CAst source language front end; its only difference from the normal
* SSAInvokeInstruction is that it is subclassed from invoke
* instructions that support explicit handling of lexical scoping. So
* it behaves exactly like an invoke from bytecode, except that it has
* extra state for managing lexical uses and definitions.
*
* This is a normal Java invoke instruction as generated by the CAst source language front end; its only difference from the normal
* SSAInvokeInstruction is that it is subclassed from invoke instructions that support explicit handling of lexical scoping. So it
* behaves exactly like an invoke from bytecode, except that it has extra state for managing lexical uses and definitions.
*
* @author Julian Dolby (dolby@us.ibm.com)
*/
public class AstJavaInvokeInstruction extends FixedParametersLexicalInvokeInstruction {
@ -39,10 +35,8 @@ public class AstJavaInvokeInstruction extends FixedParametersLexicalInvokeInstru
}
public AstJavaInvokeInstruction(int result, int[] params, int exception, CallSiteReference site) {
this(new int[]{result}, params, exception, site);
if (Assertions.verifyAssertions) {
SSAInvokeInstruction.assertParamsKosher(result, params, site);
}
this(new int[] { result }, params, exception, site);
SSAInvokeInstruction.assertParamsKosher(result, params, site);
}
/**
@ -52,22 +46,27 @@ public class AstJavaInvokeInstruction extends FixedParametersLexicalInvokeInstru
this(null, params, exception, site);
}
public AstJavaInvokeInstruction(int results[], int[] params, int exception, CallSiteReference site, Access[] lexicalReads, Access[] lexicalWrites) {
public AstJavaInvokeInstruction(int results[], int[] params, int exception, CallSiteReference site, Access[] lexicalReads,
Access[] lexicalWrites) {
super(results, params, exception, site, lexicalReads, lexicalWrites);
}
protected SSAInstruction copyInstruction(SSAInstructionFactory insts, int results[], int[] params, int exception, Access[] lexicalReads, Access[] lexicalWrites) {
return ((AstJavaInstructionFactory)insts).JavaInvokeInstruction(results, params, exception, getCallSite(), lexicalReads, lexicalWrites);
protected SSAInstruction copyInstruction(SSAInstructionFactory insts, int results[], int[] params, int exception,
Access[] lexicalReads, Access[] lexicalWrites) {
return ((AstJavaInstructionFactory) insts).JavaInvokeInstruction(results, params, exception, getCallSite(), lexicalReads,
lexicalWrites);
}
/**
* @see com.ibm.domo.ssa.SSAInstruction#visit(IVisitor)
*/
public void visit(IVisitor v) {
((AstJavaInstructionVisitor)v).visitJavaInvoke(this);
((AstJavaInstructionVisitor) v).visitJavaInvoke(this);
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see com.ibm.domo.ssa.Instruction#getExceptionTypes()
*/
public Collection<TypeReference> getExceptionTypes() {

View File

@ -7,19 +7,17 @@ import com.ibm.wala.ssa.SSAInstruction;
import com.ibm.wala.ssa.SSAInstructionFactory;
import com.ibm.wala.ssa.SymbolTable;
import com.ibm.wala.types.TypeReference;
import com.ibm.wala.util.debug.Assertions;
/**
* The CAst source language front end for Java has explicit support
* for lexicallly-enclosing objects, rather than compiling them away
* into extra fields and access-control thwarting accessor methods as
* is done in bytecode. This instruction represents a read of the
* object of the given type that lexically encloses its use value.
*
* The CAst source language front end for Java has explicit support for lexicallly-enclosing objects, rather than compiling them
* away into extra fields and access-control thwarting accessor methods as is done in bytecode. This instruction represents a read
* of the object of the given type that lexically encloses its use value.
*
* @author Julian Dolby (dolby@us.ibm.com)
*/
public class EnclosingObjectReference extends SSAInstruction {
private final TypeReference type;
private final int lval;
public EnclosingObjectReference(int lval, TypeReference type) {
@ -36,10 +34,8 @@ public class EnclosingObjectReference extends SSAInstruction {
}
public int getDef(int i) {
if (Assertions.verifyAssertions) {
assert i == 0;
}
assert i == 0;
return lval;
}
@ -52,15 +48,15 @@ public class EnclosingObjectReference extends SSAInstruction {
}
public SSAInstruction copyForSSA(SSAInstructionFactory insts, int[] defs, int[] uses) {
return ((AstJavaInstructionFactory)insts).EnclosingObjectReference(defs==null? lval: defs[0], type);
return ((AstJavaInstructionFactory) insts).EnclosingObjectReference(defs == null ? lval : defs[0], type);
}
public String toString(SymbolTable symbolTable) {
return getValueString(symbolTable, lval) + " = enclosing " + type.getName();
return getValueString(symbolTable, lval) + " = enclosing " + type.getName();
}
public void visit(IVisitor v) {
((AstJavaInstructionVisitor)v).visitEnclosingObjectReference(this);
((AstJavaInstructionVisitor) v).visitEnclosingObjectReference(this);
}
public int hashCode() {

View File

@ -119,9 +119,7 @@ public class CAstAnalysisScope extends AnalysisScope {
* @return the ClassLoaderReference specified by <code>name</code>.
*/
public ClassLoaderReference getLoader(Atom name) {
if (Assertions.verifyAssertions) {
assert name.equals(theLoader.getName());
}
assert name.equals(theLoader.getName());
return theLoader;
}

View File

@ -10,42 +10,39 @@
*****************************************************************************/
package com.ibm.wala.cast.ir.ssa;
import com.ibm.wala.ssa.SSAInstruction;
import com.ibm.wala.ssa.SSAInstructionFactory;
import com.ibm.wala.ssa.SSAUnaryOpInstruction;
import com.ibm.wala.ssa.SymbolTable;
import com.ibm.wala.util.debug.Assertions;
/**
* A simple assignment statement. Only appears in the IR before SSA
* conversion, and temporarily when needed to undo copy propagation
* A simple assignment statement. Only appears in the IR before SSA conversion, and temporarily when needed to undo copy propagation
* during processing of new lexical definitions and uses.
*
*
* @author Julian Dolby (dolby@us.ibm.com)
*
*
*/
public class AssignInstruction extends SSAUnaryOpInstruction {
/**
* create the assignment v_result := v_val
*
* @param result
* @param val
*/
public AssignInstruction(int result, int val) {
super(null, result, val);
if (Assertions.verifyAssertions) {
assert result != val;
assert result != -1;
assert val != -1;
}
assert result != val;
assert result != -1;
assert val != -1;
}
/*
* @see com.ibm.wala.ssa.SSAInstruction#copyForSSA(int[], int[])
*/
public SSAInstruction copyForSSA(SSAInstructionFactory insts, int[] defs, int[] uses) {
return ((AstInstructionFactory)insts).AssignInstruction(defs == null ? getDef(0) : defs[0], uses == null ? getUse(0) : uses[0]);
return ((AstInstructionFactory) insts)
.AssignInstruction(defs == null ? getDef(0) : defs[0], uses == null ? getUse(0) : uses[0]);
}
/*

View File

@ -47,12 +47,10 @@ public class AstIsDefinedInstruction extends SSAInstruction {
this.fieldRef = null;
}
public SSAInstruction copyForSSA(SSAInstructionFactory insts, int[] defs, int[] uses) {
if (Assertions.verifyAssertions) {
assert fieldVal == -1 || fieldRef == null;
}
public SSAInstruction copyForSSA(SSAInstructionFactory insts, int[] defs, int[] uses) {
assert fieldVal == -1 || fieldRef == null;
return ((AstInstructionFactory)insts).IsDefinedInstruction((defs == null) ? lval : defs[0], (uses == null) ? rval : uses[0],
return ((AstInstructionFactory) insts).IsDefinedInstruction((defs == null) ? lval : defs[0], (uses == null) ? rval : uses[0],
(uses == null || fieldVal == -1) ? fieldVal : uses[1], fieldRef);
}
@ -88,9 +86,7 @@ public class AstIsDefinedInstruction extends SSAInstruction {
}
public int getDef(int i) {
if (Assertions.verifyAssertions) {
assert i == 0;
}
assert i == 0;
return lval;
}

View File

@ -15,20 +15,17 @@ import java.util.NoSuchElementException;
import com.ibm.wala.cast.tree.CAst;
import com.ibm.wala.cast.tree.CAstNode;
import com.ibm.wala.cast.util.CAstPrinter;
import com.ibm.wala.util.debug.Assertions;
/**
* An implementation of CAst, i.e. a simple factory for creating capa
* ast nodes. This class simply creates generic nodes with a kind
* field, and either an array of children or a constant values. Note
* that there is no easy way to mutate these trees; do not change
* An implementation of CAst, i.e. a simple factory for creating capa ast nodes. This class simply creates generic nodes with a kind
* field, and either an array of children or a constant values. Note that there is no easy way to mutate these trees; do not change
* this (see CAstNode for the rationale for this rule).
*
*
* @author Julian Dolby (dolby@us.ibm.com)
*
*
*/
public class CAstImpl implements CAst {
private int nextID= 0;
private int nextID = 0;
public String makeUnique() {
return "id" + (nextID++);
@ -36,15 +33,16 @@ public class CAstImpl implements CAst {
protected static class CAstNodeImpl implements CAstNode {
protected final CAstNode[] cs;
protected final int kind;
protected CAstNodeImpl(int kind, CAstNode[] cs) {
this.kind = kind;
this.cs = cs;
if (Assertions.verifyAssertions)
for(int i = 0; i < cs.length; i++)
assert cs[i] != null : "argument " + i + " is null for node kind " + kind + " [" + CAstPrinter.entityKindAsString(kind) + "]";
for (int i = 0; i < cs.length; i++)
assert cs[i] != null : "argument " + i + " is null for node kind " + kind + " [" + CAstPrinter.entityKindAsString(kind)
+ "]";
}
public int getKind() {
@ -57,24 +55,24 @@ public class CAstImpl implements CAst {
public CAstNode getChild(int n) {
try {
return cs[n];
return cs[n];
} catch (ArrayIndexOutOfBoundsException e) {
throw new NoSuchElementException(n + " of " + CAstPrinter.print(this));
throw new NoSuchElementException(n + " of " + CAstPrinter.print(this));
}
}
public int getChildCount() {
return cs.length;
}
public String toString() {
return super.toString() + ":" + CAstPrinter.print(this);
return super.toString() + ":" + CAstPrinter.print(this);
}
public int hashCode() {
int code = getKind() * (getChildCount()+13);
for(int i = 0; i < getChildCount(); i++) {
code *= getChild(i).getKind();
int code = getKind() * (getChildCount() + 13);
for (int i = 0; i < getChildCount(); i++) {
code *= getChild(i).getKind();
}
return code;
@ -86,7 +84,7 @@ public class CAstImpl implements CAst {
}
public CAstNode makeNode(int kind, CAstNode c1, CAstNode[] cs) {
CAstNode[] children = new CAstNode[ cs.length + 1 ];
CAstNode[] children = new CAstNode[cs.length + 1];
children[0] = c1;
System.arraycopy(cs, 0, children, 1, cs.length);
return makeNode(kind, children);
@ -97,27 +95,27 @@ public class CAstImpl implements CAst {
}
public CAstNode makeNode(int kind, CAstNode c1) {
return makeNode(kind, new CAstNode[]{c1});
return makeNode(kind, new CAstNode[] { c1 });
}
public CAstNode makeNode(int kind, CAstNode c1, CAstNode c2) {
return makeNode(kind, new CAstNode[]{c1, c2});
return makeNode(kind, new CAstNode[] { c1, c2 });
}
public CAstNode makeNode(int kind, CAstNode c1, CAstNode c2, CAstNode c3) {
return makeNode(kind, new CAstNode[]{c1, c2, c3});
return makeNode(kind, new CAstNode[] { c1, c2, c3 });
}
public CAstNode makeNode(int kind, CAstNode c1, CAstNode c2, CAstNode c3, CAstNode c4) {
return makeNode(kind, new CAstNode[]{c1, c2, c3, c4});
return makeNode(kind, new CAstNode[] { c1, c2, c3, c4 });
}
public CAstNode makeNode(int kind, CAstNode c1, CAstNode c2, CAstNode c3, CAstNode c4, CAstNode c5) {
return makeNode(kind, new CAstNode[]{c1, c2, c3, c4, c5});
return makeNode(kind, new CAstNode[] { c1, c2, c3, c4, c5 });
}
public CAstNode makeNode(int kind, CAstNode c1, CAstNode c2, CAstNode c3, CAstNode c4, CAstNode c5, CAstNode c6) {
return makeNode(kind, new CAstNode[]{c1, c2, c3, c4, c5, c6});
return makeNode(kind, new CAstNode[] { c1, c2, c3, c4, c5, c6 });
}
protected static class CAstValueImpl implements CAstNode {
@ -142,14 +140,14 @@ public class CAstImpl implements CAst {
public int getChildCount() {
return 0;
}
public String toString() {
return "CAstValue: " + value;
}
public int hashCode() {
return getKind() * toString().hashCode();
}
}
}
public CAstNode makeConstant(final Object value) {
@ -157,31 +155,31 @@ public class CAstImpl implements CAst {
}
public CAstNode makeConstant(boolean value) {
return makeConstant(value? Boolean.TRUE: Boolean.FALSE);
return makeConstant(value ? Boolean.TRUE : Boolean.FALSE);
}
public CAstNode makeConstant(char value) {
return makeConstant( new Character(value) );
return makeConstant(new Character(value));
}
public CAstNode makeConstant(short value) {
return makeConstant( new Short(value) );
return makeConstant(new Short(value));
}
public CAstNode makeConstant(int value) {
return makeConstant( new Integer(value) );
return makeConstant(new Integer(value));
}
public CAstNode makeConstant(long value) {
return makeConstant( new Long(value) );
return makeConstant(new Long(value));
}
public CAstNode makeConstant(float value) {
return makeConstant( new Float(value) );
}
return makeConstant(new Float(value));
}
public CAstNode makeConstant(double value) {
return makeConstant( new Double(value) );
return makeConstant(new Double(value));
}
}

View File

@ -145,16 +145,12 @@ public abstract class AbstractPtrTest extends TestCase {
protected void doPointsToSizeTest(String scopeFile, String mainClass, int expected14Size, int expected15Size, int expected16Size)
throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException {
if (Assertions.verifyAssertions) {
assert scope == null;
}
assert scope == null;
Collection<InstanceKey> pointsTo = getPointsToSetToTest(scopeFile, mainClass);
if (debug) {
System.err.println("points-to for " + mainClass + ": " + pointsTo);
}
if (Assertions.verifyAssertions) {
assert scope != null;
}
assert scope != null;
if (scope.isJava16Libraries()) {
assertEquals(expected16Size, pointsTo.size());
} else if (scope.isJava15Libraries()) {
@ -199,13 +195,13 @@ public abstract class AbstractPtrTest extends TestCase {
final AnalysisCache analysisCache = new AnalysisCache();
CallGraphBuilder cgBuilder = Util.makeZeroCFABuilder(options, analysisCache, cha, scope);
final CallGraph cg = cgBuilder.makeCallGraph(options, null);
// System.err.println(cg.toString());
// System.err.println(cg.toString());
// MemoryAccessMap mam = new SimpleMemoryAccessMap(cg, cgBuilder.getPointerAnalysis().getHeapModel(), false);
// MemoryAccessMap mam = new SimpleMemoryAccessMap(cg, cgBuilder.getPointerAnalysis().getHeapModel(), false);
MemoryAccessMap mam = new PABasedMemoryAccessMap(cg, cgBuilder.getPointerAnalysis());
SSAPropagationCallGraphBuilder builder = Util.makeVanillaZeroOneCFABuilder(options, analysisCache, cha, scope);
DemandRefinementPointsTo fullDemandPointsTo = new DemandRefinementPointsTo(cg, new ThisFilteringHeapModel(builder,cha), mam, cha, options,
getStateMachineFactory());
DemandRefinementPointsTo fullDemandPointsTo = new DemandRefinementPointsTo(cg, new ThisFilteringHeapModel(builder, cha), mam,
cha, options, getStateMachineFactory());
return fullDemandPointsTo;
}

View File

@ -22,7 +22,6 @@ import com.ibm.wala.ipa.callgraph.propagation.InstanceKey;
import com.ibm.wala.ipa.callgraph.propagation.LocalPointerKey;
import com.ibm.wala.ipa.callgraph.propagation.PointerAnalysis;
import com.ibm.wala.ipa.callgraph.propagation.PointerKey;
import com.ibm.wala.ipa.cha.ClassHierarchyException;
import com.ibm.wala.types.TypeReference;
import com.ibm.wala.util.collections.CompoundIterator;
import com.ibm.wala.util.collections.EmptyIterator;
@ -46,7 +45,7 @@ import com.ibm.wala.util.intset.OrdinalSetMapping;
import com.ibm.wala.util.intset.SparseIntSet;
/**
* @author sfink
* Basic implementation of {@link HeapGraph}
*/
public class BasicHeapGraph extends HeapGraph {
@ -94,10 +93,8 @@ public class BasicHeapGraph extends HeapGraph {
if (N instanceof PointerKey) {
return pointerKeys.getMappedIndex((PointerKey) N);
} else {
if (Assertions.verifyAssertions) {
if (!(N instanceof InstanceKey)) {
Assertions.UNREACHABLE(N.getClass().toString());
}
if (!(N instanceof InstanceKey)) {
Assertions.UNREACHABLE(N.getClass().toString());
}
int inumber = P.getInstanceKeyMapping().getMappedIndex((InstanceKey) N);
return (inumber == -1) ? -1 : inumber + pointerKeys.getMaximumIndex() + 1;
@ -227,10 +224,8 @@ public class BasicHeapGraph extends HeapGraph {
InstanceKey I = (InstanceKey) N;
TypeReference T = I.getConcreteType().getReference();
if (Assertions.verifyAssertions) {
if (T == null) {
assert T != null : "null concrete type from " + I.getClass();
}
if (T == null) {
assert T != null : "null concrete type from " + I.getClass();
}
if (T.isArrayType()) {
PointerKey p = getHeapModel().getPointerKeyForArrayContents(I);
@ -241,10 +236,8 @@ public class BasicHeapGraph extends HeapGraph {
}
} else {
IClass klass = getHeapModel().getClassHierarchy().lookupClass(T);
if (Assertions.verifyAssertions) {
if (klass == null) {
assert klass != null : "null klass for type " + T;
}
if (klass == null) {
assert klass != null : "null klass for type " + T;
}
MutableSparseIntSet result = MutableSparseIntSet.makeEmpty();
for (Iterator<IField> it = klass.getAllInstanceFields().iterator(); it.hasNext();) {

View File

@ -35,7 +35,6 @@ import com.ibm.wala.types.FieldReference;
import com.ibm.wala.types.TypeReference;
import com.ibm.wala.util.collections.EmptyIterator;
import com.ibm.wala.util.collections.NonNullSingletonIterator;
import com.ibm.wala.util.debug.Assertions;
/**
* An {@link SSAContextInterpreter} specialized to interpret reflective class factories (e.g. Class.forName()) in a
@ -49,9 +48,7 @@ public class ClassFactoryContextInterpreter implements SSAContextInterpreter {
if (node == null) {
throw new IllegalArgumentException("node is null");
}
if (Assertions.verifyAssertions) {
assert understands(node);
}
assert understands(node);
if (DEBUG) {
System.err.println("generating IR for " + node);
}
@ -60,13 +57,11 @@ public class ClassFactoryContextInterpreter implements SSAContextInterpreter {
}
public int getNumberOfStatements(CGNode node) {
if (Assertions.verifyAssertions) {
assert understands(node);
}
assert understands(node);
return getIR(node).getInstructions().length;
}
/*
/*
* @see com.ibm.wala.ipa.callgraph.propagation.rta.RTAContextInterpreter#understands(com.ibm.wala.ipa.callgraph.CGNode)
*/
public boolean understands(CGNode node) {
@ -79,16 +74,14 @@ public class ClassFactoryContextInterpreter implements SSAContextInterpreter {
return ClassFactoryContextSelector.isClassFactory(node.getMethod());
}
/*
/*
* @see com.ibm.wala.ipa.callgraph.propagation.rta.RTAContextInterpreter#iterateNewSites(com.ibm.wala.ipa.callgraph.CGNode)
*/
public Iterator<NewSiteReference> iterateNewSites(CGNode node) {
if (node == null) {
throw new IllegalArgumentException("node is null");
}
if (Assertions.verifyAssertions) {
assert understands(node);
}
assert understands(node);
JavaTypeContext context = (JavaTypeContext) node.getContext();
TypeReference tr = context.getType().getTypeReference();
if (tr != null) {
@ -97,17 +90,14 @@ public class ClassFactoryContextInterpreter implements SSAContextInterpreter {
return EmptyIterator.instance();
}
/*
/*
* @see com.ibm.wala.ipa.callgraph.propagation.rta.RTAContextInterpreter#iterateCallSites(com.ibm.wala.ipa.callgraph.CGNode)
*/
public Iterator<CallSiteReference> iterateCallSites(CGNode node) {
if (Assertions.verifyAssertions) {
assert understands(node);
}
assert understands(node);
return EmptyIterator.instance();
}
private SSAInstruction[] makeStatements(JavaTypeContext context) {
SSAInstructionFactory insts = context.getType().getType().getClassLoader().getInstructionFactory();
ArrayList<SSAInstruction> statements = new ArrayList<SSAInstruction>();

View File

@ -36,12 +36,11 @@ import com.ibm.wala.types.Selector;
import com.ibm.wala.types.TypeReference;
import com.ibm.wala.util.collections.EmptyIterator;
import com.ibm.wala.util.collections.NonNullSingletonIterator;
import com.ibm.wala.util.debug.Assertions;
import com.ibm.wala.util.strings.Atom;
/**
* An {@link SSAContextInterpreter} specialized to interpret Class.forName in a {@link JavaTypeContext} which
* represents the point-type of the class object created by the call.
* An {@link SSAContextInterpreter} specialized to interpret Class.forName in a {@link JavaTypeContext} which represents the
* point-type of the class object created by the call.
*/
public class ClassNewInstanceContextInterpreter extends AbstractReflectionInterpreter {
@ -49,15 +48,17 @@ public class ClassNewInstanceContextInterpreter extends AbstractReflectionInterp
private final static Descriptor classNewInstanceDescriptor = Descriptor.findOrCreateUTF8("()Ljava/lang/Object;");
public final static MethodReference CLASS_NEW_INSTANCE_REF = MethodReference.findOrCreate(TypeReference.JavaLangClass, newInstanceAtom,
classNewInstanceDescriptor);
public final static MethodReference CLASS_NEW_INSTANCE_REF = MethodReference.findOrCreate(TypeReference.JavaLangClass,
newInstanceAtom, classNewInstanceDescriptor);
private final static Atom defCtorAtom = Atom.findOrCreateUnicodeAtom("<init>");
private final static Descriptor defCtorDescriptor = Descriptor.findOrCreateUTF8("()V");
private final static Selector defCtorSelector = new Selector(defCtorAtom, defCtorDescriptor);
private final IClassHierarchy cha;
public ClassNewInstanceContextInterpreter(IClassHierarchy cha) {
this.cha = cha;
}
@ -66,9 +67,7 @@ public class ClassNewInstanceContextInterpreter extends AbstractReflectionInterp
if (node == null) {
throw new IllegalArgumentException("node is null");
}
if (Assertions.verifyAssertions) {
assert understands(node);
}
assert understands(node);
if (DEBUG) {
System.err.println("generating IR for " + node);
}
@ -77,9 +76,7 @@ public class ClassNewInstanceContextInterpreter extends AbstractReflectionInterp
}
public int getNumberOfStatements(CGNode node) {
if (Assertions.verifyAssertions) {
assert understands(node);
}
assert understands(node);
return getIR(node).getInstructions().length;
}
@ -97,9 +94,7 @@ public class ClassNewInstanceContextInterpreter extends AbstractReflectionInterp
if (node == null) {
throw new IllegalArgumentException("node is null");
}
if (Assertions.verifyAssertions) {
assert understands(node);
}
assert understands(node);
JavaTypeContext context = (JavaTypeContext) node.getContext();
TypeReference tr = context.getType().getTypeReference();
if (tr != null) {
@ -109,45 +104,45 @@ public class ClassNewInstanceContextInterpreter extends AbstractReflectionInterp
}
public Iterator<CallSiteReference> iterateCallSites(CGNode node) {
if (Assertions.verifyAssertions) {
assert understands(node);
}
assert understands(node);
return EmptyIterator.instance();
}
private IR makeIR(IMethod method, JavaTypeContext context) {
private IR makeIR(IMethod method, JavaTypeContext context) {
SSAInstructionFactory insts = context.getType().getType().getClassLoader().getInstructionFactory();
TypeReference tr = context.getType().getTypeReference();
if (tr != null) {
SpecializedMethod m = new SpecializedMethod(method, method.getDeclaringClass(), method.isStatic(), false);
IClass klass = cha.lookupClass(tr);
IMethod publicDefaultCtor = getPublicDefaultCtor(klass);
IMethod publicDefaultCtor = getPublicDefaultCtor(klass);
if (publicDefaultCtor != null) {
m.addStatementsForConcreteSimpleType(tr);
} else if (klass.getMethod(defCtorSelector) == null) {
TypeReference instantiationExceptionRef = TypeReference.findOrCreateClass(ClassLoaderReference.Primordial, "java/lang", "InstantiationException");
TypeReference instantiationExceptionRef = TypeReference.findOrCreateClass(ClassLoaderReference.Primordial, "java/lang",
"InstantiationException");
int xobj = method.getNumberOfParameters() + 1;
SSAInstruction newStatement = insts.NewInstruction(xobj, NewSiteReference.make(2, instantiationExceptionRef));
m.addInstruction(tr, newStatement, true);
SSAInstruction throwStatement = insts.ThrowInstruction(xobj);
m.addInstruction(tr, throwStatement, false);
} else {
TypeReference illegalAccessExceptionRef = TypeReference.findOrCreateClass(ClassLoaderReference.Primordial, "java/lang", "IllegalAccessException");
TypeReference illegalAccessExceptionRef = TypeReference.findOrCreateClass(ClassLoaderReference.Primordial, "java/lang",
"IllegalAccessException");
int xobj = method.getNumberOfParameters() + 1;
SSAInstruction newStatement = insts.NewInstruction(xobj, NewSiteReference.make(2, illegalAccessExceptionRef));
m.addInstruction(tr, newStatement, true);
SSAInstruction throwStatement = insts.ThrowInstruction(xobj);
m.addInstruction(tr, throwStatement, false);
m.addInstruction(tr, throwStatement, false);
}
SSAInstruction[] instrs = new SSAInstruction[m.allInstructions.size()];
m.allInstructions.<SSAInstruction> toArray(instrs);
return new SyntheticIR(method, context, new InducedCFG(instrs, method, context), instrs, SSAOptions.defaultOptions(), null);
}
return null;
}
private IMethod getPublicDefaultCtor(IClass klass) {
IMethod ctorMethod = klass.getMethod(defCtorSelector);
if (ctorMethod != null && ctorMethod.isPublic()) {
@ -155,7 +150,7 @@ public class ClassNewInstanceContextInterpreter extends AbstractReflectionInterp
}
return null;
}
public boolean recordFactoryType(CGNode node, IClass klass) {
return false;
}

View File

@ -50,16 +50,12 @@ import com.ibm.wala.types.TypeName;
import com.ibm.wala.types.TypeReference;
import com.ibm.wala.util.collections.HashMapFactory;
import com.ibm.wala.util.collections.NonNullSingletonIterator;
import com.ibm.wala.util.debug.Assertions;
import com.ibm.wala.util.strings.Atom;
/**
*
* A context interpreter for java.lang.Object.clone
*
* TODO: The current implementation does not model CloneNotSupportedExceptions
*
* @author sfink
*/
public class CloneInterpreter implements SSAContextInterpreter {
@ -106,9 +102,7 @@ public class CloneInterpreter implements SSAContextInterpreter {
if (node == null) {
throw new IllegalArgumentException("node is null");
}
if (Assertions.verifyAssertions) {
assert understands(node);
}
assert understands(node);
IClass cls = ContextUtil.getConcreteClassFromContext(node.getContext());
IR result = IRCache.get(cls.getReference());
if (result == null) {
@ -119,9 +113,7 @@ public class CloneInterpreter implements SSAContextInterpreter {
}
public int getNumberOfStatements(CGNode node) {
if (Assertions.verifyAssertions) {
assert understands(node);
}
assert understands(node);
return getIR(node).getInstructions().length;
}
@ -136,17 +128,13 @@ public class CloneInterpreter implements SSAContextInterpreter {
if (node == null) {
throw new IllegalArgumentException("node is null");
}
if (Assertions.verifyAssertions) {
assert understands(node);
}
assert understands(node);
IClass cls = ContextUtil.getConcreteClassFromContext(node.getContext());
return new NonNullSingletonIterator<NewSiteReference>(NewSiteReference.make(NEW_PC, cls.getReference()));
}
public Iterator<CallSiteReference> iterateCallSites(CGNode node) {
if (Assertions.verifyAssertions) {
assert understands(node);
}
assert understands(node);
return new NonNullSingletonIterator<CallSiteReference>(ARRAYCOPY_SITE);
}
@ -154,9 +142,7 @@ public class CloneInterpreter implements SSAContextInterpreter {
* @return an array of statements that encode the behavior of the clone method for a given type.
*/
private SSAInstruction[] makeStatements(IClass klass) {
if (Assertions.verifyAssertions) {
assert klass != null;
}
assert klass != null;
ArrayList<SSAInstruction> statements = new ArrayList<SSAInstruction>();
// value number 1 is "this".
@ -219,9 +205,7 @@ public class CloneInterpreter implements SSAContextInterpreter {
* @return an IR that encodes the behavior of the clone method for a given type.
*/
private IR makeIR(IMethod method, Context context, IClass klass) {
if (Assertions.verifyAssertions) {
assert klass != null;
}
assert klass != null;
SSAInstruction instrs[] = makeStatements(klass);
return new SyntheticIR(method, context, new InducedCFG(instrs, method, context), instrs, SSAOptions.defaultOptions(), null);
}

View File

@ -65,8 +65,7 @@ import com.ibm.wala.util.warnings.Warnings;
class FactoryBypassInterpreter extends AbstractReflectionInterpreter {
/**
* A Map from CallerSiteContext -> Set <TypeReference>represents the types a factory method might create in a
* particular context
* A Map from CallerSiteContext -> Set <TypeReference>represents the types a factory method might create in a particular context
*/
private final Map<Context, Set<TypeReference>> map = HashMapFactory.make();
@ -97,18 +96,18 @@ class FactoryBypassInterpreter extends AbstractReflectionInterpreter {
private Set<TypeReference> getTypesForContext(Context context) {
// first try user spec
// XMLReflectionReader spec = (XMLReflectionReader) userSpec;
// if (spec != null && context instanceof CallerSiteContext) {
// CallerSiteContext site = (CallerSiteContext) context;
// MemberReference m = site.getCaller().getMethod().getReference();
// ReflectionSummary summary = spec.getSummary(m);
// if (summary != null) {
// Set<TypeReference> types = summary.getTypesForProgramLocation(site.getCallSite().getProgramCounter());
// if (types != null) {
// return types;
// }
// }
// }
// XMLReflectionReader spec = (XMLReflectionReader) userSpec;
// if (spec != null && context instanceof CallerSiteContext) {
// CallerSiteContext site = (CallerSiteContext) context;
// MemberReference m = site.getCaller().getMethod().getReference();
// ReflectionSummary summary = spec.getSummary(m);
// if (summary != null) {
// Set<TypeReference> types = summary.getTypesForProgramLocation(site.getCallSite().getProgramCounter());
// if (types != null) {
// return types;
// }
// }
// }
Set<TypeReference> types = map.get(context);
return types;
@ -127,7 +126,7 @@ class FactoryBypassInterpreter extends AbstractReflectionInterpreter {
/*
* @see com.ibm.wala.ipa.callgraph.rta.RTAContextInterpreter#understands(com.ibm.wala.classLoader.IMethod,
* com.ibm.wala.ipa.callgraph.Context)
* com.ibm.wala.ipa.callgraph.Context)
*/
public boolean understands(CGNode node) {
if (node == null) {
@ -205,7 +204,7 @@ class FactoryBypassInterpreter extends AbstractReflectionInterpreter {
/*
* @see com.ibm.wala.ipa.callgraph.propagation.rta.RTAContextInterpreter#recordFactoryType(com.ibm.wala.ipa.callgraph.CGNode,
* com.ibm.wala.classLoader.IClass)
* com.ibm.wala.classLoader.IClass)
*/
public boolean recordFactoryType(CGNode node, IClass klass) {
if (klass == null) {
@ -370,10 +369,8 @@ class FactoryBypassInterpreter extends AbstractReflectionInterpreter {
}
this.method = m;
if (Assertions.verifyAssertions) {
assert S != null;
assert m.getDeclaringClass() != null : "null declaring class for " + m;
}
assert S != null;
assert m.getDeclaringClass() != null : "null declaring class for " + m;
// add original statements from the method summary
nextLocal = addOriginalStatements(m);
@ -397,7 +394,7 @@ class FactoryBypassInterpreter extends AbstractReflectionInterpreter {
if ((T instanceof PointType) || (T instanceof ConeType)) {
TypeReference ref = T.getType().getReference();
NewSiteReference site = NewSiteReference.make(0, ref);
if (DEBUG) {
IClass klass = options.getClassTargetSelector().getAllocatedTarget(null, site);
System.err.println(("Selected allocated target: " + klass + " for " + T));
@ -447,9 +444,9 @@ class FactoryBypassInterpreter extends AbstractReflectionInterpreter {
}
} else if (T instanceof SetType) {
// This code has clearly bitrotted, since iteratePoints() returns an Iterator<TypeReference>
// and we need an Iterator<IClass>. Commenting out for now. --MS
// and we need an Iterator<IClass>. Commenting out for now. --MS
Assertions.UNREACHABLE();
//addStatementsForSetOfTypes(((SetType) T).iteratePoints());
// addStatementsForSetOfTypes(((SetType) T).iteratePoints());
} else {
Assertions.UNREACHABLE("Unexpected type " + T.getClass());
}
@ -484,7 +481,7 @@ class FactoryBypassInterpreter extends AbstractReflectionInterpreter {
SSAInvokeInstruction s = insts.InvokeInstruction(params, exc, site);
calls.add(s);
allInstructions.add(s);
}
}
}
private int addOriginalStatements(SummarizedMethod m) {
@ -564,9 +561,8 @@ class FactoryBypassInterpreter extends AbstractReflectionInterpreter {
}
/**
* Two specialized methods can be different, even if they represent the same source method. So, revert to object
* identity for testing equality. TODO: this is non-optimal; could try to re-use specialized methods that have the
* same context.
* Two specialized methods can be different, even if they represent the same source method. So, revert to object identity for
* testing equality. TODO: this is non-optimal; could try to re-use specialized methods that have the same context.
*
* @see java.lang.Object#equals(java.lang.Object)
*/
@ -597,11 +593,7 @@ class FactoryBypassInterpreter extends AbstractReflectionInterpreter {
@Override
public IClass getDeclaringClass() {
if (Assertions.verifyAssertions) {
if (method.getDeclaringClass() == null) {
assert method.getDeclaringClass() != null : "null declaring class for original method " + method;
}
}
assert method.getDeclaringClass() != null : "null declaring class for original method " + method;
return method.getDeclaringClass();
}

View File

@ -33,12 +33,9 @@ import com.ibm.wala.ssa.SSAReturnInstruction;
import com.ibm.wala.types.FieldReference;
import com.ibm.wala.types.TypeReference;
import com.ibm.wala.util.collections.EmptyIterator;
import com.ibm.wala.util.debug.Assertions;
/**
* {@link SSAContextInterpreter} specialized to interpret Object.getClass() in a {@link JavaTypeContext}
*
* @author sjfink
*/
public class GetClassContextInterpeter implements SSAContextInterpreter {
@ -48,9 +45,7 @@ public class GetClassContextInterpeter implements SSAContextInterpreter {
if (node == null) {
throw new IllegalArgumentException("node is null");
}
if (Assertions.verifyAssertions) {
assert understands(node);
}
assert understands(node);
if (DEBUG) {
System.err.println("generating IR for " + node);
}
@ -59,9 +54,7 @@ public class GetClassContextInterpeter implements SSAContextInterpreter {
}
public int getNumberOfStatements(CGNode node) {
if (Assertions.verifyAssertions) {
assert understands(node);
}
assert understands(node);
return getIR(node).getInstructions().length;
}
@ -89,7 +82,7 @@ public class GetClassContextInterpeter implements SSAContextInterpreter {
int retValue = nextLocal++;
TypeReference tr = context.getType().getTypeReference();
SSAInstructionFactory insts = context.getType().getType().getClassLoader().getInstructionFactory();
if (tr != null) {
if (tr != null) {
SSALoadMetadataInstruction l = insts.LoadMetadataInstruction(retValue, TypeReference.JavaLangClass, tr);
statements.add(l);
SSAReturnInstruction R = insts.ReturnInstruction(retValue, false);

View File

@ -97,9 +97,7 @@ public class JavaLangClassContextInterpreter implements SSAContextInterpreter {
if (node == null) {
throw new IllegalArgumentException("node is null");
}
if (Assertions.verifyAssertions) {
assert understands(node);
}
assert understands(node);
if (DEBUG) {
System.err.println("generating IR for " + node);
}
@ -154,9 +152,7 @@ public class JavaLangClassContextInterpreter implements SSAContextInterpreter {
* @see com.ibm.wala.ipa.callgraph.propagation.SSAContextInterpreter#getNumberOfStatements(com.ibm.wala.ipa.callgraph.CGNode)
*/
public int getNumberOfStatements(CGNode node) {
if (Assertions.verifyAssertions) {
assert understands(node);
}
assert understands(node);
return getIR(node).getInstructions().length;
}
@ -180,9 +176,7 @@ public class JavaLangClassContextInterpreter implements SSAContextInterpreter {
if (node == null) {
throw new IllegalArgumentException("node is null");
}
if (Assertions.verifyAssertions) {
assert understands(node);
}
assert understands(node);
JavaTypeContext context = (JavaTypeContext) node.getContext();
TypeReference tr = context.getType().getTypeReference();
if (tr != null) {
@ -192,9 +186,7 @@ public class JavaLangClassContextInterpreter implements SSAContextInterpreter {
}
public Iterator<CallSiteReference> iterateCallSites(CGNode node) {
if (Assertions.verifyAssertions) {
assert understands(node);
}
assert understands(node);
return EmptyIterator.instance();
}

View File

@ -39,7 +39,6 @@ import com.ibm.wala.types.MethodReference;
import com.ibm.wala.types.TypeReference;
import com.ibm.wala.util.collections.EmptyIterator;
import com.ibm.wala.util.collections.HashMapFactory;
import com.ibm.wala.util.debug.Assertions;
/**
* An {@link SSAContextInterpreter} specialized to interpret reflective invocations such as Constructor.newInstance and
@ -60,9 +59,7 @@ public class ReflectiveInvocationInterpreter extends AbstractReflectionInterpret
if (node == null) {
throw new IllegalArgumentException("node is null");
}
if (Assertions.verifyAssertions) {
assert understands(node);
}
assert understands(node);
if (DEBUG) {
System.err.println("generating IR for " + node);
}
@ -77,9 +74,7 @@ public class ReflectiveInvocationInterpreter extends AbstractReflectionInterpret
* @see com.ibm.wala.ipa.callgraph.propagation.SSAContextInterpreter#getNumberOfStatements(com.ibm.wala.ipa.callgraph.CGNode)
*/
public int getNumberOfStatements(CGNode node) {
if (Assertions.verifyAssertions) {
assert understands(node);
}
assert understands(node);
return getIR(node).getInstructions().length;
}
@ -107,9 +102,7 @@ public class ReflectiveInvocationInterpreter extends AbstractReflectionInterpret
if (node == null) {
throw new IllegalArgumentException("node is null");
}
if (Assertions.verifyAssertions) {
assert understands(node);
}
assert understands(node);
return getIR(node).iterateNewSites();
}
@ -117,9 +110,7 @@ public class ReflectiveInvocationInterpreter extends AbstractReflectionInterpret
* @see com.ibm.wala.ipa.callgraph.propagation.rta.RTAContextInterpreter#iterateCallSites(com.ibm.wala.ipa.callgraph.CGNode)
*/
public Iterator<CallSiteReference> iterateCallSites(CGNode node) {
if (Assertions.verifyAssertions) {
assert understands(node);
}
assert understands(node);
return getIR(node).iterateCallSites();
}
@ -131,7 +122,7 @@ public class ReflectiveInvocationInterpreter extends AbstractReflectionInterpret
*/
private IR makeIR(IMethod method, IMethod target, ReceiverInstanceContext context) {
SSAInstructionFactory insts = method.getDeclaringClass().getClassLoader().getInstructionFactory();
SpecializedMethod m = new SpecializedMethod(method, method.getDeclaringClass(), method.isStatic(), false);
Map<Integer, ConstantValue> constants = HashMapFactory.make();
@ -145,8 +136,9 @@ public class ReflectiveInvocationInterpreter extends AbstractReflectionInterpret
if (method.getReference().equals(CTOR_NEW_INSTANCE)) {
// allocate the new object constructed
TypeReference allocatedType = target.getDeclaringClass().getReference();
m.addInstruction(allocatedType, insts.NewInstruction(args[0] = nextLocal++, NewSiteReference.make(pc++, allocatedType)),
true);
m
.addInstruction(allocatedType, insts.NewInstruction(args[0] = nextLocal++, NewSiteReference.make(pc++, allocatedType)),
true);
parametersVn = 2;
} else {
// for Method.invoke, v3 is the parameter to the method being called
@ -164,16 +156,16 @@ public class ReflectiveInvocationInterpreter extends AbstractReflectionInterpret
}
int nextArg = target.isStatic() ? 0 : 1; // nextArg := next index in args[] array that needs to be initialized
int nextParameter = 0; // nextParameter := next index in the parameters[] array that needs to be copied into the args[] array.
// load each of the parameters into a local variable, args[something]
for (int j = nextArg; j < nargs; j++) {
// load the next parameter into v_temp.
// load the next parameter into v_temp.
int indexConst = nextLocal++;
constants.put(new Integer(indexConst), new ConstantValue(nextParameter++));
constants.put(new Integer(indexConst), new ConstantValue(nextParameter++));
int temp = nextLocal++;
m.addInstruction(null, insts.ArrayLoadInstruction(temp, parametersVn, indexConst, TypeReference.JavaLangObject), false);
pc++;
// cast v_temp to the appropriate type and store it in args[j]
args[j] = nextLocal++;
TypeReference type = target.getParameterType(j);
@ -198,8 +190,8 @@ public class ReflectiveInvocationInterpreter extends AbstractReflectionInterpret
false);
} else {
result = nextLocal++;
m.addInstruction(null, insts.InvokeInstruction(result, args, exceptions, CallSiteReference.make(pc++, target
.getReference(), d)), false);
m.addInstruction(null, insts.InvokeInstruction(result, args, exceptions, CallSiteReference.make(pc++,
target.getReference(), d)), false);
m.addInstruction(null, insts.ReturnInstruction(result, false), false);
}
}

View File

@ -54,7 +54,6 @@ import com.ibm.wala.shrikeBT.ThrowInstruction;
import com.ibm.wala.shrikeBT.Util;
import com.ibm.wala.types.ClassLoaderReference;
import com.ibm.wala.types.TypeReference;
import com.ibm.wala.util.debug.Assertions;
import com.ibm.wala.util.shrike.ShrikeUtil;
/**
@ -200,9 +199,7 @@ public abstract class AbstractIntStackMachine implements FixedPointConstants {
@Override
protected MachineState makeNodeVariable(BasicBlock n, boolean IN) {
if (Assertions.verifyAssertions) {
assert n != null;
}
assert n != null;
MachineState result = new MachineState(n);
if (IN && n.equals(cfg.entry())) {
entry = result;
@ -212,10 +209,8 @@ public abstract class AbstractIntStackMachine implements FixedPointConstants {
@Override
protected MachineState makeEdgeVariable(BasicBlock from, BasicBlock to) {
if (Assertions.verifyAssertions) {
assert from != null;
assert to != null;
}
assert from != null;
assert to != null;
MachineState result = new MachineState(from);
return result;
@ -224,7 +219,7 @@ public abstract class AbstractIntStackMachine implements FixedPointConstants {
@Override
protected void initializeWorkList() {
super.buildEquations(false, false);
/**
/*
* Add only the entry variable to the work list.
*/
for (Iterator it = getFixedPointSystem().getStatementsThatUse(entry); it.hasNext();) {
@ -590,10 +585,8 @@ public abstract class AbstractIntStackMachine implements FixedPointConstants {
}
public int pop() {
if (Assertions.verifyAssertions) {
if (stackHeight <= 0) {
assert stackHeight > 0 : "can't pop stack of height " + stackHeight;
}
if (stackHeight <= 0) {
assert stackHeight > 0 : "can't pop stack of height " + stackHeight;
}
stackHeight -= 1;
return stack[stackHeight];
@ -989,10 +982,8 @@ public abstract class AbstractIntStackMachine implements FixedPointConstants {
int size = instruction.getSize();
int delta = instruction.getDelta();
if (Assertions.verifyAssertions) {
assert size == 1 || size == 2;
assert delta == 0 || delta == 1 || delta == 2;
}
assert size == 1 || size == 2;
assert delta == 0 || delta == 1 || delta == 2;
int toPop = size + delta;
int v1 = workingState.pop();
int v2 = (toPop > 1) ? workingState.pop() : IGNORE;

View File

@ -19,7 +19,7 @@ import com.ibm.wala.util.debug.Assertions;
/**
*
* Represents a type and its subtypes.
* Represents a type and its subtypes.
*
* @author sfink
*/
@ -30,16 +30,13 @@ public class ConeType extends TypeAbstraction {
/**
* default constructor
*
* @throws IllegalArgumentException
* if type is null
* @throws IllegalArgumentException if type is null
*/
public ConeType(IClass type) {
if (type == null) {
throw new IllegalArgumentException("type is null");
}
if (Assertions.verifyAssertions) {
assert type.getReference().isReferenceType();
}
assert type.getReference().isReferenceType();
this.type = type;
}
@ -90,9 +87,6 @@ public class ConeType extends TypeAbstraction {
return type.getReference();
}
/**
* @see java.lang.Object#equals(Object)
*/
@Override
public boolean equals(Object obj) {
if (!(obj instanceof ConeType)) {
@ -102,10 +96,8 @@ public class ConeType extends TypeAbstraction {
if (other == TOP) {
return false;
}
if (Assertions.verifyAssertions) {
if (!type.getClassHierarchy().equals(other.type.getClassHierarchy())) {
Assertions.UNREACHABLE("different chas " + this + " " + other);
}
if (!type.getClassHierarchy().equals(other.type.getClassHierarchy())) {
Assertions.UNREACHABLE("different chas " + this + " " + other);
}
return type.equals(other.type);
}

View File

@ -15,10 +15,7 @@ import com.ibm.wala.types.TypeReference;
import com.ibm.wala.util.debug.Assertions;
/**
*
* Represents a single concrete type.
*
* @author sfink
*/
public class PointType extends TypeAbstraction {
@ -27,17 +24,14 @@ public class PointType extends TypeAbstraction {
/**
* Private constructor ... only for internal use.
*
* @throws IllegalArgumentException
* if type is null
* @throws IllegalArgumentException if type is null
*/
public PointType(IClass type) {
if (type == null) {
throw new IllegalArgumentException("type is null");
}
this.type = type;
if (Assertions.verifyAssertions) {
assert type.getReference().isReferenceType();
}
assert type.getReference().isReferenceType();
}
@Override
@ -112,10 +106,8 @@ public class PointType extends TypeAbstraction {
return false;
}
PointType other = (PointType) obj;
if (Assertions.verifyAssertions) {
if (!type.getClassHierarchy().equals(other.type.getClassHierarchy())) {
Assertions.UNREACHABLE("different chas " + this + " " + other);
}
if (!type.getClassHierarchy().equals(other.type.getClassHierarchy())) {
Assertions.UNREACHABLE("different chas " + this + " " + other);
}
return type.equals(other.type);
}

View File

@ -176,13 +176,11 @@ public class TypeInference extends SSAInference<TypeVariable> implements FixedPo
if (s instanceof SSAAbstractInvokeInstruction) {
SSAAbstractInvokeInstruction call = (SSAAbstractInvokeInstruction) s;
TypeVariable v = getVariable(call.getException());
Collection<TypeReference> defaultExceptions = call.getExceptionTypes();
Collection<TypeReference> defaultExceptions = call.getExceptionTypes();
if (defaultExceptions.size() == 0) {
continue;
}
if (Assertions.verifyAssertions) {
assert defaultExceptions.size() == 1;
}
assert defaultExceptions.size() == 1;
// t should be NullPointerException
TypeReference t = defaultExceptions.iterator().next();
IClass klass = cha.lookupClass(t);
@ -448,9 +446,7 @@ public class TypeInference extends SSAInference<TypeVariable> implements FixedPo
return NOT_CHANGED;
} else {
IClass klass = cha.lookupClass(elementType);
if (Assertions.verifyAssertions) {
assert klass != null;
}
assert klass != null;
lhs.setType(new ConeType(klass));
return CHANGED;
}
@ -515,9 +511,7 @@ public class TypeInference extends SSAInference<TypeVariable> implements FixedPo
@Override
public void visitLoadMetadata(SSALoadMetadataInstruction instruction) {
IClass jlClassKlass = cha.lookupClass(TypeReference.JavaLangClass);
if (Assertions.verifyAssertions) {
assert jlClassKlass != null;
}
assert jlClassKlass != null;
result = new DeclaredTypeOperator(new ConeType(jlClassKlass));
}
@ -689,11 +683,7 @@ public class TypeInference extends SSAInference<TypeVariable> implements FixedPo
if (valueNumber < 0) {
throw new IllegalArgumentException("bad value number " + valueNumber);
}
if (Assertions.verifyAssertions) {
if (getVariable(valueNumber) == null) {
assert getVariable(valueNumber) != null : "null variable for value number " + valueNumber;
}
}
assert getVariable(valueNumber) != null : "null variable for value number " + valueNumber;
return getVariable(valueNumber).getType();
}
@ -733,17 +723,18 @@ public class TypeInference extends SSAInference<TypeVariable> implements FixedPo
/**
* Extract all results of the type inference analysis.
* @return an array, where the i'th variable holds the type abstraction of the i'th value number.
*
* @return an array, where the i'th variable holds the type abstraction of the i'th value number.
*/
public TypeAbstraction[] extractAllResults(){
public TypeAbstraction[] extractAllResults() {
int numberOfVars = ir.getSymbolTable().getMaxValueNumber() + 1;
TypeAbstraction[] ret = new TypeAbstraction[numberOfVars];
for (int i = 0 ; i < numberOfVars ; ++i){
for (int i = 0; i < numberOfVars; ++i) {
TypeVariable var = getVariable(i);
ret[i] = var == null ? null : var.getType();
}
return ret;
}
}

View File

@ -160,9 +160,7 @@ public abstract class AbstractCFG<I, T extends IBasicBlock<I>> implements Contro
if (N == null) {
throw new IllegalArgumentException("N is null");
}
if (Assertions.verifyAssertions) {
assert !N.equals(exit());
}
assert !N.equals(exit());
int number = getNumber(N);
int xtra = 0;
if (number > 0) {
@ -177,9 +175,7 @@ public abstract class AbstractCFG<I, T extends IBasicBlock<I>> implements Contro
if (N == null) {
throw new IllegalArgumentException("N is null");
}
if (Assertions.verifyAssertions) {
assert !N.equals(exit());
}
assert !N.equals(exit());
return exceptionalEdgeManager.getPredNodeCount(N);
}

View File

@ -15,7 +15,6 @@ import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import com.ibm.wala.ipa.cha.ClassHierarchyException;
import com.ibm.wala.ipa.cha.IClassHierarchy;
import com.ibm.wala.shrikeBT.Constants;
import com.ibm.wala.types.ClassLoaderReference;
@ -44,18 +43,14 @@ public class ArrayClass implements IClass, Constants {
this.type = type;
this.loader = loader;
this.cha = cha;
if (Assertions.verifyAssertions) {
TypeReference elementType = type.getInnermostElementType();
if (!elementType.isPrimitiveType()) {
IClass klass = loader.lookupClass(elementType.getName());
if (klass == null) {
Assertions.UNREACHABLE("caller should not attempt to create an array with type " + type);
}
} else {
if (Assertions.verifyAssertions) {
assert loader.getReference().equals(ClassLoaderReference.Primordial);
}
TypeReference elementType = type.getInnermostElementType();
if (!elementType.isPrimitiveType()) {
IClass klass = loader.lookupClass(elementType.getName());
if (klass == null) {
Assertions.UNREACHABLE("caller should not attempt to create an array with type " + type);
}
} else {
assert loader.getReference().equals(ClassLoaderReference.Primordial);
}
}
@ -107,10 +102,7 @@ public class ArrayClass implements IClass, Constants {
*/
public IClass getSuperclass() {
IClass elt = getElementClass();
if (Assertions.verifyAssertions) {
assert getReference().getArrayElementType().isPrimitiveType() || elt != null;
}
assert getReference().getArrayElementType().isPrimitiveType() || elt != null;
// super is Ljava/lang/Object in two cases:
// 1) [Ljava/lang/Object
@ -279,7 +271,7 @@ public class ArrayClass implements IClass, Constants {
/*
* @see com.ibm.wala.classLoader.IClass#getAllInstanceFields()
*/
public Collection<IField> getAllInstanceFields() {
public Collection<IField> getAllInstanceFields() {
Assertions.UNREACHABLE();
return null;
}
@ -302,7 +294,7 @@ public class ArrayClass implements IClass, Constants {
/*
* @see com.ibm.wala.classLoader.IClass#getAllFields()
*/
public Collection<IField> getAllFields() {
public Collection<IField> getAllFields() {
Assertions.UNREACHABLE();
return null;
}

View File

@ -31,7 +31,6 @@ import com.ibm.wala.util.collections.HashCodeComparator;
import com.ibm.wala.util.collections.HashMapFactory;
import com.ibm.wala.util.collections.HashSetFactory;
import com.ibm.wala.util.collections.Iterator2Collection;
import com.ibm.wala.util.debug.Assertions;
import com.ibm.wala.util.shrike.ShrikeClassReaderHandle;
import com.ibm.wala.util.strings.Atom;
import com.ibm.wala.util.warnings.Warning;
@ -89,7 +88,7 @@ public class ClassLoaderImpl implements IClassLoader {
if (loader == null) {
throw new IllegalArgumentException("null loader");
}
this.arrayClassLoader = arrayClassLoader;
this.parent = parent;
this.loader = loader;
@ -194,9 +193,7 @@ public class ClassLoaderImpl implements IClassLoader {
* Return a Set of IClasses, which represents all classes this class loader can load.
*/
private Collection<IClass> getAllClasses() {
if (Assertions.verifyAssertions) {
assert loadedClasses != null;
}
assert loadedClasses != null;
return loadedClasses.values();
}
@ -234,12 +231,12 @@ public class ClassLoaderImpl implements IClassLoader {
TypeName T = TypeName.string2TypeName(className);
if (loadedClasses.get(T) != null) {
Warnings.add(MultipleImplementationsWarning.create(className));
} else if (parent != null && parent.lookupClass(T) != null) {
} else if (parent != null && parent.lookupClass(T) != null) {
Warnings.add(MultipleImplementationsWarning.create(className));
} else {
ShrikeClass klass = new ShrikeClass(reader, this, cha);
if (klass.getReference().getName().equals(T)) {
loadedClasses.put(T, klass); // new ShrikeClass(reader, this, cha));
loadedClasses.put(T, klass); // new ShrikeClass(reader, this, cha));
if (DEBUG_LEVEL > 1) {
System.err.println("put " + T + " ");
}
@ -438,7 +435,7 @@ public class ClassLoaderImpl implements IClassLoader {
ModuleEntry e = sourceMap.get(klass.getName());
return e == null ? null : e.getName();
}
public InputStream getSource(IClass klass) {
if (klass == null) {
throw new IllegalArgumentException("klass is null");

View File

@ -98,17 +98,14 @@ public abstract class ShrikeBTMethod implements IMethod, BytecodeConstants {
private int[] pcMap;
/**
* Cached map representing line number information in ShrikeCT format TODO:
* do more careful caching than just soft references
* Cached map representing line number information in ShrikeCT format TODO: do more careful caching than just soft references
*/
protected int[] lineNumberMap;
/**
* an array mapping bytecode offsets to arrays representing the local
* variable maps for each offset; a local variable map is represented as an
* array of localVars*2 elements, containing a pair (nameIndex, typeIndex)
* for each local variable; a pair (0,0) indicates there is no information
* for that local variable at that offset
* an array mapping bytecode offsets to arrays representing the local variable maps for each offset; a local variable map is
* represented as an array of localVars*2 elements, containing a pair (nameIndex, typeIndex) for each local variable; a pair
* (0,0) indicates there is no information for that local variable at that offset
*/
protected int[][] localVariableMap;
@ -140,8 +137,7 @@ public abstract class ShrikeBTMethod implements IMethod, BytecodeConstants {
}
/**
* Return the program counter (bytecode index) for a particular Shrike
* instruction index.
* Return the program counter (bytecode index) for a particular Shrike instruction index.
*
* @throws InvalidClassFileException
*/
@ -157,6 +153,7 @@ public abstract class ShrikeBTMethod implements IMethod, BytecodeConstants {
public int getNumShrikeInstructions() throws InvalidClassFileException {
return getBCInfo().pcMap.length;
}
/**
* @throws InvalidClassFileException
*/
@ -181,8 +178,7 @@ public abstract class ShrikeBTMethod implements IMethod, BytecodeConstants {
}
/**
* @return Set <TypeReference>, the exceptions that statements in this method
* may throw,
* @return Set <TypeReference>, the exceptions that statements in this method may throw,
* @throws InvalidClassFileException
*/
public Collection<TypeReference> getImplicitExceptionTypes() throws InvalidClassFileException {
@ -194,8 +190,8 @@ public abstract class ShrikeBTMethod implements IMethod, BytecodeConstants {
}
/**
* Do a cheap pass over the bytecodes to collect some mapping information.
* Some methods require this as a pre-req to accessing ShrikeCT information.
* Do a cheap pass over the bytecodes to collect some mapping information. Some methods require this as a pre-req to accessing
* ShrikeCT information.
*
* @throws InvalidClassFileException
*/
@ -407,10 +403,8 @@ public abstract class ShrikeBTMethod implements IMethod, BytecodeConstants {
private void processBytecodesWithShrikeBT(BytecodeInfo info) throws InvalidClassFileException {
info.decoder = makeDecoder();
if (Assertions.verifyAssertions) {
if (!isAbstract() && info.decoder == null) {
Assertions.UNREACHABLE("bad method " + getReference());
}
if (!isAbstract() && info.decoder == null) {
Assertions.UNREACHABLE("bad method " + getReference());
}
if (info.decoder == null) {
return;
@ -421,7 +415,7 @@ public abstract class ShrikeBTMethod implements IMethod, BytecodeConstants {
SimpleVisitor simpleVisitor = new SimpleVisitor(info);
BytecodeLanguage lang = (BytecodeLanguage)getDeclaringClass().getClassLoader().getLanguage();
BytecodeLanguage lang = (BytecodeLanguage) getDeclaringClass().getClassLoader().getLanguage();
IInstruction[] instructions = info.decoder.getInstructions();
for (int i = 0; i < instructions.length; i++) {
simpleVisitor.setInstructionIndex(i);
@ -622,8 +616,8 @@ public abstract class ShrikeBTMethod implements IMethod, BytecodeConstants {
@Override
public void visitInvoke(IInvokeInstruction instruction) {
IClassLoader loader = getDeclaringClass().getClassLoader();
MethodReference m = MethodReference.findOrCreate(loader.getLanguage(), loader.getReference(), instruction.getClassType(), instruction.getMethodName(), instruction
.getMethodSignature());
MethodReference m = MethodReference.findOrCreate(loader.getLanguage(), loader.getReference(), instruction.getClassType(),
instruction.getMethodName(), instruction.getMethodSignature());
int programCounter = 0;
try {
programCounter = getProgramCounter();
@ -678,8 +672,7 @@ public abstract class ShrikeBTMethod implements IMethod, BytecodeConstants {
}
/**
* By convention, for a non-static method, getParameterType(0) is the this
* pointer
* By convention, for a non-static method, getParameterType(0) is the this pointer
*/
public TypeReference getParameterType(int i) {
if (!isStatic()) {
@ -694,8 +687,7 @@ public abstract class ShrikeBTMethod implements IMethod, BytecodeConstants {
}
/**
* Method getNumberOfParameters. This result includes the "this" pointer if
* applicable
* Method getNumberOfParameters. This result includes the "this" pointer if applicable
*
* @return int
*/
@ -713,8 +705,7 @@ public abstract class ShrikeBTMethod implements IMethod, BytecodeConstants {
public abstract boolean hasExceptionHandler();
/**
* Clients should not modify the returned array. TODO: clone to avoid the
* problem?
* Clients should not modify the returned array. TODO: clone to avoid the problem?
*
* @throws InvalidClassFileException
*

View File

@ -45,9 +45,8 @@ import com.ibm.wala.util.io.FileProvider;
*
* Abstract base class for analysis engine implementations
*
* Some clients choose to build on this, but many don't. I usually don't in new
* code; I usually don't find the re-use enabled by this class compelling. I
* would probably nuke this except for some legacy code that uses it.
* Some clients choose to build on this, but many don't. I usually don't in new code; I usually don't find the re-use enabled by
* this class compelling. I would probably nuke this except for some legacy code that uses it.
*
* @author sfink
*/
@ -70,8 +69,7 @@ public abstract class AbstractAnalysisEngine implements AnalysisEngine {
protected static final int DEBUG_LEVEL = 1;
/**
* Name of the file which holds the class hierarchy exclusions directives for
* this analysis.
* Name of the file which holds the class hierarchy exclusions directives for this analysis.
*/
private String exclusionsFile = "J2SEClassHierarchyExclusions.txt";
@ -89,7 +87,7 @@ public abstract class AbstractAnalysisEngine implements AnalysisEngine {
* A representation of the analysis options
*/
private AnalysisOptions options;
/**
* A cache of IRs and stuff
*/
@ -120,7 +118,6 @@ public abstract class AbstractAnalysisEngine implements AnalysisEngine {
*/
protected PointerAnalysis pointerAnalysis;
/**
* Graph view of flow of pointers between heap abstractions
*/
@ -134,7 +131,8 @@ public abstract class AbstractAnalysisEngine implements AnalysisEngine {
protected abstract CallGraphBuilder getCallGraphBuilder(IClassHierarchy cha, AnalysisOptions options, AnalysisCache cache);
protected CallGraphBuilder buildCallGraph(IClassHierarchy cha, AnalysisOptions options, boolean savePointerAnalysis, IProgressMonitor monitor) throws IllegalArgumentException, CancelException {
protected CallGraphBuilder buildCallGraph(IClassHierarchy cha, AnalysisOptions options, boolean savePointerAnalysis,
IProgressMonitor monitor) throws IllegalArgumentException, CancelException {
CallGraphBuilder builder = getCallGraphBuilder(cha, options, cache);
cg = builder.makeCallGraph(options, monitor);
@ -152,14 +150,16 @@ public abstract class AbstractAnalysisEngine implements AnalysisEngine {
/**
* Set up the AnalysisScope object
* @throws IOException
*
* @throws IOException
*/
protected void buildAnalysisScope() throws IOException {
if (j2seLibs == null) {
Assertions.UNREACHABLE("no j2selibs specified. You probably did not call AppAnalysisEngine.setJ2SELibrary.");
}
scope = AnalysisScopeReader.readJavaScope(SYNTHETIC_J2SE_MODEL, FileProvider.getFile(getExclusionsFile()), getClass().getClassLoader());
scope = AnalysisScopeReader.readJavaScope(SYNTHETIC_J2SE_MODEL, FileProvider.getFile(getExclusionsFile()), getClass()
.getClassLoader());
// add standard libraries
for (int i = 0; i < j2seLibs.length; i++) {
@ -175,7 +175,7 @@ public abstract class AbstractAnalysisEngine implements AnalysisEngine {
*/
public IClassHierarchy buildClassHierarchy() {
IClassHierarchy cha = null;
ClassLoaderFactory factory = new ClassLoaderFactoryImpl(getScope().getExclusions() );
ClassLoaderFactory factory = new ClassLoaderFactoryImpl(getScope().getExclusions());
try {
cha = ClassHierarchy.make(getScope(), factory);
} catch (ClassHierarchyException e) {
@ -208,10 +208,8 @@ public abstract class AbstractAnalysisEngine implements AnalysisEngine {
ClassLoaderReference app = scope.getApplicationLoader();
for (Iterator it = moduleFiles.iterator(); it.hasNext();) {
Object o = it.next();
if (Assertions.verifyAssertions) {
if (!(o instanceof Module)) {
Assertions.UNREACHABLE("Unexpected type: " + o.getClass());
}
if (!(o instanceof Module)) {
Assertions.UNREACHABLE("Unexpected type: " + o.getClass());
}
Module M = (Module) o;
scope.addToScope(app, M);
@ -253,7 +251,7 @@ public abstract class AbstractAnalysisEngine implements AnalysisEngine {
public PointerAnalysis getPointerAnalysis() {
return pointerAnalysis;
}
public HeapGraph getHeapGraph() {
if (heapGraph == null) {
heapGraph = new BasicHeapGraph(getPointerAnalysis(), cg);
@ -272,7 +270,7 @@ public abstract class AbstractAnalysisEngine implements AnalysisEngine {
public AnalysisOptions getDefaultOptions(Iterable<Entrypoint> entrypoints) {
return new AnalysisOptions(getScope(), entrypoints);
}
public AnalysisCache makeDefaultCache() {
return new AnalysisCache(new DefaultIRFactory());
}
@ -286,11 +284,11 @@ public abstract class AbstractAnalysisEngine implements AnalysisEngine {
}
/**
* Builds the call graph for the analysis scope in effect, using all of the
* given entry points.
* @throws CancelException
* @throws IllegalArgumentException
* @throws IOException
* Builds the call graph for the analysis scope in effect, using all of the given entry points.
*
* @throws CancelException
* @throws IllegalArgumentException
* @throws IOException
*/
public CallGraphBuilder defaultCallGraphBuilder() throws IllegalArgumentException, CancelException, IOException {
buildAnalysisScope();

View File

@ -32,7 +32,6 @@ import com.ibm.wala.util.collections.Heap;
import com.ibm.wala.util.collections.Iterator2Collection;
import com.ibm.wala.util.collections.MapUtil;
import com.ibm.wala.util.collections.ToStringComparator;
import com.ibm.wala.util.debug.Assertions;
import com.ibm.wala.util.heapTrace.HeapTracer;
import com.ibm.wala.util.intset.IntIterator;
import com.ibm.wala.util.intset.IntSet;
@ -598,7 +597,7 @@ public class TabulationSolver<T, P, F> {
final T exit = exits[e];
// if "exit" is a valid exit from the callee to the return
// site being processed
if (DEBUG_LEVEL > 0 && Assertions.verifyAssertions) {
if (DEBUG_LEVEL > 0) {
assert supergraph.containsNode(exit);
}
int x_num = supergraph.getLocalBlockNumber(exit);
@ -639,7 +638,7 @@ public class TabulationSolver<T, P, F> {
}
}
}
}
}
}
});
}
@ -684,10 +683,8 @@ public class TabulationSolver<T, P, F> {
if (reached != null) {
reached.foreach(new IntSetAction() {
public void act(int x) {
if (Assertions.verifyAssertions) {
assert x >= 0;
assert edge.d1 >= 0;
}
assert x >= 0;
assert edge.d1 >= 0;
propagate(edge.entry, edge.d1, returnSite, x);
}
});
@ -766,19 +763,15 @@ public class TabulationSolver<T, P, F> {
*/
protected boolean propagate(T s_p, int i, T n, int j) {
int number = supergraph.getLocalBlockNumber(n);
if (Assertions.verifyAssertions) {
if (number < 0) {
System.err.println("BOOM " + n);
supergraph.getLocalBlockNumber(n);
}
assert number >= 0;
if (number < 0) {
System.err.println("BOOM " + n);
supergraph.getLocalBlockNumber(n);
}
assert number >= 0;
LocalPathEdges pLocal = findOrCreateLocalPathEdges(s_p);
if (Assertions.verifyAssertions) {
assert j >= 0;
}
assert j >= 0;
if (!pLocal.contains(i, number, j)) {
if (DEBUG_LEVEL > 0) {
@ -804,9 +797,7 @@ public class TabulationSolver<T, P, F> {
* return -1 if no fact should be propagated
*/
private int merge(T s_p, int i, T n, int j) {
if (Assertions.verifyAssertions) {
assert j >= 0;
}
assert j >= 0;
IMergeFunction alpha = problem.getMergeFunction();
if (alpha != null) {
LocalPathEdges lp = pathEdges.get(s_p);

View File

@ -21,7 +21,6 @@ import com.ibm.wala.fixpoint.IVariable;
import com.ibm.wala.ssa.IR;
import com.ibm.wala.ssa.SSAInstruction;
import com.ibm.wala.ssa.SymbolTable;
import com.ibm.wala.util.debug.Assertions;
/**
* This class performs intra-procedural propagation over an SSA form.
@ -117,9 +116,7 @@ public abstract class SSAInference<T extends IVariable> extends DefaultFixedPoin
for (int j = 0; j < n; j++) {
if (s.getUse(j) > -1) {
uses[j] = getVariable(s.getUse(j));
if (Assertions.verifyAssertions) {
assert uses[j] != null;
}
assert uses[j] != null;
}
}
newStatement(def, op, uses, false, false);
@ -140,7 +137,6 @@ public abstract class SSAInference<T extends IVariable> extends DefaultFixedPoin
}
/**
* @param valueNumber
* @return the dataflow variable representing the value number, or null if none found.
*/
@SuppressWarnings("unchecked")
@ -151,11 +147,7 @@ public abstract class SSAInference<T extends IVariable> extends DefaultFixedPoin
if (DEBUG) {
System.err.println(("getVariable for " + valueNumber + " returns " + vars[valueNumber]));
}
if (Assertions.verifyAssertions) {
if (vars == null) {
assert vars != null : "null vars array";
}
}
assert vars != null : "null vars array";
return (T) vars[valueNumber];
}

View File

@ -226,8 +226,8 @@ public class DemandRefinementPointsTo extends AbstractDemandPointsTo {
*/
SUCCESS,
/**
* The {@link RefinementPolicy} indicated that no more refinement was possible, <em>and</em> on at least one refinement pass
* the budget was not exhausted
* The {@link RefinementPolicy} indicated that no more refinement was possible, <em>and</em> on at least one refinement pass the
* budget was not exhausted
*/
NOMOREREFINE,
/**
@ -774,9 +774,7 @@ public class DemandRefinementPointsTo extends AbstractDemandPointsTo {
}
void handleCopy(final PointerKeyAndState curPkAndState, final PointerKey succPk, final IFlowLabel label) {
if (Assertions.verifyAssertions) {
assert !label.isBarred();
}
assert !label.isBarred();
State curState = curPkAndState.getState();
doTransition(curState, label, new Function<State, Object>() {
@ -806,18 +804,13 @@ public class DemandRefinementPointsTo extends AbstractDemandPointsTo {
}
/**
*
* @param curPkAndState
* @param predPk
* @param label the label of the edge from curPk to predPk (must be barred)
* @return those {@link PointerKeyAndState}s whose points-to sets have been queried, such that the {@link PointerKey} is
* predPk, and transitioning from its state on <code>label.bar()</code> yields the state of <code>curPkAndState</code>
* @return those {@link PointerKeyAndState}s whose points-to sets have been queried, such that the {@link PointerKey} is predPk,
* and transitioning from its state on <code>label.bar()</code> yields the state of <code>curPkAndState</code>
*/
Collection<PointerKeyAndState> matchingPToQueried(PointerKeyAndState curPkAndState, PointerKey predPk, IFlowLabel label) {
Collection<PointerKeyAndState> ret = ArraySet.make();
if (Assertions.verifyAssertions) {
assert label.isBarred();
}
assert label.isBarred();
IFlowLabel unbarredLabel = label.bar();
final State curState = curPkAndState.getState();
Set<State> predPkStates = pointsToQueried.get(predPk);
@ -833,9 +826,7 @@ public class DemandRefinementPointsTo extends AbstractDemandPointsTo {
Collection<PointerKeyAndState> matchingTrackedQueried(PointerKeyAndState curPkAndState, PointerKey succPk, IFlowLabel label) {
Collection<PointerKeyAndState> ret = ArraySet.make();
if (Assertions.verifyAssertions) {
assert label.isBarred();
}
assert label.isBarred();
final State curState = curPkAndState.getState();
Set<State> succPkStates = trackedQueried.get(succPk);
for (State succState : succPkStates) {
@ -877,11 +868,9 @@ public class DemandRefinementPointsTo extends AbstractDemandPointsTo {
boolean addToInitWorklist(PointerKeyAndState pkAndState) {
if (pointsToQueried.put(pkAndState.getPointerKey(), pkAndState.getState())) {
if (Assertions.verifyAssertions && pkAndState.getPointerKey() instanceof LocalPointerKey) {
CGNode node = ((LocalPointerKey) pkAndState.getPointerKey()).getNode();
if (!g.hasSubgraphForNode(node)) {
assert false : "missing constraints for node of var " + pkAndState;
}
CGNode node = ((LocalPointerKey) pkAndState.getPointerKey()).getNode();
if (!g.hasSubgraphForNode(node)) {
assert false : "missing constraints for node of var " + pkAndState;
}
if (DEBUG) {
// System.err.println("adding to init_ " + pkAndState);
@ -896,7 +885,7 @@ public class DemandRefinementPointsTo extends AbstractDemandPointsTo {
}
protected void addToTrackedPToWorklist(PointerKeyAndState pkAndState) {
if (Assertions.verifyAssertions && pkAndState.getPointerKey() instanceof LocalPointerKey) {
if (pkAndState.getPointerKey() instanceof LocalPointerKey) {
CGNode node = ((LocalPointerKey) pkAndState.getPointerKey()).getNode();
if (!g.hasSubgraphForNode(node)) {
assert false : "missing constraints for " + node;
@ -1028,7 +1017,7 @@ public class DemandRefinementPointsTo extends AbstractDemandPointsTo {
final State curState = curPkAndState.getState();
if (DEBUG)
System.err.println("init " + curPkAndState);
if (Assertions.verifyAssertions && curPk instanceof LocalPointerKey) {
if (curPk instanceof LocalPointerKey) {
assert g.hasSubgraphForNode(((LocalPointerKey) curPk).getNode());
}
// if (curPk instanceof LocalPointerKey) {
@ -1141,10 +1130,8 @@ public class DemandRefinementPointsTo extends AbstractDemandPointsTo {
for (int i = 0; i < callInstrs.length; i++) {
SSAAbstractInvokeInstruction callInstr = callInstrs[i];
PointerKey actualPk = heapModel.getPointerKeyForLocal(caller, callInstr.getUse(paramPos));
if (Assertions.verifyAssertions) {
assert g.containsNode(actualPk);
assert g.containsNode(localPk);
}
assert g.containsNode(actualPk);
assert g.containsNode(localPk);
handler.handle(curPkAndState, actualPk, paramLabel);
}
}
@ -1201,9 +1188,7 @@ public class DemandRefinementPointsTo extends AbstractDemandPointsTo {
g.addSubgraphForNode(callee);
PointerKey retVal = isExceptional ? heapModel.getPointerKeyForExceptionalReturnValue(callee) : heapModel
.getPointerKeyForReturnValue(callee);
if (Assertions.verifyAssertions) {
assert g.containsNode(retVal);
}
assert g.containsNode(retVal);
handler.handle(curPkAndState, retVal, ReturnLabel.make(callSiteAndCGNode));
}
} else {
@ -1219,9 +1204,7 @@ public class DemandRefinementPointsTo extends AbstractDemandPointsTo {
g.addSubgraphForNode(callee);
PointerKey retVal = isExceptional ? heapModel.getPointerKeyForExceptionalReturnValue(callee) : heapModel
.getPointerKeyForReturnValue(callee);
if (Assertions.verifyAssertions) {
assert g.containsNode(retVal);
}
assert g.containsNode(retVal);
handler.handle(curPkAndState, retVal, ReturnLabel.make(callSiteAndCGNode));
}
}
@ -1243,9 +1226,6 @@ public class DemandRefinementPointsTo extends AbstractDemandPointsTo {
* @param ikToFields either {@link #forwInstKeyToFields} or {@link #backInstKeyToFields}
*/
private void trackInstanceField(InstanceKeyAndState ikAndState, IField field, MultiMap<InstanceKeyAndState, IField> ikToFields) {
if (Assertions.verifyAssertions) {
// Assertions._assert(refineFieldAccesses(field));
}
ikToFields.put(ikAndState, field);
addPredsOfIKeyAndStateToTrackedPointsTo(ikAndState);
}
@ -1255,9 +1235,7 @@ public class DemandRefinementPointsTo extends AbstractDemandPointsTo {
PointerKey ikPred = (PointerKey) iter.next();
PointerKeyAndState ikPredAndState = new PointerKeyAndState(ikPred, ikAndState.getState());
int mappedIndex = ikAndStates.getMappedIndex(ikAndState);
if (Assertions.verifyAssertions) {
assert mappedIndex != -1;
}
assert mappedIndex != -1;
if (findOrCreate(pkToTrackedSet, ikPredAndState).add(mappedIndex)) {
addToTrackedPToWorklist(ikPredAndState);
}
@ -1445,10 +1423,8 @@ public class DemandRefinementPointsTo extends AbstractDemandPointsTo {
SSAAbstractInvokeInstruction callInstr = callInstrs[i];
PointerKey returnAtCallerKey = heapModel.getPointerKeyForLocal(caller, isExceptional ? callInstr.getException()
: callInstr.getDef());
if (Assertions.verifyAssertions) {
assert g.containsNode(returnAtCallerKey);
assert g.containsNode(returnKey);
}
assert g.containsNode(returnAtCallerKey);
assert g.containsNode(returnKey);
handler.handle(curPkAndState, returnAtCallerKey, returnBarLabel);
}
}
@ -1507,9 +1483,7 @@ public class DemandRefinementPointsTo extends AbstractDemandPointsTo {
}
g.addSubgraphForNode(callee);
PointerKey paramVal = heapModel.getPointerKeyForLocal(callee, i + 1);
if (Assertions.verifyAssertions) {
assert g.containsNode(paramVal);
}
assert g.containsNode(paramVal);
handler.handle(curPkAndState, paramVal, ParamBarLabel.make(callSiteAndCGNode));
}
} else {
@ -1524,9 +1498,7 @@ public class DemandRefinementPointsTo extends AbstractDemandPointsTo {
}
g.addSubgraphForNode(callee);
PointerKey paramVal = heapModel.getPointerKeyForLocal(callee, i + 1);
if (Assertions.verifyAssertions) {
assert g.containsNode(paramVal);
}
assert g.containsNode(paramVal);
handler.handle(curPkAndState, paramVal, ParamBarLabel.make(callSiteAndCGNode));
}
}
@ -1677,11 +1649,8 @@ public class DemandRefinementPointsTo extends AbstractDemandPointsTo {
@Override
void handle(PointerKeyAndState src, final PointerKey dst, IFlowLabel label) {
if (Assertions.verifyAssertions) {
assert src == curPkAndState;
}
assert src == curPkAndState;
doTransition(curState, label, new Function<State, Object>() {
public Object apply(State dstState) {
PointerKeyAndState dstAndState = new PointerKeyAndState(dst, dstState);
if (findOrCreate(pkToTrackedSet, dstAndState).addAll(trackedSet)) {
@ -1729,18 +1698,16 @@ public class DemandRefinementPointsTo extends AbstractDemandPointsTo {
PointerKey basePointerKey = loadEdge.base.getPointerKey();
State loadDstState = loadedValAndState.getState();
PointerKeyAndState baseAndStateToHandle = new PointerKeyAndState(basePointerKey, loadDstState);
if (Assertions.verifyAssertions) {
boolean basePointerOkay = pointsToQueried.get(basePointerKey).contains(loadDstState)
|| !pointsToQueried.get(loadedValAndState.getPointerKey()).contains(loadDstState)
|| initWorklist.contains(loadedValAndState);
// if (!basePointerOkay) {
// System.err.println("ASSERTION WILL FAIL");
// System.err.println("QUERIED: " + queriedPkAndStates);
// }
if (!basePointerOkay) {
// remove this assertion, since we now allow multiple queries --MS
// Assertions._assert(false, "queried " + loadedValAndState + " but not " + baseAndStateToHandle);
}
boolean basePointerOkay = pointsToQueried.get(basePointerKey).contains(loadDstState)
|| !pointsToQueried.get(loadedValAndState.getPointerKey()).contains(loadDstState)
|| initWorklist.contains(loadedValAndState);
// if (!basePointerOkay) {
// System.err.println("ASSERTION WILL FAIL");
// System.err.println("QUERIED: " + queriedPkAndStates);
// }
if (!basePointerOkay) {
// remove this assertion, since we now allow multiple queries --MS
// Assertions._assert(false, "queried " + loadedValAndState + " but not " + baseAndStateToHandle);
}
final IntSet curP2Set = find(pkToP2Set, baseAndStateToHandle);
// int startSize = curP2Set.size();
@ -1930,12 +1897,9 @@ public class DemandRefinementPointsTo extends AbstractDemandPointsTo {
for (int i = 0; i < callInstrs.length; i++) {
SSAAbstractInvokeInstruction callInstr = callInstrs[i];
final PointerKey actualPk = heapModel.getPointerKeyForLocal(caller, callInstr.getUse(paramPos));
if (Assertions.verifyAssertions) {
assert g.containsNode(actualPk);
assert g.containsNode(localPk);
}
assert g.containsNode(actualPk);
assert g.containsNode(localPk);
doTransition(curState, paramLabel, new Function<State, Object>() {
public Object apply(State nextState) {
propagate(new PointerKeyAndState(actualPk, nextState));
return null;
@ -1985,9 +1949,7 @@ public class DemandRefinementPointsTo extends AbstractDemandPointsTo {
g.addSubgraphForNode(callee);
final PointerKey retVal = isExceptional ? heapModel.getPointerKeyForExceptionalReturnValue(callee) : heapModel
.getPointerKeyForReturnValue(callee);
if (Assertions.verifyAssertions) {
assert g.containsNode(retVal);
}
assert g.containsNode(retVal);
doTransition(curState, ReturnLabel.make(callSiteAndCGNode), new Function<State, Object>() {
public Object apply(State nextState) {
@ -2008,9 +1970,7 @@ public class DemandRefinementPointsTo extends AbstractDemandPointsTo {
g.addSubgraphForNode(callee);
final PointerKey retVal = isExceptional ? heapModel.getPointerKeyForExceptionalReturnValue(callee) : heapModel
.getPointerKeyForReturnValue(callee);
if (Assertions.verifyAssertions) {
assert g.containsNode(retVal);
}
assert g.containsNode(retVal);
doTransition(curState, ReturnLabel.make(callSiteAndCGNode), new Function<State, Object>() {
public Object apply(State nextState) {

View File

@ -17,119 +17,116 @@ import com.ibm.wala.ipa.callgraph.propagation.FilteredPointerKey.TypeFilter;
import com.ibm.wala.ipa.cha.IClassHierarchy;
import com.ibm.wala.types.TypeReference;
import com.ibm.wala.util.debug.Assertions;
/**
* a {@link HeapModel} that delegates to another except for pointer keys
* representing <code>this</code> parameters of methods, for which it
* returns a {@link FilteredPointerKey} for the type of the parameter
*
* @see #getPointerKeyForLocal(CGNode, int)
* @author manu
*
*/
public class ThisFilteringHeapModel implements HeapModel {
private final HeapModel delegate;
/**
* a {@link HeapModel} that delegates to another except for pointer keys representing <code>this</code> parameters of methods, for
* which it returns a {@link FilteredPointerKey} for the type of the parameter
*
* @see #getPointerKeyForLocal(CGNode, int)
* @author manu
*
*/
public class ThisFilteringHeapModel implements HeapModel {
private final IClassHierarchy cha;
private final HeapModel delegate;
public IClassHierarchy getClassHierarchy() {
return delegate.getClassHierarchy();
}
public FilteredPointerKey getFilteredPointerKeyForLocal(CGNode node, int valueNumber, TypeFilter filter) {
return delegate.getFilteredPointerKeyForLocal(node, valueNumber, filter);
}
public InstanceKey getInstanceKeyForAllocation(CGNode node, NewSiteReference allocation) {
return delegate.getInstanceKeyForAllocation(node, allocation);
}
public InstanceKey getInstanceKeyForClassObject(TypeReference type) {
return delegate.getInstanceKeyForClassObject(type);
}
public InstanceKey getInstanceKeyForConstant(TypeReference type, Object S) {
return delegate.getInstanceKeyForConstant(type, S);
}
public InstanceKey getInstanceKeyForMultiNewArray(CGNode node, NewSiteReference allocation, int dim) {
return delegate.getInstanceKeyForMultiNewArray(node, allocation, dim);
}
public InstanceKey getInstanceKeyForPEI(CGNode node, ProgramCounter instr, TypeReference type) {
return delegate.getInstanceKeyForPEI(node, instr, type);
}
public PointerKey getPointerKeyForArrayContents(InstanceKey I) {
return delegate.getPointerKeyForArrayContents(I);
}
public PointerKey getPointerKeyForExceptionalReturnValue(CGNode node) {
return delegate.getPointerKeyForExceptionalReturnValue(node);
}
public PointerKey getPointerKeyForInstanceField(InstanceKey I, IField field) {
return delegate.getPointerKeyForInstanceField(I, field);
}
public PointerKey getPointerKeyForLocal(CGNode node, int valueNumber) {
if (!node.getMethod().isStatic() && valueNumber == 1) {
return delegate.getFilteredPointerKeyForLocal(node, valueNumber, getFilter(node));
} else {
return delegate.getPointerKeyForLocal(node, valueNumber);
}
}
private FilteredPointerKey.TypeFilter getFilter(CGNode target) {
FilteredPointerKey.TypeFilter filter = (FilteredPointerKey.TypeFilter) target.getContext().get(ContextKey.FILTER);
if (filter != null) {
return filter;
} else {
// the context does not select a particular concrete type for the
// receiver.
IClass C = getReceiverClass(target.getMethod());
return new FilteredPointerKey.SingleClassFilter(C);
}
}
/**
* @param method
* @return the receiver class for this method.
*/
private IClass getReceiverClass(IMethod method) {
TypeReference formalType = method.getParameterType(0);
IClass C = cha.lookupClass(formalType);
if (Assertions.verifyAssertions) {
if (method.isStatic()) {
Assertions.UNREACHABLE("asked for receiver of static method " + method);
}
if (C == null) {
Assertions.UNREACHABLE("no class found for " + formalType + " recv of " + method);
}
}
return C;
}
public PointerKey getPointerKeyForReturnValue(CGNode node) {
return delegate.getPointerKeyForReturnValue(node);
}
public PointerKey getPointerKeyForStaticField(IField f) {
return delegate.getPointerKeyForStaticField(f);
}
public Iterator<PointerKey> iteratePointerKeys() {
return delegate.iteratePointerKeys();
}
public ThisFilteringHeapModel(HeapModel delegate, IClassHierarchy cha) {
if (delegate == null) {
throw new IllegalArgumentException("delegate null");
}
this.delegate = delegate;
this.cha = cha;
}
private final IClassHierarchy cha;
public IClassHierarchy getClassHierarchy() {
return delegate.getClassHierarchy();
}
public FilteredPointerKey getFilteredPointerKeyForLocal(CGNode node, int valueNumber, TypeFilter filter) {
return delegate.getFilteredPointerKeyForLocal(node, valueNumber, filter);
}
public InstanceKey getInstanceKeyForAllocation(CGNode node, NewSiteReference allocation) {
return delegate.getInstanceKeyForAllocation(node, allocation);
}
public InstanceKey getInstanceKeyForClassObject(TypeReference type) {
return delegate.getInstanceKeyForClassObject(type);
}
public InstanceKey getInstanceKeyForConstant(TypeReference type, Object S) {
return delegate.getInstanceKeyForConstant(type, S);
}
public InstanceKey getInstanceKeyForMultiNewArray(CGNode node, NewSiteReference allocation, int dim) {
return delegate.getInstanceKeyForMultiNewArray(node, allocation, dim);
}
public InstanceKey getInstanceKeyForPEI(CGNode node, ProgramCounter instr, TypeReference type) {
return delegate.getInstanceKeyForPEI(node, instr, type);
}
public PointerKey getPointerKeyForArrayContents(InstanceKey I) {
return delegate.getPointerKeyForArrayContents(I);
}
public PointerKey getPointerKeyForExceptionalReturnValue(CGNode node) {
return delegate.getPointerKeyForExceptionalReturnValue(node);
}
public PointerKey getPointerKeyForInstanceField(InstanceKey I, IField field) {
return delegate.getPointerKeyForInstanceField(I, field);
}
public PointerKey getPointerKeyForLocal(CGNode node, int valueNumber) {
if (!node.getMethod().isStatic() && valueNumber == 1) {
return delegate.getFilteredPointerKeyForLocal(node, valueNumber, getFilter(node));
} else {
return delegate.getPointerKeyForLocal(node, valueNumber);
}
}
private FilteredPointerKey.TypeFilter getFilter(CGNode target) {
FilteredPointerKey.TypeFilter filter = (FilteredPointerKey.TypeFilter) target.getContext().get(ContextKey.FILTER);
if (filter != null) {
return filter;
} else {
// the context does not select a particular concrete type for the
// receiver.
IClass C = getReceiverClass(target.getMethod());
return new FilteredPointerKey.SingleClassFilter(C);
}
}
/**
* @param method
* @return the receiver class for this method.
*/
private IClass getReceiverClass(IMethod method) {
TypeReference formalType = method.getParameterType(0);
IClass C = cha.lookupClass(formalType);
if (method.isStatic()) {
Assertions.UNREACHABLE("asked for receiver of static method " + method);
}
if (C == null) {
Assertions.UNREACHABLE("no class found for " + formalType + " recv of " + method);
}
return C;
}
public PointerKey getPointerKeyForReturnValue(CGNode node) {
return delegate.getPointerKeyForReturnValue(node);
}
public PointerKey getPointerKeyForStaticField(IField f) {
return delegate.getPointerKeyForStaticField(f);
}
public Iterator<PointerKey> iteratePointerKeys() {
return delegate.iteratePointerKeys();
}
public ThisFilteringHeapModel(HeapModel delegate, IClassHierarchy cha) {
if (delegate == null) {
throw new IllegalArgumentException("delegate null");
}
this.delegate = delegate;
this.cha = cha;
}
}

View File

@ -49,13 +49,9 @@ import com.ibm.wala.ipa.callgraph.propagation.PointerKey;
import com.ibm.wala.ipa.cha.IClassHierarchy;
import com.ibm.wala.types.ClassLoaderReference;
import com.ibm.wala.types.TypeReference;
import com.ibm.wala.util.debug.Assertions;
/**
* Manually annotated policy for refining field accesses.
*
* @author Manu Sridharan
*
*/
public class ManualFieldPolicy implements FieldRefinePolicy {
@ -109,8 +105,6 @@ public class ManualFieldPolicy implements FieldRefinePolicy {
private final IClassHierarchy cha;
/**
*
* @param klass
* @return the top-level {@link IClass} where klass is declared, or klass itself if klass is top-level
*/
private IClass removeInner(IClass klass) {
@ -122,16 +116,12 @@ public class ManualFieldPolicy implements FieldRefinePolicy {
} else {
String topMostName = klassStr.substring(0, dollarIndex);
IClass topMostClass = cha.lookupClass(TypeReference.findOrCreate(cl, topMostName));
if (Assertions.verifyAssertions) {
assert topMostClass != null;
}
assert topMostClass != null;
return topMostClass;
}
}
/**
*
* @param cha
* @param refinePattern a pattern for detecting which match edges to refine. If the <em>declaring class</em> of the field related
* to the match edge matches the pattern, the match edge will be refined. For example, the pattern
* <code>Pattern.compile("Ljava/util")</code> will cause all fields of classes in the <code>java.util</code> package to

View File

@ -66,15 +66,11 @@ import com.ibm.wala.ssa.SSAPhiInstruction;
import com.ibm.wala.util.collections.EmptyIterator;
import com.ibm.wala.util.collections.HashMapFactory;
import com.ibm.wala.util.collections.HashSetFactory;
import com.ibm.wala.util.debug.Assertions;
import com.ibm.wala.util.intset.BitVectorIntSet;
import com.ibm.wala.util.ref.ReferenceCleanser;
/**
* A graph representing program flow, constructed method-by-method on demand
*
* @author Manu Sridharan
*
*/
public abstract class AbstractDemandFlowGraph extends AbstractFlowGraph {
private final static boolean DEBUG = false;
@ -141,10 +137,8 @@ public abstract class AbstractDemandFlowGraph extends AbstractFlowGraph {
for (int i = 0; i < callInstrs.length; i++) {
SSAAbstractInvokeInstruction callInstr = callInstrs[i];
PointerKey actualPk = heapModel.getPointerKeyForLocal(caller, callInstr.getUse(paramPos));
if (Assertions.verifyAssertions) {
assert containsNode(actualPk);
assert containsNode(pk);
}
assert containsNode(actualPk);
assert containsNode(pk);
paramSuccs.add(new PointerKeyAndCallSite(actualPk, call));
}
}
@ -176,9 +170,7 @@ public abstract class AbstractDemandFlowGraph extends AbstractFlowGraph {
// TODO test this!!!
// TODO test passing null as an argument
PointerKey paramVal = heapModel.getPointerKeyForLocal(callee, i + 1);
if (Assertions.verifyAssertions) {
assert containsNode(paramVal);
}
assert containsNode(paramVal);
paramPreds.add(new PointerKeyAndCallSite(paramVal, callSiteRef));
}
}
@ -205,9 +197,7 @@ public abstract class AbstractDemandFlowGraph extends AbstractFlowGraph {
addSubgraphForNode(callee);
PointerKey retVal = isExceptional ? heapModel.getPointerKeyForExceptionalReturnValue(callee) : heapModel
.getPointerKeyForReturnValue(callee);
if (Assertions.verifyAssertions) {
assert containsNode(retVal);
}
assert containsNode(retVal);
returnSuccs.add(new PointerKeyAndCallSite(retVal, callSiteRef));
}
@ -238,10 +228,8 @@ public abstract class AbstractDemandFlowGraph extends AbstractFlowGraph {
SSAAbstractInvokeInstruction callInstr = callInstrs[i];
PointerKey returnPk = heapModel.getPointerKeyForLocal(caller, isExceptional ? callInstr.getException() : callInstr
.getDef());
if (Assertions.verifyAssertions) {
assert containsNode(returnPk);
assert containsNode(pk);
}
assert containsNode(returnPk);
assert containsNode(pk);
returnPreds.add(new PointerKeyAndCallSite(returnPk, call));
}
}
@ -292,8 +280,8 @@ public abstract class AbstractDemandFlowGraph extends AbstractFlowGraph {
/**
* Add constraints for a particular basic block.
*/
protected void addBlockInstructionConstraints(CGNode node, ControlFlowGraph<SSAInstruction, ISSABasicBlock> cfg, ISSABasicBlock b,
FlowStatementVisitor v) {
protected void addBlockInstructionConstraints(CGNode node, ControlFlowGraph<SSAInstruction, ISSABasicBlock> cfg,
ISSABasicBlock b, FlowStatementVisitor v) {
v.setBasicBlock(b);
// visit each instruction in the basic block.
@ -325,9 +313,7 @@ public abstract class AbstractDemandFlowGraph extends AbstractFlowGraph {
break;
}
}
if (DEBUG && Assertions.verifyAssertions) {
assert n < cfg.getPredNodeCount(sb);
}
assert n < cfg.getPredNodeCount(sb);
for (Iterator<SSAPhiInstruction> phis = sb.iteratePhis(); phis.hasNext();) {
// Assertions.UNREACHABLE();
SSAPhiInstruction phi = phis.next();

View File

@ -89,6 +89,7 @@ import com.ibm.wala.util.graph.labeled.SlowSparseNumberedLabeledGraph;
/**
* A graph whose edges are labeled with {@link IFlowLabel}s.
*
* @author Manu Sridharan
*
*/
@ -109,27 +110,26 @@ public abstract class AbstractFlowGraph extends SlowSparseNumberedLabeledGraph<O
};
/**
* Map: LocalPointerKey -> SSAInvokeInstruction. If we have (x, foo()), that means that x was def'fed by the return
* value from the call to foo()
* Map: LocalPointerKey -> SSAInvokeInstruction. If we have (x, foo()), that means that x was def'fed by the return value from the
* call to foo()
*/
protected final Map<PointerKey, SSAInvokeInstruction> callDefs = HashMapFactory.make();
/**
* Map: {@link LocalPointerKey} -> Set<{@link SSAInvokeInstruction}>. If we have (x, foo()), that means x was
* passed as a parameter to the call to foo(). The parameter position is not represented and must be recovered.
* Map: {@link LocalPointerKey} -> Set<{@link SSAInvokeInstruction}>. If we have (x, foo()), that means x was passed as a
* parameter to the call to foo(). The parameter position is not represented and must be recovered.
*/
protected final Map<PointerKey, Set<SSAInvokeInstruction>> callParams = HashMapFactory.make();
/**
* Map: LocalPointerKey -> CGNode. If we have (x, foo), then x is a parameter of method foo. For now, we have to
* re-discover the parameter position. TODO this should just be a set; we can get the CGNode from the
* {@link LocalPointerKey}
* Map: LocalPointerKey -> CGNode. If we have (x, foo), then x is a parameter of method foo. For now, we have to re-discover the
* parameter position. TODO this should just be a set; we can get the CGNode from the {@link LocalPointerKey}
*/
protected final Map<PointerKey, CGNode> params = HashMapFactory.make();
/**
* Map: {@link LocalPointerKey} -> {@link CGNode}. If we have (x, foo), then x is a return value of method foo. Must
* re-discover if x is normal or exceptional return value.
* Map: {@link LocalPointerKey} -> {@link CGNode}. If we have (x, foo), then x is a return value of method foo. Must re-discover
* if x is normal or exceptional return value.
*/
protected final Map<PointerKey, CGNode> returns = HashMapFactory.make();
@ -151,7 +151,7 @@ public abstract class AbstractFlowGraph extends SlowSparseNumberedLabeledGraph<O
/*
* @see com.ibm.wala.demandpa.flowgraph.IFlowLabelGraph#visitSuccs(java.lang.Object,
* com.ibm.wala.demandpa.flowgraph.IFlowLabel.IFlowLabelVisitor)
* com.ibm.wala.demandpa.flowgraph.IFlowLabel.IFlowLabelVisitor)
*/
public void visitSuccs(Object node, IFlowLabelVisitor v) {
for (Iterator<? extends IFlowLabel> succLabelIter = getSuccLabels(node); succLabelIter.hasNext();) {
@ -164,7 +164,7 @@ public abstract class AbstractFlowGraph extends SlowSparseNumberedLabeledGraph<O
/*
* @see com.ibm.wala.demandpa.flowgraph.IFlowLabelGraph#visitPreds(java.lang.Object,
* com.ibm.wala.demandpa.flowgraph.IFlowLabel.IFlowLabelVisitor)
* com.ibm.wala.demandpa.flowgraph.IFlowLabel.IFlowLabelVisitor)
*/
public void visitPreds(Object node, IFlowLabelVisitor v) {
for (Iterator<? extends IFlowLabel> predLabelIter = getPredLabels(node); predLabelIter.hasNext();) {
@ -177,6 +177,7 @@ public abstract class AbstractFlowGraph extends SlowSparseNumberedLabeledGraph<O
/**
* For each invocation in the method, add nodes for actual parameters and return values
*
* @param node
*/
protected void addNodesForInvocations(CGNode node, IR ir) {
@ -278,7 +279,7 @@ public abstract class AbstractFlowGraph extends SlowSparseNumberedLabeledGraph<O
}
/**
* convert a pointer key to one in the memory access map's heap model
* convert a pointer key to one in the memory access map's heap model
*
* TODO move this somewhere more appropriate
*
@ -402,7 +403,7 @@ public abstract class AbstractFlowGraph extends SlowSparseNumberedLabeledGraph<O
List<ProgramCounter> peis = SSAPropagationCallGraphBuilder.getIncomingPEIs(ir, ir.getExitBlock());
PointerKey exception = heapModel.getPointerKeyForExceptionalReturnValue(node);
IClass c = node.getClassHierarchy().lookupClass(TypeReference.JavaLangThrowable);
addExceptionDefConstraints(ir, node, peis, exception, Collections.singleton(c));
}
@ -444,10 +445,8 @@ public abstract class AbstractFlowGraph extends SlowSparseNumberedLabeledGraph<O
TypeReference type = it2.next();
if (type != null) {
InstanceKey ik = heapModel.getInstanceKeyForPEI(node, peiLoc, type);
if (Assertions.verifyAssertions) {
if (!(ik instanceof ConcreteTypeKey)) {
assert ik instanceof ConcreteTypeKey : "uh oh: need to implement getCaughtException constraints for instance " + ik;
}
if (!(ik instanceof ConcreteTypeKey)) {
assert ik instanceof ConcreteTypeKey : "uh oh: need to implement getCaughtException constraints for instance " + ik;
}
ConcreteTypeKey ck = (ConcreteTypeKey) ik;
IClass klass = ck.getType();

View File

@ -82,14 +82,10 @@ import com.ibm.wala.types.FieldReference;
import com.ibm.wala.types.TypeReference;
import com.ibm.wala.util.collections.HashSetFactory;
import com.ibm.wala.util.collections.Pair;
import com.ibm.wala.util.debug.Assertions;
/**
* A graph representation of statements flowing pointer values, but <em>not</em> primitive values. Nodes are variables, and edges
* are <em>against</em> value flow; assignment x = y yields edge from x to y with label {@link AssignLabel#noFilter()}
*
* @author Manu Sridharan
*
*/
public class DemandPointerFlowGraph extends AbstractDemandFlowGraph implements IFlowGraph {
@ -99,8 +95,6 @@ public class DemandPointerFlowGraph extends AbstractDemandFlowGraph implements I
/**
* add nodes for parameters and return values
*
* @param node
*/
@Override
protected void addNodesForParameters(CGNode node, IR ir) {
@ -175,9 +169,7 @@ public class DemandPointerFlowGraph extends AbstractDemandFlowGraph implements I
this.ir = node.getIR();
this.du = node.getDU();
this.symbolTable = ir.getSymbolTable();
if (Assertions.verifyAssertions) {
assert symbolTable != null;
}
assert symbolTable != null;
}
/*
@ -288,9 +280,7 @@ public class DemandPointerFlowGraph extends AbstractDemandFlowGraph implements I
return;
}
PointerKey def = heapModel.getPointerKeyForLocal(node, lval);
if (Assertions.verifyAssertions) {
assert def != null;
}
assert def != null;
if (isStatic) {
PointerKey fKey = heapModel.getPointerKeyForStaticField(f);
@ -324,9 +314,7 @@ public class DemandPointerFlowGraph extends AbstractDemandFlowGraph implements I
return;
}
PointerKey use = heapModel.getPointerKeyForLocal(node, rval);
if (Assertions.verifyAssertions) {
assert use != null;
}
assert use != null;
if (isStatic) {
PointerKey fKey = heapModel.getPointerKeyForStaticField(f);
@ -460,11 +448,7 @@ public class DemandPointerFlowGraph extends AbstractDemandFlowGraph implements I
TypeReference type = it2.next();
if (type != null) {
InstanceKey ik = heapModel.getInstanceKeyForPEI(node, peiLoc, type);
if (Assertions.verifyAssertions) {
if (!(ik instanceof ConcreteTypeKey)) {
assert ik instanceof ConcreteTypeKey : "uh oh: need to implement getCaughtException constraints for instance " + ik;
}
}
assert ik instanceof ConcreteTypeKey : "uh oh: need to implement getCaughtException constraints for instance " + ik;
ConcreteTypeKey ck = (ConcreteTypeKey) ik;
IClass klass = ck.getType();
if (PropagationCallGraphBuilder.catches(catchClasses, klass, cha)) {
@ -508,7 +492,7 @@ public class DemandPointerFlowGraph extends AbstractDemandFlowGraph implements I
public void visitLoadMetadata(SSALoadMetadataInstruction instruction) {
PointerKey def = heapModel.getPointerKeyForLocal(node, instruction.getDef());
assert instruction.getType() == TypeReference.JavaLangClass;
InstanceKey iKey = heapModel.getInstanceKeyForClassObject((TypeReference)instruction.getToken());
InstanceKey iKey = heapModel.getInstanceKeyForClassObject((TypeReference) instruction.getToken());
g.addNode(iKey);
g.addNode(def);

View File

@ -150,9 +150,7 @@ public class DemandValueFlowGraph extends AbstractDemandFlowGraph {
this.node = node;
this.ir = node.getIR();
this.symbolTable = ir.getSymbolTable();
if (Assertions.verifyAssertions) {
assert symbolTable != null;
}
assert symbolTable != null;
this.du = node.getDU();
}
@ -252,9 +250,7 @@ public class DemandValueFlowGraph extends AbstractDemandFlowGraph {
return;
}
PointerKey def = heapModel.getPointerKeyForLocal(node, lval);
if (Assertions.verifyAssertions) {
assert def != null;
}
assert def != null;
if (isStatic) {
PointerKey fKey = heapModel.getPointerKeyForStaticField(f);
@ -285,9 +281,7 @@ public class DemandValueFlowGraph extends AbstractDemandFlowGraph {
return;
}
PointerKey use = heapModel.getPointerKeyForLocal(node, rval);
if (Assertions.verifyAssertions) {
assert use != null;
}
assert use != null;
if (isStatic) {
PointerKey fKey = heapModel.getPointerKeyForStaticField(f);

View File

@ -73,21 +73,20 @@ import com.ibm.wala.util.intset.IntSet;
import com.ibm.wala.util.ref.ReferenceCleanser;
/**
* The nodes in this graph are PointerKeys corresponding to local variables and
* static fields, InstanceKeys, and FieldRefs (see below).
* The nodes in this graph are PointerKeys corresponding to local variables and static fields, InstanceKeys, and FieldRefs (see
* below).
*
* This graph is constructed on-demand during a traversal.
*
* The edges represent
* <ul>
* <li> flow from local -> local representing assignment (i.e. phi,pi)
* <li> flow from instancekey -> local for news
* <li> flow from formal -> actual parameter
* <li> flow from return value -> local
* <li> match edges
* <li> local -> local edges representing loads/stores (e.g. x = y.f will have a
* edge x->y, labelled with f) for a getstatic x = Y.f, we have an edge from x ->
* Y.f.
* <li>flow from local -> local representing assignment (i.e. phi,pi)
* <li>flow from instancekey -> local for news
* <li>flow from formal -> actual parameter
* <li>flow from return value -> local
* <li>match edges
* <li>local -> local edges representing loads/stores (e.g. x = y.f will have a edge x->y, labelled with f) for a getstatic x = Y.f,
* we have an edge from x -> Y.f.
* </ul>
*
* N.B: Edges go OPPOSITE the flow of values.
@ -117,22 +116,21 @@ public class SimpleDemandPointerFlowGraph extends SlowSparseNumberedGraph<Object
final BitVectorIntSet cgNodesVisited = new BitVectorIntSet();
/**
* Map: LocalPointerKey -> IField. if we have (x,f), that means x was def'fed
* by a getfield on f.
* Map: LocalPointerKey -> IField. if we have (x,f), that means x was def'fed by a getfield on f.
*/
final Map<PointerKey, IField> getFieldDefs = HashMapFactory.make();
final Collection<PointerKey> arrayDefs = HashSetFactory.make();
/**
* Map: LocalPointerKey -> SSAInvokeInstruction. If we have (x, foo()), that
* means that x was def'fed by the return value from a call to foo()
* Map: LocalPointerKey -> SSAInvokeInstruction. If we have (x, foo()), that means that x was def'fed by the return value from a
* call to foo()
*/
final Map<PointerKey, SSAInvokeInstruction> callDefs = HashMapFactory.make();
/**
* Map: LocalPointerKey -> CGNode. If we have (x, foo), then x is a parameter
* of method foo. For now, we have to re-discover the parameter position.
* Map: LocalPointerKey -> CGNode. If we have (x, foo), then x is a parameter of method foo. For now, we have to re-discover the
* parameter position.
*/
final Map<PointerKey, CGNode> params = HashMapFactory.make();
@ -288,10 +286,8 @@ public class SimpleDemandPointerFlowGraph extends SlowSparseNumberedGraph<Object
IR ir = a.getNode().getIR();
SSAArrayStoreInstruction s = (SSAArrayStoreInstruction) ir.getInstructions()[a.getInstructionIndex()];
PointerKey r = heapModel.getPointerKeyForLocal(a.getNode(), s.getValue());
if (Assertions.verifyAssertions) {
assert containsNode(r);
assert containsNode(pk);
}
assert containsNode(r);
assert containsNode(pk);
addMatchEdge(pk, r);
}
}
@ -312,10 +308,8 @@ public class SimpleDemandPointerFlowGraph extends SlowSparseNumberedGraph<Object
for (int i = 0; i < callInstrs.length; i++) {
SSAAbstractInvokeInstruction callInstr = callInstrs[i];
PointerKey actualPk = heapModel.getPointerKeyForLocal(caller, callInstr.getUse(paramPos));
if (Assertions.verifyAssertions) {
assert containsNode(actualPk);
assert containsNode(pk);
}
assert containsNode(actualPk);
assert containsNode(pk);
addEdge(pk, actualPk);
}
@ -325,9 +319,7 @@ public class SimpleDemandPointerFlowGraph extends SlowSparseNumberedGraph<Object
}
/**
* @param pk
* value being def'fed by a call instruction (either normal or
* exceptional)
* @param pk value being def'fed by a call instruction (either normal or exceptional)
*/
private void addReturnEdges(LocalPointerKey pk, SSAInvokeInstruction callInstr) {
boolean isExceptional = pk.getValueNumber() == callInstr.getException();
@ -339,9 +331,7 @@ public class SimpleDemandPointerFlowGraph extends SlowSparseNumberedGraph<Object
addSubgraphForNode(callee);
PointerKey retVal = isExceptional ? heapModel.getPointerKeyForExceptionalReturnValue(callee) : heapModel
.getPointerKeyForReturnValue(callee);
if (Assertions.verifyAssertions) {
assert containsNode(retVal);
}
assert containsNode(retVal);
addEdge(pk, retVal);
}
}
@ -359,10 +349,8 @@ public class SimpleDemandPointerFlowGraph extends SlowSparseNumberedGraph<Object
IR ir = a.getNode().getIR();
SSAPutInstruction s = (SSAPutInstruction) ir.getInstructions()[a.getInstructionIndex()];
PointerKey r = heapModel.getPointerKeyForLocal(a.getNode(), s.getVal());
if (Assertions.verifyAssertions) {
assert containsNode(r);
assert containsNode(pk);
}
assert containsNode(r);
assert containsNode(pk);
addMatchEdge(pk, r);
}
}
@ -381,8 +369,7 @@ public class SimpleDemandPointerFlowGraph extends SlowSparseNumberedGraph<Object
/*
* (non-Javadoc)
*
* @see com.ibm.capa.util.graph.AbstractGraph#hasEdge(java.lang.Object,
* java.lang.Object)
* @see com.ibm.capa.util.graph.AbstractGraph#hasEdge(java.lang.Object, java.lang.Object)
*/
public boolean hasEdge(PointerKey src, PointerKey dst) {
// TODO Auto-generated method stub
@ -416,30 +403,24 @@ public class SimpleDemandPointerFlowGraph extends SlowSparseNumberedGraph<Object
}
/**
* Add constraints to represent the flow of exceptions to the exceptional
* return value for this node
* Add constraints to represent the flow of exceptions to the exceptional return value for this node
*/
protected void addNodePassthruExceptionConstraints(CGNode node, IR ir) {
// add constraints relating to thrown exceptions that reach the exit block.
List<ProgramCounter> peis = SSAPropagationCallGraphBuilder.getIncomingPEIs(ir, ir.getExitBlock());
PointerKey exception = heapModel.getPointerKeyForExceptionalReturnValue(node);
IClass c = node.getClassHierarchy().lookupClass(TypeReference.JavaLangThrowable);
addExceptionDefConstraints(ir, node, peis, exception, Collections.singleton(c));
}
/**
* Generate constraints which assign exception values into an exception
* pointer
* Generate constraints which assign exception values into an exception pointer
*
* @param node
* governing node
* @param peis
* list of PEI instructions
* @param exceptionVar
* PointerKey representing a pointer to an exception value
* @param catchClasses
* the types "caught" by the exceptionVar
* @param node governing node
* @param peis list of PEI instructions
* @param exceptionVar PointerKey representing a pointer to an exception value
* @param catchClasses the types "caught" by the exceptionVar
*/
private void addExceptionDefConstraints(IR ir, CGNode node, List<ProgramCounter> peis, PointerKey exceptionVar,
Set<IClass> catchClasses) {
@ -469,11 +450,7 @@ public class SimpleDemandPointerFlowGraph extends SlowSparseNumberedGraph<Object
for (TypeReference type : types) {
if (type != null) {
InstanceKey ik = heapModel.getInstanceKeyForPEI(node, peiLoc, type);
if (Assertions.verifyAssertions) {
if (!(ik instanceof ConcreteTypeKey)) {
assert ik instanceof ConcreteTypeKey : "uh oh: need to implement getCaughtException constraints for instance " + ik;
}
}
assert ik instanceof ConcreteTypeKey : "uh oh: need to implement getCaughtException constraints for instance " + ik;
ConcreteTypeKey ck = (ConcreteTypeKey) ik;
IClass klass = ck.getType();
if (PropagationCallGraphBuilder.catches(catchClasses, klass, cha)) {
@ -501,7 +478,8 @@ public class SimpleDemandPointerFlowGraph extends SlowSparseNumberedGraph<Object
/**
* Add constraints for a particular basic block.
*/
protected void addBlockInstructionConstraints(CGNode node, ControlFlowGraph<SSAInstruction, ISSABasicBlock> cfg, ISSABasicBlock b, StatementVisitor v) {
protected void addBlockInstructionConstraints(CGNode node, ControlFlowGraph<SSAInstruction, ISSABasicBlock> cfg,
ISSABasicBlock b, StatementVisitor v) {
v.setBasicBlock(b);
// visit each instruction in the basic block.
@ -532,9 +510,7 @@ public class SimpleDemandPointerFlowGraph extends SlowSparseNumberedGraph<Object
break;
}
}
if (DEBUG && Assertions.verifyAssertions) {
assert n < cfg.getPredNodeCount(sb);
}
assert n < cfg.getPredNodeCount(sb);
for (Iterator<SSAPhiInstruction> phis = sb.iteratePhis(); phis.hasNext();) {
SSAPhiInstruction phi = phis.next();
if (phi == null) {
@ -575,8 +551,7 @@ public class SimpleDemandPointerFlowGraph extends SlowSparseNumberedGraph<Object
/**
* A visitor that generates graph nodes and edges for an IR.
*
* strategy: when visiting a statement, for each use of that statement, add a
* graph edge from def to use.
* strategy: when visiting a statement, for each use of that statement, add a graph edge from def to use.
*
* TODO: special treatment for parameter passing, etc.
*/
@ -611,9 +586,7 @@ public class SimpleDemandPointerFlowGraph extends SlowSparseNumberedGraph<Object
this.node = node;
this.ir = ir;
this.symbolTable = ir.getSymbolTable();
if (Assertions.verifyAssertions) {
assert symbolTable != null;
}
assert symbolTable != null;
this.du = du;
}
@ -882,9 +855,7 @@ public class SimpleDemandPointerFlowGraph extends SlowSparseNumberedGraph<Object
return;
}
PointerKey def = heapModel.getPointerKeyForLocal(node, lval);
if (Assertions.verifyAssertions) {
assert def != null;
}
assert def != null;
if (isStatic) {
PointerKey fKey = heapModel.getPointerKeyForStaticField(f);
@ -965,9 +936,7 @@ public class SimpleDemandPointerFlowGraph extends SlowSparseNumberedGraph<Object
return;
}
PointerKey use = heapModel.getPointerKeyForLocal(node, rval);
if (Assertions.verifyAssertions) {
assert use != null;
}
assert use != null;
if (isStatic) {
PointerKey fKey = heapModel.getPointerKeyForStaticField(f);
@ -977,38 +946,9 @@ public class SimpleDemandPointerFlowGraph extends SlowSparseNumberedGraph<Object
} else {
addNode(use);
}
// if (DEBUG) {
// Trace.guardedPrintln("visitPut " + field, DEBUG_METHOD_SUBSTRING);
// }
//
// // skip putfields of primitive type
// if (field.getFieldType().isPrimitiveType()) {
// return;
// }
// IField f = getClassHierarchy().resolveField(field);
// if (f == null) {
// if (DEBUG) {
// Trace.guardedPrintln("Could not resolve field " + field,
// DEBUG_METHOD_SUBSTRING);
// }
// getWarnings().add(FieldResolutionFailure.create(field));
// return;
// }
// if (Assertions.verifyAssertions) {
// Assertions._assert(isStatic || !symbolTable.isStringConstant(ref),
// "put to string constant shouldn't be allowed?");
// }
// if (isStatic) {
// processPutStatic(rval, field, f);
// } else {
// processPutField(rval, ref, f);
// }
}
/*
* (non-Javadoc)
*
* @see com.ibm.domo.ssa.Instruction.Visitor#visitInvoke(com.ibm.domo.ssa.InvokeInstruction)
*/
@Override

View File

@ -58,8 +58,7 @@ import com.ibm.wala.util.debug.Assertions;
import com.ibm.wala.util.debug.UnimplementedError;
/**
* utility methods for mapping various program entities from one call graph to
* the corresponding entity in another one
* utility methods for mapping various program entities from one call graph to the corresponding entity in another one
*
* @author Manu Sridharan
*
@ -67,14 +66,11 @@ import com.ibm.wala.util.debug.UnimplementedError;
public class CallGraphMapUtil {
/**
* map a call graph node from one call graph to the corresponding node in
* another. Note that the target call graph must be context-insensitive for
* the method, i.e., the only context for the method should be
* Everywhere.EVERYWHERE.
* map a call graph node from one call graph to the corresponding node in another. Note that the target call graph must be
* context-insensitive for the method, i.e., the only context for the method should be Everywhere.EVERYWHERE.
*
* @return the corresponding node, or <code>null</code> if the method is not
* in the target call graph
* @throws IllegalArgumentException if fromCG == null
* @return the corresponding node, or <code>null</code> if the method is not in the target call graph
* @throws IllegalArgumentException if fromCG == null
*/
public static CGNode mapCGNode(CGNode orig, CallGraph fromCG, CallGraph toCG) throws IllegalArgumentException {
if (fromCG == null) {
@ -94,15 +90,14 @@ public class CallGraphMapUtil {
} else {
Set<CGNode> nodes = toCG.getNodes(methodRef);
int size = nodes.size();
if (Assertions.verifyAssertions) {
assert size <= 1;
}
assert size <= 1;
return (size == 0) ? null : nodes.iterator().next();
}
}
}
public static InstanceKey mapInstKey(InstanceKey ik, CallGraph fromCG, CallGraph toCG, HeapModel heapModel) throws UnimplementedError, NullPointerException {
public static InstanceKey mapInstKey(InstanceKey ik, CallGraph fromCG, CallGraph toCG, HeapModel heapModel)
throws UnimplementedError, NullPointerException {
InstanceKey ret = null;
if (ik instanceof InstanceKeyWithNode) {
CGNode oldCGNode = ((InstanceKeyWithNode) ik).getNode();
@ -128,14 +123,13 @@ public class CallGraphMapUtil {
} else {
Assertions.UNREACHABLE();
}
if (Assertions.verifyAssertions) {
assert ret != null;
assert ret.getClass() == ik.getClass();
}
assert ret != null;
assert ret.getClass() == ik.getClass();
return ret;
}
public static PointerKey mapPointerKey(PointerKey pk, CallGraph fromCG, CallGraph toCG, HeapModel heapModel) throws UnimplementedError {
public static PointerKey mapPointerKey(PointerKey pk, CallGraph fromCG, CallGraph toCG, HeapModel heapModel)
throws UnimplementedError {
PointerKey ret = null;
if (pk instanceof AbstractLocalPointerKey) {
CGNode oldCGNode = ((AbstractLocalPointerKey) pk).getNode();
@ -159,9 +153,7 @@ public class CallGraphMapUtil {
} else {
Assertions.UNREACHABLE();
}
if (Assertions.verifyAssertions) {
assert ret != null;
}
assert ret != null;
return ret;
}
}

View File

@ -36,15 +36,12 @@ import com.ibm.wala.util.graph.traverse.DFS;
public class LocalLiveRangeAnalysis {
/**
* Is the variable with value number v live immediately after a particular
* instruction index?
* Is the variable with value number v live immediately after a particular instruction index?
*
* Algorithm: returns true if there is a path from pc to some use of v that
* does not traverse the def of v
* Algorithm: returns true if there is a path from pc to some use of v that does not traverse the def of v
*
* @param instructionIndex
* index of an instruction in the IR
* @throws IllegalArgumentException if du is null
* @param instructionIndex index of an instruction in the IR
* @throws IllegalArgumentException if du is null
*/
public static boolean isLive(int v, int instructionIndex, IR ir, DefUse du) {
if (du == null) {
@ -53,10 +50,8 @@ public class LocalLiveRangeAnalysis {
if (du.getNumberOfUses(v) == 0) {
return false;
}
if (Assertions.verifyAssertions) {
if (instructionIndex < 0) {
Assertions.UNREACHABLE();
}
if (instructionIndex < 0) {
Assertions.UNREACHABLE();
}
ISSABasicBlock queryBlock = findBlock(ir, instructionIndex);
SSAInstruction def = du.getDef(v);
@ -101,8 +96,7 @@ public class LocalLiveRangeAnalysis {
}
/**
* @param statements
* Iterator<SSAInstruction>
* @param statements Iterator<SSAInstruction>
*/
private static Collection<BasicBlock> findBlocks(IR ir, Iterator<SSAInstruction> statements) {
Collection<SSAInstruction> s = Iterator2Collection.toSet(statements);
@ -117,10 +111,8 @@ public class LocalLiveRangeAnalysis {
}
}
}
if (Assertions.verifyAssertions) {
if (result.isEmpty()) {
Assertions.UNREACHABLE();
}
if (result.isEmpty()) {
Assertions.UNREACHABLE();
}
return result;
}
@ -131,10 +123,8 @@ public class LocalLiveRangeAnalysis {
* @return the basic block which contains the instruction
*/
private static SSACFG.BasicBlock findBlock(IR ir, SSAInstruction s) {
if (Assertions.verifyAssertions) {
if (s == null) {
Assertions.UNREACHABLE();
}
if (s == null) {
Assertions.UNREACHABLE();
}
for (Iterator it = ir.getControlFlowGraph().iterator(); it.hasNext();) {
SSACFG.BasicBlock b = (SSACFG.BasicBlock) it.next();

View File

@ -438,8 +438,7 @@ public class AnalysisScope {
ClassLoaderReference lrReference = e.getKey();
String moduleLdr = lrReference.getName().toString();
String moduleLang = lrReference.getLanguage().toString();
Assertions.precondition(Language.JAVA.getName().equals(lrReference.getLanguage()),
"Java language only is currently supported");
assert Language.JAVA.getName().equals(lrReference.getLanguage()) : "Java language only is currently supported";
for (Module m : e.getValue()) {
String moduleType;
@ -472,8 +471,7 @@ public class AnalysisScope {
ClassLoaderReference lrReference = e.getKey();
String ldrName = lrReference.getName().toString();
String ldrLang = lrReference.getLanguage().toString();
Assertions.precondition(Language.JAVA.getName().equals(lrReference.getLanguage()),
"Java language only is currently supported");
assert Language.JAVA.getName().equals(lrReference.getLanguage()) : "Java language only is currently supported";
String ldrImplName = e.getValue();
String ldrImplDescrLine = String.format("%s,%s,%s,%s", ldrName, ldrLang, "loaderImpl", ldrImplName);
ldrImplLines.add(ldrImplDescrLine);

View File

@ -46,10 +46,7 @@ public abstract class Entrypoint implements BytecodeConstants {
throw new IllegalArgumentException("method is null");
}
this.method = method;
if (Assertions.verifyAssertions) {
assert method.getDeclaringClass() != null : "null declaring class";
}
assert method.getDeclaringClass() != null : "null declaring class";
}
protected Entrypoint(MethodReference method, IClassHierarchy cha) {
@ -57,7 +54,7 @@ public abstract class Entrypoint implements BytecodeConstants {
throw new IllegalArgumentException("cha is null");
}
IMethod m = cha.resolveMethod(method);
if (Assertions.verifyAssertions && m == null) {
if (m == null) {
Assertions.UNREACHABLE("could not resolve " + method);
}
this.method = m;

View File

@ -179,12 +179,10 @@ public abstract class BasicCallGraph extends AbstractNumberedGraph<CGNode> imple
protected NodeImpl(IMethod method, Context C) {
this.method = method;
this.context = C;
if (Assertions.verifyAssertions) {
if (method != null && !method.isSynthetic() && method.isAbstract()) {
assert !method.isAbstract() : "Abstract method " + method;
}
assert C != null;
if (method != null && !method.isSynthetic() && method.isAbstract()) {
assert !method.isAbstract() : "Abstract method " + method;
}
assert C != null;
}
public IMethod getMethod() {
@ -264,10 +262,8 @@ public abstract class BasicCallGraph extends AbstractNumberedGraph<CGNode> imple
private final Context C;
public Key(IMethod m, Context C) {
if (Assertions.verifyAssertions) {
assert m != null : "null method";
assert C != null : "null context";
}
assert m != null : "null method";
assert C != null : "null context";
this.m = m;
this.C = C;
}
@ -279,9 +275,7 @@ public abstract class BasicCallGraph extends AbstractNumberedGraph<CGNode> imple
@Override
public boolean equals(Object o) {
if (Assertions.verifyAssertions) {
assert o instanceof Key;
}
assert o instanceof Key;
Key other = (Key) o;
return (m.equals(other.m) && C.equals(other.C));
}

View File

@ -18,7 +18,6 @@ import com.ibm.wala.ipa.callgraph.MethodTargetSelector;
import com.ibm.wala.ipa.cha.IClassHierarchy;
import com.ibm.wala.types.MethodReference;
import com.ibm.wala.types.TypeReference;
import com.ibm.wala.util.debug.Assertions;
/**
* A {@link MethodTargetSelector} that simply looks up the declared type, name and descriptor of a {@link CallSiteReference} in the
@ -57,11 +56,7 @@ public class ClassHierarchyMethodTargetSelector implements MethodTargetSelector
// java virtual calls
if (call.isDispatch()) {
if (Assertions.verifyAssertions) {
if (receiver == null) {
assert receiver != null : "null receiver for " + call;
}
}
assert receiver != null : "null receiver for " + call;
klass = receiver;
// java static calls

View File

@ -18,7 +18,6 @@ import com.ibm.wala.ipa.callgraph.Entrypoint;
import com.ibm.wala.ipa.cha.IClassHierarchy;
import com.ibm.wala.types.MethodReference;
import com.ibm.wala.types.TypeReference;
import com.ibm.wala.util.debug.Assertions;
/**
* An entrypoint whose parameter types are the declared types.
@ -36,9 +35,7 @@ public class DefaultEntrypoint extends Entrypoint {
}
this.cha = cha;
paramTypes = makeParameterTypes(method);
if (Assertions.verifyAssertions) {
assert paramTypes != null : method.toString();
}
assert paramTypes != null : method.toString();
}
public DefaultEntrypoint(MethodReference method, IClassHierarchy cha) {
@ -48,9 +45,7 @@ public class DefaultEntrypoint extends Entrypoint {
}
this.cha = cha;
paramTypes = makeParameterTypes(getMethod());
if (Assertions.verifyAssertions) {
assert paramTypes != null : method.toString();
}
assert paramTypes != null : method.toString();
}
protected TypeReference[][] makeParameterTypes(IMethod method) {

View File

@ -78,7 +78,7 @@ public class ExplicitCallGraph extends BasicCallGraph implements BytecodeConstan
this.options = options;
this.cache = cache;
this.maxNumberOfNodes = options.getMaxNumberOfNodes();
}
/**
@ -90,6 +90,7 @@ public class ExplicitCallGraph extends BasicCallGraph implements BytecodeConstan
/**
* subclasses may wish to override!
*
* @throws CancelException
*/
@Override
@ -99,6 +100,7 @@ public class ExplicitCallGraph extends BasicCallGraph implements BytecodeConstan
/**
* subclasses may wish to override!
*
* @throws CancelException
*/
@Override
@ -132,8 +134,8 @@ public class ExplicitCallGraph extends BasicCallGraph implements BytecodeConstan
public class ExplicitNode extends NodeImpl {
/**
* A Mapping from call site program counter (int) -> Object, where Object is a CGNode if we've discovered exactly
* one target for the site, or an IntSet of node numbers if we've discovered more than one target for the site.
* A Mapping from call site program counter (int) -> Object, where Object is a CGNode if we've discovered exactly one target for
* the site, or an IntSet of node numbers if we've discovered more than one target for the site.
*/
protected final SparseVector<Object> targets = new SparseVector<Object>();
@ -258,9 +260,7 @@ public class ExplicitCallGraph extends BasicCallGraph implements BytecodeConstan
if (s.size() > 2) {
s.remove(n);
} else {
if (Assertions.verifyAssertions) {
assert s.size() == 2;
}
assert s.size() == 2;
if (s.contains(n)) {
s.remove(n);
int i = s.intIterator().next();

View File

@ -20,7 +20,6 @@ import com.ibm.wala.classLoader.IClass;
import com.ibm.wala.classLoader.IField;
import com.ibm.wala.classLoader.IMethod;
import com.ibm.wala.classLoader.SyntheticClass;
import com.ibm.wala.ipa.cha.ClassHierarchyException;
import com.ibm.wala.ipa.cha.IClassHierarchy;
import com.ibm.wala.types.ClassLoaderReference;
import com.ibm.wala.types.FieldReference;

View File

@ -16,21 +16,19 @@ import com.ibm.wala.ipa.callgraph.CGNode;
import com.ibm.wala.util.debug.Assertions;
/**
* Abstract base class for {@link InstanceKey} which represents at least some
* {@link IClass} in some {@link CGNode}
* Abstract base class for {@link InstanceKey} which represents at least some {@link IClass} in some {@link CGNode}
*/
public abstract class AbstractTypeInNode implements InstanceKeyWithNode {
private final IClass type;
private final CGNode node;
public AbstractTypeInNode(CGNode node, IClass type) {
if (node == null) {
throw new IllegalArgumentException("null node");
}
if (Assertions.verifyAssertions) {
if (type != null && type.isInterface()) {
Assertions.UNREACHABLE("unexpected type: " + type);
}
if (type != null && type.isInterface()) {
Assertions.UNREACHABLE("unexpected type: " + type);
}
this.node = node;
this.type = type;
@ -60,4 +58,3 @@ public abstract class AbstractTypeInNode implements InstanceKeyWithNode {
}
}

View File

@ -21,8 +21,8 @@ import com.ibm.wala.types.TypeReference;
import com.ibm.wala.util.debug.Assertions;
/**
* This class provides Instance Key call backs where each instance is in the same equivalence class as all other
* instances of the same concrete type.
* This class provides Instance Key call backs where each instance is in the same equivalence class as all other instances of the
* same concrete type.
*
* @author sfink
*/
@ -62,10 +62,9 @@ public class ClassBasedInstanceKeys implements InstanceKeyFactory {
/**
* @see com.ibm.wala.ipa.callgraph.propagation.InstanceKeyFactory#getInstanceKeyForMultiNewArray(com.ibm.wala.ipa.callgraph.CGNode,
* com.ibm.wala.classLoader.NewSiteReference, int)
*
* dim == 0 represents the first dimension, e.g., the [Object; instances in [[Object; e.g., the [[Object; instances in
* [[[Object; dim == 1 represents the second dimension, e.g., the [Object instances in [[[Object;
* com.ibm.wala.classLoader.NewSiteReference, int) dim == 0 represents the first dimension, e.g., the [Object; instances in
* [[Object; e.g., the [[Object; instances in [[[Object; dim == 1 represents the second dimension, e.g., the [Object
* instances in [[[Object;
*/
public InstanceKey getInstanceKeyForMultiNewArray(CGNode node, NewSiteReference allocation, int dim) {
if (DEBUG) {
@ -76,15 +75,13 @@ public class ClassBasedInstanceKeys implements InstanceKeyFactory {
if (DEBUG) {
System.err.println(("type: " + type));
}
if (Assertions.verifyAssertions) {
if (type == null) {
assert type != null : "null type for " + allocation;
}
if (type == null) {
assert type != null : "null type for " + allocation;
}
int i = 0;
while (i <= dim) {
i++;
if (Assertions.verifyAssertions && type == null) {
if (type == null) {
Assertions.UNREACHABLE();
}
type = (ArrayClass) type.getElementClass();

View File

@ -30,10 +30,8 @@ public final class ConcreteTypeKey implements InstanceKey {
if (type == null) {
throw new IllegalArgumentException("type is null");
}
if (Assertions.verifyAssertions) {
if (type.isInterface()) {
Assertions.UNREACHABLE("unexpected interface: " + type);
}
if (type.isInterface()) {
Assertions.UNREACHABLE("unexpected interface: " + type);
}
this.type = type;
}
@ -70,13 +68,10 @@ public final class ConcreteTypeKey implements InstanceKey {
}
/**
* @param pei
* a PEI instruction
* @param cha
* governing class hierarchy
* @return a set of ConcreteTypeKeys that represent the exceptions the PEI may
* throw.
* @throws IllegalArgumentException if pei is null
* @param pei a PEI instruction
* @param cha governing class hierarchy
* @return a set of ConcreteTypeKeys that represent the exceptions the PEI may throw.
* @throws IllegalArgumentException if pei is null
*/
public static InstanceKey[] getInstanceKeysForPEI(SSAInstruction pei, IR ir, IClassHierarchy cha) {
if (pei == null) {
@ -89,13 +84,9 @@ public final class ConcreteTypeKey implements InstanceKey {
}
InstanceKey[] result = new InstanceKey[types.size()];
int i = 0;
for (Iterator it = types.iterator(); it.hasNext(); ) {
TypeReference type = (TypeReference)it.next();
if (Assertions.verifyAssertions) {
if (type == null) {
assert type != null;
}
}
for (Iterator it = types.iterator(); it.hasNext();) {
TypeReference type = (TypeReference) it.next();
assert type != null;
IClass klass = cha.lookupClass(type);
result[i++] = new ConcreteTypeKey(klass);
}

View File

@ -14,18 +14,13 @@ import java.util.Collection;
import com.ibm.wala.classLoader.ArrayClass;
import com.ibm.wala.classLoader.IClass;
import com.ibm.wala.ipa.cha.ClassHierarchyException;
import com.ibm.wala.types.ClassLoaderReference;
import com.ibm.wala.types.TypeName;
import com.ibm.wala.types.TypeReference;
import com.ibm.wala.util.collections.HashSetFactory;
import com.ibm.wala.util.debug.Assertions;
/**
*
* Utilities for container class analysis
*
* @author sfink
*/
public class ContainerUtil {
@ -56,10 +51,8 @@ public class ContainerUtil {
IClass collection = c.getClassHierarchy().lookupClass(TypeReference.JavaUtilCollection);
IClass map = c.getClassHierarchy().lookupClass(TypeReference.JavaUtilMap);
if (c.isInterface()) {
if (Assertions.verifyAssertions) {
assert collection != null;
assert map != null;
}
assert collection != null;
assert map != null;
Collection s;
s = c.getAllImplementedInterfaces();
if (s.contains(collection) || s.contains(map)) {

View File

@ -11,12 +11,9 @@
package com.ibm.wala.ipa.callgraph.propagation;
import com.ibm.wala.ipa.callgraph.CGNode;
import com.ibm.wala.util.debug.Assertions;
/**
* a local pointer key that carries a type filter
*
* @author sfink
*/
public class LocalPointerKeyWithFilter extends LocalPointerKey implements FilteredPointerKey {
@ -24,9 +21,7 @@ public class LocalPointerKeyWithFilter extends LocalPointerKey implements Filter
public LocalPointerKeyWithFilter(CGNode node, int valueNumber, TypeFilter typeFilter) {
super(node,valueNumber);
if (Assertions.verifyAssertions) {
assert typeFilter != null;
}
this.typeFilter = typeFilter;
}

View File

@ -114,12 +114,12 @@ public class PointerAnalysisImpl extends AbstractPointerAnalysis {
if (pointsToMap.isImplicit(key)) {
return computeImplicitPointsToSet(key);
}
// special logic to handle contents of char[] from string constants.
if (key instanceof InstanceFieldKey) {
InstanceFieldKey ifk = (InstanceFieldKey)key;
InstanceFieldKey ifk = (InstanceFieldKey) key;
if (ifk.getInstanceKey() instanceof ConstantKey) {
ConstantKey<?> i = (ConstantKey<?>)ifk.getInstanceKey();
ConstantKey<?> i = (ConstantKey<?>) ifk.getInstanceKey();
if (i.getValue() instanceof String) {
StringConstantCharArray contents = StringConstantCharArray.make((ConstantKey<String>) i);
instanceKeys.add(contents);
@ -129,12 +129,10 @@ public class PointerAnalysisImpl extends AbstractPointerAnalysis {
}
}
}
PointsToSetVariable v = pointsToMap.getPointsToSet(key);
if (Assertions.verifyAssertions) {
assert key != null;
}
assert key != null;
if (v == null) {
return OrdinalSet.empty();
@ -145,8 +143,7 @@ public class PointerAnalysisImpl extends AbstractPointerAnalysis {
}
/**
* did the pointer analysis use a type filter for a given points-to set? (this
* is ugly).
* did the pointer analysis use a type filter for a given points-to set? (this is ugly).
*/
public boolean isFiltered(PointerKey key) {
if (pointsToMap.isImplicit(key)) {
@ -162,16 +159,14 @@ public class PointerAnalysisImpl extends AbstractPointerAnalysis {
protected static class ImplicitPointsToSetVisitor extends SSAInstruction.Visitor {
protected final PointerAnalysisImpl analysis;
protected final CGNode node;
protected final LocalPointerKey lpk;
protected OrdinalSet<InstanceKey> pointsToSet = null;
protected ImplicitPointsToSetVisitor(PointerAnalysisImpl analysis,
LocalPointerKey lpk)
{
protected ImplicitPointsToSetVisitor(PointerAnalysisImpl analysis, LocalPointerKey lpk) {
this.lpk = lpk;
this.node = lpk.getNode();
this.analysis = analysis;
@ -184,44 +179,37 @@ public class PointerAnalysisImpl extends AbstractPointerAnalysis {
@Override
public void visitInvoke(SSAInvokeInstruction instruction) {
pointsToSet =
analysis.computeImplicitPointsToSetAtCall(lpk, node, instruction);
pointsToSet = analysis.computeImplicitPointsToSetAtCall(lpk, node, instruction);
}
@Override
public void visitCheckCast(SSACheckCastInstruction instruction) {
pointsToSet =
analysis.computeImplicitPointsToSetAtCheckCast(node, instruction);
pointsToSet = analysis.computeImplicitPointsToSetAtCheckCast(node, instruction);
}
@Override
public void visitGetCaughtException(SSAGetCaughtExceptionInstruction instruction) {
pointsToSet =
analysis.computeImplicitPointsToSetAtCatch(node, instruction);
pointsToSet = analysis.computeImplicitPointsToSetAtCatch(node, instruction);
}
@Override
public void visitGet(SSAGetInstruction instruction) {
pointsToSet =
analysis.computeImplicitPointsToSetAtGet(node, instruction);
pointsToSet = analysis.computeImplicitPointsToSetAtGet(node, instruction);
}
@Override
public void visitPhi(SSAPhiInstruction instruction) {
pointsToSet =
analysis.computeImplicitPointsToSetAtPhi(node, instruction);
pointsToSet = analysis.computeImplicitPointsToSetAtPhi(node, instruction);
}
@Override
public void visitPi(SSAPiInstruction instruction) {
pointsToSet =
analysis.computeImplicitPointsToSetAtPi(node, instruction);
pointsToSet = analysis.computeImplicitPointsToSetAtPi(node, instruction);
}
@Override
public void visitArrayLoad(SSAArrayLoadInstruction instruction) {
pointsToSet =
analysis.computeImplicitPointsToSetAtALoad(node, instruction);
pointsToSet = analysis.computeImplicitPointsToSetAtALoad(node, instruction);
}
};
@ -441,8 +429,7 @@ public class PointerAnalysisImpl extends AbstractPointerAnalysis {
}
/**
* @return the points-to set for the exceptional return values from a
* particular call site
* @return the points-to set for the exceptional return values from a particular call site
*/
private OrdinalSet<InstanceKey> computeImplicitExceptionsForCall(CGNode node, SSAInvokeInstruction call) {
MutableSparseIntSet S = MutableSparseIntSet.makeEmpty();
@ -491,8 +478,7 @@ public class PointerAnalysisImpl extends AbstractPointerAnalysis {
}
/*
* @see com.ibm.wala.ipa.callgraph.propagation.PointerKeyFactory#getPointerKeyForLocal(com.ibm.detox.ipa.callgraph.CGNode,
* int)
* @see com.ibm.wala.ipa.callgraph.propagation.PointerKeyFactory#getPointerKeyForLocal(com.ibm.detox.ipa.callgraph.CGNode, int)
*/
public PointerKey getPointerKeyForLocal(CGNode node, int valueNumber) {
return pointerKeys.getPointerKeyForLocal(node, valueNumber);
@ -510,22 +496,26 @@ public class PointerAnalysisImpl extends AbstractPointerAnalysis {
}
/*
* @see com.ibm.wala.ipa.callgraph.propagation.PointerKeyFactory#getPointerKeyForExceptionalReturnValue(com.ibm.detox.ipa.callgraph.CGNode)
* @see
* com.ibm.wala.ipa.callgraph.propagation.PointerKeyFactory#getPointerKeyForExceptionalReturnValue(com.ibm.detox.ipa.callgraph
* .CGNode)
*/
public PointerKey getPointerKeyForExceptionalReturnValue(CGNode node) {
return pointerKeys.getPointerKeyForExceptionalReturnValue(node);
}
/*
* @see com.ibm.wala.ipa.callgraph.propagation.PointerKeyFactory#getPointerKeyForStaticField(com.ibm.wala.classLoader.FieldReference)
* @see
* com.ibm.wala.ipa.callgraph.propagation.PointerKeyFactory#getPointerKeyForStaticField(com.ibm.wala.classLoader.FieldReference)
*/
public PointerKey getPointerKeyForStaticField(IField f) {
return pointerKeys.getPointerKeyForStaticField(f);
}
/*
* @see com.ibm.wala.ipa.callgraph.propagation.PointerKeyFactory#getPointerKeyForInstance(com.ibm.wala.ipa.callgraph.propagation.InstanceKey,
* com.ibm.wala.classLoader.FieldReference)
* @see
* com.ibm.wala.ipa.callgraph.propagation.PointerKeyFactory#getPointerKeyForInstance(com.ibm.wala.ipa.callgraph.propagation.
* InstanceKey, com.ibm.wala.classLoader.FieldReference)
*/
public PointerKey getPointerKeyForInstanceField(InstanceKey I, IField field) {
assert field != null;
@ -533,7 +523,9 @@ public class PointerAnalysisImpl extends AbstractPointerAnalysis {
}
/*
* @see com.ibm.wala.ipa.callgraph.propagation.PointerKeyFactory#getPointerKeyForArrayContents(com.ibm.wala.ipa.callgraph.propagation.InstanceKey)
* @see
* com.ibm.wala.ipa.callgraph.propagation.PointerKeyFactory#getPointerKeyForArrayContents(com.ibm.wala.ipa.callgraph.propagation
* .InstanceKey)
*/
public PointerKey getPointerKeyForArrayContents(InstanceKey I) {
return pointerKeys.getPointerKeyForArrayContents(I);

View File

@ -270,11 +270,9 @@ public class PointsToMap {
if (src.getPointerKey() instanceof FilteredPointerKey) {
FilteredPointerKey fpk = (FilteredPointerKey) src.getPointerKey();
if (dest.getPointerKey() instanceof FilteredPointerKey) {
if (Assertions.verifyAssertions) {
FilteredPointerKey fp = (FilteredPointerKey) dest.getPointerKey();
if (!fp.getTypeFilter().equals(fpk.getTypeFilter())) {
Assertions.UNREACHABLE("src " + fpk.getTypeFilter() + " dest " + fp.getTypeFilter());
}
FilteredPointerKey fp = (FilteredPointerKey) dest.getPointerKey();
if (!fp.getTypeFilter().equals(fpk.getTypeFilter())) {
Assertions.UNREACHABLE("src " + fpk.getTypeFilter() + " dest " + fp.getTypeFilter());
}
} else {
upgradeToFilter(dest, fpk.getTypeFilter());

View File

@ -30,8 +30,7 @@ import com.ibm.wala.util.intset.MutableSparseIntSet;
public class PointsToSetVariable extends IntSetVariable<PointsToSetVariable> {
/**
* if set, check that all instance keys in a points-to set are consistent with the type of the corresponding pointer
* key
* if set, check that all instance keys in a points-to set are consistent with the type of the corresponding pointer key
*/
public static final boolean PARANOID = false;
@ -141,9 +140,7 @@ public class PointsToSetVariable extends IntSetVariable<PointsToSetVariable> {
*/
void setPointerKey(PointerKey pointerKey) {
// check that we haven't modified the hash code!!! this is crucial
if (Assertions.verifyAssertions) {
assert this.pointerKey.hashCode() == pointerKey.hashCode();
}
assert this.pointerKey.hashCode() == pointerKey.hashCode();
this.pointerKey = pointerKey;
}

View File

@ -24,7 +24,6 @@ import com.ibm.wala.fixedpoint.impl.UnaryStatement;
import com.ibm.wala.fixpoint.IVariable;
import com.ibm.wala.util.collections.HashSetFactory;
import com.ibm.wala.util.collections.Iterator2Collection;
import com.ibm.wala.util.debug.Assertions;
import com.ibm.wala.util.graph.Graph;
import com.ibm.wala.util.graph.NumberedGraph;
import com.ibm.wala.util.intset.BimodalMutableIntSet;
@ -219,9 +218,7 @@ public class PreTransitiveSolver extends AbstractPointsToSolver {
}
public void remove(int number) {
if (Assertions.verifyAssertions) {
assert sequence.get(sequence.size() - 1).intValue() == number;
}
assert sequence.get(sequence.size() - 1).intValue() == number;
sequence.remove(sequence.size() - 1);
contents.remove(number);
}

View File

@ -51,8 +51,8 @@ import com.ibm.wala.util.warnings.Warning;
import com.ibm.wala.util.warnings.Warnings;
/**
* This abstract base class provides the general algorithm for a call graph builder that relies on propagation through
* an iterative dataflow solver
* This abstract base class provides the general algorithm for a call graph builder that relies on propagation through an iterative
* dataflow solver
*
* TODO: This implementation currently keeps all points to sets live ... even those for local variables that do not span
* interprocedural boundaries. This may be too space-inefficient .. we can consider recomputing local sets on demand.
@ -183,10 +183,8 @@ public abstract class PropagationCallGraphBuilder implements CallGraphBuilder {
this.cha = cha;
this.options = options;
this.analysisCache = cache;
if (Assertions.verifyAssertions) {
// we need pointer keys to handle reflection
assert pointerKeyFactory != null;
}
// we need pointer keys to handle reflection
assert pointerKeyFactory != null;
this.pointerKeyFactory = pointerKeyFactory;
callGraph = createEmptyCallGraph(cha, options);
try {
@ -308,8 +306,8 @@ public abstract class PropagationCallGraphBuilder implements CallGraphBuilder {
protected abstract boolean addConstraintsFromNode(CGNode n);
/**
* Add constraints from newly discovered nodes. Note: the act of adding constraints may discover new nodes, so this
* routine is iterative.
* Add constraints from newly discovered nodes. Note: the act of adding constraints may discover new nodes, so this routine is
* iterative.
*
* @return true iff any new constraints are added.
*/
@ -327,21 +325,19 @@ public abstract class PropagationCallGraphBuilder implements CallGraphBuilder {
}
/**
* @return the PointerKey that acts as a representative for the class of pointers that includes the local variable
* identified by the value number parameter.
* @return the PointerKey that acts as a representative for the class of pointers that includes the local variable identified by
* the value number parameter.
*/
public PointerKey getPointerKeyForLocal(CGNode node, int valueNumber) {
return pointerKeyFactory.getPointerKeyForLocal(node, valueNumber);
}
/**
* @return the PointerKey that acts as a representative for the class of pointers that includes the local variable
* identified by the value number parameter.
* @return the PointerKey that acts as a representative for the class of pointers that includes the local variable identified by
* the value number parameter.
*/
public FilteredPointerKey getFilteredPointerKeyForLocal(CGNode node, int valueNumber, FilteredPointerKey.TypeFilter filter) {
if (Assertions.verifyAssertions) {
assert filter != null;
}
assert filter != null;
return pointerKeyFactory.getFilteredPointerKeyForLocal(node, valueNumber, filter);
}
@ -354,35 +350,30 @@ public abstract class PropagationCallGraphBuilder implements CallGraphBuilder {
}
/**
* @return the PointerKey that acts as a representative for the class of pointers that includes the return value for a
* node
* @return the PointerKey that acts as a representative for the class of pointers that includes the return value for a node
*/
public PointerKey getPointerKeyForReturnValue(CGNode node) {
return pointerKeyFactory.getPointerKeyForReturnValue(node);
}
/**
* @return the PointerKey that acts as a representative for the class of pointers that includes the exceptional return
* value
* @return the PointerKey that acts as a representative for the class of pointers that includes the exceptional return value
*/
public PointerKey getPointerKeyForExceptionalReturnValue(CGNode node) {
return pointerKeyFactory.getPointerKeyForExceptionalReturnValue(node);
}
/**
* @return the PointerKey that acts as a representative for the class of pointers that includes the contents of the
* static field
* @return the PointerKey that acts as a representative for the class of pointers that includes the contents of the static field
*/
public PointerKey getPointerKeyForStaticField(IField f) {
if (Assertions.verifyAssertions) {
assert f != null : "null FieldReference";
}
assert f != null : "null FieldReference";
return pointerKeyFactory.getPointerKeyForStaticField(f);
}
/**
* @return the PointerKey that acts as a representation for the class of pointers that includes the given instance
* field. null if there's some problem.
* @return the PointerKey that acts as a representation for the class of pointers that includes the given instance field. null if
* there's some problem.
* @throws IllegalArgumentException if I is null
* @throws IllegalArgumentException if field is null
*/
@ -408,19 +399,17 @@ public abstract class PropagationCallGraphBuilder implements CallGraphBuilder {
* TODO: expand this API to differentiate between different array indices
*
* @param I an InstanceKey representing an abstract array
* @return the PointerKey that acts as a representation for the class of pointers that includes the given array
* contents, or null if none found.
* @return the PointerKey that acts as a representation for the class of pointers that includes the given array contents, or null
* if none found.
* @throws IllegalArgumentException if I is null
*/
public PointerKey getPointerKeyForArrayContents(InstanceKey I) {
if (I == null) {
throw new IllegalArgumentException("I is null");
}
if (Assertions.verifyAssertions) {
IClass C = I.getConcreteType();
if (!C.isArrayClass()) {
assert false : "illegal arguments: " + I;
}
IClass C = I.getConcreteType();
if (!C.isArrayClass()) {
assert false : "illegal arguments: " + I;
}
return pointerKeyFactory.getPointerKeyForArrayContents(I);
}
@ -498,19 +487,15 @@ public abstract class PropagationCallGraphBuilder implements CallGraphBuilder {
private final PointerKey base;
static TypedPointerKey make(PointerKey base, IClass type) {
if (Assertions.verifyAssertions) {
assert type != null;
}
assert type != null;
return new TypedPointerKey(base, type);
}
private TypedPointerKey(PointerKey base, IClass type) {
this.type = type;
this.base = base;
if (Assertions.verifyAssertions) {
assert type != null;
assert !(type instanceof FilteredPointerKey);
}
assert type != null;
assert !(type instanceof FilteredPointerKey);
}
/*
@ -581,9 +566,9 @@ public abstract class PropagationCallGraphBuilder implements CallGraphBuilder {
}
/**
* The FilterOperator is a filtered set-union. i.e. the LHS is `unioned' with the RHS, but filtered by the set
* associated with this operator instance. The filter is the set of InstanceKeys corresponding to the target type of
* this cast. This is still monotonic.
* The FilterOperator is a filtered set-union. i.e. the LHS is `unioned' with the RHS, but filtered by the set associated with
* this operator instance. The filter is the set of InstanceKeys corresponding to the target type of this cast. This is still
* monotonic.
*
* LHS U= (RHS n k)
*
@ -601,8 +586,7 @@ public abstract class PropagationCallGraphBuilder implements CallGraphBuilder {
}
/*
* @see com.ibm.wala.dataflow.UnaryOperator#evaluate(com.ibm.wala.dataflow.IVariable,
* com.ibm.wala.dataflow.IVariable)
* @see com.ibm.wala.dataflow.UnaryOperator#evaluate(com.ibm.wala.dataflow.IVariable, com.ibm.wala.dataflow.IVariable)
*/
@Override
public byte evaluate(PointsToSetVariable lhs, PointsToSetVariable rhs) {
@ -743,19 +727,19 @@ public abstract class PropagationCallGraphBuilder implements CallGraphBuilder {
}
/**
* @return the InstanceKey that acts as a representative for the class of objects that includes objects allocated at
* the given new instruction in the given node
* @return the InstanceKey that acts as a representative for the class of objects that includes objects allocated at the given new
* instruction in the given node
*/
public InstanceKey getInstanceKeyForAllocation(CGNode node, NewSiteReference allocation) {
return instanceKeyFactory.getInstanceKeyForAllocation(node, allocation);
}
/**
* @param dim the dimension of the array whose instance we would like to model. dim == 0 represents the first
* dimension, e.g., the [Object; instances in [[Object; e.g., the [[Object; instances in [[[Object; dim == 1
* represents the second dimension, e.g., the [Object instances in [[[Object;
* @return the InstanceKey that acts as a representative for the class of array contents objects that includes objects
* allocated at the given new instruction in the given node
* @param dim the dimension of the array whose instance we would like to model. dim == 0 represents the first dimension, e.g., the
* [Object; instances in [[Object; e.g., the [[Object; instances in [[[Object; dim == 1 represents the second dimension,
* e.g., the [Object instances in [[[Object;
* @return the InstanceKey that acts as a representative for the class of array contents objects that includes objects allocated
* at the given new instruction in the given node
*/
public InstanceKey getInstanceKeyForMultiNewArray(CGNode node, NewSiteReference allocation, int dim) {
return instanceKeyFactory.getInstanceKeyForMultiNewArray(node, allocation, dim);
@ -927,10 +911,8 @@ public abstract class PropagationCallGraphBuilder implements CallGraphBuilder {
continue;
}
IClass contents = getClassHierarchy().lookupClass(C);
if (Assertions.verifyAssertions) {
if (contents == null) {
assert false : "null type for " + C + " " + I.getConcreteType();
}
if (contents == null) {
assert false : "null type for " + C + " " + I.getConcreteType();
}
PointerKey p = getPointerKeyForArrayContents(I);
if (DEBUG_ARRAY_STORE) {
@ -1309,10 +1291,8 @@ public abstract class PropagationCallGraphBuilder implements CallGraphBuilder {
return;
}
IClass contents = getClassHierarchy().lookupClass(C);
if (Assertions.verifyAssertions) {
if (contents == null) {
assert false : "null type for " + C + " " + I.getConcreteType();
}
if (contents == null) {
assert false : "null type for " + C + " " + I.getConcreteType();
}
PointerKey p = getPointerKeyForArrayContents(I);
if (contents.isInterface()) {
@ -1414,8 +1394,7 @@ public abstract class PropagationCallGraphBuilder implements CallGraphBuilder {
/*
* simply check if rhs contains a malleable.
*
* @see com.ibm.wala.dataflow.UnaryOperator#evaluate(com.ibm.wala.dataflow.IVariable,
* com.ibm.wala.dataflow.IVariable)
* @see com.ibm.wala.dataflow.UnaryOperator#evaluate(com.ibm.wala.dataflow.IVariable, com.ibm.wala.dataflow.IVariable)
*/
@Override
public byte evaluate(PointsToSetVariable lhs, PointsToSetVariable rhs) {

View File

@ -143,9 +143,7 @@ public class PropagationGraph implements IFixedPointSystem<PointsToSetVariable>
}
public void addEquation(AbstractStatement<PointsToSetVariable, ?> eq) {
if (Assertions.verifyAssertions) {
assert !containsStatement(eq);
}
assert !containsStatement(eq);
equationCount++;
super.addNode(eq);
}
@ -236,10 +234,8 @@ public class PropagationGraph implements IFixedPointSystem<PointsToSetVariable>
}
public void removeVariable(PointsToSetVariable p) {
if (Assertions.verifyAssertions) {
assert getNumberOfStatementsThatDef(p) == 0;
assert getNumberOfStatementsThatUse(p) == 0;
}
assert getNumberOfStatementsThatDef(p) == 0;
assert getNumberOfStatementsThatUse(p) == 0;
delegateGraph.removeNode(p);
}
@ -856,7 +852,8 @@ public class PropagationGraph implements IFixedPointSystem<PointsToSetVariable>
}
/**
* NOTE: do not use this method unless you really know what you are doing. Functionality is fragile and may not work in the future.
* NOTE: do not use this method unless you really know what you are doing. Functionality is fragile and may not work in the
* future.
*/
public Graph<PointsToSetVariable> getFlowGraphIncludingImplicitConstraints() {
return new VariableGraphView();

View File

@ -164,9 +164,7 @@ public class PropagationSystem extends DefaultFixedPointSolver<PointsToSetVariab
* Keep this method private .. this returns the actual backing set for the class, which we do not want to expose to clients.
*/
private MutableIntSet findOrCreateSparseSetForClass(IClass klass) {
if (Assertions.verifyAssertions) {
assert klass.getReference() != TypeReference.JavaLangObject;
}
assert klass.getReference() != TypeReference.JavaLangObject;
MutableIntSet result = class2InstanceKey.get(klass);
if (result == null) {
result = IntSetUtil.getDefaultIntSetFactory().make();
@ -180,9 +178,7 @@ public class PropagationSystem extends DefaultFixedPointSolver<PointsToSetVariab
* the caller may bash at will.
*/
MutableIntSet cloneInstanceKeysForClass(IClass klass) {
if (Assertions.verifyAssertions) {
assert klass.getReference() != TypeReference.JavaLangObject;
}
assert klass.getReference() != TypeReference.JavaLangObject;
MutableIntSet set = class2InstanceKey.get(klass);
if (set == null) {
return IntSetUtil.getDefaultIntSetFactory().make();
@ -200,9 +196,7 @@ public class PropagationSystem extends DefaultFixedPointSolver<PointsToSetVariab
if (klass == null) {
throw new IllegalArgumentException("klass is null");
}
if (Assertions.verifyAssertions) {
assert klass.getReference() != TypeReference.JavaLangObject;
}
assert klass.getReference() != TypeReference.JavaLangObject;
return class2InstanceKey.get(klass);
}
@ -241,15 +235,13 @@ public class PropagationSystem extends DefaultFixedPointSolver<PointsToSetVariab
if (key == null) {
throw new IllegalArgumentException("null key");
}
if (Assertions.verifyAssertions) {
if (key instanceof LocalPointerKey) {
LocalPointerKey lpk = (LocalPointerKey) key;
if (lpk.isParameter()) {
System.err.println(lpk);
System.err.println("Constant? " + lpk.getNode().getIR().getSymbolTable().isConstant(lpk.getValueNumber()));
System.err.println(lpk.getNode().getIR());
Assertions.UNREACHABLE("How can parameter be implicit?");
}
if (key instanceof LocalPointerKey) {
LocalPointerKey lpk = (LocalPointerKey) key;
if (lpk.isParameter()) {
System.err.println(lpk);
System.err.println("Constant? " + lpk.getNode().getIR().getSymbolTable().isConstant(lpk.getValueNumber()));
System.err.println(lpk.getNode().getIR());
Assertions.UNREACHABLE("How can parameter be implicit?");
}
}
pointsToMap.recordImplicit(key);
@ -267,12 +259,10 @@ public class PropagationSystem extends DefaultFixedPointSolver<PointsToSetVariab
throw new IllegalArgumentException("null key");
}
if (Assertions.verifyAssertions) {
if (pointsToMap.isImplicit(key)) {
System.err.println("Did not expect to findOrCreatePointsToSet for implicitly represented PointerKey");
System.err.println(key);
Assertions.UNREACHABLE();
}
if (pointsToMap.isImplicit(key)) {
System.err.println("Did not expect to findOrCreatePointsToSet for implicitly represented PointerKey");
System.err.println(key);
Assertions.UNREACHABLE();
}
PointsToSetVariable result = pointsToMap.getPointsToSet(key);
if (result == null) {
@ -290,21 +280,19 @@ public class PropagationSystem extends DefaultFixedPointSolver<PointsToSetVariab
result.setPointerKey(key);
pk = key;
}
if (Assertions.verifyAssertions) {
FilteredPointerKey fpk = (FilteredPointerKey) pk;
if (fpk == null) {
Assertions.UNREACHABLE("fpk is null");
}
if (key == null) {
Assertions.UNREACHABLE("key is null");
}
if (fpk.getTypeFilter() == null) {
Assertions.UNREACHABLE("fpk.getTypeFilter() is null");
}
if (!fpk.getTypeFilter().equals(((FilteredPointerKey) key).getTypeFilter())) {
Assertions.UNREACHABLE("Cannot use filter " + ((FilteredPointerKey) key).getTypeFilter() + " for " + key
+ ": previously created different filter " + fpk.getTypeFilter());
}
FilteredPointerKey fpk = (FilteredPointerKey) pk;
if (fpk == null) {
Assertions.UNREACHABLE("fpk is null");
}
if (key == null) {
Assertions.UNREACHABLE("key is null");
}
if (fpk.getTypeFilter() == null) {
Assertions.UNREACHABLE("fpk.getTypeFilter() is null");
}
if (!fpk.getTypeFilter().equals(((FilteredPointerKey) key).getTypeFilter())) {
Assertions.UNREACHABLE("Cannot use filter " + ((FilteredPointerKey) key).getTypeFilter() + " for " + key
+ ": previously created different filter " + fpk.getTypeFilter());
}
}
}
@ -348,11 +336,9 @@ public class PropagationSystem extends DefaultFixedPointSolver<PointsToSetVariab
// we instead want to check in the outer loop of the pre-transitive
// solver if the value of L changes.
pointsToMap.recordTransitiveRoot(L.getPointerKey());
if (Assertions.verifyAssertions) {
if (!(L.getPointerKey() instanceof FilteredPointerKey)) {
Assertions.UNREACHABLE("expected filtered lhs " + L.getPointerKey() + " " + L.getPointerKey().getClass() + " " + lhs
+ " " + lhs.getClass());
}
if (!(L.getPointerKey() instanceof FilteredPointerKey)) {
Assertions.UNREACHABLE("expected filtered lhs " + L.getPointerKey() + " " + L.getPointerKey().getClass() + " " + lhs + " "
+ lhs.getClass());
}
}
return newStatement(L, op, R, true, true);
@ -371,10 +357,8 @@ public class PropagationSystem extends DefaultFixedPointSolver<PointsToSetVariab
if (DEBUG) {
System.err.println("Add constraint A: " + lhs + " " + op + " " + rhs);
}
if (Assertions.verifyAssertions) {
assert !pointsToMap.isUnified(lhs);
assert !pointsToMap.isUnified(rhs);
}
assert !pointsToMap.isUnified(lhs);
assert !pointsToMap.isUnified(rhs);
PointsToSetVariable L = findOrCreatePointsToSet(lhs);
PointsToSetVariable R = findOrCreatePointsToSet(rhs);
newStatement(L, op, new PointsToSetVariable[] { R }, true, true);
@ -396,11 +380,9 @@ public class PropagationSystem extends DefaultFixedPointSolver<PointsToSetVariab
if (DEBUG) {
System.err.println("Add constraint A: " + lhs + " " + op + " " + rhs1 + ", " + rhs2);
}
if (Assertions.verifyAssertions) {
assert !pointsToMap.isUnified(lhs);
assert !pointsToMap.isUnified(rhs1);
assert !pointsToMap.isUnified(rhs2);
}
assert !pointsToMap.isUnified(lhs);
assert !pointsToMap.isUnified(rhs1);
assert !pointsToMap.isUnified(rhs2);
PointsToSetVariable L = findOrCreatePointsToSet(lhs);
PointsToSetVariable R1 = findOrCreatePointsToSet(rhs1);
PointsToSetVariable R2 = findOrCreatePointsToSet(rhs2);
@ -442,9 +424,7 @@ public class PropagationSystem extends DefaultFixedPointSolver<PointsToSetVariab
L.add(index);
// also register that we have an instanceKey for the klass
if (Assertions.verifyAssertions) {
assert value.getConcreteType() != null;
}
assert value.getConcreteType() != null;
if (!value.getConcreteType().getReference().equals(TypeReference.JavaLangObject)) {
registerInstanceOfClass(value.getConcreteType(), index);
@ -463,9 +443,6 @@ public class PropagationSystem extends DefaultFixedPointSolver<PointsToSetVariab
/**
* Record that we have a new instanceKey for a given declared type.
*
* @param klass
* @param index
*/
private void registerInstanceOfClass(IClass klass, int index) {
@ -473,9 +450,7 @@ public class PropagationSystem extends DefaultFixedPointSolver<PointsToSetVariab
System.err.println("registerInstanceOfClass " + klass + " " + index);
}
if (Assertions.verifyAssertions) {
assert !klass.getReference().equals(TypeReference.JavaLangObject);
}
assert !klass.getReference().equals(TypeReference.JavaLangObject);
try {
IClass T = klass;
@ -592,9 +567,7 @@ public class PropagationSystem extends DefaultFixedPointSolver<PointsToSetVariab
if (DEBUG) {
System.err.println("add constraint D: " + op + " " + arg0);
}
if (Assertions.verifyAssertions) {
assert !pointsToMap.isUnified(arg0);
}
assert !pointsToMap.isUnified(arg0);
PointsToSetVariable v1 = findOrCreatePointsToSet(arg0);
newStatement(null, op, v1, true, true);
}
@ -603,10 +576,8 @@ public class PropagationSystem extends DefaultFixedPointSolver<PointsToSetVariab
if (DEBUG) {
System.err.println("add constraint D: " + op + " " + arg0);
}
if (Assertions.verifyAssertions) {
assert !pointsToMap.isUnified(arg0);
assert !pointsToMap.isUnified(arg1);
}
assert !pointsToMap.isUnified(arg0);
assert !pointsToMap.isUnified(arg1);
PointsToSetVariable v1 = findOrCreatePointsToSet(arg0);
PointsToSetVariable v2 = findOrCreatePointsToSet(arg1);
newStatement(null, op, v1, v2, true, true);
@ -880,9 +851,7 @@ public class PropagationSystem extends DefaultFixedPointSolver<PointsToSetVariab
private void replaceRHS(PointsToSetVariable pRef, PointsToSetVariable p,
AbstractStatement<PointsToSetVariable, AbstractOperator<PointsToSetVariable>> as) {
if (as instanceof UnaryStatement) {
if (Assertions.verifyAssertions) {
assert ((UnaryStatement) as).getRightHandSide() == p;
}
assert ((UnaryStatement) as).getRightHandSide() == p;
newStatement(as.getLHS(), (UnaryOperator<PointsToSetVariable>) as.getOperator(), pRef, false, false);
} else {
IVariable[] rhs = as.getRHS();
@ -906,9 +875,7 @@ public class PropagationSystem extends DefaultFixedPointSolver<PointsToSetVariab
*/
private void replaceLHS(PointsToSetVariable pRef, PointsToSetVariable p,
AbstractStatement<PointsToSetVariable, AbstractOperator<PointsToSetVariable>> as) {
if (Assertions.verifyAssertions) {
assert as.getLHS() == p;
}
assert as.getLHS() == p;
if (as instanceof UnaryStatement) {
newStatement(pRef, (UnaryOperator<PointsToSetVariable>) as.getOperator(), (PointsToSetVariable) ((UnaryStatement) as)
.getRightHandSide(), false, false);

View File

@ -291,9 +291,7 @@ public abstract class SSAPropagationCallGraphBuilder extends PropagationCallGrap
break;
}
}
if (DEBUG && Assertions.verifyAssertions) {
assert n < cfg.getPredNodeCount(sb);
}
assert n < cfg.getPredNodeCount(sb);
for (Iterator<? extends SSAInstruction> phis = sb.iteratePhis(); phis.hasNext();) {
SSAPhiInstruction phi = (SSAPhiInstruction) phis.next();
if (phi == null) {
@ -399,11 +397,7 @@ public abstract class SSAPropagationCallGraphBuilder extends PropagationCallGrap
if (ik == null) {
continue;
}
if (Assertions.verifyAssertions) {
if (!(ik instanceof ConcreteTypeKey)) {
assert ik instanceof ConcreteTypeKey : "uh oh: need to implement getCaughtException constraints for instance " + ik;
}
}
assert ik instanceof ConcreteTypeKey : "uh oh: need to implement getCaughtException constraints for instance " + ik;
ConcreteTypeKey ck = (ConcreteTypeKey) ik;
IClass klass = ck.getType();
if (PropagationCallGraphBuilder.catches(catchClasses, klass, cha)) {
@ -447,9 +441,7 @@ public abstract class SSAPropagationCallGraphBuilder extends PropagationCallGrap
throw new IllegalArgumentException("ir == null");
}
ISSABasicBlock[] bb = ir.getBasicBlocksForCall(call.getCallSite());
if (Assertions.verifyAssertions) {
assert bb.length == 1;
}
assert bb.length == 1;
SSACFG.BasicBlock cb = (BasicBlock) ir.getControlFlowGraph().getExceptionalSuccessors(bb[0]).iterator().next();
if (cb.isExitBlock()) {
return getPointerKeyForExceptionalReturnValue(node);
@ -553,9 +545,7 @@ public abstract class SSAPropagationCallGraphBuilder extends PropagationCallGrap
this.du = builder.getCFAContextInterpreter().getDU(node);
if (Assertions.verifyAssertions) {
assert symbolTable != null;
}
assert symbolTable != null;
}
protected SSAPropagationCallGraphBuilder getBuilder() {
@ -679,10 +669,8 @@ public abstract class SSAPropagationCallGraphBuilder extends PropagationCallGrap
}
}
} else {
if (Assertions.verifyAssertions) {
assert !system.isUnified(result);
assert !system.isUnified(arrayRefPtrKey);
}
assert !system.isUnified(result);
assert !system.isUnified(arrayRefPtrKey);
system.newSideEffect(getBuilder().new ArrayLoadOperator(system.findOrCreatePointsToSet(result)), arrayRefPtrKey);
}
}
@ -736,9 +724,7 @@ public abstract class SSAPropagationCallGraphBuilder extends PropagationCallGrap
InstanceKey[] ik = getInvariantContents(value);
for (int i = 0; i < ik.length; i++) {
system.findOrCreateIndexForInstanceKey(ik[i]);
if (Assertions.verifyAssertions) {
assert !system.isUnified(arrayRefPtrKey);
}
assert !system.isUnified(arrayRefPtrKey);
system.newSideEffect(getBuilder().new InstanceArrayStoreOperator(ik[i]), arrayRefPtrKey);
}
} else {
@ -859,9 +845,7 @@ public abstract class SSAPropagationCallGraphBuilder extends PropagationCallGrap
return;
}
PointerKey def = getPointerKeyForLocal(lval);
if (Assertions.verifyAssertions) {
assert def != null;
}
assert def != null;
IField f = getClassHierarchy().resolveField(field);
if (f == null && callGraph.getFakeRootNode().getMethod().getDeclaringClass().getReference().equals(field.getDeclaringClass())) {
@ -934,9 +918,7 @@ public abstract class SSAPropagationCallGraphBuilder extends PropagationCallGrap
Warnings.add(FieldResolutionFailure.create(field));
return;
}
if (Assertions.verifyAssertions) {
assert isStatic || !symbolTable.isStringConstant(ref) : "put to string constant shouldn't be allowed?";
}
assert isStatic || !symbolTable.isStringConstant(ref) : "put to string constant shouldn't be allowed?";
if (isStatic) {
processPutStatic(rval, field, f);
} else {
@ -945,9 +927,7 @@ public abstract class SSAPropagationCallGraphBuilder extends PropagationCallGrap
}
private void processPutField(int rval, int ref, IField f) {
if (Assertions.verifyAssertions) {
assert !f.getFieldTypeReference().isPrimitiveType();
}
assert !f.getFieldTypeReference().isPrimitiveType();
PointerKey refKey = getPointerKeyForLocal(ref);
PointerKey rvalKey = getPointerKeyForLocal(rval);
// if (!supportFullPointerFlowGraph &&
@ -1375,9 +1355,7 @@ public abstract class SSAPropagationCallGraphBuilder extends PropagationCallGrap
*/
private void processClassInitializer(IClass klass) {
if (Assertions.verifyAssertions) {
assert klass != null;
}
assert klass != null;
if (!getBuilder().getOptions().getHandleStaticInit()) {
return;
@ -1898,13 +1876,11 @@ public abstract class SSAPropagationCallGraphBuilder extends PropagationCallGrap
private IClass getReceiverClass(IMethod method) {
TypeReference formalType = method.getParameterType(0);
IClass C = getClassHierarchy().lookupClass(formalType);
if (Assertions.verifyAssertions) {
if (method.isStatic()) {
Assertions.UNREACHABLE("asked for receiver of static method " + method);
}
if (C == null) {
Assertions.UNREACHABLE("no class found for " + formalType + " recv of " + method);
}
if (method.isStatic()) {
Assertions.UNREACHABLE("asked for receiver of static method " + method);
}
if (C == null) {
Assertions.UNREACHABLE("no class found for " + formalType + " recv of " + method);
}
return C;
}

View File

@ -15,32 +15,24 @@ import com.ibm.wala.ipa.callgraph.CGNode;
import com.ibm.wala.ipa.callgraph.Context;
import com.ibm.wala.ipa.callgraph.ContextItem;
import com.ibm.wala.ipa.callgraph.ContextKey;
import com.ibm.wala.util.debug.Assertions;
/**
*
* This is a context which is defined by a pair consisting of
* <caller node, base context>.
* This is a {@link Context} which is defined by a pair consisting of <caller node, base context>.
*
* The base context is typically some special case; e.g.,
* a JavaTypeContext used for reflection.
*
* @author sfink
* The base context is typically some special case; e.g., a JavaTypeContext used for reflection.
*/
public class CallerContextPair extends CallerContext {
private final Context baseContext;
/**
* @param caller the node which defines this context.
*/
public CallerContextPair(CGNode caller, Context baseContext) {
super(caller);
this.baseContext = baseContext;
if (Assertions.verifyAssertions) {
// avoid recursive contexts for now.
assert !(baseContext instanceof CallerContextPair);
}
// avoid recursive contexts for now.
assert !(baseContext instanceof CallerContextPair);
}
@Override
@ -61,7 +53,7 @@ public class CallerContextPair extends CallerContext {
return false;
}
if (getClass().equals(obj.getClass())) {
CallerContextPair other = (CallerContextPair)obj;
CallerContextPair other = (CallerContextPair) obj;
return getCaller().equals(other.getCaller()) && baseContext.equals(other.baseContext);
} else {
return false;

View File

@ -15,7 +15,6 @@ import com.ibm.wala.ipa.callgraph.CGNode;
import com.ibm.wala.ipa.callgraph.Context;
import com.ibm.wala.ipa.callgraph.ContextItem;
import com.ibm.wala.ipa.callgraph.ContextKey;
import com.ibm.wala.util.debug.Assertions;
/**
* This is a context which is defined by a pair consisting of <caller node, base context>.
@ -35,10 +34,8 @@ public class CallerSiteContextPair extends CallerSiteContext {
throw new IllegalArgumentException("null caller");
}
this.baseContext = baseContext;
if (Assertions.verifyAssertions) {
// avoid recursive contexts for now.
assert !(baseContext instanceof CallerContextPair);
}
// avoid recursive contexts for now.
assert !(baseContext instanceof CallerContextPair);
}
@Override

View File

@ -33,13 +33,12 @@ import com.ibm.wala.util.strings.Atom;
*
* This context selector returns a context customized for the {@link InstanceKey} of the receiver if
* <ul>
* <li>receiver is a container, or </li>
* was allocated in a node whose context was a {@link ReceiverInstanceContext}, and the type is interesting according
* to a delegate {@link ZeroXInstanceKeys}
* <li>receiver is a container, or</li>
* was allocated in a node whose context was a {@link ReceiverInstanceContext}, and the type is interesting according to a delegate
* {@link ZeroXInstanceKeys}
* </ul>
*
* Additionally, we add one level of call string context to a few well-known static factory methods from the standard
* libraries.
* Additionally, we add one level of call string context to a few well-known static factory methods from the standard libraries.
*
* @author sfink
*/
@ -51,22 +50,32 @@ public class ContainerContextSelector implements ContextSelector {
public final static TypeReference SyntheticSystem = TypeReference.findOrCreate(ClassLoaderReference.Primordial,
SyntheticSystemName);
public final static TypeReference JavaUtilHashtable = TypeReference.findOrCreate(ClassLoaderReference.Primordial, "Ljava/util/Hashtable");
public final static TypeReference JavaUtilHashtable = TypeReference.findOrCreate(ClassLoaderReference.Primordial,
"Ljava/util/Hashtable");
public final static Atom arraycopyAtom = Atom.findOrCreateUnicodeAtom("arraycopy");
private final static Descriptor arraycopyDesc = Descriptor.findOrCreateUTF8("(Ljava/lang/Object;Ljava/lang/Object;)V");
public final static MethodReference synthArraycopy = MethodReference.findOrCreate(SyntheticSystem, arraycopyAtom, arraycopyDesc);
private final static TypeReference Arrays = TypeReference.findOrCreate(ClassLoaderReference.Primordial, "Ljava/util/Arrays");
private final static Atom asList = Atom.findOrCreateUnicodeAtom("asList");
private final static Atom copyOf = Atom.findOrCreateUnicodeAtom("copyOf");
private final static Atom copyOfRange = Atom.findOrCreateUnicodeAtom("copyOfRange");
private final static Atom toString = Atom.findOrCreateUnicodeAtom("toString");
private final static MethodReference StringValueOf = MethodReference.findOrCreate(TypeReference.JavaLangString, "valueOf", "(Ljava/lang/Object;)Ljava/lang/String;");
private final static MethodReference HashtableNewEntry = MethodReference.findOrCreate(JavaUtilHashtable, "newEntry", "(Ljava/lang/Object;Ljava/lang/Object;I)Ljava/util/Hashtable$Entry;");
private final static MethodReference StringValueOf = MethodReference.findOrCreate(TypeReference.JavaLangString, "valueOf",
"(Ljava/lang/Object;)Ljava/lang/String;");
private final static MethodReference HashtableNewEntry = MethodReference.findOrCreate(JavaUtilHashtable, "newEntry",
"(Ljava/lang/Object;Ljava/lang/Object;I)Ljava/util/Hashtable$Entry;");
/**
* The governing class hierarchy.
*/
@ -89,8 +98,10 @@ public class ContainerContextSelector implements ContextSelector {
}
}
/*
* @see com.ibm.wala.ipa.callgraph.ContextSelector#getCalleeTarget(com.ibm.wala.ipa.callgraph.CGNode, com.ibm.wala.classLoader.CallSiteReference, com.ibm.wala.classLoader.IMethod, com.ibm.wala.ipa.callgraph.propagation.InstanceKey)
/*
* @see com.ibm.wala.ipa.callgraph.ContextSelector#getCalleeTarget(com.ibm.wala.ipa.callgraph.CGNode,
* com.ibm.wala.classLoader.CallSiteReference, com.ibm.wala.classLoader.IMethod,
* com.ibm.wala.ipa.callgraph.propagation.InstanceKey)
*/
public Context getCalleeTarget(CGNode caller, CallSiteReference site, IMethod callee, InstanceKey receiver) {
if (DEBUG) {
@ -103,10 +114,8 @@ public class ContainerContextSelector implements ContextSelector {
if (isWellKnownStaticFactory(callee.getReference())) {
return new CallerSiteContext(caller, site);
} else {
if (Assertions.verifyAssertions) {
if (receiver == null) {
Assertions.UNREACHABLE("null receiver for " + site);
}
if (receiver == null) {
Assertions.UNREACHABLE("null receiver for " + site);
}
return new ReceiverInstanceContext(receiver);
}
@ -116,8 +125,8 @@ public class ContainerContextSelector implements ContextSelector {
}
/**
* Does m represent a static factory method we know about from the standard libraries, that we
* usually wish to model with one level of call-string context?
* Does m represent a static factory method we know about from the standard libraries, that we usually wish to model with one
* level of call-string context?
*/
public static boolean isWellKnownStaticFactory(MethodReference m) {
if (isArrayCopyingMethod(m)) {
@ -152,12 +161,12 @@ public class ContainerContextSelector implements ContextSelector {
}
if (isArrayCopyMethod(m)) {
return true;
}
}
return false;
}
/**
* return true iff m represents one of the well-known methods in java.lang.reflect.Arrays that
* do some sort of arraycopy
* return true iff m represents one of the well-known methods in java.lang.reflect.Arrays that do some sort of arraycopy
*/
private static boolean isArrayCopyMethod(MethodReference m) {
if (m.getDeclaringClass().equals(Arrays)) {
@ -167,14 +176,13 @@ public class ContainerContextSelector implements ContextSelector {
}
return false;
}
/**
* return true iff m represents one of the well-known methods in java.lang.reflect.Arrays that
* do toString() on an array
* return true iff m represents one of the well-known methods in java.lang.reflect.Arrays that do toString() on an array
*/
private static boolean isArrayToStringMethod(MethodReference m) {
if (m.getDeclaringClass().equals(Arrays)) {
if (m.getName().equals(toString)){
if (m.getName().equals(toString)) {
return true;
}
}
@ -182,8 +190,8 @@ public class ContainerContextSelector implements ContextSelector {
}
/**
* This method walks recursively up the definition of a context C, to see if the chain of contexts that give rise to C
* a) includes the method M. or b) includes the method in which the receiver was allocated
* This method walks recursively up the definition of a context C, to see if the chain of contexts that give rise to C a) includes
* the method M. or b) includes the method in which the receiver was allocated
*
* @return the matching context if found, null otherwise
*/
@ -206,11 +214,11 @@ public class ContainerContextSelector implements ContextSelector {
}
/**
* This method walks recursively up the definition of a context C, to see if the chain of contexts that give rise to C
* includes the method M.
* This method walks recursively up the definition of a context C, to see if the chain of contexts that give rise to C includes
* the method M.
*
* If C is a ReceiverInstanceContext, Let N be the node that allocated C.instance. If N.method == M, return N. Else
* return findRecursiveMatchingContext(M, N.context) Else return null
* If C is a ReceiverInstanceContext, Let N be the node that allocated C.instance. If N.method == M, return N. Else return
* findRecursiveMatchingContext(M, N.context) Else return null
*/
public static CGNode findNodeRecursiveMatchingContext(IMethod m, Context c) {
if (DEBUG) {
@ -229,7 +237,7 @@ public class ContainerContextSelector implements ContextSelector {
return findNodeRecursiveMatchingContext(m, n.getContext());
}
} else if (c instanceof CallerContext) {
CallerContext cc = (CallerContext)c;
CallerContext cc = (CallerContext) c;
CGNode n = cc.getCaller();
if (n.getMethod().equals(m)) {
return n;
@ -242,11 +250,11 @@ public class ContainerContextSelector implements ContextSelector {
}
/**
* This method walks recursively up the definition of a context C, to see if the chain of contexts that give rise to C
* includes the method M.
* This method walks recursively up the definition of a context C, to see if the chain of contexts that give rise to C includes
* the method M.
*
* If C is a ReceiverInstanceContext, Let N be the node that allocated C.instance. If N.method == M, return N.context.
* Else return findRecursiveMatchingContext(M, N.context) Else return null
* If C is a ReceiverInstanceContext, Let N be the node that allocated C.instance. If N.method == M, return N.context. Else return
* findRecursiveMatchingContext(M, N.context) Else return null
*/
public static Context findRecursiveMatchingContext(IMethod M, Context C) {
CGNode n = findNodeRecursiveMatchingContext(M, C);

View File

@ -22,7 +22,6 @@ import com.ibm.wala.ipa.callgraph.propagation.PointerKey;
import com.ibm.wala.ipa.callgraph.propagation.PointerKeyFactory;
import com.ibm.wala.ipa.callgraph.propagation.ReturnValueKey;
import com.ibm.wala.ipa.callgraph.propagation.StaticFieldKey;
import com.ibm.wala.util.debug.Assertions;
/**
* Default implementation of {@link PointerKeyFactory}
@ -43,11 +42,7 @@ public class DefaultPointerKeyFactory implements PointerKeyFactory {
if (filter == null) {
throw new IllegalArgumentException("null filter");
}
if (Assertions.verifyAssertions) {
if (valueNumber <= 0) {
assert valueNumber > 0 : "illegal value number: " + valueNumber + " in " + node;
}
}
assert valueNumber > 0 : "illegal value number: " + valueNumber + " in " + node;
// TODO: add type filters!
return new LocalPointerKeyWithFilter(node, valueNumber, filter);
}

View File

@ -19,12 +19,9 @@ import com.ibm.wala.ssa.DefUse;
import com.ibm.wala.ssa.IR;
import com.ibm.wala.ssa.ISSABasicBlock;
import com.ibm.wala.ssa.SSAInstruction;
import com.ibm.wala.util.debug.Assertions;
/**
* An {@link SSAContextInterpreter} that first checks with A, then defaults to B.
*
* @author sfink
*/
public class DelegatingSSAContextInterpreter extends DelegatingRTAContextInterpreter implements SSAContextInterpreter {
@ -53,9 +50,7 @@ public class DelegatingSSAContextInterpreter extends DelegatingRTAContextInterpr
return A.getIR(node);
}
}
if (Assertions.verifyAssertions) {
assert B.understands(node);
}
assert B.understands(node);
return B.getIR(node);
}
@ -65,9 +60,7 @@ public class DelegatingSSAContextInterpreter extends DelegatingRTAContextInterpr
return A.getNumberOfStatements(node);
}
}
if (Assertions.verifyAssertions) {
assert B.understands(node);
}
assert B.understands(node);
return B.getNumberOfStatements(node);
}
@ -85,17 +78,14 @@ public class DelegatingSSAContextInterpreter extends DelegatingRTAContextInterpr
result |= B.recordFactoryType(node, klass);
return result;
}
public ControlFlowGraph<SSAInstruction, ISSABasicBlock> getCFG(CGNode node) {
if (A != null) {
if (A.understands(node)) {
return A.getCFG(node);
}
}
if (Assertions.verifyAssertions) {
assert B.understands(node);
}
assert B.understands(node);
return B.getCFG(node);
}
@ -105,9 +95,7 @@ public class DelegatingSSAContextInterpreter extends DelegatingRTAContextInterpr
return A.getDU(node);
}
}
if (Assertions.verifyAssertions) {
assert B.understands(node);
}
assert B.understands(node);
return B.getDU(node);
}
}

View File

@ -29,10 +29,8 @@ import com.ibm.wala.ipa.callgraph.propagation.InstanceKey;
import com.ibm.wala.ipa.callgraph.propagation.PointerKey;
import com.ibm.wala.ipa.callgraph.propagation.PointsToSetVariable;
import com.ibm.wala.ipa.callgraph.propagation.SSAContextInterpreter;
import com.ibm.wala.ipa.cha.ClassHierarchyException;
import com.ibm.wala.ipa.cha.IClassHierarchy;
import com.ibm.wala.types.Selector;
import com.ibm.wala.util.debug.Assertions;
import com.ibm.wala.util.intset.IntSet;
import com.ibm.wala.util.intset.IntSetAction;
import com.ibm.wala.util.intset.IntSetUtil;

View File

@ -17,7 +17,6 @@ import com.ibm.wala.classLoader.IClass;
import com.ibm.wala.classLoader.NewSiteReference;
import com.ibm.wala.ipa.callgraph.CGNode;
import com.ibm.wala.types.FieldReference;
import com.ibm.wala.util.debug.Assertions;
/**
* A context interpreter that first checks with A, then defaults to B.
@ -50,9 +49,7 @@ public class DelegatingRTAContextInterpreter implements RTAContextInterpreter {
return A.iterateNewSites(node);
}
}
if (Assertions.verifyAssertions) {
assert B.understands(node);
}
assert B.understands(node);
return B.iterateNewSites(node);
}
@ -62,9 +59,7 @@ public class DelegatingRTAContextInterpreter implements RTAContextInterpreter {
return A.iterateCallSites(node);
}
}
if (Assertions.verifyAssertions) {
assert B.understands(node);
}
assert B.understands(node);
return B.iterateCallSites(node);
}
@ -74,9 +69,7 @@ public class DelegatingRTAContextInterpreter implements RTAContextInterpreter {
return A.iterateFieldsRead(node);
}
}
if (Assertions.verifyAssertions) {
assert B.understands(node);
}
assert B.understands(node);
return B.iterateFieldsRead(node);
}
@ -86,9 +79,7 @@ public class DelegatingRTAContextInterpreter implements RTAContextInterpreter {
return A.iterateFieldsWritten(node);
}
}
if (Assertions.verifyAssertions) {
assert B.understands(node);
}
assert B.understands(node);
return B.iterateFieldsWritten(node);
}

View File

@ -19,11 +19,8 @@ import com.ibm.wala.ipa.callgraph.CGNode;
import com.ibm.wala.types.FieldReference;
/**
*
* This object will analyze a method in a context and return information
* needed for RTA.
*
* @author sfink
*/
public interface RTAContextInterpreter {
/**

View File

@ -49,8 +49,8 @@ public abstract class AbstractInterproceduralCFG<T extends ISSABasicBlock> imple
private static final boolean FAIL_ON_EAGER_CONSTRUCTION = false;
/**
* Should the graph include call-to-return edges? When set to <code>false</code>, the graphs output by {@link IFDSExplorer}
* look incorrect
* Should the graph include call-to-return edges? When set to <code>false</code>, the graphs output by {@link IFDSExplorer} look
* incorrect
*/
private final static boolean CALL_TO_RETURN_EDGES = true;
@ -191,11 +191,9 @@ public abstract class AbstractInterproceduralCFG<T extends ISSABasicBlock> imple
// previous instruction is not a call instruction.
BasicBlockInContext<T> p = new BasicBlockInContext<T>(n, pb);
BasicBlockInContext<T> b = new BasicBlockInContext<T>(n, bb);
if (Assertions.verifyAssertions) {
if (!g.containsNode(p) || !g.containsNode(b)) {
assert g.containsNode(p) : "IPCFG does not contain " + p;
assert g.containsNode(b) : "IPCFG does not contain " + b;
}
if (!g.containsNode(p) || !g.containsNode(b)) {
assert g.containsNode(p) : "IPCFG does not contain " + p;
assert g.containsNode(b) : "IPCFG does not contain " + b;
}
g.addEdge(p, b);
}
@ -208,9 +206,9 @@ public abstract class AbstractInterproceduralCFG<T extends ISSABasicBlock> imple
if (call == null) {
throw new IllegalArgumentException("call == null");
}
return call.getCallSite().cloneReference(pc);
}
}
/**
* Add an edge from the exit() block of a callee to a return site in the caller
@ -218,16 +216,15 @@ public abstract class AbstractInterproceduralCFG<T extends ISSABasicBlock> imple
* @param returnBlock the return site for a call
* @param targetCFG the called method
*/
private void addEdgesFromExitToReturn(CGNode caller, T returnBlock, CGNode target, ControlFlowGraph<SSAInstruction, ? extends T> targetCFG) {
private void addEdgesFromExitToReturn(CGNode caller, T returnBlock, CGNode target,
ControlFlowGraph<SSAInstruction, ? extends T> targetCFG) {
T texit = targetCFG.exit();
BasicBlockInContext<T> exit = new BasicBlockInContext<T>(target, texit);
addNodeForBasicBlockIfNeeded(exit);
BasicBlockInContext<T> ret = new BasicBlockInContext<T>(caller, returnBlock);
if (Assertions.verifyAssertions) {
if (!g.containsNode(exit) || !g.containsNode(ret)) {
assert g.containsNode(exit) : "IPCFG does not contain " + exit;
assert g.containsNode(ret) : "IPCFG does not contain " + ret;
}
if (!g.containsNode(exit) || !g.containsNode(ret)) {
assert g.containsNode(exit) : "IPCFG does not contain " + exit;
assert g.containsNode(ret) : "IPCFG does not contain " + ret;
}
if (DEBUG_LEVEL > 1) {
System.err.println("addEdgeFromExitToReturn " + exit + ret);
@ -241,16 +238,15 @@ public abstract class AbstractInterproceduralCFG<T extends ISSABasicBlock> imple
* @param callBlock the return site for a call
* @param targetCFG the called method
*/
private void addEdgesFromCallToEntry(CGNode caller, T callBlock, CGNode target, ControlFlowGraph<SSAInstruction, ? extends T> targetCFG) {
private void addEdgesFromCallToEntry(CGNode caller, T callBlock, CGNode target,
ControlFlowGraph<SSAInstruction, ? extends T> targetCFG) {
T tentry = targetCFG.entry();
BasicBlockInContext<T> entry = new BasicBlockInContext<T>(target, tentry);
addNodeForBasicBlockIfNeeded(entry);
BasicBlockInContext<T> call = new BasicBlockInContext<T>(caller, callBlock);
if (Assertions.verifyAssertions) {
if (!g.containsNode(entry) || !g.containsNode(call)) {
assert g.containsNode(entry) : "IPCFG does not contain " + entry;
assert g.containsNode(call) : "IPCFG does not contain " + call;
}
if (!g.containsNode(entry) || !g.containsNode(call)) {
assert g.containsNode(entry) : "IPCFG does not contain " + entry;
assert g.containsNode(call) : "IPCFG does not contain " + call;
}
if (DEBUG_LEVEL > 1) {
System.err.println("addEdgeFromCallToEntry " + call + " " + entry);
@ -290,7 +286,7 @@ public abstract class AbstractInterproceduralCFG<T extends ISSABasicBlock> imple
ControlFlowGraph<SSAInstruction, T> ccfg = getCFG(caller);
if (ccfg != null) {
SSAInstruction[] cinsts = ccfg.getInstructions();
if (DEBUG_LEVEL > 1) {
System.err.println("Visiting " + cinsts.length + " instructions");
}
@ -469,7 +465,7 @@ public abstract class AbstractInterproceduralCFG<T extends ISSABasicBlock> imple
int num = g.getNumber(callBlock);
if (!handledCalls.contains(num)) {
handledCalls.add(num);
ControlFlowGraph<SSAInstruction,T> cfg = getCFG(n);
ControlFlowGraph<SSAInstruction, T> cfg = getCFG(n);
int index = callBlock.getLastInstructionIndex();
SSAAbstractInvokeInstruction call = (SSAAbstractInvokeInstruction) callBlock.getLastInstruction();
CallSiteReference site = makeCallSiteReference(n.getMethod().getDeclaringClass().getClassLoader().getReference(), cfg
@ -658,12 +654,10 @@ public abstract class AbstractInterproceduralCFG<T extends ISSABasicBlock> imple
int lastIndex = B.getLastInstructionIndex();
if (lastIndex >= 0) {
if (Assertions.verifyAssertions) {
if (statements.length <= lastIndex) {
System.err.println(statements.length);
System.err.println(cfg);
assert lastIndex < statements.length : "bad BB " + B + " and CFG for " + getCGNode(B);
}
if (statements.length <= lastIndex) {
System.err.println(statements.length);
System.err.println(cfg);
assert lastIndex < statements.length : "bad BB " + B + " and CFG for " + getCGNode(B);
}
SSAInstruction last = statements[lastIndex];
return (last instanceof SSAAbstractInvokeInstruction);
@ -723,7 +717,7 @@ public abstract class AbstractInterproceduralCFG<T extends ISSABasicBlock> imple
CGNode caller = src.getNode();
T entryBlock = dst.getDelegate();
T exitBlock = getCFG(callee).exit();
addEntryAndExitEdgesToCaller(callee, entryBlock, exitBlock, caller);
addEntryAndExitEdgesToCaller(callee, entryBlock, exitBlock, caller);
}
}
} else {

View File

@ -130,13 +130,13 @@ public class ClassHierarchy implements IClassHierarchy {
* @param klass class in question
* @return Set the result set
*/
private Set<IClass> computeSuperclasses(IClass klass) {
private Set<IClass> computeSuperclasses(IClass klass) {
if (DEBUG) {
System.err.println("computeSuperclasses: " + klass);
}
Set<IClass> result = HashSetFactory.make(3);
klass = klass.getSuperclass();
while (klass != null) {
@ -308,9 +308,7 @@ public class ClassHierarchy implements IClassHierarchy {
if (klass.getReference().equals(this.rootTypeRef)) {
// there is only one root
if (Assertions.verifyAssertions) {
assert root == null;
}
assert root == null;
root = node;
}
@ -346,10 +344,8 @@ public class ClassHierarchy implements IClassHierarchy {
Warnings.add(ClassExclusion.create(iface.getReference(), e.getMessage()));
continue;
}
if (DEBUG && Assertions.verifyAssertions) {
if (!iface.isInterface()) {
assert false : "not an interface: " + iface;
}
if (!iface.isInterface()) {
assert false : "not an interface: " + iface;
}
recordImplements(klass, iface);
}
@ -634,9 +630,7 @@ public class ClassHierarchy implements IClassHierarchy {
private int nextNumber = 1;
private void numberTree() {
if (Assertions.verifyAssertions) {
assert root != null;
}
assert root != null;
visitForNumbering(root);
}
@ -734,11 +728,9 @@ public class ClassHierarchy implements IClassHierarchy {
} else if (B.getReference().equals(TypeReference.JavaLangObject)) {
return B;
} else {
if (Assertions.verifyAssertions) {
Node n = map.get(B);
if (n == null) {
assert n != null : "null n for " + B;
}
Node n = map.get(B);
if (n == null) {
assert n != null : "null n for " + B;
}
Set<IClass> superB;
try {
@ -844,9 +836,7 @@ public class ClassHierarchy implements IClassHierarchy {
if (c == null) {
throw new IllegalArgumentException("c is null");
}
if (Assertions.verifyAssertions) {
assert T != null : "null T";
}
assert T != null : "null T";
if (c.isArrayClass()) {
if (T.getReference() == TypeReference.JavaLangObject) {
@ -999,11 +989,7 @@ public class ClassHierarchy implements IClassHierarchy {
return Collections.singleton(T);
}
Node node = findNode(T);
if (Assertions.verifyAssertions) {
if (node == null) {
assert node != null : "null node for class " + T;
}
}
assert node != null : "null node for class " + T;
HashSet<IClass> result = HashSetFactory.make(3);
result.add(T);
for (Iterator<Node> it = node.getChildren(); it.hasNext();) {
@ -1015,11 +1001,7 @@ public class ClassHierarchy implements IClassHierarchy {
public boolean isInterface(TypeReference type) {
IClass T = lookupClass(type);
if (Assertions.verifyAssertions) {
if (T == null) {
assert T != null : "Null lookup for " + type;
}
}
assert T != null : "Null lookup for " + type;
return T.isInterface();
}

View File

@ -26,7 +26,6 @@ import com.ibm.wala.ipa.callgraph.CallGraph;
import com.ibm.wala.ipa.callgraph.propagation.InstanceKey;
import com.ibm.wala.ipa.callgraph.propagation.PointerAnalysis;
import com.ibm.wala.ipa.callgraph.propagation.PointerKey;
import com.ibm.wala.ipa.cha.ClassHierarchyException;
import com.ibm.wala.ipa.slicer.HeapExclusions;
import com.ibm.wala.ssa.IR;
import com.ibm.wala.ssa.SSAArrayLengthInstruction;
@ -38,7 +37,6 @@ import com.ibm.wala.ssa.SSANewInstruction;
import com.ibm.wala.ssa.SSAPutInstruction;
import com.ibm.wala.util.collections.HashMapFactory;
import com.ibm.wala.util.collections.HashSetFactory;
import com.ibm.wala.util.debug.Assertions;
import com.ibm.wala.util.graph.impl.GraphInverter;
import com.ibm.wala.util.intset.OrdinalSet;

View File

@ -441,7 +441,7 @@ public class PDG implements NumberedGraph<Statement> {
case EXC_RET_CALLER:
case NORMAL_RET_CALLER:
case PARAM_CALLEE: {
if (Assertions.verifyAssertions && dOptions.isIgnoreExceptions()) {
if (dOptions.isIgnoreExceptions()) {
assert !s.getKind().equals(Kind.EXC_RET_CALLER);
}
@ -479,7 +479,7 @@ public class PDG implements NumberedGraph<Statement> {
}
break;
case EXC_RET_CALLEE:
if (Assertions.verifyAssertions && dOptions.isIgnoreExceptions()) {
if (dOptions.isIgnoreExceptions()) {
Assertions.UNREACHABLE();
}
// TODO: this is overly conservative. deal with catch blocks?

View File

@ -292,7 +292,7 @@ public class SDG extends AbstractNumberedGraph<Statement> implements ISDG {
}
public Iterator<? extends Statement> getPredNodes(Statement N) {
if (Assertions.verifyAssertions && dOptions.isIgnoreExceptions()) {
if (dOptions.isIgnoreExceptions()) {
assert !N.getKind().equals(Kind.EXC_RET_CALLEE);
assert !N.getKind().equals(Kind.EXC_RET_CALLER);
}

View File

@ -20,14 +20,9 @@ import com.ibm.wala.ipa.callgraph.ClassTargetSelector;
import com.ibm.wala.ipa.cha.IClassHierarchy;
import com.ibm.wala.types.TypeName;
import com.ibm.wala.types.TypeReference;
import com.ibm.wala.util.debug.Assertions;
/**
* A {@link ClassTargetSelector} that looks up the declared type of a {@link NewSiteReference}
* based on bypass rules.
*
* @author dolby
* @author sfink
* A {@link ClassTargetSelector} that looks up the declared type of a {@link NewSiteReference} based on bypass rules.
*/
public class BypassClassTargetSelector implements ClassTargetSelector {
private static final boolean DEBUG = false;
@ -52,14 +47,13 @@ public class BypassClassTargetSelector implements ClassTargetSelector {
*/
private final BypassSyntheticClassLoader bypassLoader;
public BypassClassTargetSelector(ClassTargetSelector parent, Set<TypeReference> allocatableTypes, IClassHierarchy cha, IClassLoader bypassLoader) throws IllegalArgumentException {
public BypassClassTargetSelector(ClassTargetSelector parent, Set<TypeReference> allocatableTypes, IClassHierarchy cha,
IClassLoader bypassLoader) throws IllegalArgumentException {
if (bypassLoader == null) {
throw new IllegalArgumentException("bypassLoader == null");
}
if (Assertions.verifyAssertions) {
if (!(bypassLoader instanceof BypassSyntheticClassLoader)) {
assert false : "unexpected bypass loader: " + bypassLoader.getClass();
}
if (!(bypassLoader instanceof BypassSyntheticClassLoader)) {
assert false : "unexpected bypass loader: " + bypassLoader.getClass();
}
this.allocatableTypes = allocatableTypes;
@ -70,7 +64,7 @@ public class BypassClassTargetSelector implements ClassTargetSelector {
/*
* @see com.ibm.wala.ipa.callgraph.ClassTargetSelector#getAllocatedTarget(com.ibm.wala.ipa.callgraph.CGNode,
* com.ibm.wala.classLoader.NewSiteReference)
* com.ibm.wala.classLoader.NewSiteReference)
*/
public IClass getAllocatedTarget(CGNode caller, NewSiteReference site) {

View File

@ -19,7 +19,6 @@ import com.ibm.wala.classLoader.IClassLoader;
import com.ibm.wala.classLoader.IField;
import com.ibm.wala.classLoader.IMethod;
import com.ibm.wala.classLoader.SyntheticClass;
import com.ibm.wala.ipa.cha.ClassHierarchyException;
import com.ibm.wala.ipa.cha.IClassHierarchy;
import com.ibm.wala.types.Selector;
import com.ibm.wala.types.TypeName;

View File

@ -24,28 +24,24 @@ import com.ibm.wala.types.MethodReference;
import com.ibm.wala.types.TypeReference;
import com.ibm.wala.util.collections.HashMapFactory;
import com.ibm.wala.util.collections.HashSetFactory;
import com.ibm.wala.util.debug.Assertions;
import com.ibm.wala.util.strings.Atom;
/**
* "Non-standard" bypass rules to use during call graph construction.
*
* Normally, the method bypass rules replace the IMethod that is resolved by
* other means, via the getBypass() method. However, the bypass rules can be
* invoked even before resolving the target of a call, by checking the intercept
* rules.
* Normally, the method bypass rules replace the IMethod that is resolved by other means, via the getBypass() method. However, the
* bypass rules can be invoked even before resolving the target of a call, by checking the intercept rules.
*/
public class MethodBypass {
static final boolean DEBUG = false;
/**
* Method summaries collected for methods. Mapping Object -> MethodSummary
* where Object is either a
* Method summaries collected for methods. Mapping Object -> MethodSummary where Object is either a
* <ul>
* <li> MethodReference
* <li> TypeReference
* <li> Atom (package name)
* <li>MethodReference
* <li>TypeReference
* <li>Atom (package name)
* </ul>
*/
private final Map methodSummaries;
@ -98,8 +94,7 @@ public class MethodBypass {
}
/**
* @param m
* a method reference
* @param m a method reference
* @return a SyntheticMethod corresponding to m; or null if none is available.
*/
private SyntheticMethod findOrCreateSyntheticMethod(MethodReference m) {
@ -111,11 +106,7 @@ public class MethodBypass {
if (summ != null) {
TypeReference T = m.getDeclaringClass();
IClass c = cha.lookupClass(T);
if (Assertions.verifyAssertions) {
if (c == null) {
assert c != null : "null class for " + T;
}
}
assert c != null : "null class for " + T;
SummarizedMethod n = new SummarizedMethod(m, summ, c);
syntheticMethods.put(m, n);
return n;
@ -162,12 +153,11 @@ public class MethodBypass {
}
/**
* Method getBypass. check to see if a call to the receiver 'target' should be
* redirected to a different receiver.
* Method getBypass. check to see if a call to the receiver 'target' should be redirected to a different receiver.
*
* @param target
* @return Object
* @throws IllegalArgumentException if target is null
* @throws IllegalArgumentException if target is null
*/
public SyntheticMethod getBypass(IMethod target) {
if (target == null) {
@ -180,8 +170,7 @@ public class MethodBypass {
* Method extractPackage.
*
* @param type
* @return Atom that represents the package name, or null if this is the
* unnamed package.
* @return Atom that represents the package name, or null if this is the unnamed package.
*/
private Atom extractPackage(TypeReference type) {
String s = type.getName().toString();
@ -210,11 +199,10 @@ public class MethodBypass {
}
/**
* Are we allowed to allocate (for analysis purposes) an instance of a given
* type? By default, the answer is yes iff T is not abstract. However,
* subclasses and summaries can override this to allow "special" abstract
* classes to be allocatable as well.
* @throws IllegalArgumentException if klass is null
* Are we allowed to allocate (for analysis purposes) an instance of a given type? By default, the answer is yes iff T is not
* abstract. However, subclasses and summaries can override this to allow "special" abstract classes to be allocatable as well.
*
* @throws IllegalArgumentException if klass is null
*
*/
public boolean isAllocatable(IClass klass) {

View File

@ -20,14 +20,10 @@ import com.ibm.wala.types.MemberReference;
import com.ibm.wala.types.MethodReference;
import com.ibm.wala.types.TypeReference;
import com.ibm.wala.util.collections.HashMapFactory;
import com.ibm.wala.util.debug.Assertions;
import com.ibm.wala.util.warnings.Warning;
/**
*
* Summary information for a method.
*
* @author sfink
*/
public class MethodSummary {
@ -122,14 +118,9 @@ public class MethodSummary {
return poison;
}
/**
* @param b
*/
public void setPoisonLevel(byte b) {
poisonLevel = b;
if (Assertions.verifyAssertions) {
assert b == Warning.MILD || b == Warning.MODERATE || b == Warning.SEVERE;
}
assert b == Warning.MILD || b == Warning.MODERATE || b == Warning.SEVERE;
}
public byte getPoisonLevel() {
@ -178,8 +169,7 @@ public class MethodSummary {
}
/**
* Note that by convention, getParameterType(0) == this for non-static
* methods.
* Note that by convention, getParameterType(0) == this for non-static methods.
*/
public TypeReference getParameterType(int i) {
if (isStatic()) {
@ -198,9 +188,8 @@ public class MethodSummary {
}
/**
* Record if this is a "factory" method; meaning it returns some object which
* we know little about ... usually we'll resolve this based on downstream
* uses of the object
* Record if this is a "factory" method; meaning it returns some object which we know little about ... usually we'll resolve this
* based on downstream uses of the object
*
* @param b
*/

View File

@ -22,25 +22,16 @@ import com.ibm.wala.ipa.cha.IClassHierarchy;
import com.ibm.wala.types.TypeReference;
import com.ibm.wala.util.collections.HashMapFactory;
import com.ibm.wala.util.collections.HashSetFactory;
import com.ibm.wala.util.debug.Assertions;
/**
*
* Reflection summary information for a method.
*
* @author sfink
* Reflection summary information for a method.
*/
public class ReflectionSummary {
/**
* Mapping from Integer -> Set of TypeReference
*/
private final Map<Integer, Set<TypeReference>> map = HashMapFactory.make();
/**
* @param bcIndex
* @param T
*/
public void addType(int bcIndex, TypeReference T) {
Set<TypeReference> S = findOrCreateSetForBCIndex(bcIndex);
S.add(T);
@ -69,17 +60,13 @@ public class ReflectionSummary {
for (int i = 0; i < p.length; i++) {
TypeReference T = (TypeReference) it.next();
IClass klass = cha.lookupClass(T);
if (Assertions.verifyAssertions) {
if (klass == null) {
assert klass != null : "null type for " + T;
}
}
assert klass != null : "null type for " + T;
p[i] = new PointType(klass);
}
return new SetType(p);
}
}
public Set<TypeReference> getTypesForProgramLocation(int bcIndex) {
return map.get(new Integer(bcIndex));
}

View File

@ -19,11 +19,9 @@ import com.ibm.wala.ssa.SSAInstruction;
import com.ibm.wala.ssa.SSAOptions;
import com.ibm.wala.types.MethodReference;
import com.ibm.wala.types.TypeReference;
import com.ibm.wala.util.debug.Assertions;
/**
* @author sfink
*
* A {@link SyntheticMethod} representing the semantics encoded in a {@link MethodSummary}
*/
public class SummarizedMethod extends SyntheticMethod {
static final boolean DEBUG = false;
@ -33,9 +31,7 @@ public class SummarizedMethod extends SyntheticMethod {
public SummarizedMethod(MethodReference ref, MethodSummary summary, IClass declaringClass) throws NullPointerException {
super(ref, declaringClass, summary.isStatic(), summary.isFactory());
this.summary = summary;
if (Assertions.verifyAssertions) {
assert declaringClass != null;
}
assert declaringClass != null;
if (DEBUG) {
System.err.println(("SummarizedMethod ctor: " + ref + " " + summary));
}

View File

@ -198,16 +198,13 @@ public class XMLMethodSummaryReader implements BytecodeConstants {
private void readXML(InputStream xml) throws SAXException, IOException, ParserConfigurationException {
SAXHandler handler = new SAXHandler();
if (Assertions.verifyAssertions) {
assert xml != null : "Null xml stream";
}
assert xml != null : "Null xml stream";
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.newSAXParser().parse(new InputSource(xml), handler);
}
/**
* @return Method summaries collected for methods. Mapping Object ->
* MethodSummary where Object is either a
* @return Method summaries collected for methods. Mapping Object -> MethodSummary where Object is either a
* <ul>
* <li>MethodReference
* <li>TypeReference
@ -235,7 +232,7 @@ public class XMLMethodSummaryReader implements BytecodeConstants {
/**
* @author sfink
*
* SAX parser logic for XML method summaries
* SAX parser logic for XML method summaries
*/
private class SAXHandler extends DefaultHandler {
/**
@ -269,8 +266,7 @@ public class XMLMethodSummaryReader implements BytecodeConstants {
private Map<String, Integer> symbolTable = null;
/*
* @see org.xml.sax.ContentHandler#startElement(java.lang.String,
* java.lang.String, java.lang.String, org.xml.sax.Attributes)
* @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
*/
@Override
public void startElement(String uri, String name, String qName, Attributes atts) {
@ -356,8 +352,7 @@ public class XMLMethodSummaryReader implements BytecodeConstants {
}
/*
* @see org.xml.sax.ContentHandler#endElement(java.lang.String,
* java.lang.String, java.lang.String)
* @see org.xml.sax.ContentHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
*/
@Override
public void endElement(String uri, String name, String qName) {
@ -370,10 +365,8 @@ public class XMLMethodSummaryReader implements BytecodeConstants {
governingLoader = null;
break;
case E_METHOD:
if (Assertions.verifyAssertions) {
if (governingMethod != null) {
checkReturnValue(governingMethod);
}
if (governingMethod != null) {
checkReturnValue(governingMethod);
}
governingMethod = null;
symbolTable = null;
@ -403,8 +396,7 @@ public class XMLMethodSummaryReader implements BytecodeConstants {
}
/**
* If a method is declared to return a value, be sure the method summary
* includes a return statement. Throw an assertion if not.
* If a method is declared to return a value, be sure the method summary includes a return statement. Throw an assertion if not.
*
* @param governingMethod
*/
@ -789,8 +781,7 @@ public class XMLMethodSummaryReader implements BytecodeConstants {
}
/**
* Begin processing of a method. 1. Set the governing method. 2. Initialize
* the nextLocal variable
* Begin processing of a method. 1. Set the governing method. 2. Initialize the nextLocal variable
*
* @param atts
*/

View File

@ -10,7 +10,6 @@
*******************************************************************************/
package com.ibm.wala.ssa;
import com.ibm.wala.util.debug.Assertions;
/**
* TODO: document me.
@ -20,7 +19,6 @@ public abstract class ReflectiveMemberAccess extends SSAInstruction {
protected final int memberRef;
protected ReflectiveMemberAccess(int objectRef, int memberRef) {
super();
this.objectRef = objectRef;
@ -37,8 +35,7 @@ public abstract class ReflectiveMemberAccess extends SSAInstruction {
*/
@Override
public int getUse(int j) {
if (Assertions.verifyAssertions)
assert j <= 1;
assert j <= 1;
return (j == 0) ? objectRef : memberRef;
}

View File

@ -11,11 +11,7 @@
package com.ibm.wala.ssa;
import com.ibm.wala.util.debug.Assertions;
/**
* @author sfink
*
*/
public abstract class SSAAbstractUnaryInstruction extends SSAInstruction {
@ -44,9 +40,7 @@ public abstract class SSAAbstractUnaryInstruction extends SSAInstruction {
@Override
public int getDef(int i) {
if (Assertions.verifyAssertions) {
assert i == 0;
}
assert i == 0;
return result;
}
@ -68,8 +62,7 @@ public abstract class SSAAbstractUnaryInstruction extends SSAInstruction {
*/
@Override
public int getUse(int j) {
if (Assertions.verifyAssertions)
assert j == 0;
assert j == 0;
return val;
}

View File

@ -11,7 +11,6 @@
package com.ibm.wala.ssa;
import com.ibm.wala.types.TypeReference;
import com.ibm.wala.util.debug.Assertions;
/**
* Abstract base class for instructions that load or store from array contents.
@ -46,9 +45,7 @@ public abstract class SSAArrayReferenceInstruction extends SSAInstruction {
*/
@Override
public int getUse(int j) {
if (Assertions.verifyAssertions) {
assert j <= 1;
}
assert j <= 1;
return (j == 0) ? arrayref : index;
}

View File

@ -12,7 +12,6 @@ package com.ibm.wala.ssa;
import com.ibm.wala.shrikeBT.BinaryOpInstruction;
import com.ibm.wala.shrikeBT.IBinaryOpInstruction;
import com.ibm.wala.util.debug.Assertions;
public abstract class SSABinaryOpInstruction extends SSAInstruction {
@ -77,9 +76,7 @@ public abstract class SSABinaryOpInstruction extends SSAInstruction {
@Override
public int getDef(int i) {
if (Assertions.verifyAssertions) {
assert i == 0;
}
assert i == 0;
return result;
}
@ -101,8 +98,7 @@ public abstract class SSABinaryOpInstruction extends SSAInstruction {
*/
@Override
public int getUse(int j) {
if (Assertions.verifyAssertions)
assert j <= 1;
assert j <= 1;
return (j == 0) ? val1 : val2;
}

View File

@ -57,8 +57,8 @@ import com.ibm.wala.util.shrike.ShrikeUtil;
* This class constructs an SSA {@link IR} from a backing ShrikeBT instruction stream.
*
* The basic algorithm here is an abstract interpretation over the Java bytecode to determine types of stack locations and local
* variables. As a side effect, the flow functions of the abstract interpretation emit instructions, eliminating the
* stack abstraction and moving to a register-transfer language in SSA form.
* variables. As a side effect, the flow functions of the abstract interpretation emit instructions, eliminating the stack
* abstraction and moving to a register-transfer language in SSA form.
*/
public class SSABuilder extends AbstractIntStackMachine {
@ -99,9 +99,7 @@ public class SSABuilder extends AbstractIntStackMachine {
this.method = method;
this.symbolTable = symbolTable;
this.insts = method.getDeclaringClass().getClassLoader().getInstructionFactory();
if (Assertions.verifyAssertions) {
assert cfg != null : "Null CFG";
}
assert cfg != null : "Null CFG";
}
private class SymbolTableMeeter implements Meeter {
@ -123,9 +121,7 @@ public class SSABuilder extends AbstractIntStackMachine {
public int meetStack(int slot, int[] rhs, BasicBlock bb) {
if (Assertions.verifyAssertions) {
assert bb != null : "null basic block";
}
assert bb != null : "null basic block";
if (bb.isExitBlock()) {
return TOP;
@ -352,10 +348,8 @@ public class SSABuilder extends AbstractIntStackMachine {
*/
private int reuseOrCreateException() {
if (Assertions.verifyAssertions) {
if (getCurrentInstruction() != null) {
assert getCurrentInstruction() instanceof SSAInvokeInstruction;
}
if (getCurrentInstruction() != null) {
assert getCurrentInstruction() instanceof SSAInvokeInstruction;
}
if (getCurrentInstruction() == null) {
return symbolTable.newSymbol();
@ -674,21 +668,21 @@ public class SSABuilder extends AbstractIntStackMachine {
}
private Dominators<ISSABasicBlock> dom = null;
private int findRethrowException() {
int index = getCurrentInstructionIndex();
SSACFG.BasicBlock bb= cfg.getBlockForInstruction(index);
SSACFG.BasicBlock bb = cfg.getBlockForInstruction(index);
if (bb.isCatchBlock()) {
SSACFG.ExceptionHandlerBasicBlock newBB = (SSACFG.ExceptionHandlerBasicBlock) bb;
SSAGetCaughtExceptionInstruction s = newBB.getCatchInstruction();
return s.getDef();
} else {
// TODO: should we really use dominators here? maybe it would be cleaner to propagate
// TODO: should we really use dominators here? maybe it would be cleaner to propagate
// the notion of 'current exception to rethrow' using the abstract interpreter.
if (dom == null) {
dom = Dominators.make(cfg, cfg.entry());
}
ISSABasicBlock x = bb;
while (x != null) {
if (x.isCatchBlock()) {
@ -699,20 +693,20 @@ public class SSABuilder extends AbstractIntStackMachine {
x = dom.getIdom(x);
}
}
//assert false;
// assert false;
return -1;
}
}
/**
* @see com.ibm.wala.shrikeBT.Instruction.Visitor#visitThrow(ThrowInstruction)
*/
@Override
public void visitThrow(com.ibm.wala.shrikeBT.ThrowInstruction instruction) {
if (instruction.isRethrow()) {
workingState.clearStack();
emitInstruction(insts.ThrowInstruction(findRethrowException()));
workingState.clearStack();
emitInstruction(insts.ThrowInstruction(findRethrowException()));
} else {
int exception = workingState.pop();
workingState.clearStack();
@ -871,17 +865,11 @@ public class SSABuilder extends AbstractIntStackMachine {
/**
* Record the beginning of a new range, starting at the given program counter, in which a particular value number corresponds to
* a particular local number
*
* @param pc
* @param valueNumber
* @param localNumber
*/
void startRange(int pc, int localNumber, int valueNumber) {
if (Assertions.verifyAssertions) {
int max = shrikeCFG.getMethod().getMaxLocals();
if (localNumber >= max) {
assert false : "invalid local " + localNumber + ">" + max;
}
int max = shrikeCFG.getMethod().getMaxLocals();
if (localNumber >= max) {
assert false : "invalid local " + localNumber + ">" + max;
}
localStoreMap[pc] = new IntPair(valueNumber, localNumber);
@ -889,8 +877,6 @@ public class SSABuilder extends AbstractIntStackMachine {
/**
* Finish populating the map of local variable information
*
* @param builder
*/
private void finishLocalMap(SSABuilder builder) {
for (Iterator it = shrikeCFG.iterator(); it.hasNext();) {

View File

@ -109,11 +109,7 @@ public class SSACFG implements ControlFlowGraph<SSAInstruction, ISSABasicBlock>
}
this.method = method;
if (Assertions.verifyAssertions) {
if (method.getDeclaringClass() == null) {
assert method.getDeclaringClass() != null : "null declaring class for " + method;
}
}
assert method.getDeclaringClass() != null : "null declaring class for " + method;
createBasicBlocks(cfg);
if (cfg instanceof InducedCFG) {
addPhisFromInducedCFG((InducedCFG) cfg);
@ -193,11 +189,9 @@ public class SSACFG implements ControlFlowGraph<SSAInstruction, ISSABasicBlock>
}
}
int instructionIndex = handler.getHandler();
if (Assertions.verifyAssertions) {
IBasicBlock b = getBlockForInstruction(instructionIndex);
if (!(b instanceof ExceptionHandlerBasicBlock)) {
assert b instanceof ExceptionHandlerBasicBlock : "not exception handler " + b + " index " + instructionIndex;
}
IBasicBlock b = getBlockForInstruction(instructionIndex);
if (!(b instanceof ExceptionHandlerBasicBlock)) {
assert b instanceof ExceptionHandlerBasicBlock : "not exception handler " + b + " index " + instructionIndex;
}
ExceptionHandlerBasicBlock bb = (ExceptionHandlerBasicBlock) getBlockForInstruction(instructionIndex);
bb.addCaughtExceptionType(t);

View File

@ -11,7 +11,6 @@
package com.ibm.wala.ssa;
import com.ibm.wala.types.TypeReference;
import com.ibm.wala.util.debug.Assertions;
/**
* A checkcast (dynamic type test) instruction. This instruction produces a new value number (like an assignment) if the check
@ -65,6 +64,7 @@ public abstract class SSACheckCastInstruction extends SSAInstruction {
/*
* @see com.ibm.wala.ssa.SSAInstruction#visit(IVisitor)
*
* @throws IllegalArgumentException if v is null
*/
@Override
@ -75,8 +75,7 @@ public abstract class SSACheckCastInstruction extends SSAInstruction {
v.visitCheckCast(this);
}
/*
/*
* @see com.ibm.wala.ssa.SSAInstruction#hasDef()
*/
@Override
@ -92,14 +91,12 @@ public abstract class SSACheckCastInstruction extends SSAInstruction {
return result;
}
/*
/*
* @see com.ibm.wala.ssa.SSAInstruction#getDef(int)
*/
@Override
public int getDef(int i) {
if (Assertions.verifyAssertions) {
assert i == 0;
}
assert i == 0;
return result;
}
@ -121,8 +118,7 @@ public abstract class SSACheckCastInstruction extends SSAInstruction {
*/
@Override
public int getUse(int j) {
if (Assertions.verifyAssertions)
assert j == 0;
assert j == 0;
return val;
}

View File

@ -11,7 +11,6 @@
package com.ibm.wala.ssa;
import com.ibm.wala.shrikeBT.IComparisonInstruction;
import com.ibm.wala.util.debug.Assertions;
/**
* SSA Instruction for comparisons between floats, longs and doubles
@ -73,9 +72,7 @@ public class SSAComparisonInstruction extends SSAInstruction {
@Override
public int getDef(int i) {
if (Assertions.verifyAssertions) {
assert i == 0;
}
assert i == 0;
return result;
}
@ -97,8 +94,7 @@ public class SSAComparisonInstruction extends SSAInstruction {
*/
@Override
public int getUse(int j) {
if (Assertions.verifyAssertions)
assert j <= 1;
assert j <= 1;
return (j == 0) ? val1 : val2;
}

View File

@ -13,7 +13,6 @@ package com.ibm.wala.ssa;
import com.ibm.wala.shrikeBT.IConditionalBranchInstruction;
import com.ibm.wala.shrikeBT.IConditionalBranchInstruction.IOperator;
import com.ibm.wala.types.TypeReference;
import com.ibm.wala.util.debug.Assertions;
/**
* A conditional branch instruction, which tests two values according to some {@link IOperator}.
@ -27,7 +26,8 @@ public class SSAConditionalBranchInstruction extends SSAInstruction {
private final TypeReference type;
public SSAConditionalBranchInstruction(IConditionalBranchInstruction.IOperator operator, TypeReference type, int val1, int val2) throws IllegalArgumentException {
public SSAConditionalBranchInstruction(IConditionalBranchInstruction.IOperator operator, TypeReference type, int val1, int val2)
throws IllegalArgumentException {
super();
this.operator = operator;
this.val1 = val1;
@ -55,13 +55,12 @@ public class SSAConditionalBranchInstruction extends SSAInstruction {
@Override
public String toString(SymbolTable symbolTable) {
return "conditional branch(" + operator + ") " + getValueString(symbolTable, val1) + ","
+ getValueString(symbolTable, val2);
return "conditional branch(" + operator + ") " + getValueString(symbolTable, val1) + "," + getValueString(symbolTable, val2);
}
/**
* @see com.ibm.wala.ssa.SSAInstruction#visit(IVisitor)
* @throws IllegalArgumentException if v is null
* @throws IllegalArgumentException if v is null
*/
@Override
public void visit(IVisitor v) {
@ -84,8 +83,7 @@ public class SSAConditionalBranchInstruction extends SSAInstruction {
*/
@Override
public int getUse(int j) {
if (Assertions.verifyAssertions)
assert j <= 1;
assert j <= 1;
return (j == 0) ? val1 : val2;
}
@ -114,4 +112,4 @@ public class SSAConditionalBranchInstruction extends SSAInstruction {
return true;
}
}
}

View File

@ -11,7 +11,6 @@
package com.ibm.wala.ssa;
import com.ibm.wala.types.TypeReference;
import com.ibm.wala.util.debug.Assertions;
/**
* An instruction which converts a value of one primitive type into another primitive type.
@ -35,8 +34,7 @@ public abstract class SSAConversionInstruction extends SSAInstruction {
@Override
public String toString(SymbolTable symbolTable) {
return getValueString(symbolTable, result) + " = conversion(" + toType.getName() + ") "
+ getValueString(symbolTable, val);
return getValueString(symbolTable, result) + " = conversion(" + toType.getName() + ") " + getValueString(symbolTable, val);
}
/**
@ -62,9 +60,7 @@ public abstract class SSAConversionInstruction extends SSAInstruction {
@Override
public int getDef(int i) {
if (Assertions.verifyAssertions) {
assert i == 0;
}
assert i == 0;
return result;
}
@ -94,8 +90,7 @@ public abstract class SSAConversionInstruction extends SSAInstruction {
*/
@Override
public int getUse(int j) {
if (Assertions.verifyAssertions)
assert j == 0;
assert j == 0;
return val;
}

View File

@ -10,10 +10,9 @@
*******************************************************************************/
package com.ibm.wala.ssa;
import com.ibm.wala.util.debug.Assertions;
/**
* A "catch" instruction, inserted at the head of a catch block, which assigns a pending exception object to a local vairable.
* A "catch" instruction, inserted at the head of a catch block, which assigns a pending exception object to a local variable.
*
* In SSA {@link IR}s, these instructions do <em>not</em> appear in the normal instruction array returned by IR.getInstructions();
* instead these instructions live in {@link ISSABasicBlock}.
@ -44,8 +43,7 @@ public class SSAGetCaughtExceptionInstruction extends SSAInstruction {
/**
* @see com.ibm.wala.ssa.SSAInstruction#visit(IVisitor)
* @throws IllegalArgumentException
* if v is null
* @throws IllegalArgumentException if v is null
*/
@Override
public void visit(IVisitor v) {
@ -79,9 +77,7 @@ public class SSAGetCaughtExceptionInstruction extends SSAInstruction {
@Override
public int getDef(int i) {
if (Assertions.verifyAssertions) {
assert i == 0;
}
assert i == 0;
return exceptionValueNumber;
}
@ -90,11 +86,6 @@ public class SSAGetCaughtExceptionInstruction extends SSAInstruction {
return 1;
}
/**
* Returns the bb.
*
* @return BasicBlock
*/
public int getBasicBlockNumber() {
return bbNumber;
}

View File

@ -12,7 +12,6 @@
package com.ibm.wala.ssa;
import com.ibm.wala.types.FieldReference;
import com.ibm.wala.util.debug.Assertions;
/**
* SSA instruction that reads a field (i.e. getstatic or getfield).
@ -72,9 +71,7 @@ public abstract class SSAGetInstruction extends SSAFieldAccessInstruction {
@Override
public int getDef(int i) {
if (Assertions.verifyAssertions) {
assert i == 0;
}
assert i == 0;
return result;
}
@ -96,8 +93,7 @@ public abstract class SSAGetInstruction extends SSAFieldAccessInstruction {
*/
@Override
public int getUse(int j) {
if (Assertions.verifyAssertions)
assert j == 0 && getRef() != -1;
assert j == 0 && getRef() != -1;
return getRef();
}

View File

@ -11,7 +11,6 @@
package com.ibm.wala.ssa;
import com.ibm.wala.types.TypeReference;
import com.ibm.wala.util.debug.Assertions;
/**
* A dynamic type test (instanceof) instruction.
@ -70,9 +69,7 @@ public class SSAInstanceofInstruction extends SSAInstruction {
@Override
public int getDef(int i) {
if (Assertions.verifyAssertions) {
assert i == 0;
}
assert i == 0;
return result;
}
@ -98,8 +95,7 @@ public class SSAInstanceofInstruction extends SSAInstruction {
*/
@Override
public int getUse(int j) {
if (Assertions.verifyAssertions)
assert j == 0;
assert j == 0;
return ref;
}
@ -116,7 +112,7 @@ public class SSAInstanceofInstruction extends SSAInstruction {
return true;
}
public int getRef() {
public int getRef() {
return ref;
}
}

View File

@ -13,20 +13,16 @@ package com.ibm.wala.ssa;
import com.ibm.wala.classLoader.CallSiteReference;
import com.ibm.wala.shrikeBT.IInvokeInstruction;
import com.ibm.wala.types.TypeReference;
import com.ibm.wala.util.debug.Assertions;
/**
* @author sfink
*
*/
public abstract class SSAInvokeInstruction extends SSAAbstractInvokeInstruction {
private final int result;
/**
* The value numbers of the arguments passed to the call. For non-static
* methods, params[0] == this. If params == null, this should be a static
* method with no parameters.
* The value numbers of the arguments passed to the call. For non-static methods, params[0] == this. If params == null, this
* should be a static method with no parameters.
*/
private final int[] params;
@ -34,9 +30,7 @@ public abstract class SSAInvokeInstruction extends SSAAbstractInvokeInstruction
super(exception, site);
this.result = result;
this.params = params;
if (Assertions.verifyAssertions) {
assertParamsKosher(result, params, site);
}
assertParamsKosher(result, params, site);
}
/**
@ -54,7 +48,7 @@ public abstract class SSAInvokeInstruction extends SSAAbstractInvokeInstruction
defs == null ? exception : defs[result == -1 ? 0 : 1], site);
}
public static void assertParamsKosher(int result, int[] params, CallSiteReference site) throws IllegalArgumentException{
public static void assertParamsKosher(int result, int[] params, CallSiteReference site) throws IllegalArgumentException {
if (site == null) {
throw new IllegalArgumentException("site cannot be null");
}
@ -76,14 +70,14 @@ public abstract class SSAInvokeInstruction extends SSAAbstractInvokeInstruction
}
if (params.length != nExpected) {
assert params.length == nExpected : "wrong number of params for " + site + " Expected " + nExpected + " got "
+ params.length;
+ params.length;
}
}
}
/**
* @see com.ibm.wala.ssa.SSAInstruction#visit(IVisitor)
* @throws IllegalArgumentException if v is null
* @throws IllegalArgumentException if v is null
*/
@Override
public void visit(IVisitor v) {
@ -99,11 +93,9 @@ public abstract class SSAInvokeInstruction extends SSAAbstractInvokeInstruction
@Override
public int getNumberOfUses() {
if (params == null) {
if (Assertions.verifyAssertions) {
assert site.getInvocationCode() == IInvokeInstruction.Dispatch.STATIC
|| site.getInvocationCode() == IInvokeInstruction.Dispatch.SPECIAL;
assert site.getDeclaredTarget().getNumberOfParameters() == 0;
}
assert site.getInvocationCode() == IInvokeInstruction.Dispatch.STATIC
|| site.getInvocationCode() == IInvokeInstruction.Dispatch.SPECIAL;
assert site.getDeclaredTarget().getNumberOfParameters() == 0;
return 0;
} else {
return params.length;
@ -117,7 +109,7 @@ public abstract class SSAInvokeInstruction extends SSAAbstractInvokeInstruction
@Override
public int getNumberOfReturnValues() {
return (result == -1)? 0: 1;
return (result == -1) ? 0 : 1;
}
@Override
@ -131,20 +123,18 @@ public abstract class SSAInvokeInstruction extends SSAAbstractInvokeInstruction
*/
@Override
public int getUse(int j) {
if (Assertions.verifyAssertions) {
if (params == null) {
assert false : "Invalid getUse: " + j + " , null params " + this;
}
if (params.length <= j) {
assert params.length > j : "Invalid getUse: " + this + ", index " + j + ", params.length " + params.length;
}
if (params == null) {
assert false : "Invalid getUse: " + j + " , null params " + this;
}
if (params.length <= j) {
assert params.length > j : "Invalid getUse: " + this + ", index " + j + ", params.length " + params.length;
}
return params[j];
}
@Override
public int hashCode() {
return (site.hashCode() * 7529) + (exception * 9823);
return (site.hashCode() * 7529) + (exception * 9823);
}
}

View File

@ -11,7 +11,6 @@
package com.ibm.wala.ssa;
import com.ibm.wala.types.TypeReference;
import com.ibm.wala.util.debug.Assertions;
/**
* An instruction that represents a reflective or meta-programming operation, like loadClass in Java
@ -83,9 +82,7 @@ public abstract class SSALoadMetadataInstruction extends SSAInstruction {
@Override
public int getDef(int i) {
if (Assertions.verifyAssertions) {
assert i == 0;
}
assert i == 0;
return lval;
}

View File

@ -10,7 +10,6 @@
*******************************************************************************/
package com.ibm.wala.ssa;
import com.ibm.wala.util.debug.Assertions;
/**
* An instruction representing a monitorenter or monitorexit operation.
@ -44,12 +43,12 @@ public abstract class SSAMonitorInstruction extends SSAInstruction {
@Override
public String toString(SymbolTable symbolTable) {
return "monitor" + (isEnter? "enter " : "exit ") + getValueString(symbolTable, ref);
return "monitor" + (isEnter ? "enter " : "exit ") + getValueString(symbolTable, ref);
}
/**
* @see com.ibm.wala.ssa.SSAInstruction#visit(IVisitor)
* @throws IllegalArgumentException if v is null
* @throws IllegalArgumentException if v is null
*/
@Override
public void visit(IVisitor v) {
@ -72,8 +71,7 @@ public abstract class SSAMonitorInstruction extends SSAInstruction {
*/
@Override
public int getUse(int j) {
if (Assertions.verifyAssertions)
assert j == 0;
assert j == 0;
return ref;
}

View File

@ -13,10 +13,9 @@ package com.ibm.wala.ssa;
import com.ibm.wala.classLoader.NewSiteReference;
import com.ibm.wala.types.ClassLoaderReference;
import com.ibm.wala.types.TypeReference;
import com.ibm.wala.util.debug.Assertions;
/**
* An allocation instruction ("new") for SSA form.
* An allocation instruction ("new") for SSA form.
*
* This includes allocations of both scalars and arrays.
*/
@ -39,10 +38,8 @@ public abstract class SSANewInstruction extends SSAInstruction {
if (site == null) {
throw new IllegalArgumentException("site cannot be null");
}
if (Assertions.verifyAssertions) {
assert !site.getDeclaredType().isArrayType()
|| site.getDeclaredType().getClassLoader().getLanguage() != ClassLoaderReference.Java;
}
assert !site.getDeclaredType().isArrayType()
|| site.getDeclaredType().getClassLoader().getLanguage() != ClassLoaderReference.Java;
this.result = result;
this.site = site;
this.params = null;
@ -62,10 +59,8 @@ public abstract class SSANewInstruction extends SSAInstruction {
if (site == null) {
throw new IllegalArgumentException("site is null");
}
if (Assertions.verifyAssertions) {
assert site.getDeclaredType().isArrayType()
|| site.getDeclaredType().getClassLoader().getLanguage() != ClassLoaderReference.Java;
}
assert site.getDeclaredType().isArrayType()
|| site.getDeclaredType().getClassLoader().getLanguage() != ClassLoaderReference.Java;
this.result = result;
this.site = site;
this.params = new int[params.length];
@ -89,7 +84,7 @@ public abstract class SSANewInstruction extends SSAInstruction {
private String array2String(int[] params, SymbolTable symbolTable) {
StringBuffer result = new StringBuffer();
for (int i =0; i < params.length; i++) {
for (int i = 0; i < params.length; i++) {
result.append(getValueString(symbolTable, params[i]));
result.append(" ");
}
@ -123,9 +118,7 @@ public abstract class SSANewInstruction extends SSAInstruction {
@Override
public int getDef(int i) {
if (Assertions.verifyAssertions) {
assert i == 0;
}
assert i == 0;
return result;
}
@ -157,10 +150,8 @@ public abstract class SSANewInstruction extends SSAInstruction {
@Override
public int getUse(int j) {
if (Assertions.verifyAssertions) {
assert params != null : "expected params but got null";
assert params.length > j : "found too few parameters";
}
assert params != null : "expected params but got null";
assert params.length > j : "found too few parameters";
return params[j];
}
@ -180,4 +171,4 @@ public abstract class SSANewInstruction extends SSAInstruction {
return true;
}
}
}

View File

@ -11,7 +11,6 @@
package com.ibm.wala.ssa;
import com.ibm.wala.types.FieldReference;
import com.ibm.wala.util.debug.Assertions;
/**
* A putfield or putstatic instruction
@ -73,8 +72,7 @@ public abstract class SSAPutInstruction extends SSAFieldAccessInstruction {
*/
@Override
public int getUse(int j) {
if (Assertions.verifyAssertions)
assert j == 0 || (!isStatic() && j == 1);
assert j == 0 || (!isStatic() && j == 1);
return (j == 0 && !isStatic()) ? getRef() : val;
}

View File

@ -11,7 +11,6 @@
package com.ibm.wala.ssa;
import com.ibm.wala.util.debug.Assertions;
import com.ibm.wala.util.intset.IntIterator;
/**
@ -83,8 +82,7 @@ public class SSASwitchInstruction extends SSAInstruction {
*/
@Override
public int getUse(int j) {
if (Assertions.verifyAssertions)
assert j <= 1;
assert j <= 1;
return val;
}
@ -139,4 +137,4 @@ public class SSASwitchInstruction extends SSAInstruction {
return false;
}
}
}

View File

@ -14,18 +14,14 @@ import java.util.Map;
import com.ibm.wala.classLoader.Language;
import com.ibm.wala.util.collections.HashMapFactory;
import com.ibm.wala.util.debug.Assertions;
import com.ibm.wala.util.strings.ImmutableByteArray;
import com.ibm.wala.util.strings.StringStuff;
import com.ibm.wala.util.strings.UTF8Convert;
/**
* A method descriptor; something like:
* (Ljava/langString;)Ljava/lang/Class;
* A method descriptor; something like: (Ljava/langString;)Ljava/lang/Class;
*
* Descriptors are canonical
*
* @author sfink
*/
public final class Descriptor {
@ -79,7 +75,7 @@ public final class Descriptor {
public static Descriptor findOrCreate(ImmutableByteArray b) throws IllegalArgumentException {
return findOrCreate(Language.JAVA, b);
}
/**
* @param s string representation of this descriptor
* @return the canonical representative for this descriptor value
@ -96,6 +92,7 @@ public final class Descriptor {
byte[] b = UTF8Convert.toUTF8(s);
return findOrCreate(l, new ImmutableByteArray(b));
}
/**
* @param key "value" of this descriptor
*/
@ -117,7 +114,7 @@ public final class Descriptor {
public String toString() {
return key.toString();
}
/**
* @return a unicode string representation of this descriptor
*/
@ -148,39 +145,43 @@ public final class Descriptor {
/**
* @author sfink
*
* value that defines a descriptor: used to canonicalize instances
*
* value that defines a descriptor: used to canonicalize instances
*/
private static class Key {
final private TypeName returnType;
final private TypeName[] parameters;
final private int hashCode; // cached for efficiency
Key(TypeName returnType, TypeName[] parameters) {
this.returnType = returnType;
this.parameters = parameters;
if (Assertions.verifyAssertions && parameters != null) {
if (parameters != null) {
assert parameters.length > 0;
}
hashCode = computeHashCode();
}
@Override
public int hashCode() {
return hashCode;
}
public int computeHashCode() {
int result = returnType.hashCode() * 5309;
if (parameters != null) {
for (int i = 0; i<parameters.length; i++) {
for (int i = 0; i < parameters.length; i++) {
result += parameters[i].hashCode() * (5323 ^ i);
}
}
return result;
}
@Override
public boolean equals(Object obj) {
if (Assertions.verifyAssertions) {
assert obj instanceof Key;
}
assert obj instanceof Key;
Key other = (Key) obj;
if (!returnType.equals(other.returnType)) {
return false;
@ -201,6 +202,7 @@ public final class Descriptor {
}
return true;
}
@Override
public String toString() {
StringBuffer result = new StringBuffer();
@ -217,7 +219,7 @@ public final class Descriptor {
appendSemicolonIfNeeded(result, returnType);
return result.toString();
}
public String toUnicodeString() {
StringBuffer result = new StringBuffer();
result.append("(");
@ -233,7 +235,7 @@ public final class Descriptor {
appendSemicolonIfNeeded(result, returnType);
return result.toString();
}
private void appendSemicolonIfNeeded(StringBuffer result, TypeName p) {
if (p.isArrayType()) {
TypeName e = p.getInnermostElementType();
@ -246,5 +248,4 @@ public final class Descriptor {
}
}
}

View File

@ -21,27 +21,17 @@ import com.ibm.wala.classLoader.ShrikeCTMethod;
import com.ibm.wala.classLoader.ShrikeClass;
import com.ibm.wala.shrikeCT.InvalidClassFileException;
import com.ibm.wala.types.TypeReference;
import com.ibm.wala.util.debug.Assertions;
/**
* Under construction.
*
* FormalTypeParameter:
* Identifier ClassBound InterfaceBound*
* FormalTypeParameter: Identifier ClassBound InterfaceBound*
*
* ClassBound:
* : FieldTypeSignature?
* ClassBound: : FieldTypeSignature?
*
* InterfaceBound
* : FieldTypeSignature
*
* FieldTypeSignature:
* ClassTypeSignature
* ArrayTypeSignature
* TypeVariableSignature
*
* @author sjfink
* InterfaceBound : FieldTypeSignature
*
* FieldTypeSignature: ClassTypeSignature ArrayTypeSignature TypeVariableSignature
*/
public class FormalTypeParameter extends Signature {
@ -102,7 +92,7 @@ public class FormalTypeParameter extends Signature {
return s.substring(0, s.indexOf(':'));
}
public static FormalTypeParameter make(String string) throws IllegalArgumentException{
public static FormalTypeParameter make(String string) throws IllegalArgumentException {
if (string == null) {
throw new IllegalArgumentException("string is null");
}
@ -118,10 +108,9 @@ public class FormalTypeParameter extends Signature {
}
/**
* @param s a string that holds a sequence of formal type parameters beginning
* at index begin
* @param s a string that holds a sequence of formal type parameters beginning at index begin
* @return the index where the next formal type parameter ends (actually, end +1)
*/
*/
static int formalTypeParameterEnds(String s, int begin) {
int result = begin;
while (s.charAt(result) != ':') {
@ -147,9 +136,7 @@ public class FormalTypeParameter extends Signature {
case ':':
break;
default:
if (Assertions.verifyAssertions) {
assert false : "bad type signature list " + s + " " + (result - 1);
}
assert false : "bad type signature list " + s + " " + (result - 1);
}
} while (s.charAt(result) == ':');
return result;

View File

@ -14,21 +14,15 @@ import java.util.ArrayList;
import java.util.Iterator;
import com.ibm.wala.types.TypeReference;
import com.ibm.wala.util.debug.Assertions;
/**
* UNDER CONSTRUCTION
*
* <verbatim>
* TypeArgument:
* WildcardIndicator? FieldTypeSignature
* *
* <verbatim> TypeArgument: WildcardIndicator? FieldTypeSignature *
*
* WildcardIndicator: + -
*
*
* WildcardIndicator:
* +
* -
*
*
* </verbatim>
*
* @author sjfink
@ -36,14 +30,12 @@ import com.ibm.wala.util.debug.Assertions;
*/
public class TypeArgument extends Signature {
private final TypeSignature sig;
private final WildcardIndicator w;
private static enum WildcardIndicator {
PLUS,
MINUS
PLUS, MINUS
}
private final static TypeArgument WILDCARD = new TypeArgument("*") {
@ -51,6 +43,7 @@ public class TypeArgument extends Signature {
public boolean isWildcard() {
return true;
}
@Override
public String toString() {
return "*";
@ -110,8 +103,7 @@ public class TypeArgument extends Signature {
}
/**
* @param typeSigs
* TypeSignature*
* @param typeSigs TypeSignature*
* @return tokenize it
*/
static String[] parseForTypeArguments(String typeArgs) {
@ -174,9 +166,7 @@ public class TypeArgument extends Signature {
}
return result;
default:
if (Assertions.verifyAssertions) {
assert false : "bad type argument list " + typeArgs;
}
assert false : "bad type argument list " + typeArgs;
}
}
}
@ -184,7 +174,6 @@ public class TypeArgument extends Signature {
public TypeSignature getFieldTypeSignature() {
return sig;
}
@Override
public String toString() {

View File

@ -19,17 +19,11 @@ import com.ibm.wala.util.debug.Assertions;
/**
* UNDER CONSTRUCTION.
*
* <verbatim> TypeSignature:
* FieldTypeSignature
* BaseType (code for a primitive)
* <verbatim> TypeSignature: FieldTypeSignature BaseType (code for a primitive)
*
* FieldTypeSignature:
* ClassTypeSignature
* ArrayTypeSignature
* TypeVariableSignature
* FieldTypeSignature: ClassTypeSignature ArrayTypeSignature TypeVariableSignature
*
* TypeVariableSignature:
* T identifier ;
* TypeVariableSignature: T identifier ;
*
* </verbatim>
*
@ -90,11 +84,10 @@ public abstract class TypeSignature extends Signature {
public abstract boolean isBaseType();
/**
* @param typeSigs
* TypeSignature*
* @param typeSigs TypeSignature*
* @return tokenize it
*/
static String[] parseForTypeSignatures(String typeSigs) throws IllegalArgumentException{
static String[] parseForTypeSignatures(String typeSigs) throws IllegalArgumentException {
ArrayList<String> sigs = new ArrayList<String>(10);
if (typeSigs.length() < 2) {
// TODO: check this?
@ -150,7 +143,7 @@ public abstract class TypeSignature extends Signature {
case TypeReference.BooleanTypeCode:
case TypeReference.ByteTypeCode:
case TypeReference.IntTypeCode:
sigs.add(typeSigs.substring(i-1, i+1));
sigs.add(typeSigs.substring(i - 1, i + 1));
break;
case 'T':
case TypeReference.ClassTypeCode:
@ -191,9 +184,7 @@ public abstract class TypeSignature extends Signature {
}
return result;
default:
if (Assertions.verifyAssertions) {
assert false : "bad type signature list " + typeSigs;
}
assert false : "bad type signature list " + typeSigs;
}
}
}

View File

@ -16,15 +16,10 @@ import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import com.ibm.wala.util.debug.Assertions;
import com.ibm.wala.util.debug.UnimplementedError;
/**
*
* This implementation of Map chooses between one of two implementations,
* depending on the size of the map.
*
* @author sfink
* This implementation of {@link Map} chooses between one of two implementations, depending on the size of the map.
*/
public class BimodalMap<K, V> implements Map<K, V> {
@ -40,9 +35,7 @@ public class BimodalMap<K, V> implements Map<K, V> {
private Map<K, V> backingStore;
/**
* @param cutoff
* the map size at which to switch from the small map implementation
* to the large map implementation
* @param cutoff the map size at which to switch from the small map implementation to the large map implementation
*/
public BimodalMap(int cutoff) {
this.cutOff = cutoff;
@ -108,10 +101,8 @@ public class BimodalMap<K, V> implements Map<K, V> {
* Switch backing implementation from a SmallMap to a HashMap
*/
private void transferBackingStore() {
if (Assertions.verifyAssertions) {
assert backingStore instanceof SmallMap;
}
SmallMap<K, V> S = (SmallMap<K,V>) backingStore;
assert backingStore instanceof SmallMap;
SmallMap<K, V> S = (SmallMap<K, V>) backingStore;
backingStore = HashMapFactory.make(2 * S.size());
for (Iterator<K> it = S.keySet().iterator(); it.hasNext();) {
K key = it.next();

Some files were not shown because too many files have changed in this diff Show More