Skip to content

Commit 239b3b0

Browse files
committed
make sure the AnalysisFields in FieldLocationIdentity are properly transplanted to HostedFields
1 parent 5b21bf0 commit 239b3b0

File tree

4 files changed

+37
-8
lines changed

4 files changed

+37
-8
lines changed

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/analysis/tesa/AbstractTesa.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import com.oracle.svm.common.meta.MultiMethod;
4141
import com.oracle.svm.hosted.analysis.tesa.effect.TesaEffect;
4242
import com.oracle.svm.hosted.meta.HostedMethod;
43+
import com.oracle.svm.hosted.meta.HostedUniverse;
4344
import com.oracle.svm.util.ClassUtil;
4445

4546
import jdk.graal.compiler.graph.Node;
@@ -229,7 +230,7 @@ public T getState(TesaEngine engine, Invoke invoke) {
229230
/**
230231
* Apply the results of this analysis on the given compilation {@code graph}.
231232
*/
232-
public void applyResults(TesaEngine engine, HostedMethod method, StructuredGraph graph) {
233+
public void applyResults(TesaEngine engine, HostedUniverse universe, HostedMethod method, StructuredGraph graph) {
233234
var state = getState(method.wrapped);
234235
if (hasOptimizationPotential(state)) {
235236
onOptimizableMethodDiscovered(method, state, graph);
@@ -240,7 +241,7 @@ public void applyResults(TesaEngine engine, HostedMethod method, StructuredGraph
240241
var targetState = getState(engine, invoke);
241242
if (hasOptimizationPotential(targetState)) {
242243
optimizableInvokesCounter.incrementAndGet();
243-
optimizeInvoke(graph, invoke, targetState);
244+
optimizeInvoke(universe, graph, invoke, targetState);
244245
}
245246
}
246247
}
@@ -279,7 +280,7 @@ protected boolean hasOptimizationPotential(T state) {
279280
* have to implement it.
280281
*/
281282
@SuppressWarnings("unused")
282-
protected void optimizeInvoke(StructuredGraph graph, Invoke invoke, T targetState) {
283+
protected void optimizeInvoke(HostedUniverse universe, StructuredGraph graph, Invoke invoke, T targetState) {
283284

284285
}
285286

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/analysis/tesa/KilledLocationTesa.java

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,17 @@
2626

2727
import org.graalvm.word.LocationIdentity;
2828

29+
import com.oracle.graal.pointsto.meta.AnalysisField;
2930
import com.oracle.graal.pointsto.meta.AnalysisMethod;
3031
import com.oracle.graal.pointsto.util.AnalysisError;
32+
import com.oracle.svm.core.graal.nodes.SubstrateFieldLocationIdentity;
3133
import com.oracle.svm.hosted.analysis.tesa.effect.LocationEffect;
34+
import com.oracle.svm.hosted.code.AnalysisToHostedGraphTransplanter;
3235
import com.oracle.svm.hosted.meta.HostedMethod;
36+
import com.oracle.svm.hosted.meta.HostedUniverse;
3337

3438
import jdk.graal.compiler.graph.Node;
39+
import jdk.graal.compiler.nodes.FieldLocationIdentity;
3540
import jdk.graal.compiler.nodes.Invoke;
3641
import jdk.graal.compiler.nodes.InvokeNode;
3742
import jdk.graal.compiler.nodes.InvokeWithExceptionNode;
@@ -114,14 +119,36 @@ private static boolean checkNoSafepointNodes(HostedMethod method, LocationEffect
114119
}
115120

116121
@Override
117-
protected void optimizeInvoke(StructuredGraph graph, Invoke invoke, LocationEffect targetState) {
122+
protected void optimizeInvoke(HostedUniverse universe, StructuredGraph graph, Invoke invoke, LocationEffect targetState) {
118123
switch (targetState) {
119124
case LocationEffect.Empty _ -> setKilledLocationIdentity(invoke, MemoryKill.NO_LOCATION);
120-
case LocationEffect.Single single -> setKilledLocationIdentity(invoke, single.location);
125+
case LocationEffect.Single single -> setKilledLocationIdentity(invoke, transplantIdentity(universe, single.location));
121126
default -> AnalysisError.shouldNotReachHere(targetState + " is not actionable.");
122127
}
123128
}
124129

130+
/**
131+
* The effects computed by the analysis may still contain <i>analysis</i> references that have
132+
* to be transplanted to <i>hosted</i>.
133+
*
134+
* @see AnalysisToHostedGraphTransplanter
135+
*/
136+
private static LocationIdentity transplantIdentity(HostedUniverse universe, LocationIdentity location) {
137+
return switch (location) {
138+
case SubstrateFieldLocationIdentity substrateFieldLocationIdentity -> {
139+
var field = substrateFieldLocationIdentity.getField();
140+
assert field instanceof AnalysisField : "The field computed by the TESA should be still an analysis field: " + field;
141+
yield new SubstrateFieldLocationIdentity(universe.lookup(field), substrateFieldLocationIdentity.isImmutable());
142+
}
143+
case FieldLocationIdentity fieldLocationIdentity -> {
144+
var field = fieldLocationIdentity.getField();
145+
assert field instanceof AnalysisField : "The field computed by the TESA should be still an analysis field: " + field;
146+
yield new FieldLocationIdentity(universe.lookup(field), fieldLocationIdentity.isImmutable());
147+
}
148+
default -> location;
149+
};
150+
}
151+
125152
private static void setKilledLocationIdentity(Invoke invoke, LocationIdentity locationIdentity) {
126153
switch (invoke) {
127154
case InvokeNode invokeNode -> invokeNode.setKilledLocationIdentity(locationIdentity);

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/analysis/tesa/TesaEngine.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import com.oracle.svm.core.util.VMError;
4747
import com.oracle.svm.hosted.analysis.tesa.effect.TesaEffect;
4848
import com.oracle.svm.hosted.meta.HostedMethod;
49+
import com.oracle.svm.hosted.meta.HostedUniverse;
4950
import com.oracle.svm.util.ClassUtil;
5051
import com.oracle.svm.util.ImageBuildStatistics;
5152

@@ -181,15 +182,15 @@ public void runFixedPointLoops(BigBang bb) {
181182
/**
182183
* @see AbstractTesa#applyResults
183184
*/
184-
public void applyResults(HostedMethod method, StructuredGraph graph) {
185+
public void applyResults(HostedUniverse universe, HostedMethod method, StructuredGraph graph) {
185186
totalMethodsCounter.incrementAndGet();
186187
for (Node node : graph.getNodes()) {
187188
if (node instanceof Invoke) {
188189
totalInvokesCounter.incrementAndGet();
189190
}
190191
}
191192
for (AbstractTesa<?> analysis : analyses.values()) {
192-
analysis.applyResults(this, method, graph);
193+
analysis.applyResults(this, universe, method, graph);
193194
}
194195
}
195196

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/code/CompileQueue.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1398,7 +1398,7 @@ private CompilationResult defaultCompileFunction(DebugContext debug, HostedMetho
13981398
assert GraphOrder.assertSchedulableGraph(graph);
13991399

14001400
if (TesaEngine.enabled()) {
1401-
TesaEngine.get().applyResults(method, graph);
1401+
TesaEngine.get().applyResults(universe, method, graph);
14021402
}
14031403

14041404
try (DebugContext.Scope _ = debug.scope("Compiling", graph, method, this);

0 commit comments

Comments
 (0)