< prev index next >

hotspot/test/runtime/valhalla/valuetypes/ValueTypeCreation.java

Print this page




   2 
   3 import jdk.test.lib.Asserts;
   4 
   5 /*
   6  * @test ValueTypeCreation
   7  * @summary Value Type creation test
   8  * @library /test/lib
   9  * @compile  -XDenableValueTypes ValueTypeCreation.java Point.java Long8Value.java Person.java
  10  * @run main/othervm -noverify -Xint -XX:+EnableValhalla runtime.valhalla.valuetypes.ValueTypeCreation
  11  * @run main/othervm -noverify -Xcomp -XX:+EnableValhalla runtime.valhalla.valuetypes.ValueTypeCreation
  12  */
  13 public class ValueTypeCreation {
  14     public static void main(String[] args) {
  15         ValueTypeCreation valueTypeCreation = new ValueTypeCreation();
  16         valueTypeCreation.run();
  17     }
  18 
  19     public void run() {
  20         testPoint();
  21         testLong8();
  22         // Embedded oops not yet supported
  23         //testPerson();
  24     }
  25 
  26     void testPoint() {
  27         Point p = Point.createPoint(1, 2);
  28         Asserts.assertEquals(p.x, 1, "invalid point x value");
  29         Asserts.assertEquals(p.y, 2, "invalid point y value");
  30         Point p2 = clonePoint(p);
  31         Asserts.assertEquals(p2.x, 1, "invalid point clone x value");
  32         Asserts.assertEquals(p2.y, 2, "invalid point clone y value");
  33     }
  34 
  35     static Point clonePoint(Point p) {
  36         Point q = p;
  37         return q;
  38     }
  39 
  40     void testLong8() {
  41         Long8Value long8Value = Long8Value.create(1, 2, 3, 4, 5, 6, 7, 8);
  42         Asserts.assertEquals(long8Value.getLongField1(), 1L, "Field 1 incorrect");
  43         Asserts.assertEquals(long8Value.getLongField8(), 8L, "Field 8 incorrect");
  44         Long8Value.check(long8Value, 1, 2, 3, 4, 5, 6, 7, 8);
  45     }
  46 
  47     void testPerson() {
  48         Person person = Person.create(1, "John", "Smith");
  49         Asserts.assertEquals(person.getId(), 1L, "Id field incorrect");
  50         Asserts.assertEquals(person.getFirstName(), "John", "First name incorrect");
  51         Asserts.assertEquals(person.getLastName(), "Smith", "Last name incorrect");



































































































  52     }
  53 }


   2 
   3 import jdk.test.lib.Asserts;
   4 
   5 /*
   6  * @test ValueTypeCreation
   7  * @summary Value Type creation test
   8  * @library /test/lib
   9  * @compile  -XDenableValueTypes ValueTypeCreation.java Point.java Long8Value.java Person.java
  10  * @run main/othervm -noverify -Xint -XX:+EnableValhalla runtime.valhalla.valuetypes.ValueTypeCreation
  11  * @run main/othervm -noverify -Xcomp -XX:+EnableValhalla runtime.valhalla.valuetypes.ValueTypeCreation
  12  */
  13 public class ValueTypeCreation {
  14     public static void main(String[] args) {
  15         ValueTypeCreation valueTypeCreation = new ValueTypeCreation();
  16         valueTypeCreation.run();
  17     }
  18 
  19     public void run() {
  20         testPoint();
  21         testLong8();
  22         testPerson();
  23         testComposite();
  24     }
  25 
  26     void testPoint() {
  27         Point p = Point.createPoint(1, 2);
  28         Asserts.assertEquals(p.x, 1, "invalid point x value");
  29         Asserts.assertEquals(p.y, 2, "invalid point y value");
  30         Point p2 = clonePoint(p);
  31         Asserts.assertEquals(p2.x, 1, "invalid point clone x value");
  32         Asserts.assertEquals(p2.y, 2, "invalid point clone y value");
  33     }
  34 
  35     static Point clonePoint(Point p) {
  36         Point q = p;
  37         return q;
  38     }
  39 
  40     void testLong8() {
  41         Long8Value long8Value = Long8Value.create(1, 2, 3, 4, 5, 6, 7, 8);
  42         Asserts.assertEquals(long8Value.getLongField1(), 1L, "Field 1 incorrect");
  43         Asserts.assertEquals(long8Value.getLongField8(), 8L, "Field 8 incorrect");
  44         Long8Value.check(long8Value, 1, 2, 3, 4, 5, 6, 7, 8);
  45     }
  46 
  47     void testPerson() {
  48         Person person = Person.create(1, "John", "Smith");
  49         Asserts.assertEquals(person.getId(), 1, "Id field incorrect");
  50         Asserts.assertEquals(person.getFirstName(), "John", "First name incorrect");
  51         Asserts.assertEquals(person.getLastName(), "Smith", "Last name incorrect");
  52     }
  53 
  54     void testComposite() {
  55         short a = 3;
  56         int   b = 7;
  57         SmallEmbed se = SmallEmbed.create((byte) 3, (byte) 7);
  58         Long8Value long8Value = Long8Value.create(4711, 13, 3147, 11, 3, 1, 0, 8);
  59         Person person = Person.create(11, "Jane", "Wayne");
  60         Composition comp = Composition.create(a, se, long8Value, person);
  61         Composition.check(comp, a, se, long8Value, person);
  62         ValueHolder holder = ValueHolder.create(a, b, se, comp);
  63         ValueHolder.check(holder, a, b, se, comp);
  64     }
  65 
  66     static final __ByValue class SmallEmbed {
  67         final byte a;
  68         final byte b;
  69 
  70         private SmallEmbed() {
  71             a = (byte)0;
  72             b = (byte)0;
  73         }
  74 
  75         __ValueFactory static SmallEmbed create(byte a, byte b) {
  76             SmallEmbed se = __MakeDefault SmallEmbed();
  77             se.a = a;
  78             se.b = b;
  79             return se;
  80         }
  81 
  82         static void check(SmallEmbed value, byte a, byte b) {
  83             Asserts.assertEquals(value.a, a, "Field a incorrect");
  84             Asserts.assertEquals(value.b, b, "Field a incorrect");
  85         }
  86     }
  87 
  88     static final __ByValue class Composition {
  89         final short      a;
  90         final SmallEmbed se;
  91         final Long8Value long8Value;
  92         final Person     person;
  93 
  94         private Composition() {
  95             a          = (short) 0;
  96             se         = SmallEmbed.create((byte)0, (byte)0);
  97             long8Value = Long8Value.create(0, 0, 0, 0, 0, 0, 0, 0);
  98             person     = Person.create(0, null, null);
  99         }
 100 
 101         __ValueFactory static Composition create(short a, SmallEmbed se, Long8Value long8Value, Person person) {
 102             Composition composition = __MakeDefault Composition();
 103             composition.a          = a;
 104             composition.se         = se;
 105             composition.long8Value = long8Value;
 106             composition.person     = person;
 107             return composition;
 108         }
 109 
 110         static void check(Composition value, short a, SmallEmbed se, Long8Value long8Value, Person person) {
 111             Asserts.assertEquals(value.a, a, "Field a incorrect");
 112             SmallEmbed.check(value.se, se.a, se.b);
 113             Long8Value.check(value.long8Value,
 114                              long8Value.longField1,
 115                              long8Value.longField2,
 116                              long8Value.longField3,
 117                              long8Value.longField4,
 118                              long8Value.longField5,
 119                              long8Value.longField6,
 120                              long8Value.longField7,
 121                              long8Value.longField8);
 122             Asserts.assertEquals(value.person.id, person.id, "Person.id");
 123             Asserts.assertEquals(value.person.firstName, person.firstName, "Person.firstName");
 124             Asserts.assertEquals(value.person.lastName, person.lastName, "Person.lastName");
 125         }
 126     }
 127 
 128     static class ValueHolder {
 129         short       a;
 130         int         b;
 131         SmallEmbed  small;
 132         Composition comp;
 133 
 134         ValueHolder(short a, int b, SmallEmbed small, Composition comp) {
 135             this.a = a;
 136             this.b = b;
 137             this.small = small;
 138             this.comp  = comp;
 139         }
 140 
 141         static ValueHolder create(short a, int b, SmallEmbed small, Composition comp) {
 142             return new ValueHolder(a, b, small, comp);
 143         }
 144 
 145         static void check(ValueHolder holder, short a, int b, SmallEmbed small, Composition comp) {
 146             Asserts.assertEquals(holder.a, a, "Field a incorrect");
 147             Asserts.assertEquals(holder.b, b, "Field b incorrect");
 148             SmallEmbed.check(holder.small, small.a, small.b);
 149             Composition.check(holder.comp, comp.a, comp.se, comp.long8Value, comp.person);
 150         }
 151     }
 152 }
< prev index next >