31 * java.management
32 * @build sun.hotspot.WhiteBox
33 * @run driver ClassFileInstaller sun.hotspot.WhiteBox
34 * sun.hotspot.WhiteBox$WhiteBoxPermission
35 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
36 * -XX:+WhiteBoxAPI
37 * compiler.rtm.locking.TestRTMDeoptOnLowAbortRatio
38 */
39
40 package compiler.rtm.locking;
41
42 import compiler.testlibrary.rtm.AbortProvoker;
43 import compiler.testlibrary.rtm.CompilableTest;
44 import compiler.testlibrary.rtm.RTMLockingStatistics;
45 import compiler.testlibrary.rtm.RTMTestBase;
46 import compiler.testlibrary.rtm.predicate.SupportedCPU;
47 import compiler.testlibrary.rtm.predicate.SupportedVM;
48 import jdk.internal.misc.Unsafe;
49 import jdk.test.lib.Asserts;
50 import jdk.test.lib.process.OutputAnalyzer;
51 import jdk.test.lib.unsafe.UnsafeHelper;
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 low abort ratio method will be deoptimized with
59 * <i>rtm_state_change</i> reason and will continue to use RTM-based lock
60 * elision after that.
61 * This test make asserts on total locks count done by compiled method,
62 * so in order to avoid issue with retriable locks -XX:RTMRetryCount=0 is used.
63 * For more details on that issue see {@link TestUseRTMAfterLockInflation}.
64 */
65 public class TestRTMDeoptOnLowAbortRatio extends CommandLineOptionTest {
66 private static final long LOCKING_THRESHOLD = 100L;
67 private static final long ABORT_THRESHOLD = LOCKING_THRESHOLD / 2L;
68
69 private TestRTMDeoptOnLowAbortRatio() {
70 super(new AndPredicate(new SupportedCPU(), new SupportedVM()));
71 }
116 + "statistics entries for method "
117 + test.getMethodWithLockName());
118
119 RTMLockingStatistics statisticsBeforeDeopt = null;
120
121 for (RTMLockingStatistics s : statistics) {
122 if (s.getTotalLocks()
123 == TestRTMDeoptOnLowAbortRatio.LOCKING_THRESHOLD) {
124 Asserts.assertNull(statisticsBeforeDeopt,
125 "Only one abort was expected during test run");
126 statisticsBeforeDeopt = s;
127 }
128 }
129
130 Asserts.assertNotNull(statisticsBeforeDeopt,
131 "After LockThreshold was reached, method should be recompiled "
132 + "with rtm lock eliding.");
133 }
134
135 public static class Test implements CompilableTest {
136 private static final Unsafe UNSAFE = UnsafeHelper.getUnsafe();
137 private final Object monitor = new Object();
138
139 @Override
140 public String getMethodWithLockName() {
141 return this.getClass().getName() + "::forceAbort";
142 }
143
144 @Override
145 public String[] getMethodsToCompileNames() {
146 return new String[] { getMethodWithLockName() };
147 }
148
149 public void forceAbort(boolean abort) {
150 synchronized(monitor) {
151 if (abort) {
152 Test.UNSAFE.addressSize();
153 }
154 }
155 }
156
|
31 * java.management
32 * @build sun.hotspot.WhiteBox
33 * @run driver ClassFileInstaller sun.hotspot.WhiteBox
34 * sun.hotspot.WhiteBox$WhiteBoxPermission
35 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
36 * -XX:+WhiteBoxAPI
37 * compiler.rtm.locking.TestRTMDeoptOnLowAbortRatio
38 */
39
40 package compiler.rtm.locking;
41
42 import compiler.testlibrary.rtm.AbortProvoker;
43 import compiler.testlibrary.rtm.CompilableTest;
44 import compiler.testlibrary.rtm.RTMLockingStatistics;
45 import compiler.testlibrary.rtm.RTMTestBase;
46 import compiler.testlibrary.rtm.predicate.SupportedCPU;
47 import compiler.testlibrary.rtm.predicate.SupportedVM;
48 import jdk.internal.misc.Unsafe;
49 import jdk.test.lib.Asserts;
50 import jdk.test.lib.process.OutputAnalyzer;
51 import jdk.test.lib.cli.CommandLineOptionTest;
52 import jdk.test.lib.cli.predicate.AndPredicate;
53
54 import java.util.List;
55
56 /**
57 * Test verifies that low abort ratio method will be deoptimized with
58 * <i>rtm_state_change</i> reason and will continue to use RTM-based lock
59 * elision after that.
60 * This test make asserts on total locks count done by compiled method,
61 * so in order to avoid issue with retriable locks -XX:RTMRetryCount=0 is used.
62 * For more details on that issue see {@link TestUseRTMAfterLockInflation}.
63 */
64 public class TestRTMDeoptOnLowAbortRatio extends CommandLineOptionTest {
65 private static final long LOCKING_THRESHOLD = 100L;
66 private static final long ABORT_THRESHOLD = LOCKING_THRESHOLD / 2L;
67
68 private TestRTMDeoptOnLowAbortRatio() {
69 super(new AndPredicate(new SupportedCPU(), new SupportedVM()));
70 }
115 + "statistics entries for method "
116 + test.getMethodWithLockName());
117
118 RTMLockingStatistics statisticsBeforeDeopt = null;
119
120 for (RTMLockingStatistics s : statistics) {
121 if (s.getTotalLocks()
122 == TestRTMDeoptOnLowAbortRatio.LOCKING_THRESHOLD) {
123 Asserts.assertNull(statisticsBeforeDeopt,
124 "Only one abort was expected during test run");
125 statisticsBeforeDeopt = s;
126 }
127 }
128
129 Asserts.assertNotNull(statisticsBeforeDeopt,
130 "After LockThreshold was reached, method should be recompiled "
131 + "with rtm lock eliding.");
132 }
133
134 public static class Test implements CompilableTest {
135 private static final Unsafe UNSAFE = Unsafe.getUnsafe();
136 private final Object monitor = new Object();
137
138 @Override
139 public String getMethodWithLockName() {
140 return this.getClass().getName() + "::forceAbort";
141 }
142
143 @Override
144 public String[] getMethodsToCompileNames() {
145 return new String[] { getMethodWithLockName() };
146 }
147
148 public void forceAbort(boolean abort) {
149 synchronized(monitor) {
150 if (abort) {
151 Test.UNSAFE.addressSize();
152 }
153 }
154 }
155
|