@Override public HeapGraph<InstanceKey> getHeapGraph() { if (heapGraph == null) { heapGraph = new BasicHeapGraph<>(this, cg); } return heapGraph; }
this.callGraph = callGraph; final OrdinalSetMapping<PointerKey> pointerKeys = getPointerKeys(); final NumberedNodeManager<Object> nodeMgr = new NumberedNodeManager<Object>() { @Override final IBinaryNaturalRelation pred = computePredecessors(nodeMgr); final IntFunction<Object> toNode = nodeMgr::getNode;
/** * @return R, y \in R(x,y) if the node y is a predecessor of node x */ private IBinaryNaturalRelation computePredecessors(NumberedNodeManager<Object> nodeManager) { BasicNaturalRelation R = new BasicNaturalRelation(new byte[] { BasicNaturalRelation.SIMPLE }, BasicNaturalRelation.SIMPLE); // we split the following loops to improve temporal locality, // particularly for locals computePredecessorsForNonLocals(nodeManager, R); computePredecessorsForLocals(nodeManager, R); return R; }
@Override public String toString() { StringBuilder result = new StringBuilder(); result.append("Nodes:\n"); for (int i = 0; i <= getMaxNumber(); i++) { Object node = getNode(i); if (node != null) { result.append(i).append(" ").append(node).append('\n'); } } result.append("Edges:\n"); for (int i = 0; i <= getMaxNumber(); i++) { Object node = getNode(i); if (node != null) { result.append(i).append(" -> "); for (Object s : Iterator2Iterable.make(getSuccNodes(node))) { result.append(getNumber(s)).append(' '); } result.append('\n'); } } return result.toString(); }
private int[] computeSuccNodeNumbers(Object N, NumberedNodeManager<Object> nodeManager) { if (N instanceof PointerKey) { PointerKey P = (PointerKey) N; OrdinalSet<T> S = getPointerAnalysis().getPointsToSet(P); int[] result = new int[S.size()]; int i = 0; PointerKey p = getHeapModel().getPointerKeyForArrayContents(I); if (p == null || !nodeManager.containsNode(p)) { return null; IClass klass = getHeapModel().getClassHierarchy().lookupClass(T); assert klass != null : "null klass for type " + T; MutableSparseIntSet result = MutableSparseIntSet.makeEmpty(); for (IField f : klass.getAllInstanceFields()) { if (!f.getReference().getFieldType().isPrimitiveType()) { PointerKey p = getHeapModel().getPointerKeyForInstanceField(I, f); if (p != null && nodeManager.containsNode(p)) { result.add(nodeManager.getNumber(p));
/** * traverse locals in order, first by node, then by value number: attempt to improve locality */ private void computePredecessorsForLocals(NumberedNodeManager<Object> nodeManager, BasicNaturalRelation R) { ArrayList<LocalPointerKey> list = new ArrayList<>(); for (Object n : nodeManager) { if (n instanceof LocalPointerKey) { list.add((LocalPointerKey) n); } } Object[] arr = list.toArray(); Arrays.sort(arr, new LocalPointerComparator()); for (int i = 0; i < arr.length; i++) { if (VERBOSE) { if (i % VERBOSE_INTERVAL == 0) { System.err.println("Building HeapGraph: " + i + " of " + arr.length); } } LocalPointerKey n = (LocalPointerKey) arr[i]; int num = nodeManager.getNumber(n); int[] succ = computeSuccNodeNumbers(n, nodeManager); if (succ != null) { for (int j : succ) { R.add(j, num); } } } }
private OrdinalSetMapping<PointerKey> getPointerKeys() { MutableMapping<PointerKey> result = MutableMapping.make(); for (PointerKey p : getPointerAnalysis().getPointerKeys()) { result.add(p); } return result; }
@Override public String toString() { StringBuilder result = new StringBuilder(); result.append("Nodes:\n"); for (int i = 0; i <= getMaxNumber(); i++) { Object node = getNode(i); if (node != null) { result.append(i).append(" ").append(node).append('\n'); } } result.append("Edges:\n"); for (int i = 0; i <= getMaxNumber(); i++) { Object node = getNode(i); if (node != null) { result.append(i).append(" -> "); for (Object s : Iterator2Iterable.make(getSuccNodes(node))) { result.append(getNumber(s)).append(' '); } result.append('\n'); } } return result.toString(); }
private int[] computeSuccNodeNumbers(Object N, NumberedNodeManager<Object> nodeManager) { if (N instanceof PointerKey) { PointerKey P = (PointerKey) N; OrdinalSet<T> S = getPointerAnalysis().getPointsToSet(P); int[] result = new int[S.size()]; int i = 0; PointerKey p = getHeapModel().getPointerKeyForArrayContents(I); if (p == null || !nodeManager.containsNode(p)) { return null; IClass klass = getHeapModel().getClassHierarchy().lookupClass(T); assert klass != null : "null klass for type " + T; MutableSparseIntSet result = MutableSparseIntSet.makeEmpty(); for (IField f : klass.getAllInstanceFields()) { if (!f.getReference().getFieldType().isPrimitiveType()) { PointerKey p = getHeapModel().getPointerKeyForInstanceField(I, f); if (p != null && nodeManager.containsNode(p)) { result.add(nodeManager.getNumber(p));
/** * traverse locals in order, first by node, then by value number: attempt to improve locality */ private void computePredecessorsForLocals(NumberedNodeManager<Object> nodeManager, BasicNaturalRelation R) { ArrayList<LocalPointerKey> list = new ArrayList<>(); for (Object n : nodeManager) { if (n instanceof LocalPointerKey) { list.add((LocalPointerKey) n); } } Object[] arr = list.toArray(); Arrays.sort(arr, new LocalPointerComparator()); for (int i = 0; i < arr.length; i++) { if (VERBOSE) { if (i % VERBOSE_INTERVAL == 0) { System.err.println("Building HeapGraph: " + i + " of " + arr.length); } } LocalPointerKey n = (LocalPointerKey) arr[i]; int num = nodeManager.getNumber(n); int[] succ = computeSuccNodeNumbers(n, nodeManager); if (succ != null) { for (int j : succ) { R.add(j, num); } } } }
private OrdinalSetMapping<PointerKey> getPointerKeys() { MutableMapping<PointerKey> result = MutableMapping.make(); for (PointerKey p : getPointerAnalysis().getPointerKeys()) { result.add(p); } return result; }
@Override public HeapGraph<InstanceKey> getHeapGraph() { if (heapGraph == null) { heapGraph = new BasicHeapGraph<>(this, cg); } return heapGraph; }
/** * @return R, y \in R(x,y) if the node y is a predecessor of node x */ private IBinaryNaturalRelation computePredecessors(NumberedNodeManager<Object> nodeManager) { BasicNaturalRelation R = new BasicNaturalRelation(new byte[] { BasicNaturalRelation.SIMPLE }, BasicNaturalRelation.SIMPLE); // we split the following loops to improve temporal locality, // particularly for locals computePredecessorsForNonLocals(nodeManager, R); computePredecessorsForLocals(nodeManager, R); return R; }
this.callGraph = callGraph; final OrdinalSetMapping<PointerKey> pointerKeys = getPointerKeys(); final NumberedNodeManager<Object> nodeMgr = new NumberedNodeManager<Object>() { @Override final IBinaryNaturalRelation pred = computePredecessors(nodeMgr); final IntFunction<Object> toNode = nodeMgr::getNode;
private void computePredecessorsForNonLocals(NumberedNodeManager<Object> nodeManager, BasicNaturalRelation R) { // Note: we run this loop backwards on purpose, to avoid lots of resizing of // bitvectors // in the backing relation. i.e., we will add the biggest bits first. // pretty damn tricky. for (int i = nodeManager.getMaxNumber(); i >= 0; i--) { if (VERBOSE) { if (i % VERBOSE_INTERVAL == 0) { System.err.println("Building HeapGraph: " + i); } } Object n = nodeManager.getNode(i); if (!(n instanceof LocalPointerKey)) { int[] succ = computeSuccNodeNumbers(n, nodeManager); if (succ != null) { for (int j : succ) { R.add(j, i); } } } } }
public HeapGraph getHeapGraph() { if (heapGraph == null) { heapGraph = new BasicHeapGraph<>(getPointerAnalysis(), cg); } return heapGraph; }
private void computePredecessorsForNonLocals(NumberedNodeManager<Object> nodeManager, BasicNaturalRelation R) { // Note: we run this loop backwards on purpose, to avoid lots of resizing of // bitvectors // in the backing relation. i.e., we will add the biggest bits first. // pretty damn tricky. for (int i = nodeManager.getMaxNumber(); i >= 0; i--) { if (VERBOSE) { if (i % VERBOSE_INTERVAL == 0) { System.err.println("Building HeapGraph: " + i); } } Object n = nodeManager.getNode(i); if (!(n instanceof LocalPointerKey)) { int[] succ = computeSuccNodeNumbers(n, nodeManager); if (succ != null) { for (int j : succ) { R.add(j, i); } } } } }
public HeapGraph getHeapGraph() { if (heapGraph == null) { heapGraph = new BasicHeapGraph<>(getPointerAnalysis(), cg); } return heapGraph; }
public static Graph<Object> buildPointsTo(String appJar) throws WalaException, IllegalArgumentException, CancelException, IOException { AnalysisScope scope = AnalysisScopeReader.makeJavaBinaryAnalysisScope(appJar, (new FileProvider()).getFile(CallGraphTestUtil.REGRESSION_EXCLUSIONS)); ClassHierarchy cha = ClassHierarchyFactory.make(scope); Iterable<Entrypoint> entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha); AnalysisOptions options = new AnalysisOptions(scope, entrypoints); // // // build the call graph // // com.ibm.wala.ipa.callgraph.CallGraphBuilder<InstanceKey> builder = Util.makeVanillaZeroOneCFABuilder(Language.JAVA, options, new AnalysisCacheImpl(),cha, scope, null, null); CallGraph cg = builder.makeCallGraph(options,null); PointerAnalysis<InstanceKey> pointerAnalysis = builder.getPointerAnalysis(); System.err.println(pointerAnalysis); return new BasicHeapGraph<>(pointerAnalysis, cg); } }