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

(cs) Performance: CharsetDecoder.decode throws exceptions

XMLWordPrintable

    • beta3
    • x86
    • windows_nt

      Using the JetStream benchmark, John Rose noticed that fillInStackTrace was being called a lot when run under Merlin. After scrounging around with hprof I've found the following examples of this:

      jetstream.io.ReadTextTest

              
      TRACE 20:
      java.lang.Throwable.fillInStackTrace(Throwable.java:Native method)
      java.lang.Throwable.<init>(Throwable.java:182)
      java.lang.Exception.<init>(Exception.java:32)
      java.lang.RuntimeException.<init>(RuntimeException.java:35)
      java.nio.BufferOverflowException.<init>(BufferOverflowException.java:36)
      java.nio.Buffer.nextPutIndex(Buffer.java:367)
      java.nio.HeapCharBuffer.put(HeapCharBuffer.java:69)
      sun.nio.cs.SingleByteDecoder.decodeStep(SingleByteDecoder.java:35)
              
      TRACE 23:
      sun.nio.cs.SingleByteDecoder.decodeStep(SingleByteDecoder.java:32)
      java.nio.CharsetDecoder.decode(CharsetDecoder.java:478)
      java.io.InputStreamReader$CharsetFiller.fill(InputStreamReader.java:368)
      java.io.InputStreamReader.read(InputStreamReader.java:508)
      java.io.BufferedReader.fill(BufferedReader.java:139)
      java.io.BufferedReader.readLine(BufferedReader.java:299)
      java.io.LineNumberReader.readLine(LineNumberReader.java:156)
      perfteam.jetstream.io.ReadTextTest.runTest(ReadTextTest.java:67)
      perfteam.jetstream.JetStream.runTests(JetStream.java:71)

              
      TRACE 18:
      java.lang.Throwable.fillInStackTrace(Throwable.java:Native method)
      java.lang.Throwable.<init>(Throwable.java:182)
      java.lang.Exception.<init>(Exception.java:32)
      java.lang.RuntimeException.<init>(RuntimeException.java:35)
      java.nio.BufferUnderflowException.<init>(BufferUnderflowException.java:36)
      java.nio.CharsetDecoder.decode(CharsetDecoder.java:464)
      java.io.InputStreamReader$CharsetFiller.fill(InputStreamReader.java:368)
      java.io.InputStreamReader.read(InputStreamReader.java:508)
              

      TRACE 31:
      java.lang.Throwable.<init>(Throwable.java:182)
      java.lang.Exception.<init>(Exception.java:32)
      java.lang.RuntimeException.<init>(RuntimeException.java:35)
      java.nio.BufferUnderflowException.<init>(BufferUnderflowException.java:36)
      java.nio.CharsetDecoder.decode(CharsetDecoder.java:464)
      java.io.InputStreamReader$CharsetFiller.fill(InputStreamReader.java:368)
      java.io.InputStreamReader.read(InputStreamReader.java:508)
      java.io.BufferedReader.fill(BufferedReader.java:139)
      java.io.BufferedReader.readLine(BufferedReader.java:299)
              

      jetstream.io.ParseTextTest

      TRACE 35:
      java.lang.Throwable.fillInStackTrace(Throwable.java:Native method)
      java.lang.Throwable.<init>(Throwable.java:182)
      java.lang.Exception.<init>(Exception.java:32)
      java.lang.RuntimeException.<init>(RuntimeException.java:35)
      java.nio.BufferUnderflowException.<init>(BufferUnderflowException.java:36)
      java.nio.CharsetDecoder.decode(CharsetDecoder.java:464)
      java.io.InputStreamReader$CharsetFiller.fill(InputStreamReader.java:368)
      java.io.InputStreamReader.read(InputStreamReader.java:508)
      java.io.BufferedReader.fill(BufferedReader.java:139)
              

      TRACE 19:
      java.lang.Throwable.fillInStackTrace(Throwable.java:Native method)
      java.lang.Throwable.<init>(Throwable.java:182)
      java.lang.Exception.<init>(Exception.java:32)
      java.lang.RuntimeException.<init>(RuntimeException.java:35)
      java.nio.BufferUnderflowException.<init>(BufferUnderflowException.java:36)
      java.nio.CharsetDecoder.decode(CharsetDecoder.java:464)
      java.io.InputStreamReader$CharsetFiller.fill(InputStreamReader.java:368)
      java.io.InputStreamReader.read(InputStreamReader.java:508)
      java.io.BufferedReader.fill(BufferedReader.java:139)
              

      TRACE 35:
      java.lang.Throwable.fillInStackTrace(Throwable.java:Native method)
      java.lang.Throwable.<init>(Throwable.java:182)
      java.lang.Exception.<init>(Exception.java:32)
      java.lang.RuntimeException.<init>(RuntimeException.java:35)
      java.nio.BufferOverflowException.<init>(BufferOverflowException.java:36)
      java.nio.Buffer.nextPutIndex(Buffer.java:367)
      java.nio.HeapCharBuffer.put(HeapCharBuffer.java:69)
      sun.nio.cs.SingleByteDecoder.decodeStep(SingleByteDecoder.java:35)
      java.nio.CharsetDecoder.decode(CharsetDecoder.java:478)

      It seems that when using the InputStreamReader.read method, a good deal of overhead can be generated by the CharsetDecoder.decode method generating BufferOverfow and BufferUnderflow exceptions.

      Would it be possible to code this in a way so that these exceptions are not thrown -- or at least pre-allocate and cache these exceptions?

            mr Mark Reinhold
            stewilso Steve Wilson (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: