8049355: compiler/rtm/locking/TestRTMLockingThreshold test may fail if transaction was aborted by interrupt

Reviewed-by: kvn, iignatyev
This commit is contained in:
Filipp Zhinkin 2015-01-14 09:54:08 +03:00
parent 251b4df764
commit b850617243
2 changed files with 18 additions and 17 deletions

View File

@ -53,6 +53,7 @@ import sun.misc.Unsafe;
*/ */
public class TestRTMDeoptOnLowAbortRatio extends CommandLineOptionTest { public class TestRTMDeoptOnLowAbortRatio extends CommandLineOptionTest {
private static final long LOCKING_THRESHOLD = 100L; private static final long LOCKING_THRESHOLD = 100L;
private static final long ABORT_THRESHOLD = LOCKING_THRESHOLD / 2L;
private TestRTMDeoptOnLowAbortRatio() { private TestRTMDeoptOnLowAbortRatio() {
super(new AndPredicate(new SupportedCPU(), new SupportedVM())); super(new AndPredicate(new SupportedCPU(), new SupportedVM()));
@ -77,7 +78,8 @@ public class TestRTMDeoptOnLowAbortRatio extends CommandLineOptionTest {
useStackLock), useStackLock),
CommandLineOptionTest.prepareNumericFlag("RTMLockingThreshold", CommandLineOptionTest.prepareNumericFlag("RTMLockingThreshold",
TestRTMDeoptOnLowAbortRatio.LOCKING_THRESHOLD), TestRTMDeoptOnLowAbortRatio.LOCKING_THRESHOLD),
"-XX:RTMAbortThreshold=1", CommandLineOptionTest.prepareNumericFlag("RTMAbortThreshold",
TestRTMDeoptOnLowAbortRatio.ABORT_THRESHOLD),
"-XX:RTMAbortRatio=100", "-XX:RTMAbortRatio=100",
"-XX:CompileThreshold=1", "-XX:CompileThreshold=1",
"-XX:RTMRetryCount=0", "-XX:RTMRetryCount=0",
@ -107,7 +109,7 @@ public class TestRTMDeoptOnLowAbortRatio extends CommandLineOptionTest {
for (RTMLockingStatistics s : statistics) { for (RTMLockingStatistics s : statistics) {
if (s.getTotalLocks() if (s.getTotalLocks()
== TestRTMDeoptOnLowAbortRatio.LOCKING_THRESHOLD + 1L) { == TestRTMDeoptOnLowAbortRatio.LOCKING_THRESHOLD) {
Asserts.assertNull(statisticsBeforeDeopt, Asserts.assertNull(statisticsBeforeDeopt,
"Only one abort was expected during test run"); "Only one abort was expected during test run");
statisticsBeforeDeopt = s; statisticsBeforeDeopt = s;
@ -154,8 +156,7 @@ public class TestRTMDeoptOnLowAbortRatio extends CommandLineOptionTest {
} }
for (int i = 0; i < AbortProvoker.DEFAULT_ITERATIONS; i++) { for (int i = 0; i < AbortProvoker.DEFAULT_ITERATIONS; i++) {
AbortProvoker.verifyMonitorState(t.monitor, shouldBeInflated); AbortProvoker.verifyMonitorState(t.monitor, shouldBeInflated);
t.forceAbort( t.forceAbort(i >= TestRTMDeoptOnLowAbortRatio.ABORT_THRESHOLD);
i == TestRTMDeoptOnLowAbortRatio.LOCKING_THRESHOLD);
} }
} }
} }

View File

@ -58,7 +58,7 @@ public class TestRTMLockingThreshold extends CommandLineOptionTest {
* interrupts, VMM calls, etc. during first lock attempt. * interrupts, VMM calls, etc. during first lock attempt.
* *
*/ */
private static final int ABORT_THRESHOLD = 10; private static final int MIN_ABORT_THRESHOLD = 10;
@Override @Override
protected void runTestCases() throws Throwable { protected void runTestCases() throws Throwable {
@ -75,6 +75,9 @@ public class TestRTMLockingThreshold extends CommandLineOptionTest {
boolean useStackLock) throws Throwable { boolean useStackLock) throws Throwable {
CompilableTest test = new Test(); CompilableTest test = new Test();
int abortThreshold = Math.max(lockingThreshold / 2,
TestRTMLockingThreshold.MIN_ABORT_THRESHOLD);
OutputAnalyzer outputAnalyzer = RTMTestBase.executeRTMTest( OutputAnalyzer outputAnalyzer = RTMTestBase.executeRTMTest(
test, test,
"-XX:CompileThreshold=1", "-XX:CompileThreshold=1",
@ -84,7 +87,7 @@ public class TestRTMLockingThreshold extends CommandLineOptionTest {
"-XX:RTMTotalCountIncrRate=1", "-XX:RTMTotalCountIncrRate=1",
"-XX:RTMRetryCount=0", "-XX:RTMRetryCount=0",
CommandLineOptionTest.prepareNumericFlag("RTMAbortThreshold", CommandLineOptionTest.prepareNumericFlag("RTMAbortThreshold",
TestRTMLockingThreshold.ABORT_THRESHOLD), abortThreshold),
CommandLineOptionTest.prepareNumericFlag("RTMLockingThreshold", CommandLineOptionTest.prepareNumericFlag("RTMLockingThreshold",
lockingThreshold), lockingThreshold),
"-XX:RTMAbortRatio=100", "-XX:RTMAbortRatio=100",
@ -103,16 +106,12 @@ public class TestRTMLockingThreshold extends CommandLineOptionTest {
+ "RTM locking statistics entries."); + "RTM locking statistics entries.");
/** /**
* We force abort on each odd iteration, so if RTMLockingThreshold==0, * If RTMLockingThreshold==0, then we have to make at least 1 call.
* 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.
*/ */
long expectedValue = lockingThreshold + long expectedValue = lockingThreshold;
(lockingThreshold == 0L ? 2L : lockingThreshold % 2L); if (expectedValue == 0) {
expectedValue++;
}
RTMLockingStatistics statBeforeDeopt = null; RTMLockingStatistics statBeforeDeopt = null;
for (RTMLockingStatistics s : statistics) { for (RTMLockingStatistics s : statistics) {
@ -159,15 +158,16 @@ public class TestRTMLockingThreshold extends CommandLineOptionTest {
* Test &lt;inflate monitor&gt; * Test &lt;inflate monitor&gt;
*/ */
public static void main(String args[]) throws Throwable { 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(); Test t = new Test();
boolean shouldBeInflated = Boolean.valueOf(args[0]); boolean shouldBeInflated = Boolean.valueOf(args[0]);
int lockingThreshold = Integer.valueOf(args[1]);
if (shouldBeInflated) { if (shouldBeInflated) {
AbortProvoker.inflateMonitor(t.monitor); AbortProvoker.inflateMonitor(t.monitor);
} }
for (int i = 0; i < Test.TOTAL_ITERATIONS; i++) { for (int i = 0; i < Test.TOTAL_ITERATIONS; i++) {
AbortProvoker.verifyMonitorState(t.monitor, shouldBeInflated); AbortProvoker.verifyMonitorState(t.monitor, shouldBeInflated);
t.lock(i % 2 == 1); t.lock(i >= lockingThreshold / 2);
} }
} }
} }