Skip to content

Commit 791f13e

Browse files
committed
Throw permanent bailout if parsing generated intrinsics outside snippets
The bailout can then be ignored in CTW
1 parent 2b69a66 commit 791f13e

File tree

4 files changed

+57
-9
lines changed

4 files changed

+57
-9
lines changed

compiler/mx.compiler/mx_compiler.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,16 @@ def ctw(args, extraVMarguments=None):
275275
parser.add_argument('--limitmods', action='store', help='limits the set of compiled classes to only those in the listed modules', metavar='<modulename>[,<modulename>...]')
276276

277277
args, vmargs = parser.parse_known_args(args)
278-
279278
vmargs.extend(_remove_empty_entries(extraVMarguments))
280279

280+
# Enable jvmci by default if not specified
281+
if _get_XX_option_value(vmargs, 'EnableJVMCI', None) is None:
282+
vmargs.append('-XX:+EnableJVMCI')
283+
284+
# Disable JVMCICompiler by default if not specified
285+
if _get_XX_option_value(vmargs, 'UseJVMCICompiler', None) is None:
286+
vmargs.append('-XX:-UseJVMCICompiler')
287+
281288
if mx.get_os() == 'darwin':
282289
# suppress menubar and dock when running on Mac
283290
vmargs.append('-Djava.awt.headless=true')
@@ -515,7 +522,7 @@ def compiler_gate_runner(suites, unit_test_runs, bootstrap_tests, tasks, extraVM
515522

516523
# Run ctw against rt.jar on hosted
517524
ctw_flags = [
518-
'-DCompileTheWorld.Config=Inline=false CompilationFailureAction=ExitVM CompilationBailoutAsFailure=false', '-esa', '-XX:-UseJVMCICompiler', '-XX:+EnableJVMCI',
525+
'-DCompileTheWorld.Config=Inline=false CompilationFailureAction=ExitVM CompilationBailoutAsFailure=false', '-ea', '-esa',
519526
'-DCompileTheWorld.MultiThreaded=true', '-Djdk.graal.InlineDuringParsing=false', '-Djdk.graal.TrackNodeSourcePosition=true',
520527
'-DCompileTheWorld.Verbose=false', '-XX:ReservedCodeCacheSize=300m',
521528
]

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/hotspot/test/CompileTheWorld.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2013, 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
@@ -90,6 +90,7 @@
9090
import jdk.graal.compiler.hotspot.CompilationTask;
9191
import jdk.graal.compiler.hotspot.CompileTheWorldFuzzedSuitesCompilationTask;
9292
import jdk.graal.compiler.hotspot.GraalHotSpotVMConfig;
93+
import jdk.graal.compiler.hotspot.HotSpotBytecodeParser;
9394
import jdk.graal.compiler.hotspot.HotSpotGraalCompiler;
9495
import jdk.graal.compiler.hotspot.HotSpotGraalRuntime;
9596
import jdk.graal.compiler.hotspot.HotSpotGraalRuntimeProvider;
@@ -102,6 +103,7 @@
102103
import jdk.graal.compiler.options.OptionsParser;
103104
import jdk.vm.ci.hotspot.HotSpotCodeCacheProvider;
104105
import jdk.vm.ci.hotspot.HotSpotCompilationRequest;
106+
import jdk.vm.ci.hotspot.HotSpotCompilationRequestResult;
105107
import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime;
106108
import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
107109
import jdk.vm.ci.hotspot.HotSpotResolvedObjectType;
@@ -938,6 +940,18 @@ private void printSuspiciousThreads() {
938940
}
939941
}
940942

