Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1154)

Side by Side Diff: test/cctest/compiler/test-run-bytecode-graph-builder.cc

Issue 1699113002: [test] Shard some slower bytecode graph builder tests. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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 <utility> 5 #include <utility>
6 6
7 #include "src/compiler/pipeline.h" 7 #include "src/compiler/pipeline.h"
8 #include "src/execution.h" 8 #include "src/execution.h"
9 #include "src/handles.h" 9 #include "src/handles.h"
10 #include "src/interpreter/bytecode-array-builder.h" 10 #include "src/interpreter/bytecode-array-builder.h"
11 #include "src/interpreter/interpreter.h" 11 #include "src/interpreter/interpreter.h"
12 #include "src/parsing/parser.h" 12 #include "src/parsing/parser.h"
13 #include "test/cctest/cctest.h" 13 #include "test/cctest/cctest.h"
14 14
15 namespace v8 { 15 namespace v8 {
16 namespace internal { 16 namespace internal {
17 namespace compiler { 17 namespace compiler {
18 18
19 #define SHARD_TEST_BY_2(x) \
20 TEST(x##_0) { Test##x(0); } \
21 TEST(x##_1) { Test##x(1); }
22 #define SHARD_TEST_BY_4(x) \
23 TEST(x##_0) { Test##x(0); } \
24 TEST(x##_1) { Test##x(1); } \
25 TEST(x##_2) { Test##x(2); } \
26 TEST(x##_3) { Test##x(3); }
19 27
20 static const char kFunctionName[] = "f"; 28 static const char kFunctionName[] = "f";
21 29
22 static const Token::Value kCompareOperators[] = { 30 static const Token::Value kCompareOperators[] = {
23 Token::Value::EQ, Token::Value::NE, Token::Value::EQ_STRICT, 31 Token::Value::EQ, Token::Value::NE, Token::Value::EQ_STRICT,
24 Token::Value::NE_STRICT, Token::Value::LT, Token::Value::LTE, 32 Token::Value::NE_STRICT, Token::Value::LT, Token::Value::LTE,
25 Token::Value::GT, Token::Value::GTE}; 33 Token::Value::GT, Token::Value::GTE};
26 34
27 static const int SMI_MAX = (1 << 30) - 1; 35 static const int SMI_MAX = (1 << 30) - 1;
28 static const int SMI_MIN = -(1 << 30); 36 static const int SMI_MIN = -(1 << 30);
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 {"return -1;", {factory->NewNumberFromInt(-1)}}, 206 {"return -1;", {factory->NewNumberFromInt(-1)}},
199 {"return +127;", {factory->NewNumberFromInt(127)}}, 207 {"return +127;", {factory->NewNumberFromInt(127)}},
200 {"return -128;", {factory->NewNumberFromInt(-128)}}, 208 {"return -128;", {factory->NewNumberFromInt(-128)}},
201 {"return 0.001;", {factory->NewNumber(0.001)}}, 209 {"return 0.001;", {factory->NewNumber(0.001)}},
202 {"return 3.7e-60;", {factory->NewNumber(3.7e-60)}}, 210 {"return 3.7e-60;", {factory->NewNumber(3.7e-60)}},
203 {"return -3.7e60;", {factory->NewNumber(-3.7e60)}}, 211 {"return -3.7e60;", {factory->NewNumber(-3.7e60)}},
204 {"return '';", {factory->NewStringFromStaticChars("")}}, 212 {"return '';", {factory->NewStringFromStaticChars("")}},
205 {"return 'catfood';", {factory->NewStringFromStaticChars("catfood")}}, 213 {"return 'catfood';", {factory->NewStringFromStaticChars("catfood")}},
206 {"return NaN;", {factory->nan_value()}}}; 214 {"return NaN;", {factory->nan_value()}}};
207 215
208 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); 216 for (size_t i = 0; i < arraysize(snippets); i++) {
209 for (size_t i = 0; i < num_snippets; i++) {
210 ScopedVector<char> script(1024); 217 ScopedVector<char> script(1024);
211 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, 218 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName,
212 snippets[i].code_snippet, kFunctionName); 219 snippets[i].code_snippet, kFunctionName);
213 220
214 BytecodeGraphTester tester(isolate, zone, script.start()); 221 BytecodeGraphTester tester(isolate, zone, script.start());
215 auto callable = tester.GetCallable<>(); 222 auto callable = tester.GetCallable<>();
216 Handle<Object> return_value = callable().ToHandleChecked(); 223 Handle<Object> return_value = callable().ToHandleChecked();
217 CHECK(return_value->SameValue(*snippets[i].return_value())); 224 CHECK(return_value->SameValue(*snippets[i].return_value()));
218 } 225 }
219 } 226 }
220 227
221 228
222 TEST(BytecodeGraphBuilderPrimitiveExpressions) { 229 TEST(BytecodeGraphBuilderPrimitiveExpressions) {
223 HandleAndZoneScope scope; 230 HandleAndZoneScope scope;
224 Isolate* isolate = scope.main_isolate(); 231 Isolate* isolate = scope.main_isolate();
225 Zone* zone = scope.main_zone(); 232 Zone* zone = scope.main_zone();
226 Factory* factory = isolate->factory(); 233 Factory* factory = isolate->factory();
227 234
228 ExpectedSnippet<0> snippets[] = { 235 ExpectedSnippet<0> snippets[] = {
229 {"return 1 + 1;", {factory->NewNumberFromInt(2)}}, 236 {"return 1 + 1;", {factory->NewNumberFromInt(2)}},
230 {"return 20 - 30;", {factory->NewNumberFromInt(-10)}}, 237 {"return 20 - 30;", {factory->NewNumberFromInt(-10)}},
231 {"return 4 * 100;", {factory->NewNumberFromInt(400)}}, 238 {"return 4 * 100;", {factory->NewNumberFromInt(400)}},
232 {"return 100 / 5;", {factory->NewNumberFromInt(20)}}, 239 {"return 100 / 5;", {factory->NewNumberFromInt(20)}},
233 {"return 25 % 7;", {factory->NewNumberFromInt(4)}}, 240 {"return 25 % 7;", {factory->NewNumberFromInt(4)}},
234 }; 241 };
235 242
236 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); 243 for (size_t i = 0; i < arraysize(snippets); i++) {
237 for (size_t i = 0; i < num_snippets; i++) {
238 ScopedVector<char> script(1024); 244 ScopedVector<char> script(1024);
239 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, 245 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName,
240 snippets[i].code_snippet, kFunctionName); 246 snippets[i].code_snippet, kFunctionName);
241 247
242 BytecodeGraphTester tester(isolate, zone, script.start()); 248 BytecodeGraphTester tester(isolate, zone, script.start());
243 auto callable = tester.GetCallable<>(); 249 auto callable = tester.GetCallable<>();
244 Handle<Object> return_value = callable().ToHandleChecked(); 250 Handle<Object> return_value = callable().ToHandleChecked();
245 CHECK(return_value->SameValue(*snippets[i].return_value())); 251 CHECK(return_value->SameValue(*snippets[i].return_value()));
246 } 252 }
247 } 253 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 factory->NewHeapNumber(6.666)}}, 291 factory->NewHeapNumber(6.666)}},
286 {"return p1 / p2;", 292 {"return p1 / p2;",
287 {factory->NewHeapNumber(2.25), factory->NewHeapNumber(9), 293 {factory->NewHeapNumber(2.25), factory->NewHeapNumber(9),
288 factory->NewHeapNumber(4)}}, 294 factory->NewHeapNumber(4)}},
289 // Strings 295 // Strings
290 {"return p1 + p2;", 296 {"return p1 + p2;",
291 {factory->NewStringFromStaticChars("abcdef"), 297 {factory->NewStringFromStaticChars("abcdef"),
292 factory->NewStringFromStaticChars("abc"), 298 factory->NewStringFromStaticChars("abc"),
293 factory->NewStringFromStaticChars("def")}}}; 299 factory->NewStringFromStaticChars("def")}}};
294 300
295 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); 301 for (size_t i = 0; i < arraysize(snippets); i++) {
296 for (size_t i = 0; i < num_snippets; i++) {
297 ScopedVector<char> script(1024); 302 ScopedVector<char> script(1024);
298 SNPrintF(script, "function %s(p1, p2) { %s }\n%s(0, 0);", kFunctionName, 303 SNPrintF(script, "function %s(p1, p2) { %s }\n%s(0, 0);", kFunctionName,
299 snippets[i].code_snippet, kFunctionName); 304 snippets[i].code_snippet, kFunctionName);
300 305
301 BytecodeGraphTester tester(isolate, zone, script.start()); 306 BytecodeGraphTester tester(isolate, zone, script.start());
302 auto callable = tester.GetCallable<Handle<Object>, Handle<Object>>(); 307 auto callable = tester.GetCallable<Handle<Object>, Handle<Object>>();
303 Handle<Object> return_value = 308 Handle<Object> return_value =
304 callable(snippets[i].parameter(0), snippets[i].parameter(1)) 309 callable(snippets[i].parameter(0), snippets[i].parameter(1))
305 .ToHandleChecked(); 310 .ToHandleChecked();
306 CHECK(return_value->SameValue(*snippets[i].return_value())); 311 CHECK(return_value->SameValue(*snippets[i].return_value()));
(...skipping 23 matching lines...) Expand all
330 {"var b;\n" REPEAT_127(SPACE, " b = p1.name; ") " return p1.name;\n", 335 {"var b;\n" REPEAT_127(SPACE, " b = p1.name; ") " return p1.name;\n",
331 {factory->NewStringFromStaticChars("abc"), 336 {factory->NewStringFromStaticChars("abc"),
332 BytecodeGraphTester::NewObject("({name : 'abc'})")}}, 337 BytecodeGraphTester::NewObject("({name : 'abc'})")}},
333 {"'use strict'; var b;\n" 338 {"'use strict'; var b;\n"
334 REPEAT_127(SPACE, " b = p1.name; ") 339 REPEAT_127(SPACE, " b = p1.name; ")
335 "return p1.name;\n", 340 "return p1.name;\n",
336 {factory->NewStringFromStaticChars("abc"), 341 {factory->NewStringFromStaticChars("abc"),
337 BytecodeGraphTester::NewObject("({ name : 'abc'})")}}, 342 BytecodeGraphTester::NewObject("({ name : 'abc'})")}},
338 }; 343 };
339 344
340 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); 345 for (size_t i = 0; i < arraysize(snippets); i++) {
341 for (size_t i = 0; i < num_snippets; i++) {
342 ScopedVector<char> script(2048); 346 ScopedVector<char> script(2048);
343 SNPrintF(script, "function %s(p1) { %s };\n%s(0);", kFunctionName, 347 SNPrintF(script, "function %s(p1) { %s };\n%s(0);", kFunctionName,
344 snippets[i].code_snippet, kFunctionName); 348 snippets[i].code_snippet, kFunctionName);
345 349
346 BytecodeGraphTester tester(isolate, zone, script.start()); 350 BytecodeGraphTester tester(isolate, zone, script.start());
347 auto callable = tester.GetCallable<Handle<Object>>(); 351 auto callable = tester.GetCallable<Handle<Object>>();
348 Handle<Object> return_value = 352 Handle<Object> return_value =
349 callable(snippets[i].parameter(0)).ToHandleChecked(); 353 callable(snippets[i].parameter(0)).ToHandleChecked();
350 CHECK(return_value->SameValue(*snippets[i].return_value())); 354 CHECK(return_value->SameValue(*snippets[i].return_value()));
351 } 355 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 {factory->NewStringFromStaticChars("abc"), 391 {factory->NewStringFromStaticChars("abc"),
388 BytecodeGraphTester::NewObject("({100 : 'abc'})"), 392 BytecodeGraphTester::NewObject("({100 : 'abc'})"),
389 factory->NewNumberFromInt(100)}}, 393 factory->NewNumberFromInt(100)}},
390 {"'use strict'; var b;\n" REPEAT_127(SPACE, 394 {"'use strict'; var b;\n" REPEAT_127(SPACE,
391 " b = p1[p2]; ") "return p1[p2];\n", 395 " b = p1[p2]; ") "return p1[p2];\n",
392 {factory->NewStringFromStaticChars("abc"), 396 {factory->NewStringFromStaticChars("abc"),
393 BytecodeGraphTester::NewObject("({ 100 : 'abc'})"), 397 BytecodeGraphTester::NewObject("({ 100 : 'abc'})"),
394 factory->NewNumberFromInt(100)}}, 398 factory->NewNumberFromInt(100)}},
395 }; 399 };
396 400
397 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); 401 for (size_t i = 0; i < arraysize(snippets); i++) {
398 for (size_t i = 0; i < num_snippets; i++) {
399 ScopedVector<char> script(2048); 402 ScopedVector<char> script(2048);
400 SNPrintF(script, "function %s(p1, p2) { %s };\n%s(0);", kFunctionName, 403 SNPrintF(script, "function %s(p1, p2) { %s };\n%s(0);", kFunctionName,
401 snippets[i].code_snippet, kFunctionName); 404 snippets[i].code_snippet, kFunctionName);
402 405
403 BytecodeGraphTester tester(isolate, zone, script.start()); 406 BytecodeGraphTester tester(isolate, zone, script.start());
404 auto callable = tester.GetCallable<Handle<Object>, Handle<Object>>(); 407 auto callable = tester.GetCallable<Handle<Object>, Handle<Object>>();
405 Handle<Object> return_value = 408 Handle<Object> return_value =
406 callable(snippets[i].parameter(0), snippets[i].parameter(1)) 409 callable(snippets[i].parameter(0), snippets[i].parameter(1))
407 .ToHandleChecked(); 410 .ToHandleChecked();
408 CHECK(return_value->SameValue(*snippets[i].return_value())); 411 CHECK(return_value->SameValue(*snippets[i].return_value()));
409 } 412 }
410 } 413 }
411 414
412 415 void TestBytecodeGraphBuilderNamedStore(size_t shard) {
413 TEST(BytecodeGraphBuilderNamedStore) {
414 HandleAndZoneScope scope; 416 HandleAndZoneScope scope;
415 Isolate* isolate = scope.main_isolate(); 417 Isolate* isolate = scope.main_isolate();
416 Zone* zone = scope.main_zone(); 418 Zone* zone = scope.main_zone();
417 Factory* factory = isolate->factory(); 419 Factory* factory = isolate->factory();
418 420
419 ExpectedSnippet<1> snippets[] = { 421 ExpectedSnippet<1> snippets[] = {
420 {"return p1.val = 20;", 422 {"return p1.val = 20;",
421 {factory->NewNumberFromInt(20), 423 {factory->NewNumberFromInt(20),
422 BytecodeGraphTester::NewObject("({val : 10})")}}, 424 BytecodeGraphTester::NewObject("({val : 10})")}},
423 {"p1.type = 'int'; return p1.type;", 425 {"p1.type = 'int'; return p1.type;",
(...skipping 14 matching lines...) Expand all
438 {"var b = 'abc';\n" REPEAT_127( 440 {"var b = 'abc';\n" REPEAT_127(
439 SPACE, " p1.name = b; ") " p1.name = 'def'; return p1.name;\n", 441 SPACE, " p1.name = b; ") " p1.name = 'def'; return p1.name;\n",
440 {factory->NewStringFromStaticChars("def"), 442 {factory->NewStringFromStaticChars("def"),
441 BytecodeGraphTester::NewObject("({name : 'abc'})")}}, 443 BytecodeGraphTester::NewObject("({name : 'abc'})")}},
442 {"'use strict'; var b = 'def';\n" REPEAT_127( 444 {"'use strict'; var b = 'def';\n" REPEAT_127(
443 SPACE, " p1.name = 'abc'; ") "p1.name = b; return p1.name;\n", 445 SPACE, " p1.name = 'abc'; ") "p1.name = b; return p1.name;\n",
444 {factory->NewStringFromStaticChars("def"), 446 {factory->NewStringFromStaticChars("def"),
445 BytecodeGraphTester::NewObject("({ name : 'abc'})")}}, 447 BytecodeGraphTester::NewObject("({ name : 'abc'})")}},
446 }; 448 };
447 449
448 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); 450 for (size_t i = 0; i < arraysize(snippets); i++) {
449 for (size_t i = 0; i < num_snippets; i++) { 451 if ((i % 2) != shard) continue;
450 ScopedVector<char> script(3072); 452 ScopedVector<char> script(3072);
451 SNPrintF(script, "function %s(p1) { %s };\n%s({});", kFunctionName, 453 SNPrintF(script, "function %s(p1) { %s };\n%s({});", kFunctionName,
452 snippets[i].code_snippet, kFunctionName); 454 snippets[i].code_snippet, kFunctionName);
453 455
454 BytecodeGraphTester tester(isolate, zone, script.start()); 456 BytecodeGraphTester tester(isolate, zone, script.start());
455 auto callable = tester.GetCallable<Handle<Object>>(); 457 auto callable = tester.GetCallable<Handle<Object>>();
456 Handle<Object> return_value = 458 Handle<Object> return_value =
457 callable(snippets[i].parameter(0)).ToHandleChecked(); 459 callable(snippets[i].parameter(0)).ToHandleChecked();
458 CHECK(return_value->SameValue(*snippets[i].return_value())); 460 CHECK(return_value->SameValue(*snippets[i].return_value()));
459 } 461 }
460 } 462 }
461 463
464 SHARD_TEST_BY_2(BytecodeGraphBuilderNamedStore)
462 465
463 TEST(BytecodeGraphBuilderKeyedStore) { 466 void TestBytecodeGraphBuilderKeyedStore(size_t shard) {
464 HandleAndZoneScope scope; 467 HandleAndZoneScope scope;
465 Isolate* isolate = scope.main_isolate(); 468 Isolate* isolate = scope.main_isolate();
466 Zone* zone = scope.main_zone(); 469 Zone* zone = scope.main_zone();
467 Factory* factory = isolate->factory(); 470 Factory* factory = isolate->factory();
468 471
469 ExpectedSnippet<2> snippets[] = { 472 ExpectedSnippet<2> snippets[] = {
470 {"p1[p2] = 20; return p1[p2];", 473 {"p1[p2] = 20; return p1[p2];",
471 {factory->NewNumberFromInt(20), 474 {factory->NewNumberFromInt(20),
472 BytecodeGraphTester::NewObject("({val : 10})"), 475 BytecodeGraphTester::NewObject("({val : 10})"),
473 factory->NewStringFromStaticChars("val")}}, 476 factory->NewStringFromStaticChars("val")}},
(...skipping 22 matching lines...) Expand all
496 {factory->NewStringFromStaticChars("def"), 499 {factory->NewStringFromStaticChars("def"),
497 BytecodeGraphTester::NewObject("({100 : 'abc'})"), 500 BytecodeGraphTester::NewObject("({100 : 'abc'})"),
498 factory->NewNumberFromInt(100)}}, 501 factory->NewNumberFromInt(100)}},
499 {"'use strict'; var b;\n" REPEAT_127( 502 {"'use strict'; var b;\n" REPEAT_127(
500 SPACE, " b = p1[p2]; ") " p1[p2] = 'def'; return p1[p2];\n", 503 SPACE, " b = p1[p2]; ") " p1[p2] = 'def'; return p1[p2];\n",
501 {factory->NewStringFromStaticChars("def"), 504 {factory->NewStringFromStaticChars("def"),
502 BytecodeGraphTester::NewObject("({ 100 : 'abc'})"), 505 BytecodeGraphTester::NewObject("({ 100 : 'abc'})"),
503 factory->NewNumberFromInt(100)}}, 506 factory->NewNumberFromInt(100)}},
504 }; 507 };
505 508
506 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); 509 for (size_t i = 0; i < arraysize(snippets); i++) {
507 for (size_t i = 0; i < num_snippets; i++) { 510 if ((i % 2) != shard) continue;
508 ScopedVector<char> script(2048); 511 ScopedVector<char> script(2048);
509 SNPrintF(script, "function %s(p1, p2) { %s };\n%s({});", kFunctionName, 512 SNPrintF(script, "function %s(p1, p2) { %s };\n%s({});", kFunctionName,
510 snippets[i].code_snippet, kFunctionName); 513 snippets[i].code_snippet, kFunctionName);
511 514
512 BytecodeGraphTester tester(isolate, zone, script.start()); 515 BytecodeGraphTester tester(isolate, zone, script.start());
513 auto callable = tester.GetCallable<Handle<Object>>(); 516 auto callable = tester.GetCallable<Handle<Object>>();
514 Handle<Object> return_value = 517 Handle<Object> return_value =
515 callable(snippets[i].parameter(0)).ToHandleChecked(); 518 callable(snippets[i].parameter(0)).ToHandleChecked();
516 CHECK(return_value->SameValue(*snippets[i].return_value())); 519 CHECK(return_value->SameValue(*snippets[i].return_value()));
517 } 520 }
518 } 521 }
519 522
523 SHARD_TEST_BY_2(BytecodeGraphBuilderKeyedStore)
520 524
521 TEST(BytecodeGraphBuilderPropertyCall) { 525 TEST(BytecodeGraphBuilderPropertyCall) {
522 HandleAndZoneScope scope; 526 HandleAndZoneScope scope;
523 Isolate* isolate = scope.main_isolate(); 527 Isolate* isolate = scope.main_isolate();
524 Zone* zone = scope.main_zone(); 528 Zone* zone = scope.main_zone();
525 Factory* factory = isolate->factory(); 529 Factory* factory = isolate->factory();
526 530
527 ExpectedSnippet<1> snippets[] = { 531 ExpectedSnippet<1> snippets[] = {
528 {"return p1.func();", 532 {"return p1.func();",
529 {factory->NewNumberFromInt(25), 533 {factory->NewNumberFromInt(25),
530 BytecodeGraphTester::NewObject("({func() { return 25; }})")}}, 534 BytecodeGraphTester::NewObject("({func() { return 25; }})")}},
531 {"return p1.func('abc');", 535 {"return p1.func('abc');",
532 {factory->NewStringFromStaticChars("abc"), 536 {factory->NewStringFromStaticChars("abc"),
533 BytecodeGraphTester::NewObject("({func(a) { return a; }})")}}, 537 BytecodeGraphTester::NewObject("({func(a) { return a; }})")}},
534 {"return p1.func(1, 2, 3, 4, 5, 6, 7, 8);", 538 {"return p1.func(1, 2, 3, 4, 5, 6, 7, 8);",
535 {factory->NewNumberFromInt(36), 539 {factory->NewNumberFromInt(36),
536 BytecodeGraphTester::NewObject( 540 BytecodeGraphTester::NewObject(
537 "({func(a, b, c, d, e, f, g, h) {\n" 541 "({func(a, b, c, d, e, f, g, h) {\n"
538 " return a + b + c + d + e + f + g + h;}})")}}, 542 " return a + b + c + d + e + f + g + h;}})")}},
539 }; 543 };
540 544
541 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); 545 for (size_t i = 0; i < arraysize(snippets); i++) {
542 for (size_t i = 0; i < num_snippets; i++) {
543 ScopedVector<char> script(2048); 546 ScopedVector<char> script(2048);
544 SNPrintF(script, "function %s(p1) { %s };\n%s({func() {}});", kFunctionName, 547 SNPrintF(script, "function %s(p1) { %s };\n%s({func() {}});", kFunctionName,
545 snippets[i].code_snippet, kFunctionName); 548 snippets[i].code_snippet, kFunctionName);
546 549
547 BytecodeGraphTester tester(isolate, zone, script.start()); 550 BytecodeGraphTester tester(isolate, zone, script.start());
548 auto callable = tester.GetCallable<Handle<Object>>(); 551 auto callable = tester.GetCallable<Handle<Object>>();
549 Handle<Object> return_value = 552 Handle<Object> return_value =
550 callable(snippets[i].parameter(0)).ToHandleChecked(); 553 callable(snippets[i].parameter(0)).ToHandleChecked();
551 CHECK(return_value->SameValue(*snippets[i].return_value())); 554 CHECK(return_value->SameValue(*snippets[i].return_value()));
552 } 555 }
(...skipping 22 matching lines...) Expand all
575 {"function counter(arg0, arg1) {\n" 578 {"function counter(arg0, arg1) {\n"
576 " this.count = 17; this.x = arg0; this.y = arg1;\n" 579 " this.count = 17; this.x = arg0; this.y = arg1;\n"
577 "}\n" 580 "}\n"
578 "function f() {\n" 581 "function f() {\n"
579 " var c = new counter(3, 5);\n" 582 " var c = new counter(3, 5);\n"
580 " return c.count + c.x + c.y;\n" 583 " return c.count + c.x + c.y;\n"
581 "}; f()", 584 "}; f()",
582 {factory->NewNumberFromInt(25)}}, 585 {factory->NewNumberFromInt(25)}},
583 }; 586 };
584 587
585 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); 588 for (size_t i = 0; i < arraysize(snippets); i++) {
586 for (size_t i = 0; i < num_snippets; i++) {
587 BytecodeGraphTester tester(isolate, zone, snippets[i].code_snippet); 589 BytecodeGraphTester tester(isolate, zone, snippets[i].code_snippet);
588 auto callable = tester.GetCallable<>(); 590 auto callable = tester.GetCallable<>();
589 Handle<Object> return_value = callable().ToHandleChecked(); 591 Handle<Object> return_value = callable().ToHandleChecked();
590 CHECK(return_value->SameValue(*snippets[i].return_value())); 592 CHECK(return_value->SameValue(*snippets[i].return_value()));
591 } 593 }
592 } 594 }
593 595
594 596
595 TEST(BytecodeGraphBuilderCreateClosure) { 597 TEST(BytecodeGraphBuilderCreateClosure) {
596 HandleAndZoneScope scope; 598 HandleAndZoneScope scope;
(...skipping 17 matching lines...) Expand all
614 {"function f() {\n" 616 {"function f() {\n"
615 " function counter(arg0, arg1) {\n" 617 " function counter(arg0, arg1) {\n"
616 " this.count = 17; this.x = arg0; this.y = arg1;\n" 618 " this.count = 17; this.x = arg0; this.y = arg1;\n"
617 " }\n" 619 " }\n"
618 " var c = new counter(3, 5);\n" 620 " var c = new counter(3, 5);\n"
619 " return c.count + c.x + c.y;\n" 621 " return c.count + c.x + c.y;\n"
620 "}; f()", 622 "}; f()",
621 {factory->NewNumberFromInt(25)}}, 623 {factory->NewNumberFromInt(25)}},
622 }; 624 };
623 625
624 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); 626 for (size_t i = 0; i < arraysize(snippets); i++) {
625 for (size_t i = 0; i < num_snippets; i++) {
626 BytecodeGraphTester tester(isolate, zone, snippets[i].code_snippet); 627 BytecodeGraphTester tester(isolate, zone, snippets[i].code_snippet);
627 auto callable = tester.GetCallable<>(); 628 auto callable = tester.GetCallable<>();
628 Handle<Object> return_value = callable().ToHandleChecked(); 629 Handle<Object> return_value = callable().ToHandleChecked();
629 CHECK(return_value->SameValue(*snippets[i].return_value())); 630 CHECK(return_value->SameValue(*snippets[i].return_value()));
630 } 631 }
631 } 632 }
632 633
633 634
634 TEST(BytecodeGraphBuilderCallRuntime) { 635 TEST(BytecodeGraphBuilderCallRuntime) {
635 HandleAndZoneScope scope; 636 HandleAndZoneScope scope;
636 Isolate* isolate = scope.main_isolate(); 637 Isolate* isolate = scope.main_isolate();
637 Zone* zone = scope.main_zone(); 638 Zone* zone = scope.main_zone();
638 Factory* factory = isolate->factory(); 639 Factory* factory = isolate->factory();
639 640
640 ExpectedSnippet<1> snippets[] = { 641 ExpectedSnippet<1> snippets[] = {
641 {"function f(arg0) { return %MaxSmi(); }\nf()", 642 {"function f(arg0) { return %MaxSmi(); }\nf()",
642 {factory->NewNumberFromInt(Smi::kMaxValue), factory->undefined_value()}}, 643 {factory->NewNumberFromInt(Smi::kMaxValue), factory->undefined_value()}},
643 {"function f(arg0) { return %IsArray(arg0) }\nf(undefined)", 644 {"function f(arg0) { return %IsArray(arg0) }\nf(undefined)",
644 {factory->true_value(), BytecodeGraphTester::NewObject("[1, 2, 3]")}}, 645 {factory->true_value(), BytecodeGraphTester::NewObject("[1, 2, 3]")}},
645 {"function f(arg0) { return %Add(arg0, 2) }\nf(1)", 646 {"function f(arg0) { return %Add(arg0, 2) }\nf(1)",
646 {factory->NewNumberFromInt(5), factory->NewNumberFromInt(3)}}, 647 {factory->NewNumberFromInt(5), factory->NewNumberFromInt(3)}},
647 {"function f(arg0) { return %spread_arguments(arg0).length }\nf([])", 648 {"function f(arg0) { return %spread_arguments(arg0).length }\nf([])",
648 {factory->NewNumberFromInt(3), 649 {factory->NewNumberFromInt(3),
649 BytecodeGraphTester::NewObject("[1, 2, 3]")}}, 650 BytecodeGraphTester::NewObject("[1, 2, 3]")}},
650 }; 651 };
651 652
652 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); 653 for (size_t i = 0; i < arraysize(snippets); i++) {
653 for (size_t i = 0; i < num_snippets; i++) {
654 BytecodeGraphTester tester(isolate, zone, snippets[i].code_snippet); 654 BytecodeGraphTester tester(isolate, zone, snippets[i].code_snippet);
655 auto callable = tester.GetCallable<Handle<Object>>(); 655 auto callable = tester.GetCallable<Handle<Object>>();
656 Handle<Object> return_value = 656 Handle<Object> return_value =
657 callable(snippets[i].parameter(0)).ToHandleChecked(); 657 callable(snippets[i].parameter(0)).ToHandleChecked();
658 CHECK(return_value->SameValue(*snippets[i].return_value())); 658 CHECK(return_value->SameValue(*snippets[i].return_value()));
659 } 659 }
660 } 660 }
661 661
662 662 void TestBytecodeGraphBuilderGlobals(size_t shard) {
663 TEST(BytecodeGraphBuilderGlobals) {
664 HandleAndZoneScope scope; 663 HandleAndZoneScope scope;
665 Isolate* isolate = scope.main_isolate(); 664 Isolate* isolate = scope.main_isolate();
666 Zone* zone = scope.main_zone(); 665 Zone* zone = scope.main_zone();
667 Factory* factory = isolate->factory(); 666 Factory* factory = isolate->factory();
668 667
669 ExpectedSnippet<0> snippets[] = { 668 ExpectedSnippet<0> snippets[] = {
670 {"var global = 321;\n function f() { return global; };\n f();", 669 {"var global = 321;\n function f() { return global; };\n f();",
671 {factory->NewNumberFromInt(321)}}, 670 {factory->NewNumberFromInt(321)}},
672 {"var global = 321;\n" 671 {"var global = 321;\n"
673 "function f() { global = 123; return global };\n f();", 672 "function f() { global = 123; return global };\n f();",
(...skipping 19 matching lines...) Expand all
693 SPACE, " var b = global_obj.name;\n") "global = 'xyz'; return " 692 SPACE, " var b = global_obj.name;\n") "global = 'xyz'; return "
694 "global };\n f();\n", 693 "global };\n f();\n",
695 {factory->NewStringFromStaticChars("xyz")}}, 694 {factory->NewStringFromStaticChars("xyz")}},
696 {"function f() { return typeof(undeclared_var); }\n; f();\n", 695 {"function f() { return typeof(undeclared_var); }\n; f();\n",
697 {factory->NewStringFromStaticChars("undefined")}}, 696 {factory->NewStringFromStaticChars("undefined")}},
698 {"var defined_var = 10; function f() { return typeof(defined_var); }\n; " 697 {"var defined_var = 10; function f() { return typeof(defined_var); }\n; "
699 "f();\n", 698 "f();\n",
700 {factory->NewStringFromStaticChars("number")}}, 699 {factory->NewStringFromStaticChars("number")}},
701 }; 700 };
702 701
703 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); 702 for (size_t i = 0; i < arraysize(snippets); i++) {
704 for (size_t i = 0; i < num_snippets; i++) { 703 if ((i % 2) != shard) continue;
705 BytecodeGraphTester tester(isolate, zone, snippets[i].code_snippet); 704 BytecodeGraphTester tester(isolate, zone, snippets[i].code_snippet);
706 auto callable = tester.GetCallable<>(); 705 auto callable = tester.GetCallable<>();
707 Handle<Object> return_value = callable().ToHandleChecked(); 706 Handle<Object> return_value = callable().ToHandleChecked();
708 CHECK(return_value->SameValue(*snippets[i].return_value())); 707 CHECK(return_value->SameValue(*snippets[i].return_value()));
709 } 708 }
710 } 709 }
711 710
711 SHARD_TEST_BY_2(BytecodeGraphBuilderGlobals)
712 712
713 TEST(BytecodeGraphBuilderToObject) { 713 TEST(BytecodeGraphBuilderToObject) {
714 // TODO(mythria): tests for ToObject. Needs ForIn. 714 // TODO(mythria): tests for ToObject. Needs ForIn.
715 } 715 }
716 716
717 717
718 TEST(BytecodeGraphBuilderToName) { 718 TEST(BytecodeGraphBuilderToName) {
719 HandleAndZoneScope scope; 719 HandleAndZoneScope scope;
720 Isolate* isolate = scope.main_isolate(); 720 Isolate* isolate = scope.main_isolate();
721 Zone* zone = scope.main_zone(); 721 Zone* zone = scope.main_zone();
(...skipping 17 matching lines...) Expand all
739 {"var a = {valueOf : function() { return 'x'}};\n" 739 {"var a = {valueOf : function() { return 'x'}};\n"
740 "var obj = {[a] : 10};\n" 740 "var obj = {[a] : 10};\n"
741 "return obj.x;", 741 "return obj.x;",
742 {factory->undefined_value()}}, 742 {factory->undefined_value()}},
743 {"var a = {[Symbol.toPrimitive] : function() { return 'x'}};\n" 743 {"var a = {[Symbol.toPrimitive] : function() { return 'x'}};\n"
744 "var obj = {[a] : 10};\n" 744 "var obj = {[a] : 10};\n"
745 "return obj.x;", 745 "return obj.x;",
746 {factory->NewNumberFromInt(10)}}, 746 {factory->NewNumberFromInt(10)}},
747 }; 747 };
748 748
749 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); 749 for (size_t i = 0; i < arraysize(snippets); i++) {
750 for (size_t i = 0; i < num_snippets; i++) {
751 ScopedVector<char> script(1024); 750 ScopedVector<char> script(1024);
752 SNPrintF(script, "function %s() { %s }\n%s({});", kFunctionName, 751 SNPrintF(script, "function %s() { %s }\n%s({});", kFunctionName,
753 snippets[i].code_snippet, kFunctionName); 752 snippets[i].code_snippet, kFunctionName);
754 753
755 BytecodeGraphTester tester(isolate, zone, script.start()); 754 BytecodeGraphTester tester(isolate, zone, script.start());
756 auto callable = tester.GetCallable<>(); 755 auto callable = tester.GetCallable<>();
757 Handle<Object> return_value = callable().ToHandleChecked(); 756 Handle<Object> return_value = callable().ToHandleChecked();
758 CHECK(return_value->SameValue(*snippets[i].return_value())); 757 CHECK(return_value->SameValue(*snippets[i].return_value()));
759 } 758 }
760 } 759 }
(...skipping 10 matching lines...) Expand all
771 {factory->false_value(), 770 {factory->false_value(),
772 BytecodeGraphTester::NewObject("({val : 10})")}}, 771 BytecodeGraphTester::NewObject("({val : 10})")}},
773 {"return !p1;", {factory->true_value(), factory->NewNumberFromInt(0)}}, 772 {"return !p1;", {factory->true_value(), factory->NewNumberFromInt(0)}},
774 {"return !p1;", {factory->true_value(), factory->undefined_value()}}, 773 {"return !p1;", {factory->true_value(), factory->undefined_value()}},
775 {"return !p1;", {factory->false_value(), factory->NewNumberFromInt(10)}}, 774 {"return !p1;", {factory->false_value(), factory->NewNumberFromInt(10)}},
776 {"return !p1;", {factory->false_value(), factory->true_value()}}, 775 {"return !p1;", {factory->false_value(), factory->true_value()}},
777 {"return !p1;", 776 {"return !p1;",
778 {factory->false_value(), factory->NewStringFromStaticChars("abc")}}, 777 {factory->false_value(), factory->NewStringFromStaticChars("abc")}},
779 }; 778 };
780 779
781 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); 780 for (size_t i = 0; i < arraysize(snippets); i++) {
782 for (size_t i = 0; i < num_snippets; i++) {
783 ScopedVector<char> script(1024); 781 ScopedVector<char> script(1024);
784 SNPrintF(script, "function %s(p1) { %s }\n%s({});", kFunctionName, 782 SNPrintF(script, "function %s(p1) { %s }\n%s({});", kFunctionName,
785 snippets[i].code_snippet, kFunctionName); 783 snippets[i].code_snippet, kFunctionName);
786 784
787 BytecodeGraphTester tester(isolate, zone, script.start()); 785 BytecodeGraphTester tester(isolate, zone, script.start());
788 auto callable = tester.GetCallable<Handle<Object>>(); 786 auto callable = tester.GetCallable<Handle<Object>>();
789 Handle<Object> return_value = 787 Handle<Object> return_value =
790 callable(snippets[i].parameter(0)).ToHandleChecked(); 788 callable(snippets[i].parameter(0)).ToHandleChecked();
791 CHECK(return_value->SameValue(*snippets[i].return_value())); 789 CHECK(return_value->SameValue(*snippets[i].return_value()));
792 } 790 }
(...skipping 16 matching lines...) Expand all
809 {"return typeof p1;", 807 {"return typeof p1;",
810 {factory->NewStringFromStaticChars("number"), 808 {factory->NewStringFromStaticChars("number"),
811 factory->NewNumberFromInt(10)}}, 809 factory->NewNumberFromInt(10)}},
812 {"return typeof p1;", 810 {"return typeof p1;",
813 {factory->NewStringFromStaticChars("boolean"), factory->true_value()}}, 811 {factory->NewStringFromStaticChars("boolean"), factory->true_value()}},
814 {"return typeof p1;", 812 {"return typeof p1;",
815 {factory->NewStringFromStaticChars("string"), 813 {factory->NewStringFromStaticChars("string"),
816 factory->NewStringFromStaticChars("abc")}}, 814 factory->NewStringFromStaticChars("abc")}},
817 }; 815 };
818 816
819 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); 817 for (size_t i = 0; i < arraysize(snippets); i++) {
820 for (size_t i = 0; i < num_snippets; i++) {
821 ScopedVector<char> script(1024); 818 ScopedVector<char> script(1024);
822 SNPrintF(script, "function %s(p1) { %s }\n%s({});", kFunctionName, 819 SNPrintF(script, "function %s(p1) { %s }\n%s({});", kFunctionName,
823 snippets[i].code_snippet, kFunctionName); 820 snippets[i].code_snippet, kFunctionName);
824 821
825 BytecodeGraphTester tester(isolate, zone, script.start()); 822 BytecodeGraphTester tester(isolate, zone, script.start());
826 auto callable = tester.GetCallable<Handle<Object>>(); 823 auto callable = tester.GetCallable<Handle<Object>>();
827 Handle<Object> return_value = 824 Handle<Object> return_value =
828 callable(snippets[i].parameter(0)).ToHandleChecked(); 825 callable(snippets[i].parameter(0)).ToHandleChecked();
829 CHECK(return_value->SameValue(*snippets[i].return_value())); 826 CHECK(return_value->SameValue(*snippets[i].return_value()));
830 } 827 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 {factory->NewNumberFromInt(11), 861 {factory->NewNumberFromInt(11),
865 BytecodeGraphTester::NewObject("({1 : 10})")}}, 862 BytecodeGraphTester::NewObject("({1 : 10})")}},
866 {" function inner() { return p1 } return --p1;", 863 {" function inner() { return p1 } return --p1;",
867 {factory->NewNumberFromInt(9), factory->NewNumberFromInt(10)}}, 864 {factory->NewNumberFromInt(9), factory->NewNumberFromInt(10)}},
868 {" function inner() { return p1 } return p1--;", 865 {" function inner() { return p1 } return p1--;",
869 {factory->NewNumberFromInt(10), factory->NewNumberFromInt(10)}}, 866 {factory->NewNumberFromInt(10), factory->NewNumberFromInt(10)}},
870 {"return ++p1;", 867 {"return ++p1;",
871 {factory->nan_value(), factory->NewStringFromStaticChars("String")}}, 868 {factory->nan_value(), factory->NewStringFromStaticChars("String")}},
872 }; 869 };
873 870
874 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); 871 for (size_t i = 0; i < arraysize(snippets); i++) {
875 for (size_t i = 0; i < num_snippets; i++) {
876 ScopedVector<char> script(1024); 872 ScopedVector<char> script(1024);
877 SNPrintF(script, "function %s(p1) { %s }\n%s({});", kFunctionName, 873 SNPrintF(script, "function %s(p1) { %s }\n%s({});", kFunctionName,
878 snippets[i].code_snippet, kFunctionName); 874 snippets[i].code_snippet, kFunctionName);
879 875
880 BytecodeGraphTester tester(isolate, zone, script.start()); 876 BytecodeGraphTester tester(isolate, zone, script.start());
881 auto callable = tester.GetCallable<Handle<Object>>(); 877 auto callable = tester.GetCallable<Handle<Object>>();
882 Handle<Object> return_value = 878 Handle<Object> return_value =
883 callable(snippets[i].parameter(0)).ToHandleChecked(); 879 callable(snippets[i].parameter(0)).ToHandleChecked();
884 CHECK(return_value->SameValue(*snippets[i].return_value())); 880 CHECK(return_value->SameValue(*snippets[i].return_value()));
885 } 881 }
(...skipping 18 matching lines...) Expand all
904 {"'use strict'; return delete p1.val;", 900 {"'use strict'; return delete p1.val;",
905 {factory->true_value(), BytecodeGraphTester::NewObject("({val : 10})")}}, 901 {factory->true_value(), BytecodeGraphTester::NewObject("({val : 10})")}},
906 {"'use strict'; delete p1.val; return p1.val;", 902 {"'use strict'; delete p1.val; return p1.val;",
907 {factory->undefined_value(), 903 {factory->undefined_value(),
908 BytecodeGraphTester::NewObject("({val : 10})")}}, 904 BytecodeGraphTester::NewObject("({val : 10})")}},
909 {"'use strict'; delete p1.name; return p1.val;", 905 {"'use strict'; delete p1.name; return p1.val;",
910 {factory->NewNumberFromInt(10), 906 {factory->NewNumberFromInt(10),
911 BytecodeGraphTester::NewObject("({val : 10, name:'abc'})")}}, 907 BytecodeGraphTester::NewObject("({val : 10, name:'abc'})")}},
912 }; 908 };
913 909
914 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); 910 for (size_t i = 0; i < arraysize(snippets); i++) {
915 for (size_t i = 0; i < num_snippets; i++) {
916 ScopedVector<char> script(1024); 911 ScopedVector<char> script(1024);
917 SNPrintF(script, "function %s(p1) { %s }\n%s({});", kFunctionName, 912 SNPrintF(script, "function %s(p1) { %s }\n%s({});", kFunctionName,
918 snippets[i].code_snippet, kFunctionName); 913 snippets[i].code_snippet, kFunctionName);
919 914
920 BytecodeGraphTester tester(isolate, zone, script.start()); 915 BytecodeGraphTester tester(isolate, zone, script.start());
921 auto callable = tester.GetCallable<Handle<Object>>(); 916 auto callable = tester.GetCallable<Handle<Object>>();
922 Handle<Object> return_value = 917 Handle<Object> return_value =
923 callable(snippets[i].parameter(0)).ToHandleChecked(); 918 callable(snippets[i].parameter(0)).ToHandleChecked();
924 CHECK(return_value->SameValue(*snippets[i].return_value())); 919 CHECK(return_value->SameValue(*snippets[i].return_value()));
925 } 920 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
959 "function f() { delete obj[1]; return obj[2];};", 954 "function f() { delete obj[1]; return obj[2];};",
960 {factory->NewNumberFromInt(20)}}, 955 {factory->NewNumberFromInt(20)}},
961 {"function f() {" 956 {"function f() {"
962 " var obj = {1 : 10, 2 : 20};" 957 " var obj = {1 : 10, 2 : 20};"
963 " function inner() { return obj[1]; };" 958 " function inner() { return obj[1]; };"
964 " return delete obj[1];" 959 " return delete obj[1];"
965 "}", 960 "}",
966 {factory->true_value()}}, 961 {factory->true_value()}},
967 }; 962 };
968 963
969 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); 964 for (size_t i = 0; i < arraysize(snippets); i++) {
970 for (size_t i = 0; i < num_snippets; i++) {
971 ScopedVector<char> script(1024); 965 ScopedVector<char> script(1024);
972 SNPrintF(script, "%s %s({});", snippets[i].code_snippet, kFunctionName); 966 SNPrintF(script, "%s %s({});", snippets[i].code_snippet, kFunctionName);
973 967
974 BytecodeGraphTester tester(isolate, zone, script.start()); 968 BytecodeGraphTester tester(isolate, zone, script.start());
975 auto callable = tester.GetCallable<>(); 969 auto callable = tester.GetCallable<>();
976 Handle<Object> return_value = callable().ToHandleChecked(); 970 Handle<Object> return_value = callable().ToHandleChecked();
977 CHECK(return_value->SameValue(*snippets[i].return_value())); 971 CHECK(return_value->SameValue(*snippets[i].return_value()));
978 } 972 }
979 } 973 }
980 974
(...skipping 15 matching lines...) Expand all
996 " eval(\"function t() {"; 990 " eval(\"function t() {";
997 const char* function_epilogue = " }; f = t; t();\");" 991 const char* function_epilogue = " }; f = t; t();\");"
998 "}" 992 "}"
999 "f1();"; 993 "f1();";
1000 994
1001 ExpectedSnippet<0> snippets[] = { 995 ExpectedSnippet<0> snippets[] = {
1002 {"return delete y;", {factory->true_value()}}, 996 {"return delete y;", {factory->true_value()}},
1003 {"return delete z;", {factory->false_value()}}, 997 {"return delete z;", {factory->false_value()}},
1004 }; 998 };
1005 999
1006 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); 1000 for (size_t i = 0; i < arraysize(snippets); i++) {
1007 for (size_t i = 0; i < num_snippets; i++) {
1008 ScopedVector<char> script(1024); 1001 ScopedVector<char> script(1024);
1009 SNPrintF(script, "%s %s %s", function_prologue, snippets[i].code_snippet, 1002 SNPrintF(script, "%s %s %s", function_prologue, snippets[i].code_snippet,
1010 function_epilogue); 1003 function_epilogue);
1011 1004
1012 BytecodeGraphTester tester(isolate, zone, script.start(), "t"); 1005 BytecodeGraphTester tester(isolate, zone, script.start(), "t");
1013 auto callable = tester.GetCallable<>(); 1006 auto callable = tester.GetCallable<>();
1014 Handle<Object> return_value = callable().ToHandleChecked(); 1007 Handle<Object> return_value = callable().ToHandleChecked();
1015 CHECK(return_value->SameValue(*snippets[i].return_value())); 1008 CHECK(return_value->SameValue(*snippets[i].return_value()));
1016 } 1009 }
1017 } 1010 }
(...skipping 20 matching lines...) Expand all
1038 ExpectedSnippet<0> snippets[] = { 1031 ExpectedSnippet<0> snippets[] = {
1039 {"return x;", {factory->NewNumber(12)}}, 1032 {"return x;", {factory->NewNumber(12)}},
1040 {"return obj.val;", {factory->NewNumber(3.1414)}}, 1033 {"return obj.val;", {factory->NewNumber(3.1414)}},
1041 {"return typeof x;", {factory->NewStringFromStaticChars("number")}}, 1034 {"return typeof x;", {factory->NewStringFromStaticChars("number")}},
1042 {"return typeof dummy;", 1035 {"return typeof dummy;",
1043 {factory->NewStringFromStaticChars("undefined")}}, 1036 {factory->NewStringFromStaticChars("undefined")}},
1044 {"x = 23; return x;", {factory->NewNumber(23)}}, 1037 {"x = 23; return x;", {factory->NewNumber(23)}},
1045 {"'use strict'; obj.val = 23.456; return obj.val;", 1038 {"'use strict'; obj.val = 23.456; return obj.val;",
1046 {factory->NewNumber(23.456)}}}; 1039 {factory->NewNumber(23.456)}}};
1047 1040
1048 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); 1041 for (size_t i = 0; i < arraysize(snippets); i++) {
1049 for (size_t i = 0; i < num_snippets; i++) {
1050 ScopedVector<char> script(1024); 1042 ScopedVector<char> script(1024);
1051 SNPrintF(script, "%s %s %s", function_prologue, snippets[i].code_snippet, 1043 SNPrintF(script, "%s %s %s", function_prologue, snippets[i].code_snippet,
1052 function_epilogue); 1044 function_epilogue);
1053 1045
1054 BytecodeGraphTester tester(isolate, zone, script.start(), "t"); 1046 BytecodeGraphTester tester(isolate, zone, script.start(), "t");
1055 auto callable = tester.GetCallable<>(); 1047 auto callable = tester.GetCallable<>();
1056 Handle<Object> return_value = callable().ToHandleChecked(); 1048 Handle<Object> return_value = callable().ToHandleChecked();
1057 CHECK(return_value->SameValue(*snippets[i].return_value())); 1049 CHECK(return_value->SameValue(*snippets[i].return_value()));
1058 } 1050 }
1059 } 1051 }
(...skipping 22 matching lines...) Expand all
1082 ExpectedSnippet<0> snippets[] = { 1074 ExpectedSnippet<0> snippets[] = {
1083 {"var y = 2.3;" REPEAT_256(SPACE, "y = 2.3;") "return x;", 1075 {"var y = 2.3;" REPEAT_256(SPACE, "y = 2.3;") "return x;",
1084 {factory->NewNumber(12)}}, 1076 {factory->NewNumber(12)}},
1085 {"var y = 2.3;" REPEAT_256(SPACE, "y = 2.3;") "return typeof x;", 1077 {"var y = 2.3;" REPEAT_256(SPACE, "y = 2.3;") "return typeof x;",
1086 {factory->NewStringFromStaticChars("number")}}, 1078 {factory->NewStringFromStaticChars("number")}},
1087 {"var y = 2.3;" REPEAT_256(SPACE, "y = 2.3;") "return x = 23;", 1079 {"var y = 2.3;" REPEAT_256(SPACE, "y = 2.3;") "return x = 23;",
1088 {factory->NewNumber(23)}}, 1080 {factory->NewNumber(23)}},
1089 {"'use strict';" REPEAT_256(SPACE, "y = 2.3;") "return obj.val = 23.456;", 1081 {"'use strict';" REPEAT_256(SPACE, "y = 2.3;") "return obj.val = 23.456;",
1090 {factory->NewNumber(23.456)}}}; 1082 {factory->NewNumber(23.456)}}};
1091 1083
1092 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); 1084 for (size_t i = 0; i < arraysize(snippets); i++) {
1093 for (size_t i = 0; i < num_snippets; i++) {
1094 ScopedVector<char> script(3072); 1085 ScopedVector<char> script(3072);
1095 SNPrintF(script, "%s %s %s", function_prologue, snippets[i].code_snippet, 1086 SNPrintF(script, "%s %s %s", function_prologue, snippets[i].code_snippet,
1096 function_epilogue); 1087 function_epilogue);
1097 1088
1098 BytecodeGraphTester tester(isolate, zone, script.start(), "t"); 1089 BytecodeGraphTester tester(isolate, zone, script.start(), "t");
1099 auto callable = tester.GetCallable<>(); 1090 auto callable = tester.GetCallable<>();
1100 Handle<Object> return_value = callable().ToHandleChecked(); 1091 Handle<Object> return_value = callable().ToHandleChecked();
1101 CHECK(return_value->SameValue(*snippets[i].return_value())); 1092 CHECK(return_value->SameValue(*snippets[i].return_value()));
1102 } 1093 }
1103 } 1094 }
1104 1095
1105 1096
1106 TEST(BytecodeGraphBuilderCallLookupSlot) { 1097 TEST(BytecodeGraphBuilderCallLookupSlot) {
1107 HandleAndZoneScope scope; 1098 HandleAndZoneScope scope;
1108 Isolate* isolate = scope.main_isolate(); 1099 Isolate* isolate = scope.main_isolate();
1109 Zone* zone = scope.main_zone(); 1100 Zone* zone = scope.main_zone();
1110 1101
1111 ExpectedSnippet<0> snippets[] = { 1102 ExpectedSnippet<0> snippets[] = {
1112 {"g = function(){ return 2 }; eval(''); return g();", 1103 {"g = function(){ return 2 }; eval(''); return g();",
1113 {handle(Smi::FromInt(2), isolate)}}, 1104 {handle(Smi::FromInt(2), isolate)}},
1114 {"g = function(){ return 2 }; eval('g = function() {return 3}');\n" 1105 {"g = function(){ return 2 }; eval('g = function() {return 3}');\n"
1115 "return g();", 1106 "return g();",
1116 {handle(Smi::FromInt(3), isolate)}}, 1107 {handle(Smi::FromInt(3), isolate)}},
1117 {"g = { x: function(){ return this.y }, y: 20 };\n" 1108 {"g = { x: function(){ return this.y }, y: 20 };\n"
1118 "eval('g = { x: g.x, y: 30 }');\n" 1109 "eval('g = { x: g.x, y: 30 }');\n"
1119 "return g.x();", 1110 "return g.x();",
1120 {handle(Smi::FromInt(30), isolate)}}, 1111 {handle(Smi::FromInt(30), isolate)}},
1121 }; 1112 };
1122 1113
1123 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); 1114 for (size_t i = 0; i < arraysize(snippets); i++) {
1124 for (size_t i = 0; i < num_snippets; i++) {
1125 ScopedVector<char> script(1024); 1115 ScopedVector<char> script(1024);
1126 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, 1116 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName,
1127 snippets[i].code_snippet, kFunctionName); 1117 snippets[i].code_snippet, kFunctionName);
1128 BytecodeGraphTester tester(isolate, zone, script.start()); 1118 BytecodeGraphTester tester(isolate, zone, script.start());
1129 auto callable = tester.GetCallable<>(); 1119 auto callable = tester.GetCallable<>();
1130 Handle<Object> return_value = callable().ToHandleChecked(); 1120 Handle<Object> return_value = callable().ToHandleChecked();
1131 CHECK(return_value->SameValue(*snippets[i].return_value())); 1121 CHECK(return_value->SameValue(*snippets[i].return_value()));
1132 } 1122 }
1133 } 1123 }
1134 1124
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1166 {"'use strict'; eval('var y = 10;'); return typeof unallocated;", 1156 {"'use strict'; eval('var y = 10;'); return typeof unallocated;",
1167 {factory->NewStringFromStaticChars("undefined")}}, 1157 {factory->NewStringFromStaticChars("undefined")}},
1168 {"eval('var x = 10;'); return typeof x;", 1158 {"eval('var x = 10;'); return typeof x;",
1169 {factory->NewStringFromStaticChars("number")}}, 1159 {factory->NewStringFromStaticChars("number")}},
1170 {"var x = {}; eval('var x = 10;'); return typeof x;", 1160 {"var x = {}; eval('var x = 10;'); return typeof x;",
1171 {factory->NewStringFromStaticChars("number")}}, 1161 {factory->NewStringFromStaticChars("number")}},
1172 {"'use strict'; var x = {}; eval('var x = 10;'); return typeof x;", 1162 {"'use strict'; var x = {}; eval('var x = 10;'); return typeof x;",
1173 {factory->NewStringFromStaticChars("object")}}, 1163 {factory->NewStringFromStaticChars("object")}},
1174 }; 1164 };
1175 1165
1176 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); 1166 for (size_t i = 0; i < arraysize(snippets); i++) {
1177 for (size_t i = 0; i < num_snippets; i++) {
1178 ScopedVector<char> script(1024); 1167 ScopedVector<char> script(1024);
1179 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, 1168 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName,
1180 snippets[i].code_snippet, kFunctionName); 1169 snippets[i].code_snippet, kFunctionName);
1181 BytecodeGraphTester tester(isolate, zone, script.start()); 1170 BytecodeGraphTester tester(isolate, zone, script.start());
1182 auto callable = tester.GetCallable<>(); 1171 auto callable = tester.GetCallable<>();
1183 Handle<Object> return_value = callable().ToHandleChecked(); 1172 Handle<Object> return_value = callable().ToHandleChecked();
1184 CHECK(return_value->SameValue(*snippets[i].return_value())); 1173 CHECK(return_value->SameValue(*snippets[i].return_value()));
1185 } 1174 }
1186 } 1175 }
1187 1176
1188 1177
1189 TEST(BytecodeGraphBuilderEvalParams) { 1178 TEST(BytecodeGraphBuilderEvalParams) {
1190 HandleAndZoneScope scope; 1179 HandleAndZoneScope scope;
1191 Isolate* isolate = scope.main_isolate(); 1180 Isolate* isolate = scope.main_isolate();
1192 Zone* zone = scope.main_zone(); 1181 Zone* zone = scope.main_zone();
1193 1182
1194 ExpectedSnippet<1> snippets[] = { 1183 ExpectedSnippet<1> snippets[] = {
1195 {"var x = 10; return eval('x + p1;');", 1184 {"var x = 10; return eval('x + p1;');",
1196 {handle(Smi::FromInt(30), isolate), handle(Smi::FromInt(20), isolate)}}, 1185 {handle(Smi::FromInt(30), isolate), handle(Smi::FromInt(20), isolate)}},
1197 {"var x = 10; eval('p1 = x;'); return p1;", 1186 {"var x = 10; eval('p1 = x;'); return p1;",
1198 {handle(Smi::FromInt(10), isolate), handle(Smi::FromInt(20), isolate)}}, 1187 {handle(Smi::FromInt(10), isolate), handle(Smi::FromInt(20), isolate)}},
1199 {"var a = 10;" 1188 {"var a = 10;"
1200 "function inner() { return eval('a + p1;');}" 1189 "function inner() { return eval('a + p1;');}"
1201 "return inner();", 1190 "return inner();",
1202 {handle(Smi::FromInt(30), isolate), handle(Smi::FromInt(20), isolate)}}, 1191 {handle(Smi::FromInt(30), isolate), handle(Smi::FromInt(20), isolate)}},
1203 }; 1192 };
1204 1193
1205 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); 1194 for (size_t i = 0; i < arraysize(snippets); i++) {
1206 for (size_t i = 0; i < num_snippets; i++) {
1207 ScopedVector<char> script(1024); 1195 ScopedVector<char> script(1024);
1208 SNPrintF(script, "function %s(p1) { %s }\n%s(0);", kFunctionName, 1196 SNPrintF(script, "function %s(p1) { %s }\n%s(0);", kFunctionName,
1209 snippets[i].code_snippet, kFunctionName); 1197 snippets[i].code_snippet, kFunctionName);
1210 BytecodeGraphTester tester(isolate, zone, script.start()); 1198 BytecodeGraphTester tester(isolate, zone, script.start());
1211 auto callable = tester.GetCallable<Handle<Object>>(); 1199 auto callable = tester.GetCallable<Handle<Object>>();
1212 Handle<Object> return_value = 1200 Handle<Object> return_value =
1213 callable(snippets[i].parameter(0)).ToHandleChecked(); 1201 callable(snippets[i].parameter(0)).ToHandleChecked();
1214 CHECK(return_value->SameValue(*snippets[i].return_value())); 1202 CHECK(return_value->SameValue(*snippets[i].return_value()));
1215 } 1203 }
1216 } 1204 }
(...skipping 10 matching lines...) Expand all
1227 "function f() { add_global(); return z; }; f();", 1215 "function f() { add_global(); return z; }; f();",
1228 {handle(Smi::FromInt(33), isolate)}}, 1216 {handle(Smi::FromInt(33), isolate)}},
1229 {"function add_global() {\n" 1217 {"function add_global() {\n"
1230 " eval('\"use strict\"; function f() { y = 33; };" 1218 " eval('\"use strict\"; function f() { y = 33; };"
1231 " try { f() } catch(e) {}');\n" 1219 " try { f() } catch(e) {}');\n"
1232 "}\n" 1220 "}\n"
1233 "function f() { add_global(); return typeof y; } f();", 1221 "function f() { add_global(); return typeof y; } f();",
1234 {factory->NewStringFromStaticChars("undefined")}}, 1222 {factory->NewStringFromStaticChars("undefined")}},
1235 }; 1223 };
1236 1224
1237 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); 1225 for (size_t i = 0; i < arraysize(snippets); i++) {
1238 for (size_t i = 0; i < num_snippets; i++) {
1239 BytecodeGraphTester tester(isolate, zone, snippets[i].code_snippet); 1226 BytecodeGraphTester tester(isolate, zone, snippets[i].code_snippet);
1240 auto callable = tester.GetCallable<>(); 1227 auto callable = tester.GetCallable<>();
1241 Handle<Object> return_value = callable().ToHandleChecked(); 1228 Handle<Object> return_value = callable().ToHandleChecked();
1242 CHECK(return_value->SameValue(*snippets[i].return_value())); 1229 CHECK(return_value->SameValue(*snippets[i].return_value()));
1243 } 1230 }
1244 } 1231 }
1245 1232
1246 1233
1247 bool get_compare_result(Token::Value opcode, Handle<Object> lhs_value, 1234 bool get_compare_result(Token::Value opcode, Handle<Object> lhs_value,
1248 Handle<Object> rhs_value) { 1235 Handle<Object> rhs_value) {
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
1359 factory->NewNumberFromInt(10)}}, 1346 factory->NewNumberFromInt(10)}},
1360 {"return p2 in p1;", 1347 {"return p2 in p1;",
1361 {factory->true_value(), BytecodeGraphTester::NewObject("({10 : 'val'})"), 1348 {factory->true_value(), BytecodeGraphTester::NewObject("({10 : 'val'})"),
1362 factory->NewNumberFromInt(10)}}, 1349 factory->NewNumberFromInt(10)}},
1363 {"return p2 in p1;", 1350 {"return p2 in p1;",
1364 {factory->false_value(), 1351 {factory->false_value(),
1365 BytecodeGraphTester::NewObject("({10 : 'val'})"), 1352 BytecodeGraphTester::NewObject("({10 : 'val'})"),
1366 factory->NewNumberFromInt(1)}}, 1353 factory->NewNumberFromInt(1)}},
1367 }; 1354 };
1368 1355
1369 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); 1356 for (size_t i = 0; i < arraysize(snippets); i++) {
1370 for (size_t i = 0; i < num_snippets; i++) {
1371 ScopedVector<char> script(1024); 1357 ScopedVector<char> script(1024);
1372 SNPrintF(script, "function %s(p1, p2) { %s }\n%s({}, {});", kFunctionName, 1358 SNPrintF(script, "function %s(p1, p2) { %s }\n%s({}, {});", kFunctionName,
1373 snippets[i].code_snippet, kFunctionName); 1359 snippets[i].code_snippet, kFunctionName);
1374 1360
1375 BytecodeGraphTester tester(isolate, zone, script.start()); 1361 BytecodeGraphTester tester(isolate, zone, script.start());
1376 auto callable = tester.GetCallable<Handle<Object>, Handle<Object>>(); 1362 auto callable = tester.GetCallable<Handle<Object>, Handle<Object>>();
1377 Handle<Object> return_value = 1363 Handle<Object> return_value =
1378 callable(snippets[i].parameter(0), snippets[i].parameter(1)) 1364 callable(snippets[i].parameter(0), snippets[i].parameter(1))
1379 .ToHandleChecked(); 1365 .ToHandleChecked();
1380 CHECK(return_value->SameValue(*snippets[i].return_value())); 1366 CHECK(return_value->SameValue(*snippets[i].return_value()));
(...skipping 11 matching lines...) Expand all
1392 {"return p1 instanceof Object;", 1378 {"return p1 instanceof Object;",
1393 {factory->true_value(), BytecodeGraphTester::NewObject("({val : 10})")}}, 1379 {factory->true_value(), BytecodeGraphTester::NewObject("({val : 10})")}},
1394 {"return p1 instanceof String;", 1380 {"return p1 instanceof String;",
1395 {factory->false_value(), factory->NewStringFromStaticChars("string")}}, 1381 {factory->false_value(), factory->NewStringFromStaticChars("string")}},
1396 {"var cons = function() {};" 1382 {"var cons = function() {};"
1397 "var obj = new cons();" 1383 "var obj = new cons();"
1398 "return obj instanceof cons;", 1384 "return obj instanceof cons;",
1399 {factory->true_value(), factory->undefined_value()}}, 1385 {factory->true_value(), factory->undefined_value()}},
1400 }; 1386 };
1401 1387
1402 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); 1388 for (size_t i = 0; i < arraysize(snippets); i++) {
1403 for (size_t i = 0; i < num_snippets; i++) {
1404 ScopedVector<char> script(1024); 1389 ScopedVector<char> script(1024);
1405 SNPrintF(script, "function %s(p1) { %s }\n%s({});", kFunctionName, 1390 SNPrintF(script, "function %s(p1) { %s }\n%s({});", kFunctionName,
1406 snippets[i].code_snippet, kFunctionName); 1391 snippets[i].code_snippet, kFunctionName);
1407 1392
1408 BytecodeGraphTester tester(isolate, zone, script.start()); 1393 BytecodeGraphTester tester(isolate, zone, script.start());
1409 auto callable = tester.GetCallable<Handle<Object>>(); 1394 auto callable = tester.GetCallable<Handle<Object>>();
1410 Handle<Object> return_value = 1395 Handle<Object> return_value =
1411 callable(snippets[i].parameter(0)).ToHandleChecked(); 1396 callable(snippets[i].parameter(0)).ToHandleChecked();
1412 CHECK(return_value->SameValue(*snippets[i].return_value())); 1397 CHECK(return_value->SameValue(*snippets[i].return_value()));
1413 } 1398 }
1414 } 1399 }
1415 1400
1416 TEST(BytecodeGraphBuilderTryCatch) { 1401 TEST(BytecodeGraphBuilderTryCatch) {
1417 HandleAndZoneScope scope; 1402 HandleAndZoneScope scope;
1418 Isolate* isolate = scope.main_isolate(); 1403 Isolate* isolate = scope.main_isolate();
1419 Zone* zone = scope.main_zone(); 1404 Zone* zone = scope.main_zone();
1420 1405
1421 ExpectedSnippet<0> snippets[] = { 1406 ExpectedSnippet<0> snippets[] = {
1422 {"var a = 1; try { a = 2 } catch(e) { a = 3 }; return a;", 1407 {"var a = 1; try { a = 2 } catch(e) { a = 3 }; return a;",
1423 {handle(Smi::FromInt(2), isolate)}}, 1408 {handle(Smi::FromInt(2), isolate)}},
1424 {"var a; try { undef.x } catch(e) { a = 2 }; return a;", 1409 {"var a; try { undef.x } catch(e) { a = 2 }; return a;",
1425 {handle(Smi::FromInt(2), isolate)}}, 1410 {handle(Smi::FromInt(2), isolate)}},
1426 {"var a; try { throw 1 } catch(e) { a = e + 2 }; return a;", 1411 {"var a; try { throw 1 } catch(e) { a = e + 2 }; return a;",
1427 {handle(Smi::FromInt(3), isolate)}}, 1412 {handle(Smi::FromInt(3), isolate)}},
1428 {"var a; try { throw 1 } catch(e) { a = e + 2 };" 1413 {"var a; try { throw 1 } catch(e) { a = e + 2 };"
1429 " try { throw a } catch(e) { a = e + 3 }; return a;", 1414 " try { throw a } catch(e) { a = e + 3 }; return a;",
1430 {handle(Smi::FromInt(6), isolate)}}, 1415 {handle(Smi::FromInt(6), isolate)}},
1431 }; 1416 };
1432 1417
1433 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); 1418 for (size_t i = 0; i < arraysize(snippets); i++) {
1434 for (size_t i = 0; i < num_snippets; i++) {
1435 ScopedVector<char> script(1024); 1419 ScopedVector<char> script(1024);
1436 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, 1420 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName,
1437 snippets[i].code_snippet, kFunctionName); 1421 snippets[i].code_snippet, kFunctionName);
1438 1422
1439 BytecodeGraphTester tester(isolate, zone, script.start()); 1423 BytecodeGraphTester tester(isolate, zone, script.start());
1440 auto callable = tester.GetCallable<>(); 1424 auto callable = tester.GetCallable<>();
1441 Handle<Object> return_value = callable().ToHandleChecked(); 1425 Handle<Object> return_value = callable().ToHandleChecked();
1442 CHECK(return_value->SameValue(*snippets[i].return_value())); 1426 CHECK(return_value->SameValue(*snippets[i].return_value()));
1443 } 1427 }
1444 } 1428 }
(...skipping 17 matching lines...) Expand all
1462 {"var a = 1; for (var i = 10; i < 20; i += 5) {" 1446 {"var a = 1; for (var i = 10; i < 20; i += 5) {"
1463 " try { a = 2; continue; } finally { a = 3; }" 1447 " try { a = 2; continue; } finally { a = 3; }"
1464 "} return a + i;", 1448 "} return a + i;",
1465 {handle(Smi::FromInt(23), isolate)}}, 1449 {handle(Smi::FromInt(23), isolate)}},
1466 {"var a = 1; try { a = 2;" 1450 {"var a = 1; try { a = 2;"
1467 " try { a = 3; throw 23; } finally { a = 4; }" 1451 " try { a = 3; throw 23; } finally { a = 4; }"
1468 "} catch(e) { a = a + e; } return a;", 1452 "} catch(e) { a = a + e; } return a;",
1469 {handle(Smi::FromInt(27), isolate)}}, 1453 {handle(Smi::FromInt(27), isolate)}},
1470 }; 1454 };
1471 1455
1472 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); 1456 for (size_t i = 0; i < arraysize(snippets); i++) {
1473 for (size_t i = 0; i < num_snippets; i++) {
1474 ScopedVector<char> script(1024); 1457 ScopedVector<char> script(1024);
1475 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, 1458 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName,
1476 snippets[i].code_snippet, kFunctionName); 1459 snippets[i].code_snippet, kFunctionName);
1477 1460
1478 BytecodeGraphTester tester(isolate, zone, script.start()); 1461 BytecodeGraphTester tester(isolate, zone, script.start());
1479 auto callable = tester.GetCallable<>(); 1462 auto callable = tester.GetCallable<>();
1480 Handle<Object> return_value = callable().ToHandleChecked(); 1463 Handle<Object> return_value = callable().ToHandleChecked();
1481 CHECK(return_value->SameValue(*snippets[i].return_value())); 1464 CHECK(return_value->SameValue(*snippets[i].return_value()));
1482 } 1465 }
1483 } 1466 }
1484 1467
1485 TEST(BytecodeGraphBuilderTryFinally2) { 1468 TEST(BytecodeGraphBuilderTryFinally2) {
1486 HandleAndZoneScope scope; 1469 HandleAndZoneScope scope;
1487 Isolate* isolate = scope.main_isolate(); 1470 Isolate* isolate = scope.main_isolate();
1488 Zone* zone = scope.main_zone(); 1471 Zone* zone = scope.main_zone();
1489 1472
1490 ExpectedSnippet<0, const char*> snippets[] = { 1473 ExpectedSnippet<0, const char*> snippets[] = {
1491 {"var a = 1; try { a = 2; throw 23; } finally { a = 3 }; return a;", 1474 {"var a = 1; try { a = 2; throw 23; } finally { a = 3 }; return a;",
1492 {"Uncaught 23"}}, 1475 {"Uncaught 23"}},
1493 {"var a = 1; try { a = 2; throw 23; } finally { throw 42; };", 1476 {"var a = 1; try { a = 2; throw 23; } finally { throw 42; };",
1494 {"Uncaught 42"}}, 1477 {"Uncaught 42"}},
1495 }; 1478 };
1496 1479
1497 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); 1480 for (size_t i = 0; i < arraysize(snippets); i++) {
1498 for (size_t i = 0; i < num_snippets; i++) {
1499 ScopedVector<char> script(1024); 1481 ScopedVector<char> script(1024);
1500 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, 1482 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName,
1501 snippets[i].code_snippet, kFunctionName); 1483 snippets[i].code_snippet, kFunctionName);
1502 1484
1503 BytecodeGraphTester tester(isolate, zone, script.start()); 1485 BytecodeGraphTester tester(isolate, zone, script.start());
1504 v8::Local<v8::String> message = tester.CheckThrowsReturnMessage()->Get(); 1486 v8::Local<v8::String> message = tester.CheckThrowsReturnMessage()->Get();
1505 v8::Local<v8::String> expected_string = v8_str(snippets[i].return_value()); 1487 v8::Local<v8::String> expected_string = v8_str(snippets[i].return_value());
1506 CHECK( 1488 CHECK(
1507 message->Equals(CcTest::isolate()->GetCurrentContext(), expected_string) 1489 message->Equals(CcTest::isolate()->GetCurrentContext(), expected_string)
1508 .FromJust()); 1490 .FromJust());
1509 } 1491 }
1510 } 1492 }
1511 1493
1512 TEST(BytecodeGraphBuilderThrow) { 1494 TEST(BytecodeGraphBuilderThrow) {
1513 HandleAndZoneScope scope; 1495 HandleAndZoneScope scope;
1514 Isolate* isolate = scope.main_isolate(); 1496 Isolate* isolate = scope.main_isolate();
1515 Zone* zone = scope.main_zone(); 1497 Zone* zone = scope.main_zone();
1516 1498
1517 // TODO(mythria): Add more tests when real try-catch and deoptimization 1499 // TODO(mythria): Add more tests when real try-catch and deoptimization
1518 // information are supported. 1500 // information are supported.
1519 ExpectedSnippet<0, const char*> snippets[] = { 1501 ExpectedSnippet<0, const char*> snippets[] = {
1520 {"throw undefined;", {"Uncaught undefined"}}, 1502 {"throw undefined;", {"Uncaught undefined"}},
1521 {"throw 1;", {"Uncaught 1"}}, 1503 {"throw 1;", {"Uncaught 1"}},
1522 {"throw 'Error';", {"Uncaught Error"}}, 1504 {"throw 'Error';", {"Uncaught Error"}},
1523 {"throw 'Error1'; throw 'Error2'", {"Uncaught Error1"}}, 1505 {"throw 'Error1'; throw 'Error2'", {"Uncaught Error1"}},
1524 {"var a = true; if (a) { throw 'Error'; }", {"Uncaught Error"}}, 1506 {"var a = true; if (a) { throw 'Error'; }", {"Uncaught Error"}},
1525 }; 1507 };
1526 1508
1527 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); 1509 for (size_t i = 0; i < arraysize(snippets); i++) {
1528 for (size_t i = 0; i < num_snippets; i++) {
1529 ScopedVector<char> script(1024); 1510 ScopedVector<char> script(1024);
1530 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, 1511 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName,
1531 snippets[i].code_snippet, kFunctionName); 1512 snippets[i].code_snippet, kFunctionName);
1532 1513
1533 BytecodeGraphTester tester(isolate, zone, script.start()); 1514 BytecodeGraphTester tester(isolate, zone, script.start());
1534 v8::Local<v8::String> message = tester.CheckThrowsReturnMessage()->Get(); 1515 v8::Local<v8::String> message = tester.CheckThrowsReturnMessage()->Get();
1535 v8::Local<v8::String> expected_string = v8_str(snippets[i].return_value()); 1516 v8::Local<v8::String> expected_string = v8_str(snippets[i].return_value());
1536 CHECK( 1517 CHECK(
1537 message->Equals(CcTest::isolate()->GetCurrentContext(), expected_string) 1518 message->Equals(CcTest::isolate()->GetCurrentContext(), expected_string)
1538 .FromJust()); 1519 .FromJust());
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1580 " var innerMostFunc = function() {return x + innerFunc();};" 1561 " var innerMostFunc = function() {return x + innerFunc();};"
1581 " }" 1562 " }"
1582 " x = 'inner_changed ';" 1563 " x = 'inner_changed ';"
1583 " }" 1564 " }"
1584 " return(innerMostFunc() + x);" 1565 " return(innerMostFunc() + x);"
1585 "}" 1566 "}"
1586 "f();", 1567 "f();",
1587 {factory->NewStringFromStaticChars("innermost inner_changed outer")}}, 1568 {factory->NewStringFromStaticChars("innermost inner_changed outer")}},
1588 }; 1569 };
1589 1570
1590 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); 1571 for (size_t i = 0; i < arraysize(snippets); i++) {
1591 for (size_t i = 0; i < num_snippets; i++) {
1592 ScopedVector<char> script(1024); 1572 ScopedVector<char> script(1024);
1593 SNPrintF(script, "%s", snippets[i].code_snippet); 1573 SNPrintF(script, "%s", snippets[i].code_snippet);
1594 1574
1595 BytecodeGraphTester tester(isolate, zone, script.start(), "f"); 1575 BytecodeGraphTester tester(isolate, zone, script.start(), "f");
1596 auto callable = tester.GetCallable<>("f"); 1576 auto callable = tester.GetCallable<>("f");
1597 Handle<Object> return_value = callable().ToHandleChecked(); 1577 Handle<Object> return_value = callable().ToHandleChecked();
1598 CHECK(return_value->SameValue(*snippets[i].return_value())); 1578 CHECK(return_value->SameValue(*snippets[i].return_value()));
1599 } 1579 }
1600 } 1580 }
1601 1581
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1646 {"function testOuter(outerArg) {" 1626 {"function testOuter(outerArg) {"
1647 " var outerVar = outerArg * 2;" 1627 " var outerVar = outerArg * 2;"
1648 " this.testinnerFunc = function testInner(innerArg) {" 1628 " this.testinnerFunc = function testInner(innerArg) {"
1649 " outerVar = outerVar + innerArg; return outerVar;" 1629 " outerVar = outerVar + innerArg; return outerVar;"
1650 " }" 1630 " }"
1651 "}" 1631 "}"
1652 "var f = new testOuter(10).testinnerFunc;" 1632 "var f = new testOuter(10).testinnerFunc;"
1653 "f(0);", 1633 "f(0);",
1654 {factory->NewNumberFromInt(24), factory->NewNumberFromInt(4)}}}; 1634 {factory->NewNumberFromInt(24), factory->NewNumberFromInt(4)}}};
1655 1635
1656 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); 1636 for (size_t i = 0; i < arraysize(snippets); i++) {
1657 for (size_t i = 0; i < num_snippets; i++) {
1658 ScopedVector<char> script(1024); 1637 ScopedVector<char> script(1024);
1659 SNPrintF(script, "%s", snippets[i].code_snippet); 1638 SNPrintF(script, "%s", snippets[i].code_snippet);
1660 1639
1661 BytecodeGraphTester tester(isolate, zone, script.start(), "*"); 1640 BytecodeGraphTester tester(isolate, zone, script.start(), "*");
1662 auto callable = tester.GetCallable<Handle<Object>>("f"); 1641 auto callable = tester.GetCallable<Handle<Object>>("f");
1663 Handle<Object> return_value = 1642 Handle<Object> return_value =
1664 callable(snippets[i].parameter(0)).ToHandleChecked(); 1643 callable(snippets[i].parameter(0)).ToHandleChecked();
1665 CHECK(return_value->SameValue(*snippets[i].return_value())); 1644 CHECK(return_value->SameValue(*snippets[i].return_value()));
1666 } 1645 }
1667 } 1646 }
(...skipping 11 matching lines...) Expand all
1679 {"function f() {'use strict'; return arguments[0];}", 1658 {"function f() {'use strict'; return arguments[0];}",
1680 {factory->undefined_value()}}, 1659 {factory->undefined_value()}},
1681 {"function f(a) {'use strict'; return arguments[0];}", 1660 {"function f(a) {'use strict'; return arguments[0];}",
1682 {factory->undefined_value()}}, 1661 {factory->undefined_value()}},
1683 {"function f(...restArgs) {return restArgs[0];}", 1662 {"function f(...restArgs) {return restArgs[0];}",
1684 {factory->undefined_value()}}, 1663 {factory->undefined_value()}},
1685 {"function f(a, ...restArgs) {return restArgs[0];}", 1664 {"function f(a, ...restArgs) {return restArgs[0];}",
1686 {factory->undefined_value()}}, 1665 {factory->undefined_value()}},
1687 }; 1666 };
1688 1667
1689 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); 1668 for (size_t i = 0; i < arraysize(snippets); i++) {
1690 for (size_t i = 0; i < num_snippets; i++) {
1691 ScopedVector<char> script(1024); 1669 ScopedVector<char> script(1024);
1692 SNPrintF(script, "%s\n%s();", snippets[i].code_snippet, kFunctionName); 1670 SNPrintF(script, "%s\n%s();", snippets[i].code_snippet, kFunctionName);
1693 1671
1694 BytecodeGraphTester tester(isolate, zone, script.start()); 1672 BytecodeGraphTester tester(isolate, zone, script.start());
1695 auto callable = tester.GetCallable<>(); 1673 auto callable = tester.GetCallable<>();
1696 Handle<Object> return_value = callable().ToHandleChecked(); 1674 Handle<Object> return_value = callable().ToHandleChecked();
1697 CHECK(return_value->SameValue(*snippets[i].return_value())); 1675 CHECK(return_value->SameValue(*snippets[i].return_value()));
1698 } 1676 }
1699 } 1677 }
1700 1678
(...skipping 22 matching lines...) Expand all
1723 factory->NewNumberFromInt(2), factory->NewNumberFromInt(3)}}, 1701 factory->NewNumberFromInt(2), factory->NewNumberFromInt(3)}},
1724 {"function f(a, b, c) {'use strict'; b = c; return arguments[1];}", 1702 {"function f(a, b, c) {'use strict'; b = c; return arguments[1];}",
1725 {factory->NewNumberFromInt(2), factory->NewNumberFromInt(1), 1703 {factory->NewNumberFromInt(2), factory->NewNumberFromInt(1),
1726 factory->NewNumberFromInt(2), factory->NewNumberFromInt(3)}}, 1704 factory->NewNumberFromInt(2), factory->NewNumberFromInt(3)}},
1727 {"function inline_func(a, b) { return arguments[0] }" 1705 {"function inline_func(a, b) { return arguments[0] }"
1728 "function f(a, b, c) {return inline_func(b, c) + arguments[0];}", 1706 "function f(a, b, c) {return inline_func(b, c) + arguments[0];}",
1729 {factory->NewNumberFromInt(3), factory->NewNumberFromInt(1), 1707 {factory->NewNumberFromInt(3), factory->NewNumberFromInt(1),
1730 factory->NewNumberFromInt(2), factory->NewNumberFromInt(30)}}, 1708 factory->NewNumberFromInt(2), factory->NewNumberFromInt(30)}},
1731 }; 1709 };
1732 1710
1733 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); 1711 for (size_t i = 0; i < arraysize(snippets); i++) {
1734 for (size_t i = 0; i < num_snippets; i++) {
1735 ScopedVector<char> script(1024); 1712 ScopedVector<char> script(1024);
1736 SNPrintF(script, "%s\n%s();", snippets[i].code_snippet, kFunctionName); 1713 SNPrintF(script, "%s\n%s();", snippets[i].code_snippet, kFunctionName);
1737 1714
1738 BytecodeGraphTester tester(isolate, zone, script.start()); 1715 BytecodeGraphTester tester(isolate, zone, script.start());
1739 auto callable = 1716 auto callable =
1740 tester.GetCallable<Handle<Object>, Handle<Object>, Handle<Object>>(); 1717 tester.GetCallable<Handle<Object>, Handle<Object>, Handle<Object>>();
1741 Handle<Object> return_value = 1718 Handle<Object> return_value =
1742 callable(snippets[i].parameter(0), snippets[i].parameter(1), 1719 callable(snippets[i].parameter(0), snippets[i].parameter(1),
1743 snippets[i].parameter(2)) 1720 snippets[i].parameter(2))
1744 .ToHandleChecked(); 1721 .ToHandleChecked();
(...skipping 22 matching lines...) Expand all
1767 factory->NewNumberFromInt(2), factory->NewNumberFromInt(3)}}, 1744 factory->NewNumberFromInt(2), factory->NewNumberFromInt(3)}},
1768 {"function f(a, ...restArgs) { return arguments[0] + restArgs[1];}", 1745 {"function f(a, ...restArgs) { return arguments[0] + restArgs[1];}",
1769 {factory->NewNumberFromInt(4), factory->NewNumberFromInt(1), 1746 {factory->NewNumberFromInt(4), factory->NewNumberFromInt(1),
1770 factory->NewNumberFromInt(2), factory->NewNumberFromInt(3)}}, 1747 factory->NewNumberFromInt(2), factory->NewNumberFromInt(3)}},
1771 {"function inline_func(a, ...restArgs) { return restArgs[0] }" 1748 {"function inline_func(a, ...restArgs) { return restArgs[0] }"
1772 "function f(a, b, c) {return inline_func(b, c) + arguments[0];}", 1749 "function f(a, b, c) {return inline_func(b, c) + arguments[0];}",
1773 {factory->NewNumberFromInt(31), factory->NewNumberFromInt(1), 1750 {factory->NewNumberFromInt(31), factory->NewNumberFromInt(1),
1774 factory->NewNumberFromInt(2), factory->NewNumberFromInt(30)}}, 1751 factory->NewNumberFromInt(2), factory->NewNumberFromInt(30)}},
1775 }; 1752 };
1776 1753
1777 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); 1754 for (size_t i = 0; i < arraysize(snippets); i++) {
1778 for (size_t i = 0; i < num_snippets; i++) {
1779 ScopedVector<char> script(1024); 1755 ScopedVector<char> script(1024);
1780 SNPrintF(script, "%s\n%s();", snippets[i].code_snippet, kFunctionName); 1756 SNPrintF(script, "%s\n%s();", snippets[i].code_snippet, kFunctionName);
1781 1757
1782 BytecodeGraphTester tester(isolate, zone, script.start()); 1758 BytecodeGraphTester tester(isolate, zone, script.start());
1783 auto callable = 1759 auto callable =
1784 tester.GetCallable<Handle<Object>, Handle<Object>, Handle<Object>>(); 1760 tester.GetCallable<Handle<Object>, Handle<Object>, Handle<Object>>();
1785 Handle<Object> return_value = 1761 Handle<Object> return_value =
1786 callable(snippets[i].parameter(0), snippets[i].parameter(1), 1762 callable(snippets[i].parameter(0), snippets[i].parameter(1),
1787 snippets[i].parameter(2)) 1763 snippets[i].parameter(2))
1788 .ToHandleChecked(); 1764 .ToHandleChecked();
(...skipping 17 matching lines...) Expand all
1806 {factory->NewStringFromStaticChars("abbd")}}, 1782 {factory->NewStringFromStaticChars("abbd")}},
1807 {"return /ab+d/.exec('cccabbdd')[1];", {factory->undefined_value()}}, 1783 {"return /ab+d/.exec('cccabbdd')[1];", {factory->undefined_value()}},
1808 {"return /AbC/i.exec('ssaBC')[0];", 1784 {"return /AbC/i.exec('ssaBC')[0];",
1809 {factory->NewStringFromStaticChars("aBC")}}, 1785 {factory->NewStringFromStaticChars("aBC")}},
1810 {"return 'ssaBC'.match(/AbC/i)[0];", 1786 {"return 'ssaBC'.match(/AbC/i)[0];",
1811 {factory->NewStringFromStaticChars("aBC")}}, 1787 {factory->NewStringFromStaticChars("aBC")}},
1812 {"return 'ssaBCtAbC'.match(/(AbC)/gi)[1];", 1788 {"return 'ssaBCtAbC'.match(/(AbC)/gi)[1];",
1813 {factory->NewStringFromStaticChars("AbC")}}, 1789 {factory->NewStringFromStaticChars("AbC")}},
1814 }; 1790 };
1815 1791
1816 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); 1792 for (size_t i = 0; i < arraysize(snippets); i++) {
1817 for (size_t i = 0; i < num_snippets; i++) {
1818 ScopedVector<char> script(4096); 1793 ScopedVector<char> script(4096);
1819 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, 1794 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName,
1820 snippets[i].code_snippet, kFunctionName); 1795 snippets[i].code_snippet, kFunctionName);
1821 1796
1822 BytecodeGraphTester tester(isolate, zone, script.start()); 1797 BytecodeGraphTester tester(isolate, zone, script.start());
1823 auto callable = tester.GetCallable<>(); 1798 auto callable = tester.GetCallable<>();
1824 Handle<Object> return_value = callable().ToHandleChecked(); 1799 Handle<Object> return_value = callable().ToHandleChecked();
1825 CHECK(return_value->SameValue(*snippets[i].return_value())); 1800 CHECK(return_value->SameValue(*snippets[i].return_value()));
1826 } 1801 }
1827 } 1802 }
(...skipping 19 matching lines...) Expand all
1847 REPEAT_256(SPACE, "a = 9.34;") 1822 REPEAT_256(SPACE, "a = 9.34;")
1848 "return [a, ++a, a + 2, a + 3][2];", 1823 "return [a, ++a, a + 2, a + 3][2];",
1849 {factory->NewHeapNumber(12.34)}}, 1824 {factory->NewHeapNumber(12.34)}},
1850 {"return [[1, 2, 3], ['a', 'b', 'c']][1][0];", 1825 {"return [[1, 2, 3], ['a', 'b', 'c']][1][0];",
1851 {factory->NewStringFromStaticChars("a")}}, 1826 {factory->NewStringFromStaticChars("a")}},
1852 {"var t = 't'; return [[t, t + 'est'], [1 + t]][0][1];", 1827 {"var t = 't'; return [[t, t + 'est'], [1 + t]][0][1];",
1853 {factory->NewStringFromStaticChars("test")}}, 1828 {factory->NewStringFromStaticChars("test")}},
1854 {"var t = 't'; return [[t, t + 'est'], [1 + t]][1][0];", 1829 {"var t = 't'; return [[t, t + 'est'], [1 + t]][1][0];",
1855 {factory->NewStringFromStaticChars("1t")}}}; 1830 {factory->NewStringFromStaticChars("1t")}}};
1856 1831
1857 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); 1832 for (size_t i = 0; i < arraysize(snippets); i++) {
1858 for (size_t i = 0; i < num_snippets; i++) {
1859 ScopedVector<char> script(4096); 1833 ScopedVector<char> script(4096);
1860 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, 1834 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName,
1861 snippets[i].code_snippet, kFunctionName); 1835 snippets[i].code_snippet, kFunctionName);
1862 1836
1863 BytecodeGraphTester tester(isolate, zone, script.start()); 1837 BytecodeGraphTester tester(isolate, zone, script.start());
1864 auto callable = tester.GetCallable<>(); 1838 auto callable = tester.GetCallable<>();
1865 Handle<Object> return_value = callable().ToHandleChecked(); 1839 Handle<Object> return_value = callable().ToHandleChecked();
1866 CHECK(return_value->SameValue(*snippets[i].return_value())); 1840 CHECK(return_value->SameValue(*snippets[i].return_value()));
1867 } 1841 }
1868 } 1842 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1913 {factory->NewStringFromStaticChars("testing")}}, 1887 {factory->NewStringFromStaticChars("testing")}},
1914 {"var a = 'proto_str';\n" 1888 {"var a = 'proto_str';\n"
1915 "var b = { [a]: 1, __proto__: { var : a } };\n" 1889 "var b = { [a]: 1, __proto__: { var : a } };\n"
1916 "return Object.getPrototypeOf(b).var", 1890 "return Object.getPrototypeOf(b).var",
1917 {factory->NewStringFromStaticChars("proto_str")}}, 1891 {factory->NewStringFromStaticChars("proto_str")}},
1918 {"var n = 'name';\n" 1892 {"var n = 'name';\n"
1919 "return { [n]: 'val', get a() { return 987 } }['a'];", 1893 "return { [n]: 'val', get a() { return 987 } }['a'];",
1920 {factory->NewNumberFromInt(987)}}, 1894 {factory->NewNumberFromInt(987)}},
1921 }; 1895 };
1922 1896
1923 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); 1897 for (size_t i = 0; i < arraysize(snippets); i++) {
1924 for (size_t i = 0; i < num_snippets; i++) {
1925 ScopedVector<char> script(4096); 1898 ScopedVector<char> script(4096);
1926 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, 1899 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName,
1927 snippets[i].code_snippet, kFunctionName); 1900 snippets[i].code_snippet, kFunctionName);
1928 BytecodeGraphTester tester(isolate, zone, script.start()); 1901 BytecodeGraphTester tester(isolate, zone, script.start());
1929 auto callable = tester.GetCallable<>(); 1902 auto callable = tester.GetCallable<>();
1930 Handle<Object> return_value = callable().ToHandleChecked(); 1903 Handle<Object> return_value = callable().ToHandleChecked();
1931 CHECK(return_value->SameValue(*snippets[i].return_value())); 1904 CHECK(return_value->SameValue(*snippets[i].return_value()));
1932 } 1905 }
1933 } 1906 }
1934 1907
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
2022 " x = 4; d = 2;" 1995 " x = 4; d = 2;"
2023 "} else {\n" 1996 "} else {\n"
2024 " d = 3;\n" 1997 " d = 3;\n"
2025 "}" 1998 "}"
2026 "x = d;" 1999 "x = d;"
2027 "function f1() {x}" 2000 "function f1() {x}"
2028 "return x + c;", 2001 "return x + c;",
2029 {factory->NewNumberFromInt(5), factory->NewNumberFromInt(-1)}}, 2002 {factory->NewNumberFromInt(5), factory->NewNumberFromInt(-1)}},
2030 }; 2003 };
2031 2004
2032 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); 2005 for (size_t i = 0; i < arraysize(snippets); i++) {
2033 for (size_t i = 0; i < num_snippets; i++) {
2034 ScopedVector<char> script(2048); 2006 ScopedVector<char> script(2048);
2035 SNPrintF(script, "function %s(p1) { %s };\n%s(0);", kFunctionName, 2007 SNPrintF(script, "function %s(p1) { %s };\n%s(0);", kFunctionName,
2036 snippets[i].code_snippet, kFunctionName); 2008 snippets[i].code_snippet, kFunctionName);
2037 2009
2038 BytecodeGraphTester tester(isolate, zone, script.start()); 2010 BytecodeGraphTester tester(isolate, zone, script.start());
2039 auto callable = tester.GetCallable<Handle<Object>>(); 2011 auto callable = tester.GetCallable<Handle<Object>>();
2040 Handle<Object> return_value = 2012 Handle<Object> return_value =
2041 callable(snippets[i].parameter(0)).ToHandleChecked(); 2013 callable(snippets[i].parameter(0)).ToHandleChecked();
2042 CHECK(return_value->SameValue(*snippets[i].return_value())); 2014 CHECK(return_value->SameValue(*snippets[i].return_value()));
2043 } 2015 }
(...skipping 10 matching lines...) Expand all
2054 {"return (p1 > 1) ? 1 : -1;", 2026 {"return (p1 > 1) ? 1 : -1;",
2055 {factory->NewNumberFromInt(1), factory->NewNumberFromInt(2)}}, 2027 {factory->NewNumberFromInt(1), factory->NewNumberFromInt(2)}},
2056 {"return (p1 > 1) ? 1 : -1;", 2028 {"return (p1 > 1) ? 1 : -1;",
2057 {factory->NewNumberFromInt(-1), factory->NewNumberFromInt(0)}}, 2029 {factory->NewNumberFromInt(-1), factory->NewNumberFromInt(0)}},
2058 {"return (p1 > 50) ? 1 : ((p1 < 10) ? 10 : -10);", 2030 {"return (p1 > 50) ? 1 : ((p1 < 10) ? 10 : -10);",
2059 {factory->NewNumberFromInt(10), factory->NewNumberFromInt(2)}}, 2031 {factory->NewNumberFromInt(10), factory->NewNumberFromInt(2)}},
2060 {"return (p1 > 50) ? 1 : ((p1 < 10) ? 10 : -10);", 2032 {"return (p1 > 50) ? 1 : ((p1 < 10) ? 10 : -10);",
2061 {factory->NewNumberFromInt(-10), factory->NewNumberFromInt(20)}}, 2033 {factory->NewNumberFromInt(-10), factory->NewNumberFromInt(20)}},
2062 }; 2034 };
2063 2035
2064 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); 2036 for (size_t i = 0; i < arraysize(snippets); i++) {
2065 for (size_t i = 0; i < num_snippets; i++) {
2066 ScopedVector<char> script(2048); 2037 ScopedVector<char> script(2048);
2067 SNPrintF(script, "function %s(p1) { %s };\n%s(0);", kFunctionName, 2038 SNPrintF(script, "function %s(p1) { %s };\n%s(0);", kFunctionName,
2068 snippets[i].code_snippet, kFunctionName); 2039 snippets[i].code_snippet, kFunctionName);
2069 2040
2070 BytecodeGraphTester tester(isolate, zone, script.start()); 2041 BytecodeGraphTester tester(isolate, zone, script.start());
2071 auto callable = tester.GetCallable<Handle<Object>>(); 2042 auto callable = tester.GetCallable<Handle<Object>>();
2072 Handle<Object> return_value = 2043 Handle<Object> return_value =
2073 callable(snippets[i].parameter(0)).ToHandleChecked(); 2044 callable(snippets[i].parameter(0)).ToHandleChecked();
2074 CHECK(return_value->SameValue(*snippets[i].return_value())); 2045 CHECK(return_value->SameValue(*snippets[i].return_value()));
2075 } 2046 }
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
2598 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, 2569 SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName,
2599 snippets[i].code_snippet, kFunctionName); 2570 snippets[i].code_snippet, kFunctionName);
2600 2571
2601 BytecodeGraphTester tester(isolate, zone, script.start()); 2572 BytecodeGraphTester tester(isolate, zone, script.start());
2602 auto callable = tester.GetCallable<>(); 2573 auto callable = tester.GetCallable<>();
2603 Handle<Object> return_value = callable().ToHandleChecked(); 2574 Handle<Object> return_value = callable().ToHandleChecked();
2604 CHECK(return_value->SameValue(*snippets[i].return_value())); 2575 CHECK(return_value->SameValue(*snippets[i].return_value()));
2605 } 2576 }
2606 } 2577 }
2607 2578
2608 2579 void TestJumpWithConstantsAndWideConstants(size_t shard) {
2609 TEST(JumpWithConstantsAndWideConstants) { 2580 const int kStep = 46;
2610 const int kStep = 19; 2581 int start = static_cast<int>(7 + 17 * shard);
2611 int start = 7; 2582 for (int constants = start; constants < 300; constants += kStep) {
2612 for (int constants = start; constants < 256 + 3 * kStep; constants += kStep) {
2613 std::stringstream filler_os; 2583 std::stringstream filler_os;
2614 // Generate a string that consumes constant pool entries and 2584 // Generate a string that consumes constant pool entries and
2615 // spread out branch distances in script below. 2585 // spread out branch distances in script below.
2616 for (int i = 0; i < constants; i++) { 2586 for (int i = 0; i < constants; i++) {
2617 filler_os << "var x_ = 'x_" << i << "';\n"; 2587 filler_os << "var x_ = 'x_" << i << "';\n";
2618 } 2588 }
2619 std::string filler(filler_os.str()); 2589 std::string filler(filler_os.str());
2620 2590
2621 std::stringstream script_os; 2591 std::stringstream script_os;
2622 script_os << "function " << kFunctionName << "(a) {\n"; 2592 script_os << "function " << kFunctionName << "(a) {\n";
2623 script_os << " " << filler; 2593 script_os << " " << filler;
2624 script_os << " for (var i = a; i < 2; i++) {\n"; 2594 script_os << " for (var i = a; i < 2; i++) {\n";
2625 script_os << " " << filler; 2595 script_os << " " << filler;
2626 script_os << " if (i == 0) { " << filler << "i = 10; continue; }\n"; 2596 script_os << " if (i == 0) { " << filler << "i = 10; continue; }\n";
2627 script_os << " else if (i == a) { " << filler << "i = 12; break; }\n"; 2597 script_os << " else if (i == a) { " << filler << "i = 12; break; }\n";
2628 script_os << " else { " << filler << " }\n"; 2598 script_os << " else { " << filler << " }\n";
2629 script_os << " }\n"; 2599 script_os << " }\n";
2630 script_os << " return i;\n"; 2600 script_os << " return i;\n";
2631 script_os << "}\n"; 2601 script_os << "}\n";
2632 script_os << kFunctionName << "(0);\n"; 2602 script_os << kFunctionName << "(0);\n";
2633 std::string script(script_os.str()); 2603 std::string script(script_os.str());
2634 2604
2635 HandleAndZoneScope scope; 2605 HandleAndZoneScope scope;
2636 auto isolate = scope.main_isolate(); 2606 auto isolate = scope.main_isolate();
2637 auto factory = isolate->factory(); 2607 auto factory = isolate->factory();
2638 auto zone = scope.main_zone(); 2608 auto zone = scope.main_zone();
2609 BytecodeGraphTester tester(isolate, zone, script.c_str());
2610 auto callable = tester.GetCallable<Handle<Object>>();
rmcilroy 2016/02/16 14:06:56 Thanks for spotting this.
2639 for (int a = 0; a < 3; a++) { 2611 for (int a = 0; a < 3; a++) {
2640 BytecodeGraphTester tester(isolate, zone, script.c_str());
2641 auto callable = tester.GetCallable<Handle<Object>>();
2642 Handle<Object> return_val = 2612 Handle<Object> return_val =
2643 callable(factory->NewNumberFromInt(a)).ToHandleChecked(); 2613 callable(factory->NewNumberFromInt(a)).ToHandleChecked();
2644 static const int results[] = {11, 12, 2}; 2614 static const int results[] = {11, 12, 2};
2645 CHECK_EQ(Handle<Smi>::cast(return_val)->value(), results[a]); 2615 CHECK_EQ(Handle<Smi>::cast(return_val)->value(), results[a]);
2646 } 2616 }
2647 } 2617 }
2648 } 2618 }
2649 2619
2620 SHARD_TEST_BY_4(JumpWithConstantsAndWideConstants)
2621
2650 TEST(BytecodeGraphBuilderDoExpressions) { 2622 TEST(BytecodeGraphBuilderDoExpressions) {
2651 bool old_flag = FLAG_harmony_do_expressions; 2623 bool old_flag = FLAG_harmony_do_expressions;
2652 FLAG_harmony_do_expressions = true; 2624 FLAG_harmony_do_expressions = true;
2653 HandleAndZoneScope scope; 2625 HandleAndZoneScope scope;
2654 Isolate* isolate = scope.main_isolate(); 2626 Isolate* isolate = scope.main_isolate();
2655 Zone* zone = scope.main_zone(); 2627 Zone* zone = scope.main_zone();
2656 Factory* factory = isolate->factory(); 2628 Factory* factory = isolate->factory();
2657 ExpectedSnippet<0> snippets[] = { 2629 ExpectedSnippet<0> snippets[] = {
2658 {"var a = do {}; return a;", {factory->undefined_value()}}, 2630 {"var a = do {}; return a;", {factory->undefined_value()}},
2659 {"var a = do { var x = 100; }; return a;", {factory->undefined_value()}}, 2631 {"var a = do { var x = 100; }; return a;", {factory->undefined_value()}},
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
3003 2975
3004 BytecodeGraphTester tester(isolate, zone, script.start()); 2976 BytecodeGraphTester tester(isolate, zone, script.start());
3005 auto callable = tester.GetCallable<>(); 2977 auto callable = tester.GetCallable<>();
3006 Handle<Object> return_value = callable().ToHandleChecked(); 2978 Handle<Object> return_value = callable().ToHandleChecked();
3007 CHECK(return_value->SameValue(*snippet.return_value())); 2979 CHECK(return_value->SameValue(*snippet.return_value()));
3008 } 2980 }
3009 2981
3010 } // namespace compiler 2982 } // namespace compiler
3011 } // namespace internal 2983 } // namespace internal
3012 } // namespace v8 2984 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698