blob: 2e2c578abf554a3d61e70cf0877fa5039979cb43 (
plain)
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
34
35
36
37
38
39
40
41
42
43
44
|
function str(c) {
let s = c;
for (let i = 0; i < 30; i++)
s += c;
ensureLinearString(s);
return s;
}
function f() {
// Create some slots to write into.
const o = {owner: 'short1', s: 'short2'};
// Make a tenured rope.
const r1 = str("a") + str("b");
gc();
// Write the first instance of our duplicate string into one of the slots
// (`owner`). This will be scanned first, and entered into deDupSet when
// tenured.
o.owner = ensureLinearString(str("a") + str("b") + str("c"));
// Make another rope with identical contents, with a tenured subtree.
const r2 = r1 + str("c");
// Linearize the new rope, creating a new extensible string and a bunch of
// dependent strings replacing the rest of the rope nodes.
ensureLinearString(r2);
// Write the new rope into a slot, so that it will be scanned next during the
// minor GC during traceSlots().
o.s = r2;
// Do a nursery collection. o.owner will be tenured and inserted into
// deDupSet. Then o.s aka r2 will be tenured. If things work correctly, r2
// will be marked non-deduplicatable because it is the base of a tenured
// string r1. If not, it will be deduplicated to o.owner.
minorgc();
// Extract out that r1 child node. If its base was deduplicated, this will
// assert because its chars have been freed.
const s1 = r1.substr(0, 31);
}
f();
|