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:
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 methodAddress NewSpaceStart()
found online 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,