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

sun.awt.X11.XEvent is creating 600 MB of char[] for no good reason

XMLWordPrintable

    • b14
    • generic
    • generic

        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.

              anthony Anthony Petrov (Inactive)
              anthony Anthony Petrov (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: