JDK-4435369 : (cs) Performance: CharsetDecoder.decode throws exceptions
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 1.4.0
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_nt
  • CPU: x86
  • Submitted: 2001-04-07
  • Updated: 2013-11-01
  • Resolved: 2001-10-02
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.4.0 beta3Fixed
Related Reports
Relates :  
Relates :  
Description
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?

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: generic FIXED IN: merlin-beta3 INTEGRATED IN: merlin-beta3
14-06-2004

EVALUATION Fixed by the redesign of the Charset API (4503732). -- ###@###.### 2001/10/2
10-09-0168