-
Notifications
You must be signed in to change notification settings - Fork 3
/
guardians.txt
33 lines (26 loc) · 1.39 KB
/
guardians.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
In JS:
new Guardian() => <Guardian>
<Guardian>.add(obj) => void
obj must be an object value and not null, or the request will be
ignored. Add obj to the guardian. The same obj may be added
repeatedly to the same guardian and will in that case appear
multiple times in the guardian. The same obj may be added to
multiple guardians at the same time.
<Guardian>.dequeue() => obj | null
Get an enqueued object from the guarian.
<Guardian>.onqueued = <function>
Event handler that is invoked (from the event loop, not
synchronously) when the dequeueable set has grown.
Objects become dequeuable at the earliest when they are not reachable
by the GC except via guardians. Dequeueable objects are added to a
queue in the order they were added to the queue's guardian. An object
that is in multiple guardians is added to the queues in all the
guardians where it is present. An object that is multiple times in a
guardian is added multiple times to the queue in that guardian.
In SpiderMonkey it might be sufficient to consider a Guardian a
regular object for the purposes of a minor GC, and to only scan for
dead objects on major GC. This might simplify the implementation.
It might seem that such a simplification will tend to tenure objects
that should not be tenured, but that's not true - the objects are not
"dead", and would have to be tenured in any case so that they can be
added to the queue.