Path: blob/master/test/hotspot/jtreg/compiler/rtm/locking/TestRTMTotalCountIncrRate.java
41155 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 RTMTotalCountIncrRate option affects27* RTM locking statistics.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.TestRTMTotalCountIncrRate37*/3839package compiler.rtm.locking;4041import compiler.testlibrary.rtm.AbortProvoker;42import compiler.testlibrary.rtm.XAbortProvoker;43import compiler.testlibrary.rtm.CompilableTest;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 with RTMTotalCountIncrRate=1 RTM locking statistics54* contains precise information abort attempted locks and that with other values55* statistics contains information abort non-zero locking attempts.56* Since assert done for RTMTotalCountIncrRate=1 is pretty strict, test uses57* -XX:RTMRetryCount=0 to avoid issue with retriable aborts. For more details on58* that issue see {@link TestUseRTMAfterLockInflation}.59*/60public class TestRTMTotalCountIncrRate {61protected void runTestCases() throws Throwable {62verifyLocksCount(1, false);63verifyLocksCount(64, false);64verifyLocksCount(128, false);65verifyLocksCount(1, true);66verifyLocksCount(64, true);67verifyLocksCount(128, true);68}6970private void verifyLocksCount(int incrRate, boolean useStackLock)71throws Throwable{72CompilableTest test = new Test();7374OutputAnalyzer outputAnalyzer = RTMTestBase.executeRTMTest(75test,76CommandLineOptionTest.prepareBooleanFlag("UseRTMForStackLocks",77useStackLock),78CommandLineOptionTest.prepareNumericFlag(79"RTMTotalCountIncrRate", incrRate),80"-XX:RTMRetryCount=0",81"-XX:+PrintPreciseRTMLockingStatistics",82Test.class.getName(),83Boolean.toString(!useStackLock)84);8586outputAnalyzer.shouldHaveExitValue(0);8788List<RTMLockingStatistics> statistics = RTMLockingStatistics.fromString(89test.getMethodWithLockName(), outputAnalyzer.getOutput());9091Asserts.assertEQ(statistics.size(), 1, "VM output should contain "92+ "exactly one RTM locking statistics entry for method "93+ test.getMethodWithLockName());9495RTMLockingStatistics lock = statistics.get(0);96if (incrRate == 1) {97Asserts.assertEQ(lock.getTotalLocks(), Test.TOTAL_ITERATIONS,98"Total locks should be exactly the same as amount of "99+ "iterations.");100}101}102103public static class Test implements CompilableTest {104private static final long TOTAL_ITERATIONS = 10000L;105private final XAbortProvoker xabort = new XAbortProvoker();106private final Object monitor = new Object();107// Following field have to be static in order to avoid escape analysis.108@SuppressWarnings("UnsuedDeclaration")109private static int field = 0;110111@Override112public String getMethodWithLockName() {113return this.getClass().getName() + "::lock";114}115116@Override117public String[] getMethodsToCompileNames() {118return new String[] { getMethodWithLockName(), "*.doAbort" };119}120121public void lock(boolean forceAbort) {122synchronized(monitor) {123if (forceAbort) {124// We're calling native method in order to force125// abort. It's done by explicit xabort call emitted126// in SharedRuntime::generate_native_wrapper.127// If an actual JNI call will be replaced by128// intrinsic - we'll be in trouble, since xabort129// will be no longer called and test may fail.130xabort.doAbort();131}132Test.field++;133}134}135136/**137* Usage:138* Test <inflate monitor>139*/140public static void main(String args[]) throws Throwable {141Asserts.assertGTE(args.length, 1, "One argument required.");142Test test = new Test();143boolean shouldBeInflated = Boolean.valueOf(args[0]);144if (shouldBeInflated) {145AbortProvoker.inflateMonitor(test.monitor);146}147for (long i = 0L; i < Test.TOTAL_ITERATIONS; i++) {148AbortProvoker.verifyMonitorState(test.monitor,149shouldBeInflated);150// Force abort on first iteration to avoid rare case when151// there were no aborts and locks count was not incremented152// with RTMTotalCountIncrRate > 1 (in such case JVM won't153// print JVM locking statistics).154test.lock(i == 0);155}156}157}158159public static void main(String args[]) throws Throwable {160new TestRTMTotalCountIncrRate().runTestCases();161}162}163164165