Shaka Player Embedded
|
#include <v8_heap_tracer.h>
Public Member Functions | |
V8HeapTracer () | |
~V8HeapTracer () override | |
bool | IsTracingDone () override |
void | TracePrologue (TraceFlags flags) override |
void | TraceEpilogue (TraceSummary *trace_summary) override |
void | EnterFinalPause (EmbedderStackState stack_state) override |
void | RegisterV8References (const std::vector< std::pair< void *, void *>> &internal_fields) override |
bool | AdvanceTracing (double deadline_ms) override |
![]() | |
HeapTracer () | |
~HeapTracer () | |
const std::unordered_set< const Traceable * > & | alive () const |
void | ForceAlive (const Traceable *ptr) |
void | Trace (const Traceable *ptr) |
template<typename T > | |
void | Trace (const std::vector< T > *array) |
template<typename T > | |
void | Trace (const std::list< T > *array) |
template<typename Key , typename Value > | |
void | Trace (const std::unordered_map< Key, Value > *map) |
template<typename T > | |
void | Trace (const optional< T > *opt) |
template<typename... Types> | |
void | Trace (const variant< Types... > *variant) |
void | Trace (const std::string *) |
void | Trace (const bool *) |
template<typename T , typename = util::enable_if_t<util::is_number<T>::value || std::is_enum<T>::value>> | |
void | Trace (const T *) |
void | BeginPass () |
void | TraceAll (const std::unordered_set< const Traceable *> &ref_alive) |
void | ResetState () |
This wraps the normal HeapTracer in an interface that can be used by V8 to track objects. Methods defined here will be called by V8 when it decides that a GC needs to be run.
This explains how the V8 GC works and how we interact with it:
There are two kinds of objects that are managed by different GCs, a JavaScript object (v8::Value) which is handled by the V8 gc, and BackingObject's which are handled by ObjectTracker. When the V8 GC runs, we need to tell it what objects we hold so it knows the V8 objects to delete. That is the purpose of this class.
When a V8 pass start, V8 will call TracePrologue. Then it will traverse its objects, marking alive objects. Any object that looks like a wrapper will be added to a list. Once the traversal is done, it will call RegisterV8References passing in the list. Then it will call AdvanceTracing to allow us to traverse our heap. We should traverse our alive objects and any wrapper objects given to us. We should then (a) mark these object as alive so we don't free them, and (b) tell V8 about any objects we hold.
When we tell V8 about alive objects, it may need to do some more traversals, which may in turn find more wrappers. If this happens, it will call RegisterV8References and AdvanceTracing again.
At points between method calls, it is possible for JavaScript to run. Because this runs on the event thread, it is not possible for JavaScript to run while one of these methods are being called, but between it is possible. V8 monitors all the objects and will ensure that any new objects will be given to us.
After V8 has traced every object TraceEpilogue is called. We use this to free any object that is not marked as alive.
Definition at line 61 of file v8_heap_tracer.h.
shaka::memory::V8HeapTracer::V8HeapTracer | ( | ) |
Definition at line 26 of file v8_heap_tracer.cc.
|
override |
Definition at line 28 of file v8_heap_tracer.cc.
|
override |
Called by V8 to advance the GC run. We should only take |deadline_ms| time to complete, telling V8 whether there is more work to do.
Definition at line 57 of file v8_heap_tracer.cc.
|
override |
Called by V8 when entering the final marking phase. There will be no more incremental marking calls.
Definition at line 47 of file v8_heap_tracer.cc.
|
override |
Definition at line 30 of file v8_heap_tracer.cc.
|
override |
Called by V8 to tell us about wrapper objects. The pair contains the internal field values of the wrapper object. We should store the values and process them only in AdvanceTracing.
Definition at line 49 of file v8_heap_tracer.cc.
|
override |
Called by V8 when a GC pass ends.
Definition at line 40 of file v8_heap_tracer.cc.
|
override |
Called by V8 when a GC pass begins.
Definition at line 34 of file v8_heap_tracer.cc.