Skip to content

Commit 3a12264

Browse files
committed
Fix handling of macros in SVM runtime compilations
1 parent 35647e1 commit 3a12264

File tree

4 files changed

+31
-38
lines changed

4 files changed

+31
-38
lines changed

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/nodes/MacroInvokable.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2013, 2025, 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
@@ -26,6 +26,7 @@
2626

2727
import static jdk.vm.ci.code.BytecodeFrame.isPlaceholderBci;
2828

29+
import jdk.graal.compiler.core.common.type.ObjectStamp;
2930
import jdk.graal.compiler.core.common.type.StampPair;
3031
import jdk.graal.compiler.debug.Assertions;
3132
import jdk.graal.compiler.debug.DebugContext;
@@ -89,6 +90,13 @@ public interface MacroInvokable extends Invokable, Lowerable, StateSplit, Single
8990
*/
9091
NodeInputList<ValueNode> getArguments();
9192

93+
/**
94+
* Gets {@linkplain #getArguments() the arguments} for this macro node as an array.
95+
*/
96+
default ValueNode[] toArgumentArray() {
97+
return getArguments().toArray(ValueNode.EMPTY_ARRAY);
98+
}
99+
92100
/**
93101
* @see #getArguments()
94102
*/
@@ -197,4 +205,21 @@ default MethodCallTargetNode createCallTarget() {
197205
* {@link Invoke} later.
198206
*/
199207
void addMethodHandleInfo(ResolvedMethodHandleCallTargetNode methodHandle);
208+
209+
/**
210+
* Build a new copy of the {@link MacroNode.MacroParams} stored in this node.
211+
*/
212+
default MacroNode.MacroParams copyParams() {
213+
return new MacroNode.MacroParams(getInvokeKind(), getContextMethod(), getTargetMethod(), bci(), getReturnStamp(), toArgumentArray());
214+
}
215+
216+
/**
217+
* Builds a new copy of this node's macro parameters, but with the return stamp replaced by the
218+
* trusted {@code newStamp}.
219+
*/
220+
default MacroNode.MacroParams copyParamsWithImprovedStamp(ObjectStamp newStamp) {
221+
GraalError.guarantee(newStamp.join(getReturnStamp().getTrustedStamp()).equals(newStamp), "stamp should improve from %s to %s", getReturnStamp(), newStamp);
222+
StampPair improvedReturnStamp = StampPair.createSingle(newStamp);
223+
return new MacroNode.MacroParams(getInvokeKind(), getContextMethod(), getTargetMethod(), bci(), improvedReturnStamp, toArgumentArray());
224+
}
200225
}

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/nodes/MacroNode.java

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
import org.graalvm.word.LocationIdentity;
3232

33-
import jdk.graal.compiler.core.common.type.ObjectStamp;
3433
import jdk.graal.compiler.core.common.type.StampPair;
3534
import jdk.graal.compiler.debug.DebugCloseable;
3635
import jdk.graal.compiler.debug.GraalError;
@@ -187,10 +186,6 @@ public NodeInputList<ValueNode> getArguments() {
187186
return arguments;
188187
}
189188

190-
public ValueNode[] toArgumentArray() {
191-
return arguments.toArray(ValueNode.EMPTY_ARRAY);
192-
}
193-
194189
@Override
195190
public int bci() {
196191
return bci;
@@ -243,15 +238,6 @@ public final boolean hasSideEffect() {
243238
return true;
244239
}
245240

246-
/**
247-
* Returns {@code true} if the lowered version of the macro, or the fallback invoke, can
248-
* deoptimize in any way or throw any implicit or explicit exception. Such nodes should be
249-
* represented as {@link MacroWithExceptionNode} in SVM runtime compilations.
250-
*/
251-
public boolean canDeoptimizeOrThrow() {
252-
return true;
253-
}
254-
255241
/**
256242
* Returns {@link LocationIdentity#any()}. This node needs to kill any location because it might
257243
* get {@linkplain MacroInvokable#replaceWithInvoke() replaced with an invoke} and
@@ -310,21 +296,4 @@ public void addMethodHandleInfo(ResolvedMethodHandleCallTargetNode methodHandle)
310296
originalTargetMethod = methodHandle.originalTargetMethod;
311297
originalArguments.addAll(methodHandle.originalArguments);
312298
}
313-
314-
/**
315-
* Build a new copy of the {@link MacroParams} stored in this node.
316-
*/
317-
public MacroParams copyParams() {
318-
return new MacroParams(invokeKind, callerMethod, targetMethod, bci, returnStamp, toArgumentArray());
319-
}
320-
321-
/**
322-
* Builds a new copy of this node's macro parameters, but with the return stamp replaced by the
323-
* trusted {@code newStamp}.
324-
*/
325-
protected MacroParams copyParamsWithImprovedStamp(ObjectStamp newStamp) {
326-
GraalError.guarantee(newStamp.join(returnStamp.getTrustedStamp()).equals(newStamp), "stamp should improve from %s to %s", returnStamp, newStamp);
327-
StampPair improvedReturnStamp = StampPair.createSingle(newStamp);
328-
return new MacroParams(invokeKind, callerMethod, targetMethod, bci, improvedReturnStamp, toArgumentArray());
329-
}
330299
}

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/results/StrengthenGraphs.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2025, 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
@@ -117,7 +117,7 @@
117117
import jdk.graal.compiler.phases.common.CanonicalizerPhase.CustomSimplification;
118118
import jdk.graal.compiler.phases.common.inlining.InliningUtil;
119119
import jdk.graal.compiler.printer.GraalDebugHandlersFactory;
120-
import jdk.graal.compiler.replacements.nodes.MacroNode;
120+
import jdk.graal.compiler.replacements.nodes.MacroInvokable;
121121
import jdk.vm.ci.meta.Constant;
122122
import jdk.vm.ci.meta.JavaConstant;
123123
import jdk.vm.ci.meta.JavaKind;
@@ -406,7 +406,7 @@ protected TypeFlow<?> getNodeFlow(Node node) {
406406

407407
@Override
408408
public void simplify(Node n, SimplifierTool tool) {
409-
if (n instanceof ValueNode && !(n instanceof LimitedValueProxy) && !(n instanceof PhiNode) && !(n instanceof MacroNode)) {
409+
if (n instanceof ValueNode && !(n instanceof LimitedValueProxy) && !(n instanceof PhiNode) && !(n instanceof MacroInvokable)) {
410410
/*
411411
* The stamp of proxy nodes and phi nodes is inferred automatically, so we do not
412412
* need to improve them. Macro nodes prohibit changing their stamp because it is

substratevm/src/com.oracle.svm.graal/src/com/oracle/svm/graal/hosted/runtimecompilation/RuntimeCompiledMethodSupport.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2023, 2023, 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
@@ -488,8 +488,7 @@ public static class ConvertMacroNodes extends Phase {
488488
@Override
489489
protected void run(StructuredGraph graph) {
490490
for (Node n : graph.getNodes().snapshot()) {
491-
VMError.guarantee(!(n instanceof MacroNode macro && macro.canDeoptimizeOrThrow()), "DeoptTarget Methods do not support Macro Nodes that may deopt or throw: method %s, node %s",
492-
graph.method(), n);
491+
VMError.guarantee(!(n instanceof MacroNode), "DeoptTarget Methods do not support Macro Nodes: method %s, node %s", graph.method(), n);
493492

494493
if (n instanceof MacroWithExceptionNode macro) {
495494
macro.replaceWithInvoke();

0 commit comments

Comments
 (0)