Java虚拟机 safepoints 初探

safepoint的定义很不规范,还跟JVM的具体实现有关,我们的讨论主要针对Hotspot VM。  

先看看openjdk的官方解释:  http://openjdk.java.net/groups/hotspot/docs/HotSpotGlossary.html

Safepoint    :在程序执行过程中,该点处的所有GC roots 是已知的 和 所有heap object contents是 一致的(consistent)。
从全局观点来看,所有线程必须在GC 运行前,在一个safepoint处阻塞(block)。
从局部观点来看,safepoint是一个代码块中特殊的一点,该处正在执行的线程可以因GC而阻塞。
很多调用点都满足要求,可以成为safepoints。存在 strong invariants在所有safepoints中都成立,而在non-safepoints中可能就被无视了。
Java code 和c/c++ code的优化都是在safepoints之间,很少跨过safepoints。
JIT编译器在每个safepoint处生成(emit)了一个GC map。
VM中的C/C++ code 使用格式化的基于宏的约定来标记可能的safepoints。

 什么时候使用safepoints:

  1. GC时的停顿 Garbage collection pauses  
  2. JIT生成的代码反优化  Code deoptimization
  3. Flushing code cache
  4. 类重定义 Class redefinition (e.g. hot swap or instrumentation)
  5. 偏向锁  Biased lock revocation
  6. Various debug operation (e.g. deadlock check or stacktrace dump)

Troubleshooting in safepoints:

通常情况下,safepoints正常工作。有问题时,可以使用下面两个选项帮助诊断问题:

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

参考文章:

openjdk  官方文档

safepoints in hotspot jvm

 

 

转载于:https://www.cnblogs.com/ridox/p/3634827.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值