Path: blob/master/test/hotspot/jtreg/compiler/rtm/locking/TestRTMDeoptOnHighAbortRatio.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 on high abort ratio method will be recompiled27* without rtm locking.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.TestRTMDeoptOnHighAbortRatio37*/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;47import jdk.test.lib.cli.CommandLineOptionTest;4849import java.util.List;5051/**52* Test verifies that on high abort ratio method wil be deoptimized with53* <i>rtm_state_change</i> reason and after that RTM-based lock elision will not54* be used for that method.55* This test make asserts on total locks count done by compiled method,56* so in order to avoid issue with retriable locks -XX:RTMRetryCount=0 is used.57* For more details on that issue see {@link TestUseRTMAfterLockInflation}.58*/59public class TestRTMDeoptOnHighAbortRatio {60private static final long ABORT_THRESHOLD61= AbortProvoker.DEFAULT_ITERATIONS / 2L;6263protected void runTestCases() throws Throwable {64verifyDeopt(false);65verifyDeopt(true);66}6768private void verifyDeopt(boolean useStackLock) throws Throwable {69AbortProvoker provoker = AbortType.XABORT.provoker();70String logFileName = String.format("rtm_deopt_%s_stack_lock.xml",71(useStackLock ? "use" : "no"));7273OutputAnalyzer outputAnalyzer = RTMTestBase.executeRTMTest(74logFileName,75provoker,76"-XX:+UseRTMDeopt",77CommandLineOptionTest.prepareBooleanFlag("UseRTMForStackLocks",78useStackLock),79"-XX:RTMRetryCount=0",80CommandLineOptionTest.prepareNumericFlag("RTMAbortThreshold",81TestRTMDeoptOnHighAbortRatio.ABORT_THRESHOLD),82"-XX:RTMAbortRatio=100",83"-XX:CompileThreshold=1",84"-XX:RTMTotalCountIncrRate=1",85"-XX:+PrintPreciseRTMLockingStatistics",86AbortProvoker.class.getName(),87AbortType.XABORT.toString(),88Boolean.toString(!useStackLock)89);9091outputAnalyzer.shouldHaveExitValue(0);9293int firedTraps = RTMTestBase.firedRTMStateChangeTraps(logFileName);9495Asserts.assertEQ(firedTraps, 1, "Expected to get only one "96+ "deoptimization due to rtm state change");9798List<RTMLockingStatistics> statistics = RTMLockingStatistics.fromString(99provoker.getMethodWithLockName(), outputAnalyzer.getOutput());100101Asserts.assertEQ(statistics.size(), 1, "VM output should contain "102+ "exactly one RTM locking statistics entry for method "103+ provoker.getMethodWithLockName());104105Asserts.assertEQ(statistics.get(0).getTotalLocks(),106TestRTMDeoptOnHighAbortRatio.ABORT_THRESHOLD,107"After AbortThreshold was reached, method should be"108+ " recompiled without rtm lock eliding.");109}110111public static void main(String args[]) throws Throwable {112new TestRTMDeoptOnHighAbortRatio().runTestCases();113}114}115116117118