test/compiler/rtm/locking/TestRTMSpinLoopCount.java

changeset 0
f90c822e73f8
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/compiler/rtm/locking/TestRTMSpinLoopCount.java	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,115 @@
     1.4 +/*
     1.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +/**
    1.29 + * @test
    1.30 + * @bug 8031320
    1.31 + * @summary Verify that RTMSpinLoopCount affects time spent
    1.32 + *          between locking attempts.
    1.33 + * @library /testlibrary /testlibrary/whitebox /compiler/testlibrary
    1.34 + * @build TestRTMSpinLoopCount
    1.35 + * @run main ClassFileInstaller sun.hotspot.WhiteBox
    1.36 + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
    1.37 + *                   -XX:+WhiteBoxAPI TestRTMSpinLoopCount
    1.38 + */
    1.39 +
    1.40 +import java.util.List;
    1.41 +import com.oracle.java.testlibrary.*;
    1.42 +import com.oracle.java.testlibrary.cli.CommandLineOptionTest;
    1.43 +import com.oracle.java.testlibrary.cli.predicate.AndPredicate;
    1.44 +import rtm.*;
    1.45 +import rtm.predicate.SupportedCPU;
    1.46 +import rtm.predicate.SupportedVM;
    1.47 +
    1.48 +/**
    1.49 + * Test verifies that RTMSpinLoopCount increase time spent between retries
    1.50 + * by comparing amount of retries done with different RTMSpinLoopCount's values.
    1.51 + */
    1.52 +public class TestRTMSpinLoopCount extends CommandLineOptionTest {
    1.53 +    private static final int LOCKING_TIME = 1000;
    1.54 +    private static final int RTM_RETRY_COUNT = 1000;
    1.55 +    private static final boolean INFLATE_MONITOR = true;
    1.56 +    private static final long MAX_ABORTS = RTM_RETRY_COUNT + 1L;
    1.57 +    private static final int[] SPIN_LOOP_COUNTS
    1.58 +            = new int[] { 0, 100, 1_000, 1_000_000, 10_000_000 };
    1.59 +
    1.60 +    private TestRTMSpinLoopCount() {
    1.61 +        super(new AndPredicate(new SupportedVM(), new SupportedCPU()));
    1.62 +    }
    1.63 +
    1.64 +    @Override
    1.65 +    protected void runTestCases() throws Throwable {
    1.66 +        long[] aborts = new long[TestRTMSpinLoopCount.SPIN_LOOP_COUNTS.length];
    1.67 +        for (int i = 0; i < TestRTMSpinLoopCount.SPIN_LOOP_COUNTS.length; i++) {
    1.68 +            aborts[i] = getAbortsCountOnLockBusy(
    1.69 +                    TestRTMSpinLoopCount.SPIN_LOOP_COUNTS[i]);
    1.70 +        }
    1.71 +
    1.72 +        for (int i = 1; i < aborts.length; i++) {
    1.73 +            Asserts.assertLTE(aborts[i], aborts[i - 1], "Increased spin loop "
    1.74 +                    + "count should not increase retries count.");
    1.75 +        }
    1.76 +    }
    1.77 +
    1.78 +    private long getAbortsCountOnLockBusy(int spinLoopCount) throws Throwable {
    1.79 +        CompilableTest test = new BusyLock();
    1.80 +
    1.81 +        OutputAnalyzer outputAnalyzer = RTMTestBase.executeRTMTest(
    1.82 +                test,
    1.83 +                CommandLineOptionTest.prepareNumericFlag("RTMRetryCount",
    1.84 +                        TestRTMSpinLoopCount.RTM_RETRY_COUNT),
    1.85 +                CommandLineOptionTest.prepareNumericFlag("RTMSpinLoopCount",
    1.86 +                        spinLoopCount),
    1.87 +                "-XX:-UseRTMXendForLockBusy",
    1.88 +                "-XX:RTMTotalCountIncrRate=1",
    1.89 +                "-XX:+PrintPreciseRTMLockingStatistics",
    1.90 +                BusyLock.class.getName(),
    1.91 +                Boolean.toString(TestRTMSpinLoopCount.INFLATE_MONITOR),
    1.92 +                Integer.toString(TestRTMSpinLoopCount.LOCKING_TIME)
    1.93 +        );
    1.94 +
    1.95 +        outputAnalyzer.shouldHaveExitValue(0);
    1.96 +
    1.97 +        List<RTMLockingStatistics> statistics = RTMLockingStatistics.fromString(
    1.98 +                test.getMethodWithLockName(), outputAnalyzer.getOutput());
    1.99 +
   1.100 +        Asserts.assertEQ(statistics.size(), 1,
   1.101 +                "VM output should contain exactly one entry for method "
   1.102 +                 + test.getMethodWithLockName());
   1.103 +
   1.104 +        RTMLockingStatistics lock = statistics.get(0);
   1.105 +
   1.106 +        Asserts.assertLTE(lock.getTotalAborts(),
   1.107 +                TestRTMSpinLoopCount.MAX_ABORTS, String.format("Total aborts "
   1.108 +                        + "count (%d) should be less or equal to %d",
   1.109 +                        lock.getTotalAborts(),
   1.110 +                        TestRTMSpinLoopCount.MAX_ABORTS));
   1.111 +
   1.112 +        return lock.getTotalAborts();
   1.113 +    }
   1.114 +
   1.115 +    public static void main(String args[]) throws Throwable {
   1.116 +        new TestRTMSpinLoopCount().test();
   1.117 +    }
   1.118 +}

mercurial