Skip to content

Commit 61a8b7c

Browse files
committed
[GR-57553] Delay the canonicalization of TestDeoptimizeNode
PullRequest: graal/18647
2 parents b1869c0 + 6e0435d commit 61a8b7c

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/nodes/TestDeoptimizeNode.java renamed to substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/nodes/TestDeoptimizeNode.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -22,9 +22,11 @@
2222
* or visit www.oracle.com if you need additional information or have any
2323
* questions.
2424
*/
25-
package com.oracle.svm.hosted.nodes;
25+
package com.oracle.svm.core.graal.nodes;
2626

27-
import com.oracle.svm.hosted.code.SubstrateCompilationDirectives;
27+
import com.oracle.svm.core.BuildPhaseProvider;
28+
import com.oracle.svm.core.SubstrateUtil;
29+
import com.oracle.svm.core.util.VMError;
2830

2931
import jdk.graal.compiler.core.common.type.StampFactory;
3032
import jdk.graal.compiler.graph.Node;
@@ -40,8 +42,8 @@
4042
import jdk.vm.ci.meta.DeoptimizationReason;
4143

4244
/**
43-
* For deoptimzation testing. The node performs a deoptimization in a normally compiled method, but
44-
* is a no-op in the deoptimization target method.
45+
* For deoptimization testing. The node performs a deoptimization, but the lowering to
46+
* DeoptimizeNode is delayed, so that the analysis sees a return from original method.
4547
*/
4648
@NodeInfo(cycles = NodeCycles.CYCLES_IGNORED, size = NodeSize.SIZE_IGNORED)
4749
public class TestDeoptimizeNode extends FixedWithNextNode implements Canonicalizable {
@@ -53,12 +55,12 @@ public TestDeoptimizeNode() {
5355

5456
@Override
5557
public Node canonical(CanonicalizerTool tool) {
56-
if (SubstrateCompilationDirectives.isDeoptTarget(graph().method())) {
57-
/* no-op for deoptimization target methods. */
58-
return null;
59-
} else {
60-
/* deoptimization for all other methods. */
58+
if (SubstrateUtil.HOSTED) {
59+
if (!BuildPhaseProvider.isAnalysisFinished()) {
60+
return this;
61+
}
6162
return new DeoptimizeNode(DeoptimizationAction.None, DeoptimizationReason.TransferToInterpreter);
6263
}
64+
throw VMError.shouldNotReachHere("Should only be used in hosted.");
6365
}
6466
}

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/heap/PodFactorySubstitutionMethod.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@
4343
import com.oracle.svm.core.graal.nodes.DeoptProxyAnchorNode;
4444
import com.oracle.svm.core.graal.nodes.LoweredDeadEndNode;
4545
import com.oracle.svm.core.graal.nodes.NewPodInstanceNode;
46+
import com.oracle.svm.core.graal.nodes.TestDeoptimizeNode;
4647
import com.oracle.svm.core.heap.Pod;
4748
import com.oracle.svm.core.heap.Pod.RuntimeSupport.PodFactory;
4849
import com.oracle.svm.hosted.annotation.CustomSubstitutionMethod;
4950
import com.oracle.svm.hosted.code.SubstrateCompilationDirectives;
5051
import com.oracle.svm.hosted.nodes.DeoptProxyNode;
51-
import com.oracle.svm.hosted.nodes.TestDeoptimizeNode;
5252
import com.oracle.svm.hosted.phases.HostedGraphKit;
5353

5454
import jdk.graal.compiler.core.common.type.StampFactory;
@@ -133,7 +133,9 @@ public StructuredGraph buildGraph(DebugContext debug, AnalysisMethod method, Hos
133133
int nextDeoptIndex = startMethod(kit, deoptInfo, 0);
134134
instantiatePod(kit, factoryType, podConcreteType, instanceLocal);
135135
if (isAnnotationPresent(DeoptTest.class)) {
136-
kit.append(new TestDeoptimizeNode());
136+
if (!SubstrateCompilationDirectives.isDeoptTarget(method)) {
137+
kit.append(new TestDeoptimizeNode());
138+
}
137139
}
138140
nextDeoptIndex = invokeConstructor(kit, deoptInfo, nextDeoptIndex, targetCtor, instanceLocal);
139141

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/snippets/SubstrateGraphBuilderPlugins.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
import com.oracle.svm.core.graal.nodes.SubstrateCompressionNode;
7575
import com.oracle.svm.core.graal.nodes.SubstrateNarrowOopStamp;
7676
import com.oracle.svm.core.graal.nodes.SubstrateReflectionGetCallerClassNode;
77+
import com.oracle.svm.core.graal.nodes.TestDeoptimizeNode;
7778
import com.oracle.svm.core.graal.stackvalue.LateStackValueNode;
7879
import com.oracle.svm.core.graal.stackvalue.StackValueNode;
7980
import com.oracle.svm.core.graal.stackvalue.UnsafeLateStackValue;
@@ -100,7 +101,6 @@
100101
import com.oracle.svm.hosted.code.SubstrateCompilationDirectives;
101102
import com.oracle.svm.hosted.nodes.DeoptProxyNode;
102103
import com.oracle.svm.hosted.nodes.ReadReservedRegister;
103-
import com.oracle.svm.hosted.nodes.TestDeoptimizeNode;
104104
import com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor;
105105

106106
import jdk.graal.compiler.core.common.CompressEncoding;
@@ -951,7 +951,9 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec
951951
r.register(new RequiredInvocationPlugin("testDeoptimize") {
952952
@Override
953953
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
954-
b.add(new TestDeoptimizeNode());
954+
if (!SubstrateCompilationDirectives.isDeoptTarget(b.getMethod())) {
955+
b.add(new TestDeoptimizeNode());
956+
}
955957
return true;
956958
}
957959
});

0 commit comments

Comments
 (0)