< prev index next >

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

Print this page




  26 
  27 /*
  28  * @test ValueTypeCreation
  29  * @summary Value Type creation test
  30  * @library /test/lib
  31  * @compile  -XDenableValueTypes ValueTypeCreation.java Point.java Long8Value.java Person.java
  32  * @run main/othervm -Xint -XX:+EnableValhalla runtime.valhalla.valuetypes.ValueTypeCreation
  33  * @run main/othervm -Xcomp -XX:+EnableValhalla runtime.valhalla.valuetypes.ValueTypeCreation
  34  */
  35 public class ValueTypeCreation {
  36     public static void main(String[] args) {
  37         ValueTypeCreation valueTypeCreation = new ValueTypeCreation();
  38         valueTypeCreation.run();
  39     }
  40 
  41     public void run() {
  42         testPoint();
  43         testLong8();
  44         // Embedded oops not yet supported
  45         //testPerson();

  46     }
  47 
  48     void testPoint() {
  49         Point p = Point.createPoint(1, 2);
  50         Asserts.assertEquals(p.x, 1, "invalid point x value");
  51         Asserts.assertEquals(p.y, 2, "invalid point y value");
  52         Point p2 = clonePoint(p);
  53         Asserts.assertEquals(p2.x, 1, "invalid point clone x value");
  54         Asserts.assertEquals(p2.y, 2, "invalid point clone y value");
  55     }
  56 
  57     static Point clonePoint(Point p) {
  58         Point q = p;
  59         return q;
  60     }
  61 
  62     void testLong8() {
  63         Long8Value long8Value = Long8Value.create(1, 2, 3, 4, 5, 6, 7, 8);
  64         Asserts.assertEquals(long8Value.getLongField1(), 1L, "Field 1 incorrect");
  65         Asserts.assertEquals(long8Value.getLongField8(), 8L, "Field 8 incorrect");
  66         Long8Value.check(long8Value, 1, 2, 3, 4, 5, 6, 7, 8);
  67     }
  68 
  69     void testPerson() {
  70         Person person = Person.create(1, "John", "Smith");
  71         Asserts.assertEquals(person.getId(), 1L, "Id field incorrect");
  72         Asserts.assertEquals(person.getFirstName(), "John", "First name incorrect");
  73         Asserts.assertEquals(person.getLastName(), "Smith", "Last name incorrect");




















  74     }
  75 }


  26 
  27 /*
  28  * @test ValueTypeCreation
  29  * @summary Value Type creation test
  30  * @library /test/lib
  31  * @compile  -XDenableValueTypes ValueTypeCreation.java Point.java Long8Value.java Person.java
  32  * @run main/othervm -Xint -XX:+EnableValhalla runtime.valhalla.valuetypes.ValueTypeCreation
  33  * @run main/othervm -Xcomp -XX:+EnableValhalla runtime.valhalla.valuetypes.ValueTypeCreation
  34  */
  35 public class ValueTypeCreation {
  36     public static void main(String[] args) {
  37         ValueTypeCreation valueTypeCreation = new ValueTypeCreation();
  38         valueTypeCreation.run();
  39     }
  40 
  41     public void run() {
  42         testPoint();
  43         testLong8();
  44         // Embedded oops not yet supported
  45         //testPerson();
  46         StaticSelf.test();
  47     }
  48 
  49     void testPoint() {
  50         Point p = Point.createPoint(1, 2);
  51         Asserts.assertEquals(p.x, 1, "invalid point x value");
  52         Asserts.assertEquals(p.y, 2, "invalid point y value");
  53         Point p2 = clonePoint(p);
  54         Asserts.assertEquals(p2.x, 1, "invalid point clone x value");
  55         Asserts.assertEquals(p2.y, 2, "invalid point clone y value");
  56     }
  57 
  58     static Point clonePoint(Point p) {
  59         Point q = p;
  60         return q;
  61     }
  62 
  63     void testLong8() {
  64         Long8Value long8Value = Long8Value.create(1, 2, 3, 4, 5, 6, 7, 8);
  65         Asserts.assertEquals(long8Value.getLongField1(), 1L, "Field 1 incorrect");
  66         Asserts.assertEquals(long8Value.getLongField8(), 8L, "Field 8 incorrect");
  67         Long8Value.check(long8Value, 1, 2, 3, 4, 5, 6, 7, 8);
  68     }
  69 
  70     void testPerson() {
  71         Person person = Person.create(1, "John", "Smith");
  72         Asserts.assertEquals(person.getId(), 1L, "Id field incorrect");
  73         Asserts.assertEquals(person.getFirstName(), "John", "First name incorrect");
  74         Asserts.assertEquals(person.getLastName(), "Smith", "Last name incorrect");
  75     }
  76 
  77     static final __ByValue class StaticSelf {
  78 
  79         static final StaticSelf DEFAULT = create(0);
  80         final int f1;
  81 
  82         private StaticSelf() { f1 = 0; }
  83         public String toString() { return "StaticSelf f1=" + f1; }
  84 
  85         __ValueFactory static StaticSelf create(int f1) {
  86             StaticSelf s = __MakeDefault StaticSelf();
  87             s.f1 = f1;
  88             return s;
  89         }
  90 
  91         public static void test() {
  92             String s = DEFAULT.toString();
  93         }
  94 
  95     }
  96 }
< prev index next >