Path: blob/master/test/hotspot/jtreg/compiler/rtm/locking/TestUseRTMAfterLockInflation.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 before27* inflation and after it used for inflated locks.28* @library /test/lib /29* @modules java.base/jdk.internal.misc30* java.management31* @requires vm.rtm.cpu & vm.rtm.compiler32* @build sun.hotspot.WhiteBox33* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox34* @run main/othervm/native -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions35* -XX:+WhiteBoxAPI36* compiler.rtm.locking.TestUseRTMAfterLockInflation37*/3839package compiler.rtm.locking;4041import compiler.testlibrary.rtm.AbortProvoker;42import compiler.testlibrary.rtm.AbortType;43import compiler.testlibrary.rtm.RTMLockingStatistics;44import compiler.testlibrary.rtm.RTMTestBase;45import jdk.test.lib.Asserts;46import jdk.test.lib.process.OutputAnalyzer;4748import java.util.List;4950/**51* Test verifies that RTM is used after lock inflation by executing compiled52* method with RTM-based lock elision using stack lock first, then that lock53* is inflated and the same compiled method invoked again.54*55* Compiled method invoked {@code AbortProvoker.DEFAULT_ITERATIONS} times before56* lock inflation and the same amount of times after inflation.57* As a result total locks count should be equal to58* {@code 2 * AbortProvoker.DEFAULT_ITERATIONS}.59* It is a pretty strict assertion which could fail if some retriable abort60* happened: it could be {@code AbortType.RETRIABLE} or61* {@code AbortType.MEM_CONFLICT}, but unfortunately abort can has both these62* reasons simultaneously. In order to avoid false negative failures related63* to incorrect aborts counting, -XX:RTMRetryCount=0 is used.64*/65public class TestUseRTMAfterLockInflation {66private static final long EXPECTED_LOCKS67= 2L * AbortProvoker.DEFAULT_ITERATIONS;6869protected void runTestCases() throws Throwable {70AbortProvoker provoker = AbortType.XABORT.provoker();71long totalLocksCount = 0;7273OutputAnalyzer outputAnalyzer = RTMTestBase.executeRTMTest(74provoker,75"-XX:+UseRTMForStackLocks",76"-XX:RTMTotalCountIncrRate=1",77"-XX:RTMRetryCount=0",78"-XX:+PrintPreciseRTMLockingStatistics",79Test.class.getName(),80AbortType.XABORT.toString());8182outputAnalyzer.shouldHaveExitValue(0);8384List<RTMLockingStatistics> statistics = RTMLockingStatistics.fromString(85provoker.getMethodWithLockName(), outputAnalyzer.getOutput());8687Asserts.assertEQ(statistics.size(), 2,88"VM output should contain two rtm locking statistics entries "89+ "for method " + provoker.getMethodWithLockName());9091for (RTMLockingStatistics s : statistics) {92totalLocksCount += s.getTotalLocks();93}9495Asserts.assertEQ(totalLocksCount,96TestUseRTMAfterLockInflation.EXPECTED_LOCKS,97"Total lock count should be greater or equal to "98+ TestUseRTMAfterLockInflation.EXPECTED_LOCKS);99}100101public static class Test {102/**103* Usage:104* Test <provoker type>105*/106public static void main(String args[]) throws Throwable {107Asserts.assertGT(args.length, 0,108"AbortType name is expected as first argument.");109110AbortProvoker provoker111= AbortType.lookup(Integer.valueOf(args[0])).provoker();112for (int i = 0; i < AbortProvoker.DEFAULT_ITERATIONS; i++) {113AbortProvoker.verifyMonitorState(provoker, false /*deflated*/);114provoker.forceAbort();115}116provoker.inflateMonitor();117for (int i = 0; i < AbortProvoker.DEFAULT_ITERATIONS; i++) {118AbortProvoker.verifyMonitorState(provoker, true /*inflated*/);119provoker.forceAbort();120}121}122}123124public static void main(String args[]) throws Throwable {125new TestUseRTMAfterLockInflation().runTestCases();126}127}128129130