JDK-8010297 : Missing isLoggable() checks in logging code
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2013-03-19
  • Updated: 2017-01-11
  • Resolved: 2013-04-12
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 8 Other
8 b87Fixed openjdk7uFixed
Related Reports
Duplicate :  
Relates :  
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.
Comments
[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]
23-08-2013

Review thread: http://mail.openjdk.java.net/pipermail/core-libs-dev/2013-April/015916.html
12-04-2013

Contributed patch at http://mail.openjdk.java.net/pipermail/awt-dev/2013-March/004449.html
19-03-2013