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

Missing isLoggable() checks in logging code

    Details

    • Subcomponent:
    • Resolved In Build:
      b87

      Backports

        Description

        Reported at http://mail.openjdk.java.net/pipermail/awt-dev/2013-March/004439.html :

        I run recently netbeans profiler on my swing application (Aspro2:
        http://www.jmmc.fr/aspro) under linux x64 platform and I figured out that a
        lot of char[] instances are coming from String + operator called by
        sun.awt.X11 code.

        I looked at PlatformLogger source code but found not way to disable it
        completely: maybe an empty logger implementation could be interesting to be
        used during profiling or normal use (not debugging).
        Apparently JDK8 provides some patchs to avoid String creation when the
        logger is disabled (level).

        However, I looked also to the sun.awt code (jdk7u repository) to see the
        origin of the string allocations:
        XDecoratedPeer:
            public void handleFocusEvent(XEvent xev) {
        ...
        * focusLog.finer("Received focus event on shell: " + xfe);
        * }

            public boolean requestWindowFocus(long time, boolean timeProvided) {
        ...
        * focusLog.finest("Real native focused window: " +
        realNativeFocusedWindow +
                                    "\nKFM's focused window: " + focusedWindow);
        *...
        * focusLog.fine("Requesting focus to " + (this == toFocus ? "this
        window" : toFocus));
        *...
        }

        XBaseWindow:
            public void xSetBounds(int x, int y, int width, int height) {
        ...
        * insLog.fine("Setting bounds on " + this + " to (" + x + ", " + y +
        "), " + width + "x" + height);
        *}

        XNetProtocol:
            boolean doStateProtocol() {
        ...
        * stateLog.finer("doStateProtocol() returns " + res);
        *}

        XSystemTrayPeer:
            XSystemTrayPeer(SystemTray target) {
        ...
        * log.fine(" check if system tray is available. selection owner: " +
        selection_owner);
        *}
            void addTrayIcon(XTrayIconPeer tiPeer) throws AWTException {
        ...
        * log.fine(" send SYSTEM_TRAY_REQUEST_DOCK message to owner: " +
        selection_owner);
        *}

        XFramePeer:
            public void handlePropertyNotify(XEvent xev) {
        ...
                    stateLog.finer("State is the same: " + state);
        }

        However I only give here few cases but certainly others are still present
        in the source code; maybe findbugs or netbeans warnings could help you
        finding all of them.

        I advocate the amount of waste (GC) is not very important but String
        conversion are also calling several toString() methods that can be costly
        (event, Frame, window ...)

        Finally, I ran few grep commands on the sun.awt.X11 code (jdk7u) and you
        can look at them to see all string + operations related to log statements.

          Issue Links

            Activity

            Show
            anthony Anthony Petrov (Inactive) added a comment - Contributed patch at http://mail.openjdk.java.net/pipermail/awt-dev/2013-March/004449.html
            Hide
            hgupdate HG Updates added a comment -
            URL: http://hg.openjdk.java.net/jdk8/awt/jdk/rev/4490ef60ecd3
            User: anthony
            Date: 2013-04-12 10:34:20 +0000
            Show
            hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk8/awt/jdk/rev/4490ef60ecd3 User: anthony Date: 2013-04-12 10:34:20 +0000
            Show
            anthony Anthony Petrov (Inactive) added a comment - Review thread: http://mail.openjdk.java.net/pipermail/core-libs-dev/2013-April/015916.html
            Hide
            hgupdate HG Updates added a comment -
            URL: http://hg.openjdk.java.net/jdk8/jdk8/jdk/rev/4490ef60ecd3
            User: lana
            Date: 2013-04-23 16:55:28 +0000
            Show
            hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk8/jdk8/jdk/rev/4490ef60ecd3 User: lana Date: 2013-04-23 16:55:28 +0000
            Hide
            anthony Anthony Petrov (Inactive) added a comment -
            [SQE]

            This fix only affects the logging statements. Logging is usually disabled, and only used for debugging purposes. Besides the fix itself only adds missing isLoggable() checks before actually writing to the log. Hence noreg-trivial.

            [/SQE]
            Show
            anthony Anthony Petrov (Inactive) added a comment - [SQE] This fix only affects the logging statements. Logging is usually disabled, and only used for debugging purposes. Besides the fix itself only adds missing isLoggable() checks before actually writing to the log. Hence noreg-trivial. [/SQE]

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved: