@Override public void visitAstGlobalRead(AstGlobalRead instruction) { pointsToSet = analysis.computeImplicitPointsToSetAtGet(node, instruction.getDeclaredField(), -1, true); }
@Override public String toString() { StringBuilder result = new StringBuilder("PointerAnalysis:\n"); for (PointerKey p : Iterator2Iterable.make(pointsToMap.iterateKeys())) { OrdinalSet<InstanceKey> O = getPointsToSet(p); result.append(" ").append(p).append(" ->\n"); for (InstanceKey instanceKey : O) { result.append(" ").append(instanceKey).append('\n'); } } return result.toString(); }
/** * @return an object which encapsulates the pointer analysis result */ public PointerAnalysis<InstanceKey> makePointerAnalysis(PropagationCallGraphBuilder builder) { return new PointerAnalysisImpl(builder, cg, pointsToMap, instanceKeys, pointerKeyFactory, instanceKeyFactory); }
/** * @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(); for (CGNode target : getCallGraph().getPossibleTargets(node, call.getCallSite())) { PointerKey retVal = pointerKeys.getPointerKeyForExceptionalReturnValue(target); IntSet set = getPointsToSet(retVal).getBackingSet(); if (set != null) { S.addAll(set); } } return new OrdinalSet<>(S, instanceKeys); }
@Override public void visitAstGlobalRead(AstGlobalRead instruction) { JSPointerAnalysisImpl jsAnalysis = (JSPointerAnalysisImpl) analysis; FieldReference field = makeNonGlobalFieldReference(instruction.getDeclaredField()); assert !directGlobalObjectRef(field); IField f = jsAnalysis.builder.getCallGraph().getClassHierarchy().resolveField(field); assert f != null; MutableSparseIntSet S = MutableSparseIntSet.makeEmpty(); InstanceKey globalObj = ((AstSSAPropagationCallGraphBuilder) jsAnalysis.builder).getGlobalObject(JavaScriptTypes.jsName); PointerKey fkey = analysis.getHeapModel().getPointerKeyForInstanceField(globalObj, f); if (fkey != null) { OrdinalSet<InstanceKey> pointees = analysis.getPointsToSet(fkey); IntSet set = pointees.getBackingSet(); if (set != null) { S.addAll(set); } } pointsToSet = new OrdinalSet<>(S, analysis.getInstanceKeyMapping()); }
private OrdinalSet<InstanceKey> computeImplicitPointsToSetAtCheckCast(CGNode node, SSACheckCastInstruction instruction) { PointerKey rhs = pointerKeys.getPointerKeyForLocal(node, instruction.getVal()); OrdinalSet<InstanceKey> rhsSet = getPointsToSet(rhs); MutableSparseIntSet S = MutableSparseIntSet.makeEmpty(); for (TypeReference t : instruction.getDeclaredResultTypes()) { IClass klass = getCallGraph().getClassHierarchy().lookupClass(t); if (klass == null) { // could not find the type. conservatively assume Object return rhsSet; } else { if (klass.isInterface()) { for (InstanceKey ik : rhsSet) { if (getCallGraph().getClassHierarchy().implementsInterface(ik.getConcreteType(), klass)) { S.add(getInstanceKeyMapping().getMappedIndex(ik)); } } } else { for (InstanceKey ik : rhsSet) { if (getCallGraph().getClassHierarchy().isSubclassOf(ik.getConcreteType(), klass)) { S.add(getInstanceKeyMapping().getMappedIndex(ik)); } } } } } return new OrdinalSet<>(S, instanceKeys); }
return toOrdinalSet(ik); } else { SSAInstruction def = du.getDef(lpk.getValueNumber()); if (def != null) { ImplicitPointsToSetVisitor v = makeImplicitPointsToVisitor(lpk); def.visit(v); if (v.pointsToSet != null) {
private OrdinalSet<InstanceKey> computeImplicitPointsToSetAtCall(LocalPointerKey lpk, CGNode node, SSAInvokeInstruction call) { int exc = call.getException(); if (lpk.getValueNumber() == exc) { return computeImplicitExceptionsForCall(node, call); } else { Assertions.UNREACHABLE("time to implement me."); return null; } }
@Override public IClassHierarchy getClassHierarchy() { return getCallGraph().getClassHierarchy(); } }
public PointerAnalysisImpl(PropagationCallGraphBuilder builder, CallGraph cg, PointsToMap pointsToMap, MutableMapping<InstanceKey> instanceKeys, PointerKeyFactory pointerKeys, InstanceKeyFactory iKeyFactory) { super(cg, instanceKeys); this.builder = builder; this.pointerKeys = pointerKeys; this.iKeyFactory = iKeyFactory; this.pointsToMap = pointsToMap; if (iKeyFactory == null) { throw new IllegalArgumentException("null iKeyFactory"); } H = makeHeapModel(); }
@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); } }
public OrdinalSet<InstanceKey> computeImplicitPointsToSetAtGet(CGNode node, FieldReference field, int refVn, boolean isStatic) { IField f = getCallGraph().getClassHierarchy().resolveField(field); if (f == null) { return OrdinalSet.empty(); } if (isStatic) { PointerKey fKey = pointerKeys.getPointerKeyForStaticField(f); return getPointsToSet(fKey); } else { PointerKey ref = pointerKeys.getPointerKeyForLocal(node, refVn); MutableSparseIntSet S = MutableSparseIntSet.makeEmpty(); OrdinalSet<InstanceKey> refs = getPointsToSet(ref); for (InstanceKey ik : refs) { PointerKey fkey = pointerKeys.getPointerKeyForInstanceField(ik, f); if (fkey != null) { OrdinalSet pointees = getPointsToSet(fkey); IntSet set = pointees.getBackingSet(); if (set != null) { S.addAll(set); } } } return new OrdinalSet<>(S, instanceKeys); } }
@Override public void visitAstGlobalRead(AstGlobalRead instruction) { JSPointerAnalysisImpl jsAnalysis = (JSPointerAnalysisImpl) analysis; FieldReference field = makeNonGlobalFieldReference(instruction.getDeclaredField()); assert !directGlobalObjectRef(field); IField f = jsAnalysis.builder.getCallGraph().getClassHierarchy().resolveField(field); assert f != null; MutableSparseIntSet S = MutableSparseIntSet.makeEmpty(); InstanceKey globalObj = ((AstSSAPropagationCallGraphBuilder) jsAnalysis.builder).getGlobalObject(JavaScriptTypes.jsName); PointerKey fkey = analysis.getHeapModel().getPointerKeyForInstanceField(globalObj, f); if (fkey != null) { OrdinalSet<InstanceKey> pointees = analysis.getPointsToSet(fkey); IntSet set = pointees.getBackingSet(); if (set != null) { S.addAll(set); } } pointsToSet = new OrdinalSet<>(S, analysis.getInstanceKeyMapping()); }
private OrdinalSet<InstanceKey> computeImplicitPointsToSetAtCheckCast(CGNode node, SSACheckCastInstruction instruction) { PointerKey rhs = pointerKeys.getPointerKeyForLocal(node, instruction.getVal()); OrdinalSet<InstanceKey> rhsSet = getPointsToSet(rhs); MutableSparseIntSet S = MutableSparseIntSet.makeEmpty(); for (TypeReference t : instruction.getDeclaredResultTypes()) { IClass klass = getCallGraph().getClassHierarchy().lookupClass(t); if (klass == null) { // could not find the type. conservatively assume Object return rhsSet; } else { if (klass.isInterface()) { for (InstanceKey ik : rhsSet) { if (getCallGraph().getClassHierarchy().implementsInterface(ik.getConcreteType(), klass)) { S.add(getInstanceKeyMapping().getMappedIndex(ik)); } } } else { for (InstanceKey ik : rhsSet) { if (getCallGraph().getClassHierarchy().isSubclassOf(ik.getConcreteType(), klass)) { S.add(getInstanceKeyMapping().getMappedIndex(ik)); } } } } } return new OrdinalSet<>(S, instanceKeys); }
return toOrdinalSet(ik); } else { SSAInstruction def = du.getDef(lpk.getValueNumber()); if (def != null) { ImplicitPointsToSetVisitor v = makeImplicitPointsToVisitor(lpk); def.visit(v); if (v.pointsToSet != null) {
private OrdinalSet<InstanceKey> computeImplicitPointsToSetAtCall(LocalPointerKey lpk, CGNode node, SSAInvokeInstruction call) { int exc = call.getException(); if (lpk.getValueNumber() == exc) { return computeImplicitExceptionsForCall(node, call); } else { Assertions.UNREACHABLE("time to implement me."); return null; } }
@Override public IClassHierarchy getClassHierarchy() { return getCallGraph().getClassHierarchy(); } }
public PointerAnalysisImpl(PropagationCallGraphBuilder builder, CallGraph cg, PointsToMap pointsToMap, MutableMapping<InstanceKey> instanceKeys, PointerKeyFactory pointerKeys, InstanceKeyFactory iKeyFactory) { super(cg, instanceKeys); this.builder = builder; this.pointerKeys = pointerKeys; this.iKeyFactory = iKeyFactory; this.pointsToMap = pointsToMap; if (iKeyFactory == null) { throw new IllegalArgumentException("null iKeyFactory"); } H = makeHeapModel(); }
@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); } }
public OrdinalSet<InstanceKey> computeImplicitPointsToSetAtGet(CGNode node, FieldReference field, int refVn, boolean isStatic) { IField f = getCallGraph().getClassHierarchy().resolveField(field); if (f == null) { return OrdinalSet.empty(); } if (isStatic) { PointerKey fKey = pointerKeys.getPointerKeyForStaticField(f); return getPointsToSet(fKey); } else { PointerKey ref = pointerKeys.getPointerKeyForLocal(node, refVn); MutableSparseIntSet S = MutableSparseIntSet.makeEmpty(); OrdinalSet<InstanceKey> refs = getPointsToSet(ref); for (InstanceKey ik : refs) { PointerKey fkey = pointerKeys.getPointerKeyForInstanceField(ik, f); if (fkey != null) { OrdinalSet pointees = getPointsToSet(fkey); IntSet set = pointees.getBackingSet(); if (set != null) { S.addAll(set); } } } return new OrdinalSet<>(S, instanceKeys); } }