Path: blob/master/test/hotspot/jtreg/compiler/rtm/method_options/TestUseRTMLockElidingOption.java
41152 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 UseRTMLockEliding option could be applied to27* specified method and that such method will not be deoptimized28* on high abort ratio.29* @library /test/lib /30* @modules java.base/jdk.internal.misc31* java.management32* @requires vm.rtm.cpu & vm.rtm.compiler33* @build sun.hotspot.WhiteBox34* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox35* @run main/othervm/native -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions36* -XX:+WhiteBoxAPI37* compiler.rtm.method_options.TestUseRTMLockElidingOption38*/3940package compiler.rtm.method_options;4142import compiler.testlibrary.rtm.AbortProvoker;43import compiler.testlibrary.rtm.AbortType;44import compiler.testlibrary.rtm.RTMLockingStatistics;45import compiler.testlibrary.rtm.RTMTestBase;46import jdk.test.lib.Asserts;47import jdk.test.lib.process.OutputAnalyzer;48import jdk.test.lib.cli.CommandLineOptionTest;4950import java.util.List;5152/**53* Test verifies that method tagged with option <i>UseRTMLockElidingOption</i>54* will use RTM-based lock elision, but will be never deoptimized with55* <i>rtm_state_change reason</i>.56* Test invokes compiled method and checks that no deoptimization with57* <i>rtm_state_change</i> reason had happened and that that VM output58* contains RTM locking statistics for compiled method and that total locks59* count equals to method's invocations.60* Since last assert is pretty strict, test uses -XX:RTMRetryCount=0 in order61* to avoid issue with retriable aborts described in62* {@link TestUseRTMAfterLockInflation}.63*/64public class TestUseRTMLockElidingOption {6566public void runTestCases() throws Throwable {67verifyOption(false);68verifyOption(true);69}7071public void verifyOption(boolean useStackLock) throws Throwable {72AbortProvoker provoker = AbortType.XABORT.provoker();73String logFileName = String.format("rtm_deopt_%s_stack_lock.xml",74(useStackLock ? "use" : "no"));75String methodOption = String.format("-XX:CompileCommand=option," +76"%s,UseRTMLockEliding", provoker.getMethodWithLockName());7778OutputAnalyzer outputAnalyzer = RTMTestBase.executeRTMTest(79logFileName,80provoker,81CommandLineOptionTest.prepareBooleanFlag("UseRTMForStackLocks",82useStackLock),83methodOption,84"-XX:RTMTotalCountIncrRate=1",85"-XX:RTMRetryCount=0",86"-XX:+UseRTMDeopt",87"-XX:+PrintPreciseRTMLockingStatistics",88provoker.getClass().getName(),89AbortType.XABORT.toString(),90Boolean.toString(!useStackLock)91);9293outputAnalyzer.shouldHaveExitValue(0);9495int firedTraps = RTMTestBase.firedRTMStateChangeTraps(logFileName);9697Asserts.assertEQ(firedTraps, 0,98"Method deoptimization with rtm_state_change is unexpected");99100List<RTMLockingStatistics> statistics = RTMLockingStatistics.fromString(101provoker.getMethodWithLockName(), outputAnalyzer.getOutput());102103Asserts.assertEQ(statistics.size(), 1,104"VM output should contain exactly one RTM locking "105+ "statistics entry for method "106+ provoker.getMethodWithLockName());107108RTMLockingStatistics lock = statistics.get(0);109110Asserts.assertEQ(lock.getTotalLocks(), AbortProvoker.DEFAULT_ITERATIONS,111"Expected to get total locks count equal to total amount of "112+ "lock attempts.");113}114115public static void main(String args[]) throws Throwable {116new TestUseRTMLockElidingOption().runTestCases();117}118}119120121