gpt4 book ai didi

java - V8 如何管理它的堆?

转载 作者:行者123 更新时间:2023-12-05 02:22:08 29 4
gpt4 key购买 nike

我知道V8的Garbage Collection在工作的时候,会从GC的root开始追溯,标记不可达的对象,然后进行清理。我的问题是GC是怎么遍历遍历那些对象的?必须有一个数据结构来存储所有可达或不可达的对象。位图?链接表?

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

最佳答案

艾伦秀

Google 的 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.cc 中和 heap.h .堆的初始化从 5423 行 开始。在 heap.h615 行 中找到的方法 Address NewSpaceStart()包含新空间开始的地址位置,以及利用时间局部性将对象存储在哪里。

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

GC 也有不同的风格,比如你想要 low-latency environment , 如果你 re-wrote the JVM in Scala , 和 the Latency tuning options within the .NET environment .

如有任何问题,请告诉我!

谢谢你的时间,

温暖的问候,

关于java - V8 如何管理它的堆?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30679006/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com