32 * java.management
33 * @build sun.hotspot.WhiteBox
34 * @run driver ClassFileInstaller sun.hotspot.WhiteBox
35 * sun.hotspot.WhiteBox$WhiteBoxPermission
36 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
37 * -XX:+WhiteBoxAPI
38 * compiler.rtm.locking.TestRTMTotalCountIncrRate
39 */
40
41 package compiler.rtm.locking;
42
43 import compiler.testlibrary.rtm.AbortProvoker;
44 import compiler.testlibrary.rtm.CompilableTest;
45 import compiler.testlibrary.rtm.RTMLockingStatistics;
46 import compiler.testlibrary.rtm.RTMTestBase;
47 import compiler.testlibrary.rtm.predicate.SupportedCPU;
48 import compiler.testlibrary.rtm.predicate.SupportedVM;
49 import jdk.internal.misc.Unsafe;
50 import jdk.test.lib.Asserts;
51 import jdk.test.lib.process.OutputAnalyzer;
52 import jdk.test.lib.unsafe.UnsafeHelper;
53 import jdk.test.lib.cli.CommandLineOptionTest;
54 import jdk.test.lib.cli.predicate.AndPredicate;
55
56 import java.util.List;
57
58 /**
59 * Test verifies that with RTMTotalCountIncrRate=1 RTM locking statistics
60 * contains precise information abort attempted locks and that with other values
61 * statistics contains information abort non-zero locking attempts.
62 * Since assert done for RTMTotalCountIncrRate=1 is pretty strict, test uses
63 * -XX:RTMRetryCount=0 to avoid issue with retriable aborts. For more details on
64 * that issue see {@link TestUseRTMAfterLockInflation}.
65 */
66 public class TestRTMTotalCountIncrRate extends CommandLineOptionTest {
67 private TestRTMTotalCountIncrRate() {
68 super(new AndPredicate(new SupportedCPU(), new SupportedVM()));
69 }
70
71 @Override
72 protected void runTestCases() throws Throwable {
96
97 outputAnalyzer.shouldHaveExitValue(0);
98
99 List<RTMLockingStatistics> statistics = RTMLockingStatistics.fromString(
100 test.getMethodWithLockName(), outputAnalyzer.getOutput());
101
102 Asserts.assertEQ(statistics.size(), 1, "VM output should contain "
103 + "exactly one RTM locking statistics entry for method "
104 + test.getMethodWithLockName());
105
106 RTMLockingStatistics lock = statistics.get(0);
107 if (incrRate == 1) {
108 Asserts.assertEQ(lock.getTotalLocks(), Test.TOTAL_ITERATIONS,
109 "Total locks should be exactly the same as amount of "
110 + "iterations.");
111 }
112 }
113
114 public static class Test implements CompilableTest {
115 private static final long TOTAL_ITERATIONS = 10000L;
116 private static final Unsafe UNSAFE = UnsafeHelper.getUnsafe();
117 private final Object monitor = new Object();
118 // Following field have to be static in order to avoid escape analysis.
119 @SuppressWarnings("UnsuedDeclaration")
120 private static int field = 0;
121
122 @Override
123 public String getMethodWithLockName() {
124 return this.getClass().getName() + "::lock";
125 }
126
127 @Override
128 public String[] getMethodsToCompileNames() {
129 return new String[] { getMethodWithLockName() };
130 }
131
132 public void lock(boolean forceAbort) {
133 synchronized(monitor) {
134 if (forceAbort) {
135 // We're calling native method in order to force
136 // abort. It's done by explicit xabort call emitted
|
32 * java.management
33 * @build sun.hotspot.WhiteBox
34 * @run driver ClassFileInstaller sun.hotspot.WhiteBox
35 * sun.hotspot.WhiteBox$WhiteBoxPermission
36 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
37 * -XX:+WhiteBoxAPI
38 * compiler.rtm.locking.TestRTMTotalCountIncrRate
39 */
40
41 package compiler.rtm.locking;
42
43 import compiler.testlibrary.rtm.AbortProvoker;
44 import compiler.testlibrary.rtm.CompilableTest;
45 import compiler.testlibrary.rtm.RTMLockingStatistics;
46 import compiler.testlibrary.rtm.RTMTestBase;
47 import compiler.testlibrary.rtm.predicate.SupportedCPU;
48 import compiler.testlibrary.rtm.predicate.SupportedVM;
49 import jdk.internal.misc.Unsafe;
50 import jdk.test.lib.Asserts;
51 import jdk.test.lib.process.OutputAnalyzer;
52 import jdk.test.lib.cli.CommandLineOptionTest;
53 import jdk.test.lib.cli.predicate.AndPredicate;
54
55 import java.util.List;
56
57 /**
58 * Test verifies that with RTMTotalCountIncrRate=1 RTM locking statistics
59 * contains precise information abort attempted locks and that with other values
60 * statistics contains information abort non-zero locking attempts.
61 * Since assert done for RTMTotalCountIncrRate=1 is pretty strict, test uses
62 * -XX:RTMRetryCount=0 to avoid issue with retriable aborts. For more details on
63 * that issue see {@link TestUseRTMAfterLockInflation}.
64 */
65 public class TestRTMTotalCountIncrRate extends CommandLineOptionTest {
66 private TestRTMTotalCountIncrRate() {
67 super(new AndPredicate(new SupportedCPU(), new SupportedVM()));
68 }
69
70 @Override
71 protected void runTestCases() throws Throwable {
95
96 outputAnalyzer.shouldHaveExitValue(0);
97
98 List<RTMLockingStatistics> statistics = RTMLockingStatistics.fromString(
99 test.getMethodWithLockName(), outputAnalyzer.getOutput());
100
101 Asserts.assertEQ(statistics.size(), 1, "VM output should contain "
102 + "exactly one RTM locking statistics entry for method "
103 + test.getMethodWithLockName());
104
105 RTMLockingStatistics lock = statistics.get(0);
106 if (incrRate == 1) {
107 Asserts.assertEQ(lock.getTotalLocks(), Test.TOTAL_ITERATIONS,
108 "Total locks should be exactly the same as amount of "
109 + "iterations.");
110 }
111 }
112
113 public static class Test implements CompilableTest {
114 private static final long TOTAL_ITERATIONS = 10000L;
115 private static final Unsafe UNSAFE = Unsafe.getUnsafe();
116 private final Object monitor = new Object();
117 // Following field have to be static in order to avoid escape analysis.
118 @SuppressWarnings("UnsuedDeclaration")
119 private static int field = 0;
120
121 @Override
122 public String getMethodWithLockName() {
123 return this.getClass().getName() + "::lock";
124 }
125
126 @Override
127 public String[] getMethodsToCompileNames() {
128 return new String[] { getMethodWithLockName() };
129 }
130
131 public void lock(boolean forceAbort) {
132 synchronized(monitor) {
133 if (forceAbort) {
134 // We're calling native method in order to force
135 // abort. It's done by explicit xabort call emitted
|