Path: blob/master/test/hotspot/jtreg/compiler/rtm/locking/TestUseRTMXendForLockBusy.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 UseRTMXendForLockBusy option affects27* method behaviour if lock is busy.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 -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions35* -XX:+WhiteBoxAPI36* compiler.rtm.locking.TestUseRTMXendForLockBusy37*/3839package compiler.rtm.locking;4041import compiler.testlibrary.rtm.AbortType;42import compiler.testlibrary.rtm.BusyLock;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 +UseRTMXendForLockBusy there will be no aborts54* forced by the test.55*/56public class TestUseRTMXendForLockBusy {57private final static int LOCKING_TIME = 5000;5859protected void runTestCases() throws Throwable {60// inflated lock, xabort on lock busy61verifyXendForLockBusy(true, false);62// inflated lock, xend on lock busy63verifyXendForLockBusy(true, true);64// stack lock, xabort on lock busy65verifyXendForLockBusy(false, false);66// stack lock, xend on lock busy67verifyXendForLockBusy(false, true);68}6970private void verifyXendForLockBusy(boolean inflateMonitor,71boolean useXend) throws Throwable {72CompilableTest test = new BusyLock();7374OutputAnalyzer outputAnalyzer = RTMTestBase.executeRTMTest(75test,76CommandLineOptionTest.prepareBooleanFlag("UseRTMForStackLocks",77!inflateMonitor),78CommandLineOptionTest.prepareBooleanFlag(79"UseRTMXendForLockBusy",80useXend),81"-XX:RTMRetryCount=0",82"-XX:RTMTotalCountIncrRate=1",83"-XX:+PrintPreciseRTMLockingStatistics",84BusyLock.class.getName(),85Boolean.toString(inflateMonitor),86Integer.toString(TestUseRTMXendForLockBusy.LOCKING_TIME)87);8889outputAnalyzer.shouldHaveExitValue(0);9091List<RTMLockingStatistics> statistics = RTMLockingStatistics.fromString(92test.getMethodWithLockName(), outputAnalyzer.getOutput());9394Asserts.assertEQ(statistics.size(), 1, "VM output should contain "95+ "exactly one rtm locking statistics entry for method "96+ test.getMethodWithLockName());9798long aborts = statistics.get(0).getAborts(AbortType.XABORT);99100if (useXend) {101Asserts.assertEQ(aborts, 0L,102"Expected to get no aborts on busy lock");103} else {104Asserts.assertGT(aborts, 0L,105"Expected to get at least one abort on busy lock");106}107}108109public static void main(String args[]) throws Throwable {110new TestUseRTMXendForLockBusy().runTestCases();111}112}113114115