< prev index next >

test/hotspot/jtreg/runtime/valhalla/valuetypes/ObjectMethods.java

Print this page




  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 runtime.valhalla.valuetypes;
  24 
  25 import java.lang.invoke.*;
  26 
  27 import jdk.experimental.value.MethodHandleBuilder;
  28 
  29 /*
  30  * @test ObjectMethods
  31  * @summary Check object method implemented by the VM behave with value types
  32  * @modules java.base/jdk.experimental.bytecode
  33  *          java.base/jdk.experimental.value
  34  * @library /test/lib
  35  * @compile -XDenableValueTypes ObjectMethods.java
  36  * @run main/othervm -Xint -XX:+EnableValhalla -XX:+UseBiasedLocking -XX:+UseCompressedClassPointers runtime.valhalla.valuetypes.ObjectMethods
  37  * @run main/othervm -Xint -XX:+EnableValhalla -XX:-UseBiasedLocking -XX:-UseCompressedClassPointers runtime.valhalla.valuetypes.ObjectMethods
  38  * @run main/othervm -Xint -XX:+EnableValhalla -noverify runtime.valhalla.valuetypes.ObjectMethods noverify



  39  */
  40 
  41 public class ObjectMethods {
  42 
  43     public static void main(String[] args) {
  44         testObjectMethods((args.length > 0 && args[0].equals("noverify")));
  45     }
  46 
  47     public static void testObjectMethods(boolean verifierDisabled) {
  48         MyInt val = MyInt.create(7);
  49         MyInt sameVal = MyInt.create(7);
  50 
  51         // Exercise all the Object native/VM methods...
  52 
  53         if (verifierDisabled) { // Just noverifier...
  54             checkMonitorExit(val);
  55             return;
  56         }
  57 
  58         // getClass()


 121         // jni monitor ops tested by "ValueWithJni"
 122     }
 123 
 124     // Check we haven't broken the mismatched monitor block check...
 125     static void checkMonitorExit(Object val) {
 126         boolean sawImse = false;
 127         try {
 128             MethodHandleBuilder.loadCode(MethodHandles.lookup(),
 129                                          "mismatchedMonitorExit",
 130                                          MethodType.methodType(Void.TYPE, Object.class),
 131                                          CODE->{
 132                                              CODE
 133                                                  .aload(0)
 134                                                  .monitorexit()
 135                                                  .return_();
 136                                          }).invokeExact(val);
 137             throw new IllegalStateException("Unreachable code, reached");
 138         } catch (Throwable t) {
 139             if (t instanceof IllegalMonitorStateException) {
 140                 sawImse = true;
 141             }
 142             else {
 143                 throw new RuntimeException(t);
 144             }
 145         }
 146         if (!sawImse) {
 147             throw new RuntimeException("monitorexit did not fail");
 148         }
 149     }
 150 
 151     static void checkWait(Object val) {
 152         boolean sawImse = false;
 153         try {
 154             val.wait();
 155         } catch (IllegalMonitorStateException imse) {
 156             sawImse = true;
 157         } catch (InterruptedException intExc) {
 158             throw new RuntimeException(intExc);
 159         }
 160         if (!sawImse) {
 161             throw new RuntimeException("wait() did not fail");
 162         }




  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 runtime.valhalla.valuetypes;
  24 
  25 import java.lang.invoke.*;
  26 
  27 import jdk.experimental.value.MethodHandleBuilder;
  28 
  29 /*
  30  * @test ObjectMethods
  31  * @summary Check object method implemented by the VM behave with value types
  32  * @modules java.base/jdk.experimental.bytecode
  33  *          java.base/jdk.experimental.value
  34  * @library /test/lib
  35  * @compile -XDenableValueTypes ObjectMethods.java
  36  * @run main/othervm -Xint -XX:+EnableValhalla -XX:+UseBiasedLocking -XX:+UseCompressedClassPointers runtime.valhalla.valuetypes.ObjectMethods
  37  * @run main/othervm -Xint -XX:+EnableValhalla -XX:-UseBiasedLocking -XX:-UseCompressedClassPointers runtime.valhalla.valuetypes.ObjectMethods
  38  * @run main/othervm -Xint -XX:+EnableValhalla -noverify runtime.valhalla.valuetypes.ObjectMethods noverify
  39  * @run main/othervm -Xcomp -XX:+EnableValhalla -XX:+UseBiasedLocking -XX:+UseCompressedClassPointers runtime.valhalla.valuetypes.ObjectMethods
  40  * @run main/othervm -Xcomp -XX:+EnableValhalla -XX:-UseBiasedLocking -XX:-UseCompressedClassPointers runtime.valhalla.valuetypes.ObjectMethods
  41  * @run main/othervm -Xcomp -XX:+EnableValhalla -noverify runtime.valhalla.valuetypes.ObjectMethods noverify
  42  */
  43 
  44 public class ObjectMethods {
  45 
  46     public static void main(String[] args) {
  47         testObjectMethods((args.length > 0 && args[0].equals("noverify")));
  48     }
  49 
  50     public static void testObjectMethods(boolean verifierDisabled) {
  51         MyInt val = MyInt.create(7);
  52         MyInt sameVal = MyInt.create(7);
  53 
  54         // Exercise all the Object native/VM methods...
  55 
  56         if (verifierDisabled) { // Just noverifier...
  57             checkMonitorExit(val);
  58             return;
  59         }
  60 
  61         // getClass()


 124         // jni monitor ops tested by "ValueWithJni"
 125     }
 126 
 127     // Check we haven't broken the mismatched monitor block check...
 128     static void checkMonitorExit(Object val) {
 129         boolean sawImse = false;
 130         try {
 131             MethodHandleBuilder.loadCode(MethodHandles.lookup(),
 132                                          "mismatchedMonitorExit",
 133                                          MethodType.methodType(Void.TYPE, Object.class),
 134                                          CODE->{
 135                                              CODE
 136                                                  .aload(0)
 137                                                  .monitorexit()
 138                                                  .return_();
 139                                          }).invokeExact(val);
 140             throw new IllegalStateException("Unreachable code, reached");
 141         } catch (Throwable t) {
 142             if (t instanceof IllegalMonitorStateException) {
 143                 sawImse = true;
 144             } else {

 145                 throw new RuntimeException(t);
 146             }
 147         }
 148         if (!sawImse) {
 149             throw new RuntimeException("monitorexit did not fail");
 150         }
 151     }
 152 
 153     static void checkWait(Object val) {
 154         boolean sawImse = false;
 155         try {
 156             val.wait();
 157         } catch (IllegalMonitorStateException imse) {
 158             sawImse = true;
 159         } catch (InterruptedException intExc) {
 160             throw new RuntimeException(intExc);
 161         }
 162         if (!sawImse) {
 163             throw new RuntimeException("wait() did not fail");
 164         }


< prev index next >