1 /*
   2  * Copyright (c) 2014, 2016, 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 UseRTMForStackLocks option processing on CPUs without
  29  *          rtm support and/or on VMs without rtm locking support.
  30  * @library /test/lib /
  31  * @modules java.base/jdk.internal.misc
  32  *          java.management
  33  *
  34  * @build sun.hotspot.WhiteBox
  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.TestUseRTMForStackLocksOptionOnUnsupportedConfig
  40  */
  41 
  42 package compiler.rtm.cli;
  43 
  44 import compiler.testlibrary.rtm.predicate.SupportedCPU;
  45 import compiler.testlibrary.rtm.predicate.SupportedOS;
  46 import compiler.testlibrary.rtm.predicate.SupportedVM;
  47 import jdk.test.lib.process.ExitCode;
  48 import jdk.test.lib.cli.CommandLineOptionTest;
  49 import jdk.test.lib.cli.predicate.AndPredicate;
  50 import jdk.test.lib.cli.predicate.NotPredicate;
  51 
  52 public class TestUseRTMForStackLocksOptionOnUnsupportedConfig
  53         extends RTMGenericCommandLineOptionTest {
  54     private static final String DEFAULT_VALUE = "false";
  55 
  56     private TestUseRTMForStackLocksOptionOnUnsupportedConfig() {
  57         super(new NotPredicate(
  58                 new AndPredicate(new SupportedCPU(), new SupportedOS(), new SupportedVM())),
  59                 "UseRTMForStackLocks", true, true,
  60                 TestUseRTMForStackLocksOptionOnUnsupportedConfig.DEFAULT_VALUE,
  61                 "true");
  62     }
  63 
  64     @Override
  65     protected void runX86SupportedVMTestCases() throws Throwable {
  66         String shouldFailMessage = String.format("VM option '%s' is "
  67                 + "experimental%nJVM startup should fail without "
  68                 + "-XX:+UnlockExperimentalVMOptions flag", optionName);
  69 
  70         // verify that option is experimental
  71         CommandLineOptionTest.verifySameJVMStartup(
  72                 new String[] { experimentalOptionError }, null,
  73                 shouldFailMessage, shouldFailMessage + "%nError message "
  74                         + "should be shown", ExitCode.FAIL,
  75                 prepareOptionValue("true"));
  76 
  77         CommandLineOptionTest.verifySameJVMStartup(
  78                 new String[]{ experimentalOptionError }, null,
  79                 shouldFailMessage, shouldFailMessage + "%nError message "
  80                         + "should be shown", ExitCode.FAIL,
  81                 prepareOptionValue("false"));
  82 
  83         String shouldPassMessage = String.format("VM option '%s' is "
  84                 + " experimental%nJVM startup should pass with "
  85                 + "-XX:+UnlockExperimentalVMOptions flag", optionName);
  86         // verify that if we turn it on, then VM output will contain
  87         // warning saying that this option could be turned on only
  88         // when we use rtm locking
  89         CommandLineOptionTest.verifySameJVMStartup(
  90                 new String[]{
  91                     RTMGenericCommandLineOptionTest.RTM_FOR_STACK_LOCKS_WARNING
  92                 }, null, shouldPassMessage, "There should be warning when try "
  93                     + "to use rtm for stack lock, but not using rtm locking",
  94                 ExitCode.OK,
  95                 CommandLineOptionTest.UNLOCK_EXPERIMENTAL_VM_OPTIONS,
  96                 prepareOptionValue("true")
  97         );
  98         // verify that options is turned off by default
  99         CommandLineOptionTest.verifyOptionValueForSameVM(optionName,
 100                 TestUseRTMForStackLocksOptionOnUnsupportedConfig.DEFAULT_VALUE,
 101                 String.format("Default value of option '%s' should be '%s'",
 102                         optionName, DEFAULT_VALUE),
 103                 CommandLineOptionTest.UNLOCK_EXPERIMENTAL_VM_OPTIONS);
 104         // verify that it could not be turned on without rtm locking
 105         CommandLineOptionTest.verifyOptionValueForSameVM(optionName,
 106                 TestUseRTMForStackLocksOptionOnUnsupportedConfig.DEFAULT_VALUE,
 107                 String.format("Value of '%s' shouldn't able to be set to "
 108                         + "'true' without setting -XX:+UseRTMLocking flag",
 109                         optionName),
 110                 CommandLineOptionTest.UNLOCK_EXPERIMENTAL_VM_OPTIONS,
 111                 prepareOptionValue("true"));
 112     }
 113 
 114     public static void main(String args[]) throws Throwable {
 115         new TestUseRTMForStackLocksOptionOnUnsupportedConfig().test();
 116     }
 117 }