Assembler questions

Rémi Forax forax at univ-mlv.fr
Mon Apr 16 04:53:11 PDT 2012


On 04/16/2012 12:31 PM, Krystal Mok wrote:
> Hi Remi,
>
> Apparently the original code was trying to do something like:
>
> if (obj.getClass() == A.class) {
>   A a = (A) obj;
>   // ...
> }
>
> Right?

yes.
In fact, it's the equivalent code done using method handles.

>
> If the condition was
>
> if (obj instanceof A)
>
> then the checkcast would have been elided.

yes, you're right. I've just tested :)

>
> Maybe this kind of code pattern should be recognized by C2 in a future 
> enhancement?

Yes, I think it should.
>
> Regards,
> Kris

regards,
Rémi

>
> On Mon, Apr 16, 2012 at 5:59 PM, Rémi Forax <forax at univ-mlv.fr 
> <mailto:forax at univ-mlv.fr>> wrote:
>
>     Hi guys,
>     I'm trying to read some assembler dump printed by hsdis.
>
>     In the snippet below, I don't understand why there is a %r12 in
>     the middle of the mov.
>     Is some intermediary result stored in %r12 ?
>     Is it equivalent to
>      move 0x8(%r11), %r12
>      move 0x78(%r12), %rbp ?
>
>     Another question more related to the layout of the class in hotspot.
>     It seems there are two kinds of class pointer, the one with the
>     type java/lang/Class
>     and another one used by checkcast (oop('A')).
>     I suppose it's the same object at two different offsets perhaps
>     the Java one and the C++ one
>     but  I don't understand why they both exist in the generated code.
>
>     And the last question is why the checkcast is not removed because
>     the test getClass() == A.class is just above.
>     Is the VM also lost with the double representation of a class ?
>
>     regards,
>     Rémi
>
>     0x00007f67a46e326c: mov    0x8(%rsi),%r11d    ; implicit
>     exception: dispatches to 0x00007f67a46e32ea
>      ;; B2: #    B7 B3 <- B1  Freq: 0.999999
>
>      0x00007f67a46e3270: mov    0x78(%r12,%r11,8),%rbp
>      ;*invokevirtual getClass
>                                                    ; -
>     RT::classCheck at 1 (line 102)
>                                                    ; -
>     java.lang.invoke.MethodHandle::invokeExact at 3
>                                                    ; -
>     java.lang.invoke.MethodHandle::invokeExact at 3
>                                                    ; - IndyTest::test at 1
>      0x00007f67a46e3275: mov    $0x7d6bb4228,%r10  ;   {oop(a
>     'java/lang/Class' = 'A')}
>      0x00007f67a46e327f: cmp    %r10,%rbp
>      0x00007f67a46e3282: jne    0x00007f67a46e32c9  ;*if_acmpne
>                                                    ; -
>     RT::classCheck at 5 (line 102)
>                                                    ; -
>     java.lang.invoke.MethodHandle::invokeExact at 3
>                                                    ; -
>     java.lang.invoke.MethodHandle::invokeExact at 3
>                                                    ; - IndyTest::test at 1
>      ;; B3: #    B6 B4 <- B2  Freq: 0.999999
>
>      0x00007f67a46e3284: mov    0x40(%r12,%r11,8),%r10
>      0x00007f67a46e3289: mov    $0x77f280d58,%r11  ;   {oop('A')}
>      0x00007f67a46e3293: cmp    %r11,%r10
>      0x00007f67a46e3296: jne    0x00007f67a46e32b4  ;*checkcast
>                                                    ; -
>     java.lang.invoke.MethodHandle::invokeExact at 1
>                                                    ; -
>     java.lang.invoke.MethodHandle::invokeExact at 21
>                                                    ; - IndyTest::test at 1
>
>



More information about the hotspot-compiler-dev mailing list