From f4281728963e47ff33805acc2bcc9423621a7ed3 Mon Sep 17 00:00:00 2001 From: Doug Simon Date: Fri, 27 Nov 2020 20:59:40 +0100 Subject: [PATCH 1/2] JVMCI option parsing should not result in a VM crash producing a hs-err log --- .../vm/ci/hotspot/HotSpotJVMCIRuntime.java | 13 +++-- .../jvmci/TestInvalidJVMCIOption.java | 49 +++++++++++++++++++ 2 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 test/hotspot/jtreg/compiler/jvmci/TestInvalidJVMCIOption.java diff --git a/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotJVMCIRuntime.java b/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotJVMCIRuntime.java index 6915035af8376..36d45b902cbd9 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotJVMCIRuntime.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotJVMCIRuntime.java @@ -379,8 +379,10 @@ 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 */ - static void parse() { + static void parse(CompilerToVM compilerToVm) { Map savedProps = jdk.vm.ci.services.Services.getSavedProperties(); for (Map.Entry e : savedProps.entrySet()) { String name = e.getKey(); @@ -395,14 +397,17 @@ static void parse() { } } Formatter msg = new Formatter(); - msg.format("Could not find option %s", name); + msg.format("Error parsing JVMCI options: Could not find option %s", name); if (!matches.isEmpty()) { msg.format("%nDid you mean one of the following?"); for (String match : matches) { msg.format("%n %s=", match); } } - throw new IllegalArgumentException(msg.toString()); + 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); } else if (value instanceof Option) { Option option = (Option) value; option.init(e.getValue()); @@ -531,7 +536,7 @@ private HotSpotJVMCIRuntime() { } // Initialize the Option values. - Option.parse(); + Option.parse(compilerToVm); String hostArchitecture = config.getHostArchitectureName(); diff --git a/test/hotspot/jtreg/compiler/jvmci/TestInvalidJVMCIOption.java b/test/hotspot/jtreg/compiler/jvmci/TestInvalidJVMCIOption.java new file mode 100644 index 0000000000000..cd8db418dd5b8 --- /dev/null +++ b/test/hotspot/jtreg/compiler/jvmci/TestInvalidJVMCIOption.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test TestInvalidJVMCIOption + * @bug 8257220 + * @summary Ensures invalid JVMCI options do not crash the VM with a hs-err log. + * @requires vm.jvmci & vm.compMode == "Xmixed" + * @library /test/lib + * @run driver TestInvalidJVMCIOption + */ + +import jdk.test.lib.process.ProcessTools; +import jdk.test.lib.process.OutputAnalyzer; + +public class TestInvalidJVMCIOption { + + public static void main(String[] args) throws Exception { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( + "-XX:+UnlockExperimentalVMOptions", + "-XX:+EagerJVMCI", + "-XX:+UseJVMCICompiler", + "-Djvmci.XXXXXXXXX=true"); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldMatch("Error parsing JVMCI options: Could not find option jvmci.XXXXXXXXX" + System.lineSeparator() + + "Error: A fatal exception has occurred. Program will exit." + System.lineSeparator()); + output.shouldHaveExitValue(255); + } +} From fb69a9001864d077969ff16e96110f5087baba6c Mon Sep 17 00:00:00 2001 From: Doug Simon Date: Sun, 29 Nov 2020 01:13:52 +0100 Subject: [PATCH 2/2] fixed test failure on Windows --- .../src/jdk/vm/ci/hotspot/HotSpotJVMCIRuntime.java | 2 +- .../compiler/jvmci/TestInvalidJVMCIOption.java | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotJVMCIRuntime.java b/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotJVMCIRuntime.java index 36d45b902cbd9..530706f75b94f 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotJVMCIRuntime.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotJVMCIRuntime.java @@ -407,7 +407,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); + compilerToVm.callSystemExit(1); } else if (value instanceof Option) { Option option = (Option) value; option.init(e.getValue()); diff --git a/test/hotspot/jtreg/compiler/jvmci/TestInvalidJVMCIOption.java b/test/hotspot/jtreg/compiler/jvmci/TestInvalidJVMCIOption.java index cd8db418dd5b8..e376377444087 100644 --- a/test/hotspot/jtreg/compiler/jvmci/TestInvalidJVMCIOption.java +++ b/test/hotspot/jtreg/compiler/jvmci/TestInvalidJVMCIOption.java @@ -42,8 +42,16 @@ public static void main(String[] args) throws Exception { "-XX:+UseJVMCICompiler", "-Djvmci.XXXXXXXXX=true"); OutputAnalyzer output = new OutputAnalyzer(pb.start()); - output.shouldMatch("Error parsing JVMCI options: Could not find option jvmci.XXXXXXXXX" + System.lineSeparator() + - "Error: A fatal exception has occurred. Program will exit." + System.lineSeparator()); - output.shouldHaveExitValue(255); + String expectStdout = String.format( + "Error parsing JVMCI options: Could not find option jvmci.XXXXXXXXX%n" + + "Error: A fatal exception has occurred. Program will exit.%n"); + String actualStdout = output.getStdout(); + if (!actualStdout.equals(expectStdout)) { + throw new RuntimeException(String.format("Invalid STDOUT:%nExpect:%n%s%nActual:%n%s", expectStdout, actualStdout)); + } + if (!output.getStderr().isEmpty()) { + throw new RuntimeException("STDERR was not empty: " + output.getStderr()); + } + output.shouldHaveExitValue(1); } }