java - ZGC如何在不使用写屏障的情况下进行并发标记?

标签 java garbage-collection

最近看了一些关于ZGC的文章。
例如。 https://dinfuehr.github.io/blog/a-first-look-into-zgc/
并且它说ZGC中没有写障碍。

Both reading and writing in the heap is extremely common, so both GC-barriers need to be super efficient. That means just a few assembly instructions in the common case. Read barriers are an order of magnitude more likely than write-barriers (although this can certainly vary depending on the application), so read-barriers are even more performance-sensitive. Generational GC’s for example usually get by with just a write barrier, no read barrier needed. ZGC needs a read barrier but no write barrier. For concurrent compaction I haven’t seen a solution without read barriers.

Write-Barrier不需要并发紧凑,但是没有Write-Barrier怎么做并发标记呢?一些收集器,例如G1,使用三色标记和SATB+write Barrier来进行并发标记。

我从 OJ 那里读到还有另一种方法:

An alternative approach would be to keep a queue of all changes that could potentially violate the invariant, and then have a secondary “fixup” phase that runs after the main phase has finished. Different collectors can resolve this problem with tri-color marking in different ways, based on criteria such as performance or the amount of locking required.

我想知道它是如何工作的...搜索了一段时间后几乎没有关于它的信息...(也许我应该阅读一些源代码...

最佳答案

据我了解,不需要写入屏障,因为重定位集中的根引用是在并发重定位之前的 STW 阶段处理的。因此,你永远不会从堆栈、局部变量等引用旧对象。

关于java - ZGC如何在不使用写屏障的情况下进行并发标记?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58640689/

相关文章:

java - Hazelcast 中的分区警告消息

java - 多维词典?

java - 将 clojure/java.jmx 暴露给监控工具

c# - 为什么垃圾收集器不收集用户控件?

Java:如何优化读取/更新/写入许多小文件的内存占用?

java - 如何减少 Full GC 的数量?

java - 从局部变量创建 ByteArrayInputStream 是否有效?

java - 如何使用 Java ByteBuffer 处理负 int

java - 如何使用drawOval()创建一个圆环?

java - 使用 "+"运算符的非字符串操作数后,结果字符串会进入字符串池吗?