Skip to content
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

Merged
merged 1 commit into from
Sep 14, 2018

Conversation

pdbain-ibm
Copy link
Contributor

@pdbain-ibm pdbain-ibm commented Sep 11, 2018

Avoid synchronization when the enabled state of logging is known.

  • Remove the volatile declaration of the logging status variable.
  • If the current thread's copy of loggingStatus is in a terminal state (enabled or disabled), avoid synchronizing.
  • In heavily used functions, test loggingStatus for the most probable value directly without a method call.
  • Clean up and reorganize some logging variables and methods.

Fixes #2048

@pshipton would you kindly review this? Thank you.

Signed-off-by: Peter Bain peter_bain@ca.ibm.com

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$
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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) {
Copy link
Member

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.

Copy link
Contributor Author

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;
Copy link
Member

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.

Copy link
Contributor Author

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>
@pshipton
Copy link
Member

jenkins test sanity plinux jdk8

@pshipton pshipton merged commit e60de42 into eclipse-openj9:master Sep 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants