1 /*
2 * Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /**
25 * @test
26 * @bug 8031320
27 * @summary Verify UseRTMLocking option processing on CPUs without
28 * rtm support.
29 * @library /test/lib /
30 * @modules java.base/jdk.internal.misc
31 * java.management
32 * @requires vm.flagless
33 * @requires !vm.rtm.cpu & vm.rtm.compiler
34 * @run driver compiler.rtm.cli.TestUseRTMLockingOptionOnUnsupportedCPU
35 */
36
37 package compiler.rtm.cli;
38
39 import jdk.test.lib.process.ExitCode;
40 import jdk.test.lib.Platform;
41 import jdk.test.lib.cli.CommandLineOptionTest;
42
43 public class TestUseRTMLockingOptionOnUnsupportedCPU {
44 private static final String DEFAULT_VALUE = "false";
45
46 public void runTestCases() throws Throwable {
47 String unrecognizedOption
48 = CommandLineOptionTest.getUnrecognizedOptionErrorMessage(
49 "UseRTMLocking");
50 String errorMessage = RTMGenericCommandLineOptionTest.RTM_INSTR_ERROR;
51
52 if (Platform.isX86() || Platform.isX64()) {
53 String shouldFailMessage = "JVM startup should fail with option " +
54 "-XX:+UseRTMLocking on unsupported CPU";
55
56 // verify that we get an error when use +UseRTMLocking
57 // on unsupported CPU
58 CommandLineOptionTest.verifySameJVMStartup(
59 new String[] { errorMessage },
60 new String[] { unrecognizedOption }, shouldFailMessage,
61 shouldFailMessage + ". Error message should be shown.",
62 ExitCode.FAIL, "-XX:+UseRTMLocking");
63
64 String shouldPassMessage = "JVM startup should pass with option "
65 + "-XX:-UseRTMLocking even on unsupported CPU";
66 // verify that we can pass -UseRTMLocking without
67 // getting any error messages
68 CommandLineOptionTest.verifySameJVMStartup(null, new String[] {
69 errorMessage, unrecognizedOption }, shouldPassMessage,
70 shouldPassMessage + " without any warnings", ExitCode.OK,
71 "-XX:-UseRTMLocking");
72
73 // verify that UseRTMLocking is false by default
74 CommandLineOptionTest.verifyOptionValueForSameVM("UseRTMLocking",
75 TestUseRTMLockingOptionOnUnsupportedCPU.DEFAULT_VALUE,
76 String.format("Default value of option 'UseRTMLocking' "
77 +"should be '%s'", DEFAULT_VALUE));
78 } else {
79 String shouldFailMessage = "RTMLocking should be unrecognized"
80 + " on non-x86 CPUs. JVM startup should fail."
81 + "Error message should be shown";
82 // verify that on non-x86 CPUs RTMLocking could not be used
83 CommandLineOptionTest.verifySameJVMStartup(
84 new String[] { unrecognizedOption },
85 null, shouldFailMessage, shouldFailMessage,
86 ExitCode.FAIL, "-XX:+UseRTMLocking");
87
88 CommandLineOptionTest.verifySameJVMStartup(
89 new String[] { unrecognizedOption },
90 null, shouldFailMessage, shouldFailMessage,
91 ExitCode.FAIL, "-XX:-UseRTMLocking");
92 }
93 }
94
95 public static void main(String args[]) throws Throwable {
96 new TestUseRTMLockingOptionOnUnsupportedCPU().runTestCases();
97 }
98 }