Java GC安全点 [英] Java GC safepoint

查看:665
本文介绍了Java GC安全点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当垃圾收集器在清理未引用的对象之前冻结应用程序线程时,所有线程都需要处于执行的安全点。我发现了大量描述安全点概念的文字,但很少有例子。在哪里将安全点置于典型的Java方法中,为什么?更重要的是,哪里可以找到一个安全点?

解决方案 确切的定义和安全点的实现从一个虚拟机实现改变到另一个虚拟机实现,但考虑到Hotspot虚拟机,您可以在以下位置找到一个很好的定义: SafePoint in HotSpot JVM



热点词汇表表示:


程序执行过程中的一个点,所有GC根已知并且所有堆对象内容都是一致的。从全局的角度来看,所有线程必须在GC运行之前在一个安全点上阻塞。


通常,安全点由JVM向方法中注入一个安全点检查,大多数调用站点被认定为安全点 - 当到达安全点检查时,线程将检查是否需要安全点(例如,FullGC是预定的),如果是,则线程阻塞。当VM块中的所有线程都已达到虚拟机中所有对象完全可达的安全点时。然后,执行请求安全点的VM操作(例如FullGC),之后线程被恢复。

检查需要安全点的虚拟机操作列表: -XX:+ PrintSafepointStatistics -XX来研究Hotspot中的安全点行为。 :PrintSafepointStatisticsCount = 1 。


When a garbage collector freezes the application threads before cleaning up unreferenced objects, all threads are required to be at a "safepoint" in their execution. I found a wealth of writing describing the concept of a safepoint, but very few examples. Where will a safepoint be placed within a typical Java method and why? And more importantly, where can a safepoint not occur?

解决方案

The exact definition and implementation of a safepoint changes from one VM implementation to another, but considering Hotspot VM, you can find a nice definition in: Safepoints in HotSpot JVM.

HotSpot glossary says:

A point during program execution at which all GC roots are known and all heap object contents are consistent. From a global point of view, all threads must block at a safepoint before the GC can run.

Typically, the safepoint is implemented by JVM injecting a safepoint check into a method, most call sites qualify as safepoints - when reaching the safepoint check, the thread will check if the safepoint is required (e.g. FullGC is scheduled), if yes, then the thread blocks. When all the threads in the VM block, you have reached the safepoint where all the the objects in the VM are perfectly reachable. Then, the VM operation that requested the safepoint is performed (e.g. a FullGC), after that the threads are resumed.

Check for the list of VM operations requiring a safepoint : Safety First: Safepoints.

You can study safepoint behavior in Hotspot by using -XX:+PrintSafepointStatistics –XX:PrintSafepointStatisticsCount=1.

这篇关于Java GC安全点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