Skip to content

Z: Value types: Nested field class for aconst_init is not patched correctly in non-SVM AOT compilation #15424

Description

@a7ehuo

Value type bytecode aconst_init is represented as newvalue jitNewValue in ILGen and later lowered as new in CG. If a field of VT is also a VT, we will generate newvalue jitNewValue for the field instance as well.

I'm testing enabling AOT compilation for aconst_init, using the following test code, I noticed the field class SingleFieldPrimitive for NestedFieldsPrimitive is not patched correctly on AOT load on Z.

primitive public class NestedFieldsPrimitive {
    public final SingleFieldPrimitive f1;

    public NestedFieldsPrimitive() {
        this.f1 = new SingleFieldPrimitive();
    }

    public NestedFieldsPrimitive(int val) {
        this.f1 = new SingleFieldPrimitive(val);
    }
}
public class TestAOTAConstInit2 {

   public static NestedFieldsPrimitive _nfp;

   public static void test() {
      _nfp = NestedFieldsPrimitive.default; // aconst_init

   public static void main(String[] args) {
      test();
      test();
   }
}
n7n       treetop                                                                             [     0x3ff88201770] bci=[-1,0,-] rc=0 vc=0 vn=- li=- udi=- nc=1
n6n         newvalue  jitNewValue[#101  helper Method] [flags 0x400 0x0 ] (Identityless sharedMemory )  [     0x3ff88201720] bci=[-1,0,-] rc=2 vc=0 vn=- li=- udi=- nc=2 flg=0x2000
n4n           loadaddr  SingleFieldPrimitive[#383  Static] [flags 0x18307 0x0 ]               [     0x3ff88201680] bci=[-1,0,-] rc=1 vc=0 vn=- li=- udi=- nc=0
n5n           iconst 0                                                                        [     0x3ff882016d0] bci=[-1,0,-] rc=1 vc=0 vn=- li=- udi=- nc=0
n9n       treetop                                                                             [     0x3ff88201810] bci=[-1,0,-] rc=0 vc=0 vn=- li=- udi=- nc=1
n8n         newvalue  jitNewValue[#101  helper Method] [flags 0x400 0x0 ] (Identityless sharedMemory )  [     0x3ff882017c0] bci=[-1,0,-] rc=2 vc=0 vn=- li=- udi=- nc=2 flg=0x2000
n3n           loadaddr  NestedFieldsPrimitive[#382  Static] [flags 0x18307 0x0 ]              [     0x3ff88201630] bci=[-1,0,-] rc=1 vc=0 vn=- li=- udi=- nc=0
n6n           ==>newvalue

In AOT compilation, I'm guessing 0x3ff882e0ec0 loads class SingleFieldPrimitive. On AOT load, it's incorrectly patched as TestAOTAConstInit2.

---- AOT Compilation ----

------------------------------
 n7n      (  0)  treetop                                                                              [     0x3ff88201770] bci=[-1,0,-] rc=0 vc=80 vn=- li=2 udi=- nc=1
 n6n      (  3)    new  jitNewValue[#101  helper Method] [flags 0x400 0x0 ] (in &GPR_0034) (highWordZero Unsigned X!=0 skipZeroInit allocationCanBeRemoved sharedMemory )  [     0x3ff88201720] bci=[-1,0,-] rc=3 vc=80 vn=- li=2 udi=- nc=1 flg=0xc004
 n4n      (  0)      loadaddr  SingleFieldPrimitive[#383  Static] [flags 0x18307 0x0 ] (in GPR_0032)  [     0x3ff88201680] bci=[-1,0,-] rc=0 vc=80 vn=- li=2 udi=- nc=0
------------------------------

 [     0x3ff882e0ec0]	                       LGRL    GPR_0032, 0x000003FF882E0D30	
 [     0x3ff882e1190]	                       LGFI    GPR_0033,16	
 [     0x3ff882e1360]	                       AG      GPR_0033,#389 96(GPR13)
 [     0x3ff882e14f0]	                       CLG     GPR_0033,#390 104(GPR13)
 [     0x3ff882ef7a0]	                       Label L0022:	# (Start of internal control flow)	
 [     0x3ff882e15c0]	                       BRC     BL(0x2), Outlined Label L0016	
 [     0x3ff882e1760]	                       LG      &GPR_0034,#391 96(GPR13)
 [     0x3ff882e18f0]	                       STG     GPR_0033,#392 96(GPR13)
 [     0x3ff882ef5e0]	                       ST      GPR_0032,#393 0(&GPR_0034)


     0x3ff6af0009c 0000001c [     0x3ff882e0670] 17 00                                             XR      GPR0,GPR0	
     0x3ff6af0009e 0000001e [     0x3ff882e0ec0] c4 08 00 00 00 a1                                 LGRL    GPR0, 0x000003FF882E0D30, targetAddr=0x000003FF6AF001E0 (offset=0x0000000000000142)	
     0x3ff6af000a4 00000024 [     0x3ff882e1190] c0 11 00 00 00 10                                 LGFI    GPR1,16	
     0x3ff6af000aa 0000002a [     0x3ff882e1360] e3 10 d0 60 00 08                                 AG      GPR1,#389 96(GPR13)
     0x3ff6af000b0 00000030 [     0x3ff882e14f0] e3 10 d0 68 00 21                                 CLG     GPR1,#390 104(GPR13)

---- AOT Load ----

0x3ffdde7f09c {TestAOTAConstInit2.test} +28                       1700         xr        %r0, %r0
0x3ffdde7f09e {TestAOTAConstInit2.test} +30                       c408000000a1 lgrl      %r0, 0x3ffdde7f1e0 J9Class - {TestAOTAConstInit2} //<---- wrong class!! It should be SingleFieldPrimitive
0x3ffdde7f0a4 {TestAOTAConstInit2.test} +36                       c01100000010 lgfi      %r1, 0x10 
0x3ffdde7f0aa {TestAOTAConstInit2.test} +42                       e310d0600008 ag        %r1, 0x60(%r13)  J9VMThread.heapAlloc
0x3ffdde7f0b0 {TestAOTAConstInit2.test} +48                       e310d0680021 clg       %r1, 0x68(%r13)  J9VMThread.heapTop


(kca) what (0x3ffdde7f1e0)
0x3ffdde7f1e0: 0x0000000000240a00 J9Class - {TestAOTAConstInit2}

0623_NestedFieldsPrimitive_AOT.zip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions