tor-browser

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

bug1681806.js (3370B)


      1 // |jit-test| skip-if: !getJitCompilerOptions()['ion.enable']
      2 
      3 with ({}) {}
      4 
      5 let foo, bar, active;
      6 
      7 function test(depth) {
      8    print(depth);
      9 
     10    // Define two mutually recursive functions with as many locals as possible
     11    // to maximize the size of the rematerialized frame when we bail out (~4K).
     12    foo = new Function('n', `
     13       var a0,b0,c0,d0,e0,f0,g0,h0,i0,j0,k0,l0,m0,n0,o0,p0,q0,r0,s0,t0,u0,v0,w0,x0,y0,z0;
     14       var a1,b1,c1,d1,e1,f1,g1,h1,i1,j1,k1,l1,m1,n1,o1,p1,q1,r1,s1,t1,u1,v1,w1,x1,y1,z1;
     15       var a2,b2,c2,d2,e2,f2,g2,h2,i2,j2,k2,l2,m2,n2,o2,p2,q2,r2,s2,t2,u2,v2,w2,x2,y2,z2;
     16       var a3,b3,c3,d3,e3,f3,g3,h3,i3,j3,k3,l3,m3,n3,o3,p3,q3,r3,s3,t3,u3,v3,w3,x3,y3,z3;
     17       var a4,b4,c4,d4,e4,f4,g4,h4,i4,j4,k4,l4,m4,n4,o4,p4,q4,r4,s4,t4,u4,v4,w4,x4,y4,z4;
     18       var a5,b5,c5,d5,e5,f5,g5,h5,i5,j5,k5,l5,m5,n5,o5,p5,q5,r5,s5,t5,u5,v5,w5,x5,y5,z5;
     19       var a6,b6,c6,d6,e6,f6,g6,h6,i6,j6,k6,l6,m6,n6,o6,p6,q6,r6,s6,t6,u6,v6,w6,x6,y6,z6;
     20       var a7,b7,c7,d7,e7,f7,g7,h7,i7,j7,k7,l7,m7,n7,o7,p7,q7,r7,s7,t7,u7,v7,w7,x7,y7,z7;
     21       var a8,b8,c8,d8,e8,f8,g8,h8,i8,j8,k8,l8,m8,n8,o8,p8,q8,r8,s8,t8,u8,v8,w8,x8,y8,z8;
     22       var a9,b9,c9,d9,e9,f9,g9,h9,i9,j9,k9,l9,m9,n9,o9,p9,q9,r9,s9,t9;
     23       if (n == 0) {
     24         if (active) invalidate();
     25       } else {
     26         bar(n);
     27       }`);
     28    bar = new Function('n', `
     29       var a0,b0,c0,d0,e0,f0,g0,h0,i0,j0,k0,l0,m0,n0,o0,p0,q0,r0,s0,t0,u0,v0,w0,x0,y0,z0;
     30       var a1,b1,c1,d1,e1,f1,g1,h1,i1,j1,k1,l1,m1,n1,o1,p1,q1,r1,s1,t1,u1,v1,w1,x1,y1,z1;
     31       var a2,b2,c2,d2,e2,f2,g2,h2,i2,j2,k2,l2,m2,n2,o2,p2,q2,r2,s2,t2,u2,v2,w2,x2,y2,z2;
     32       var a3,b3,c3,d3,e3,f3,g3,h3,i3,j3,k3,l3,m3,n3,o3,p3,q3,r3,s3,t3,u3,v3,w3,x3,y3,z3;
     33       var a4,b4,c4,d4,e4,f4,g4,h4,i4,j4,k4,l4,m4,n4,o4,p4,q4,r4,s4,t4,u4,v4,w4,x4,y4,z4;
     34       var a5,b5,c5,d5,e5,f5,g5,h5,i5,j5,k5,l5,m5,n5,o5,p5,q5,r5,s5,t5,u5,v5,w5,x5,y5,z5;
     35       var a6,b6,c6,d6,e6,f6,g6,h6,i6,j6,k6,l6,m6,n6,o6,p6,q6,r6,s6,t6,u6,v6,w6,x6,y6,z6;
     36       var a7,b7,c7,d7,e7,f7,g7,h7,i7,j7,k7,l7,m7,n7,o7,p7,q7,r7,s7,t7,u7,v7,w7,x7,y7,z7;
     37       var a8,b8,c8,d8,e8,f8,g8,h8,i8,j8,k8,l8,m8,n8,o8,p8,q8,r8,s8,t8,u8,v8,w8,x8,y8,z8;
     38       var a9,b9,c9,d9,e9,f9,g9,h9,i9,j9,k9,l9,m9,n9,o9,p9,q9,r9,s9,t9;
     39       foo(n-1);`);
     40 
     41    with ({}) {}
     42 
     43    // Warm up the invalidate() branch of foo to avoid FirstExecution bailouts.
     44    active = true;
     45    for (var i = 0; i < 10; i++) {
     46        foo(2);
     47    }
     48 
     49    // Warp-compile foo, inlining bar.
     50    active = false;
     51    for (var i = 0; i < 30; i++) {
     52        foo(2);
     53    }
     54 
     55    // Consume stack with frames that don't have to be invalidated.
     56    function recurse(n) {
     57        with ({}) {}
     58        if (n == 0) {
     59            foo(2);
     60        } else {
     61            recurse(n-1);
     62        }
     63    }
     64 
     65    // Trigger an invalidation.
     66    active = true;
     67    recurse(depth);
     68 }
     69 
     70 // Binary search to find the right recursion depth such that
     71 // the invalidation bailout will cause stack overflow.
     72 let depth = 0;
     73 function probeStackLimit(increment) {
     74    try {
     75        while (true) {
     76            test(depth + increment);
     77            depth += increment;
     78        }
     79    } catch {}
     80 }
     81 
     82 probeStackLimit(8192);
     83 probeStackLimit(4096);
     84 probeStackLimit(2048);
     85 probeStackLimit(1024);
     86 probeStackLimit(512);
     87 probeStackLimit(256);
     88 probeStackLimit(128);
     89 probeStackLimit(64);
     90 probeStackLimit(32);
     91 probeStackLimit(16);
     92 probeStackLimit(8);