stencil-eager-delazify.js (2114B)
1 // |jit-test| skip-if: helperThreadCount() === 0 || isLcovEnabled() 2 3 // Extra GCs can empty the StencilCache to reclaim memory. This lines 4 // re-configure the gc-zeal setting to prevent this from happening in this test 5 // case which waits for the cache to contain some entry. 6 if ('gczeal' in this) 7 gczeal(0); 8 9 let u = 0; 10 11 // At each function, create `width` inner functions. 12 let width = 2; 13 // Depth of inner functions. 14 let depth = 4; 15 // Number of additional parser & delazification workload running concurrently 16 // with the one we are attempting to measure, such that we can see differences 17 // in the report of `isDelazificationPopulatedFor`. 18 let load = 14; 19 20 // Return the number of function generated by a to `depthFirstExec` given the 21 // same parameters. 22 function count(w, d) { 23 return (Math.pow(w, d + 1) - 1) / (w - 1); 24 } 25 26 // Generate a source code with a large number of inner functions, such that 27 // eager delazification can be observe while running JS code concurrently. 28 function depthFirstExec(indent, name, w, d) { 29 let fun = `${indent}function ${name} (arg) {\n`; 30 let inner = ""; 31 let val = `arg + isDelazificationPopulatedFor(${name})`; 32 if (d > 0) { 33 for (let i = 0; i < w; i++) { 34 inner += depthFirstExec(`${indent} `, `${name}_${i}`, w, d - 1); 35 val = `${name}_${i}(${val})`; 36 } 37 } 38 fun += inner; 39 fun += `${indent} return ${u} + ${val} - ${u};\n`; 40 fun += `${indent}}\n`; 41 u += 1; 42 return fun; 43 }; 44 45 const options = { 46 fileName: "depthFirstExec.js", 47 lineNumber: 1, 48 eagerDelazificationStrategy: "ConcurrentDepthFirst", 49 }; 50 let script = depthFirstExec("", "raceMe", width, depth); 51 52 let jobs = []; 53 for (let i = 0; i < load; i++) { 54 // Spin up extra compilation workload... 55 jobs.push(offThreadCompileToStencil(script, options)); 56 } 57 58 const stencil = finishOffThreadStencil(jobs[0]); 59 evalStencil(stencil, options); 60 61 waitForDelazificationOf(raceMe); 62 let start = raceMe(0); 63 let mid = raceMe(0); 64 let end = raceMe(0); 65 66 assertEq(1 <= start, true); 67 assertEq(start <= mid, true); 68 assertEq(mid <= end, true); 69 assertEq(end <= count(width, depth), true); 70 print(start, mid, end);