protected void doVisitArrayLoad(int def, int arrayRef) { PointerKey result = getPointerKeyForLocal(def); PointerKey arrayRefPtrKey = getPointerKeyForLocal(arrayRef); if (hasNoInterestingUses(def)) { system.recordImplicitPointsToSet(result); } else { if (contentsAreInvariant(symbolTable, du, arrayRef)) { system.recordImplicitPointsToSet(arrayRefPtrKey); InstanceKey[] ik = getInvariantContents(arrayRef); for (int i = 0; i < ik.length; i++) { if (!representsNullType(ik[i])) { system.findOrCreateIndexForInstanceKey(ik[i]); PointerKey p = getPointerKeyForArrayContents(ik[i]); if (p == null) { } else { system.newConstraint(result, assignOperator, p); } } } } else { assert !system.isUnified(result); assert !system.isUnified(arrayRefPtrKey); system.newSideEffect(getBuilder().new ArrayLoadOperator(system.findOrCreatePointsToSet(result)), arrayRefPtrKey); } } }
protected PropagationSystem makeSystem(@SuppressWarnings("unused") AnalysisOptions options) { return new PropagationSystem(callGraph, pointerKeyFactory, instanceKeyFactory); }
@Override protected void action(PointerKey lexicalKey, int vn) { PointerKey rval = getPointerKeyForLocal(vn); if (contentsAreInvariant(symbolTable, du, vn)) { InstanceKey[] ik = getInvariantContents(vn); system.recordImplicitPointsToSet(rval); for (InstanceKey element : ik) { system.findOrCreateIndexForInstanceKey(element); system.newConstraint(lexicalKey, element); } } else { system.newConstraint(lexicalKey, assignOperator, rval); } } });
public void newSideEffect(UnaryOperator<PointsToSetVariable> op, PointerKey arg0) { if (arg0 == null) { throw new IllegalArgumentException("null arg0"); } if (DEBUG) { System.err.println("add constraint D: " + op + ' ' + arg0); } assert !pointsToMap.isUnified(arg0); PointsToSetVariable v1 = findOrCreatePointsToSet(arg0); newStatement(null, op, v1, true, true); }
@Override public void action(AbstractFieldPointerKey fieldKey) { if (!representsNullType(fieldKey.getInstanceKey())) { for (InstanceKey rhsFixedValue : rhsFixedValues) { system.findOrCreateIndexForInstanceKey(rhsFixedValue); system.newConstraint(fieldKey, rhsFixedValue); } } } }
@Override public byte evaluate(PointsToSetVariable lhs, PointsToSetVariable rhs) { IntSetVariable<?> tv = rhs; if (tv.getValue() != null) { tv.getValue().foreach(ptr -> { InstanceKey iKey = system.getInstanceKey(ptr); PointerKey enclosing = new EnclosingObjectReferenceKey(iKey, cls); system.newConstraint(lvalKey, assignOperator, enclosing); }); } return NOT_CHANGED; }
/** * Add a constraint to the system indicating that the contents of local src flows to dst, with no special type filter. */ private void addPiAssignment(PointerKey dst, int src) { PointerKey srcKey = getPointerKeyForLocal(src); if (contentsAreInvariant(symbolTable, du, src)) { system.recordImplicitPointsToSet(srcKey); InstanceKey[] ik = getInvariantContents(src); for (InstanceKey element : ik) { system.newConstraint(dst, element); } } else { system.newConstraint(dst, assignOperator, srcKey); } }
DefUse du = getBuilder().getCFAContextInterpreter().getDU(opNode); if (contentsAreInvariant(symtab, du, 1)) { system.recordImplicitPointsToSet(F); final InstanceKey[] functionKeys = getInvariantContents(symtab, du, opNode, 1); for (InstanceKey functionKey : functionKeys) { system.findOrCreateIndexForInstanceKey(functionKey); ScopeMappingInstanceKey K = (ScopeMappingInstanceKey) functionKey; Iterator<CGNode> x = K.getFunargNodes(definer); PointsToSetVariable FV = system.findOrCreatePointsToSet(F); if (FV.getValue() != null) { FV.getValue().foreach(ptr -> { InstanceKey iKey = system.getInstanceKey(ptr); if (iKey instanceof ScopeMappingInstanceKey) { ScopeMappingInstanceKey K = (ScopeMappingInstanceKey) iKey;
system.recordImplicitPointsToSet(objKey); system.newConstraint(lvalKey, assignOperator, enclosing); system.newSideEffect(new UnaryOperator<PointsToSetVariable>() { @Override public byte evaluate(PointsToSetVariable lhs, PointsToSetVariable rhs) {
PointerKey objCatalog = getPointerKeyForObjectCatalog(objKey); if (objCatalog != null) { system.newConstraint(objCatalog, assignOperator, fieldKey); system.newSideEffect(new UnaryOperator<PointsToSetVariable>() { @Override public byte evaluate(PointsToSetVariable lhs, PointsToSetVariable rhs) {
/** * @return true iff the system changes */ public boolean newFieldRead(PointerKey lhs, UnaryOperator<PointsToSetVariable> op, PointerKey rhs) { return newConstraint(lhs, op, rhs); }
PointsToSetVariable L = findOrCreatePointsToSet(lhs); int index = findOrCreateIndexForInstanceKey(value); if (!L.add(index)) { registerInstanceOfClass(value.getConcreteType(), index); changedVariable(L);
PointerKey receiverKey = getPointerKeyForLocal(receiverVn); if (contentsAreInvariant(symbolTable, du, receiverVn)) { system.recordImplicitPointsToSet(receiverKey); InstanceKey[] ik = getInvariantContents(receiverVn); for (InstanceKey element : ik) { system.newSideEffect(new ReceiverForDispatchOp(), receiverKey);
/** * Side effect: records invariant parameters as implicit points-to-sets. * * @return if non-null, then result[i] holds the set of instance keys which may be passed as the ith parameter. (which must be * invariant) */ @Override public InstanceKey[][] computeInvariantParameters(SSAAbstractInvokeInstruction call) { InstanceKey[][] constParams = null; for (int i = 0; i < call.getNumberOfUses(); i++) { // not sure how getUse(i) <= 0 .. dead code? // TODO: investigate if (call.getUse(i) > 0) { if (contentsAreInvariant(symbolTable, du, call.getUse(i))) { system.recordImplicitPointsToSet(getPointerKeyForLocal(call.getUse(i))); if (constParams == null) { constParams = new InstanceKey[call.getNumberOfUses()][]; } constParams[i] = getInvariantContents(call.getUse(i)); for (int j = 0; j < constParams[i].length; j++) { system.findOrCreateIndexForInstanceKey(constParams[i][j]); } } } } return constParams; } }
system.newSideEffect(new FieldValueDispatch(), fieldKey);
private String printRHSInstances(AbstractStatement s) { if (s instanceof UnaryStatement) { UnaryStatement u = (UnaryStatement) s; PointsToSetVariable rhs = (PointsToSetVariable) u.getRightHandSide(); IntSet value = rhs.getValue(); final int[] topFive = new int[5]; value.foreach(x -> { System.arraycopy(topFive, 1, topFive, 0, 4); topFive[4] = x; }); StringBuilder result = new StringBuilder(); for (int i = 0; i < 5; i++) { int p = topFive[i]; if (p != 0) { InstanceKey ik = getInstanceKey(p); result.append(p).append(" ").append(ik).append('\n'); } } return result.toString(); } else { return s.getClass().toString(); } }
public void newFieldWrite(CGNode opNode, int objVn, int fieldsVn, int rhsVn) { IRView ir = getBuilder().getCFAContextInterpreter().getIRView(opNode); SymbolTable symtab = ir.getSymbolTable(); DefUse du = getBuilder().getCFAContextInterpreter().getDU(opNode); PointerKey rhsKey = getBuilder().getPointerKeyForLocal(opNode, rhsVn); if (contentsAreInvariant(symtab, du, rhsVn)) { system.recordImplicitPointsToSet(rhsKey); newFieldWrite(opNode, objVn, fieldsVn, getInvariantContents(symtab, du, opNode, rhsVn)); } else { newFieldWrite(opNode, objVn, fieldsVn, rhsKey); } }
@Override public boolean addFiltered(PropagationSystem system, PointsToSetVariable L, PointsToSetVariable R) { int idx = system.findOrCreateIndexForInstanceKey(concreteType); if (R.contains(idx)) { return L.add(idx); } return false; }
protected IntSet getParamObjects(int paramIndex, @SuppressWarnings("unused") int rhsi) { int paramVn = call.getUse(paramIndex); PointerKey var = getPointerKeyForLocal(caller, paramVn); IntSet s = system.findOrCreatePointsToSet(var).getValue(); return s; } }
@Override protected void action(PointerKey lexicalKey, int vn) { PointerKey rval = getPointerKeyForLocal(vn); if (contentsAreInvariant(symbolTable, du, vn)) { InstanceKey[] ik = getInvariantContents(vn); system.recordImplicitPointsToSet(rval); for (InstanceKey element : ik) { system.findOrCreateIndexForInstanceKey(element); system.newConstraint(lexicalKey, element); } } else { system.newConstraint(lexicalKey, assignOperator, rval); } } });