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

Improve setting signalsWithMasterHandlers and fix omrsig_protect #2611

Merged
merged 1 commit into from
Jun 4, 2018

Conversation

babsingh
Copy link
Contributor

@babsingh babsingh commented Jun 1, 2018

Currently, signalsWithMasterHandlers is set at two places:
omrsig_register_os_handler and registerMasterHandlers.

With this changeset, signalsWithMasterHandlers will only be set within
registerSignalHandlerWithOS after an OS handler has been successfully
registered.

A write barrier is issued before updating signalsWithHandlers and
signalsWithMasterHandlers within registerSignalHandlerWithOS. The write
barrier will allow us to read signalsWithHandlers and
signalsWithMasterHandlers without acquiring registerHandlerMonitor.

omrsig_protect serves asynchronous signals, and OS handlers for
asynchronous signals are generally registered once at startup. Now
onwards, signalsWithMasterHandlers is read without acquiring
registerHandlerMonitor within omrsig_protect. This serves two purposes.

First, omrsig_protect won't acquire registerHandlerMonitor if a handler
is already registered. From past performance numbers, this would save
1828 instructions from the newDirectByteBuffer pathlength.

Second, thread->monitor value ends up being NULL if the thread gets
aborted during the call to
omrthread_monitor_enter(registerHandlerMonitor). This impacts the
behavior of omrthread.c::interrupt_waiting_server. In OpenJ9,
intermittent segmentation faults are observed during calls to
Java_java_lang_Thread_interruptImpl. By not acquiring
registerHandlerMonitor if an OS handler is already registered,
omrsig_protect avoids conflict with the thread library and prevents
segmentation fault in OpenJ9.

Signed-off-by: Babneet Singh [email protected]

@babsingh babsingh force-pushed the fix_java8_gpf_issue branch from 9715cad to 4e22d92 Compare June 1, 2018 13:28
@babsingh
Copy link
Contributor Author

babsingh commented Jun 1, 2018

fyi - @pshipton this is the fix for the gpf issue. i am testing changes in personal builds. i will remove the WIP after testing.

@@ -1274,10 +1258,22 @@ registerSignalHandlerWithOS(OMRPortLibrary *portLibrary, uint32_t portLibrarySig
}
}

issueWriteBarrier();

/* Set the portLibrarySignalNo bit in signalsWithHandlers to record successful registration
* of the handler. */
signalsWithHandlers |= portLibrarySignalNo;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems these updates need to be atomic. Otherwise without a monitor bits could be lost.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a monitor is always acquired before calling registerSignalHandlerWithOS.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a lock being held at this point while the flags are being modified?

Copy link
Contributor Author

@babsingh babsingh Jun 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the flags are modified within registerSignalHandlerWithOS, and registerHandlerMonitor is always acquired before calls to registerSignalHandlerWithOS. this info is documented in registerSignalHandlerWithOS's description.

Currently, signalsWithMasterHandlers is set at two places:
omrsig_register_os_handler and registerMasterHandlers.

With this changeset, signalsWithMasterHandlers will only be set within
registerSignalHandlerWithOS after an OS handler has been successfully
registered.

A write barrier is issued before updating signalsWithHandlers and
signalsWithMasterHandlers within registerSignalHandlerWithOS. The write
barrier will allow us to read signalsWithHandlers and
signalsWithMasterHandlers without acquiring registerHandlerMonitor.

omrsig_protect serves asynchronous signals, and OS handlers for
asynchronous signals are generally registered once at startup. Now
onwards, signalsWithMasterHandlers is read without acquiring
registerHandlerMonitor within omrsig_protect. This serves two purposes. 

First, omrsig_protect won't acquire registerHandlerMonitor if a handler
is already registered. From past performance numbers, this would save
1828 instructions from the newDirectByteBuffer pathlength. 

Second, thread->monitor value ends up being NULL if the thread gets
aborted during the call to
omrthread_monitor_enter(registerHandlerMonitor). This impacts the
behavior of omrthread.c::interrupt_waiting_server. In OpenJ9,
intermittent segmentation faults are observed during calls to
Java_java_lang_Thread_interruptImpl. By not acquiring
registerHandlerMonitor if an OS handler is already registered,
omrsig_protect avoids conflict with the thread library and prevents
segmentation fault in OpenJ9.

Signed-off-by: Babneet Singh <[email protected]>
@babsingh babsingh force-pushed the fix_java8_gpf_issue branch from 4e22d92 to ab151c5 Compare June 1, 2018 14:58
@babsingh babsingh changed the title WIP: Improve setting signalsWithMasterHandlers and fix omrsig_protect Improve setting signalsWithMasterHandlers and fix omrsig_protect Jun 1, 2018
@babsingh
Copy link
Contributor Author

babsingh commented Jun 1, 2018

Removed the WIP tag. Personal builds and local testing have succeeded.

@charliegracie
Copy link
Contributor

@genie-omr build all

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants