private void initDataStructures(PointerAnalysis<InstanceKey> pa) { HeapGraph<InstanceKey> heapGraph = pa.getHeapGraph(); OrdinalSetMapping<InstanceKey> instanceKeyMapping = pa.getInstanceKeyMapping(); for (Object n : heapGraph){ if (heapGraph.getPredNodeCount(n) == 0){ if (n instanceof PointerKey){ if (n instanceof ObjectPropertyCatalogKey){ ObjectPropertyCatalogKey opck = (ObjectPropertyCatalogKey) n; InstanceKey instanceKey = opck.getObject(); int instanceKeyId = instanceKeyMapping.getMappedIndex(instanceKey); mapUsingMutableMapping(instanceKeyIdToObjectPropertyCatalogKey, instanceKeyId, opck); } else if (n instanceof AstGlobalPointerKey){ globalsPointerKeys.add((AstGlobalPointerKey) n); } } else { System.err.println("Non Pointer key root: " + n); } } } }
/** * Collects all exceptions, which could be dispatched by the throw * instruction, using the pointer analysis. Adds the collected exceptions to * addTo. * * @param addTo * set to add the result * @param instruction * the throw instruction */ private void addThrown(LinkedHashSet<TypeReference> addTo, SSAThrowInstruction instruction) { int exceptionVariable = instruction.getException(); if (pointerAnalysis != null) { PointerKey pointerKey = pointerAnalysis.getHeapModel().getPointerKeyForLocal(node, exceptionVariable); Iterator<Object> it = pointerAnalysis.getHeapGraph().getSuccNodes(pointerKey); while (it.hasNext()) { Object next = it.next(); if (next instanceof InstanceKey) { InstanceKey instanceKey = (InstanceKey) next; IClass iclass = instanceKey.getConcreteType(); addTo.add(iclass.getReference()); } else { throw new IllegalStateException("Internal error: Expected InstanceKey, got " + next.getClass().getName()); } } } }
InstanceKey ik = hg.getHeapModel().getInstanceKeyForAllocation(n, site); if (ik == null) { throw new WalaException("could not get instance key at site " + site + " in " + n); for (Object o : Iterator2Iterable.make(hg.getPredNodes(ik))) { PointerKey p = (PointerKey) o; if (!(p instanceof AbstractLocalPointerKey)) {
for(ObjectVertex o : objPtrs) { PointerKey propKey = fbPA.getHeapModel().getPointerKeyForInstanceField(o, new AstDynamicField(false, o.getConcreteType(), Atom.findOrCreateUnicodeAtom(p), JavaScriptTypes.Root)); Assert.assertTrue("object " + o + " should have field " + propKey, hg.hasEdge(o, propKey)); OrdinalSet<ObjectVertex> valPtrs = fbPA.getPointsToSet(valKey); for(ObjectVertex v : valPtrs) { Assert.assertTrue("field " + propKey + " should point to object " + valKey + "(" + v + ")", hg.hasEdge(propKey, v)); propName = propName.substring("global ".length()); PointerKey propKey = fbPA.getHeapModel().getPointerKeyForInstanceField(null, new AstDynamicField(false, null, Atom.findOrCreateUnicodeAtom(propName), JavaScriptTypes.Root)); Assert.assertTrue("global " + propName + " should exist", hg.hasEdge(GlobalVertex.instance(), propKey)); boolean dump = false; PointerKey pointerKeyForInstanceField = fbPA.getHeapModel().getPointerKeyForInstanceField(k, new AstDynamicField(false, k.getConcreteType(), Atom.findOrCreateUnicodeAtom(f), JavaScriptTypes.Root)); if (! hg.containsNode(pointerKeyForInstanceField)) { dump = true; System.err.println("no " + f + " for " + k + "(" + k.getConcreteType() + ")"); } else if (! hg.getSuccNodes(pointerKeyForInstanceField).hasNext()){ dump = true; System.err.println("empty " + f + " for " + k + "(" + k.getConcreteType() + ")");
private static Set<Pair<CGNode, NewSiteReference>> getFbPrototypes(PointerAnalysis<ObjectVertex> fbPA, final HeapGraph<ObjectVertex> hg, CallGraph CG, CGNode node, int vn) { return getPrototypeSites(fbPA, CG, o -> { PrototypeFieldVertex proto = new PrototypeFieldVertex(PrototypeField.__proto__, o); if (hg.containsNode(proto)) { return new MapIterator<>(hg.getSuccNodes(proto), ObjectVertex.class::cast); } else { return EmptyIterator.instance(); } }, node, vn); }
@Override public boolean mayBeLive(CGNode allocMethod, int allocPC, CGNode m, int instructionIndex) throws IllegalArgumentException, WalaException { if (allocMethod == null) { throw new IllegalArgumentException("allocMethod == null"); } NewSiteReference site = TrivialMethodEscape.findAlloc(allocMethod, allocPC); InstanceKey ik = heapGraph.getHeapModel().getInstanceKeyForAllocation(allocMethod, site); return mayBeLive(ik, m, instructionIndex); }
@Override public boolean mayBeLive(CGNode allocMethod, int allocPC, CGNode m, int instructionIndex) throws IllegalArgumentException, WalaException { if (allocMethod == null) { throw new IllegalArgumentException("allocMethod == null"); } NewSiteReference site = TrivialMethodEscape.findAlloc(allocMethod, allocPC); InstanceKey ik = heapGraph.getHeapModel().getInstanceKeyForAllocation(allocMethod, site); return mayBeLive(ik, m, instructionIndex); }
private void initDataStructures(PointerAnalysis<InstanceKey> pa) { HeapGraph<InstanceKey> heapGraph = pa.getHeapGraph(); OrdinalSetMapping<InstanceKey> instanceKeyMapping = pa.getInstanceKeyMapping(); for (Object n : heapGraph){ if (heapGraph.getPredNodeCount(n) == 0){ if (n instanceof PointerKey){ if (n instanceof ObjectPropertyCatalogKey){ ObjectPropertyCatalogKey opck = (ObjectPropertyCatalogKey) n; InstanceKey instanceKey = opck.getObject(); int instanceKeyId = instanceKeyMapping.getMappedIndex(instanceKey); mapUsingMutableMapping(instanceKeyIdToObjectPropertyCatalogKey, instanceKeyId, opck); } else if (n instanceof AstGlobalPointerKey){ globalsPointerKeys.add((AstGlobalPointerKey) n); } } else { System.err.println("Non Pointer key root: " + n); } } } }
InstanceKey ik = hg.getHeapModel().getInstanceKeyForAllocation(n, site); if (ik == null) { throw new WalaException("could not get instance key at site " + site + " in " + n); for (Object o : Iterator2Iterable.make(hg.getPredNodes(ik))) { PointerKey p = (PointerKey) o; if (!(p instanceof AbstractLocalPointerKey)) {
/** * Collects all exceptions, which could be dispatched by the throw * instruction, using the pointer analysis. Adds the collected exceptions to * addTo. * * @param addTo * set to add the result * @param instruction * the throw instruction */ private void addThrown(LinkedHashSet<TypeReference> addTo, SSAThrowInstruction instruction) { int exceptionVariable = instruction.getException(); if (pointerAnalysis != null) { PointerKey pointerKey = pointerAnalysis.getHeapModel().getPointerKeyForLocal(node, exceptionVariable); Iterator<Object> it = pointerAnalysis.getHeapGraph().getSuccNodes(pointerKey); while (it.hasNext()) { Object next = it.next(); if (next instanceof InstanceKey) { InstanceKey instanceKey = (InstanceKey) next; IClass iclass = instanceKey.getConcreteType(); addTo.add(iclass.getReference()); } else { throw new IllegalStateException("Internal error: Expected InstanceKey, got " + next.getClass().getName()); } } } }
private void initDataStructures(PointerAnalysis<InstanceKey> pa) { HeapGraph<InstanceKey> heapGraph = pa.getHeapGraph(); OrdinalSetMapping<InstanceKey> instanceKeyMapping = pa.getInstanceKeyMapping(); for (Object n : heapGraph){ if (heapGraph.getPredNodeCount(n) == 0){ // considering only roots of the heap graph. if (n instanceof PointerKey){ if (n instanceof LocalPointerKey){ LocalPointerKey lpk = (LocalPointerKey) n; int nodeId = lpk.getNode().getGraphNodeId(); mapUsingMutableMapping(cgNodeIdToLocalPointers, nodeId, lpk); } else if (n instanceof ReturnValueKey){ ReturnValueKey rvk = (ReturnValueKey) n; int nodeId = rvk.getNode().getGraphNodeId(); mapUsingMutableMapping(cgNodeIdToReturnValue, nodeId, rvk); } else if (n instanceof InstanceFieldPointerKey){ InstanceFieldPointerKey ifpk = (InstanceFieldPointerKey) n; int instanceKeyId = instanceKeyMapping.getMappedIndex(ifpk.getInstanceKey()); mapUsingMutableMapping(instanceKeyIdToInstanceFieldPointers, instanceKeyId, ifpk); } } else { System.err.println("Non Pointer key root: " + n); } } } }
private void initDataStructures(PointerAnalysis<InstanceKey> pa) { HeapGraph<InstanceKey> heapGraph = pa.getHeapGraph(); OrdinalSetMapping<InstanceKey> instanceKeyMapping = pa.getInstanceKeyMapping(); for (Object n : heapGraph){ if (heapGraph.getPredNodeCount(n) == 0){ // considering only roots of the heap graph. if (n instanceof PointerKey){ if (n instanceof LocalPointerKey){ LocalPointerKey lpk = (LocalPointerKey) n; int nodeId = lpk.getNode().getGraphNodeId(); mapUsingMutableMapping(cgNodeIdToLocalPointers, nodeId, lpk); } else if (n instanceof ReturnValueKey){ ReturnValueKey rvk = (ReturnValueKey) n; int nodeId = rvk.getNode().getGraphNodeId(); mapUsingMutableMapping(cgNodeIdToReturnValue, nodeId, rvk); } else if (n instanceof InstanceFieldPointerKey){ InstanceFieldPointerKey ifpk = (InstanceFieldPointerKey) n; int instanceKeyId = instanceKeyMapping.getMappedIndex(ifpk.getInstanceKey()); mapUsingMutableMapping(instanceKeyIdToInstanceFieldPointers, instanceKeyId, ifpk); } } else { System.err.println("Non Pointer key root: " + n); } } } }