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 NoRTMLockEliding option could be applied to aoqi@0: * specified method and that such method will not use rtm. aoqi@0: * @library /testlibrary /testlibrary/whitebox /compiler/testlibrary aoqi@0: * @build TestNoRTMLockElidingOption aoqi@0: * @run main ClassFileInstaller sun.hotspot.WhiteBox aoqi@0: * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions aoqi@0: * -XX:+WhiteBoxAPI TestNoRTMLockElidingOption 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 NoRTMLockElidingOption aoqi@0: * will not use RTM-based lock elision. 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: * does not contain RTM locking statistics for compiled method. aoqi@0: */ aoqi@0: public class TestNoRTMLockElidingOption extends CommandLineOptionTest { aoqi@0: private TestNoRTMLockElidingOption() { 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,NoRTMLockEliding", 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:+UseRTMDeopt", aoqi@0: "-XX:+PrintPreciseRTMLockingStatistics", aoqi@0: AbortProvoker.class.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: "No deoptimizations with rtm_state_change reason are expected"); aoqi@0: aoqi@0: List statistics = RTMLockingStatistics.fromString( aoqi@0: provoker.getMethodWithLockName(), outputAnalyzer.getOutput()); aoqi@0: aoqi@0: Asserts.assertEQ(statistics.size(), 0, aoqi@0: "VM output should not contain RTM locking statistics entries " aoqi@0: + "for method " + provoker.getMethodWithLockName()); aoqi@0: } aoqi@0: aoqi@0: public static void main(String args[]) throws Throwable { aoqi@0: new TestNoRTMLockElidingOption().test(); aoqi@0: } aoqi@0: }