C2 optimization bug ?
Ulf Zibis
Ulf.Zibis at gmx.de
Fri Mar 19 11:21:32 PDT 2010
Below you see 2 code snippets, im exactly doing the same if boolean
validateNonSurrogates is set to false by constant value.
In the 1. example, I'm wondering, why register values are copied around
and from/to the stack on each loop:
0x00b88930: mov %ebx,0x4(%esp)
0x00b88934: mov %eax,0x34(%esp) ;*aload_0
...
0x00b88940: mov %ecx,%eax
...
0x00b88952: mov $0x2,%ecx
0x00b88957: mov 0x34(%esp),%eax ;*invokestatic charCount
; -
java.lang.Character::charCount at 26 (line 2946)
0x00b8895b: add %ecx,%esi ;*iadd
...
Even in the 2nd example it is not comprehensible, why the base address
of int[] codePoints is repetitively loaded from the stack on each loop:
0x00b84e0e: mov 0x4(%esp),%edi
========================== Example 1:
n += Character.charCount(codePoints, 0, codePoints.length,
false);
public static int charCount(int codePoint, boolean
validateNonSurrogates) {
if (isBMPCodePoint(codePoint)) {
if (!validateNonSurrogates || !isSurrogate((char)codePoint))
return 1;
} else if (isSupplementaryCodePoint(codePoint))
return 2;
return 0;
}
public static int charCount(int[] codePoints, int offset, int
count, boolean validateNonSurrogates) {
checkBoundsOnCount(codePoints.length, offset, count);
int n = 0;
for (int i = offset; i < offset + count; i++) {
int m = charCount(codePoints[i], validateNonSurrogates);
if (m == 0)
throw new IllegalArgumentException("At position "+i);
n += m;
}
return n;
}
0x00b88930: mov %ebx,0x4(%esp)
0x00b88934: mov %eax,0x34(%esp) ;*aload_0
; -
java.lang.Character::charCount at 21 (line 2946)
0x00b88938: mov 0x4(%esp),%ebx
0x00b8893c: mov 0xc(%ebx,%ebp,4),%ecx ;*iaload
; -
java.lang.Character::charCount at 24 (line 2946)
0x00b88940: mov %ecx,%eax
0x00b88942: shr $0x10,%eax ;*iushr
; -
java.lang.Character::isBMPCodePoint at 3 (line 2737)
; -
java.lang.Character::charCount at 1 (line 2907)
; -
java.lang.Character::charCount at 26 (line 2946)
0x00b88945: test %eax,%eax
0x00b88947: je 0x00b88973 ;*ifeq
; -
java.lang.Character::charCount at 4 (line 2907)
; -
java.lang.Character::charCount at 26 (line 2946)
0x00b88949: cmp $0x11,%eax
0x00b8894c: jge 0x00b889bf ;*if_icmpge
; -
java.lang.Character::isValidCodePoint at 6 (line 2713)
; -
java.lang.Character::isSupplementaryCodePoint at 8 (line 2768)
; -
java.lang.Character::charCount at 22 (line 2910)
; -
java.lang.Character::charCount at 26 (line 2946)
0x00b88952: mov $0x2,%ecx
0x00b88957: mov 0x34(%esp),%eax ;*invokestatic charCount
; -
java.lang.Character::charCount at 26 (line 2946)
0x00b8895b: add %ecx,%esi ;*iadd
; -
java.lang.Character::charCount at 68 (line 2949)
0x00b8895d: inc %ebp ;*iinc
; -
java.lang.Character::charCount at 71 (line 2945)
0x00b8895e: cmp %edx,%ebp
0x00b88960: jl 0x00b88930 ;*if_icmpge
; -
java.lang.Character::charCount at 18 (line 2945)
========================== Example 2:
n += Character.charCount(codePoints, 0, codePoints.length);
public static int charCount(int[] codePoints, int offset, int count) {
checkBoundsOnCount(codePoints.length, offset, count);
int n = 0;
for (int i = offset; i < offset + count; i++) {
int c = codePoints[i];
if (Character.isBMPCodePoint(c))
n += 1;
else if (Character.isSupplementaryCodePoint(c))
n += 2;
else
throw new IllegalArgumentException("At position "+i);
}
return n;
}
0x00b84e0e: mov 0x4(%esp),%edi
0x00b84e12: mov 0xc(%edi,%edx,4),%ebp
0x00b84e16: shr $0x10,%ebp ;*iushr
; -
java.lang.Character::isBMPCodePoint at 3 (line 2737)
; -
java.lang.Character::charCount at 28 (line 2958)
0x00b84e19: test %ebp,%ebp
0x00b84e1b: je 0x00b84f21 ;*ifeq
; -
java.lang.Character::charCount at 31 (line 2958)
0x00b84e21: cmp $0x11,%ebp
0x00b84e24: jge 0x00b84eee ;*if_icmpge
; -
java.lang.Character::isValidCodePoint at 6 (line 2713)
; -
java.lang.Character::isSupplementaryCodePoint at 8 (line 2768)
; -
java.lang.Character::charCount at 42 (line 2960)
0x00b84e2a: add $0x2,%eax ;*goto
; -
java.lang.Character::charCount at 51 (line 2961)
0x00b84e2d: inc %edx ;*iinc
; -
java.lang.Character::charCount at 82 (line 2956)
0x00b84e2e: cmp %ecx,%edx
0x00b84e30: jl 0x00b84e0e
-Ulf
More information about the hotspot-compiler-dev
mailing list