JDK-7104625 : sun.awt.X11.XEvent is creating 600 MB of char[] for no good reason
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 7
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2011-10-25
  • Updated: 2014-10-15
  • Resolved: 2011-11-16
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.
JDK 7 JDK 8
7u4Fixed 8 b14Fixed
Related Reports
Relates :  
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
25-10-2011