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.TestRTMAbortRatio
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 method will be deoptimized on high abort ratio
60 * as soon as abort ratio reaches RTMAbortRatio's value.
61 */
62 public class TestRTMAbortRatio extends CommandLineOptionTest {
63 private TestRTMAbortRatio() {
64 super(new AndPredicate(new SupportedCPU(), new SupportedVM()));
65 }
66
67 @Override
68 protected void runTestCases() throws Throwable {
69 verifyAbortRatio(0, false);
70 verifyAbortRatio(10, false);
71 verifyAbortRatio(50, false);
72 verifyAbortRatio(100, false);
108 int actualRatio;
109
110 if (lock.getTotalAborts() == 1L) {
111 actualRatio = 0;
112 } else {
113 actualRatio = (int) (lock.getTotalLocks()
114 / (lock.getTotalAborts() - 1L));
115 }
116
117 Asserts.assertLTE(actualRatio, abortRatio, String.format(
118 "Actual abort ratio (%d) should lower or equal to "
119 + "specified (%d).", actualRatio, abortRatio));
120 }
121
122 /**
123 * Force abort after {@code Test.WARMUP_ITERATIONS} is done.
124 */
125 public static class Test implements CompilableTest {
126 private static final int TOTAL_ITERATIONS = 10000;
127 private static final int WARMUP_ITERATIONS = 1000;
128 private static final Unsafe UNSAFE = UnsafeHelper.getUnsafe();
129 private final Object monitor = new Object();
130 // Following field have to be static in order to avoid escape analysis.
131 @SuppressWarnings("UnsuedDeclaration")
132 private static int field = 0;
133
134 @Override
135 public String getMethodWithLockName() {
136 return this.getClass().getName() + "::lock";
137 }
138
139 @Override
140 public String[] getMethodsToCompileNames() {
141 return new String[] { getMethodWithLockName() };
142 }
143
144 public void lock(boolean abort) {
145 synchronized(monitor) {
146 if (abort) {
147 Test.UNSAFE.addressSize();
148 }
|
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.TestRTMAbortRatio
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 method will be deoptimized on high abort ratio
59 * as soon as abort ratio reaches RTMAbortRatio's value.
60 */
61 public class TestRTMAbortRatio extends CommandLineOptionTest {
62 private TestRTMAbortRatio() {
63 super(new AndPredicate(new SupportedCPU(), new SupportedVM()));
64 }
65
66 @Override
67 protected void runTestCases() throws Throwable {
68 verifyAbortRatio(0, false);
69 verifyAbortRatio(10, false);
70 verifyAbortRatio(50, false);
71 verifyAbortRatio(100, false);
107 int actualRatio;
108
109 if (lock.getTotalAborts() == 1L) {
110 actualRatio = 0;
111 } else {
112 actualRatio = (int) (lock.getTotalLocks()
113 / (lock.getTotalAborts() - 1L));
114 }
115
116 Asserts.assertLTE(actualRatio, abortRatio, String.format(
117 "Actual abort ratio (%d) should lower or equal to "
118 + "specified (%d).", actualRatio, abortRatio));
119 }
120
121 /**
122 * Force abort after {@code Test.WARMUP_ITERATIONS} is done.
123 */
124 public static class Test implements CompilableTest {
125 private static final int TOTAL_ITERATIONS = 10000;
126 private static final int WARMUP_ITERATIONS = 1000;
127 private static final Unsafe UNSAFE = Unsafe.getUnsafe();
128 private final Object monitor = new Object();
129 // Following field have to be static in order to avoid escape analysis.
130 @SuppressWarnings("UnsuedDeclaration")
131 private static int field = 0;
132
133 @Override
134 public String getMethodWithLockName() {
135 return this.getClass().getName() + "::lock";
136 }
137
138 @Override
139 public String[] getMethodsToCompileNames() {
140 return new String[] { getMethodWithLockName() };
141 }
142
143 public void lock(boolean abort) {
144 synchronized(monitor) {
145 if (abort) {
146 Test.UNSAFE.addressSize();
147 }
|