safepoint的定义很不规范,还跟JVM的具体实现有关,我们的讨论主要针对Hotspot VM。
先看看openjdk的官方解释: http://openjdk.java.net/groups/hotspot/docs/HotSpotGlossary.html
Safepoint : 在程序执行过程中,该点处的所有GC roots 是已知的 和 所有heap object contents是 一致的(consistent)。<br>从全局观点来看,所有线程必须在GC 运行前,在一个safepoint处阻塞(block)。<br>从局部观点来看,safepoint是一个代码块中特殊的一点,该处正在执行的线程可以因GC而阻塞。 <br>很多调用点都满足要求,可以成为safepoints。存在 strong invariants在所有safepoints中都成立,而在non-safepoints中可能就被无视了。<br>Java code 和c/c++ code的优化都是在safepoints之间,很少跨过safepoints。<br>JIT编译器在每个safepoint处生成(emit)了一个GC map。<br>VM中的C/C++ code 使用格式化的基于宏的约定来标记可能的safepoints。 |
什么时候使用safepoints:
Troubleshooting in safepoints:
通常情况下,safepoints正常工作。有问题时,可以使用下面两个选项帮助诊断问题:
- -XX:+PrintGCApplicationStoppedTime – this will actually report pause time for all safepoints (GC related or not). Unfortunately output from this option lacks timestamps, but it is still useful to narrow down problem to safepoints.
- -XX:+PrintSafepointStatistics –XX:PrintSafepointStatisticsCount=1 – this two options will force JVM to report reason and timings after each safepoint (it will be reported to stdout, not GC log).
参考文章: