tor-browser

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

pretenuring.js (1611B)


      1 // Test nursery string allocation and pretenuring.
      2 
      3 gczeal(0);
      4 gcparam("semispaceNurseryEnabled", 0);
      5 
      6 gcparam("minNurseryBytes", 4096 * 1024);
      7 gcparam("maxNurseryBytes", 4096 * 1024);
      8 gc();
      9 
     10 // String allocation in the nursery is initially enabled.
     11 assertEq(nurseryStringsEnabled(), true);
     12 
     13 // Literal strings are atoms (which are always tenured).
     14 assertEq(isNurseryAllocated("foo"), false);
     15 
     16 // The result of Number.toString is nursery allocated.
     17 assertEq(isNurseryAllocated((1234).toString()), true);
     18 
     19 // Ropes are nursery allocated.
     20 let s = "bar";
     21 assertEq(isNurseryAllocated("foo" + s), true);
     22 
     23 // Dependent strings are nursery allocated.
     24 assertEq(isNurseryAllocated("foobar".substr(1)), true);
     25 
     26 // The testing function 'newString' allows control over which heap is used.
     27 assertEq(isNurseryAllocated(newString("foobar", { tenured: true })), false);
     28 assertEq(isNurseryAllocated(newString("foobar", { tenured: false })), true);
     29 
     30 // Allocating lots of strings which survive nursery collection disables
     31 // allocating strings in the nursery.
     32 let a = [];
     33 for (let i = 1; i < 500000; i++) {
     34  a.push(i.toString());
     35 }
     36 gc();
     37 assertEq(nurseryStringsEnabled(), false);
     38 a = undefined;
     39 
     40 // When a large number of tenured strings die very soon after allocation,
     41 // pretenuring for that zone is reset and nursery allocation enabled again.
     42 
     43 gc();
     44 assertEq(nurseryStringsEnabled(), false);
     45 let initGCNumber = gcparam('majorGCNumber');
     46 while (!nurseryStringsEnabled() && gcparam('majorGCNumber') < initGCNumber + 3) {
     47  for (let i = 1; i < 100000; i++) {
     48    a = i.toString();
     49  }
     50 }
     51 assertEq(nurseryStringsEnabled(), true);