/** * Create a constant key for a string. * @param cha the class hierarchy * @param str the string * @return the constant key */ protected static ConstantKey<String> makeConstantKey(IClassHierarchy cha,String str) { IClass cls = cha.lookupClass(TypeReference.JavaLangString); ConstantKey<String> ck = new ConstantKey<>(str,cls); return ck; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; final StringConstantCharArray other = (StringConstantCharArray) obj; if (constant == null) { if (other.constant != null) return false; } else if (!constant.equals(other.constant)) return false; return true; }
@Override public Context getCalleeTarget(CGNode caller, CallSiteReference site, IMethod callee, InstanceKey[] actualParameters) { Context baseContext = base.getCalleeTarget(caller, site, callee, actualParameters); if ((isInvoke(callee) || isType(callee)) && callee.getReference().getDeclaringClass().getName().equals(TypeReference.JavaLangInvokeMethodHandle.getName())) { if (actualParameters != null && actualParameters.length > 0) { InstanceKey selfKey = actualParameters[0]; if (selfKey instanceof ConstantKey && ((ConstantKey)selfKey).getConcreteType().getReference().equals(TypeReference.JavaLangInvokeMethodHandle)) { MethodReference ref = ((IMethod) ((ConstantKey)selfKey).getValue()).getReference(); return new MethodContext(baseContext, ref); } } } if (isFindStatic(callee) && callee.getDeclaringClass().getReference().equals(TypeReference.JavaLangInvokeMethodHandlesLookup)) { if (actualParameters != null && actualParameters.length > 2) { InstanceKey classKey = actualParameters[1]; InstanceKey nameKey = actualParameters[2]; if (classKey instanceof ConstantKey && ((ConstantKey)classKey).getConcreteType().getReference().equals(TypeReference.JavaLangClass) && nameKey instanceof ConstantKey && ((ConstantKey)nameKey).getConcreteType().getReference().equals(TypeReference.JavaLangString)) { return new FindContext(baseContext, ((IClass)((ConstantKey)classKey).getValue()).getReference(), (String)((ConstantKey)nameKey).getValue()); } } } return baseContext; }
private static boolean isConstructorConstant(InstanceKey instance) { if (instance instanceof ConstantKey) { ConstantKey c = (ConstantKey) instance; if (c.getConcreteType().getReference().equals(TypeReference.JavaLangReflectConstructor)) { return true; } } return false; }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((constant == null) ? 0 : constant.hashCode()); return result; }
@Override public Context getCalleeTarget(CGNode caller, CallSiteReference site, IMethod callee, InstanceKey[] actualParameters) { Context baseContext = base.getCalleeTarget(caller, site, callee, actualParameters); if ((isInvoke(callee) || isType(callee)) && callee.getReference().getDeclaringClass().getName().equals(TypeReference.JavaLangInvokeMethodHandle.getName())) { if (actualParameters != null && actualParameters.length > 0) { InstanceKey selfKey = actualParameters[0]; if (selfKey instanceof ConstantKey && ((ConstantKey)selfKey).getConcreteType().getReference().equals(TypeReference.JavaLangInvokeMethodHandle)) { MethodReference ref = ((IMethod) ((ConstantKey)selfKey).getValue()).getReference(); return new MethodContext(baseContext, ref); } } } if (isFindStatic(callee) && callee.getDeclaringClass().getReference().equals(TypeReference.JavaLangInvokeMethodHandlesLookup)) { if (actualParameters != null && actualParameters.length > 2) { InstanceKey classKey = actualParameters[1]; InstanceKey nameKey = actualParameters[2]; if (classKey instanceof ConstantKey && ((ConstantKey)classKey).getConcreteType().getReference().equals(TypeReference.JavaLangClass) && nameKey instanceof ConstantKey && ((ConstantKey)nameKey).getConcreteType().getReference().equals(TypeReference.JavaLangString)) { return new FindContext(baseContext, ((IClass)((ConstantKey)classKey).getValue()).getReference(), (String)((ConstantKey)nameKey).getValue()); } } } return baseContext; }
private static boolean isConstructorConstant(InstanceKey instance) { if (instance instanceof ConstantKey) { ConstantKey c = (ConstantKey) instance; if (c.getConcreteType().getReference().equals(TypeReference.JavaLangReflectConstructor)) { return true; } } return false; }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((constant == null) ? 0 : constant.hashCode()); return result; }
/** * Get the name. * @return the name */ public String getName() { return (String)name.getValue(); } }
@Override @SuppressWarnings("unchecked") public OrdinalSet<InstanceKey> getPointsToSet(PointerKey key) { 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; if (ifk.getInstanceKey() instanceof ConstantKey) { ConstantKey<?> i = (ConstantKey<?>) ifk.getInstanceKey(); if (i.getValue() instanceof String && i.getConcreteType().getClassLoader().getLanguage().equals(Language.JAVA)) { StringConstantCharArray contents = StringConstantCharArray.make((ConstantKey<String>) i); instanceKeys.add(contents); Collection<InstanceKey> singleton = HashSetFactory.make(); singleton.add(contents); return OrdinalSet.toOrdinalSet(singleton, instanceKeys); } } } PointsToSetVariable v = pointsToMap.getPointsToSet(key); if (v == null) { return OrdinalSet.empty(); } else { IntSet S = v.getValue(); return new OrdinalSet<>(S, instanceKeys); } }
/** * Create a constant key for a string. * @param cha the class hierarchy * @param str the string * @return the constant key */ protected static ConstantKey<String> makeConstantKey(IClassHierarchy cha,String str) { IClass cls = cha.lookupClass(TypeReference.JavaLangString); ConstantKey<String> ck = new ConstantKey<>(str,cls); return ck; }
@Override public IClass getConcreteType() { return constant.getConcreteType().getClassHierarchy().lookupClass(TypeReference.CharArray); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; final StringConstantCharArray other = (StringConstantCharArray) obj; if (constant == null) { if (other.constant != null) return false; } else if (!constant.equals(other.constant)) return false; return true; }
@Override public int hashCode() { return 6367 * type.hashCode() * name.hashCode(); }
@Override @SuppressWarnings("unchecked") public OrdinalSet<InstanceKey> getPointsToSet(PointerKey key) { 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; if (ifk.getInstanceKey() instanceof ConstantKey) { ConstantKey<?> i = (ConstantKey<?>) ifk.getInstanceKey(); if (i.getValue() instanceof String && i.getConcreteType().getClassLoader().getLanguage().equals(Language.JAVA)) { StringConstantCharArray contents = StringConstantCharArray.make((ConstantKey<String>) i); instanceKeys.add(contents); Collection<InstanceKey> singleton = HashSetFactory.make(); singleton.add(contents); return OrdinalSet.toOrdinalSet(singleton, instanceKeys); } } } PointsToSetVariable v = pointsToMap.getPointsToSet(key); if (v == null) { return OrdinalSet.empty(); } else { IntSet S = v.getValue(); return new OrdinalSet<>(S, instanceKeys); } }
@Override public InstanceKey getInstanceKeyForMetadataObject(Object obj, TypeReference objType) { IClass cls = cha.lookupClass(objType); assert cls != null : objType; if (obj instanceof TypeReference) { IClass klass = cha.lookupClass((TypeReference)obj); if (klass == null) { return new ConcreteTypeKey(cls); } else { // return the IClass itself, wrapped as a constant! return new ConstantKey<>(klass, cls); } } else if (obj instanceof MethodReference) { IMethod m = cha.resolveMethod((MethodReference)obj); if (m == null) { return new ConcreteTypeKey(cls); } else { return new ConstantKey<>(m, cls); } } else if (obj instanceof Descriptor) { return new ConstantKey<>((Descriptor)obj, cls); } else { // other cases throw new Error(); } }
@Override public IClass getConcreteType() { return constant.getConcreteType().getClassHierarchy().lookupClass(TypeReference.CharArray); }
@Override public boolean equals(Object obj) { if (obj == null) { return false; } if (getClass().equals(obj.getClass())) { GetMethodContext other = (GetMethodContext) obj; return type.equals(other.type) && name.equals(other.name); } else { return false; } }