tor-browser

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

array-push-multiple.js (1856B)


      1 // |jit-test| --no-threads
      2 
      3 // This test case check's Ion ability to recover from an allocation failure in
      4 // the inlining of Array.prototype.push, when given multiple arguments. Note,
      5 // that the following are not equivalent in case of failures:
      6 //
      7 //   arr = [];
      8 //   arr.push(1,2,3); // OOM ---> arr == []
      9 //
     10 //   arr = [];
     11 //   arr.push(1);
     12 //   arr.push(2); // OOM --> arr == [1]
     13 //   arr.push(3);
     14 
     15 function canIoncompile() {
     16  while (true) {
     17    var i = inIon();
     18    if (i)
     19      return i;
     20  }
     21 }
     22 
     23 if (canIoncompile() != true)
     24  quit();
     25 if ("gczeal" in this)
     26  gczeal(0);
     27 
     28 function pushLimits(limit, offset) {
     29  var arr = [0,1,2,3,4,5,6,7,8,9];
     30  arr.length = offset;
     31  var l = arr.length;
     32  var was = inIon();
     33  oomAtAllocation(limit);
     34  try {
     35    for (var i = 0; i < 100; i++)
     36      arr.push(0,1,2,3,4,5,6,7,8,9);
     37  } catch (e) {
     38    // Catch OOM.
     39  }
     40  resetOOMFailure();
     41  assertEq(arr.length % 10, l);
     42  // Check for a bailout.
     43  var is = inIon();
     44  return was ? is ? 1 : 2 : 0;
     45 }
     46 
     47 // We need this limit to be high enough to be able to OSR in the for-loop of
     48 // pushLimits.
     49 var limit = 1024 * 1024 * 1024;
     50 while(true) {
     51  var res = pushLimits(limit, 0);
     52 
     53  if (res == 0) {
     54    limit = 1024 * 1024 * 1024;
     55  } else if (res == 1) { // Started and finished in Ion.
     56    if (limit <= 1) // If we are not in the Jit.
     57      break;
     58    // We want to converge quickly to a state where the memory is limited
     59    // enough to cause failures in array.prototype.push.
     60    limit = (limit / 2) | 0;
     61  } else if (res == 2) { // Started in Ion, and finished in Baseline.
     62    if (limit < 10) {
     63      // This is used to offset the OOM location, such that we can test
     64      // each steps of the Array.push function, when it is jitted.
     65      for (var off = 1; off < 10; off++)
     66        pushLimits(limit, off);
     67    }
     68    if (limit == 1)
     69      break;
     70    limit--;
     71  }
     72 }