tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

dedupeTenuredBase.js (1374B)


      1 function str(c) {
      2  let s = c;
      3  for (let i = 0; i < 30; i++) {
      4    s += c;
      5  }
      6  ensureLinearString(s);
      7  return s;
      8 }
      9 
     10 function f() {
     11  // Create some slots to write into.
     12  const o = { owner: "short1", s: "short2" };
     13 
     14  // Make a tenured rope.
     15  const r1 = str("a") + str("b");
     16  gc();
     17 
     18  // Write the first instance of our duplicate string into one of the slots
     19  // (`owner`). This will be scanned first, and entered into deDupSet when
     20  // tenured.
     21  o.owner = ensureLinearString(str("a") + str("b") + str("c"));
     22 
     23  // Make another rope with identical contents, with a tenured subtree.
     24  const r2 = r1 + str("c");
     25 
     26  // Linearize the new rope, creating a new extensible string and a bunch of
     27  // dependent strings replacing the rest of the rope nodes.
     28  ensureLinearString(r2);
     29 
     30  // Write the new rope into a slot, so that it will be scanned next during the
     31  // minor GC during traceSlots().
     32  o.s = r2;
     33 
     34  // Do a nursery collection. o.owner will be tenured and inserted into
     35  // deDupSet. Then o.s aka r2 will be tenured. If things work correctly, r2
     36  // will be marked non-deduplicatable because it is the base of a tenured
     37  // string r1. If not, it will be deduplicated to o.owner.
     38  minorgc();
     39 
     40  // Extract out that r1 child node. If its base was deduplicated, this will
     41  // assert because its chars have been freed.
     42  const s1 = r1.substr(0, 31);
     43 }
     44 
     45 f();