use of org.jikesrvm.compilers.opt.util.Stack in project JikesRVM by JikesRVM.
the class Simple method removeCodeAfterTrapInstruction.
private static void removeCodeAfterTrapInstruction(Instruction trap) {
if (VM.VerifyAssertions)
opt_assert(Trap.conforms(trap));
Stack<Instruction> toRemove = new Stack<Instruction>();
Instruction s = trap.nextInstructionInCodeOrder();
while (s != null && !(s.operator() == BBEND)) {
toRemove.push(s);
s = s.nextInstructionInCodeOrder();
}
while (!toRemove.isEmpty()) {
DefUse.removeInstructionAndUpdateDU(toRemove.pop());
}
}
use of org.jikesrvm.compilers.opt.util.Stack in project JikesRVM by JikesRVM.
the class ClassLoaderProxy method findCommonSuperclass.
/**
* Returns a common superclass of the two types.
* NOTE: If both types are references, but are not both loaded, then this
* may be a conservative approximation (java.lang.Object).
*
* @param t1 first type
* @param t2 second type
* @return a common superclass or {@code null} if there's none
*/
public static TypeReference findCommonSuperclass(TypeReference t1, TypeReference t2) {
if (t1 == t2) {
return t1;
}
if (t1.isPrimitiveType() || t2.isPrimitiveType()) {
if (t1.isIntLikeType() && t2.isIntLikeType()) {
// 2 non-identical int like types, return the largest
if (t1.isIntType() || t2.isIntType()) {
return TypeReference.Int;
} else if (t1.isCharType() || t2.isCharType()) {
return TypeReference.Char;
} else if (t1.isShortType() || t2.isShortType()) {
return TypeReference.Short;
} else if (t1.isByteType() || t2.isByteType()) {
return TypeReference.Byte;
} else {
if (VM.VerifyAssertions)
VM._assert(VM.NOT_REACHED);
return null;
}
} else if (t1.isWordLikeType() && t2.isWordLikeType()) {
return TypeReference.Word;
} else {
// other primitive and unboxed types have no commonality so return null
return null;
}
}
// the other operand is the most precise
if (t1 == TypeReference.NULL_TYPE) {
return t2;
} else if (t2 == TypeReference.NULL_TYPE) {
return t1;
}
if (DBG_TYPE) {
VM.sysWrite("finding common supertype of " + t1 + " and " + t2);
}
// Strip off all array junk.
int arrayDimensions = 0;
while (t1.isArrayType() && t2.isArrayType()) {
++arrayDimensions;
t1 = t1.getArrayElementType();
t2 = t2.getArrayElementType();
}
// dimensionality
if (t1.isPrimitiveType() || t2.isPrimitiveType()) {
TypeReference type = TypeReference.JavaLangObject;
if (t1 == t2) {
// Unboxed types are wrapped in their own array objects
if (t1.isUnboxedType()) {
arrayDimensions++;
type = t1;
} else {
if (VM.VerifyAssertions)
VM._assert(VM.NOT_REACHED);
}
}
--arrayDimensions;
while (arrayDimensions-- > 0) {
type = type.getArrayTypeForElementType();
}
if (DBG_TYPE) {
VM.sysWrite("one is a primitive array, so supertype is " + type);
}
return type;
}
// is this a case of arrays with different dimensionalities?
if (t1.isArrayType() || t2.isArrayType()) {
// one is a class type, while the other is an array
TypeReference type = TypeReference.JavaLangObject;
while (arrayDimensions-- > 0) {
type = type.getArrayTypeForElementType();
}
if (DBG_TYPE) {
VM.sysWrite("differing dimensionalities for arrays, so supertype is " + type);
}
return type;
}
// At this point they both must be class types.
// technique: push heritage of each type on a separate stack,
// then find the highest point in the stack where they differ.
RVMClass c1 = (RVMClass) t1.peekType();
RVMClass c2 = (RVMClass) t2.peekType();
if (c1 != null && c2 != null) {
// The ancestor hierarchy is available, so do this exactly
Stack<RVMClass> s1 = new Stack<RVMClass>();
do {
s1.push(c1);
c1 = c1.getSuperClass();
} while (c1 != null);
Stack<RVMClass> s2 = new Stack<RVMClass>();
do {
s2.push(c2);
c2 = c2.getSuperClass();
} while (c2 != null);
if (DBG_TYPE) {
VM.sysWrite("stack 1: " + s1);
}
if (DBG_TYPE) {
VM.sysWrite("stack 2: " + s2);
}
TypeReference best = TypeReference.JavaLangObject;
while (!s1.empty() && !s2.empty()) {
RVMClass temp = s1.pop();
if (temp == s2.pop()) {
best = temp.getTypeRef();
} else {
break;
}
}
if (DBG_TYPE) {
VM.sysWrite("common supertype of the two classes is " + best);
}
while (arrayDimensions-- > 0) {
best = best.getArrayTypeForElementType();
}
return best;
} else {
if (DBG_TYPE && c1 == null) {
VM.sysWrite(c1 + " is not loaded, using Object as common supertype");
}
if (DBG_TYPE && c2 == null) {
VM.sysWrite(c2 + " is not loaded, using Object as common supertype");
}
TypeReference common = TypeReference.JavaLangObject;
while (arrayDimensions-- > 0) {
common = common.getArrayTypeForElementType();
}
return common;
}
}
Aggregations