Path: blob/master/test/hotspot/jtreg/compiler/rtm/locking/TestUseRTMForStackLocks.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 stack 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.TestUseRTMForStackLocks36*/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 stack locks51* by calling compiled method that use RTM-based lock elision and using52* stack 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 TestUseRTMForStackLocks {60private static final boolean INFLATE_MONITOR = false;6162protected void runTestCases() throws Throwable {63AbortProvoker provoker = AbortType.XABORT.provoker();64RTMLockingStatistics lock;6566OutputAnalyzer outputAnalyzer = RTMTestBase.executeRTMTest(67provoker,68"-XX:+UseRTMForStackLocks",69"-XX:RTMTotalCountIncrRate=1",70"-XX:RTMRetryCount=0",71"-XX:+PrintPreciseRTMLockingStatistics",72AbortProvoker.class.getName(),73AbortType.XABORT.toString(),74Boolean.toString(TestUseRTMForStackLocks.INFLATE_MONITOR));7576outputAnalyzer.shouldHaveExitValue(0);7778List<RTMLockingStatistics> statistics = RTMLockingStatistics.fromString(79provoker.getMethodWithLockName(), outputAnalyzer.getOutput());8081Asserts.assertEQ(statistics.size(), 1,82"VM output should contain exactly one rtm locking statistics "83+ "entry for method " + provoker.getMethodWithLockName());8485lock = statistics.get(0);86Asserts.assertEQ(lock.getTotalLocks(), AbortProvoker.DEFAULT_ITERATIONS,87"Total locks count should be greater or equal to "88+ AbortProvoker.DEFAULT_ITERATIONS);89}9091public static void main(String args[]) throws Throwable {92new TestUseRTMForStackLocks().runTestCases();93}94}959697