Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8187653

Lock in CoderResult.Cache becomes performance bottleneck

XMLWordPrintable

      A DESCRIPTION OF THE REQUEST :
      We have a load test for digital signature, we found that the CPU can not be fully utilized. After reviewing the thread dump we found that when you create a String with the constructor "String(bytes[])", it will try to decode the string with CoderResult, then CoderResult.Cache.get() will often block threads. Can we replace this with a lock-free cache? Another problem is that since CoderResult is very small, I don't think we really need a WeakReference to wrap it.

      Below is the stack dump:

      "catalina-exec-325" #26395 daemon prio=5 os_prio=0 tid=0x00007f56a012a000 nid=0x2347 waiting for monitor entry [0x00007f53dbc7a000]
         java.lang.Thread.State: BLOCKED (on object monitor)
              at java.nio.charset.CoderResult$Cache.get(CoderResult.java:201)
              - waiting to lock <0x00000005c0e89b58> (a java.nio.charset.CoderResult$1)
              at java.nio.charset.CoderResult$Cache.access$200(CoderResult.java:194)
              at java.nio.charset.CoderResult.malformedForLength(CoderResult.java:236)
              at sun.nio.cs.UTF_8$Decoder.malformedN(UTF_8.java:147)
              at sun.nio.cs.UTF_8$Decoder.decode(UTF_8.java:473)
              at java.lang.StringCoding$StringDecoder.decode(StringCoding.java:153)
              at java.lang.StringCoding.decode(StringCoding.java:193)
              at java.lang.StringCoding.decode(StringCoding.java:254)
              at java.lang.String.<init>(String.java:546)
              at java.lang.String.<init>(String.java:566)


      JUSTIFICATION :
      In web servers or string processing applications, you will often create a lot of Strings from bytes, the synchronized block has become a bottleneck in our benchmark. Optimizing this part of code can benefit a lot of applications with bytes/string processing.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Replace the synchronized cache method with a better cache implementation.

            sherman Xueming Shen
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: