JDK 9 RFC on JDK-8029561: Optimization in Integer to string conversion

Brian Burkhalter brian.burkhalter at oracle.com
Fri Dec 27 22:04:12 UTC 2013


I performed some micro-benchmarking on my MacBookPro5,3 with respect to  https://bugs.openjdk.java.net/browse/JDK-8029561.

With this patch applied to JDK 9

--- a/src/share/classes/java/lang/Integer.java	Tue Dec 24 20:07:12 2013 -0800
+++ b/src/share/classes/java/lang/Integer.java	Fri Dec 27 13:45:28 2013 -0800
@@ -453,7 +453,11 @@
         // Fall thru to fast mode for smaller numbers
         // assert(i <= 65536, i);
         for (;;) {
-            q = (i * 52429) >>> (16+3);
+            // The value of z1 ends up being 52429*i
+            int z1 = (i << 3) + (i << 2);
+            z1 = (z1 << 4) + z1;
+            z1 = (z1 << 8) + z1 + i;
+            q = z1 >>> 19; // 19 = 16 + 3
             r = i - ((q << 3) + (q << 1));  // r = i-(q*10) ...
             buf [--charPos] = digits [r];
             i = q;

The performance of toString() over 100 random ints in the range [0,0xffff) was actually about 12% slower than without the patch applied.

Similarly, micro-benchmarks of

    int z1 = y*52429

versus

    int z1 = (y << 3) + (y << 2);
    z1 = (z1 << 4) + z1;
    z1 = (z1 << 8) + z1 + y;

showed the latter to be about 8% slower than the former.

The foregoing results suggest that the patch should be rejected and the issue resolved (as "Won't Fix").

Brian


More information about the core-libs-dev mailing list