< prev index next >

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

Print this page

        

*** 17,28 **** } public void run() { testPoint(); testLong8(); ! // Embedded oops not yet supported ! //testPerson(); } void testPoint() { Point p = Point.createPoint(1, 2); Asserts.assertEquals(p.x, 1, "invalid point x value"); --- 17,28 ---- } public void run() { testPoint(); testLong8(); ! testPerson(); ! testComposite(); } void testPoint() { Point p = Point.createPoint(1, 2); Asserts.assertEquals(p.x, 1, "invalid point x value");
*** 44,53 **** Long8Value.check(long8Value, 1, 2, 3, 4, 5, 6, 7, 8); } void testPerson() { Person person = Person.create(1, "John", "Smith"); ! Asserts.assertEquals(person.getId(), 1L, "Id field incorrect"); Asserts.assertEquals(person.getFirstName(), "John", "First name incorrect"); Asserts.assertEquals(person.getLastName(), "Smith", "Last name incorrect"); } } --- 44,152 ---- Long8Value.check(long8Value, 1, 2, 3, 4, 5, 6, 7, 8); } void testPerson() { Person person = Person.create(1, "John", "Smith"); ! Asserts.assertEquals(person.getId(), 1, "Id field incorrect"); Asserts.assertEquals(person.getFirstName(), "John", "First name incorrect"); Asserts.assertEquals(person.getLastName(), "Smith", "Last name incorrect"); } + + void testComposite() { + short a = 3; + int b = 7; + SmallEmbed se = SmallEmbed.create((byte) 3, (byte) 7); + Long8Value long8Value = Long8Value.create(4711, 13, 3147, 11, 3, 1, 0, 8); + Person person = Person.create(11, "Jane", "Wayne"); + Composition comp = Composition.create(a, se, long8Value, person); + Composition.check(comp, a, se, long8Value, person); + ValueHolder holder = ValueHolder.create(a, b, se, comp); + ValueHolder.check(holder, a, b, se, comp); + } + + static final __ByValue class SmallEmbed { + final byte a; + final byte b; + + private SmallEmbed() { + a = (byte)0; + b = (byte)0; + } + + __ValueFactory static SmallEmbed create(byte a, byte b) { + SmallEmbed se = __MakeDefault SmallEmbed(); + se.a = a; + se.b = b; + return se; + } + + static void check(SmallEmbed value, byte a, byte b) { + Asserts.assertEquals(value.a, a, "Field a incorrect"); + Asserts.assertEquals(value.b, b, "Field a incorrect"); + } + } + + static final __ByValue class Composition { + final short a; + final SmallEmbed se; + final Long8Value long8Value; + final Person person; + + private Composition() { + a = (short) 0; + se = SmallEmbed.create((byte)0, (byte)0); + long8Value = Long8Value.create(0, 0, 0, 0, 0, 0, 0, 0); + person = Person.create(0, null, null); + } + + __ValueFactory static Composition create(short a, SmallEmbed se, Long8Value long8Value, Person person) { + Composition composition = __MakeDefault Composition(); + composition.a = a; + composition.se = se; + composition.long8Value = long8Value; + composition.person = person; + return composition; + } + + static void check(Composition value, short a, SmallEmbed se, Long8Value long8Value, Person person) { + Asserts.assertEquals(value.a, a, "Field a incorrect"); + SmallEmbed.check(value.se, se.a, se.b); + Long8Value.check(value.long8Value, + long8Value.longField1, + long8Value.longField2, + long8Value.longField3, + long8Value.longField4, + long8Value.longField5, + long8Value.longField6, + long8Value.longField7, + long8Value.longField8); + Asserts.assertEquals(value.person.id, person.id, "Person.id"); + Asserts.assertEquals(value.person.firstName, person.firstName, "Person.firstName"); + Asserts.assertEquals(value.person.lastName, person.lastName, "Person.lastName"); + } + } + + static class ValueHolder { + short a; + int b; + SmallEmbed small; + Composition comp; + + ValueHolder(short a, int b, SmallEmbed small, Composition comp) { + this.a = a; + this.b = b; + this.small = small; + this.comp = comp; + } + + static ValueHolder create(short a, int b, SmallEmbed small, Composition comp) { + return new ValueHolder(a, b, small, comp); + } + + static void check(ValueHolder holder, short a, int b, SmallEmbed small, Composition comp) { + Asserts.assertEquals(holder.a, a, "Field a incorrect"); + Asserts.assertEquals(holder.b, b, "Field b incorrect"); + SmallEmbed.check(holder.small, small.a, small.b); + Composition.check(holder.comp, comp.a, comp.se, comp.long8Value, comp.person); + } + } }
< prev index next >