The citation comes from: http://blog.ragozin.info/2012/10/safepoints-in-hotspot-jvm.html
Safepoint status check itself is implemented in very cunning way. Normal memory variable check would require expensive memory barriers. Though, safepoint check is implemented as memory reads a barrier. Then safepoint is required, JVM unmaps page with that address provoking page fault on application thread (which is handled by JVM’s handler). This way, HotSpot maintains its JITed code CPU pipeline friendly, yet ensures correct memory semantic (page unmap is forcing memory barrier to processing cores).
I have some doubts:
OS handles page faults in the first place. If the reason of this fault is an illegal memory access attempted by an application, OS delivers the appropriate signal to the application, typically SIGSEGV.
By default, SIGSEGV kills an application. However, an application may install its own signal handler. That's what JVM does. It receives SIGSEGV, and if it sees that the signal is caused by safepoint poll instruction, JVM suspends current thread until the safepoint operation is over.
A process may unmap pages by calling munmap()
. But in this particular case JVM does not unmap the page, but rather changes its protection state by calling mprotect()
with PROT_NONE.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With