/** * Returns <code>true</code> if both references may point to the same memory location. The current * implementation is conservative, as it does not take any points-to information into account. */ public static boolean maybeSameLocation(Value abstrRef, Value programRef) { // arrays are handled through their "base" pointer assert !(abstrRef instanceof ArrayRef); assert !(programRef instanceof ArrayRef); if (abstrRef == programRef) return true; // handle primtive types Type abstrRefType = abstrRef.getType(); Type programRefType = programRef.getType(); if (programRefType instanceof PrimType) { // we don't track primitive types, just Strings, ClassLoaders, etc. // ... return false; } if (abstrRefType instanceof PrimType) { // we don't track primitive types, just Strings, ClassLoaders, etc. // ... throw new InternalError("abstraction ref type is " + abstrRefType); } if (abstrRef instanceof Local && programRef instanceof Local) { // two locals only point to the same memory locations if they are // the same return abstrRef == programRef; } else if (abstrRef instanceof FieldRef && programRef instanceof FieldRef) { FieldRef fieldRef = (FieldRef) abstrRef; FieldRef fieldRef2 = (FieldRef) programRef; // references point to the same location if class and field name are // identical; // note that we ignore the receiver object of InstanceFieldRefs return fieldRef .getField() .getDeclaringClass() .equals(fieldRef2.getField().getDeclaringClass()) && fieldRef.getFieldRef().name().equals(fieldRef2.getFieldRef().name()); } else { return false; } }