< prev index next >

test/compiler/rtm/locking/TestRTMLockingThreshold.java

Print this page




  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.TestRTMLockingThreshold
  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 RTMLockingThreshold option actually affects how soon
  60  * method will be deoptimized on low abort ratio.
  61  */
  62 public class TestRTMLockingThreshold extends CommandLineOptionTest {
  63     private TestRTMLockingThreshold() {
  64         super(new AndPredicate(new SupportedVM(), new SupportedCPU()));
  65     }
  66 
  67     /**
  68      * We use non-zero abort threshold to avoid abort related to
  69      * interrupts, VMM calls, etc. during first lock attempt.
  70      *
  71      */
  72     private static final int MIN_ABORT_THRESHOLD = 10;


 125         }
 126 
 127         RTMLockingStatistics statBeforeDeopt = null;
 128         for (RTMLockingStatistics s : statistics) {
 129             if (s.getTotalLocks() == expectedValue) {
 130                 Asserts.assertNull(statBeforeDeopt,
 131                         "Only one statistics entry should contain aborts");
 132                 statBeforeDeopt = s;
 133             }
 134         }
 135 
 136         Asserts.assertNotNull(statBeforeDeopt, "There should be exactly one "
 137                 + "statistics entry corresponding to ProfileRTM state.");
 138     }
 139 
 140     public static class Test implements CompilableTest {
 141         // Following field have to be static in order to avoid escape analysis.
 142         @SuppressWarnings("UnsuedDeclaration")
 143         private static int field = 0;
 144         private static final int TOTAL_ITERATIONS = 10000;
 145         private static final Unsafe UNSAFE = UnsafeHelper.getUnsafe();
 146         private final Object monitor = new Object();
 147 
 148 
 149         @Override
 150         public String getMethodWithLockName() {
 151             return this.getClass().getName() + "::lock";
 152         }
 153 
 154         @Override
 155         public String[] getMethodsToCompileNames() {
 156             return new String[] { getMethodWithLockName() };
 157         }
 158 
 159         public void lock(boolean abort) {
 160             synchronized(monitor) {
 161                 if (abort) {
 162                     Test.field += Test.UNSAFE.addressSize();
 163                 }
 164             }
 165         }




  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.TestRTMLockingThreshold
  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 RTMLockingThreshold option actually affects how soon
  59  * method will be deoptimized on low abort ratio.
  60  */
  61 public class TestRTMLockingThreshold extends CommandLineOptionTest {
  62     private TestRTMLockingThreshold() {
  63         super(new AndPredicate(new SupportedVM(), new SupportedCPU()));
  64     }
  65 
  66     /**
  67      * We use non-zero abort threshold to avoid abort related to
  68      * interrupts, VMM calls, etc. during first lock attempt.
  69      *
  70      */
  71     private static final int MIN_ABORT_THRESHOLD = 10;


 124         }
 125 
 126         RTMLockingStatistics statBeforeDeopt = null;
 127         for (RTMLockingStatistics s : statistics) {
 128             if (s.getTotalLocks() == expectedValue) {
 129                 Asserts.assertNull(statBeforeDeopt,
 130                         "Only one statistics entry should contain aborts");
 131                 statBeforeDeopt = s;
 132             }
 133         }
 134 
 135         Asserts.assertNotNull(statBeforeDeopt, "There should be exactly one "
 136                 + "statistics entry corresponding to ProfileRTM state.");
 137     }
 138 
 139     public static class Test implements CompilableTest {
 140         // Following field have to be static in order to avoid escape analysis.
 141         @SuppressWarnings("UnsuedDeclaration")
 142         private static int field = 0;
 143         private static final int TOTAL_ITERATIONS = 10000;
 144         private static final Unsafe UNSAFE = Unsafe.getUnsafe();
 145         private final Object monitor = new Object();
 146 
 147 
 148         @Override
 149         public String getMethodWithLockName() {
 150             return this.getClass().getName() + "::lock";
 151         }
 152 
 153         @Override
 154         public String[] getMethodsToCompileNames() {
 155             return new String[] { getMethodWithLockName() };
 156         }
 157 
 158         public void lock(boolean abort) {
 159             synchronized(monitor) {
 160                 if (abort) {
 161                     Test.field += Test.UNSAFE.addressSize();
 162                 }
 163             }
 164         }


< prev index next >