Wednesday, September 21, 2011

Adding Indonesian Locale to Java web-app

Due to this bug
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6457127

you must have resources_in.properties
(not resources_id.properties) for the translation to work.

Indonesian code is in_ID and due to the bug above
"The indonesian locale gets parsed from both the identifiers "id" and "in". ISO 639 specifies only "id" as correct. When you ask the locale customer for its representation, it returns "in", which is not correct."

Wednesday, September 7, 2011

When will Java JIT start compiling into native code ?

With this following code, and

java version "1.7.0"
Java(TM) SE Runtime Environment (build 1.7.0-b147)
Java HotSpot(TM) Client VM (build 21.0-b17, mixed mode, sharing)

The main method will be compiled into native code when count is greater or equal to 170,000 (more or less, i didn't try to get a more accurate result)

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

public class t5 {

public static void main(String[] args) {

int count = 170000;
int sum = 3;
int A = 4;
int B = 5;
for(int i=0; i sum += A + B;
}
}
}


Native code printed:

Code:
[Disassembling for mach='i386']
[Entry Point]
[Verified Entry Point]
[Constants]
# {method} 'main' '([Ljava/lang/String;)V' in 't5'
0x02ccd480: mov %eax,0xffffd000(%esp)
0x02ccd487: push %ebp
0x02ccd488: sub $0x28,%esp ;*ldc ; - t5::main@0 (line 6)
0x02ccd48b: mov $0x0,%esi
0x02ccd490: mov $0x5,%edi
0x02ccd495: mov $0x4,%ebx
0x02ccd49a: mov $0x3,%eax
0x02ccd49f: mov $0x29810,%edx
0x02ccd4a4: jmp 0x02ccd4bb ;*iload
; - t5::main@13 (line 10)
0x02ccd4a9: xchg %ax,%ax
0x02ccd4ac: mov %ebx,%ecx
0x02ccd4ae: add %edi,%ecx
0x02ccd4b0: add %eax,%ecx
0x02ccd4b2: inc %esi ; OopMap{off=51}
;*goto
; - t5::main@29 (line 10)
0x02ccd4b3: test %eax,0x1c0100 ; {poll}
0x02ccd4b9: mov %ecx,%eax ;*goto
; - t5::main@29 (line 10)
0x02ccd4bb: cmp %edx,%esi
0x02ccd4bd: jl 0x02ccd4ac ;*if_icmpge
; - t5::main@16 (line 10)
0x02ccd4bf: add $0x28,%esp
0x02ccd4c2: pop %ebp
0x02ccd4c3: test %eax,0x1c0100 ; {poll_return}
0x02ccd4c9: ret ;*return
; - t5::main@32 (line 16)
0x02ccd4ca: mov %eax,0xffffd000(%esp)
0x02ccd4d1: push %ebp
0x02ccd4d2: sub $0x28,%esp
0x02ccd4d5: mov 0x10(%ecx),%esi
0x02ccd4d8: mov 0xc(%ecx),%edi
0x02ccd4db: mov 0x8(%ecx),%ebx
0x02ccd4de: mov 0x4(%ecx),%eax
0x02ccd4e1: mov (%ecx),%edx
0x02ccd4e3: mov %ecx,(%esp)
0x02ccd4e6: mov %esi,0x20(%esp)
0x02ccd4ea: mov %edi,0x1c(%esp)
0x02ccd4ee: mov %ebx,0x18(%esp)
0x02ccd4f2: mov %eax,0x14(%esp)
0x02ccd4f6: mov %edx,0x10(%esp)
0x02ccd4fa: call 0x636aad50 ; {runtime_call}
0x02ccd4ff: mov 0x10(%esp),%edx
0x02ccd503: mov %edx,%esi
0x02ccd505: mov 0x14(%esp),%eax
0x02ccd509: mov %eax,%edi
0x02ccd50b: mov 0x18(%esp),%ebx
0x02ccd50f: mov 0x1c(%esp),%eax
0x02ccd513: mov 0x20(%esp),%edx
0x02ccd517: jmp 0x02ccd4bb
0x02ccd519: nop
0x02ccd51a: nop
0x02ccd51b: mov %fs:0x0,%esi
0x02ccd523: mov 0xfffffff4(%esi),%esi
0x02ccd526: mov 0x184(%esi),%eax
0x02ccd52c: movl $0x0,0x184(%esi)
0x02ccd536: movl $0x0,0x188(%esi)
0x02ccd540: add $0x28,%esp
0x02ccd543: pop %ebp
0x02ccd544: jmp 0x02c9ba40 ; {runtime_call}
0x02ccd549: hlt
0x02ccd54a: hlt
0x02ccd54b: hlt
0x02ccd54c: hlt
0x02ccd54d: hlt
0x02ccd54e: hlt
0x02ccd54f: hlt
[Exception Handler]
[Stub Code]
0x02ccd550: call 0x02ccbb80 ; {no_reloc}
0x02ccd555: push $0x638dcd40 ; {external_word}
0x02ccd55a: call 0x02ccd55f
0x02ccd55f: pusha
0x02ccd560: call 0x637cf5f0 ; {runtime_call}
0x02ccd565: hlt
[Deopt Handler Code]
0x02ccd566: push $0x2ccd566 ; {section_word}
0x02ccd56b: jmp 0x02c8c930 ; {runtime_call}

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;
}
}