patch 1850117, fix some unguarded assertions

git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@2176 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
sjfink 2007-12-13 17:08:17 +00:00
parent 8b4cb4cb66
commit ebedfde191
16 changed files with 108 additions and 60 deletions

View File

@ -97,3 +97,5 @@ junit
backedge backedge
lhs lhs
bytecode bytecode
alan
donovan

View File

@ -27,7 +27,7 @@ import com.ibm.wala.util.debug.Assertions;
import com.ibm.wala.util.debug.UnimplementedError; import com.ibm.wala.util.debug.UnimplementedError;
/** /**
* Implementation of IClass for array classes. * Implementation of {@link IClass} for array classes.
* *
* @author Alan Donovan * @author Alan Donovan
* @author sfink * @author sfink
@ -35,7 +35,7 @@ import com.ibm.wala.util.debug.UnimplementedError;
public class ArrayClass implements IClass, Constants { public class ArrayClass implements IClass, Constants {
private final IClassHierarchy cha; private final IClassHierarchy cha;
/** /**
* Package-visible constructor; only for use by ArrayClassLoader class. * Package-visible constructor; only for use by ArrayClassLoader class.
* 'loader' must be the Primordial IClassLoader. * 'loader' must be the Primordial IClassLoader.
@ -54,7 +54,9 @@ public class ArrayClass implements IClass, Constants {
Assertions.UNREACHABLE("caller should not attempt to create an array with type " + type); Assertions.UNREACHABLE("caller should not attempt to create an array with type " + type);
} }
} else { } else {
Assertions._assert(loader.getReference().equals(ClassLoaderReference.Primordial)); if (Assertions.verifyAssertions) {
Assertions._assert(loader.getReference().equals(ClassLoaderReference.Primordial));
}
} }
} }
} }
@ -109,7 +111,9 @@ public class ArrayClass implements IClass, Constants {
try { try {
IClass elt = getElementClass(); IClass elt = getElementClass();
Assertions._assert(getReference().getArrayElementType().isPrimitiveType() || elt != null); if (Assertions.verifyAssertions) {
Assertions._assert(getReference().getArrayElementType().isPrimitiveType() || elt != null);
}
// super is Ljava/lang/Object in two cases: // super is Ljava/lang/Object in two cases:
// 1) [Ljava/lang/Object // 1) [Ljava/lang/Object
@ -284,8 +288,8 @@ public class ArrayClass implements IClass, Constants {
Assertions.UNREACHABLE(); Assertions.UNREACHABLE();
return null; return null;
} }
/* /*
* @see com.ibm.wala.classLoader.IClass#getAllStaticFields() * @see com.ibm.wala.classLoader.IClass#getAllStaticFields()
*/ */
public Collection<IField> getAllStaticFields() throws UnimplementedError, ClassHierarchyException { public Collection<IField> getAllStaticFields() throws UnimplementedError, ClassHierarchyException {
@ -293,20 +297,20 @@ public class ArrayClass implements IClass, Constants {
return null; return null;
} }
/* /*
* @see com.ibm.wala.classLoader.IClass#getAllMethods() * @see com.ibm.wala.classLoader.IClass#getAllMethods()
*/ */
public Collection<IMethod> getAllMethods() throws UnimplementedError, ClassHierarchyException { public Collection<IMethod> getAllMethods() throws UnimplementedError, ClassHierarchyException {
Assertions.UNREACHABLE(); Assertions.UNREACHABLE();
return null; return null;
} }
/* /*
* @see com.ibm.wala.classLoader.IClass#getAllFields() * @see com.ibm.wala.classLoader.IClass#getAllFields()
*/ */
public Collection<IField> getAllFields() throws UnimplementedError, ClassHierarchyException { public Collection<IField> getAllFields() throws UnimplementedError, ClassHierarchyException {
Assertions.UNREACHABLE(); Assertions.UNREACHABLE();
return null; return null;
} }
public IClassHierarchy getClassHierarchy() { public IClassHierarchy getClassHierarchy() {

View File

@ -157,8 +157,8 @@ public class ClassHierarchy implements IClassHierarchy {
this(scope, factory, scope.getLanguages(), progressMonitor); this(scope, factory, scope.getLanguages(), progressMonitor);
} }
private ClassHierarchy(AnalysisScope scope, ClassLoaderFactory factory, Collection<Language> languages, IProgressMonitor progressMonitor) private ClassHierarchy(AnalysisScope scope, ClassLoaderFactory factory, Collection<Language> languages,
throws ClassHierarchyException, IllegalArgumentException { IProgressMonitor progressMonitor) throws ClassHierarchyException, IllegalArgumentException {
// now is a good time to clear the warnings globally. // now is a good time to clear the warnings globally.
// TODO: think of a better way to guard against warning leaks. // TODO: think of a better way to guard against warning leaks.
Warnings.clear(); Warnings.clear();
@ -171,18 +171,18 @@ public class ClassHierarchy implements IClassHierarchy {
} }
this.scope = scope; this.scope = scope;
this.factory = factory; this.factory = factory;
Set<Atom> langNames= new HashSet<Atom>(); Set<Atom> langNames = new HashSet<Atom>();
for(Language lang: languages) { for (Language lang : languages) {
this.languages.add(lang); this.languages.add(lang);
this.languages.addAll(lang.getDerivedLanguages()); this.languages.addAll(lang.getDerivedLanguages());
langNames.add(lang.getName()); langNames.add(lang.getName());
} }
for(Language lang: this.languages) { for (Language lang : this.languages) {
if (lang.getRootType() != null) { if (lang.getRootType() != null) {
if (this.rootTypeRef != null) { if (this.rootTypeRef != null) {
throw new IllegalArgumentException("AnalysisScope must have only 1 root type"); throw new IllegalArgumentException("AnalysisScope must have only 1 root type");
} else { } else {
this.rootTypeRef= lang.getRootType(); this.rootTypeRef = lang.getRootType();
} }
} }
} }
@ -290,7 +290,9 @@ public class ClassHierarchy implements IClassHierarchy {
if (klass.getReference().equals(this.rootTypeRef)) { if (klass.getReference().equals(this.rootTypeRef)) {
// there is only one root // there is only one root
Assertions._assert(root == null); if (Assertions.verifyAssertions) {
Assertions._assert(root == null);
}
root = node; root = node;
} }
@ -956,8 +958,8 @@ public class ClassHierarchy implements IClassHierarchy {
/** /**
* Does c implement i? * Does c implement i?
* *
* @return true iff i is an interface and c is a class that implements i, r * @return true iff i is an interface and c is a class that implements i, r c
* c is an interface that extends i. * is an interface that extends i.
* *
*/ */
public boolean implementsInterface(IClass c, IClass i) { public boolean implementsInterface(IClass c, IClass i) {

View File

@ -15,11 +15,12 @@ import com.ibm.wala.util.debug.Assertions;
/** /**
* @author sfink * @author sfink
* *
*/ */
public abstract class SSAAbstractUnaryInstruction extends SSAInstruction { public abstract class SSAAbstractUnaryInstruction extends SSAInstruction {
protected final int result; protected final int result;
protected final int val; protected final int val;
protected SSAAbstractUnaryInstruction(int result, int val) { protected SSAAbstractUnaryInstruction(int result, int val) {
@ -43,7 +44,9 @@ public abstract class SSAAbstractUnaryInstruction extends SSAInstruction {
@Override @Override
public int getDef(int i) { public int getDef(int i) {
Assertions._assert(i == 0); if (Assertions.verifyAssertions) {
Assertions._assert(i == 0);
}
return result; return result;
} }
@ -75,7 +78,7 @@ public abstract class SSAAbstractUnaryInstruction extends SSAInstruction {
return val * 1663 ^ result * 4027; return val * 1663 ^ result * 4027;
} }
/* /*
* @see com.ibm.wala.ssa.Instruction#isFallThrough() * @see com.ibm.wala.ssa.Instruction#isFallThrough()
*/ */
@Override @Override

View File

@ -71,7 +71,9 @@ public class SSAArrayLengthInstruction extends SSAInstruction {
@Override @Override
public int getDef(int i) { public int getDef(int i) {
Assertions._assert(i == 0); if (Assertions.verifyAssertions) {
Assertions._assert(i == 0);
}
return result; return result;
} }

View File

@ -76,7 +76,9 @@ public class SSAArrayLoadInstruction extends SSAArrayReferenceInstruction {
@Override @Override
public int getDef(int i) { public int getDef(int i) {
Assertions._assert(i == 0); if (Assertions.verifyAssertions) {
Assertions._assert(i == 0);
}
return result; return result;
} }

View File

@ -31,7 +31,7 @@ public class SSABinaryOpInstruction extends SSAInstruction {
private final int val2; private final int val2;
private final BinaryOpInstruction.IOperator operator; private final BinaryOpInstruction.IOperator operator;
/** /**
* Might this instruction represent integer arithmetic? * Might this instruction represent integer arithmetic?
*/ */
@ -44,7 +44,9 @@ public class SSABinaryOpInstruction extends SSAInstruction {
this.val2 = val2; this.val2 = val2;
this.operator = operator; this.operator = operator;
this.mayBeInteger = mayBeInteger; this.mayBeInteger = mayBeInteger;
Assertions._assert(val1 != -1 && val2 != -1); if (Assertions.verifyAssertions) {
Assertions._assert(val1 != -1 && val2 != -1);
}
} }
@Override @Override
@ -71,7 +73,7 @@ public class SSABinaryOpInstruction extends SSAInstruction {
} }
/** /**
* Ugh. clean up shrike operator stuff. * Ugh. clean up shrike operator stuff.
*/ */
public BinaryOpInstruction.IOperator getOperator() { public BinaryOpInstruction.IOperator getOperator() {
return operator; return operator;
@ -89,7 +91,9 @@ public class SSABinaryOpInstruction extends SSAInstruction {
@Override @Override
public int getDef(int i) { public int getDef(int i) {
Assertions._assert(i == 0); if (Assertions.verifyAssertions) {
Assertions._assert(i == 0);
}
return result; return result;
} }

View File

@ -18,7 +18,7 @@ import com.ibm.wala.util.debug.Assertions;
/** /**
* @author sfink * @author sfink
* *
*/ */
public class SSACheckCastInstruction extends SSAInstruction { public class SSACheckCastInstruction extends SSAInstruction {
@ -48,12 +48,14 @@ public class SSACheckCastInstruction extends SSAInstruction {
@Override @Override
public String toString(SymbolTable symbolTable, ValueDecorator d) { public String toString(SymbolTable symbolTable, ValueDecorator d) {
return getValueString(symbolTable, d, result) + " = checkcast " + declaredResultType.getName() + " " + getValueString(symbolTable, d, val); return getValueString(symbolTable, d, result) + " = checkcast " + declaredResultType.getName() + " "
+ getValueString(symbolTable, d, val);
} }
/** /**
* @see com.ibm.wala.ssa.SSAInstruction#visit(IVisitor) * @see com.ibm.wala.ssa.SSAInstruction#visit(IVisitor)
* @throws IllegalArgumentException if v is null * @throws IllegalArgumentException
* if v is null
*/ */
@Override @Override
public void visit(IVisitor v) { public void visit(IVisitor v) {
@ -78,7 +80,9 @@ public class SSACheckCastInstruction extends SSAInstruction {
@Override @Override
public int getDef(int i) { public int getDef(int i) {
Assertions._assert(i == 0); if (Assertions.verifyAssertions) {
Assertions._assert(i == 0);
}
return result; return result;
} }

View File

@ -32,7 +32,8 @@ public class SSAComparisonInstruction extends SSAInstruction {
private final short opcode; private final short opcode;
/** /**
* @param opcode opcode from list in {@link Constants} * @param opcode
* opcode from list in {@link Constants}
*/ */
SSAComparisonInstruction(short opcode, int result, int val1, int val2) { SSAComparisonInstruction(short opcode, int result, int val1, int val2) {
super(); super();
@ -45,7 +46,7 @@ public class SSAComparisonInstruction extends SSAInstruction {
@Override @Override
public SSAInstruction copyForSSA(int[] defs, int[] uses) throws IllegalArgumentException { public SSAInstruction copyForSSA(int[] defs, int[] uses) throws IllegalArgumentException {
// TODO: Julian ... is this correct? // TODO: Julian ... is this correct?
if (uses!= null && uses.length != 2) { if (uses != null && uses.length != 2) {
throw new IllegalArgumentException("expected 2 uses, got " + uses.length); throw new IllegalArgumentException("expected 2 uses, got " + uses.length);
} }
return new SSAComparisonInstruction(opcode, defs == null || defs.length == 0 ? result : defs[0], uses == null ? val1 : uses[0], return new SSAComparisonInstruction(opcode, defs == null || defs.length == 0 ? result : defs[0], uses == null ? val1 : uses[0],
@ -81,7 +82,9 @@ public class SSAComparisonInstruction extends SSAInstruction {
@Override @Override
public int getDef(int i) { public int getDef(int i) {
Assertions._assert(i == 0); if (Assertions.verifyAssertions) {
Assertions._assert(i == 0);
}
return result; return result;
} }

View File

@ -48,7 +48,8 @@ public class SSAConversionInstruction extends SSAInstruction {
@Override @Override
public String toString(SymbolTable symbolTable, ValueDecorator d) { public String toString(SymbolTable symbolTable, ValueDecorator d) {
return getValueString(symbolTable, d, result) + " = conversion(" + toType.getName() + ") " + getValueString(symbolTable, d, val); return getValueString(symbolTable, d, result) + " = conversion(" + toType.getName() + ") "
+ getValueString(symbolTable, d, val);
} }
/** /**
@ -74,7 +75,9 @@ public class SSAConversionInstruction extends SSAInstruction {
@Override @Override
public int getDef(int i) { public int getDef(int i) {
Assertions._assert(i == 0); if (Assertions.verifyAssertions) {
Assertions._assert(i == 0);
}
return result; return result;
} }

View File

@ -46,7 +46,8 @@ public class SSAGetCaughtExceptionInstruction extends SSAInstruction {
/** /**
* @see com.ibm.wala.ssa.SSAInstruction#visit(IVisitor) * @see com.ibm.wala.ssa.SSAInstruction#visit(IVisitor)
* @throws IllegalArgumentException if v is null * @throws IllegalArgumentException
* if v is null
*/ */
@Override @Override
public void visit(IVisitor v) { public void visit(IVisitor v) {
@ -80,7 +81,9 @@ public class SSAGetCaughtExceptionInstruction extends SSAInstruction {
@Override @Override
public int getDef(int i) { public int getDef(int i) {
Assertions._assert(i == 0); if (Assertions.verifyAssertions) {
Assertions._assert(i == 0);
}
return exceptionValueNumber; return exceptionValueNumber;
} }

View File

@ -11,7 +11,6 @@
package com.ibm.wala.ssa; package com.ibm.wala.ssa;
import com.ibm.wala.types.FieldReference; import com.ibm.wala.types.FieldReference;
import com.ibm.wala.util.debug.Assertions; import com.ibm.wala.util.debug.Assertions;
@ -74,7 +73,9 @@ public class SSAGetInstruction extends SSAFieldAccessInstruction {
@Override @Override
public int getDef(int i) { public int getDef(int i) {
Assertions._assert(i == 0); if (Assertions.verifyAssertions) {
Assertions._assert(i == 0);
}
return result; return result;
} }

View File

@ -74,7 +74,9 @@ public class SSAInstanceofInstruction extends SSAInstruction {
@Override @Override
public int getDef(int i) { public int getDef(int i) {
Assertions._assert(i == 0); if (Assertions.verifyAssertions) {
Assertions._assert(i == 0);
}
return result; return result;
} }

View File

@ -18,7 +18,8 @@ import com.ibm.wala.util.debug.Assertions;
public class SSALoadClassInstruction extends SSAInstruction { public class SSALoadClassInstruction extends SSAInstruction {
private static final Collection<TypeReference> loadClassExceptions = Collections.singleton(TypeReference.JavaLangClassNotFoundException); private static final Collection<TypeReference> loadClassExceptions = Collections
.singleton(TypeReference.JavaLangClassNotFoundException);
private final int lval; private final int lval;
@ -72,7 +73,9 @@ public class SSALoadClassInstruction extends SSAInstruction {
@Override @Override
public int getDef(int i) { public int getDef(int i) {
Assertions._assert(i == 0); if (Assertions.verifyAssertions) {
Assertions._assert(i == 0);
}
return lval; return lval;
} }

View File

@ -42,7 +42,8 @@ public class SSANewInstruction extends SSAInstruction {
throw new IllegalArgumentException("site cannot be null"); throw new IllegalArgumentException("site cannot be null");
} }
if (Assertions.verifyAssertions) { if (Assertions.verifyAssertions) {
Assertions._assert(!site.getDeclaredType().isArrayType() || site.getDeclaredType().getClassLoader().getLanguage() != ClassLoaderReference.Java); Assertions._assert(!site.getDeclaredType().isArrayType()
|| site.getDeclaredType().getClassLoader().getLanguage() != ClassLoaderReference.Java);
} }
this.result = result; this.result = result;
this.site = site; this.site = site;
@ -51,8 +52,11 @@ public class SSANewInstruction extends SSAInstruction {
/** /**
* Create a new instruction to allocate an array. * Create a new instruction to allocate an array.
* @throws IllegalArgumentException if site is null *
* @throws IllegalArgumentException if params is null * @throws IllegalArgumentException
* if site is null
* @throws IllegalArgumentException
* if params is null
*/ */
public SSANewInstruction(int result, NewSiteReference site, int[] params) { public SSANewInstruction(int result, NewSiteReference site, int[] params) {
@ -64,7 +68,8 @@ public class SSANewInstruction extends SSAInstruction {
throw new IllegalArgumentException("site is null"); throw new IllegalArgumentException("site is null");
} }
if (Assertions.verifyAssertions) { if (Assertions.verifyAssertions) {
Assertions._assert(site.getDeclaredType().isArrayType() || site.getDeclaredType().getClassLoader().getLanguage() != ClassLoaderReference.Java); Assertions._assert(site.getDeclaredType().isArrayType()
|| site.getDeclaredType().getClassLoader().getLanguage() != ClassLoaderReference.Java);
} }
this.result = result; this.result = result;
this.site = site; this.site = site;
@ -77,20 +82,20 @@ public class SSANewInstruction extends SSAInstruction {
if (params == null) { if (params == null) {
return new SSANewInstruction(defs == null ? result : defs[0], site); return new SSANewInstruction(defs == null ? result : defs[0], site);
} else { } else {
return new SSANewInstruction(defs == null ? result : defs[0], return new SSANewInstruction(defs == null ? result : defs[0], site, uses == null ? params : uses);
site,
uses == null ? params: uses);
} }
} }
@Override @Override
public String toString(SymbolTable symbolTable, ValueDecorator d) { public String toString(SymbolTable symbolTable, ValueDecorator d) {
return getValueString(symbolTable, d, result) + " = new " + site.getDeclaredType() + "@" + site.getProgramCounter() + (params==null?"":" dims: "+params.length); return getValueString(symbolTable, d, result) + " = new " + site.getDeclaredType() + "@" + site.getProgramCounter()
+ (params == null ? "" : " dims: " + params.length);
} }
/** /**
* @see com.ibm.wala.ssa.SSAInstruction#visit(IVisitor) * @see com.ibm.wala.ssa.SSAInstruction#visit(IVisitor)
* @throws IllegalArgumentException if v is null * @throws IllegalArgumentException
* if v is null
*/ */
@Override @Override
public void visit(IVisitor v) { public void visit(IVisitor v) {
@ -115,7 +120,9 @@ public class SSANewInstruction extends SSAInstruction {
@Override @Override
public int getDef(int i) { public int getDef(int i) {
Assertions._assert(i == 0); if (Assertions.verifyAssertions) {
Assertions._assert(i == 0);
}
return result; return result;
} }

View File

@ -19,7 +19,7 @@ import com.ibm.wala.util.debug.Assertions;
/** /**
* @author sfink * @author sfink
* *
*/ */
public class SSAPhiInstruction extends SSAInstruction { public class SSAPhiInstruction extends SSAInstruction {
private final int result; private final int result;
@ -66,7 +66,8 @@ public class SSAPhiInstruction extends SSAInstruction {
/** /**
* @see com.ibm.wala.ssa.SSAInstruction#visit(IVisitor) * @see com.ibm.wala.ssa.SSAInstruction#visit(IVisitor)
* @throws IllegalArgumentException if v is null * @throws IllegalArgumentException
* if v is null
*/ */
@Override @Override
public void visit(IVisitor v) { public void visit(IVisitor v) {
@ -91,7 +92,9 @@ public class SSAPhiInstruction extends SSAInstruction {
@Override @Override
public int getDef(int i) { public int getDef(int i) {
Assertions._assert(i == 0); if (Assertions.verifyAssertions) {
Assertions._assert(i == 0);
}
return result; return result;
} }