Path: blob/master/test/hotspot/jtreg/compiler/rtm/locking/TestUseRTMForInflatedLocks.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 rtm locking is used for inflated locks.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.TestUseRTMForInflatedLocks36*/3738package compiler.rtm.locking;3940import compiler.testlibrary.rtm.AbortProvoker;41import compiler.testlibrary.rtm.AbortType;42import compiler.testlibrary.rtm.RTMLockingStatistics;43import compiler.testlibrary.rtm.RTMTestBase;44import jdk.test.lib.Asserts;45import jdk.test.lib.process.OutputAnalyzer;4647import java.util.List;4849/**50* Test verifies that RTM-based lock elision could be used for inflated locks51* by calling compiled method that use RTM-based lock elision and using52* manually inflated lock.53* Compiled method invoked {@code AbortProvoker.DEFAULT_ITERATIONS} times,54* so total locks count should be the same.55* This test could also be affected by retriable aborts, so -XX:RTMRetryCount=056* is used. For more information abort that issue see57* {@link TestUseRTMAfterLockInflation}.58*/59public class TestUseRTMForInflatedLocks {6061protected void runTestCases() throws Throwable {62AbortProvoker provoker = AbortType.XABORT.provoker();63RTMLockingStatistics lock;6465OutputAnalyzer outputAnalyzer = RTMTestBase.executeRTMTest(66provoker,67"-XX:-UseRTMForStackLocks",68"-XX:RTMTotalCountIncrRate=1",69"-XX:RTMRetryCount=0",70"-XX:+PrintPreciseRTMLockingStatistics",71AbortProvoker.class.getName(),72AbortType.XABORT.toString());7374outputAnalyzer.shouldHaveExitValue(0);7576List<RTMLockingStatistics> statistics = RTMLockingStatistics.fromString(77provoker.getMethodWithLockName(), outputAnalyzer.getOutput());7879Asserts.assertEQ(statistics.size(), 1,80"VM output should contain exactly one rtm locking statistics "81+ "entry for method " + provoker.getMethodWithLockName());8283lock = statistics.get(0);84Asserts.assertEQ(lock.getTotalLocks(), AbortProvoker.DEFAULT_ITERATIONS,85"Total lock count should be greater or equal to "86+ AbortProvoker.DEFAULT_ITERATIONS);87}8889public static void main(String args[]) throws Throwable {90new TestUseRTMForInflatedLocks().runTestCases();91}92}939495