src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/GraalOSRLockTest.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/GraalOSRLockTest.java

Print this page




  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package org.graalvm.compiler.hotspot.test;
  24 
  25 import java.lang.management.ManagementFactory;
  26 import java.lang.management.MonitorInfo;
  27 import java.lang.management.ThreadInfo;
  28 import java.lang.management.ThreadMXBean;
  29 import java.util.Collection;
  30 import java.util.HashMap;
  31 import java.util.HashSet;
  32 
  33 import org.graalvm.compiler.api.directives.GraalDirectives;
  34 import org.graalvm.compiler.core.phases.HighTier;
  35 import org.graalvm.compiler.debug.DebugEnvironment;
  36 import org.graalvm.compiler.debug.GraalError;
  37 import org.graalvm.compiler.debug.TTY;
  38 import org.graalvm.compiler.hotspot.phases.OnStackReplacementPhase;
  39 import org.graalvm.compiler.options.OptionKey;
  40 import org.graalvm.compiler.options.OptionValues;
  41 import org.graalvm.util.EconomicMap;
  42 import org.junit.Assert;
  43 import org.junit.BeforeClass;
  44 import org.junit.Test;
  45 
  46 import jdk.vm.ci.meta.ResolvedJavaMethod;
  47 
  48 /**
  49  * Test on-stack-replacement with locks.
  50  */
  51 public class GraalOSRLockTest extends GraalOSRTestBase {
  52 
  53     private static boolean TestInSeparateThread = false;
  54 
  55     // testing only
  56     public static boolean isMonitorLockHeld(Object o) {
  57         return isMonitorLockHeldByThread(o, null);
  58     }
  59 
  60     public static boolean isMonitorLockHeldByThread(Object o, Thread t) {
  61         int oihc = System.identityHashCode(o);
  62         ThreadMXBean tmxbean = ManagementFactory.getThreadMXBean();
  63         ThreadInfo[] tinfos = tmxbean.dumpAllThreads(true, false);


 132             Assert.fail("Object " + msg + " was locked");
 133         }
 134     }
 135 
 136     private static void beforeOSRLockTest() {
 137         // try lock both objects
 138         lockOnObject(lock, "lock");
 139         lockOnObject(lock1, "lock1");
 140         Assert.assertFalse(wasLocked());
 141     }
 142 
 143     private static void afterOSRLockTest() {
 144         // try lock both objects
 145         lockOnObject(lock, "lock");
 146         lockOnObject(lock1, "lock1");
 147         Assert.assertFalse(wasLocked());
 148         // force a safepoint and hope the inflated locks are deflated
 149         System.gc();
 150     }
 151 
 152     @BeforeClass
 153     public static void init() {
 154         DebugEnvironment.ensureInitialized(getInitialOptions());
 155     }
 156 
 157     // @Test
 158     @SuppressWarnings("try")
 159     public void testLockOSROuterImmediateDeoptAfter() {
 160         run(() -> {
 161             OptionValues options = new OptionValues(getInitialOptions(), osrLockDeopt());
 162             testOSR(options, "testOuterLockImmediateDeoptAfter");
 163         });
 164     }
 165 
 166     static class A {
 167 
 168     }
 169 
 170     static class B {
 171         @SuppressWarnings("unused")
 172         B(A a) {
 173 
 174         }
 175     }
 176 


 296     public void testLockOSROuterInnerSameLockCompileRestOfMethod() {
 297         run(() -> {
 298             OptionValues options = new OptionValues(getInitialOptions(), osrLockNoDeopt());
 299             testOSR(options, "testOuterInnerSameLockCompileRestOfMethod");
 300         });
 301     }
 302 
 303     @Test
 304     @SuppressWarnings("try")
 305     public void testLockOSRRecursive() {
 306         run(() -> {
 307             // call it
 308             testRecursiveLockingLeaf();
 309             ResolvedJavaMethod leaf = getResolvedJavaMethod("testRecursiveLockingLeaf");
 310             // profile it
 311             leaf.reprofile();
 312             testRecursiveLockingLeaf();
 313             EconomicMap<OptionKey<?>, Object> overrides = osrLockNoDeopt();
 314             overrides.put(HighTier.Options.Inline, false);
 315             OptionValues options = new OptionValues(getInitialOptions(), overrides);
 316             compile(options, leaf, -1);

 317             testOSR(options, "testRecursiveLockingRoot");
 318         });
 319     }
 320 
 321     @Test
 322     @SuppressWarnings("try")
 323     public void testLockOSRRecursiveLeafOSR() {
 324         run(() -> {
 325             testRecursiveRootNoOSR();
 326             ResolvedJavaMethod root = getResolvedJavaMethod("testRecursiveRootNoOSR");
 327             EconomicMap<OptionKey<?>, Object> overrides = osrLockNoDeopt();
 328             overrides.put(HighTier.Options.Inline, false);
 329             OptionValues options = new OptionValues(getInitialOptions(), overrides);
 330             compile(options, root, -1);

 331             testOSR(options, "testRecursiveLeafOSR");
 332             // force a safepoint and hope the inflated locks are deflated
 333             System.gc();
 334             // call the root to call into the leaf and enter the osr-ed code
 335             testRecursiveRootNoOSR();
 336 
 337         });
 338     }
 339 
 340     protected static int limit = 10000;
 341     protected static Object lock = new Object();
 342     protected static Object lock1 = new Object();
 343     private static final boolean LOG = false;
 344 
 345     static {
 346         // force identity hash code for easy displaced mark identification
 347         int h1 = System.identityHashCode(lock);
 348         int h2 = System.identityHashCode(lock1);
 349         if (LOG) {
 350             TTY.println("Forcing a system identity hashcode on lock object " + h1);




  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package org.graalvm.compiler.hotspot.test;
  24 
  25 import java.lang.management.ManagementFactory;
  26 import java.lang.management.MonitorInfo;
  27 import java.lang.management.ThreadInfo;
  28 import java.lang.management.ThreadMXBean;
  29 import java.util.Collection;
  30 import java.util.HashMap;
  31 import java.util.HashSet;
  32 
  33 import org.graalvm.compiler.api.directives.GraalDirectives;
  34 import org.graalvm.compiler.core.phases.HighTier;
  35 import org.graalvm.compiler.debug.DebugContext;
  36 import org.graalvm.compiler.debug.GraalError;
  37 import org.graalvm.compiler.debug.TTY;
  38 import org.graalvm.compiler.hotspot.phases.OnStackReplacementPhase;
  39 import org.graalvm.compiler.options.OptionKey;
  40 import org.graalvm.compiler.options.OptionValues;
  41 import org.graalvm.util.EconomicMap;
  42 import org.junit.Assert;

  43 import org.junit.Test;
  44 
  45 import jdk.vm.ci.meta.ResolvedJavaMethod;
  46 
  47 /**
  48  * Test on-stack-replacement with locks.
  49  */
  50 public class GraalOSRLockTest extends GraalOSRTestBase {
  51 
  52     private static boolean TestInSeparateThread = false;
  53 
  54     // testing only
  55     public static boolean isMonitorLockHeld(Object o) {
  56         return isMonitorLockHeldByThread(o, null);
  57     }
  58 
  59     public static boolean isMonitorLockHeldByThread(Object o, Thread t) {
  60         int oihc = System.identityHashCode(o);
  61         ThreadMXBean tmxbean = ManagementFactory.getThreadMXBean();
  62         ThreadInfo[] tinfos = tmxbean.dumpAllThreads(true, false);


 131             Assert.fail("Object " + msg + " was locked");
 132         }
 133     }
 134 
 135     private static void beforeOSRLockTest() {
 136         // try lock both objects
 137         lockOnObject(lock, "lock");
 138         lockOnObject(lock1, "lock1");
 139         Assert.assertFalse(wasLocked());
 140     }
 141 
 142     private static void afterOSRLockTest() {
 143         // try lock both objects
 144         lockOnObject(lock, "lock");
 145         lockOnObject(lock1, "lock1");
 146         Assert.assertFalse(wasLocked());
 147         // force a safepoint and hope the inflated locks are deflated
 148         System.gc();
 149     }
 150 





 151     // @Test
 152     @SuppressWarnings("try")
 153     public void testLockOSROuterImmediateDeoptAfter() {
 154         run(() -> {
 155             OptionValues options = new OptionValues(getInitialOptions(), osrLockDeopt());
 156             testOSR(options, "testOuterLockImmediateDeoptAfter");
 157         });
 158     }
 159 
 160     static class A {
 161 
 162     }
 163 
 164     static class B {
 165         @SuppressWarnings("unused")
 166         B(A a) {
 167 
 168         }
 169     }
 170 


 290     public void testLockOSROuterInnerSameLockCompileRestOfMethod() {
 291         run(() -> {
 292             OptionValues options = new OptionValues(getInitialOptions(), osrLockNoDeopt());
 293             testOSR(options, "testOuterInnerSameLockCompileRestOfMethod");
 294         });
 295     }
 296 
 297     @Test
 298     @SuppressWarnings("try")
 299     public void testLockOSRRecursive() {
 300         run(() -> {
 301             // call it
 302             testRecursiveLockingLeaf();
 303             ResolvedJavaMethod leaf = getResolvedJavaMethod("testRecursiveLockingLeaf");
 304             // profile it
 305             leaf.reprofile();
 306             testRecursiveLockingLeaf();
 307             EconomicMap<OptionKey<?>, Object> overrides = osrLockNoDeopt();
 308             overrides.put(HighTier.Options.Inline, false);
 309             OptionValues options = new OptionValues(getInitialOptions(), overrides);
 310             DebugContext debug = getDebugContext(options);
 311             compile(debug, leaf, -1);
 312             testOSR(options, "testRecursiveLockingRoot");
 313         });
 314     }
 315 
 316     @Test
 317     @SuppressWarnings("try")
 318     public void testLockOSRRecursiveLeafOSR() {
 319         run(() -> {
 320             testRecursiveRootNoOSR();
 321             ResolvedJavaMethod root = getResolvedJavaMethod("testRecursiveRootNoOSR");
 322             EconomicMap<OptionKey<?>, Object> overrides = osrLockNoDeopt();
 323             overrides.put(HighTier.Options.Inline, false);
 324             OptionValues options = new OptionValues(getInitialOptions(), overrides);
 325             DebugContext debug = getDebugContext(options);
 326             compile(debug, root, -1);
 327             testOSR(options, "testRecursiveLeafOSR");
 328             // force a safepoint and hope the inflated locks are deflated
 329             System.gc();
 330             // call the root to call into the leaf and enter the osr-ed code
 331             testRecursiveRootNoOSR();
 332 
 333         });
 334     }
 335 
 336     protected static int limit = 10000;
 337     protected static Object lock = new Object();
 338     protected static Object lock1 = new Object();
 339     private static final boolean LOG = false;
 340 
 341     static {
 342         // force identity hash code for easy displaced mark identification
 343         int h1 = System.identityHashCode(lock);
 344         int h2 = System.identityHashCode(lock1);
 345         if (LOG) {
 346             TTY.println("Forcing a system identity hashcode on lock object " + h1);


src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/GraalOSRLockTest.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File