TestUseRTMLockingOptionOnUnsupportedCPU.java revision 11707:ad7af1afda7a
1/*
2 * Copyright (c) 2014, 2015, 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/**
26 * @test
27 * @bug 8031320
28 * @summary Verify UseRTMLocking option processing on CPU without
29 *          rtm support.
30 * @library /testlibrary /test/lib /
31 * @modules java.base/jdk.internal.misc
32 *          java.management
33 *
34 * @build compiler.rtm.cli.TestUseRTMLockingOptionOnUnsupportedCPU
35 * @run driver ClassFileInstaller sun.hotspot.WhiteBox
36 *                                sun.hotspot.WhiteBox$WhiteBoxPermission
37 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
38 *                   -XX:+WhiteBoxAPI
39 *                   compiler.rtm.cli.TestUseRTMLockingOptionOnUnsupportedCPU
40 */
41
42package compiler.rtm.cli;
43
44import compiler.testlibrary.rtm.predicate.SupportedCPU;
45import compiler.testlibrary.rtm.predicate.SupportedVM;
46import jdk.test.lib.ExitCode;
47import jdk.test.lib.Platform;
48import jdk.test.lib.cli.CommandLineOptionTest;
49import jdk.test.lib.cli.predicate.AndPredicate;
50import jdk.test.lib.cli.predicate.NotPredicate;
51
52public class TestUseRTMLockingOptionOnUnsupportedCPU
53        extends CommandLineOptionTest {
54    private static final String DEFAULT_VALUE = "false";
55
56    private TestUseRTMLockingOptionOnUnsupportedCPU() {
57        super(new AndPredicate(new NotPredicate(new SupportedCPU()),
58                new SupportedVM()));
59    }
60
61    @Override
62    public void runTestCases() throws Throwable {
63        String unrecongnizedOption
64                = CommandLineOptionTest.getUnrecognizedOptionErrorMessage(
65                "UseRTMLocking");
66        String errorMessage = RTMGenericCommandLineOptionTest.RTM_INSTR_ERROR;
67
68        if (Platform.isX86() || Platform.isX64() || Platform.isPPC()) {
69            String shouldFailMessage = "JVM startup should fail with option "
70                    + "-XX:+UseRTMLocking on unsupported CPU";
71            // verify that we get an error when use +UseRTMLocking
72            // on unsupported CPU
73            CommandLineOptionTest.verifySameJVMStartup(
74                    new String[] { errorMessage },
75                    new String[] { unrecongnizedOption }, shouldFailMessage,
76                    shouldFailMessage + ". Error message should be shown",
77                    ExitCode.FAIL, "-XX:+UseRTMLocking");
78
79            String shouldPassMessage = "JVM startup should pass with option "
80                    + "-XX:-UseRTMLocking even on unsupported CPU";
81            // verify that we can pass -UseRTMLocking without
82            // getting any error messages
83            CommandLineOptionTest.verifySameJVMStartup(null, new String[] {
84                    errorMessage, unrecongnizedOption }, shouldPassMessage,
85                    shouldPassMessage + " without any warnings", ExitCode.OK,
86                    "-XX:-UseRTMLocking");
87
88            // verify that UseRTMLocking is false by default
89            CommandLineOptionTest.verifyOptionValueForSameVM("UseRTMLocking",
90                    TestUseRTMLockingOptionOnUnsupportedCPU.DEFAULT_VALUE,
91                    String.format("Default value of option 'UseRTMLocking' "
92                        +"should be '%s'", DEFAULT_VALUE));
93        } else {
94            String shouldFailMessage = "RTMLocking should be unrecognized"
95                    + " on non-x86 CPUs. JVM startup should fail."
96                    + "Error message should be shown";
97            // verify that on non-x86 CPUs RTMLocking could not be used
98            CommandLineOptionTest.verifySameJVMStartup(
99                    new String[] { unrecongnizedOption },
100                    null, shouldFailMessage, shouldFailMessage,
101                    ExitCode.FAIL, "-XX:+UseRTMLocking");
102
103            CommandLineOptionTest.verifySameJVMStartup(
104                    new String[] { unrecongnizedOption },
105                    null, shouldFailMessage, shouldFailMessage,
106                    ExitCode.FAIL, "-XX:-UseRTMLocking");
107        }
108    }
109
110    public static void main(String args[]) throws Throwable {
111        new TestUseRTMLockingOptionOnUnsupportedCPU().test();
112    }
113}
114