| 9 | |
| 10 | function runTest(f, message, mkICTraining, deoptArg, speculationCheck) { |
| 11 | function test(f, message, ictraining, deoptArg, speculationCheck) { |
| 12 | // Train the call ic to the maps. |
| 13 | let t = ictraining; |
| 14 | |
| 15 | // We put the training data into local variables |
| 16 | // to ensure their maps are kepts alive. If the |
| 17 | // maps die, gc *may* deoptimize {f}, which makes |
| 18 | // the test flaky. |
| 19 | let t1 = t(); |
| 20 | let t2 = t(); |
| 21 | let t3 = t(); |
| 22 | |
| 23 | %PrepareFunctionForOptimization(f); |
| 24 | for (let a of t1) { |
| 25 | f(a.arr, () => a.el); |
| 26 | } |
| 27 | for (let a of t2) { |
| 28 | f(a.arr, () => a.el); |
| 29 | } |
| 30 | %OptimizeFunctionOnNextCall(f); |
| 31 | message += " trained with" + JSON.stringify(t()); |
| 32 | if (deoptArg == undefined) { |
| 33 | // Make sure the optimized function can handle |
| 34 | // all trained maps without deopt. |
| 35 | for (let a of t3) { |
| 36 | message += " for args " + JSON.stringify(a) + " should have been optimized"; |
| 37 | f(a.arr, () => a.el); |
| 38 | assertOptimized(f, message); |
| 39 | } |
| 40 | } else { |
| 41 | // Trigger deopt, causing no-speculation bit to be set. |
| 42 | let a1 = deoptArg; |
| 43 | let a2 = deoptArg; |
| 44 | let a3 = deoptArg; |
| 45 | message += " for args " + JSON.stringify(a1); |
| 46 | message_unoptimized = message + " should have been unoptimized" |
| 47 | message_optimized = message + " should have been optimized" |
| 48 | f(a1.darr, () => a1.del); |
| 49 | assertUnoptimized(f, message_unoptimized); |
| 50 | if (speculationCheck) { |
| 51 | %PrepareFunctionForOptimization(f); |
| 52 | %OptimizeFunctionOnNextCall(f); |
| 53 | f(a2.darr, () => a2.del); |
| 54 | assertUnoptimized(f, message_unoptimized); |
| 55 | } |
| 56 | %PrepareFunctionForOptimization(f); |
| 57 | %OptimizeFunctionOnNextCall(f); |
| 58 | // No speculation should protect against further deopts. |
| 59 | f(a3.darr, () => a3.del); |
| 60 | assertOptimized(f, message_optimized); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | // Get function as a string. |
| 65 | var testString = test.toString(); |