最近看了一些关于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/