34 * -XX:+WhiteBoxAPI TestUseRTMAfterLockInflation
35 */
36
37 import java.util.List;
38
39 import com.oracle.java.testlibrary.*;
40 import com.oracle.java.testlibrary.cli.CommandLineOptionTest;
41 import com.oracle.java.testlibrary.cli.predicate.AndPredicate;
42 import rtm.*;
43 import rtm.predicate.SupportedCPU;
44 import rtm.predicate.SupportedVM;
45
46 /**
47 * Test verifies that RTM is used after lock inflation by executing compiled
48 * method with RTM-based lock elision using stack lock first, then that lock
49 * is inflated and the same compiled method invoked again.
50 *
51 * Compiled method invoked {@code AbortProvoker.DEFAULT_ITERATIONS} times before
52 * lock inflation and the same amount of times after inflation.
53 * As a result total locks count should be equal to
54 * {@code 2*AbortProvoker.DEFAULT_ITERATIONS}.
55 * It is a pretty strict assertion which could fail if some retriable abort
56 * happened: it could be {@code AbortType.RETRIABLE} or
57 * {@code AbortType.MEM_CONFLICT}, but unfortunately abort can has both these
58 * reasons simultaneously. In order to avoid false negative failures related
59 * to incorrect aborts counting, -XX:RTMRetryCount=0 is used.
60 */
61 public class TestUseRTMAfterLockInflation extends CommandLineOptionTest {
62 private static final long EXPECTED_LOCKS
63 = 2L * AbortProvoker.DEFAULT_ITERATIONS;
64
65 private TestUseRTMAfterLockInflation() {
66 super(new AndPredicate(new SupportedVM(), new SupportedCPU()));
67 }
68
69 @Override
70 protected void runTestCases() throws Throwable {
71 AbortProvoker provoker = AbortType.XABORT.provoker();
72 long totalLocksCount = 0;
73
74 OutputAnalyzer outputAnalyzer = RTMTestBase.executeRTMTest(
83 outputAnalyzer.shouldHaveExitValue(0);
84
85 List<RTMLockingStatistics> statistics = RTMLockingStatistics.fromString(
86 provoker.getMethodWithLockName(), outputAnalyzer.getOutput());
87
88 Asserts.assertEQ(statistics.size(), 2,
89 "VM output should contain two rtm locking statistics entries "
90 + "for method " + provoker.getMethodWithLockName());
91
92 for (RTMLockingStatistics s : statistics) {
93 totalLocksCount += s.getTotalLocks();
94 }
95
96 Asserts.assertEQ(totalLocksCount,
97 TestUseRTMAfterLockInflation.EXPECTED_LOCKS,
98 "Total lock count should be greater or equal to "
99 + TestUseRTMAfterLockInflation.EXPECTED_LOCKS);
100 }
101
102 public static class Test {
103
104 /**
105 * Usage:
106 * Test <provoker type>
107 */
108 public static void main(String args[]) throws Throwable {
109 Asserts.assertGT(args.length, 0,
110 "AbortType name is expected as first argument.");
111
112 AbortProvoker provoker
113 = AbortType.lookup(Integer.valueOf(args[0])).provoker();
114 for (int i = 0; i < AbortProvoker.DEFAULT_ITERATIONS; i++) {
115 provoker.forceAbort();
116 }
117 provoker.inflateMonitor();
118 for (int i = 0; i < AbortProvoker.DEFAULT_ITERATIONS; i++) {
119 provoker.forceAbort();
120 }
121 }
122 }
123
124 public static void main(String args[]) throws Throwable {
125 new TestUseRTMAfterLockInflation().test();
126 }
127 }
|
34 * -XX:+WhiteBoxAPI TestUseRTMAfterLockInflation
35 */
36
37 import java.util.List;
38
39 import com.oracle.java.testlibrary.*;
40 import com.oracle.java.testlibrary.cli.CommandLineOptionTest;
41 import com.oracle.java.testlibrary.cli.predicate.AndPredicate;
42 import rtm.*;
43 import rtm.predicate.SupportedCPU;
44 import rtm.predicate.SupportedVM;
45
46 /**
47 * Test verifies that RTM is used after lock inflation by executing compiled
48 * method with RTM-based lock elision using stack lock first, then that lock
49 * is inflated and the same compiled method invoked again.
50 *
51 * Compiled method invoked {@code AbortProvoker.DEFAULT_ITERATIONS} times before
52 * lock inflation and the same amount of times after inflation.
53 * As a result total locks count should be equal to
54 * {@code 2 * AbortProvoker.DEFAULT_ITERATIONS}.
55 * It is a pretty strict assertion which could fail if some retriable abort
56 * happened: it could be {@code AbortType.RETRIABLE} or
57 * {@code AbortType.MEM_CONFLICT}, but unfortunately abort can has both these
58 * reasons simultaneously. In order to avoid false negative failures related
59 * to incorrect aborts counting, -XX:RTMRetryCount=0 is used.
60 */
61 public class TestUseRTMAfterLockInflation extends CommandLineOptionTest {
62 private static final long EXPECTED_LOCKS
63 = 2L * AbortProvoker.DEFAULT_ITERATIONS;
64
65 private TestUseRTMAfterLockInflation() {
66 super(new AndPredicate(new SupportedVM(), new SupportedCPU()));
67 }
68
69 @Override
70 protected void runTestCases() throws Throwable {
71 AbortProvoker provoker = AbortType.XABORT.provoker();
72 long totalLocksCount = 0;
73
74 OutputAnalyzer outputAnalyzer = RTMTestBase.executeRTMTest(
83 outputAnalyzer.shouldHaveExitValue(0);
84
85 List<RTMLockingStatistics> statistics = RTMLockingStatistics.fromString(
86 provoker.getMethodWithLockName(), outputAnalyzer.getOutput());
87
88 Asserts.assertEQ(statistics.size(), 2,
89 "VM output should contain two rtm locking statistics entries "
90 + "for method " + provoker.getMethodWithLockName());
91
92 for (RTMLockingStatistics s : statistics) {
93 totalLocksCount += s.getTotalLocks();
94 }
95
96 Asserts.assertEQ(totalLocksCount,
97 TestUseRTMAfterLockInflation.EXPECTED_LOCKS,
98 "Total lock count should be greater or equal to "
99 + TestUseRTMAfterLockInflation.EXPECTED_LOCKS);
100 }
101
102 public static class Test {
103 /**
104 * Usage:
105 * Test <provoker type>
106 */
107 public static void main(String args[]) throws Throwable {
108 Asserts.assertGT(args.length, 0,
109 "AbortType name is expected as first argument.");
110
111 AbortProvoker provoker
112 = AbortType.lookup(Integer.valueOf(args[0])).provoker();
113 for (int i = 0; i < AbortProvoker.DEFAULT_ITERATIONS; i++) {
114 AbortProvoker.verifyMonitorState(provoker, false /*deflated*/);
115 provoker.forceAbort();
116 }
117 provoker.inflateMonitor();
118 for (int i = 0; i < AbortProvoker.DEFAULT_ITERATIONS; i++) {
119 AbortProvoker.verifyMonitorState(provoker, true /*inflated*/);
120 provoker.forceAbort();
121 }
122 }
123 }
124
125 public static void main(String args[]) throws Throwable {
126 new TestUseRTMAfterLockInflation().test();
127 }
128 }
|