1 of 21

Tracing Wrappers from V8 to Blink

hlopko@, hpayer@, eisinger@, haraken@, ulan@, mlippautz@

Confidential + Proprietary

2 of 21

Story of two Garbage Collectors

Blink

V8

Confidential + Proprietary

3 of 21

V8 Handles

Handles keep V8 objects alive

(V8 object will be collected only after the handle is reset)

Blink

V8

Confidential + Proprietary

4 of 21

Blink Wrappers

Wrappers keep Blink objects alive

(Blink object will be collected only after the wrapper is collected by V8)

Blink

V8

Confidential + Proprietary

5 of 21

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

6 of 21

With great power comes great complexity

Unfortunate arrangement of wrappers and handles lead to a memory leak

Blink

V8

Confidential + Proprietary

7 of 21

Tracing Wrappers begins

Blink

V8

Confidential + Proprietary

8 of 21

V8 marks all reachable objects

Blink

V8

Confidential + Proprietary

9 of 21

V8 asks Blink to trace wrappers from the found ones

Blink

V8

Confidential + Proprietary

10 of 21

V8 asks Blink to trace wrappers from the found ones

Blink

V8

Confidential + Proprietary

11 of 21

V8 asks Blink to trace wrappers from the found ones

Blink

V8

Confidential + Proprietary

12 of 21

V8 asks Blink to trace wrappers from the found ones

Blink

V8

Confidential + Proprietary

13 of 21

Blink reports new wrappers to V8

Blink

V8

Confidential + Proprietary

14 of 21

V8 continues marking from wrappers

Blink

V8

Confidential + Proprietary

15 of 21

V8 continues marking from wrappers

Blink

V8

Confidential + Proprietary

16 of 21

V8 continues marking from wrappers

Blink

V8

Confidential + Proprietary

17 of 21

V8 continues marking from wrappers

Blink

V8

Confidential + Proprietary

18 of 21

… until the fixed point is reached

Blink

V8

Confidential + Proprietary

19 of 21

And the garbage is collected

Blink

V8

Confidential + Proprietary

20 of 21

TraceWrappers API

DEFINE_TRACE_WRAPPERS(Node)

{

visitor->traceWrappers(m_parent);

visitor->traceWrappers(m_previous);

visitor->traceWrappers(m_next);

}

Confidential + Proprietary

21 of 21

Next step

Make wrapper tracing incremental to reduce latency

Confidential + Proprietary