943+
@Override
944+
protected void handleFailure(HotSpotCompilationRequestResult result) {
945+
/*
946+
* Ignore bailouts caused by calling node intrinsics outside a Snippet. Since in CTW we try
947+
* to compile all methods as compilation roots indiscriminately, we may hit upon a helper
948+
* method that expects to only be inlined into a snippet.
949+
*/
950+
if (!result.getFailureMessage().startsWith(HotSpotBytecodeParser.BAD_NODE_INTRINSIC_PLUGIN_CONTEXT)) {
951+
super.handleFailure(result);
952+
}
953+
}
954+
941955
/**
942956
* Prepares a compilation of the methods in the classes in {@link #inputClassPath}. If
943957
* {@link #inputClassPath} equals {@link #SUN_BOOT_CLASS_PATH} the boot classes are used.

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/hotspot/test/LibGraalCompilationDriver.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,7 @@ protected CompilationResult compileWithLibGraal(Compilation compilation, LibGraa
571571
TTY.println("%s : Error compiling method: %s", compilation.testName(), compilation);
572572
TTY.println(stackTrace);
573573
}
574+
failedCompilations.getAndAdd(1);
574575
return null;
575576
}
576577
return new CompilationResult(installedCode, memTimeBuffer.readTimeElapsed(), memTimeBuffer.readBytesAllocated());
@@ -598,6 +599,11 @@ protected final CompilationTask createCompilationTask(HotSpotResolvedJavaMethod
598599
return createCompilationTask(jvmciRuntime, compiler, request, useProfilingInfo, installAsDefault);
599600
}
600601

602+
protected void handleFailure(HotSpotCompilationRequestResult result) {
603+
failedCompilations.getAndAdd(1);
604+
throw new GraalError("Compilation request failed: %s", result.getFailureMessage());
605+
}
606+
601607
/**
602608
* Compiles a method using {@link HotSpotCompilationRequest}.
603609
*
@@ -624,14 +630,13 @@ protected CompilationResult compileWithJarGraal(Compilation compilation, OptionV
624630
CompilationTask task = createCompilationTask(method, useProfilingInfo, installAsDefault);
625631
HotSpotCompilationRequestResult result = task.runCompilation(compileOptions);
626632
if (result.getFailure() != null) {
627-
var error = new GraalError("Compilation request failed: %s", result.getFailureMessage());
628633
if (result.getRetry() && !retried) {
629-
error.printStackTrace(TTY.out);
630-
TTY.println("Retrying...");
634+
TTY.println("Retrying %s after transient failure...", task);
631635
retried = true;
632636
continue;
633637
}
634-
throw error;
638+
handleFailure(result);
639+
return null;
635640
}
636641
HotSpotInstalledCode installedCode = task.getInstalledCode();
637642
assert installedCode != null : "installed code is null yet no failure detected";
@@ -715,7 +720,6 @@ private void compileAndRecord(Compilation task, LibGraalParams libgraal, OptionV
715720
Map<ResolvedJavaMethod, CompilationResult> results) {
716721
CompilationResult result = compile(task, libgraal, options);
717722
if (result == null) {
718-
failedCompilations.getAndAdd(1);
719723
return;
720724
}
721725
compileTime.getAndAdd(result.compileTime());

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,27 @@
2424
*/
2525
package jdk.graal.compiler.hotspot;
2626

27+
import static org.graalvm.nativeimage.ImageInfo.inImageRuntimeCode;
28+
29+
import jdk.graal.compiler.api.replacements.Snippet;
30+
import jdk.graal.compiler.core.common.PermanentBailoutException;
2731
import jdk.graal.compiler.java.BytecodeParser;
2832
import jdk.graal.compiler.java.GraphBuilderPhase.Instance;
33+
import jdk.graal.compiler.nodes.CallTargetNode;
2934
import jdk.graal.compiler.nodes.DeoptimizeNode;
3035
import jdk.graal.compiler.nodes.FixedGuardNode;
3136
import jdk.graal.compiler.nodes.LogicNode;
3237
import jdk.graal.compiler.nodes.StructuredGraph;
38+
import jdk.graal.compiler.nodes.ValueNode;
3339
import jdk.graal.compiler.nodes.extended.GuardingNode;
40+
import jdk.graal.compiler.nodes.graphbuilderconf.GeneratedNodeIntrinsicInvocationPlugin;
3441
import jdk.graal.compiler.nodes.graphbuilderconf.GraphBuilderContext;
3542
import jdk.graal.compiler.nodes.graphbuilderconf.IntrinsicContext;
36-
43+
import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugin;
3744
import jdk.vm.ci.hotspot.HotSpotResolvedJavaField;
3845
import jdk.vm.ci.meta.DeoptimizationAction;
3946
import jdk.vm.ci.meta.DeoptimizationReason;
47+
import jdk.vm.ci.meta.JavaKind;
4048
import jdk.vm.ci.meta.ResolvedJavaField;
4149
import jdk.vm.ci.meta.ResolvedJavaMethod;
4250

@@ -69,6 +77,21 @@ public GuardingNode intrinsicRangeCheck(LogicNode condition, boolean negated) {
6977
return doIntrinsicRangeCheck(this, condition, negated);
7078
}
7179

80+
public static final String BAD_NODE_INTRINSIC_PLUGIN_CONTEXT = "@NodeIntrinsic plugin can't be used outside of Snippet context: ";
81+
82+
@Override
83+
protected boolean applyInvocationPlugin(CallTargetNode.InvokeKind invokeKind, ValueNode[] args, ResolvedJavaMethod targetMethod, JavaKind resultType, InvocationPlugin plugin) {
84+
// It's an error to call generated invocation plugins outside of snippets.
85+
if (plugin instanceof GeneratedNodeIntrinsicInvocationPlugin nodeIntrinsicPlugin) {
86+
// Snippets are never parsed in libgraal, and they are the root of the compilation
87+
// in jargraal, so check the root method for the Snippet annotation.
88+
if (inImageRuntimeCode() || graph.method().getAnnotation(Snippet.class) == null) {
89+
throw new PermanentBailoutException(BAD_NODE_INTRINSIC_PLUGIN_CONTEXT + nodeIntrinsicPlugin.getSource().getSimpleName());
90+
}
91+
}
92+
return super.applyInvocationPlugin(invokeKind, args, targetMethod, resultType, plugin);
93+
}
94+
7295
public static FixedGuardNode doIntrinsicRangeCheck(GraphBuilderContext context, LogicNode condition, boolean negated) {
7396
/*
7497
* On HotSpot it's simplest to always deoptimize. We could dispatch to the fallback code

0 commit comments

Comments
 (0)