Strange speed dependency
Ulf Zibis
Ulf.Zibis at gmx.de
Mon Feb 2 14:35:20 PST 2009
Hi all,
I have experienced a strange speed dependency of HotSpot compiled code
after little change in code, which is not part of the "hot" loop.
Is there any explanation for this behavior?
Code before little change:
class UTF_8_new extends Unicode {
// ....
private static CoderResult malformed(ByteBuffer src, int sp,
CharBuffer dst, int dp, int
nb) {
src.position(sp -= nb - src.arrayOffset());
CoderResult cr = malformedN(src, nb);
updatePositions(src, sp, dst, dp);
return cr;
}
// ....
while (sp < sl) {
// ....
int b2 = sa[sp++];
int b3 = sa[sp++];
int b4 = sa[sp++];
if (isMalformed4(b1, b2))
return malformed(src, sp-2, dst, dp, 2);
if (isNotContinuation(b3))
return malformed(src, sp-1, dst, dp, 3);
if (isNotContinuation(b4))
return malformed(src, sp, dst, dp, 4);
if (dp >= dl - 1)
return overflow(src, sp-4, dst, dp);
int uc = (b1 << 18) ^ (b2 << 12) ^ (b3 << 06) ^ b4 ^
0x00381f80;
// ....
}
The above code has following output (note gain against UTF_8_70$Decoder):
time for sun.nio.cs.UTF_8_60$Decoder: 2701 ms
time for sun.nio.cs.UTF_8_70$Decoder: 1984 ms
time for sun.nio.cs.UTF_8_new$Decoder: 1720 ms // gain: 264 ms
time for sun.nio.cs.UTF_8_last$Decoder: 2110 ms
Following small code change made the "hot" part of the loop much slower:
class UTF_8_new extends Unicode {
// ....
private static CoderResult malformed(ByteBuffer src, int sp,
CharBuffer dst, int dp, int
nb) {
src.position(sp - src.arrayOffset()); // removed
subtraction of nb
CoderResult cr = malformedN(src, nb);
updatePositions(src, sp, dst, dp);
return cr;
}
// ....
while (sp < sl) {
// ....
int b2 = sa[sp++];
int b3 = sa[sp++];
int b4 = sa[sp++];
if (isMalformed4(b1, b2))
return malformed(src, sp-4, dst, dp, 2);
if (isNotContinuation(b3))
return malformed(src, sp-4, dst, dp, 3);
if (isNotContinuation(b4))
return malformed(src, sp-4, dst, dp, 4);
if (dp >= dl - 1)
return overflow(src, sp-4, dst, dp);
int uc = (b1 << 18) ^ (b2 << 12) ^ (b3 << 06) ^ b4 ^
0x00381f80;
// ....
}
time for sun.nio.cs.UTF_8_60$Decoder: 2731 ms
time for sun.nio.cs.UTF_8_70$Decoder: 1981 ms
time for sun.nio.cs.UTF_8_new$Decoder: 1872 ms // gain: 109 ms
time for sun.nio.cs.UTF_8_last$Decoder: 2094 ms
For complete sources compare following revisions (... and run
UTF_8Benchmark.java ):
https://java-nio-charset-enhanced.dev.java.net/source/browse/java-nio-charset-enhanced/trunk/test/sun/nio/cs/?diff_format=s&rev=613
https://java-nio-charset-enhanced.dev.java.net/source/browse/java-nio-charset-enhanced/trunk/test/sun/nio/cs/?diff_format=s&rev=614
-Ulf
More information about the hotspot-compiler-dev
mailing list