V8如何管理其堆?

时间:2015-06-06 04:44:13

标签: java garbage-collection heap v8 mark-and-sweep

我知道当V8的垃圾收集工作正常时,它将从GC的根目录进行跟踪,以便标记无法访问的对象,然后进行扫描。我的问题是GC遍历如何遍历这些对象?必须有一个数据结构来存储所有可到达或无法访问的对象。位图?链接表?

BTW,JVM也这样做吗?

1 个答案:

答案 0 :(得分:2)

AllenShow,

谷歌的V8堆被组织成几个不同的空间。有一篇很棒的帖子,“A tour of V8: Garbage Collection”解释了V8堆如何组织为:

New-space: Most objects are allocated here. New-space is small and is
designed to be garbage collected very quickly, independent of other
spaces.

Old-pointer-space: Contains most objects which may have pointers to 
other objects. Most objects are moved here after surviving in new-space 
for a while.

Old-data-space: Contains objects which just contain raw data (no 
pointers to other objects). Strings, boxed numbers, and arrays of
unboxed doubles are moved here after surviving in new-space for a 
while.

Large-object-space: This space contains objects which are larger than
the size limits of other spaces. Each object gets its own mmap'd region
of memory. Large objects are never moved by the garbage collector.

Code-space: Code objects, which contain JITed instructions, are 
allocated here. This is the only space with executable memory (although
Codes may be allocated in large-object-space, and those are executable, too).

Cell-space, property-cell-space and map-space: These spaces contain
Cells, PropertyCells, and Maps, respectively. Each of these spaces
contains objects which are all the same size and has some constraints 
on what kind of objects they point to, which simplifies collection.

Conrad的文章接着解释了V8 GC的构建方式是Cheney's Algorithm

V8的堆实现位于heap.ccheap.h。堆的初始化从line 5423开始。在heap.hAddress NewSpaceStart()上找到的方法line 615包含新空间开始的地址位置,并且通过利用时间局部性来存储对象。

现在提出第二个问题: JVM是否也这样做了?一个有趣的事实:有3个主要的生产JVM,它们都以不同的方式实现GC算法。有一个很棒的性能博客撰写了文章“How Garbage Collection differs in the three big JVMs”,它将更详细地讨论它们的实现。

还有GC的风格,例如,如果您需要low-latency environmentre-wrote the JVM in Scalathe Latency tuning options within the .NET environment

如果您有任何疑问,请与我们联系!

感谢您的时间,

温暖的问候,