V8如何管理它的堆? [英] How does V8 manage its heap?

查看:167
本文介绍了V8如何管理它的堆?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



顺便说一句,JVM是否也这样做?

解决方案

AllenShow,



Google的V8堆被组织成几个不同的空间。有一个很棒的帖子, V8游览:垃圾收集,它解释了V8堆是如何组织的:

 新空间:大多数对象在这里被分配。新空间很小,并且
旨在非常快速地收集垃圾,与其他
空间无关。

旧指针空间:包含大多数可能指向
其他对象指针的对象。在新空间
存活一段时间后,大多数物体都会移动到这里。

旧数据空间:包含仅包含原始数据的对象(不包含指向其他对象的
指针)。字符串,盒装数字和
无箱装双数阵列在新空间中幸存
的同时移动到这里。

大对象空间:这个空间包含的对象大于
其他空间的大小限制。每个对象都有自己的mmap'd区域
的内存。大对象永远不会被垃圾收集器移动。

代码空间:包含JITed指令的代码对象在这里分配
。这是唯一具有可执行内存的空间(尽管
代码可能在大对象空间中分配,而且这些代码也可执行)。

Cell-space,property-cell-space和map-space:这些空格分别包含
Cells,PropertyCells和Maps。这些空间中的每一个
都包含所有大小相同的对象,并且它们指向的对象类型有一些约束
,这简化了收集。

康拉德的文章继续解释V8 GC是从切尼算法



V8的堆实现驻留在 heap.cc 和< href =https://code.google.com/p/v8/source/browse/branches/3.24/src/heap.h?r=20595 =nofollow> heap.h 。堆的初始化始于第5423行。在第615行 of Address NewSpaceStart() com / p / v8 / source / browse / branches / 3.24 / src / heap.h?r = 20595rel =nofollow> heap.h 包含新空间开始的地址位置,通过利用时间局部性来存储对象。

现在针对第二个问题: JVM是否也这样做?一个有趣的事实:那里是3个主要的生产JVM,它们都以不同的方式实施其GC算法。有一个伟大的表现博客写了文章,垃圾收集在三个大型JVM中的不同之处这将详细讨论它们的实现。



GC,例如您是否想要低延迟环境,如果你在Scala中重写了JVM .NET环境下的延迟调整选项

请让我知道您是否有任何问题!



感谢您的时间,
热烈的问候,

I know when V8's Garbage Collection is working, it will trace from GC's root so that unreachable objects will be marked and then be swept. My question is how GC traverses traverse those objects? There must be a data structure to store all objects reachable or unreachable. Bitmap? Linked table?

BTW, does JVM do the same?

解决方案

AllenShow,

Google's V8 Heap is organized into a couple of different spaces. There's a great post, "A tour of V8: Garbage Collection" which explains how the V8 heap is organized as:

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's article goes on to explain the V8 GC is built from a flavor of Cheney's Algorithm.

V8's heap implementation resides in heap.cc and heap.h. Initialization of the heap begins at line 5423. The method Address NewSpaceStart() found on line 615 of heap.h contains the address location of where new-space starts, and the objects are stored where by taking advantage of temporal locality.

Now for your second question: does JVM do the same? A fun fact: there are 3 major production JVMs and they all implement their GC algorithms differently. There's a great performance blog which wrote the article, "How Garbage Collection differs in the three big JVMs" which will discusses their implementations in further detail.

There are also flavors of GC, such as if you want a low-latency environment, if you re-wrote the JVM in Scala, and the Latency tuning options within the .NET environment.

Please let me know if you have any questions!

Thank you for your time,

Warm Regards,

这篇关于V8如何管理它的堆?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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