aoqi@0: /* aoqi@0: * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: /** aoqi@0: * @test aoqi@0: * @bug 8031320 aoqi@0: * @summary Verify that UseRTMXendForLockBusy option affects aoqi@0: * method behaviour if lock is busy. aoqi@0: * @library /testlibrary /testlibrary/whitebox /compiler/testlibrary aoqi@0: * @build TestUseRTMXendForLockBusy aoqi@0: * @run main ClassFileInstaller sun.hotspot.WhiteBox aoqi@0: * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions aoqi@0: * -XX:+WhiteBoxAPI TestUseRTMXendForLockBusy aoqi@0: */ aoqi@0: aoqi@0: import java.util.List; aoqi@0: aoqi@0: import com.oracle.java.testlibrary.*; aoqi@0: import com.oracle.java.testlibrary.cli.CommandLineOptionTest; aoqi@0: import com.oracle.java.testlibrary.cli.predicate.AndPredicate; aoqi@0: import rtm.*; aoqi@0: import rtm.predicate.SupportedCPU; aoqi@0: import rtm.predicate.SupportedVM; aoqi@0: aoqi@0: /** aoqi@0: * Test verifies that with +UseRTMXendForLockBusy there will be no aborts aoqi@0: * forced by the test. aoqi@0: */ aoqi@0: public class TestUseRTMXendForLockBusy extends CommandLineOptionTest { aoqi@0: private final static int LOCKING_TIME = 5000; aoqi@0: aoqi@0: private TestUseRTMXendForLockBusy() { aoqi@0: super(new AndPredicate(new SupportedVM(), new SupportedCPU())); aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: protected void runTestCases() throws Throwable { aoqi@0: // inflated lock, xabort on lock busy aoqi@0: verifyXendForLockBusy(true, false); aoqi@0: // inflated lock, xend on lock busy aoqi@0: verifyXendForLockBusy(true, true); aoqi@0: // stack lock, xabort on lock busy aoqi@0: verifyXendForLockBusy(false, false); aoqi@0: // stack lock, xend on lock busy aoqi@0: verifyXendForLockBusy(false, true); aoqi@0: } aoqi@0: aoqi@0: private void verifyXendForLockBusy(boolean inflateMonitor, aoqi@0: boolean useXend) throws Throwable { aoqi@0: CompilableTest test = new BusyLock(); aoqi@0: aoqi@0: OutputAnalyzer outputAnalyzer = RTMTestBase.executeRTMTest( aoqi@0: test, aoqi@0: CommandLineOptionTest.prepareBooleanFlag("UseRTMForStackLocks", aoqi@0: inflateMonitor), aoqi@0: CommandLineOptionTest.prepareBooleanFlag( aoqi@0: "UseRTMXendForLockBusy", aoqi@0: useXend), aoqi@0: "-XX:RTMRetryCount=0", aoqi@0: "-XX:RTMTotalCountIncrRate=1", aoqi@0: "-XX:+PrintPreciseRTMLockingStatistics", aoqi@0: BusyLock.class.getName(), aoqi@0: Boolean.toString(inflateMonitor), aoqi@0: Integer.toString(TestUseRTMXendForLockBusy.LOCKING_TIME) aoqi@0: ); aoqi@0: aoqi@0: outputAnalyzer.shouldHaveExitValue(0); aoqi@0: aoqi@0: List statistics = RTMLockingStatistics.fromString( aoqi@0: test.getMethodWithLockName(), outputAnalyzer.getOutput()); aoqi@0: aoqi@0: Asserts.assertEQ(statistics.size(), 1, "VM output should contain " aoqi@0: + "exactly one rtm locking statistics entry for method " aoqi@0: + test.getMethodWithLockName()); aoqi@0: aoqi@0: long aborts = statistics.get(0).getAborts(AbortType.XABORT); aoqi@0: aoqi@0: if (useXend) { aoqi@0: Asserts.assertEQ(aborts, 0L, aoqi@0: "Expected to get no aborts on busy lock"); aoqi@0: } else { aoqi@0: Asserts.assertGT(aborts, 0L, aoqi@0: "Expected to get at least one abort on busy lock"); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: public static void main(String args[]) throws Throwable { aoqi@0: new TestUseRTMXendForLockBusy().test(); aoqi@0: } aoqi@0: }