如何V8管理它的堆?(How does V8 manage its heap?)

2019-10-23 06:50发布

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

顺便说一句,不JVM做?

Answer 1:

所有显示,

谷歌的V8堆分为几个不同的空间。 有一个伟大的职位,“ V8的游:垃圾回收 ”这也解释了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.

康拉德的文章接着解释了V8 GC是从的味道内置切尼的算法 。

V8的堆实现驻留在heap.cc和heap.h 。 堆的初始化开始于line 5423 。 该方法Address NewSpaceStart()上发现的line 615的heap.h包含的新空间开始,在此地址的位置,且对象均是在那里采取时间局部性的优势存储。

现在你的第二个问题: 不JVM做? 一个有趣的事实:有3级主要生产的JVM和他们都不同的方式实现自己的GC算法。 这里面有写的文章,一个伟大的表现博客“ 垃圾收集在三大JVM上有何不同 ,这将更加详细地讨论它们的实现”。

也有GC的口味,比如,如果你想有一个低延迟环境中 ,如果你重新写的JVM在Scala中 ,并在.NET环境中的延迟调整选项 。

请让我知道,如果你有任何问题!

感谢您的时间,

温暖的问候,



文章来源: How does V8 manage its heap?