Value Types - static fields are not assgined in value's constructors
Tobias Hartmann
tobias.hartmann at oracle.com
Mon Mar 6 11:46:04 UTC 2017
Hi Fabien,
On 06.03.2017 12:18, GIACHERIO Fabien wrote:
> Hi everyone,
>
> I'm trying to execute some tests of the ValueTypeTestBench.java and i've
> noticed that the static field 's' of MyValue1 is never affected to the
> value of the integer x.
>
> The static method called in order to create the value is
> createDontInline(int, long).
>
> It seems that we can set a static field using a VALUE_FACTORY method, but
> we can not assign it in a constructor.
>
> Is it a normal behavior ?
Yes, that's normal. The constructor is not executed but the value type is directly created by vnew like this:
public static compiler.valhalla.valuetypes.MyValue1 createDontInline(int, long);
Code:
0: iload_0
1: lload_1
2: iload_0
3: iconst_1
4: invokestatic #39 // Method compiler/valhalla/valuetypes/MyValue2.createInline:(IZ)Qcompiler/valhalla/valuetypes/MyValue2;
7: iload_0
8: iconst_0
9: invokestatic #39 // Method compiler/valhalla/valuetypes/MyValue2.createInline:(IZ)Qcompiler/valhalla/valuetypes/MyValue2;
12: getstatic #44 // Field compiler/valhalla/valuetypes/ValueTypeTestBench.rI:I
15: vnew #48 // Method "<vminit>":(IJQcompiler/valhalla/valuetypes/MyValue2;Qcompiler/valhalla/valuetypes/MyValue2;I)Qcompiler/valhalla/valuetypes/MyValue1;
18: vreturn
Best regards,
Tobias
>
> ____________________________________________
>
> __ByValue final class MyValue1 {
> static int s;
> static final long sf = ValueTypeTestBench.rL;
> final int x;
> final long y;
> final MyValue2 v1;
> final MyValue2 v2;
> static final MyValue2 v3 =
> MyValue2.createInline(ValueTypeTestBench.rI, true);
> final int c;
>
> private MyValue1(int x, long y, MyValue2 v1, MyValue2 v2, int c) {
> s = x;
> this.x = x;
> this.y = y;
> this.v1 = v1;
> this.v2 = v2;
> this.c = c;
> }
>
> public static MyValue1 createDontInline(int x, long y) {
> return __Make MyValue1(x, y, MyValue2.createInline(x, true),
> MyValue2.createInline(x, false), ValueTypeTestBench.rI);
> }
>
>
> Best regards,
> Fabien GIACHERIO
>
More information about the valhalla-dev
mailing list