Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For HotSpot and OpenJDK at least, the JVM uses safe points to stop the application's flow in each thread, either introduced in the JITed code or by changing the bytecode mappings for interpreted code (see <a href="http://blog.ragozin.info/2012/10/safepoints-in-hotspot-jvm.html" rel="nofollow noreferrer">this post</a> by Alexey Ragozin for more details).</p> <p>See also <a href="https://stackoverflow.com/a/15206301/1350869">this answer</a> by Gil Tene on why safepointing can be an additional issue when dealing with stop-the-world pauses.</p> <hr> <p>Here are more details (as I understand them, I don't claim to be an expert) on the safepointing mechanism in Hotspot/OpenJDK (see for example <a href="http://hg.openjdk.java.net/jdk8/jdk8/hotspot/file/1ae0472ff3a0/src/share/vm/runtime/safepoint.cpp" rel="nofollow noreferrer">safepoint.cpp</a>, line 154), based on the above resources, and probably on some articles by Cliff Click on the <a href="http://www.azulsystems.com/" rel="nofollow noreferrer">Azul Systems</a> blog (which seems to have disappeared from the site).</p> <h2>Reaching the safepoint</h2> <p>The JVM needs to get control of the flow from the application, so it depends on the current state of the threads:</p> <ul> <li><p><strong>Blocked</strong></p> <p>The JVM already has control of that thread.</p></li> <li><p><strong>Running interpreted code</strong></p> <p>The interpreter goes into a mode (by swapping its dispatch table) where each bytecode evaluation will be preceded by a safepoint check.</p></li> <li><p><strong>Running native code</strong> (JNI)</p> <p>JNI code runs in a safepoint and can continue running, unless it calls back into Java or calls some specific JVM methods, at which point it may be stopped to prevent leaving the safepoint (thanks Nitsan for the comments).</p></li> <li><p><strong>Running compiled code</strong></p> <p>The JVM makes a specific memory page (the Safepoint Polling page) unreadable, which makes the periodic reads of that page (inserted into the compiled code by the JIT compiler) fail and go to a JVM handler.</p></li> <li><p><strong>Running in the VM or transitioning states (in the VM also)</strong></p> <p>The flow goes through the safepoint check at some point anyway, so the VM waits for it.</p></li> </ul> <h2>Stopping at the safepoint</h2> <p>Once a thread is at the safepoint, controlled by the JVM, the JVM simply blocks it from exiting. When all threads have been stopped (i.e. the world is stopped), the JVM can do the garbage collection then release all the threads which resume execution.</p> <p>For much more details, you can go read this <a href="http://psy-lob-saw.blogspot.co.za/2015/12/safepoints.html" rel="nofollow noreferrer">blog post on safepoints</a> written by Nitsan Wakart in the meantime (which itself has even more references).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload