method with parameter requiring null check and class cast check

Deneau, Tom tom.deneau at amd.com
Fri Jan 3 12:18:02 PST 2014


Yes sorry, the question was are the 2nd and 3rd null checks really necessary.

Yes there was no profiling, just a bare compile.
I compiled this using the BasicTest.java framework that I think Doug sent a while ago

which derives from com.oracle.graal.compiler.test.GraalCompilerTest

in BasicTest we have

    private void test(String snippet) {
        StructuredGraph graph = parse(snippet);
        InstalledCode code = getCode(graph.method(), graph);
        Debug.dump(graph, "Graph");

        DisassemblerProvider dis = Graal.getRuntime().getCapability(DisassemblerProvider.class);
        if (dis != null) {
            String disasm = dis.disassemble(code);
            TTY.println("code generated for " + snippet + "\n" + disasm);
        }
    }

-- Tom

> -----Original Message-----
> From: Christian Thalinger [mailto:christian.thalinger at oracle.com]
> Sent: Friday, January 03, 2014 2:00 PM
> To: Deneau, Tom
> Cc: graal-dev at openjdk.java.net
> Subject: Re: method with parameter requiring null check and class cast
> check
> 
> 
> On Jan 2, 2014, at 10:11 AM, Deneau, Tom <tom.deneau at amd.com> wrote:
> 
> > I ran the following code thru the AMD64 backend with -G:-
> OptImplicitNullChecks.
> > So this should generate both a null check and a class cast check on
> the input parameter.
> >
> > Below I show the code I got.  See my questions inline below...
> 
> What are the actual questions?  Why there are these additional null
> checks?
> 
> One thing I find odd is that the path on which the cast succeeds is out-
> of-line and not a fall-through.  How did you compile this method?  Was
> there some profiling going on before?
> 
> >
> > -- Tom
> >
> >
> >    static class Vec3 {
> >
> >        public Vec3(float x, float y, float z) {
> >            this.x = x;
> >            this.y = y;
> >            this.z = z;
> >        }
> >
> >        public float x;
> >        public float y;
> >        public float z;
> >    }
> >
> >    static class MyVec3 extends Vec3 {
> >        public MyVec3(float x, float y, float z) {
> >            super(x, y, z);
> >        }
> >    }
> >
> >
> >    public void runvec3(Vec3 vec3) {
> >        MyVec3 myvec3 = (MyVec3) vec3;
> >        myvec3.z = myvec3.x + myvec3.y;
> >    }
> >
> >
> >
> >
> > ========================================
> > [Verified Entry Point]
> >  0x00007fc7fc5c8880: mov    qword ptr [rsp-0x14000],rax
> >  0x00007fc7fc5c8888: sub    rsp,0x18
> >  0x00007fc7fc5c888c: mov    qword ptr [rsp+0x10],rbp  ; OopMap{rdx=Oop
> off=49}
> >                                                ;*aload_1
> >                                                ; -
> > com.oracle.graal.compiler.test.BasicTest2::runvec3 at 0 (line 67)
> >
> >  0x00007fc7fc5c8891: test   dword ptr [rdx],eax
> >  0x00007fc7fc5c8893: cmp    rdx,0x0
> >  0x00007fc7fc5c8897: je     0x00007fc7fc5c88fa         ;; if null take
> path as if class cast did not match...
> >
> >  ;; odd to have both an implicit and explicit null check here but I
> > think that's related to the GuardLoweringPhase  ;; thing I mentioned
> > in an earlier email.  If I fix that issue in GuardLoweringPhase, the
> test instruction  ;; becomes an explicit null check which goes to a null
> check deopt.
> >  ;; But in either case the second null check seems unnecessary.
> >
> >  0x00007fc7fc5c889d: mov    eax,dword ptr [rdx+0x8]     ;; checking
> the class of the parameter
> >  0x00007fc7fc5c88a0: shl    rax,0x3
> >  0x00007fc7fc5c88a4: movabs rbx,0x100109c28
> >  0x00007fc7fc5c88ae: cmp    rbx,rax
> >  0x00007fc7fc5c88b1: je     0x00007fc7fc5c88f3
> >  0x00007fc7fc5c88b7: mov    eax,0x0                     ;; eax == 0
> means class cast problem, not exact match
> >
> >  0x00007fc7fc5c88bc: cmp    rdx,0x0                     ;; this third
> null check seems unnecessary.
> >  0x00007fc7fc5c88c0: je     0x00007fc7fc5c88cf
> >  0x00007fc7fc5c88c6: cmp    eax,0x1                     ;; compare
> whether class cast worked
> >  0x00007fc7fc5c88c9: jne    0x00007fc7fc5c8901          ;; if not go
> to class cast deopt
> >  0x00007fc7fc5c88cf: movss  xmm0,dword ptr [rdx+0xc]    ;; class cast
> ok, do the real work
> >  0x00007fc7fc5c88d4: movss  xmm1,dword ptr [rdx+0x10]
> >  0x00007fc7fc5c88d9: addss  xmm1,xmm0
> >  0x00007fc7fc5c88dd: movss  dword ptr [rdx+0x14],xmm1
> >  0x00007fc7fc5c88e2: mov    rbp,qword ptr [rsp+0x10]
> >  0x00007fc7fc5c88e7: add    rsp,0x18
> >  0x00007fc7fc5c88eb: mov    rbx,qword ptr [rip+0x1b37e715]        #
> 0x00007fc817947007
> >                                                ;   {poll_return}
> >  0x00007fc7fc5c88f2: ret
> >  0x00007fc7fc5c88f3: mov    eax,0x1                     ;; eax == 1
> means class cast worked, not exact match
> >  0x00007fc7fc5c88f8: jmp    0x00007fc7fc5c88bc
> >  0x00007fc7fc5c88fa: mov    eax,0x0
> >  0x00007fc7fc5c88ff: jmp    0x00007fc7fc5c88bc
> >  0x00007fc7fc5c8901: mov    dword ptr [r15+0x8],0xffffffdd
> ;; class cast deopt
> >  0x00007fc7fc5c8909: call   0x00007fc7fc046bf3  ; OopMap{rdx=Oop
> off=174}
> >                                                ;*aload_1
> >                                                ; -
> com.oracle.graal.compiler.test.BasicTest2::runvec3 at 0 (line 67)
> >                                                ;   {runtime_call}
> >  0x00007fc7fc5c890e: nop
> > [Exception Handler]
> >  0x00007fc7fc5c890f: call   0x00007fc7fc5c8520  ;   {runtime_call}
> >  0x00007fc7fc5c8914: nop
> > [Deopt Handler Code]
> >  0x00007fc7fc5c8915: call   0x00007fc7fc046b00  ;   {runtime_call}
> >  0x00007fc7fc5c891a: nop
> > [Stub Code]
> >  0x00007fc7fc5c891b: hlt
> >  0x00007fc7fc5c891c: hlt
> >  0x00007fc7fc5c891d: hlt
> >  0x00007fc7fc5c891e: hlt
> >  0x00007fc7fc5c891f: hlt
> >
> >
> >
> >
> >
> 




More information about the graal-dev mailing list