Path: blob/master/test/hotspot/jtreg/compiler/rtm/locking/TestRTMRetryCount.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 RTMRetryCount affects actual amount of retries.27* @library /test/lib /28* @modules java.base/jdk.internal.misc29* java.management30* @requires vm.rtm.cpu & vm.rtm.compiler31* @build sun.hotspot.WhiteBox32* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox33* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions34* -XX:+WhiteBoxAPI35* compiler.rtm.locking.TestRTMRetryCount36*/3738package compiler.rtm.locking;3940import compiler.testlibrary.rtm.BusyLock;41import compiler.testlibrary.rtm.CompilableTest;42import compiler.testlibrary.rtm.RTMLockingStatistics;43import compiler.testlibrary.rtm.RTMTestBase;44import jdk.test.lib.Asserts;45import jdk.test.lib.process.OutputAnalyzer;46import jdk.test.lib.cli.CommandLineOptionTest;4748import java.util.List;4950/**51* Test verifies that RTMRetryCount option actually affects amount of52* retries on lock busy.53*/54public class TestRTMRetryCount {55/**56* Time in ms, during which busy lock will be locked.57*/58private static final int LOCKING_TIME = 5000;59private static final boolean INFLATE_MONITOR = true;6061protected void runTestCases() throws Throwable {62verifyRTMRetryCount(0);63verifyRTMRetryCount(1);64verifyRTMRetryCount(5);65verifyRTMRetryCount(10);66}6768private void verifyRTMRetryCount(int retryCount) throws Throwable {69CompilableTest busyLock = new BusyLock();70long expectedAborts = retryCount + 1L;7172OutputAnalyzer outputAnalyzer = RTMTestBase.executeRTMTest(73busyLock,74"-XX:-UseRTMXendForLockBusy",75"-XX:RTMTotalCountIncrRate=1",76CommandLineOptionTest.prepareNumericFlag("RTMRetryCount",77retryCount),78"-XX:RTMTotalCountIncrRate=1",79"-XX:+PrintPreciseRTMLockingStatistics",80BusyLock.class.getName(),81Boolean.toString(TestRTMRetryCount.INFLATE_MONITOR),82Integer.toString(TestRTMRetryCount.LOCKING_TIME)83);8485outputAnalyzer.shouldHaveExitValue(0);8687List<RTMLockingStatistics> statistics = RTMLockingStatistics.fromString(88busyLock.getMethodWithLockName(), outputAnalyzer.getStdout());8990Asserts.assertEQ(statistics.size(), 1, "VM output should contain "91+ "exactly one rtm locking statistics entry for method "92+ busyLock.getMethodWithLockName());9394Asserts.assertEQ(statistics.get(0).getTotalAborts(), expectedAborts,95String.format("It is expected to get %d aborts",96expectedAborts));97}9899public static void main(String args[]) throws Throwable {100new TestRTMRetryCount().runTestCases();101}102}103104105