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 UseRTMLockEliding option could be applied to
aoqi@0: * specified method and that such method will not be deoptimized
aoqi@0: * on high abort ratio.
aoqi@0: * @library /testlibrary /testlibrary/whitebox /compiler/testlibrary
aoqi@0: * @build TestUseRTMLockElidingOption
aoqi@0: * @run main ClassFileInstaller sun.hotspot.WhiteBox
aoqi@0: * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
aoqi@0: * -XX:+WhiteBoxAPI TestUseRTMLockElidingOption
aoqi@0: */
aoqi@0:
aoqi@0: import java.util.List;
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 method tagged with option UseRTMLockElidingOption
aoqi@0: * will use RTM-based lock elision, but will be never deoptimized with
aoqi@0: * rtm_state_change reason.
aoqi@0: * Test invokes compiled method and checks that no deoptimization with
aoqi@0: * rtm_state_change reason had happened and that that VM output
aoqi@0: * contains RTM locking statistics for compiled method and that total locks
aoqi@0: * count equals to method's invocations.
aoqi@0: * Since last assert is pretty strict, test uses -XX:RTMRetryCount=0 in order
aoqi@0: * to avoid issue with retriable aborts described in
aoqi@0: * {@link TestUseRTMAfterLockInflation}.
aoqi@0: */
aoqi@0: public class TestUseRTMLockElidingOption extends CommandLineOptionTest {
aoqi@0: private TestUseRTMLockElidingOption() {
aoqi@0: super(new AndPredicate(new SupportedCPU(), new SupportedVM()));
aoqi@0: }
aoqi@0:
aoqi@0: @Override
aoqi@0: public void runTestCases() throws Throwable {
aoqi@0: verifyOption(false);
aoqi@0: verifyOption(true);
aoqi@0: }
aoqi@0:
aoqi@0: public void verifyOption(boolean useStackLock) throws Throwable {
aoqi@0: AbortProvoker provoker = AbortType.XABORT.provoker();
aoqi@0: String logFileName = String.format("rtm_deopt_%s_stack_lock.xml",
aoqi@0: (useStackLock ? "use" : "no"));
aoqi@0: String methodOption = String.format("-XX:CompileCommand=option," +
aoqi@0: "%s,UseRTMLockEliding", provoker.getMethodWithLockName());
aoqi@0:
aoqi@0: OutputAnalyzer outputAnalyzer = RTMTestBase.executeRTMTest(
aoqi@0: logFileName,
aoqi@0: provoker,
aoqi@0: CommandLineOptionTest.prepareBooleanFlag("UseRTMForStackLocks",
aoqi@0: useStackLock),
aoqi@0: methodOption,
aoqi@0: "-XX:RTMTotalCountIncrRate=1",
aoqi@0: "-XX:RTMRetryCount=0",
aoqi@0: "-XX:+UseRTMDeopt",
aoqi@0: "-XX:+PrintPreciseRTMLockingStatistics",
aoqi@0: provoker.getClass().getName(),
aoqi@0: AbortType.XABORT.toString(),
aoqi@0: Boolean.toString(!useStackLock)
aoqi@0: );
aoqi@0:
aoqi@0: outputAnalyzer.shouldHaveExitValue(0);
aoqi@0:
aoqi@0: int firedTraps = RTMTestBase.firedRTMStateChangeTraps(logFileName);
aoqi@0:
aoqi@0: Asserts.assertEQ(firedTraps, 0,
aoqi@0: "Method deoptimization with rtm_state_change is unexpected");
aoqi@0:
aoqi@0: List statistics = RTMLockingStatistics.fromString(
aoqi@0: provoker.getMethodWithLockName(), outputAnalyzer.getOutput());
aoqi@0:
aoqi@0: Asserts.assertEQ(statistics.size(), 1,
aoqi@0: "VM output should contain exactly one RTM locking "
aoqi@0: + "statistics entry for method "
aoqi@0: + provoker.getMethodWithLockName());
aoqi@0:
aoqi@0: RTMLockingStatistics lock = statistics.get(0);
aoqi@0:
aoqi@0: Asserts.assertEQ(lock.getTotalLocks(), AbortProvoker.DEFAULT_ITERATIONS,
aoqi@0: "Expected to get total locks count equal to total amount of "
aoqi@0: + "lock attempts.");
aoqi@0: }
aoqi@0:
aoqi@0: public static void main(String args[]) throws Throwable {
aoqi@0: new TestUseRTMLockElidingOption().test();
aoqi@0: }
aoqi@0: }