tor-browser

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

incremental-state.js (2409B)


      1 // |jit-test| skip-if: !hasFunction["gczeal"]
      2 
      3 function assert(x) {
      4  assertEq(true, x);
      5 }
      6 
      7 function waitForState(state) {
      8  while (gcstate() !== state && gcstate() !== "NotActive") {
      9    gcslice(100);
     10  }
     11 }
     12 
     13 // Test expected state changes during collection.
     14 gczeal(0);
     15 
     16 // Non-incremental GC.
     17 gc();
     18 assertEq(gcstate(), "NotActive");
     19 
     20 // Incremental GC in minimal slice. Note that finalization always uses zero-
     21 // sized slices while background finalization is on-going, so we need to loop.
     22 gcslice(1000000);
     23 assert(gcstate() !== "Mark");
     24 finishgc();
     25 assertEq(gcstate(), "NotActive");
     26 
     27 // Incremental GC in multiple slices: if marking takes more than one slice,
     28 // we yield before we start sweeping.
     29 gczeal(0);
     30 gcslice(1);
     31 waitForState("Mark");
     32 assertEq(gcstate(), "Mark");
     33 gcslice(1000000);
     34 assertEq(gcstate(), "Mark");
     35 gcslice(1000000);
     36 assert(gcstate() !== "Mark");
     37 finishgc();
     38 
     39 // Zeal mode 6: Incremental GC in two slices:
     40 //   1) prepare
     41 //   2) mark roots, mark and sweep
     42 gczeal(6, 0);
     43 gcslice(1);
     44 assertEq(gcstate(), "Prepare");
     45 gcslice(1);
     46 assertEq(gcstate(), "NotActive");
     47 
     48 // Zeal mode 8: Incremental GC in two slices:
     49 //   1) prepare and mark roots
     50 //   2) mark and sweep
     51 gczeal(8, 0);
     52 gcslice(1);
     53 assertEq(gcstate(), "Mark");
     54 gcslice(1);
     55 assertEq(gcstate(), "NotActive");
     56 
     57 // Zeal mode 9: Incremental GC in two slices:
     58 //   1) prepare, mark roots and marking
     59 //   2) new marking and sweeping
     60 gczeal(9, 0);
     61 gcslice(1);
     62 assertEq(gcstate(), "Mark");
     63 gcslice(1);
     64 assertEq(gcstate(), "NotActive");
     65 
     66 // Zeal mode 10: Incremental GC in multiple slices (always yeilds before
     67 // sweeping). This test uses long slices to prove that this zeal mode yields
     68 // in sweeping, where normal IGC (above) does not.
     69 gczeal(10, 0);
     70 gcslice(1000000);
     71 while (gcstate() === "Prepare" || gcstate() == "MarkRoots") {
     72  gcslice(1000000);
     73 }
     74 assertEq(gcstate(), "Sweep");
     75 gcslice(1000000);
     76 assert(gcstate() !== "Sweep");
     77 finishgc();
     78 
     79 // Two-slice zeal modes that yield once during sweeping.
     80 for (let mode of [ 17, 19 ]) {
     81    gczeal(mode, 0);
     82    gcslice(1);
     83    assertEq(gcstate(), "Sweep");
     84    gcslice(1);
     85    assertEq(gcstate(), "NotActive");
     86 }
     87 
     88 // Two-slice zeal modes that yield per-zone during sweeping.
     89 const sweepingZealModes = [ 20, 21, 22, 23 ];
     90 for (let mode of sweepingZealModes) {
     91    gczeal(mode, 0);
     92    gcslice(1);
     93    while (gcstate() === "Sweep")
     94        gcslice(1);
     95    assertEq(gcstate(), "NotActive");
     96 }