src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/HotSpotMonitorValueTest.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/HotSpotMonitorValueTest.java

Print this page




  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 static org.hamcrest.CoreMatchers.not;
  26 import static org.junit.Assert.assertNotNull;
  27 import static org.junit.Assert.assertNull;
  28 import static org.junit.Assert.assertThat;
  29 
  30 import java.util.Arrays;
  31 import java.util.List;
  32 
  33 import org.junit.Test;
  34 
  35 import org.graalvm.compiler.code.CompilationResult;
  36 import org.graalvm.compiler.core.test.GraalCompilerTest;

  37 import org.graalvm.compiler.debug.GraalError;
  38 
  39 import jdk.vm.ci.code.BytecodeFrame;
  40 import jdk.vm.ci.code.InstalledCode;
  41 import jdk.vm.ci.code.StackLockValue;
  42 import jdk.vm.ci.code.site.Call;
  43 import jdk.vm.ci.code.site.Infopoint;
  44 import jdk.vm.ci.meta.ResolvedJavaMethod;
  45 
  46 public class HotSpotMonitorValueTest extends GraalCompilerTest {
  47 
  48     @Override
  49     protected InstalledCode addMethod(ResolvedJavaMethod method, CompilationResult compResult) {
  50         for (Infopoint i : compResult.getInfopoints()) {
  51             if (i instanceof Call) {
  52                 Call call = (Call) i;
  53                 if (call.target instanceof ResolvedJavaMethod) {
  54                     ResolvedJavaMethod target = (ResolvedJavaMethod) call.target;
  55                     if (target.equals(lookupObjectWait())) {
  56                         BytecodeFrame frame = call.debugInfo.frame();
  57                         BytecodeFrame caller = frame.caller();
  58                         assertNotNull(caller);
  59                         assertNull(caller.caller());
  60                         assertDeepEquals(2, frame.numLocks);
  61                         assertDeepEquals(2, caller.numLocks);
  62                         StackLockValue lock1 = (StackLockValue) frame.getLockValue(0);
  63                         StackLockValue lock2 = (StackLockValue) frame.getLockValue(1);
  64                         StackLockValue lock3 = (StackLockValue) caller.getLockValue(0);
  65                         StackLockValue lock4 = (StackLockValue) caller.getLockValue(1);
  66 
  67                         List<StackLockValue> locks = Arrays.asList(lock1, lock2, lock3, lock4);
  68                         for (StackLockValue lock : locks) {
  69                             for (StackLockValue other : locks) {
  70                                 if (other != lock) {
  71                                     // Every lock must have a different stack slot
  72                                     assertThat(lock.getSlot(), not(other.getSlot()));
  73                                 }
  74                             }
  75                         }
  76                         assertDeepEquals(lock3.getOwner(), lock4.getOwner());
  77                         assertThat(lock1.getOwner(), not(lock2.getOwner()));
  78                         return super.addMethod(method, compResult);
  79                     }
  80                 }
  81             }
  82         }
  83         throw new AssertionError("Could not find debug info for call to Object.wait(long)");
  84     }
  85 
  86     private ResolvedJavaMethod lookupObjectWait() {
  87         try {
  88             return getMetaAccess().lookupJavaMethod(Object.class.getDeclaredMethod("wait", long.class));
  89         } catch (Exception e) {
  90             throw new GraalError("Could not find Object.wait(long): %s", e);
  91         }
  92     }
  93 
  94     @Test
  95     public void test() {
  96         test("testSnippet", "a", "b");
  97     }
  98 


  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 static org.hamcrest.CoreMatchers.not;
  26 import static org.junit.Assert.assertNotNull;
  27 import static org.junit.Assert.assertNull;
  28 import static org.junit.Assert.assertThat;
  29 
  30 import java.util.Arrays;
  31 import java.util.List;
  32 
  33 import org.junit.Test;
  34 
  35 import org.graalvm.compiler.code.CompilationResult;
  36 import org.graalvm.compiler.core.test.GraalCompilerTest;
  37 import org.graalvm.compiler.debug.DebugContext;
  38 import org.graalvm.compiler.debug.GraalError;
  39 
  40 import jdk.vm.ci.code.BytecodeFrame;
  41 import jdk.vm.ci.code.InstalledCode;
  42 import jdk.vm.ci.code.StackLockValue;
  43 import jdk.vm.ci.code.site.Call;
  44 import jdk.vm.ci.code.site.Infopoint;
  45 import jdk.vm.ci.meta.ResolvedJavaMethod;
  46 
  47 public class HotSpotMonitorValueTest extends GraalCompilerTest {
  48 
  49     @Override
  50     protected InstalledCode addMethod(DebugContext debug, ResolvedJavaMethod method, CompilationResult compResult) {
  51         for (Infopoint i : compResult.getInfopoints()) {
  52             if (i instanceof Call) {
  53                 Call call = (Call) i;
  54                 if (call.target instanceof ResolvedJavaMethod) {
  55                     ResolvedJavaMethod target = (ResolvedJavaMethod) call.target;
  56                     if (target.equals(lookupObjectWait())) {
  57                         BytecodeFrame frame = call.debugInfo.frame();
  58                         BytecodeFrame caller = frame.caller();
  59                         assertNotNull(caller);
  60                         assertNull(caller.caller());
  61                         assertDeepEquals(2, frame.numLocks);
  62                         assertDeepEquals(2, caller.numLocks);
  63                         StackLockValue lock1 = (StackLockValue) frame.getLockValue(0);
  64                         StackLockValue lock2 = (StackLockValue) frame.getLockValue(1);
  65                         StackLockValue lock3 = (StackLockValue) caller.getLockValue(0);
  66                         StackLockValue lock4 = (StackLockValue) caller.getLockValue(1);
  67 
  68                         List<StackLockValue> locks = Arrays.asList(lock1, lock2, lock3, lock4);
  69                         for (StackLockValue lock : locks) {
  70                             for (StackLockValue other : locks) {
  71                                 if (other != lock) {
  72                                     // Every lock must have a different stack slot
  73                                     assertThat(lock.getSlot(), not(other.getSlot()));
  74                                 }
  75                             }
  76                         }
  77                         assertDeepEquals(lock3.getOwner(), lock4.getOwner());
  78                         assertThat(lock1.getOwner(), not(lock2.getOwner()));
  79                         return super.addMethod(debug, method, compResult);
  80                     }
  81                 }
  82             }
  83         }
  84         throw new AssertionError("Could not find debug info for call to Object.wait(long)");
  85     }
  86 
  87     private ResolvedJavaMethod lookupObjectWait() {
  88         try {
  89             return getMetaAccess().lookupJavaMethod(Object.class.getDeclaredMethod("wait", long.class));
  90         } catch (Exception e) {
  91             throw new GraalError("Could not find Object.wait(long): %s", e);
  92         }
  93     }
  94 
  95     @Test
  96     public void test() {
  97         test("testSnippet", "a", "b");
  98     }
  99 
src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/HotSpotMonitorValueTest.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File