< prev index next >

test/hotspot/jtreg/compiler/valhalla/valuetypes/TestUnloadedValueTypeArray.java

Print this page


  14  *
  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 
  24 /**
  25  * @test
  26  * @bug 8182997 8214898
  27  * @library /test/lib
  28  * @summary Test the handling of Arrays of unloaded value classes.
  29  * @compile -XDemitQtypes -XDenableValueTypes -XDallowFlattenabilityModifiers -XDallowWithFieldOperator TestUnloadedValueTypeArray.java
  30  * @run main/othervm -XX:+EnableValhalla -Xcomp
  31  *        -XX:CompileCommand=compileonly,TestUnloadedValueTypeArray::test1
  32  *        -XX:CompileCommand=compileonly,TestUnloadedValueTypeArray::test2
  33  *        -XX:CompileCommand=compileonly,TestUnloadedValueTypeArray::test3

  34  *      TestUnloadedValueTypeArray
  35  */
  36 
  37 import jdk.test.lib.Asserts;
  38 
  39 value final class MyValue {
  40     final int foo;
  41 
  42     private MyValue() {
  43         foo = 0x42;
  44     }
  45 }
  46 
  47 value final class MyValue2 {
  48     final int foo;
  49 
  50     private MyValue2() {
  51         foo = 0x42;
  52     }
  53     static MyValue2 make(int n) {
  54         return __WithField(MyValue2.default.foo, n);
  55     }
  56 }
  57 
  58 value final class MyValue3 {
  59     final int foo;
  60 
  61     private MyValue3() {
  62         foo = 0x42;
  63     }
  64     static MyValue3 make(int n) {
  65         return __WithField(MyValue3.default.foo, n);
  66     }
  67 }
  68 


  69 







  70 
  71 public class TestUnloadedValueTypeArray {
  72 
  73     static MyValue[] target() {
  74         return new MyValue[10];
  75     }
  76 
  77     static void test1() {
  78         target();
  79     }
  80 
  81     static int test2(MyValue2[] arr) {
  82         if (arr != null) {
  83             return arr[1].foo;
  84         } else {
  85             return 1234;
  86         }
  87     }
  88 
  89     static void test2_verifier() {


 107     static void test3(MyValue3[] arr) {
 108         if (arr != null) {
 109             arr[1] = MyValue3.make(2345);
 110         }
 111     }
 112 
 113     static void test3_verifier() {
 114         int n = 50000;
 115 
 116         for (int i=0; i<n; i++) {
 117             test3(null);
 118         }
 119 
 120         MyValue3[] arr = new MyValue3[2];
 121         for (int i=0; i<n; i++) {
 122             test3(arr);
 123         }
 124         Asserts.assertEQ(arr[1].foo, 2345);
 125     }
 126 

























 127     static public void main(String[] args) {
 128         test1();
 129         test2_verifier();
 130         test3_verifier();

 131     }
 132 }


  14  *
  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 
  24 /**
  25  * @test
  26  * @bug 8182997 8214898
  27  * @library /test/lib
  28  * @summary Test the handling of Arrays of unloaded value classes.
  29  * @compile -XDemitQtypes -XDenableValueTypes -XDallowFlattenabilityModifiers -XDallowWithFieldOperator TestUnloadedValueTypeArray.java
  30  * @run main/othervm -XX:+EnableValhalla -Xcomp
  31  *        -XX:CompileCommand=compileonly,TestUnloadedValueTypeArray::test1
  32  *        -XX:CompileCommand=compileonly,TestUnloadedValueTypeArray::test2
  33  *        -XX:CompileCommand=compileonly,TestUnloadedValueTypeArray::test3
  34  *        -XX:CompileCommand=compileonly,TestUnloadedValueTypeArray::test4
  35  *      TestUnloadedValueTypeArray
  36  */
  37 
  38 import jdk.test.lib.Asserts;
  39 
  40 value final class MyValue {
  41     final int foo;
  42 
  43     private MyValue() {
  44         foo = 0x42;
  45     }
  46 }
  47 
  48 value final class MyValue2 {
  49     final int foo;
  50 
  51     private MyValue2() {
  52         foo = 0x42;
  53     }
  54     static MyValue2 make(int n) {
  55         return __WithField(MyValue2.default.foo, n);
  56     }
  57 }
  58 
  59 value final class MyValue3 {
  60     final int foo;
  61 
  62     private MyValue3() {
  63         foo = 0x42;
  64     }
  65     static MyValue3 make(int n) {
  66         return __WithField(MyValue3.default.foo, n);
  67     }
  68 }
  69 
  70 value final class MyValue4 {
  71     final int foo;
  72 
  73     private MyValue4() {
  74         foo = 0x53;
  75     }
  76     static MyValue4 make(int n) {
  77         return __WithField(MyValue4.default.foo, n);
  78     }
  79 }
  80 
  81 public class TestUnloadedValueTypeArray {
  82 
  83     static MyValue[] target() {
  84         return new MyValue[10];
  85     }
  86 
  87     static void test1() {
  88         target();
  89     }
  90 
  91     static int test2(MyValue2[] arr) {
  92         if (arr != null) {
  93             return arr[1].foo;
  94         } else {
  95             return 1234;
  96         }
  97     }
  98 
  99     static void test2_verifier() {


 117     static void test3(MyValue3[] arr) {
 118         if (arr != null) {
 119             arr[1] = MyValue3.make(2345);
 120         }
 121     }
 122 
 123     static void test3_verifier() {
 124         int n = 50000;
 125 
 126         for (int i=0; i<n; i++) {
 127             test3(null);
 128         }
 129 
 130         MyValue3[] arr = new MyValue3[2];
 131         for (int i=0; i<n; i++) {
 132             test3(arr);
 133         }
 134         Asserts.assertEQ(arr[1].foo, 2345);
 135     }
 136 
 137     static MyValue4[] test4(boolean b) {
 138         // range check elimination
 139         if (b) {
 140             MyValue4[] arr = new MyValue4[10];
 141             arr[1] = MyValue4.make(2345);
 142             return arr;
 143         } else {
 144             return null;
 145         }
 146     }
 147 
 148     static void test4_verifier() {
 149         int n = 50000;
 150 
 151         for (int i=0; i<n; i++) {
 152             test4(false);
 153         }
 154 
 155         MyValue4[] arr = null;
 156         for (int i=0; i<n; i++) {
 157           arr = test4(true);
 158         }
 159         Asserts.assertEQ(arr[1].foo, 2345);
 160     }
 161 
 162     static public void main(String[] args) {
 163         test1();
 164         test2_verifier();
 165         test3_verifier();
 166         test4_verifier();
 167     }
 168 }
< prev index next >