109 110 /** 111 * Force abort after {@code Test.WARMUP_ITERATIONS} is done. 112 */ 113 public static class Test implements CompilableTest { 114 private static final int TOTAL_ITERATIONS = 10000; 115 private static final int WARMUP_ITERATIONS = 1000; 116 private static final Unsafe UNSAFE = Utils.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[] { 130 getMethodWithLockName(), 131 Unsafe.class.getName() + "::addressSize" 132 }; 133 } 134 135 public void lock(boolean abort) { 136 synchronized(monitor) { 137 if (abort) { 138 Test.UNSAFE.addressSize(); 139 } 140 } 141 } 142 143 /** 144 * Usage: 145 * Test <inflate monitor> 146 */ 147 public static void main(String args[]) throws Throwable { 148 Asserts.assertGTE(args.length, 1, "One argument required."); 149 Test t = new Test(); 150 if (Boolean.valueOf(args[0])) { 151 AbortProvoker.inflateMonitor(t.monitor); 152 } 153 for (int i = 0; i < Test.TOTAL_ITERATIONS; i++) { 154 t.lock(i >= Test.WARMUP_ITERATIONS); 155 } 156 } 157 } 158 159 public static void main(String args[]) throws Throwable { 160 new TestRTMAbortRatio().test(); 161 } 162 } 163 | 109 110 /** 111 * Force abort after {@code Test.WARMUP_ITERATIONS} is done. 112 */ 113 public static class Test implements CompilableTest { 114 private static final int TOTAL_ITERATIONS = 10000; 115 private static final int WARMUP_ITERATIONS = 1000; 116 private static final Unsafe UNSAFE = Utils.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 abort) { 133 synchronized(monitor) { 134 if (abort) { 135 Test.UNSAFE.addressSize(); 136 } 137 } 138 } 139 140 /** 141 * Usage: 142 * Test <inflate monitor> 143 */ 144 public static void main(String args[]) throws Throwable { 145 Asserts.assertGTE(args.length, 1, "One argument required."); 146 Test t = new Test(); 147 boolean shouldBeInflated = Boolean.valueOf(args[0]); 148 if (shouldBeInflated) { 149 AbortProvoker.inflateMonitor(t.monitor); 150 } 151 for (int i = 0; i < Test.TOTAL_ITERATIONS; i++) { 152 AbortProvoker.verifyMonitorState(t.monitor, shouldBeInflated); 153 t.lock(i >= Test.WARMUP_ITERATIONS); 154 } 155 } 156 } 157 158 public static void main(String args[]) throws Throwable { 159 new TestRTMAbortRatio().test(); 160 } 161 } 162 |