test/compiler/rtm/locking/TestRTMLockingThreshold.java

Print this page




 125         Asserts.assertNotNull(statBeforeDeopt, "There should be exactly one "
 126                 + "statistics entry corresponding to ProfileRTM state.");
 127     }
 128 
 129     public static class Test implements CompilableTest {
 130         // Following field have to be static in order to avoid escape analysis.
 131         @SuppressWarnings("UnsuedDeclaration")
 132         private static int field = 0;
 133         private static final int TOTAL_ITERATIONS = 10000;
 134         private static final Unsafe UNSAFE = Utils.getUnsafe();
 135         private final Object monitor = new Object();
 136 
 137 
 138         @Override
 139         public String getMethodWithLockName() {
 140             return this.getClass().getName() + "::lock";
 141         }
 142 
 143         @Override
 144         public String[] getMethodsToCompileNames() {
 145             return new String[] {
 146                 getMethodWithLockName(),
 147                 sun.misc.Unsafe.class.getName() + "::addressSize"
 148             };
 149         }
 150 
 151         public void lock(boolean abort) {
 152             synchronized(monitor) {
 153                 if (abort) {
 154                     Test.field += Test.UNSAFE.addressSize();
 155                 }
 156             }
 157         }
 158 
 159         /**
 160          * Usage:
 161          * Test <inflate monitor>
 162          */
 163         public static void main(String args[]) throws Throwable {
 164             Asserts.assertGTE(args.length, 1, "One argument required.");
 165             Test t = new Test();
 166 
 167             if (Boolean.valueOf(args[0])) {
 168                 AbortProvoker.inflateMonitor(t.monitor);
 169             }
 170             for (int i = 0; i < Test.TOTAL_ITERATIONS; i++) {

 171                 t.lock(i % 2 == 1);
 172             }
 173         }
 174     }
 175 
 176     public static void main(String args[]) throws Throwable {
 177         new TestRTMLockingThreshold().test();
 178     }
 179 }


 125         Asserts.assertNotNull(statBeforeDeopt, "There should be exactly one "
 126                 + "statistics entry corresponding to ProfileRTM state.");
 127     }
 128 
 129     public static class Test implements CompilableTest {
 130         // Following field have to be static in order to avoid escape analysis.
 131         @SuppressWarnings("UnsuedDeclaration")
 132         private static int field = 0;
 133         private static final int TOTAL_ITERATIONS = 10000;
 134         private static final Unsafe UNSAFE = Utils.getUnsafe();
 135         private final Object monitor = new Object();
 136 
 137 
 138         @Override
 139         public String getMethodWithLockName() {
 140             return this.getClass().getName() + "::lock";
 141         }
 142 
 143         @Override
 144         public String[] getMethodsToCompileNames() {
 145             return new String[] { getMethodWithLockName() };



 146         }
 147 
 148         public void lock(boolean abort) {
 149             synchronized(monitor) {
 150                 if (abort) {
 151                     Test.field += Test.UNSAFE.addressSize();
 152                 }
 153             }
 154         }
 155 
 156         /**
 157          * Usage:
 158          * Test &lt;inflate monitor&gt;
 159          */
 160         public static void main(String args[]) throws Throwable {
 161             Asserts.assertGTE(args.length, 1, "One argument required.");
 162             Test t = new Test();
 163             boolean shouldBeInflated = Boolean.valueOf(args[0]);
 164             if (shouldBeInflated) {
 165                 AbortProvoker.inflateMonitor(t.monitor);
 166             }
 167             for (int i = 0; i < Test.TOTAL_ITERATIONS; i++) {
 168                 AbortProvoker.verifyMonitorState(t.monitor, shouldBeInflated);
 169                 t.lock(i % 2 == 1);
 170             }
 171         }
 172     }
 173 
 174     public static void main(String args[]) throws Throwable {
 175         new TestRTMLockingThreshold().test();
 176     }
 177 }