OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "test/cctest/compiler/function-tester.h" | 7 #include "test/cctest/compiler/function-tester.h" |
8 | 8 |
9 #if V8_TURBOFAN_TARGET | 9 #if V8_TURBOFAN_TARGET |
10 | 10 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 CompilationInfo::kContextSpecializing | CompilationInfo::kTypingEnabled; | 44 CompilationInfo::kContextSpecializing | CompilationInfo::kTypingEnabled; |
45 | 45 |
46 const uint32_t kInlineFlags = CompilationInfo::kInliningEnabled | | 46 const uint32_t kInlineFlags = CompilationInfo::kInliningEnabled | |
47 CompilationInfo::kContextSpecializing | | 47 CompilationInfo::kContextSpecializing | |
48 CompilationInfo::kTypingEnabled; | 48 CompilationInfo::kTypingEnabled; |
49 | 49 |
50 } // namespace | 50 } // namespace |
51 | 51 |
52 | 52 |
53 TEST(SimpleInlining) { | 53 TEST(SimpleInlining) { |
54 FLAG_turbo_deoptimization = true; | |
55 FunctionTester T( | 54 FunctionTester T( |
56 "(function(){" | 55 "(function(){" |
57 " function foo(s) { AssertInlineCount(2); return s; };" | 56 " function foo(s) { AssertInlineCount(2); return s; };" |
58 " function bar(s, t) { return foo(s); };" | 57 " function bar(s, t) { return foo(s); };" |
59 " return bar;" | 58 " return bar;" |
60 "})();", | 59 "})();", |
61 kInlineFlags); | 60 kInlineFlags); |
62 | 61 |
63 InstallAssertInlineCountHelper(CcTest::isolate()); | 62 InstallAssertInlineCountHelper(CcTest::isolate()); |
64 T.CheckCall(T.Val(1), T.Val(1), T.Val(2)); | 63 T.CheckCall(T.Val(1), T.Val(1), T.Val(2)); |
65 } | 64 } |
66 | 65 |
67 | 66 |
68 TEST(SimpleInliningDeopt) { | 67 TEST(SimpleInliningDeopt) { |
69 FLAG_turbo_deoptimization = true; | |
70 FunctionTester T( | 68 FunctionTester T( |
71 "(function(){" | 69 "(function(){" |
72 " function foo(s) { %DeoptimizeFunction(bar); return s; };" | 70 " function foo(s) { %DeoptimizeFunction(bar); return s; };" |
73 " function bar(s, t) { return foo(s); };" | 71 " function bar(s, t) { return foo(s); };" |
74 " return bar;" | 72 " return bar;" |
75 "})();", | 73 "})();", |
76 kInlineFlags); | 74 kInlineFlags); |
77 | 75 |
78 InstallAssertInlineCountHelper(CcTest::isolate()); | 76 InstallAssertInlineCountHelper(CcTest::isolate()); |
79 T.CheckCall(T.Val(1), T.Val(1), T.Val(2)); | 77 T.CheckCall(T.Val(1), T.Val(1), T.Val(2)); |
80 } | 78 } |
81 | 79 |
82 | 80 |
83 TEST(SimpleInliningContext) { | 81 TEST(SimpleInliningContext) { |
84 FLAG_turbo_deoptimization = true; | |
85 FunctionTester T( | 82 FunctionTester T( |
86 "(function () {" | 83 "(function () {" |
87 " function foo(s) { AssertInlineCount(2); var x = 12; return s + x; };" | 84 " function foo(s) { AssertInlineCount(2); var x = 12; return s + x; };" |
88 " function bar(s, t) { return foo(s); };" | 85 " function bar(s, t) { return foo(s); };" |
89 " return bar;" | 86 " return bar;" |
90 "})();", | 87 "})();", |
91 kInlineFlags); | 88 kInlineFlags); |
92 | 89 |
93 InstallAssertInlineCountHelper(CcTest::isolate()); | 90 InstallAssertInlineCountHelper(CcTest::isolate()); |
94 T.CheckCall(T.Val(13), T.Val(1), T.Val(2)); | 91 T.CheckCall(T.Val(13), T.Val(1), T.Val(2)); |
95 } | 92 } |
96 | 93 |
97 | 94 |
98 TEST(SimpleInliningContextDeopt) { | 95 TEST(SimpleInliningContextDeopt) { |
99 FLAG_turbo_deoptimization = true; | |
100 FunctionTester T( | 96 FunctionTester T( |
101 "(function () {" | 97 "(function () {" |
102 " function foo(s) {" | 98 " function foo(s) {" |
103 " AssertInlineCount(2); %DeoptimizeFunction(bar); var x = 12;" | 99 " AssertInlineCount(2); %DeoptimizeFunction(bar); var x = 12;" |
104 " return s + x;" | 100 " return s + x;" |
105 " };" | 101 " };" |
106 " function bar(s, t) { return foo(s); };" | 102 " function bar(s, t) { return foo(s); };" |
107 " return bar;" | 103 " return bar;" |
108 "})();", | 104 "})();", |
109 kInlineFlags); | 105 kInlineFlags); |
110 | 106 |
111 InstallAssertInlineCountHelper(CcTest::isolate()); | 107 InstallAssertInlineCountHelper(CcTest::isolate()); |
112 T.CheckCall(T.Val(13), T.Val(1), T.Val(2)); | 108 T.CheckCall(T.Val(13), T.Val(1), T.Val(2)); |
113 } | 109 } |
114 | 110 |
115 | 111 |
116 TEST(CaptureContext) { | 112 TEST(CaptureContext) { |
117 FLAG_turbo_deoptimization = true; | |
118 FunctionTester T( | 113 FunctionTester T( |
119 "var f = (function () {" | 114 "var f = (function () {" |
120 " var x = 42;" | 115 " var x = 42;" |
121 " function bar(s) { return x + s; };" | 116 " function bar(s) { return x + s; };" |
122 " return (function (s) { return bar(s); });" | 117 " return (function (s) { return bar(s); });" |
123 "})();" | 118 "})();" |
124 "(function (s) { return f(s) })", | 119 "(function (s) { return f(s) })", |
125 kInlineFlags); | 120 kInlineFlags); |
126 | 121 |
127 InstallAssertInlineCountHelper(CcTest::isolate()); | 122 InstallAssertInlineCountHelper(CcTest::isolate()); |
128 T.CheckCall(T.Val(42 + 12), T.Val(12), T.undefined()); | 123 T.CheckCall(T.Val(42 + 12), T.Val(12), T.undefined()); |
129 } | 124 } |
130 | 125 |
131 | 126 |
132 // TODO(sigurds) For now we do not inline any native functions. If we do at | 127 // TODO(sigurds) For now we do not inline any native functions. If we do at |
133 // some point, change this test. | 128 // some point, change this test. |
134 TEST(DontInlineEval) { | 129 TEST(DontInlineEval) { |
135 FLAG_turbo_deoptimization = true; | |
136 FunctionTester T( | 130 FunctionTester T( |
137 "var x = 42;" | 131 "var x = 42;" |
138 "(function () {" | 132 "(function () {" |
139 " function bar(s, t) { return eval(\"AssertInlineCount(1); x\") };" | 133 " function bar(s, t) { return eval(\"AssertInlineCount(1); x\") };" |
140 " return bar;" | 134 " return bar;" |
141 "})();", | 135 "})();", |
142 kInlineFlags); | 136 kInlineFlags); |
143 | 137 |
144 InstallAssertInlineCountHelper(CcTest::isolate()); | 138 InstallAssertInlineCountHelper(CcTest::isolate()); |
145 T.CheckCall(T.Val(42), T.Val("x"), T.undefined()); | 139 T.CheckCall(T.Val(42), T.Val("x"), T.undefined()); |
146 } | 140 } |
147 | 141 |
148 | 142 |
149 TEST(InlineOmitArguments) { | 143 TEST(InlineOmitArguments) { |
150 FLAG_turbo_deoptimization = true; | |
151 FunctionTester T( | 144 FunctionTester T( |
152 "(function () {" | 145 "(function () {" |
153 " var x = 42;" | 146 " var x = 42;" |
154 " function bar(s, t, u, v) { AssertInlineCount(2); return x + s; };" | 147 " function bar(s, t, u, v) { AssertInlineCount(2); return x + s; };" |
155 " return (function (s,t) { return bar(s); });" | 148 " return (function (s,t) { return bar(s); });" |
156 "})();", | 149 "})();", |
157 kInlineFlags); | 150 kInlineFlags); |
158 | 151 |
159 InstallAssertInlineCountHelper(CcTest::isolate()); | 152 InstallAssertInlineCountHelper(CcTest::isolate()); |
160 T.CheckCall(T.Val(42 + 12), T.Val(12), T.undefined()); | 153 T.CheckCall(T.Val(42 + 12), T.Val(12), T.undefined()); |
161 } | 154 } |
162 | 155 |
163 | 156 |
164 TEST(InlineOmitArgumentsDeopt) { | 157 TEST(InlineOmitArgumentsDeopt) { |
165 FLAG_turbo_deoptimization = true; | |
166 FunctionTester T( | 158 FunctionTester T( |
167 "(function () {" | 159 "(function () {" |
168 " function foo(s,t,u,v) { AssertInlineCount(2);" | 160 " function foo(s,t,u,v) { AssertInlineCount(2);" |
169 " %DeoptimizeFunction(bar); return baz(); };" | 161 " %DeoptimizeFunction(bar); return baz(); };" |
170 " function bar() { return foo(11); };" | 162 " function bar() { return foo(11); };" |
171 " function baz() { return foo.arguments.length == 1 &&" | 163 " function baz() { return foo.arguments.length == 1 &&" |
172 " foo.arguments[0] == 11; }" | 164 " foo.arguments[0] == 11; }" |
173 " return bar;" | 165 " return bar;" |
174 "})();", | 166 "})();", |
175 kInlineFlags); | 167 kInlineFlags); |
176 | 168 |
177 InstallAssertInlineCountHelper(CcTest::isolate()); | 169 InstallAssertInlineCountHelper(CcTest::isolate()); |
178 T.CheckCall(T.true_value(), T.Val(12), T.Val(14)); | 170 T.CheckCall(T.true_value(), T.Val(12), T.Val(14)); |
179 } | 171 } |
180 | 172 |
181 | 173 |
182 TEST(InlineSurplusArguments) { | 174 TEST(InlineSurplusArguments) { |
183 FLAG_turbo_deoptimization = true; | |
184 FunctionTester T( | 175 FunctionTester T( |
185 "(function () {" | 176 "(function () {" |
186 " var x = 42;" | 177 " var x = 42;" |
187 " function foo(s) { AssertInlineCount(2); return x + s; };" | 178 " function foo(s) { AssertInlineCount(2); return x + s; };" |
188 " function bar(s,t) { return foo(s,t,13); };" | 179 " function bar(s,t) { return foo(s,t,13); };" |
189 " return bar;" | 180 " return bar;" |
190 "})();", | 181 "})();", |
191 kInlineFlags); | 182 kInlineFlags); |
192 | 183 |
193 InstallAssertInlineCountHelper(CcTest::isolate()); | 184 InstallAssertInlineCountHelper(CcTest::isolate()); |
194 T.CheckCall(T.Val(42 + 12), T.Val(12), T.undefined()); | 185 T.CheckCall(T.Val(42 + 12), T.Val(12), T.undefined()); |
195 } | 186 } |
196 | 187 |
197 | 188 |
198 TEST(InlineSurplusArgumentsDeopt) { | 189 TEST(InlineSurplusArgumentsDeopt) { |
199 FLAG_turbo_deoptimization = true; | |
200 FunctionTester T( | 190 FunctionTester T( |
201 "(function () {" | 191 "(function () {" |
202 " function foo(s) { AssertInlineCount(2); %DeoptimizeFunction(bar);" | 192 " function foo(s) { AssertInlineCount(2); %DeoptimizeFunction(bar);" |
203 " return baz(); };" | 193 " return baz(); };" |
204 " function bar() { return foo(13, 14, 15); };" | 194 " function bar() { return foo(13, 14, 15); };" |
205 " function baz() { return foo.arguments.length == 3 &&" | 195 " function baz() { return foo.arguments.length == 3 &&" |
206 " foo.arguments[0] == 13 &&" | 196 " foo.arguments[0] == 13 &&" |
207 " foo.arguments[1] == 14 &&" | 197 " foo.arguments[1] == 14 &&" |
208 " foo.arguments[2] == 15; }" | 198 " foo.arguments[2] == 15; }" |
209 " return bar;" | 199 " return bar;" |
210 "})();", | 200 "})();", |
211 kInlineFlags); | 201 kInlineFlags); |
212 | 202 |
213 InstallAssertInlineCountHelper(CcTest::isolate()); | 203 InstallAssertInlineCountHelper(CcTest::isolate()); |
214 T.CheckCall(T.true_value(), T.Val(12), T.Val(14)); | 204 T.CheckCall(T.true_value(), T.Val(12), T.Val(14)); |
215 } | 205 } |
216 | 206 |
217 | 207 |
218 TEST(InlineTwice) { | 208 TEST(InlineTwice) { |
219 FLAG_turbo_deoptimization = true; | |
220 FunctionTester T( | 209 FunctionTester T( |
221 "(function () {" | 210 "(function () {" |
222 " var x = 42;" | 211 " var x = 42;" |
223 " function bar(s) { AssertInlineCount(2); return x + s; };" | 212 " function bar(s) { AssertInlineCount(2); return x + s; };" |
224 " return (function (s,t) { return bar(s) + bar(t); });" | 213 " return (function (s,t) { return bar(s) + bar(t); });" |
225 "})();", | 214 "})();", |
226 kInlineFlags); | 215 kInlineFlags); |
227 | 216 |
228 InstallAssertInlineCountHelper(CcTest::isolate()); | 217 InstallAssertInlineCountHelper(CcTest::isolate()); |
229 T.CheckCall(T.Val(2 * 42 + 12 + 4), T.Val(12), T.Val(4)); | 218 T.CheckCall(T.Val(2 * 42 + 12 + 4), T.Val(12), T.Val(4)); |
230 } | 219 } |
231 | 220 |
232 | 221 |
233 TEST(InlineTwiceDependent) { | 222 TEST(InlineTwiceDependent) { |
234 FLAG_turbo_deoptimization = true; | |
235 FunctionTester T( | 223 FunctionTester T( |
236 "(function () {" | 224 "(function () {" |
237 " var x = 42;" | 225 " var x = 42;" |
238 " function foo(s) { AssertInlineCount(2); return x + s; };" | 226 " function foo(s) { AssertInlineCount(2); return x + s; };" |
239 " function bar(s,t) { return foo(foo(s)); };" | 227 " function bar(s,t) { return foo(foo(s)); };" |
240 " return bar;" | 228 " return bar;" |
241 "})();", | 229 "})();", |
242 kInlineFlags); | 230 kInlineFlags); |
243 | 231 |
244 InstallAssertInlineCountHelper(CcTest::isolate()); | 232 InstallAssertInlineCountHelper(CcTest::isolate()); |
245 T.CheckCall(T.Val(42 + 42 + 12), T.Val(12), T.Val(4)); | 233 T.CheckCall(T.Val(42 + 42 + 12), T.Val(12), T.Val(4)); |
246 } | 234 } |
247 | 235 |
248 | 236 |
249 TEST(InlineTwiceDependentDiamond) { | 237 TEST(InlineTwiceDependentDiamond) { |
250 FLAG_turbo_deoptimization = true; | |
251 FunctionTester T( | 238 FunctionTester T( |
252 "(function () {" | 239 "(function () {" |
253 " var x = 41;" | 240 " var x = 41;" |
254 " function foo(s) { AssertInlineCount(2); if (s % 2 == 0) {" | 241 " function foo(s) { AssertInlineCount(2); if (s % 2 == 0) {" |
255 " return x - s } else { return x + s; } };" | 242 " return x - s } else { return x + s; } };" |
256 " function bar(s,t) { return foo(foo(s)); };" | 243 " function bar(s,t) { return foo(foo(s)); };" |
257 " return bar;" | 244 " return bar;" |
258 "})();", | 245 "})();", |
259 kInlineFlags); | 246 kInlineFlags); |
260 | 247 |
261 InstallAssertInlineCountHelper(CcTest::isolate()); | 248 InstallAssertInlineCountHelper(CcTest::isolate()); |
262 T.CheckCall(T.Val(-11), T.Val(11), T.Val(4)); | 249 T.CheckCall(T.Val(-11), T.Val(11), T.Val(4)); |
263 } | 250 } |
264 | 251 |
265 | 252 |
266 TEST(InlineTwiceDependentDiamondDifferent) { | 253 TEST(InlineTwiceDependentDiamondDifferent) { |
267 FLAG_turbo_deoptimization = true; | |
268 FunctionTester T( | 254 FunctionTester T( |
269 "(function () {" | 255 "(function () {" |
270 " var x = 41;" | 256 " var x = 41;" |
271 " function foo(s,t) { AssertInlineCount(2); if (s % 2 == 0) {" | 257 " function foo(s,t) { AssertInlineCount(2); if (s % 2 == 0) {" |
272 " return x - s * t } else { return x + s * t; } };" | 258 " return x - s * t } else { return x + s * t; } };" |
273 " function bar(s,t) { return foo(foo(s, 3), 5); };" | 259 " function bar(s,t) { return foo(foo(s, 3), 5); };" |
274 " return bar;" | 260 " return bar;" |
275 "})();", | 261 "})();", |
276 kInlineFlags); | 262 kInlineFlags); |
277 | 263 |
278 InstallAssertInlineCountHelper(CcTest::isolate()); | 264 InstallAssertInlineCountHelper(CcTest::isolate()); |
279 T.CheckCall(T.Val(-329), T.Val(11), T.Val(4)); | 265 T.CheckCall(T.Val(-329), T.Val(11), T.Val(4)); |
280 } | 266 } |
281 | 267 |
282 | 268 |
283 TEST(InlineLoopGuardedEmpty) { | 269 TEST(InlineLoopGuardedEmpty) { |
284 FLAG_turbo_deoptimization = true; | |
285 FunctionTester T( | 270 FunctionTester T( |
286 "(function () {" | 271 "(function () {" |
287 " function foo(s) { AssertInlineCount(2); if (s) while (s); return s; };" | 272 " function foo(s) { AssertInlineCount(2); if (s) while (s); return s; };" |
288 " function bar(s,t) { return foo(s); };" | 273 " function bar(s,t) { return foo(s); };" |
289 " return bar;" | 274 " return bar;" |
290 "})();", | 275 "})();", |
291 kInlineFlags); | 276 kInlineFlags); |
292 | 277 |
293 InstallAssertInlineCountHelper(CcTest::isolate()); | 278 InstallAssertInlineCountHelper(CcTest::isolate()); |
294 T.CheckCall(T.Val(0.0), T.Val(0.0), T.Val(4)); | 279 T.CheckCall(T.Val(0.0), T.Val(0.0), T.Val(4)); |
295 } | 280 } |
296 | 281 |
297 | 282 |
298 TEST(InlineLoopGuardedOnce) { | 283 TEST(InlineLoopGuardedOnce) { |
299 FLAG_turbo_deoptimization = true; | |
300 FunctionTester T( | 284 FunctionTester T( |
301 "(function () {" | 285 "(function () {" |
302 " function foo(s,t) { AssertInlineCount(2); if (t > 0) while (s > 0) {" | 286 " function foo(s,t) { AssertInlineCount(2); if (t > 0) while (s > 0) {" |
303 " s = s - 1; }; return s; };" | 287 " s = s - 1; }; return s; };" |
304 " function bar(s,t) { return foo(s,t); };" | 288 " function bar(s,t) { return foo(s,t); };" |
305 " return bar;" | 289 " return bar;" |
306 "})();", | 290 "})();", |
307 kInlineFlags); | 291 kInlineFlags); |
308 | 292 |
309 InstallAssertInlineCountHelper(CcTest::isolate()); | 293 InstallAssertInlineCountHelper(CcTest::isolate()); |
310 T.CheckCall(T.Val(0.0), T.Val(11), T.Val(4)); | 294 T.CheckCall(T.Val(0.0), T.Val(11), T.Val(4)); |
311 } | 295 } |
312 | 296 |
313 | 297 |
314 TEST(InlineLoopGuardedTwice) { | 298 TEST(InlineLoopGuardedTwice) { |
315 FLAG_turbo_deoptimization = true; | |
316 FunctionTester T( | 299 FunctionTester T( |
317 "(function () {" | 300 "(function () {" |
318 " function foo(s,t) { AssertInlineCount(2); if (t > 0) while (s > 0) {" | 301 " function foo(s,t) { AssertInlineCount(2); if (t > 0) while (s > 0) {" |
319 " s = s - 1; }; return s; };" | 302 " s = s - 1; }; return s; };" |
320 " function bar(s,t) { return foo(foo(s,t),t); };" | 303 " function bar(s,t) { return foo(foo(s,t),t); };" |
321 " return bar;" | 304 " return bar;" |
322 "})();", | 305 "})();", |
323 kInlineFlags); | 306 kInlineFlags); |
324 | 307 |
325 InstallAssertInlineCountHelper(CcTest::isolate()); | 308 InstallAssertInlineCountHelper(CcTest::isolate()); |
326 T.CheckCall(T.Val(0.0), T.Val(11), T.Val(4)); | 309 T.CheckCall(T.Val(0.0), T.Val(11), T.Val(4)); |
327 } | 310 } |
328 | 311 |
329 | 312 |
330 TEST(InlineLoopUnguardedEmpty) { | 313 TEST(InlineLoopUnguardedEmpty) { |
331 FLAG_turbo_deoptimization = true; | |
332 FunctionTester T( | 314 FunctionTester T( |
333 "(function () {" | 315 "(function () {" |
334 " function foo(s) { AssertInlineCount(2); while (s); return s; };" | 316 " function foo(s) { AssertInlineCount(2); while (s); return s; };" |
335 " function bar(s, t) { return foo(s); };" | 317 " function bar(s, t) { return foo(s); };" |
336 " return bar;" | 318 " return bar;" |
337 "})();", | 319 "})();", |
338 kInlineFlags); | 320 kInlineFlags); |
339 | 321 |
340 InstallAssertInlineCountHelper(CcTest::isolate()); | 322 InstallAssertInlineCountHelper(CcTest::isolate()); |
341 T.CheckCall(T.Val(0.0), T.Val(0.0), T.Val(4)); | 323 T.CheckCall(T.Val(0.0), T.Val(0.0), T.Val(4)); |
342 } | 324 } |
343 | 325 |
344 | 326 |
345 TEST(InlineLoopUnguardedOnce) { | 327 TEST(InlineLoopUnguardedOnce) { |
346 FLAG_turbo_deoptimization = true; | |
347 FunctionTester T( | 328 FunctionTester T( |
348 "(function () {" | 329 "(function () {" |
349 " function foo(s) { AssertInlineCount(2); while (s) {" | 330 " function foo(s) { AssertInlineCount(2); while (s) {" |
350 " s = s - 1; }; return s; };" | 331 " s = s - 1; }; return s; };" |
351 " function bar(s, t) { return foo(s); };" | 332 " function bar(s, t) { return foo(s); };" |
352 " return bar;" | 333 " return bar;" |
353 "})();", | 334 "})();", |
354 kInlineFlags); | 335 kInlineFlags); |
355 | 336 |
356 InstallAssertInlineCountHelper(CcTest::isolate()); | 337 InstallAssertInlineCountHelper(CcTest::isolate()); |
357 T.CheckCall(T.Val(0.0), T.Val(0.0), T.Val(4)); | 338 T.CheckCall(T.Val(0.0), T.Val(0.0), T.Val(4)); |
358 } | 339 } |
359 | 340 |
360 | 341 |
361 TEST(InlineLoopUnguardedTwice) { | 342 TEST(InlineLoopUnguardedTwice) { |
362 FLAG_turbo_deoptimization = true; | |
363 FunctionTester T( | 343 FunctionTester T( |
364 "(function () {" | 344 "(function () {" |
365 " function foo(s) { AssertInlineCount(2); while (s > 0) {" | 345 " function foo(s) { AssertInlineCount(2); while (s > 0) {" |
366 " s = s - 1; }; return s; };" | 346 " s = s - 1; }; return s; };" |
367 " function bar(s,t) { return foo(foo(s,t),t); };" | 347 " function bar(s,t) { return foo(foo(s,t),t); };" |
368 " return bar;" | 348 " return bar;" |
369 "})();", | 349 "})();", |
370 kInlineFlags); | 350 kInlineFlags); |
371 | 351 |
372 InstallAssertInlineCountHelper(CcTest::isolate()); | 352 InstallAssertInlineCountHelper(CcTest::isolate()); |
373 T.CheckCall(T.Val(0.0), T.Val(0.0), T.Val(4)); | 353 T.CheckCall(T.Val(0.0), T.Val(0.0), T.Val(4)); |
374 } | 354 } |
375 | 355 |
376 | 356 |
377 TEST(InlineStrictIntoNonStrict) { | 357 TEST(InlineStrictIntoNonStrict) { |
378 FLAG_turbo_deoptimization = true; | |
379 FunctionTester T( | 358 FunctionTester T( |
380 "(function () {" | 359 "(function () {" |
381 " var x = Object.create({}, { y: { value:42, writable:false } });" | 360 " var x = Object.create({}, { y: { value:42, writable:false } });" |
382 " function foo(s) { 'use strict';" | 361 " function foo(s) { 'use strict';" |
383 " x.y = 9; };" | 362 " x.y = 9; };" |
384 " function bar(s,t) { return foo(s); };" | 363 " function bar(s,t) { return foo(s); };" |
385 " return bar;" | 364 " return bar;" |
386 "})();", | 365 "})();", |
387 kInlineFlags); | 366 kInlineFlags); |
388 | 367 |
389 InstallAssertInlineCountHelper(CcTest::isolate()); | 368 InstallAssertInlineCountHelper(CcTest::isolate()); |
390 T.CheckThrows(T.undefined(), T.undefined()); | 369 T.CheckThrows(T.undefined(), T.undefined()); |
391 } | 370 } |
392 | 371 |
393 | 372 |
394 TEST(InlineNonStrictIntoStrict) { | 373 TEST(InlineNonStrictIntoStrict) { |
395 FLAG_turbo_deoptimization = true; | |
396 FunctionTester T( | 374 FunctionTester T( |
397 "(function () {" | 375 "(function () {" |
398 " var x = Object.create({}, { y: { value:42, writable:false } });" | 376 " var x = Object.create({}, { y: { value:42, writable:false } });" |
399 " function foo(s) { x.y = 9; return x.y; };" | 377 " function foo(s) { x.y = 9; return x.y; };" |
400 " function bar(s,t) { \'use strict\'; return foo(s); };" | 378 " function bar(s,t) { \'use strict\'; return foo(s); };" |
401 " return bar;" | 379 " return bar;" |
402 "})();", | 380 "})();", |
403 kInlineFlags); | 381 kInlineFlags); |
404 | 382 |
405 InstallAssertInlineCountHelper(CcTest::isolate()); | 383 InstallAssertInlineCountHelper(CcTest::isolate()); |
406 T.CheckCall(T.Val(42), T.undefined(), T.undefined()); | 384 T.CheckCall(T.Val(42), T.undefined(), T.undefined()); |
407 } | 385 } |
408 | 386 |
409 | 387 |
410 TEST(InlineIntrinsicIsSmi) { | 388 TEST(InlineIntrinsicIsSmi) { |
411 FLAG_turbo_deoptimization = true; | |
412 FunctionTester T( | 389 FunctionTester T( |
413 "(function () {" | 390 "(function () {" |
414 " var x = 42;" | 391 " var x = 42;" |
415 " function bar(s,t) { return %_IsSmi(x); };" | 392 " function bar(s,t) { return %_IsSmi(x); };" |
416 " return bar;" | 393 " return bar;" |
417 "})();", | 394 "})();", |
418 kInlineFlags); | 395 kInlineFlags); |
419 | 396 |
420 InstallAssertInlineCountHelper(CcTest::isolate()); | 397 InstallAssertInlineCountHelper(CcTest::isolate()); |
421 T.CheckCall(T.true_value(), T.Val(12), T.Val(4)); | 398 T.CheckCall(T.true_value(), T.Val(12), T.Val(4)); |
422 } | 399 } |
423 | 400 |
424 | 401 |
425 TEST(InlineIntrinsicIsNonNegativeSmi) { | 402 TEST(InlineIntrinsicIsNonNegativeSmi) { |
426 FLAG_turbo_deoptimization = true; | |
427 FunctionTester T( | 403 FunctionTester T( |
428 "(function () {" | 404 "(function () {" |
429 " var x = 42;" | 405 " var x = 42;" |
430 " function bar(s,t) { return %_IsNonNegativeSmi(x); };" | 406 " function bar(s,t) { return %_IsNonNegativeSmi(x); };" |
431 " return bar;" | 407 " return bar;" |
432 "})();", | 408 "})();", |
433 kInlineFlags); | 409 kInlineFlags); |
434 | 410 |
435 InstallAssertInlineCountHelper(CcTest::isolate()); | 411 InstallAssertInlineCountHelper(CcTest::isolate()); |
436 T.CheckCall(T.true_value(), T.Val(12), T.Val(4)); | 412 T.CheckCall(T.true_value(), T.Val(12), T.Val(4)); |
437 } | 413 } |
438 | 414 |
439 | 415 |
440 TEST(InlineIntrinsicIsArray) { | 416 TEST(InlineIntrinsicIsArray) { |
441 FLAG_turbo_deoptimization = true; | |
442 FunctionTester T( | 417 FunctionTester T( |
443 "(function () {" | 418 "(function () {" |
444 " var x = [1,2,3];" | 419 " var x = [1,2,3];" |
445 " function bar(s,t) { return %_IsArray(x); };" | 420 " function bar(s,t) { return %_IsArray(x); };" |
446 " return bar;" | 421 " return bar;" |
447 "})();", | 422 "})();", |
448 kInlineFlags); | 423 kInlineFlags); |
449 | 424 |
450 InstallAssertInlineCountHelper(CcTest::isolate()); | 425 InstallAssertInlineCountHelper(CcTest::isolate()); |
451 T.CheckCall(T.true_value(), T.Val(12), T.Val(4)); | 426 T.CheckCall(T.true_value(), T.Val(12), T.Val(4)); |
(...skipping 14 matching lines...) Expand all Loading... |
466 " function bar(s,t) { return %_IsArray(x); };" | 441 " function bar(s,t) { return %_IsArray(x); };" |
467 " return bar;" | 442 " return bar;" |
468 "})();", | 443 "})();", |
469 kInlineFlags); | 444 kInlineFlags); |
470 | 445 |
471 T3.CheckCall(T.false_value(), T.Val(12), T.Val(4)); | 446 T3.CheckCall(T.false_value(), T.Val(12), T.Val(4)); |
472 } | 447 } |
473 | 448 |
474 | 449 |
475 TEST(InlineWithArguments) { | 450 TEST(InlineWithArguments) { |
476 FLAG_turbo_deoptimization = true; | |
477 FunctionTester T( | 451 FunctionTester T( |
478 "(function () {" | 452 "(function () {" |
479 " function foo(s,t,u) { AssertInlineCount(2);" | 453 " function foo(s,t,u) { AssertInlineCount(2);" |
480 " return foo.arguments.length == 3 &&" | 454 " return foo.arguments.length == 3 &&" |
481 " foo.arguments[0] == 13 &&" | 455 " foo.arguments[0] == 13 &&" |
482 " foo.arguments[1] == 14 &&" | 456 " foo.arguments[1] == 14 &&" |
483 " foo.arguments[2] == 15;" | 457 " foo.arguments[2] == 15;" |
484 " }" | 458 " }" |
485 " function bar() { return foo(13, 14, 15); };" | 459 " function bar() { return foo(13, 14, 15); };" |
486 " return bar;" | 460 " return bar;" |
487 "})();", | 461 "})();", |
488 kInlineFlags); | 462 kInlineFlags); |
489 | 463 |
490 InstallAssertInlineCountHelper(CcTest::isolate()); | 464 InstallAssertInlineCountHelper(CcTest::isolate()); |
491 T.CheckCall(T.true_value(), T.Val(12), T.Val(14)); | 465 T.CheckCall(T.true_value(), T.Val(12), T.Val(14)); |
492 } | 466 } |
493 | 467 |
494 | 468 |
495 TEST(InlineBuiltin) { | 469 TEST(InlineBuiltin) { |
496 FLAG_turbo_deoptimization = true; | |
497 FunctionTester T( | 470 FunctionTester T( |
498 "(function () {" | 471 "(function () {" |
499 " function foo(s,t,u) { AssertInlineCount(2); return true; }" | 472 " function foo(s,t,u) { AssertInlineCount(2); return true; }" |
500 " function bar() { return foo(); };" | 473 " function bar() { return foo(); };" |
501 " %SetForceInlineFlag(foo);" | 474 " %SetForceInlineFlag(foo);" |
502 " return bar;" | 475 " return bar;" |
503 "})();", | 476 "})();", |
504 kRestrictedInliningFlags); | 477 kRestrictedInliningFlags); |
505 | 478 |
506 InstallAssertInlineCountHelper(CcTest::isolate()); | 479 InstallAssertInlineCountHelper(CcTest::isolate()); |
507 T.CheckCall(T.true_value()); | 480 T.CheckCall(T.true_value()); |
508 } | 481 } |
509 | 482 |
510 | 483 |
511 TEST(InlineNestedBuiltin) { | 484 TEST(InlineNestedBuiltin) { |
512 FLAG_turbo_deoptimization = true; | |
513 FunctionTester T( | 485 FunctionTester T( |
514 "(function () {" | 486 "(function () {" |
515 " function foo(s,t,u) { AssertInlineCount(3); return true; }" | 487 " function foo(s,t,u) { AssertInlineCount(3); return true; }" |
516 " function baz(s,t,u) { return foo(s,t,u); }" | 488 " function baz(s,t,u) { return foo(s,t,u); }" |
517 " function bar() { return baz(); };" | 489 " function bar() { return baz(); };" |
518 " %SetForceInlineFlag(foo);" | 490 " %SetForceInlineFlag(foo);" |
519 " %SetForceInlineFlag(baz);" | 491 " %SetForceInlineFlag(baz);" |
520 " return bar;" | 492 " return bar;" |
521 "})();", | 493 "})();", |
522 kRestrictedInliningFlags); | 494 kRestrictedInliningFlags); |
523 | 495 |
524 InstallAssertInlineCountHelper(CcTest::isolate()); | 496 InstallAssertInlineCountHelper(CcTest::isolate()); |
525 T.CheckCall(T.true_value()); | 497 T.CheckCall(T.true_value()); |
526 } | 498 } |
527 | 499 |
528 | 500 |
529 TEST(StrongModeArity) { | 501 TEST(StrongModeArity) { |
530 FLAG_turbo_deoptimization = true; | |
531 FLAG_strong_mode = true; | 502 FLAG_strong_mode = true; |
532 FunctionTester T( | 503 FunctionTester T( |
533 "(function () {" | 504 "(function () {" |
534 " function foo(x, y) { 'use strong'; return x; }" | 505 " function foo(x, y) { 'use strong'; return x; }" |
535 " function bar(x, y) { return foo(x); }" | 506 " function bar(x, y) { return foo(x); }" |
536 " return bar;" | 507 " return bar;" |
537 "})();", | 508 "})();", |
538 kInlineFlags); | 509 kInlineFlags); |
539 T.CheckThrows(T.undefined(), T.undefined()); | 510 T.CheckThrows(T.undefined(), T.undefined()); |
540 } | 511 } |
541 | 512 |
542 | 513 |
543 TEST(StrongModeArityOuter) { | 514 TEST(StrongModeArityOuter) { |
544 FLAG_turbo_deoptimization = true; | |
545 FLAG_strong_mode = true; | 515 FLAG_strong_mode = true; |
546 FunctionTester T( | 516 FunctionTester T( |
547 "(function () {" | 517 "(function () {" |
548 " 'use strong';" | 518 " 'use strong';" |
549 " function foo(x, y) { return x; }" | 519 " function foo(x, y) { return x; }" |
550 " function bar(x, y) { return foo(x); }" | 520 " function bar(x, y) { return foo(x); }" |
551 " return bar;" | 521 " return bar;" |
552 "})();", | 522 "})();", |
553 kInlineFlags); | 523 kInlineFlags); |
554 T.CheckThrows(T.undefined(), T.undefined()); | 524 T.CheckThrows(T.undefined(), T.undefined()); |
555 } | 525 } |
| 526 |
556 #endif // V8_TURBOFAN_TARGET | 527 #endif // V8_TURBOFAN_TARGET |
OLD | NEW |