Path: blob/master/test/hotspot/jtreg/compiler/rtm/locking/TestRTMDeoptOnLowAbortRatio.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 on low abort ratio method will be recompiled.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/native -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions34* -XX:+WhiteBoxAPI35* compiler.rtm.locking.TestRTMDeoptOnLowAbortRatio36*/3738package compiler.rtm.locking;3940import compiler.testlibrary.rtm.AbortProvoker;41import compiler.testlibrary.rtm.XAbortProvoker;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;4849import java.util.List;5051/**52* Test verifies that low abort ratio method will be deoptimized with53* <i>rtm_state_change</i> reason and will continue to use RTM-based lock54* elision after that.55* This test make asserts on total locks count done by compiled method,56* so in order to avoid issue with retriable locks -XX:RTMRetryCount=0 is used.57* For more details on that issue see {@link TestUseRTMAfterLockInflation}.58*/59public class TestRTMDeoptOnLowAbortRatio {60private static final long LOCKING_THRESHOLD = 100L;61private static final long ABORT_THRESHOLD = LOCKING_THRESHOLD / 2L;6263protected void runTestCases() throws Throwable {64verifyRTMDeopt(false);65verifyRTMDeopt(true);66}6768private void verifyRTMDeopt(boolean useStackLock) throws Throwable {69CompilableTest test = new Test();70String logFileName = String.format("rtm_deopt_%s_stack_lock.xml",71useStackLock ? "use" : "no");7273OutputAnalyzer outputAnalyzer = RTMTestBase.executeRTMTest(74logFileName,75test,76"-XX:+UseRTMDeopt",77CommandLineOptionTest.prepareBooleanFlag("UseRTMForStackLocks",78useStackLock),79CommandLineOptionTest.prepareNumericFlag("RTMLockingThreshold",80TestRTMDeoptOnLowAbortRatio.LOCKING_THRESHOLD),81CommandLineOptionTest.prepareNumericFlag("RTMAbortThreshold",82TestRTMDeoptOnLowAbortRatio.ABORT_THRESHOLD),83"-XX:RTMAbortRatio=100",84"-XX:CompileThreshold=1",85"-XX:RTMRetryCount=0",86"-XX:RTMTotalCountIncrRate=1",87"-XX:+PrintPreciseRTMLockingStatistics",88Test.class.getName(),89Boolean.toString(!useStackLock)90);9192outputAnalyzer.shouldHaveExitValue(0);9394int firedTraps = RTMTestBase.firedRTMStateChangeTraps(logFileName);9596Asserts.assertEQ(firedTraps, 1,97"Expected to get only one deoptimization due to rtm"98+ " state change");99100List<RTMLockingStatistics> statistics = RTMLockingStatistics.fromString(101test.getMethodWithLockName(), outputAnalyzer.getOutput());102103Asserts.assertEQ(statistics.size(), 2,104"VM output should contain two RTM locking "105+ "statistics entries for method "106+ test.getMethodWithLockName());107108RTMLockingStatistics statisticsBeforeDeopt = null;109110for (RTMLockingStatistics s : statistics) {111if (s.getTotalLocks()112== TestRTMDeoptOnLowAbortRatio.LOCKING_THRESHOLD) {113Asserts.assertNull(statisticsBeforeDeopt,114"Only one abort was expected during test run");115statisticsBeforeDeopt = s;116}117}118119Asserts.assertNotNull(statisticsBeforeDeopt,120"After LockThreshold was reached, method should be recompiled "121+ "with rtm lock eliding.");122}123124public static class Test implements CompilableTest {125private final XAbortProvoker xabort = new XAbortProvoker();126private final Object monitor = new Object();127128@Override129public String getMethodWithLockName() {130return this.getClass().getName() + "::forceAbort";131}132133@Override134public String[] getMethodsToCompileNames() {135return new String[] { getMethodWithLockName(),136XAbortProvoker.class.getName() + "::doAbort" };137}138139public void forceAbort(boolean abort) {140synchronized(monitor) {141if (abort) {142xabort.doAbort();143}144}145}146147/**148* Usage:149* Test <inflate monitor>150*/151public static void main(String args[]) throws Throwable {152Asserts.assertGTE(args.length, 1, "One argument required.");153Test t = new Test();154boolean shouldBeInflated = Boolean.valueOf(args[0]);155if (shouldBeInflated) {156AbortProvoker.inflateMonitor(t.monitor);157}158for (int i = 0; i < AbortProvoker.DEFAULT_ITERATIONS; i++) {159AbortProvoker.verifyMonitorState(t.monitor, shouldBeInflated);160t.forceAbort(i >= TestRTMDeoptOnLowAbortRatio.ABORT_THRESHOLD);161}162}163}164165public static void main(String args[]) throws Throwable {166new TestRTMDeoptOnLowAbortRatio().runTestCases();167}168}169170171