changeset 7684:a257e2effbf0

8049355: compiler/rtm/locking/TestRTMLockingThreshold test may fail if transaction was aborted by interrupt Reviewed-by: kvn, iignatyev
author fzhinkin
date Wed, 14 Jan 2015 09:54:08 +0300
parents 0a04b80f7e86
children eb3576118c11
files test/compiler/rtm/locking/TestRTMDeoptOnLowAbortRatio.java test/compiler/rtm/locking/TestRTMLockingThreshold.java
diffstat 2 files changed, 18 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/test/compiler/rtm/locking/TestRTMDeoptOnLowAbortRatio.java	Wed Jan 14 09:54:45 2015 +0300
+++ b/test/compiler/rtm/locking/TestRTMDeoptOnLowAbortRatio.java	Wed Jan 14 09:54:08 2015 +0300
@@ -53,6 +53,7 @@
  */
 public class TestRTMDeoptOnLowAbortRatio extends CommandLineOptionTest {
     private static final long LOCKING_THRESHOLD = 100L;
+    private static final long ABORT_THRESHOLD = LOCKING_THRESHOLD / 2L;
 
     private TestRTMDeoptOnLowAbortRatio() {
         super(new AndPredicate(new SupportedCPU(), new SupportedVM()));
@@ -77,7 +78,8 @@
                         useStackLock),
                 CommandLineOptionTest.prepareNumericFlag("RTMLockingThreshold",
                         TestRTMDeoptOnLowAbortRatio.LOCKING_THRESHOLD),
-                "-XX:RTMAbortThreshold=1",
+                CommandLineOptionTest.prepareNumericFlag("RTMAbortThreshold",
+                        TestRTMDeoptOnLowAbortRatio.ABORT_THRESHOLD),
                 "-XX:RTMAbortRatio=100",
                 "-XX:CompileThreshold=1",
                 "-XX:RTMRetryCount=0",
@@ -107,7 +109,7 @@
 
         for (RTMLockingStatistics s : statistics) {
             if (s.getTotalLocks()
-                    == TestRTMDeoptOnLowAbortRatio.LOCKING_THRESHOLD + 1L) {
+                    == TestRTMDeoptOnLowAbortRatio.LOCKING_THRESHOLD) {
                 Asserts.assertNull(statisticsBeforeDeopt,
                         "Only one abort was expected during test run");
                 statisticsBeforeDeopt = s;
@@ -154,8 +156,7 @@
             }
             for (int i = 0; i < AbortProvoker.DEFAULT_ITERATIONS; i++) {
                 AbortProvoker.verifyMonitorState(t.monitor, shouldBeInflated);
-                t.forceAbort(
-                        i == TestRTMDeoptOnLowAbortRatio.LOCKING_THRESHOLD);
+                t.forceAbort(i >= TestRTMDeoptOnLowAbortRatio.ABORT_THRESHOLD);
             }
         }
     }
--- a/test/compiler/rtm/locking/TestRTMLockingThreshold.java	Wed Jan 14 09:54:45 2015 +0300
+++ b/test/compiler/rtm/locking/TestRTMLockingThreshold.java	Wed Jan 14 09:54:08 2015 +0300
@@ -58,7 +58,7 @@
      * interrupts, VMM calls, etc. during first lock attempt.
      *
      */
-    private static final int ABORT_THRESHOLD = 10;
+    private static final int MIN_ABORT_THRESHOLD = 10;
 
     @Override
     protected void runTestCases() throws Throwable {
@@ -75,6 +75,9 @@
             boolean useStackLock) throws Throwable {
         CompilableTest test = new Test();
 
+        int abortThreshold = Math.max(lockingThreshold / 2,
+                TestRTMLockingThreshold.MIN_ABORT_THRESHOLD);
+
         OutputAnalyzer outputAnalyzer = RTMTestBase.executeRTMTest(
                 test,
                 "-XX:CompileThreshold=1",
@@ -84,7 +87,7 @@
                 "-XX:RTMTotalCountIncrRate=1",
                 "-XX:RTMRetryCount=0",
                 CommandLineOptionTest.prepareNumericFlag("RTMAbortThreshold",
-                        TestRTMLockingThreshold.ABORT_THRESHOLD),
+                        abortThreshold),
                 CommandLineOptionTest.prepareNumericFlag("RTMLockingThreshold",
                         lockingThreshold),
                 "-XX:RTMAbortRatio=100",
@@ -103,16 +106,12 @@
                 + "RTM locking statistics entries.");
 
         /**
-         * We force abort on each odd iteration, so if RTMLockingThreshold==0,
-         * then we have to make 1 call without abort to avoid rtm state
-         * transition to NoRTM (otherwise actual abort ratio will be 100%),
-         * and after that make 1 call with abort to force deoptimization.
-         * This leads us to two locks for threshold 0.
-         * For other threshold values we have to make RTMLockingThreshold + 1
-         * locks if locking threshold is even, or + 0 if odd.
+         * If RTMLockingThreshold==0, then we have to make at least 1 call.
          */
-        long expectedValue = lockingThreshold +
-                (lockingThreshold == 0L ? 2L : lockingThreshold % 2L);
+        long expectedValue = lockingThreshold;
+        if (expectedValue == 0) {
+            expectedValue++;
+        }
 
         RTMLockingStatistics statBeforeDeopt = null;
         for (RTMLockingStatistics s : statistics) {
@@ -159,15 +158,16 @@
          * Test &lt;inflate monitor&gt;
          */
         public static void main(String args[]) throws Throwable {
-            Asserts.assertGTE(args.length, 1, "One argument required.");
+            Asserts.assertGTE(args.length, 2, "Two arguments required.");
             Test t = new Test();
             boolean shouldBeInflated = Boolean.valueOf(args[0]);
+            int lockingThreshold = Integer.valueOf(args[1]);
             if (shouldBeInflated) {
                 AbortProvoker.inflateMonitor(t.monitor);
             }
             for (int i = 0; i < Test.TOTAL_ITERATIONS; i++) {
                 AbortProvoker.verifyMonitorState(t.monitor, shouldBeInflated);
-                t.lock(i % 2 == 1);
+                t.lock(i >= lockingThreshold / 2);
             }
         }
     }