Tracing Wrappers from V8 to Blink
hlopko@, hpayer@, eisinger@, haraken@, ulan@, mlippautz@
Confidential + Proprietary
Story of two Garbage Collectors
Blink
V8
Confidential + Proprietary
V8 Handles
Handles keep V8 objects alive
(V8 object will be collected only after the handle is reset)
Blink
V8
Confidential + Proprietary
Blink Wrappers
Wrappers keep Blink objects alive
(Blink object will be collected only after the wrapper is collected by V8)
Blink
V8
Confidential + Proprietary
Some wrappers like to keep friends alive - Object grouping to the rescue!
For V8 gc, we iterate all handles and ask them which group they want to be in
Rules are defined by SetWrapperReferenceFrom, SetWrapperReferenceTo, Custom=VisitDOMWrapper
Blink
V8
Confidential + Proprietary
With great power comes great complexity
Unfortunate arrangement of wrappers and handles lead to a memory leak
Blink
V8
Confidential + Proprietary
Tracing Wrappers begins
Blink
V8
Confidential + Proprietary
V8 marks all reachable objects
Blink
V8
Confidential + Proprietary
V8 asks Blink to trace wrappers from the found ones
Blink
V8
Confidential + Proprietary
V8 asks Blink to trace wrappers from the found ones
Blink
V8
Confidential + Proprietary
V8 asks Blink to trace wrappers from the found ones
Blink
V8
Confidential + Proprietary
V8 asks Blink to trace wrappers from the found ones
Blink
V8
Confidential + Proprietary
Blink reports new wrappers to V8
Blink
V8
Confidential + Proprietary
V8 continues marking from wrappers
Blink
V8
Confidential + Proprietary
V8 continues marking from wrappers
Blink
V8
Confidential + Proprietary
V8 continues marking from wrappers
Blink
V8
Confidential + Proprietary
V8 continues marking from wrappers
Blink
V8
Confidential + Proprietary
… until the fixed point is reached
Blink
V8
Confidential + Proprietary
And the garbage is collected
Blink
V8
Confidential + Proprietary
TraceWrappers API
DEFINE_TRACE_WRAPPERS(Node)
{
visitor->traceWrappers(m_parent);
visitor->traceWrappers(m_previous);
visitor->traceWrappers(m_next);
}
Confidential + Proprietary
Next step
Make wrapper tracing incremental to reduce latency
Confidential + Proprietary