Skip to content

Commit

Permalink
8257471: fatal error: Fatal exception in JVMCI: Exception during JVMC…
Browse files Browse the repository at this point in the history
…I compiler initialization

Reviewed-by: kvn, never
  • Loading branch information
Doug Simon committed Dec 2, 2020
1 parent 3e3745c commit 7e37c7c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,16 @@ final class HotSpotJVMCICompilerConfig {
private static class DummyCompilerFactory implements JVMCICompilerFactory, JVMCICompiler {

private final String reason;
private final HotSpotJVMCIRuntime runtime;

DummyCompilerFactory(String reason) {
DummyCompilerFactory(String reason, HotSpotJVMCIRuntime runtime) {
this.reason = reason;
this.runtime = runtime;
}

@Override
public HotSpotCompilationRequestResult compileMethod(CompilationRequest request) {
throw new JVMCIError("no JVMCI compiler selected: " + reason);
throw runtime.exitHotSpotWithMessage(1, "Cannot use JVMCI compiler: %s%n", reason);
}

@Override
Expand All @@ -64,7 +66,7 @@ public String getCompilerName() {
}

@Override
public JVMCICompiler createCompiler(JVMCIRuntime runtime) {
public JVMCICompiler createCompiler(JVMCIRuntime rt) {
return this;
}
}
Expand All @@ -81,15 +83,16 @@ public JVMCICompiler createCompiler(JVMCIRuntime runtime) {
* @throws SecurityException if a security manager is present and it denies
* {@link JVMCIPermission} for any {@link JVMCIServiceLocator} loaded by this method
*/
static JVMCICompilerFactory getCompilerFactory() {
static JVMCICompilerFactory getCompilerFactory(HotSpotJVMCIRuntime runtime) {
if (compilerFactory == null) {
JVMCICompilerFactory factory = null;
String compilerName = Option.Compiler.getString();
if (compilerName != null) {
String compPropertyName = Option.Compiler.getPropertyName();
if (compilerName.isEmpty()) {
factory = new DummyCompilerFactory(" empty \"\" is specified");
factory = new DummyCompilerFactory("Value of " + compPropertyName + " is empty", runtime);
} else if (compilerName.equals("null")) {
factory = new DummyCompilerFactory("\"null\" is specified");
factory = new DummyCompilerFactory("Value of " + compPropertyName + " is \"null\"", runtime);
} else {
for (JVMCICompilerFactory f : getJVMCICompilerFactories()) {
if (f.getCompilerName().equals(compilerName)) {
Expand All @@ -98,29 +101,29 @@ static JVMCICompilerFactory getCompilerFactory() {
}
if (factory == null) {
if (Services.IS_IN_NATIVE_IMAGE) {
throw new JVMCIError("JVMCI compiler '%s' not found in JVMCI native library.%n" +
"Use -XX:-UseJVMCINativeLibrary when specifying a JVMCI compiler available on a class path with %s.",
compilerName, Option.Compiler.getPropertyName());
throw runtime.exitHotSpotWithMessage(1, "JVMCI compiler '%s' not found in JVMCI native library.%n" +
"Use -XX:-UseJVMCINativeLibrary when specifying a JVMCI compiler available on a class path with %s.%n",
compilerName, compPropertyName);
}
throw new JVMCIError("JVMCI compiler '%s' not found", compilerName);
throw runtime.exitHotSpotWithMessage(1, "JVMCI compiler '%s' specified by %s not found%n", compilerName, compPropertyName);
}
}
} else {
// Auto select a single available compiler
String reason = "default compiler is not found";
String reason = "No JVMCI compiler found";
for (JVMCICompilerFactory f : getJVMCICompilerFactories()) {
if (factory == null) {
openJVMCITo(f.getClass().getModule());
factory = f;
} else {
// Multiple factories seen - cancel auto selection
reason = "multiple factories seen: \"" + factory.getCompilerName() + "\" and \"" + f.getCompilerName() + "\"";
reason = "Multiple JVMCI compilers found: \"" + factory.getCompilerName() + "\" and \"" + f.getCompilerName() + "\"";
factory = null;
break;
}
}
if (factory == null) {
factory = new DummyCompilerFactory(reason);
factory = new DummyCompilerFactory(reason, runtime);
}
}
factory.onSelection();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
import jdk.vm.ci.runtime.JVMCICompilerFactory;
import jdk.vm.ci.runtime.JVMCIRuntime;
import jdk.vm.ci.services.JVMCIServiceLocator;
import jdk.vm.ci.services.Services;

/**
* HotSpot implementation of a JVMCI runtime.
Expand Down Expand Up @@ -380,9 +379,9 @@ static float stringSimiliarity(String str1, String str2) {
* Parses all system properties starting with {@value #JVMCI_OPTION_PROPERTY_PREFIX} and
* initializes the options based on their values.
*
* @param compilerToVm
* @param runtime
*/
static void parse(CompilerToVM compilerToVm) {
static void parse(HotSpotJVMCIRuntime runtime) {
Map<String, String> savedProps = jdk.vm.ci.services.Services.getSavedProperties();
for (Map.Entry<String, String> e : savedProps.entrySet()) {
String name = e.getKey();
Expand All @@ -405,9 +404,7 @@ static void parse(CompilerToVM compilerToVm) {
}
}
msg.format("%nError: A fatal exception has occurred. Program will exit.%n");
byte[] msgBytes = msg.toString().getBytes();
compilerToVm.writeDebugOutput(msgBytes, 0, msgBytes.length, true, true);
compilerToVm.callSystemExit(1);
runtime.exitHotSpotWithMessage(1, msg.toString());
} else if (value instanceof Option) {
Option option = (Option) value;
option.init(e.getValue());
Expand Down Expand Up @@ -536,7 +533,7 @@ private HotSpotJVMCIRuntime() {
}

// Initialize the Option values.
Option.parse(compilerToVm);
Option.parse(this);

String hostArchitecture = config.getHostArchitectureName();

Expand All @@ -549,7 +546,7 @@ private HotSpotJVMCIRuntime() {
hostBackend = registerBackend(factory.createJVMCIBackend(this, null));
}

compilerFactory = HotSpotJVMCICompilerConfig.getCompilerFactory();
compilerFactory = HotSpotJVMCICompilerConfig.getCompilerFactory(this);
if (compilerFactory instanceof HotSpotJVMCICompilerFactory) {
hsCompilerFactory = (HotSpotJVMCICompilerFactory) compilerFactory;
if (hsCompilerFactory.getCompilationLevelAdjustment() != None) {
Expand Down Expand Up @@ -1161,12 +1158,12 @@ public void detachCurrentThread() {
}

/**
* Informs HotSpot that no method whose module is in {@code modules} is to be compiled
* with {@link #compileMethod}.
* Informs HotSpot that no method whose module is in {@code modules} is to be compiled with
* {@link #compileMethod}.
*
* @param modules the set of modules containing JVMCI compiler classes
*/
public void excludeFromJVMCICompilation(Module...modules) {
public void excludeFromJVMCICompilation(Module... modules) {
this.excludeFromJVMCICompilation = modules.clone();
}

Expand All @@ -1179,4 +1176,15 @@ public void exitHotSpot(int status) {
}
compilerToVm.callSystemExit(status);
}

/**
* Writes a message to HotSpot's log stream and then calls {@link System#exit(int)} in HotSpot's
* runtime.
*/
JVMCIError exitHotSpotWithMessage(int status, String format, Object... args) {
byte[] messageBytes = String.format(format, args).getBytes();
compilerToVm.writeDebugOutput(messageBytes, 0, messageBytes.length, true, true);
exitHotSpot(status);
throw JVMCIError.shouldNotReachHere();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ static void test(String explicitFlag, Expectation... expectations) throws Except
for (Expectation expectation : expectations) {
output.stdoutShouldMatch(expectation.pattern);
}
output.shouldHaveExitValue(0);
if (output.getExitValue() != 0) {
// This should only happen when JVMCI compilation is requested and the VM has no
// JVMCI compiler (e.g. Graal is not included in the build)
output.stdoutShouldMatch("No JVMCI compiler found");
}
}
}

1 comment on commit 7e37c7c

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.