bmacnaughton
bmacnaughton

Reputation: 5318

what do v8's IncrementalMarking and ProcessWeakCallbacks garbage collections do?

I have implemented v8's garbage collection callbacks (prologue and epilogue) and am recording the time taken by garbage collection as well as the counts of each type. Everything I've read on v8 talks about major GCs (Mark/Sweep/Compact) and minor GCs (Scavenge). But there are two additional types both of which generate callbacks as well. From the v8 code:

enum GCType {
  kGCTypeScavenge = 1 << 0,
  kGCTypeMarkSweepCompact = 1 << 1,
  kGCTypeIncrementalMarking = 1 << 2,
  kGCTypeProcessWeakCallbacks = 1 << 3,
  kGCTypeAll = kGCTypeScavenge | kGCTypeMarkSweepCompact |
               kGCTypeIncrementalMarking | kGCTypeProcessWeakCallbacks
};

One odd thing about IncrementalMarking and ProcessWeakCallbacks is that their callbacks are always called the exact same number of times as the MarkSweepCompact callback.

My question is what are the IncrementalMarking and ProcessWeakCallbacks garbage collections? And also, why are they always invoked the same number of times as the MarkSweepCompact garbage collection (should they be considered part of that collection type)?

Upvotes: 0

Views: 504

Answers (1)

jmrk
jmrk

Reputation: 40561

(V8 developer here.) Yes, "IncrementalMarking" and "ProcessWeakCallbacks" are not types of GC, but phases of major GC cycles. (I don't know why that enum happens to be called GCType, probably for historical reasons.)

I am recording the time taken by garbage collection as well as the counts of each type

Note that the GC callbacks are neither intended nor suitable for time measurements. In particular, incremental marking (as the name implies) happens in many tiny incremental steps, but you only get one invocation of the callback before the first of these steps happens; after that incremental marking steps and program execution will be interleaved until marking is done.

Further, note that the team is working on moving as much of the GC work as possible into background threads, which makes the whole question of "how much time did it take?" somewhat ill-defined.

For offline investigation purposes, your best bet is the --trace-gc flag, which should provide accurate and complete timing information.

For online bookkeeping (as at V8 garbage collector callbacks for measuring GC activity, see also my detailed answer there), I'm afraid there is no good solution.

Upvotes: 1

Related Questions