Path: blob/master/test/hotspot/jtreg/compiler/rtm/locking/TestRTMSpinLoopCount.java
41154 views
/*1* Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 803132026* @summary Verify that RTMSpinLoopCount affects time spent27* between locking attempts.28* @library /test/lib /29* @modules java.base/jdk.internal.misc30* java.management31* @requires vm.rtm.cpu & vm.rtm.compiler32* @build sun.hotspot.WhiteBox33* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox34* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions35* -XX:+WhiteBoxAPI36* compiler.rtm.locking.TestRTMSpinLoopCount37*/3839package compiler.rtm.locking;4041import compiler.testlibrary.rtm.BusyLock;42import compiler.testlibrary.rtm.CompilableTest;43import compiler.testlibrary.rtm.RTMLockingStatistics;44import compiler.testlibrary.rtm.RTMTestBase;45import jdk.test.lib.Asserts;46import jdk.test.lib.process.OutputAnalyzer;47import jdk.test.lib.cli.CommandLineOptionTest;48import jdk.test.lib.Platform;4950import java.util.List;5152/**53* Test verifies that RTMSpinLoopCount increase time spent between retries54* by comparing amount of retries done with different RTMSpinLoopCount's values.55*/56public class TestRTMSpinLoopCount {57private static final int LOCKING_TIME = 1000;58private static final int RTM_RETRY_COUNT = 1000;59private static final boolean INFLATE_MONITOR = true;60private static final long MAX_ABORTS = RTM_RETRY_COUNT + 1L;61private static int[] SPIN_LOOP_COUNTS;6263protected void runTestCases() throws Throwable {6465if (Platform.isPPC()) {66SPIN_LOOP_COUNTS = new int[] { 0, 10, 100, 1_000, 10_000 };67} else {68SPIN_LOOP_COUNTS = new int[] { 0, 100, 1_000, 10_000, 100_000 };69}7071long[] aborts = new long[TestRTMSpinLoopCount.SPIN_LOOP_COUNTS.length];7273for (int i = 0; i < TestRTMSpinLoopCount.SPIN_LOOP_COUNTS.length; i++) {74aborts[i] = getAbortsCountOnLockBusy(75TestRTMSpinLoopCount.SPIN_LOOP_COUNTS[i]);76}7778for (int i = 1; i < aborts.length; i++) {79Asserts.assertLTE(aborts[i], aborts[i - 1], "Increased spin loop "80+ "count should not increase retries count.");81}82}8384private long getAbortsCountOnLockBusy(int spinLoopCount) throws Throwable {85CompilableTest test = new BusyLock();8687OutputAnalyzer outputAnalyzer = RTMTestBase.executeRTMTest(88test,89CommandLineOptionTest.prepareNumericFlag("RTMRetryCount",90TestRTMSpinLoopCount.RTM_RETRY_COUNT),91CommandLineOptionTest.prepareNumericFlag("RTMSpinLoopCount",92spinLoopCount),93"-XX:-UseRTMXendForLockBusy",94"-XX:RTMTotalCountIncrRate=1",95"-XX:+PrintPreciseRTMLockingStatistics",96BusyLock.class.getName(),97Boolean.toString(TestRTMSpinLoopCount.INFLATE_MONITOR),98Integer.toString(TestRTMSpinLoopCount.LOCKING_TIME)99);100101outputAnalyzer.shouldHaveExitValue(0);102103List<RTMLockingStatistics> statistics = RTMLockingStatistics.fromString(104test.getMethodWithLockName(), outputAnalyzer.getOutput());105106Asserts.assertEQ(statistics.size(), 1,107"VM output should contain exactly one entry for method "108+ test.getMethodWithLockName());109110RTMLockingStatistics lock = statistics.get(0);111112Asserts.assertLTE(lock.getTotalAborts(),113TestRTMSpinLoopCount.MAX_ABORTS, String.format("Total aborts "114+ "count (%d) should be less or equal to %d",115lock.getTotalAborts(),116TestRTMSpinLoopCount.MAX_ABORTS));117118return lock.getTotalAborts();119}120121public static void main(String args[]) throws Throwable {122new TestRTMSpinLoopCount().runTestCases();123}124}125126127