-
Notifications
You must be signed in to change notification settings - Fork 738
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove unnecessary synchronization in attach API logging #2827
Conversation
84b0998
to
345e545
Compare
File logFile = new File(logName + pidProperty + ".log"); //$NON-NLS-1$ | ||
IPC.logStream = new PrintStream(logFile); | ||
IPC.setDefaultVmId(pidProperty); | ||
IPC.logMessage("AttachHandler initialize"); //$NON-NLS-1$ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This message won't be logged since logging is not yet enabled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. Changing to unconditional print.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or you can set LOGGING_ENABLED before calling logMessage()
} | ||
} | ||
|
||
private static void printMessageWithHeader(String msg, PrintStream log) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method should have a comment that it must be called from inside a synchronized block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good plan.
IPC.logStream = new PrintStream(logFile); | ||
IPC.setDefaultVmId(pidProperty); | ||
IPC.logMessage("AttachHandler initialize"); //$NON-NLS-1$ | ||
loggingStatus = LOGGING_ENABLED; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this implementation is 100% proper. In theory the IPC logging code could see that logging is enabled before the logstream is fully initialized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logStream
is initialized and used inside synchronized blocks, so it cannot be used until initialization is complete.
Avoid synchronization when the enabled state of logging is known. Signed-off-by: Peter Bain <peter_bain@ca.ibm.com>
345e545
to
e67da56
Compare
jenkins test sanity plinux jdk8 |
Avoid synchronization when the enabled state of logging is known.
volatile
declaration of the logging status variable.loggingStatus
is in a terminal state (enabled or disabled), avoid synchronizing.loggingStatus
for the most probable value directly without a method call.Fixes #2048
@pshipton would you kindly review this? Thank you.
Signed-off-by: Peter Bain peter_bain@ca.ibm.com