@Override public String toString() { StringBuilder str = new StringBuilder(); str.append("DynamicNewInstanceFlow<").append(getState()).append(">"); return str.toString(); } }
@Override public void initClone(BigBang bb) { assert this.isClone(); this.newTypeFlow.addObserver(bb, this); }
@Override public void onObservedUpdate(BigBang bb) { /* Only a clone should be updated */ assert this.isClone(); /* The state of the new type provider has changed. */ TypeState newTypeState = newTypeFlow.getState(); TypeState currentTypeState = getState(); /* Generate a heap object for every new incoming type. */ TypeState resultState = newTypeState.typesStream() .filter(t -> !currentTypeState.containsType(t)) .map(type -> TypeState.forAllocation(bb, source, allocationSite, type, allocationContext)) .reduce(TypeState.forEmpty(), (s1, s2) -> TypeState.forUnion(bb, s1, s2)); assert !resultState.canBeNull(); addState(bb, resultState); }
@Override public TypeFlow<ValueNode> copy(BigBang bb, MethodFlowsGraph methodFlows) { AnalysisContext enclosingContext = methodFlows.context(); AnalysisContext allocContext = bb.contextPolicy().allocationContext(enclosingContext, PointstoOptions.MaxHeapContextDepth.getValue(bb.getOptions())); return new DynamicNewInstanceTypeFlow(bb, this, methodFlows, allocContext); }
BytecodeLocation allocationLabel = bb.analysisPolicy().createAllocationSite(bb, key, method); TypeFlowBuilder<DynamicNewInstanceTypeFlow> dynamicNewInstanceBuilder = TypeFlowBuilder.create(bb, node, DynamicNewInstanceTypeFlow.class, () -> { DynamicNewInstanceTypeFlow newInstanceTypeFlow = new DynamicNewInstanceTypeFlow(instanceTypeBuilder.get(), node, allocationLabel); methodFlow.addDynamicAllocation(newInstanceTypeFlow); return newInstanceTypeFlow; DynamicNewInstanceTypeFlow newArrayTypeFlow = new DynamicNewInstanceTypeFlow(arrayType.getTypeFlow(bb, false), node, allocationLabel); methodFlow.addDynamicAllocation(newArrayTypeFlow); return newArrayTypeFlow; DynamicNewInstanceTypeFlow newArrayFlow = new DynamicNewInstanceTypeFlow(newArrayTypeBuilder.get(), node, newArrayLabel); methodFlow.addDynamicAllocation(newArrayFlow); return newArrayFlow;