I wrote a very stupid test class in Java:
public class Vector3 {
public double x,y,z ;
public Vector3(double x, double y, double z) {
this.x=x ; this.y=y ; this.z=z ;
}
public Vector3 subst(Vector3 v) {
return new Vector3(x-v.x,y-v.y,z-v.z) ;
}
}
Then I wanted to see the code generated by the Java Hotspot JIT (Client VM build 23.7-b01). I used the "-XX:+PrintAssembly" option and the hsdis-i386.dll from http://classparser.blogspot.dk/2010/03/hsdis-i386dll.html
Here is the interesting part of the generated code (I have skipped the initialization of the new object. EDIT: the code for the subst method). Obviously, ebx is the "this" pointer and edx is the pointer to the argument.
lds edi,(bad)
sti
adc BYTE PTR [ebx+8],al ;*getfield x
mov edx,DWORD PTR [esp+56]
lds edi,(bad) ; implicit exception: dispatches to 0x02611f2d
sti
adc BYTE PTR [edx+8],cl ;*getfield x
lds edi,(bad)
sti
adc BYTE PTR [ebx+16],dl ;*getfield y
lds edi,(bad)
sti
adc BYTE PTR [edx+16],bl ;*getfield y
lds edi,(bad)
sti
adc BYTE PTR [ebx+24],ah ;*getfield z
lds edi,(bad)
sti
adc BYTE PTR [edx+24],ch ;*getfield z
lds edi,(bad)
sti
pop esp
rol ebp,0xfb
adc DWORD PTR [eax+8],eax ;*putfield x
lds ebp,(bad)
jmp 0x02611f66
rol ebp,cl
sti
adc DWORD PTR [eax+16],edx ;*putfield y
lds ebx,(bad)
fistp DWORD PTR [ebp-59]
sti
adc DWORD PTR [eax+24],esp ;*putfield z
Honestly, I am not very familar with x86 assembly but does that code make sense to you? What are those strange instructions like "adc BYTE PTR [edx+8],cl" doing? I would have expected some FPU instructions.
Me again. I have built the hsdis-i386.dll using the latest binutils 2.23. It was easier than I expected thanks to the instructions in http://dropzone.nfshost.com/hsdis.htm (at least for the x86 version. The 64-bit version compiles but stops the JVM immediately without any error message)
The output now looks much better:
vmovsd xmm0,QWORD PTR [ebx+0x8] ;*getfield x
mov edx,DWORD PTR [esp+0x40]
vmovsd xmm1,QWORD PTR [edx+0x8] ;*getfield x
vmovsd xmm2,QWORD PTR [ebx+0x10] ;*getfield y
vmovsd xmm3,QWORD PTR [edx+0x10] ;*getfield y
vmovsd xmm4,QWORD PTR [ebx+0x18] ;*getfield z
vmovsd xmm5,QWORD PTR [edx+0x18] ;*getfield z
vsubsd xmm0,xmm0,xmm1
vmovsd QWORD PTR [eax+0x8],xmm0 ;*putfield x
vsubsd xmm2,xmm2,xmm3
vmovsd QWORD PTR [eax+0x10],xmm2 ;*putfield y
vsubsd xmm4,xmm4,xmm5
vmovsd QWORD PTR [eax+0x18],xmm4 ;*putfield z
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With