hotspot/test/compiler/rtm/locking/TestRTMSpinLoopCount.java
author mgerdin
Mon, 11 Aug 2014 17:12:41 +0400
changeset 25958 8dc85547d6d6
parent 24006 54399106938f
child 28190 5a6b07edeb21
permissions -rw-r--r--
8011397: JTREG needs to copy additional WhiteBox class file to JTwork/scratch/sun/hotspot Reviewed-by: kvn, iignatyev, mgerdin Contributed-by: andrey.x.zakharov@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24006
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
     1
/*
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
     4
 *
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
     7
 * published by the Free Software Foundation.
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
     8
 *
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    13
 * accompanied this code).
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    14
 *
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    18
 *
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    21
 * questions.
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    22
 *
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    23
 */
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    24
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    25
/**
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    26
 * @test
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    27
 * @bug 8031320
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    28
 * @summary Verify that RTMSpinLoopCount affects time spent
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    29
 *          between locking attempts.
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    30
 * @library /testlibrary /testlibrary/whitebox /compiler/testlibrary
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    31
 * @build TestRTMSpinLoopCount
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    32
 * @run main ClassFileInstaller sun.hotspot.WhiteBox
25958
8dc85547d6d6 8011397: JTREG needs to copy additional WhiteBox class file to JTwork/scratch/sun/hotspot
mgerdin
parents: 24006
diff changeset
    33
 *                              sun.hotspot.WhiteBox$WhiteBoxPermission
24006
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    34
 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    35
 *                   -XX:+WhiteBoxAPI TestRTMSpinLoopCount
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    36
 */
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    37
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    38
import java.util.List;
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    39
import com.oracle.java.testlibrary.*;
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    40
import com.oracle.java.testlibrary.cli.CommandLineOptionTest;
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    41
import com.oracle.java.testlibrary.cli.predicate.AndPredicate;
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    42
import rtm.*;
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    43
import rtm.predicate.SupportedCPU;
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    44
import rtm.predicate.SupportedVM;
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    45
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    46
/**
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    47
 * Test verifies that RTMSpinLoopCount increase time spent between retries
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    48
 * by comparing amount of retries done with different RTMSpinLoopCount's values.
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    49
 */
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    50
public class TestRTMSpinLoopCount extends CommandLineOptionTest {
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    51
    private static final int LOCKING_TIME = 1000;
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    52
    private static final int RTM_RETRY_COUNT = 1000;
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    53
    private static final boolean INFLATE_MONITOR = true;
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    54
    private static final long MAX_ABORTS = RTM_RETRY_COUNT + 1L;
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    55
    private static final int[] SPIN_LOOP_COUNTS
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    56
            = new int[] { 0, 100, 1_000, 1_000_000, 10_000_000 };
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    57
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    58
    private TestRTMSpinLoopCount() {
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    59
        super(new AndPredicate(new SupportedVM(), new SupportedCPU()));
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    60
    }
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    61
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    62
    @Override
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    63
    protected void runTestCases() throws Throwable {
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    64
        long[] aborts = new long[TestRTMSpinLoopCount.SPIN_LOOP_COUNTS.length];
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    65
        for (int i = 0; i < TestRTMSpinLoopCount.SPIN_LOOP_COUNTS.length; i++) {
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    66
            aborts[i] = getAbortsCountOnLockBusy(
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    67
                    TestRTMSpinLoopCount.SPIN_LOOP_COUNTS[i]);
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    68
        }
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    69
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    70
        for (int i = 1; i < aborts.length; i++) {
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    71
            Asserts.assertLTE(aborts[i], aborts[i - 1], "Increased spin loop "
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    72
                    + "count should not increase retries count.");
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    73
        }
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    74
    }
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    75
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    76
    private long getAbortsCountOnLockBusy(int spinLoopCount) throws Throwable {
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    77
        CompilableTest test = new BusyLock();
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    78
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    79
        OutputAnalyzer outputAnalyzer = RTMTestBase.executeRTMTest(
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    80
                test,
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    81
                CommandLineOptionTest.prepareNumericFlag("RTMRetryCount",
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    82
                        TestRTMSpinLoopCount.RTM_RETRY_COUNT),
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    83
                CommandLineOptionTest.prepareNumericFlag("RTMSpinLoopCount",
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    84
                        spinLoopCount),
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    85
                "-XX:-UseRTMXendForLockBusy",
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    86
                "-XX:RTMTotalCountIncrRate=1",
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    87
                "-XX:+PrintPreciseRTMLockingStatistics",
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    88
                BusyLock.class.getName(),
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    89
                Boolean.toString(TestRTMSpinLoopCount.INFLATE_MONITOR),
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    90
                Integer.toString(TestRTMSpinLoopCount.LOCKING_TIME)
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    91
        );
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    92
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    93
        outputAnalyzer.shouldHaveExitValue(0);
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    94
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    95
        List<RTMLockingStatistics> statistics = RTMLockingStatistics.fromString(
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    96
                test.getMethodWithLockName(), outputAnalyzer.getOutput());
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    97
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    98
        Asserts.assertEQ(statistics.size(), 1,
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
    99
                "VM output should contain exactly one entry for method "
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
   100
                 + test.getMethodWithLockName());
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
   101
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
   102
        RTMLockingStatistics lock = statistics.get(0);
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
   103
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
   104
        Asserts.assertLTE(lock.getTotalAborts(),
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
   105
                TestRTMSpinLoopCount.MAX_ABORTS, String.format("Total aborts "
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
   106
                        + "count (%d) should be less or equal to %d",
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
   107
                        lock.getTotalAborts(),
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
   108
                        TestRTMSpinLoopCount.MAX_ABORTS));
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
   109
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
   110
        return lock.getTotalAborts();
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
   111
    }
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
   112
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
   113
    public static void main(String args[]) throws Throwable {
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
   114
        new TestRTMSpinLoopCount().test();
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
   115
    }
54399106938f 8037860: Add tests to cover Intel RTM instructions support
iignatyev
parents:
diff changeset
   116
}