TestUseRTMDeopt.java revision 11707:ad7af1afda7a
14Srgrimes/*
24Srgrimes * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
34Srgrimes * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44Srgrimes *
54Srgrimes * This code is free software; you can redistribute it and/or modify it
64Srgrimes * under the terms of the GNU General Public License version 2 only, as
74Srgrimes * published by the Free Software Foundation.
84Srgrimes *
94Srgrimes * This code is distributed in the hope that it will be useful, but WITHOUT
104Srgrimes * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
114Srgrimes * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
124Srgrimes * version 2 for more details (a copy is included in the LICENSE file that
134Srgrimes * accompanied this code).
144Srgrimes *
154Srgrimes * You should have received a copy of the GNU General Public License version
164Srgrimes * 2 along with this work; if not, write to the Free Software Foundation,
174Srgrimes * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
184Srgrimes *
194Srgrimes * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
204Srgrimes * or visit www.oracle.com if you need additional information or have any
214Srgrimes * questions.
224Srgrimes *
234Srgrimes */
244Srgrimes
254Srgrimes/**
264Srgrimes * @test
274Srgrimes * @bug 8031320
284Srgrimes * @summary Verify that UseRTMDeopt affects uncommon trap installation in
294Srgrimes *          copmpiled methods with synchronized block.
304Srgrimes * @library /testlibrary /test/lib /
314Srgrimes * @modules java.base/jdk.internal.misc
324Srgrimes *          java.management
334Srgrimes * @build compiler.rtm.locking.TestUseRTMDeopt
344Srgrimes * @run driver ClassFileInstaller sun.hotspot.WhiteBox
354Srgrimes *                                sun.hotspot.WhiteBox$WhiteBoxPermission
36620Srgrimes * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
3725723Stegge *                   -XX:+WhiteBoxAPI
384Srgrimes *                   compiler.rtm.locking.TestUseRTMDeopt
394Srgrimes */
404Srgrimes
414Srgrimespackage compiler.rtm.locking;
424Srgrimes
438876Srgrimesimport compiler.testlibrary.rtm.AbortProvoker;
444Srgrimesimport compiler.testlibrary.rtm.AbortType;
454Srgrimesimport compiler.testlibrary.rtm.RTMTestBase;
464Srgrimesimport compiler.testlibrary.rtm.predicate.SupportedCPU;
474Srgrimesimport compiler.testlibrary.rtm.predicate.SupportedVM;
4825164Speterimport jdk.test.lib.Asserts;
4925460Sjoergimport jdk.test.lib.OutputAnalyzer;
5025164Speterimport jdk.test.lib.cli.CommandLineOptionTest;
512056Swollmanimport jdk.test.lib.cli.predicate.AndPredicate;
522056Swollman
532056Swollman/**
542056Swollman * Test verifies that usage of UseRTMDeopt option affects uncommon traps usage
552056Swollman * for methods that use locking.
562056Swollman */
572056Swollmanpublic class TestUseRTMDeopt extends CommandLineOptionTest {
5812604Sbde    private TestUseRTMDeopt() {
5922521Sdyson        super(new AndPredicate(new SupportedVM(), new SupportedCPU()));
6012649Speter    }
614Srgrimes
6220641Sbde    @Override
6310665Sbde    protected void runTestCases() throws Throwable {
647090Sbde        verifyUseRTMDeopt(false);
6525164Speter        verifyUseRTMDeopt(true);
6625164Speter    }
6725164Speter
6825172Speter    private void verifyUseRTMDeopt(boolean useRTMDeopt) throws Throwable {
6925164Speter        AbortProvoker provoker = AbortType.XABORT.provoker();
7012604Sbde        String logFileName = String.format("rtm_%s_deopt.xml",
7112604Sbde                useRTMDeopt ? "use" : "no");
7212604Sbde
7312604Sbde        OutputAnalyzer outputAnalyzer = RTMTestBase.executeRTMTest(
7410665Sbde                logFileName,
7512604Sbde                provoker,
7612604Sbde                CommandLineOptionTest.prepareBooleanFlag("UseRTMDeopt",
7712604Sbde                        useRTMDeopt),
7812604Sbde                AbortProvoker.class.getName(),
7910665Sbde                AbortType.XABORT.toString()
8012604Sbde        );
8112604Sbde
8212604Sbde        outputAnalyzer.shouldHaveExitValue(0);
8312604Sbde
84798Swollman        int expectedUncommonTraps = useRTMDeopt ? 1 : 0;
8512604Sbde        int installedUncommonTraps
8612604Sbde                = RTMTestBase.installedRTMStateChangeTraps(logFileName);
8712604Sbde
8812604Sbde        Asserts.assertEQ(expectedUncommonTraps, installedUncommonTraps,
894Srgrimes                String.format("Expected to find %d uncommon traps "
9012604Sbde                              + "installed with reason rtm_state_change.",
9112604Sbde                        expectedUncommonTraps));
9212604Sbde    }
9312604Sbde
9412604Sbde    public static void main(String args[]) throws Throwable {
9512604Sbde        new TestUseRTMDeopt().test();
9612604Sbde    }
9712604Sbde}
9812848Sbde