/** * @return the heap model used in this pointer analysis. */ @Override public HeapModel getHeapModel() { return pa.getHeapModel(); }
/** * @return the heap model used in this pointer analysis. */ @Override public HeapModel getHeapModel() { return pa.getHeapModel(); }
@Override public ExtendedHeapModel makeHeapModel(PointerAnalysis<T> pa) { return (AstHeapModel)pa.getHeapModel(); }
@Override public ExtendedHeapModel makeHeapModel(PointerAnalysis<T> pa) { return (AstHeapModel)pa.getHeapModel(); }
public ExtendedHeapModel makeHeapModel(PointerAnalysis<T> pa) { HeapModel heapModel = pa.getHeapModel(); if (heapModel instanceof ExtendedHeapModel) { return (ExtendedHeapModel) heapModel; } else { return new DelegatingExtendedHeapModel(heapModel); } }
public ExtendedHeapModel makeHeapModel(PointerAnalysis<T> pa) { HeapModel heapModel = pa.getHeapModel(); if (heapModel instanceof ExtendedHeapModel) { return (ExtendedHeapModel) heapModel; } else { return new DelegatingExtendedHeapModel(heapModel); } }
private static boolean predHoldsForPk(PointerKey curPk, Predicate<InstanceKey> pred, PointerAnalysis<InstanceKey> pa) { PointerKey curPkForPAHeapModel = convertToHeapModel(curPk, pa.getHeapModel()); OrdinalSet<InstanceKey> pointsToSet = pa.getPointsToSet(curPkForPAHeapModel); for (InstanceKey ik : pointsToSet) { if (!pred.test(ik)) { return false; } } return true; }
public PABasedMemoryAccessMap(PointerAnalysis<InstanceKey> pa, Map<Statement, Set<PointerKey>> mod, Map<Statement, Set<PointerKey>> ref) { if (pa == null) { throw new IllegalArgumentException("null pa"); } this.pa = pa; this.heapModel = pa.getHeapModel(); invMod = MapUtil.inverseMap(mod); invRef = MapUtil.inverseMap(ref); }
public PABasedMemoryAccessMap(PointerAnalysis<InstanceKey> pa, Map<Statement, Set<PointerKey>> mod, Map<Statement, Set<PointerKey>> ref) { if (pa == null) { throw new IllegalArgumentException("null pa"); } this.pa = pa; this.heapModel = pa.getHeapModel(); invMod = MapUtil.inverseMap(mod); invRef = MapUtil.inverseMap(ref); }
private static boolean predHoldsForPk(PointerKey curPk, Predicate<InstanceKey> pred, PointerAnalysis<InstanceKey> pa) { PointerKey curPkForPAHeapModel = convertToHeapModel(curPk, pa.getHeapModel()); OrdinalSet<InstanceKey> pointsToSet = pa.getPointsToSet(curPkForPAHeapModel); for (InstanceKey ik : pointsToSet) { if (!pred.test(ik)) { return false; } } return true; }
private Collection<Pair<CGNode, String>> getNodeNamePairsForAccess(CGNode n, Pair<String, String> nameAndDefiner) { Collection<Pair<CGNode, String>> result = HashSetFactory.make(); // use scope-mapping instance keys in pointer analysis. may need a different // scheme for CG construction not based on pointer analysis OrdinalSet<InstanceKey> functionValues = pa.getPointsToSet(pa.getHeapModel().getPointerKeyForLocal(n, 1)); for (InstanceKey ik : functionValues) { if (ik instanceof ScopeMappingInstanceKey) { ScopeMappingInstanceKey smik = (ScopeMappingInstanceKey) ik; for (CGNode definerNode : Iterator2Iterable.make(smik.getFunargNodes(nameAndDefiner))) { result.add(Pair.make(definerNode, nameAndDefiner.fst)); } } } return result; } }
private Collection<Pair<CGNode, String>> getNodeNamePairsForAccess(CGNode n, Pair<String, String> nameAndDefiner) { Collection<Pair<CGNode, String>> result = HashSetFactory.make(); // use scope-mapping instance keys in pointer analysis. may need a different // scheme for CG construction not based on pointer analysis OrdinalSet<InstanceKey> functionValues = pa.getPointsToSet(pa.getHeapModel().getPointerKeyForLocal(n, 1)); for (InstanceKey ik : functionValues) { if (ik instanceof ScopeMappingInstanceKey) { ScopeMappingInstanceKey smik = (ScopeMappingInstanceKey) ik; for (CGNode definerNode : Iterator2Iterable.make(smik.getFunargNodes(nameAndDefiner))) { result.add(Pair.make(definerNode, nameAndDefiner.fst)); } } } return result; } }
private static boolean isGlobal(Set<CGNode> functions, int local, PointerAnalysis<? extends InstanceKey> pa) { for(CGNode n : functions) { PointerKey l = pa.getHeapModel().getPointerKeyForLocal(n, local); if (l != null) { OrdinalSet<? extends InstanceKey> pointers = pa.getPointsToSet(l); if (pointers != null) { for(InstanceKey k : pointers) { if (k instanceof GlobalObjectKey || k instanceof GlobalVertex) { return true; } } } } } return false; }
private Set<CodeElement> getFieldAccessCodeElts(CGNode node, SSAFieldAccessInstruction inst) { if (inst.isStatic()) { return getStaticFieldAccessCodeElts(inst); } Set<CodeElement> elts = HashSetFactory.make(); final FieldReference fieldRef = inst.getDeclaredField(); final IField field = node.getClassHierarchy().resolveField(fieldRef); PointerKey pk = pa.getHeapModel().getPointerKeyForLocal(node, inst.getRef()); final OrdinalSet<InstanceKey> pointsToSet = pa.getPointsToSet(pk); if (pointsToSet.isEmpty()) { InstanceKey ik = new ConcreteTypeKey(field.getDeclaringClass()); elts.add(new FieldElement(ik, fieldRef)); elts.add(new InstanceKeyElement(ik)); } else { for (InstanceKey ik : pointsToSet) { elts.add(new FieldElement(ik, fieldRef)); elts.add(new InstanceKeyElement(ik)); } } return elts; }
private Set<CodeElement> getArrayRefCodeElts(CGNode node, SSAArrayReferenceInstruction inst) { Set<CodeElement> elts = HashSetFactory.make(); final PointerKey pk = pa.getHeapModel().getPointerKeyForLocal(node, inst.getArrayRef()); final OrdinalSet<InstanceKey> pointsToSet = pa.getPointsToSet(pk); if (pointsToSet.isEmpty()) { TypeReference arrayType = TypeReference.findOrCreateArrayOf(inst .getElementType()); InstanceKey ik = new ConcreteTypeKey(pa.getClassHierarchy() .lookupClass(arrayType)); elts.add(new InstanceKeyElement(ik)); } else { for (InstanceKey ik : pointsToSet) { elts.add(new InstanceKeyElement(ik)); } } return elts; }
private static <T extends InstanceKey> Set<Pair<CGNode, NewSiteReference>> getPrototypeSites(PointerAnalysis<T> fbPA, CallGraph CG, Function<T,Iterator<T>> proto, CGNode node, int vn) { Set<Pair<CGNode, NewSiteReference>> fbProtos = HashSetFactory.make(); PointerKey fbKey = fbPA.getHeapModel().getPointerKeyForLocal(node, vn); OrdinalSet<T> fbPointsTo = fbPA.getPointsToSet(fbKey); for(T o : fbPointsTo) { for(T p : Iterator2Iterable.make(proto.apply(o))) { for(Pair<CGNode, NewSiteReference> cs : Iterator2Iterable.make(p.getCreationSites(CG))) { fbProtos.add(cs); } } } return fbProtos; }
private static Set<Pair<CGNode, NewSiteReference>> ptrs(Set<CGNode> functions, int local, CallGraph CG, PointerAnalysis<? extends InstanceKey> pa) { Set<Pair<CGNode, NewSiteReference>> result = HashSetFactory.make(); for(CGNode n : functions) { PointerKey l = pa.getHeapModel().getPointerKeyForLocal(n, local); if (l != null) { OrdinalSet<? extends InstanceKey> pointers = pa.getPointsToSet(l); if (pointers != null) { for(InstanceKey k : pointers) { for(Pair<CGNode, NewSiteReference> cs : Iterator2Iterable.make(k.getCreationSites(CG))) { result.add(cs); } } } } } return result; }
private static DemandRefinementPointsTo makeDemandPointerAnalysis(String scopeFile, String mainClass, String benchName) throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException { AnalysisScope scope = CallGraphTestUtil.makeJ2SEAnalysisScope(scopeFile, getExclusions(benchName)); // build a type hierarchy ClassHierarchy cha = ClassHierarchyFactory.make(scope); // set up call graph construction options; mainly what should be considered // entrypoints? Iterable<Entrypoint> entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha, mainClass); AnalysisOptions options = CallGraphTestUtil.makeAnalysisOptions(scope, entrypoints); System.err.print("constructing call graph..."); final Pair<CallGraph, PointerAnalysis<InstanceKey>> cgAndPA = buildCallGraph(scope, cha, options); CallGraph cg = cgAndPA.fst; System.err.println("done"); System.err.println(CallGraphStats.getStats(cg)); MemoryAccessMap fam = new SimpleMemoryAccessMap(cg, cgAndPA.snd.getHeapModel(), false); DemandRefinementPointsTo fullDemandPointsTo = DemandRefinementPointsTo.makeWithDefaultFlowGraph(cg, heapModel, fam, cha, options, makeStateMachineFactory()); fullDemandPointsTo.setRefinementPolicyFactory(chooseRefinePolicyFactory(cha)); return fullDemandPointsTo; }
@Test public void testMultiDim() throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException { AnalysisScope scope = CallGraphTestUtil.makeJ2SEAnalysisScope(TestConstants.WALA_TESTDATA, CallGraphTestUtil.REGRESSION_EXCLUSIONS); ClassHierarchy cha = ClassHierarchyFactory.make(scope); Iterable<Entrypoint> entrypoints = com.ibm.wala.ipa.callgraph.impl.Util .makeMainEntrypoints(scope, cha, TestConstants.MULTI_DIM_MAIN); AnalysisOptions options = CallGraphTestUtil.makeAnalysisOptions(scope, entrypoints); CallGraphBuilder<InstanceKey> builder = Util.makeVanillaZeroOneCFABuilder(Language.JAVA, options, new AnalysisCacheImpl(),cha, scope); CallGraph cg = builder.makeCallGraph(options, null); PointerAnalysis<InstanceKey> pa = builder.getPointerAnalysis(); CGNode node = findDoNothingNode(cg); PointerKey pk = pa.getHeapModel().getPointerKeyForLocal(node, 1); OrdinalSet<InstanceKey> ptsTo = pa.getPointsToSet(pk); Assert.assertEquals(1, ptsTo.size()); }
@Test public void testZeroOneContainerCopyOf() throws IOException, ClassHierarchyException, IllegalArgumentException, CancelException { AnalysisScope scope = CallGraphTestUtil.makeJ2SEAnalysisScope(TestConstants.WALA_TESTDATA, CallGraphTestUtil.REGRESSION_EXCLUSIONS); ClassHierarchy cha = ClassHierarchyFactory.make(scope); Iterable<Entrypoint> entrypoints = Util.makeMainEntrypoints(scope, cha, "Ldemandpa/TestArraysCopyOf"); AnalysisOptions options = CallGraphTestUtil.makeAnalysisOptions(scope, entrypoints); IAnalysisCacheView cache = new AnalysisCacheImpl(); CallGraphBuilder<InstanceKey> builder = Util.makeZeroOneContainerCFABuilder(options, cache, cha, scope); CallGraph cg = builder.makeCallGraph(options, null); PointerAnalysis<InstanceKey> pa = builder.getPointerAnalysis(); CGNode mainMethod = AbstractPtrTest.findMainMethod(cg); PointerKey keyToQuery = AbstractPtrTest.getParam(mainMethod, "testThisVar", pa.getHeapModel()); OrdinalSet<InstanceKey> pointsToSet = pa.getPointsToSet(keyToQuery); Assert.assertEquals(1, pointsToSet.size()); } /**