Skip to content

Commit f92b1b0

Browse files
committed
Collect type flows that need initialization.
1 parent ba0b4ef commit f92b1b0

16 files changed

+92
-27
lines changed

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/flow/AbstractStaticInvokeTypeFlow.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ public void initFlow(PointsToAnalysis bb) {
4747
bb.postFlow(this);
4848
}
4949

50+
@Override
51+
public boolean needsInitialization() {
52+
return true;
53+
}
54+
5055
@Override
5156
public String toString() {
5257
return "StaticInvoke<" + targetMethod.format("%h.%n") + ">" + ":" + getState();

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/flow/CallSiteSensitiveMethodTypeFlow.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
package com.oracle.graal.pointsto.flow;
2626

2727
import java.util.Collection;
28+
import java.util.List;
2829
import java.util.concurrent.ConcurrentHashMap;
2930
import java.util.concurrent.ConcurrentMap;
3031

@@ -81,7 +82,7 @@ public MethodFlowsGraphInfo addContext(PointsToAnalysis bb, AnalysisContext call
8182
}
8283

8384
@Override
84-
protected void initFlowsGraph(PointsToAnalysis bb) {
85+
protected void initFlowsGraph(PointsToAnalysis bb, List<TypeFlow<?>> postInitFlows) {
8586
// nothing to do, cloning does all the initialization
8687
}
8788

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/flow/ConstantTypeFlow.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ public void initFlow(PointsToAnalysis bb) {
6666
addState(bb, constantState);
6767
}
6868

69+
@Override
70+
public boolean needsInitialization() {
71+
return true;
72+
}
73+
6974
@Override
7075
public String toString() {
7176
return "ConstantFlow<" + getState() + ">";

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/flow/DynamicNewInstanceTypeFlow.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ public void initFlow(PointsToAnalysis bb) {
7070
this.newTypeFlow.addObserver(bb, this);
7171
}
7272

73+
@Override
74+
public boolean needsInitialization() {
75+
return true;
76+
}
77+
7378
@Override
7479
public void onObservedUpdate(PointsToAnalysis bb) {
7580
/* The state of the new type provider has changed. */

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/flow/LoadFieldTypeFlow.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ public void initFlow(PointsToAnalysis bb) {
7474
fieldFlow.addUse(bb, this);
7575
}
7676

77+
@Override
78+
public boolean needsInitialization() {
79+
return true;
80+
}
81+
7782
@Override
7883
public String toString() {
7984
return "LoadStaticFieldTypeFlow<" + getState() + ">";

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/flow/MethodFlowsGraph.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,6 @@ public <T extends TypeFlow<?>> T lookupCloneOf(@SuppressWarnings("unused") Point
111111
return original;
112112
}
113113

114-
public void init(final PointsToAnalysis bb) {
115-
for (TypeFlow<?> flow : flows()) {
116-
/*
117-
* Run initialization code for corner case type flows. This can be used to add link from
118-
* 'outside' into the graph.
119-
*/
120-
flow.initFlow(bb);
121-
}
122-
}
123-
124114
protected static boolean nonCloneableFlow(TypeFlow<?> flow) {
125115
/*
126116
* References to field flows and to array elements flows are not part of the method itself;

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/flow/MethodFlowsGraphClone.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,6 @@ private <V extends TypeFlow<?>> List<V> lookupClonesOf(PointsToAnalysis bb, List
120120
return result;
121121
}
122122

123-
@Override
124-
public void init(final PointsToAnalysis bb) {
125-
// the cloning mechanism does all the initialization
126-
throw AnalysisError.shouldNotReachHere();
127-
}
128-
129123
@Override
130124
@SuppressWarnings("unchecked")
131125
public <T extends TypeFlow<?>> T lookupCloneOf(PointsToAnalysis bb, T original) {
@@ -175,7 +169,9 @@ void linkCloneFlows(final PointsToAnalysis bb) {
175169
* Run initialization code for corner case type flows. This can be used to add link from
176170
* 'outside' into the graph.
177171
*/
178-
clone.initFlow(bb);
172+
if (clone.needsInitialization()) {
173+
clone.initFlow(bb);
174+
}
179175

180176
/* Link all 'internal' observers. */
181177
for (TypeFlow<?> originalObserver : original.getObservers()) {

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/flow/MethodTypeFlow.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.graalvm.compiler.nodes.ValueNode;
4040

4141
import com.oracle.graal.pointsto.PointsToAnalysis;
42+
import com.oracle.graal.pointsto.flow.builder.TypeFlowGraphBuilder;
4243
import com.oracle.graal.pointsto.meta.AnalysisMethod;
4344
import com.oracle.graal.pointsto.meta.PointsToAnalysisMethod;
4445
import com.oracle.graal.pointsto.typestate.TypeState;
@@ -173,7 +174,7 @@ private synchronized void createFlowsGraph(PointsToAnalysis bb, InvokeTypeFlow r
173174
flowsGraph = builder.flowsGraph;
174175
assert flowsGraph != null;
175176

176-
initFlowsGraph(bb);
177+
initFlowsGraph(bb, builder.postInitFlows);
177178
} catch (Throwable t) {
178179
/* Wrap all other errors as parsing errors. */
179180
throw AnalysisError.parsingError(method, t);
@@ -202,8 +203,18 @@ private static int computeReturnedParameterIndex(StructuredGraph graph) {
202203
}
203204
}
204205

205-
protected void initFlowsGraph(PointsToAnalysis bb) {
206-
flowsGraph.init(bb);
206+
/**
207+
* Run type flow initialization. This will trigger state propagation from source flows, link
208+
* static load/store field flows, publish unsafe load/store flows, etc. The flows that need
209+
* initialization are collected by {@link TypeFlowGraphBuilder#build()}. Their initialization
210+
* needs to be triggered only after the graph is fully materialized such that lazily constructed
211+
* type flows (like InovkeTypeFlow.actualReturn) can observe the type state that other flows may
212+
* generate on initialization.
213+
*/
214+
protected void initFlowsGraph(PointsToAnalysis bb, List<TypeFlow<?>> postInitFlows) {
215+
for (TypeFlow<?> flow : postInitFlows) {
216+
flow.initFlow(bb);
217+
}
207218
}
208219

209220
public Collection<MethodFlowsGraph> getFlows() {
@@ -320,7 +331,7 @@ public synchronized boolean updateFlowsGraph(PointsToAnalysis bb, MethodFlowsGra
320331

321332
flowsGraph.updateInternalState(newGraphKind);
322333

323-
initFlowsGraph(bb);
334+
initFlowsGraph(bb, builder.postInitFlows);
324335

325336
if (registerAsImplementationInvoked) {
326337
if (parsingReason == null) {

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/flow/MethodTypeFlowBuilder.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ public class MethodTypeFlowBuilder {
161161
private final boolean newFlowsGraph;
162162

163163
protected final TypeFlowGraphBuilder typeFlowGraphBuilder;
164+
protected List<TypeFlow<?>> postInitFlows = List.of();
164165

165166
public MethodTypeFlowBuilder(PointsToAnalysis bb, PointsToAnalysisMethod method, MethodFlowsGraph flowsGraph, GraphKind graphKind) {
166167
this.bb = bb;
@@ -555,8 +556,8 @@ private void createTypeFlow() {
555556
// Propagate the type flows through the method's graph
556557
new NodeIterator(graph.start(), typeFlows).apply();
557558

558-
/* Prune the method graph. Eliminate nodes with no uses. */
559-
typeFlowGraphBuilder.build();
559+
/* Prune the method graph. Eliminate nodes with no uses. Collect flows that need init. */
560+
postInitFlows = typeFlowGraphBuilder.build();
560561

561562
/*
562563
* Make sure that all existing InstanceOfNodes are registered even when only used as an

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/flow/NewInstanceTypeFlow.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ public void initFlow(PointsToAnalysis bb) {
7474
}
7575
}
7676

77+
@Override
78+
public boolean needsInitialization() {
79+
return true;
80+
}
81+
7782
NewInstanceTypeFlow(PointsToAnalysis bb, NewInstanceTypeFlow original, MethodFlowsGraph methodFlows) {
7883
super(original, methodFlows, original.createCloneState(bb, methodFlows));
7984
}

0 commit comments

Comments
 (0)