array-push-multiple-with-funapply.js (1950B)
1 // |jit-test| --no-threads 2 3 // This test case check's Ion ability to inline Array.prototype.push, when 4 // fun.apply is used and inlined with the set of arguments of the current 5 // function. Note, 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 function pusher() { 30 Array.prototype.push.apply(arr, arguments) 31 } 32 var arr = [0,1,2,3,4,5,6,7]; 33 arr.length = offset; 34 var l = arr.length; 35 var was = inIon(); 36 oomAtAllocation(limit); 37 try { 38 for (var i = 0; i < 100; i++) 39 pusher(0,1,2,3,4,5,6,7); 40 } catch (e) { 41 // Catch OOM. 42 } 43 resetOOMFailure(); 44 assertEq(arr.length % 8, l); 45 // Check for a bailout. 46 var is = inIon(); 47 return was ? is ? 1 : 2 : 0; 48 } 49 50 51 52 // We need this limit to be high enough to be able to OSR in the for-loop of 53 // pushLimits. 54 var limit = 1024 * 1024 * 1024; 55 while(true) { 56 var res = pushLimits(limit, 0); 57 print(limit, res); 58 59 if (res == 0) { 60 limit = 1024 * 1024 * 1024; 61 } else if (res == 1) { // Started and finished in Ion. 62 // We want to converge quickly to a state where the memory is limited 63 // enough to cause failures in array.prototype.push. 64 limit = (limit / 1.5) | 0; 65 if (limit == 0) // If we are not in the Jit. 66 break; 67 } else if (res == 2) { // Started in Ion, and finished in Baseline. 68 if (limit < 10) { 69 // This is used to offset the OOM location, such that we can test 70 // each steps of the Array.push function, when it is jitted. 71 for (var off = 1; off < 8; off++) 72 pushLimits(limit, off); 73 } 74 if (limit == 1) 75 break; 76 limit--; 77 } 78 }