Skip to content

Commit e98678b

Browse files
committed
[GR-65389] Use LIR lowering for DeoptimizeNode
PullRequest: graal/20864
2 parents f67d0bf + 543d3e1 commit e98678b

File tree

11 files changed

+33
-160
lines changed

11 files changed

+33
-160
lines changed

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/CompilationTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ protected HotSpotCompilationRequestResult performCompilation(DebugContext debug)
313313
ListIterator<BasePhase<? super LowTierContext>> lowTierPhasesIterator = suites.getLowTier().findPhase(SchedulePhase.FinalSchedulePhase.class);
314314
if (lowTierPhasesIterator != null) {
315315
lowTierPhasesIterator.previous();
316-
lowTierPhasesIterator.add(new ForceDeoptSpeculationPhase(decompileCount, null));
316+
lowTierPhasesIterator.add(new ForceDeoptSpeculationPhase(decompileCount));
317317
}
318318
}
319319
result = compiler.compile(graph, shouldRetainLocalVariables, shouldUsePreciseUnresolvedDeopts, eagerResolving, compilationId, debug, suites);

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/phases/common/ForceDeoptSpeculationPhase.java

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,14 @@
2828

2929
import java.util.Optional;
3030

31-
import jdk.graal.compiler.core.common.spi.ForeignCallDescriptor;
3231
import jdk.graal.compiler.debug.GraalError;
3332
import jdk.graal.compiler.graph.Node;
34-
import jdk.graal.compiler.nodes.ConstantNode;
3533
import jdk.graal.compiler.nodes.DeoptimizeNode;
3634
import jdk.graal.compiler.nodes.DynamicDeoptimizeNode;
3735
import jdk.graal.compiler.nodes.GraphState;
3836
import jdk.graal.compiler.nodes.ImplicitNullCheckNode;
3937
import jdk.graal.compiler.nodes.StructuredGraph;
4038
import jdk.graal.compiler.nodes.ValueNode;
41-
import jdk.graal.compiler.nodes.extended.ForeignCallNode;
4239
import jdk.graal.compiler.nodes.spi.CoreProviders;
4340
import jdk.graal.compiler.phases.BasePhase;
4441
import jdk.graal.compiler.phases.util.GraphSignature;
@@ -63,33 +60,8 @@ public class ForceDeoptSpeculationPhase extends BasePhase<CoreProviders> {
6360
*/
6461
final int recompileCount;
6562

66-
/**
67-
* Specifies the descriptor of deoptimize calls that have a speculation as an argument. Those
68-
* speculation arguments also have to be replaced if they are not proper speculations.
69-
*/
70-
final ForeignCallDescriptor deoptimizeCallDescriptor;
71-
final int deoptimizeCallSpeculationReasonArgumentIndex;
72-
73-
public ForceDeoptSpeculationPhase(int recompileCount, ForeignCallDescriptor deoptimizeCallDescriptor) {
63+
public ForceDeoptSpeculationPhase(int recompileCount) {
7464
this.recompileCount = recompileCount;
75-
int speculationReasonArgumentIndex = -1;
76-
if (deoptimizeCallDescriptor != null) {
77-
Class<?>[] argumentTypes = deoptimizeCallDescriptor.getArgumentTypes();
78-
for (int i = 0; i < argumentTypes.length; i++) {
79-
if (SpeculationLog.SpeculationReason.class.equals(argumentTypes[i])) {
80-
speculationReasonArgumentIndex = i;
81-
break;
82-
}
83-
}
84-
}
85-
if (speculationReasonArgumentIndex >= 0) {
86-
this.deoptimizeCallDescriptor = deoptimizeCallDescriptor;
87-
this.deoptimizeCallSpeculationReasonArgumentIndex = speculationReasonArgumentIndex;
88-
} else {
89-
this.deoptimizeCallDescriptor = null;
90-
this.deoptimizeCallSpeculationReasonArgumentIndex = -1;
91-
}
92-
9365
}
9466

9567
public static class TooManyDeoptimizationsError extends GraalError {
@@ -121,20 +93,6 @@ protected void run(StructuredGraph graph, CoreProviders context) {
12193
deopt.setSpeculation(speculation);
12294
}
12395
}
124-
if (deoptimizeCallDescriptor != null) {
125-
if (node instanceof ForeignCallNode foreignCallNode && deoptimizeCallDescriptor.equals(foreignCallNode.getDescriptor())) {
126-
ValueNode speculationReasonArgument = foreignCallNode.getArguments().get(deoptimizeCallSpeculationReasonArgumentIndex);
127-
assert speculationReasonArgument.isJavaConstant() : "Speculation reason argument node is not a JavaConstant";
128-
SpeculationLog.Speculation originalSpeculation = context.getMetaAccess().decodeSpeculation((JavaConstant) ((ConstantNode) speculationReasonArgument).getValue(),
129-
graph.getSpeculationLog());
130-
if (NO_SPECULATION.equals(originalSpeculation)) {
131-
SpeculationLog.Speculation newSpeculation = createSpeculation(graph, signature, foreignCallNode);
132-
JavaConstant speculationConstant = context.getMetaAccess().encodeSpeculation(newSpeculation);
133-
ConstantNode speculationNode = graph.addOrUnique(ConstantNode.forConstant(speculationConstant, context.getMetaAccess(), graph));
134-
((ConstantNode) speculationReasonArgument).replace(graph, speculationNode);
135-
}
136-
}
137-
}
13896
if (node instanceof ImplicitNullCheckNode implicitNullCheck) {
13997
JavaConstant spec = implicitNullCheck.getDeoptSpeculation();
14098
SpeculationLog.Speculation speculation = spec != null ? context.getMetaAccess().decodeSpeculation(spec, speculationLog) : NO_SPECULATION;

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@
2424
*/
2525
package jdk.graal.compiler.truffle;
2626

27-
import jdk.graal.compiler.core.common.spi.ForeignCallDescriptor;
2827
import jdk.graal.compiler.core.target.Backend;
2928
import jdk.graal.compiler.lir.phases.LIRSuites;
30-
import jdk.graal.compiler.options.OptionValues;
3129
import jdk.graal.compiler.phases.tiers.Suites;
3230
import jdk.graal.compiler.phases.util.Providers;
3331
import jdk.graal.compiler.truffle.phases.TruffleCompilerPhases;
@@ -39,19 +37,13 @@ public final class TruffleTierConfiguration {
3937
private final Suites suites;
4038
private final LIRSuites lirSuites;
4139

42-
public TruffleTierConfiguration(PartialEvaluatorConfiguration configuration, Backend backend, OptionValues options, KnownTruffleTypes knownTruffleTypes) {
43-
this(configuration, backend, backend.getProviders(), backend.getSuites().getDefaultSuites(options, backend.getTarget().arch), backend.getSuites().getDefaultLIRSuites(options),
44-
knownTruffleTypes, null);
45-
}
46-
47-
public TruffleTierConfiguration(PartialEvaluatorConfiguration configuration, Backend backend, Providers providers, Suites suites, LIRSuites lirSuites, KnownTruffleTypes knownTruffleTypes,
48-
ForeignCallDescriptor deoptimizeCallDescriptor) {
40+
public TruffleTierConfiguration(PartialEvaluatorConfiguration configuration, Backend backend, Providers providers, Suites suites, LIRSuites lirSuites, KnownTruffleTypes knownTruffleTypes) {
4941
this.configuration = configuration;
5042
this.backend = backend;
5143
this.providers = providers.copyWith(new TruffleStringConstantFieldProvider(providers, knownTruffleTypes));
5244
this.suites = suites;
5345
this.lirSuites = lirSuites;
54-
TruffleCompilerPhases.register(knownTruffleTypes, providers, suites, deoptimizeCallDescriptor);
46+
TruffleCompilerPhases.register(knownTruffleTypes, providers, suites);
5547
this.suites.setImmutable();
5648
}
5749

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/truffle/hotspot/HotSpotTruffleCompilerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ private static TruffleTierConfiguration createTierConfiguration(HotSpotGraalRunt
198198
Backend backend = createTruffleBackend(hotspotGraalRuntime, options, knownTruffleTypes, forceConfigName);
199199
Suites suites = backend.getSuites().getDefaultSuites(options, backend.getTarget().arch);
200200
LIRSuites lirSuites = backend.getSuites().getDefaultLIRSuites(options);
201-
return new TruffleTierConfiguration(peConfig, backend, backend.getProviders(), suites, lirSuites, knownTruffleTypes, null);
201+
return new TruffleTierConfiguration(peConfig, backend, backend.getProviders(), suites, lirSuites, knownTruffleTypes);
202202
}
203203

204204
private static String resolveConfigurationName(HotSpotGraalRuntimeProvider hotspotGraalRuntime, OptionValues options, String forceConfigName) {

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
import java.util.ListIterator;
2828

29-
import jdk.graal.compiler.core.common.spi.ForeignCallDescriptor;
3029
import jdk.graal.compiler.loop.phases.LoopSafepointEliminationPhase;
3130
import jdk.graal.compiler.phases.BasePhase;
3231
import jdk.graal.compiler.phases.common.DeoptimizationGroupingPhase;
@@ -43,7 +42,7 @@ public final class TruffleCompilerPhases {
4342
private TruffleCompilerPhases() {
4443
}
4544

46-
public static void register(KnownTruffleTypes types, Providers providers, Suites suites, ForeignCallDescriptor deoptimizeCallDescriptor) {
45+
public static void register(KnownTruffleTypes types, Providers providers, Suites suites) {
4746
if (suites.isImmutable()) {
4847
throw new IllegalStateException("Suites are already immutable.");
4948
}
@@ -64,7 +63,7 @@ public static void register(KnownTruffleTypes types, Providers providers, Suites
6463
ListIterator<BasePhase<? super LowTierContext>> lowTierPhasesIterator = suites.getLowTier().findPhase(SchedulePhase.FinalSchedulePhase.class);
6564
if (lowTierPhasesIterator != null) {
6665
lowTierPhasesIterator.previous();
67-
lowTierPhasesIterator.add(new TruffleForceDeoptSpeculationPhase(deoptimizeCallDescriptor));
66+
lowTierPhasesIterator.add(new TruffleForceDeoptSpeculationPhase());
6867
}
6968
}
7069

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
import com.oracle.truffle.compiler.TruffleCompilable;
2828

29-
import jdk.graal.compiler.core.common.spi.ForeignCallDescriptor;
3029
import jdk.graal.compiler.debug.GraalError;
3130
import jdk.graal.compiler.nodes.StructuredGraph;
3231
import jdk.graal.compiler.nodes.ValueNode;
@@ -37,8 +36,8 @@
3736
import jdk.graal.compiler.truffle.TruffleCompilerOptions;
3837

3938
public class TruffleForceDeoptSpeculationPhase extends ForceDeoptSpeculationPhase {
40-
public TruffleForceDeoptSpeculationPhase(ForeignCallDescriptor deoptimizeCallDescriptor) {
41-
super(0, deoptimizeCallDescriptor);
39+
public TruffleForceDeoptSpeculationPhase() {
40+
super(0);
4241
}
4342

4443
@Override

substratevm/src/com.oracle.svm.core.graal.aarch64/src/com/oracle/svm/core/graal/aarch64/SubstrateAArch64Backend.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
import com.oracle.svm.core.SubstrateUtil;
5050
import com.oracle.svm.core.aarch64.SubstrateAArch64MacroAssembler;
5151
import com.oracle.svm.core.config.ConfigurationValues;
52+
import com.oracle.svm.core.deopt.DeoptimizationRuntime;
53+
import com.oracle.svm.core.deopt.DeoptimizationSupport;
5254
import com.oracle.svm.core.deopt.Deoptimizer;
5355
import com.oracle.svm.core.graal.code.AssignedLocation;
5456
import com.oracle.svm.core.graal.code.PatchConsumerFactory;
@@ -607,7 +609,13 @@ public void emitUnwind(Value operand) {
607609

608610
@Override
609611
public void emitDeoptimize(Value actionAndReason, Value failedSpeculation, LIRFrameState state) {
610-
throw shouldNotReachHere("Substrate VM does not use deoptimization");
612+
if (!SubstrateUtil.HOSTED && DeoptimizationSupport.enabled()) {
613+
ForeignCallLinkage linkage = getForeignCalls().lookupForeignCall(DeoptimizationRuntime.DEOPTIMIZE);
614+
emitForeignCall(linkage, state, actionAndReason, failedSpeculation);
615+
append(new DeadEndOp());
616+
} else {
617+
throw shouldNotReachHere("Substrate VM does not use deoptimization");
618+
}
611619
}
612620

613621
@Override

substratevm/src/com.oracle.svm.core.graal.amd64/src/com/oracle/svm/core/graal/amd64/SubstrateAMD64Backend.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
import com.oracle.svm.core.amd64.AMD64CPUFeatureAccess;
6060
import com.oracle.svm.core.config.ConfigurationValues;
6161
import com.oracle.svm.core.cpufeature.Stubs;
62+
import com.oracle.svm.core.deopt.DeoptimizationRuntime;
63+
import com.oracle.svm.core.deopt.DeoptimizationSupport;
6264
import com.oracle.svm.core.deopt.Deoptimizer;
6365
import com.oracle.svm.core.graal.RuntimeCompilation;
6466
import com.oracle.svm.core.graal.code.AssignedLocation;
@@ -753,7 +755,13 @@ public void emitUnwind(Value operand) {
753755

754756
@Override
755757
public void emitDeoptimize(Value actionAndReason, Value failedSpeculation, LIRFrameState state) {
756-
throw shouldNotReachHere("Substrate VM does not use deoptimization");
758+
if (!SubstrateUtil.HOSTED && DeoptimizationSupport.enabled()) {
759+
ForeignCallLinkage linkage = getForeignCalls().lookupForeignCall(DeoptimizationRuntime.DEOPTIMIZE);
760+
emitForeignCall(linkage, state, actionAndReason, failedSpeculation);
761+
append(new DeadEndOp());
762+
} else {
763+
throw shouldNotReachHere("Substrate VM does not use deoptimization");
764+
}
757765
}
758766

759767
@Override

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/snippets/DeoptRuntimeSnippets.java

Lines changed: 0 additions & 88 deletions
This file was deleted.

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/snippets/DeoptSnippetsFeature.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@
2626

2727
import java.util.Map;
2828

29-
import jdk.graal.compiler.graph.Node;
30-
import jdk.graal.compiler.options.OptionValues;
31-
import jdk.graal.compiler.phases.util.Providers;
32-
3329
import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
3430
import com.oracle.svm.core.feature.InternalFeature;
3531
import com.oracle.svm.core.graal.meta.RuntimeConfiguration;
3632

33+
import jdk.graal.compiler.graph.Node;
34+
import jdk.graal.compiler.options.OptionValues;
35+
import jdk.graal.compiler.phases.util.Providers;
36+
3737
@AutomaticallyRegisteredFeature
3838
final class DeoptSnippetsFeature implements InternalFeature {
3939

@@ -42,8 +42,6 @@ public void registerLowerings(RuntimeConfiguration runtimeConfig, OptionValues o
4242
Map<Class<? extends Node>, NodeLoweringProvider<?>> lowerings, boolean hosted) {
4343
if (hosted) {
4444
DeoptHostedSnippets.registerLowerings(options, providers, lowerings);
45-
} else {
46-
DeoptRuntimeSnippets.registerLowerings(options, providers, lowerings);
4745
}
4846
}
4947
}

0 commit comments

Comments
 (0)