United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-7104625 sun.awt.X11.XEvent is creating 600 MB of char[] for no good reason
JDK-7104625 : sun.awt.X11.XEvent is creating 600 MB of char[] for no good reason

Details
Type:
Bug
Submit Date:
2011-10-25
Status:
Resolved
Updated Date:
2013-07-10
Project Name:
JDK
Resolved Date:
2011-11-16
Component:
client-libs
OS:
generic
Sub-Component:
java.awt
CPU:
generic
Priority:
P4
Resolution:
Fixed
Affected Versions:
7
Fixed Versions:

Related Reports
Backport:
Relates:

Sub Tasks

Description
I'm running

java -version
java version "1.7.0_147-icedtea"
OpenJDK Runtime Environment (IcedTea7 2.0pre) (7~b147-2.0~pre6-1ubuntu1)
OpenJDK 64-Bit Server VM (build 21.0-b17, mixed mode)

and profiling a simple Swing application.

Just by opening a JFrame and moving the mouse over it for 10 secods I
see 600 MB of char[] being created. I can easily create several
terabytes or those if I move the mouse a little longer. Thanks to the
incredibly efficient garbage collector the application performance is
not visibly affected on my 4GB quad core machine.

The problem is an incredibly inefficient method 

sun.awt.X11.XEvent.getFieldsAsString() which I pasted at the end of this
message.

The way it it handling string concatenation forces StringBuilder to grow
many times and ends up calling Arrays.copyOf a lot of times. 

It is being called by the sun.awt.X11.XWrapperBase.toString() just for
the sake of logging here:

sun.awt.X11.XComponentPeer

protected boolean isEventDisabled(XEvent e)

enableLog.finest("Component is {1}, checking for disabled event {0}", e,
(isEnabled()?"enabled":"disable"));

The worse part is that even if logging is disabled and nothing at all is
ever logged, the toString is called anyway and all those char[] are
created anyway.

                                    

Comments
EVALUATION

The issue reported here: http://mail.openjdk.java.net/pipermail/awt-dev/2011-October/001952.html

The final version of the patch: http://mail.openjdk.java.net/pipermail/awt-dev/2011-October/001960.html
                                     
2011-10-25



Hardware and Software, Engineered to Work Together