Skip to content

Commit ca66d4a

Browse files
committed
[GR-71719] Fix early inlining and escape analysis needs two unwrap types on SVM.
PullRequest: graal/22750
2 parents 87743f1 + cd8f8f2 commit ca66d4a

File tree

5 files changed

+21
-14
lines changed

5 files changed

+21
-14
lines changed

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/truffle/CachingPEGraphDecoder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
package jdk.graal.compiler.truffle;
2626

2727
import java.util.concurrent.ConcurrentHashMap;
28+
import java.util.function.Function;
2829
import java.util.function.Supplier;
2930

3031
import org.graalvm.collections.EconomicMap;
@@ -128,7 +129,7 @@ private EncodedGraph createGraph(ResolvedJavaMethod method) {
128129
try (DebugContext.Scope scope = debug.scope("createGraph", graphToEncode)) {
129130
Providers p = this.graphCacheProviders;
130131

131-
new PrePartialEvaluationSuite(graphToEncode.getOptions(), truffleTypes, p, canonicalizer, (m) -> buildGraph(m, canonicalizer)).apply(graphToEncode, p);
132+
new PrePartialEvaluationSuite(graphToEncode.getOptions(), truffleTypes, p, canonicalizer, (m) -> buildGraph(m, canonicalizer), Function.identity()).apply(graphToEncode, p);
132133

133134
new ConvertDeoptimizeToGuardPhase(canonicalizer).apply(graphToEncode, p);
134135
if (GraalOptions.EarlyGVN.getValue(graphToEncode.getOptions())) {

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/truffle/phases/PrePartialEvaluationSuite.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import jdk.graal.compiler.phases.util.Providers;
3434
import jdk.graal.compiler.truffle.KnownTruffleTypes;
3535
import jdk.vm.ci.meta.ResolvedJavaMethod;
36+
import jdk.vm.ci.meta.ResolvedJavaType;
3637

3738
/**
3839
* This suite is intended to run on every graph prior to partial evaluation. It is not optional, as
@@ -44,10 +45,10 @@ public final class PrePartialEvaluationSuite extends PhaseSuite<Providers> {
4445

4546
@SuppressWarnings("this-escape")
4647
public PrePartialEvaluationSuite(OptionValues optionValues, KnownTruffleTypes truffleTypes, Providers providers, CanonicalizerPhase canonicalizer,
47-
Function<ResolvedJavaMethod, StructuredGraph> graphLookup) {
48+
Function<ResolvedJavaMethod, StructuredGraph> graphLookup, Function<ResolvedJavaType, ResolvedJavaType> unwrapType) {
4849
// only if Truffle is installed we can apply these phases.
49-
appendPhase(new TruffleEarlyInliningPhase(optionValues, canonicalizer, truffleTypes, providers, graphLookup));
50-
appendPhase(new TruffleEarlyEscapeAnalysisPhase(canonicalizer, optionValues, truffleTypes));
50+
appendPhase(new TruffleEarlyInliningPhase(optionValues, canonicalizer, truffleTypes, providers, graphLookup, unwrapType));
51+
appendPhase(new TruffleEarlyEscapeAnalysisPhase(canonicalizer, optionValues, truffleTypes, unwrapType));
5152

5253
}
5354

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/truffle/phases/TruffleEarlyEscapeAnalysisPhase.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
package jdk.graal.compiler.truffle.phases;
2626

2727
import java.util.Map;
28+
import java.util.function.Function;
2829

2930
import jdk.graal.compiler.annotation.AnnotationValue;
3031
import jdk.graal.compiler.annotation.AnnotationValueSupport;
@@ -40,11 +41,12 @@
4041
*/
4142
public final class TruffleEarlyEscapeAnalysisPhase extends PartialEscapePhase {
4243

43-
private final KnownTruffleTypes types;
44+
private final ResolvedJavaType unwrappedAnnotationType;
4445

45-
public TruffleEarlyEscapeAnalysisPhase(CanonicalizerPhase canonicalizer, OptionValues options, KnownTruffleTypes truffleTypes) {
46+
public TruffleEarlyEscapeAnalysisPhase(CanonicalizerPhase canonicalizer, OptionValues options, KnownTruffleTypes truffleTypes,
47+
Function<ResolvedJavaType, ResolvedJavaType> unwrapType) {
4648
super(false, canonicalizer, options);
47-
this.types = truffleTypes;
49+
this.unwrappedAnnotationType = unwrapType.apply(truffleTypes.CompilerDirectives_EarlyEscapeAnalysis);
4850
}
4951

5052
@Override
@@ -55,7 +57,7 @@ public boolean checkContract() {
5557
@Override
5658
protected boolean matchGraph(StructuredGraph graph) {
5759
Map<ResolvedJavaType, AnnotationValue> declaredAnnotationValues = AnnotationValueSupport.getDeclaredAnnotationValues(graph.method());
58-
if (!declaredAnnotationValues.containsKey(types.CompilerDirectives_EarlyEscapeAnalysis)) {
60+
if (!declaredAnnotationValues.containsKey(unwrappedAnnotationType)) {
5961
return false;
6062
}
6163
// we do not respect the PE only option for Truffle because PE depends on escape analysis

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/truffle/phases/TruffleEarlyInliningPhase.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,18 @@ static class Options {
7777
}
7878

7979
private final Providers providers;
80-
private final KnownTruffleTypes types;
8180
private final Function<ResolvedJavaMethod, StructuredGraph> lookup;
82-
protected final CanonicalizerPhase canonicalizer;
81+
private final ResolvedJavaType unwrappedAnnotationType;
82+
private final CanonicalizerPhase canonicalizer;
8383
private final int maxDepth;
8484

85-
public TruffleEarlyInliningPhase(OptionValues options, CanonicalizerPhase canonicalizer, KnownTruffleTypes types, Providers providers, Function<ResolvedJavaMethod, StructuredGraph> lookup) {
86-
this.types = types;
85+
public TruffleEarlyInliningPhase(OptionValues options, CanonicalizerPhase canonicalizer, KnownTruffleTypes types, Providers providers,
86+
Function<ResolvedJavaMethod, StructuredGraph> lookup, Function<ResolvedJavaType, ResolvedJavaType> unwrapType) {
8787
this.providers = providers;
8888
this.lookup = lookup;
8989
this.canonicalizer = canonicalizer;
9090
this.maxDepth = Options.TruffleEarlyInliningMaxDepth.getValue(options);
91+
this.unwrappedAnnotationType = unwrapType.apply(types.CompilerDirectives_EarlyInline);
9192
}
9293

9394
@Override
@@ -176,7 +177,7 @@ private boolean shouldInline(Invoke invoke) {
176177
return false;
177178
}
178179
Map<ResolvedJavaType, AnnotationValue> declaredAnnotationValues = AnnotationValueSupport.getDeclaredAnnotationValues(targetMethod);
179-
if (!declaredAnnotationValues.containsKey(types.CompilerDirectives_EarlyInline)) {
180+
if (!declaredAnnotationValues.containsKey(unwrappedAnnotationType)) {
180181
return false;
181182
}
182183
String failureMessage = InliningUtil.checkInvokeConditions(invoke);

substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/TruffleRuntimeCompilationFeature.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import com.oracle.svm.graal.hosted.runtimecompilation.RuntimeCompilationFeature;
4040
import com.oracle.svm.graal.hosted.runtimecompilation.RuntimeCompiledMethodSupport;
4141
import com.oracle.svm.hosted.FeatureImpl;
42+
import com.oracle.svm.util.OriginalClassProvider;
4243

4344
import jdk.graal.compiler.debug.DebugContext;
4445
import jdk.graal.compiler.nodes.StructuredGraph;
@@ -82,9 +83,10 @@ protected void applyParsingHookPhases(DebugContext debug, StructuredGraph graph,
8283
if (!ImageSingletons.contains(KnownTruffleTypes.class)) {
8384
return;
8485
}
86+
8587
KnownTruffleTypes truffleTypes = ImageSingletons.lookup(KnownTruffleTypes.class);
8688
new PrePartialEvaluationSuite(debug.getOptions(), truffleTypes,
87-
providers, canonicalizer, buildGraph).apply(graph, providers);
89+
providers, canonicalizer, buildGraph, OriginalClassProvider::getOriginalType).apply(graph, providers);
8890
}
8991

9092
@SuppressWarnings("javadoc")

0 commit comments

Comments
 (0)