stampa Codice assembly Java hotspot JIT


Ho scritto una classe di test molto stupida 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) ;
   }
}

Quindi volevo vedere il codice generato dall'Hotspot Java JIT (VM Client build 23.7-b01). Ho usato l'opzione "- XX: + PrintAssembly " e hsdis-i386.dll da http://classparser.blogspot.dk/2010/03/hsdis-i386dll.html

Ecco la parte interessante del codice generato (ho saltato l'inizializzazione del nuovo oggetto. MODIFICA: il codice per il metodo subst). Ovviamente, ebx è il puntatore "this" e edx è il puntatore all'argomento.

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

Onestamente, non sono molto familiare con l'assembly x86 ma quel codice ha senso per te? Cosa fanno quelle strane istruzioni come "adc BYTE PTR [edx + 8], cl"? Mi sarei aspettato alcune istruzioni FPU.

Author: trunklop, 2013-03-11

1 answers

Di nuovo io. Ho costruito il hsdis-i386.dll utilizzando l'ultima binutils 2.23. È stato più facile di quanto mi aspettassi grazie alle istruzioni in http://dropzone.nfshost.com/hsdis.htm (almeno per la versione x86. La versione a 64 bit compila ma interrompe immediatamente la JVM senza alcun messaggio di errore)

L'output ora sembra molto meglio:

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
 6
Author: trunklop, 2013-03-12 09:12:38