Tuesday, September 6, 2011

JDK 7 Print JIT'ed code

>> jdk1.7.0/bin/java -XX:+PrintCompilation -XX:+UnlockDiagnosticVMOptions -XX:+PrintAssembly t4 100000

Output:

Java HotSpot(TM) Client VM warning: PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output
32 1 java.lang.String::hashCode (67 bytes)
Loaded disassembler from hsdis-i386.dll

...
... String methods such as hashCode(), charAt() have been removed for clarity
...

Decoding compiled method 0x0290db08:
Code:
[Disassembling for mach='i386']
[Entry Point]
[Verified Entry Point]
[Constants]
# {method} 'theSum' '(I)I' in 't4'
# parm0: ecx = int
# [sp+0x20] (sp of caller)
0x0290dc00: mov %eax,0xffffd000(%esp)
0x0290dc07: push %ebp
0x0290dc08: sub $0x18,%esp ;*bipush
; - t4::theSum@0 (line 15)
0x0290dc0b: mov $0x0,%eax
0x0290dc10: mov $0x0,%esi
0x0290dc15: jmp 0x0290dc29 ;*iload
; - t4::theSum@11 (line 18)
0x0290dc1a: xchg %ax,%ax
0x0290dc1c: add $0xbb,%esi
0x0290dc22: inc %eax ; OopMap{off=35}
;*goto
; - t4::theSum@26 (line 18)
0x0290dc23: test %eax,0x1d0100 ;*goto
; - t4::theSum@26 (line 18)
; {poll}
0x0290dc29: cmp %ecx,%eax
0x0290dc2b: jl 0x0290dc1c ;*if_icmpge
; - t4::theSum@14 (line 18)
0x0290dc2d: mov %esi,%eax
0x0290dc2f: add $0x18,%esp
0x0290dc32: pop %ebp
0x0290dc33: test %eax,0x1d0100 ; {poll_return}
0x0290dc39: ret
0x0290dc3a: nop
0x0290dc3b: nop
0x0290dc3c: mov %fs:0x0,%esi
0x0290dc44: mov 0xfffffff4(%esi),%esi
0x0290dc47: mov 0x184(%esi),%eax
0x0290dc4d: movl $0x0,0x184(%esi)
0x0290dc57: movl $0x0,0x188(%esi)
0x0290dc61: add $0x18,%esp
0x0290dc64: pop %ebp
0x0290dc65: jmp 0x028dba40 ; {runtime_call}
0x0290dc6a: hlt
0x0290dc6b: hlt
0x0290dc6c: hlt
0x0290dc6d: hlt
0x0290dc6e: hlt
0x0290dc6f: hlt
[Exception Handler]
[Stub Code]
0x0290dc70: call 0x0290bb80 ; {no_reloc}
0x0290dc75: push $0x5c3ccd40 ; {external_word}
0x0290dc7a: call 0x0290dc7f
0x0290dc7f: pusha
0x0290dc80: call 0x5c2bf5f0 ; {runtime_call}
0x0290dc85: hlt
[Deopt Handler Code]
0x0290dc86: push $0x290dc86 ; {section_word}
0x0290dc8b: jmp 0x028cc930 ; {runtime_call}
1377 2 % t4::main @ 9 (26 bytes)
Decoding compiled method 0x0290dd48:
Code:
[Disassembling for mach='i386']
[Entry Point]
[Verified Entry Point]
[Constants]
# {method} 'main' '([Ljava/lang/String;)V' in 't4'
0x0290de50: mov %eax,0xffffd000(%esp)
0x0290de57: push %ebp
0x0290de58: sub $0x28,%esp ;*aload_0
; - t4::main@0 (line 5)
0x0290de5b: cmpl $0x0,0x8(%ecx) ; implicit exception: dispatches to 0x02
90dee9
0x0290de62: jbe 0x0290def3
0x0290de68: mov 0xc(%ecx),%ecx ;*aaload
; - t4::main@2 (line 5)
0x0290de6b: mov $0xa,%edx ;*invokestatic parseInt
; - java.lang.Integer::parseInt@3 (line
527)
; - t4::main@3 (line 5)
0x0290de70: nop
0x0290de71: nop
0x0290de72: nop
0x0290de73: call 0x028cd5c0 ; OopMap{off=40}
;*invokestatic parseInt
; - java.lang.Integer::parseInt@3 (line
527)
; - t4::main@3 (line 5)
; {static_call}
0x0290de78: mov $0x0,%esi
0x0290de7d: jmp 0x0290deac ;*iload_2
; - t4::main@9 (line 8)
0x0290de82: xchg %ax,%ax
0x0290de84: mov $0x0,%edi
0x0290de89: mov $0x0,%ebx
0x0290de8e: jmp 0x0290dea1 ;*iload
; - t4::theSum@11 (line 18)
; - t4::main@15 (line 9)
0x0290de93: nop
0x0290de94: add $0xbb,%ebx
0x0290de9a: inc %edi ; OopMap{off=75}
;*goto
; - t4::theSum@26 (line 18)
; - t4::main@15 (line 9)
0x0290de9b: test %eax,0x1d0100 ;*goto
; - t4::theSum@26 (line 18)
; - t4::main@15 (line 9)
; {poll}
0x0290dea1: cmp %eax,%edi
0x0290dea3: jl 0x0290de94 ;*if_icmpge
; - t4::theSum@14 (line 18)
; - t4::main@15 (line 9)
0x0290dea5: inc %esi ; OopMap{off=86}
;*goto
; - t4::main@22 (line 8)
0x0290dea6: test %eax,0x1d0100 ;*goto
; - t4::main@22 (line 8)
; {poll}
0x0290deac: cmp %eax,%esi
0x0290deae: jl 0x0290de84 ;*if_icmpge
; - t4::main@11 (line 8)
0x0290deb0: add $0x28,%esp
0x0290deb3: pop %ebp
0x0290deb4: test %eax,0x1d0100 ; {poll_return}
0x0290deba: ret ;*return
; - t4::main@25 (line 12)
0x0290debb: mov %eax,0xffffd000(%esp)
0x0290dec2: push %ebp
0x0290dec3: sub $0x28,%esp
0x0290dec6: mov 0x4(%ecx),%esi
0x0290dec9: mov (%ecx),%edi
0x0290decb: mov %ecx,(%esp)
0x0290dece: mov %esi,0x1c(%esp)
0x0290ded2: mov %edi,0x18(%esp)
0x0290ded6: call 0x5c19ad50 ; {runtime_call}
0x0290dedb: mov 0x18(%esp),%edi
0x0290dedf: mov %edi,%esi
0x0290dee1: mov 0x1c(%esp),%edi
0x0290dee5: mov %edi,%eax
0x0290dee7: jmp 0x0290deac
0x0290dee9: call 0x0290a850 ; OopMap{ecx=Oop off=158}
;*aaload
; - t4::main@2 (line 5)
; {runtime_call}
0x0290deee: call 0x0290a850 ; OopMap{ecx=Oop off=163}
;*aaload
; - t4::main@2 (line 5)
; {runtime_call}
0x0290def3: movl $0x0,(%esp)
0x0290defa: call 0x0290a550 ; OopMap{ecx=Oop off=175}
;*aaload
; - t4::main@2 (line 5)
; {runtime_call}
0x0290deff: nop
0x0290df00: nop
0x0290df01: mov %fs:0x0,%esi
0x0290df09: mov 0xfffffff4(%esi),%esi
0x0290df0c: mov 0x184(%esi),%eax
0x0290df12: movl $0x0,0x184(%esi)
0x0290df1c: movl $0x0,0x188(%esi)
0x0290df26: add $0x28,%esp
0x0290df29: pop %ebp
0x0290df2a: jmp 0x028dba40 ; {runtime_call}
0x0290df2f: hlt
[Stub Code]
0x0290df30: nop ; {no_reloc}
0x0290df31: nop
0x0290df32: mov $0x0,%ebx ; {static_stub}
0x0290df37: jmp 0x0290df37 ; {runtime_call}
[Exception Handler]
0x0290df3c: call 0x0290bb80 ; {runtime_call}
0x0290df41: push $0x5c3ccd40 ; {external_word}
0x0290df46: call 0x0290df4b
0x0290df4b: pusha
0x0290df4c: call 0x5c2bf5f0 ; {runtime_call}
0x0290df51: hlt
[Deopt Handler Code]
0x0290df52: push $0x290df52 ; {section_word}
0x0290df57: jmp 0x028cc930 ; {runtime_call}

t4.java

public class t4 {

public static void main(String[] args) {

int count = Integer.parseInt(args[0]);
for(int i=0; i theSum(count);
}
}

public static int theSum(int count) {
int A = 88;
int B = 99;
int sum = 0;
for (int i = 0; i < count; i++)
sum += A + B;

return sum;
}
}

No comments:

Post a Comment