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 that RTMLockingCalculationDelay affect when
  29  *          abort ratio calculation is started.
  30  * @library /testlibrary /../../test/lib /compiler/testlibrary
  31  * @modules java.base/sun.misc
  32  *          java.management
  33  * @build TestRTMLockingCalculationDelay
  34  * @run main ClassFileInstaller sun.hotspot.WhiteBox
  35  *                              sun.hotspot.WhiteBox$WhiteBoxPermission
  36  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
  37  *                   -XX:+WhiteBoxAPI TestRTMLockingCalculationDelay
  38  */
  39 
  40 import jdk.test.lib.*;
  41 import jdk.test.lib.cli.CommandLineOptionTest;
  42 import jdk.test.lib.cli.predicate.AndPredicate;
  43 import rtm.*;
  44 import rtm.predicate.SupportedCPU;
  45 import rtm.predicate.SupportedVM;
  46 
  47 /**
  48  * Test verifies that abort ratio calculation could be delayed using
  49  * RTMLockingCalculationDelay option.
  50  */
  51 public class TestRTMLockingCalculationDelay extends CommandLineOptionTest {
  52     private static final boolean INFLATE_MONITOR = true;
  53 
  54     private TestRTMLockingCalculationDelay() {
  55         super(new AndPredicate(new SupportedCPU(), new SupportedVM()));
  56     }
  57 
  58     @Override
  59     protected void runTestCases() throws Throwable {
  60         // verify that calculation will be started immediately
  61         verifyLockingCalculationDelay(0, 0, true);
  62 
  63         // verify that calculation will not be started during
  64         // first 10 minutes, while test will be started immediately
  65         verifyLockingCalculationDelay(600000, 0, false);
  66 
  67         // verify that calculation will be started after a second
  68         verifyLockingCalculationDelay(1000, 1000, true);
  69     }
  70 
  71     private void verifyLockingCalculationDelay(long delay, long testDelay,
  72             boolean deoptExpected) throws Throwable {
  73         AbortProvoker provoker = AbortType.XABORT.provoker();
  74         String logFileName = String.format("rtm_delay_%d_%d.xml", delay,
  75                 testDelay);
  76 
  77         OutputAnalyzer outputAnalyzer = RTMTestBase.executeRTMTest(
  78                 logFileName,
  79                 provoker,
  80                 "-XX:+UseRTMDeopt",
  81                 CommandLineOptionTest.prepareNumericFlag(
  82                         "RTMLockingCalculationDelay", delay),
  83                 "-XX:RTMAbortRatio=0",
  84                 "-XX:RTMAbortThreshold=0",
  85                 AbortProvoker.class.getName(),
  86                 AbortType.XABORT.toString(),
  87                 Boolean.toString(
  88                         TestRTMLockingCalculationDelay.INFLATE_MONITOR),
  89                 Long.toString(AbortProvoker.DEFAULT_ITERATIONS),
  90                 Long.toString(testDelay)
  91         );
  92 
  93         outputAnalyzer.shouldHaveExitValue(0);
  94 
  95         int deopts = RTMTestBase.firedRTMStateChangeTraps(logFileName);
  96 
  97         if (deoptExpected) {
  98             Asserts.assertGT(deopts, 0, "At least one deoptimization due to "
  99                     + "rtm_state_chage is expected");
 100         } else {
 101             Asserts.assertEQ(deopts, 0, "No deoptimizations due to "
 102                     + "rtm_state_chage are expected");
 103         }
 104     }
 105 
 106     public static void main(String args[]) throws Throwable {
 107         new TestRTMLockingCalculationDelay().test();
 108     }
 109 }