< prev index next >

test/micro/org/openjdk/bench/vm/lang/LockUnlock.java

Print this page
rev 53382 : 8217368: AArch64: C2 recursive stack locking optimisation not triggered
Reviewed-by: duke


  93         for (int i = 0; i < innerCount; i++) {
  94             synchronized (localObject) {
  95                 dummyInt1++;
  96             }
  97             synchronized (localObject) {
  98                 dummyInt2++;
  99             }
 100         }
 101     }
 102 
 103     /**
 104      * Performs recursive synchronizations on the same local object.
 105      * <p/>
 106      * Result is 3628800
 107      */
 108     @Benchmark
 109     public void testRecursiveSynchronization() {
 110         factorial = fact(10);
 111     }
 112 












 113     private synchronized int fact(int n) {
 114         if (n == 0) {
 115             return 1;
 116         } else {
 117             return fact(n - 1) * n;
 118         }
 119     }
 120 
 121     /**
 122      * With two threads lockObject1 will be contended so should be
 123      * inflated.
 124      */
 125     @Threads(2)
 126     @Benchmark
 127     public void testContendedLock() {
 128         synchronized (lockObject1) {
 129             dummyInt1++;
 130         }
 131     }
 132 }


  93         for (int i = 0; i < innerCount; i++) {
  94             synchronized (localObject) {
  95                 dummyInt1++;
  96             }
  97             synchronized (localObject) {
  98                 dummyInt2++;
  99             }
 100         }
 101     }
 102 
 103     /**
 104      * Performs recursive synchronizations on the same local object.
 105      * <p/>
 106      * Result is 3628800
 107      */
 108     @Benchmark
 109     public void testRecursiveSynchronization() {
 110         factorial = fact(10);
 111     }
 112 
 113     /**
 114      * Same as {@link #testRecursiveSynchronization()} but the first call
 115      * to this method will generate the identity hashcode for this object
 116      * which effectively disables biased locking as they occupy the same
 117      * bits in the object header.
 118      */
 119     @Benchmark
 120     public void testRecursiveSynchronizationNoBias() {
 121         System.identityHashCode(this);
 122         factorial = fact(10);
 123     }
 124 
 125     private synchronized int fact(int n) {
 126         if (n == 0) {
 127             return 1;
 128         } else {
 129             return fact(n - 1) * n;
 130         }
 131     }
 132 
 133     /**
 134      * With two threads lockObject1 will be contended so should be
 135      * inflated.
 136      */
 137     @Threads(2)
 138     @Benchmark
 139     public void testContendedLock() {
 140         synchronized (lockObject1) {
 141             dummyInt1++;
 142         }
 143     }
 144 }
< prev index next >