Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Safepoints in JVM

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:

  1. From what I know page fault is always handled by OS (and, from what I understsand it can handled only by kernel because of security). So, what autor does mean?
  2. The second is very similar to the first one: How JVM is able to unmap a page?
like image 800
Gilgamesz Avatar asked Mar 07 '23 23:03

Gilgamesz


1 Answers

  1. 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.

  2. 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.

like image 168
apangin Avatar answered Apr 26 '23 03:04

apangin