-
Notifications
You must be signed in to change notification settings - Fork 398
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
Conversation
9715cad
to
4e22d92
Compare
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; |
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.
Seems these updates need to be atomic. Otherwise without a monitor bits could be lost.
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.
a monitor is always acquired before calling registerSignalHandlerWithOS.
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.
Is there a lock being held at this point while the flags are being modified?
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.
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]>
4e22d92
to
ab151c5
Compare
Removed the WIP tag. Personal builds and local testing have succeeded. |
@genie-omr build all |
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]