OLD | NEW |
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 "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/execution.h" | 7 #include "src/execution.h" |
8 #include "src/handles.h" | 8 #include "src/handles.h" |
9 #include "src/interpreter/bytecode-array-builder.h" | 9 #include "src/interpreter/bytecode-array-builder.h" |
10 #include "src/interpreter/interpreter.h" | 10 #include "src/interpreter/interpreter.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 MaybeHandle<Object> operator()(A... args) { | 43 MaybeHandle<Object> operator()(A... args) { |
44 return CallInterpreter(isolate_, function_, args...); | 44 return CallInterpreter(isolate_, function_, args...); |
45 } | 45 } |
46 | 46 |
47 private: | 47 private: |
48 Isolate* isolate_; | 48 Isolate* isolate_; |
49 Handle<JSFunction> function_; | 49 Handle<JSFunction> function_; |
50 }; | 50 }; |
51 | 51 |
52 | 52 |
| 53 static const char* kFunctionName = "f"; |
| 54 |
| 55 |
53 class InterpreterTester { | 56 class InterpreterTester { |
54 public: | 57 public: |
55 InterpreterTester(Isolate* isolate, Handle<BytecodeArray> bytecode, | 58 InterpreterTester(Isolate* isolate, const char* source, |
56 MaybeHandle<TypeFeedbackVector> feedback_vector = | 59 MaybeHandle<BytecodeArray> bytecode, |
57 MaybeHandle<TypeFeedbackVector>()) | 60 MaybeHandle<TypeFeedbackVector> feedback_vector) |
58 : isolate_(isolate), | 61 : isolate_(isolate), |
| 62 source_(source), |
59 bytecode_(bytecode), | 63 bytecode_(bytecode), |
60 feedback_vector_(feedback_vector) { | 64 feedback_vector_(feedback_vector) { |
61 i::FLAG_vector_stores = true; | 65 i::FLAG_vector_stores = true; |
62 i::FLAG_ignition = true; | 66 i::FLAG_ignition = true; |
| 67 i::FLAG_always_opt = false; |
| 68 // Set ignition filter flag via SetFlagsFromString to avoid double-free |
| 69 // (or potential leak with StrDup() based on ownership confusion). |
| 70 ScopedVector<char> ignition_filter(64); |
| 71 SNPrintF(ignition_filter, "--ignition-filter=%s", kFunctionName); |
| 72 FlagList::SetFlagsFromString(ignition_filter.start(), |
| 73 ignition_filter.length()); |
63 // Ensure handler table is generated. | 74 // Ensure handler table is generated. |
64 isolate->interpreter()->Initialize(); | 75 isolate->interpreter()->Initialize(); |
65 } | 76 } |
| 77 |
| 78 InterpreterTester(Isolate* isolate, Handle<BytecodeArray> bytecode, |
| 79 MaybeHandle<TypeFeedbackVector> feedback_vector = |
| 80 MaybeHandle<TypeFeedbackVector>()) |
| 81 : InterpreterTester(isolate, nullptr, bytecode, feedback_vector) {} |
| 82 |
| 83 |
| 84 InterpreterTester(Isolate* isolate, const char* source) |
| 85 : InterpreterTester(isolate, source, MaybeHandle<BytecodeArray>(), |
| 86 MaybeHandle<TypeFeedbackVector>()) {} |
| 87 |
66 virtual ~InterpreterTester() {} | 88 virtual ~InterpreterTester() {} |
67 | 89 |
68 template <class... A> | 90 template <class... A> |
69 InterpreterCallable<A...> GetCallable() { | 91 InterpreterCallable<A...> GetCallable() { |
70 return InterpreterCallable<A...>(isolate_, GetBytecodeFunction<A...>()); | 92 return InterpreterCallable<A...>(isolate_, GetBytecodeFunction<A...>()); |
71 } | 93 } |
72 | 94 |
73 Handle<Object> NewObject(const char* script) { | 95 static Handle<Object> NewObject(const char* script) { |
74 return v8::Utils::OpenHandle(*CompileRun(script)); | 96 return v8::Utils::OpenHandle(*CompileRun(script)); |
75 } | 97 } |
76 | 98 |
| 99 static Handle<String> GetName(Isolate* isolate, const char* name) { |
| 100 Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(name); |
| 101 return isolate->factory()->string_table()->LookupString(isolate, result); |
| 102 } |
| 103 |
| 104 static std::string function_name() { |
| 105 return std::string(kFunctionName); |
| 106 } |
| 107 |
77 private: | 108 private: |
78 Isolate* isolate_; | 109 Isolate* isolate_; |
79 Handle<BytecodeArray> bytecode_; | 110 const char* source_; |
| 111 MaybeHandle<BytecodeArray> bytecode_; |
80 MaybeHandle<TypeFeedbackVector> feedback_vector_; | 112 MaybeHandle<TypeFeedbackVector> feedback_vector_; |
81 | 113 |
82 template <class... A> | 114 template <class... A> |
83 Handle<JSFunction> GetBytecodeFunction() { | 115 Handle<JSFunction> GetBytecodeFunction() { |
84 int arg_count = sizeof...(A); | 116 Handle<JSFunction> function; |
85 std::string function_text("(function("); | 117 if (source_) { |
86 for (int i = 0; i < arg_count; i++) { | 118 CompileRun(source_); |
87 function_text += i == 0 ? "a" : ", a"; | 119 Local<Function> api_function = |
| 120 Local<Function>::Cast(CcTest::global()->Get(v8_str(kFunctionName))); |
| 121 function = v8::Utils::OpenHandle(*api_function); |
| 122 } else { |
| 123 int arg_count = sizeof...(A); |
| 124 std::string source("(function " + function_name() + "("); |
| 125 for (int i = 0; i < arg_count; i++) { |
| 126 source += i == 0 ? "a" : ", a"; |
| 127 } |
| 128 source += "){})"; |
| 129 function = v8::Utils::OpenHandle( |
| 130 *v8::Handle<v8::Function>::Cast(CompileRun(source.c_str()))); |
| 131 function->ReplaceCode( |
| 132 *isolate_->builtins()->InterpreterEntryTrampoline()); |
88 } | 133 } |
89 function_text += "){})"; | |
90 | 134 |
91 Handle<JSFunction> function = v8::Utils::OpenHandle( | 135 if (!bytecode_.is_null()) { |
92 *v8::Handle<v8::Function>::Cast(CompileRun(function_text.c_str()))); | 136 function->shared()->set_function_data(*bytecode_.ToHandleChecked()); |
93 function->ReplaceCode(*isolate_->builtins()->InterpreterEntryTrampoline()); | 137 } |
94 function->shared()->set_function_data(*bytecode_); | |
95 if (!feedback_vector_.is_null()) { | 138 if (!feedback_vector_.is_null()) { |
96 function->shared()->set_feedback_vector( | 139 function->shared()->set_feedback_vector( |
97 *feedback_vector_.ToHandleChecked()); | 140 *feedback_vector_.ToHandleChecked()); |
98 } | 141 } |
99 return function; | 142 return function; |
100 } | 143 } |
101 | 144 |
102 DISALLOW_COPY_AND_ASSIGN(InterpreterTester); | 145 DISALLOW_COPY_AND_ASSIGN(InterpreterTester); |
103 }; | 146 }; |
104 | 147 |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 Handle<Smi> arg7 = Handle<Smi>(Smi::FromInt(7), handles.main_isolate()); | 506 Handle<Smi> arg7 = Handle<Smi>(Smi::FromInt(7), handles.main_isolate()); |
464 Handle<Smi> arg8 = Handle<Smi>(Smi::FromInt(8), handles.main_isolate()); | 507 Handle<Smi> arg8 = Handle<Smi>(Smi::FromInt(8), handles.main_isolate()); |
465 // Check for Smis. | 508 // Check for Smis. |
466 Handle<Object> return_val = | 509 Handle<Object> return_val = |
467 callable(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) | 510 callable(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) |
468 .ToHandleChecked(); | 511 .ToHandleChecked(); |
469 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(36)); | 512 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(36)); |
470 } | 513 } |
471 | 514 |
472 | 515 |
| 516 TEST(InterpreterLoadGlobal) { |
| 517 HandleAndZoneScope handles; |
| 518 |
| 519 // Test loading a global. |
| 520 std::string source( |
| 521 "var global = 321;\n" |
| 522 "function " + InterpreterTester::function_name() + "() {\n" |
| 523 " return global;\n" |
| 524 "}"); |
| 525 InterpreterTester tester(handles.main_isolate(), source.c_str()); |
| 526 auto callable = tester.GetCallable<>(); |
| 527 |
| 528 Handle<Object> return_val = callable().ToHandleChecked(); |
| 529 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(321)); |
| 530 } |
| 531 |
| 532 |
| 533 TEST(InterpreterCallGlobal) { |
| 534 HandleAndZoneScope handles; |
| 535 |
| 536 // Test calling a global function. |
| 537 std::string source( |
| 538 "function g_add(a, b) { return a + b; }\n" |
| 539 "function " + InterpreterTester::function_name() + "() {\n" |
| 540 " return g_add(5, 10);\n" |
| 541 "}"); |
| 542 InterpreterTester tester(handles.main_isolate(), source.c_str()); |
| 543 auto callable = tester.GetCallable<>(); |
| 544 |
| 545 Handle<Object> return_val = callable().ToHandleChecked(); |
| 546 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(15)); |
| 547 } |
| 548 |
| 549 |
473 TEST(InterpreterLoadNamedProperty) { | 550 TEST(InterpreterLoadNamedProperty) { |
474 HandleAndZoneScope handles; | 551 HandleAndZoneScope handles; |
475 i::Isolate* isolate = handles.main_isolate(); | 552 i::Isolate* isolate = handles.main_isolate(); |
476 i::Factory* factory = isolate->factory(); | 553 i::Factory* factory = isolate->factory(); |
477 | 554 |
478 i::Code::Kind ic_kinds[] = {i::Code::LOAD_IC}; | 555 i::Code::Kind ic_kinds[] = {i::Code::LOAD_IC}; |
479 i::FeedbackVectorSpec feedback_spec(0, 1, ic_kinds); | 556 i::FeedbackVectorSpec feedback_spec(0, 1, ic_kinds); |
480 Handle<i::TypeFeedbackVector> vector = | 557 Handle<i::TypeFeedbackVector> vector = |
481 factory->NewTypeFeedbackVector(&feedback_spec); | 558 factory->NewTypeFeedbackVector(&feedback_spec); |
482 | 559 |
483 Handle<i::String> name = factory->NewStringFromAsciiChecked("val"); | 560 Handle<i::String> name = factory->NewStringFromAsciiChecked("val"); |
484 name = factory->string_table()->LookupString(isolate, name); | 561 name = factory->string_table()->LookupString(isolate, name); |
485 | 562 |
486 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); | 563 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); |
487 builder.set_locals_count(0); | 564 builder.set_locals_count(0); |
488 builder.set_parameter_count(1); | 565 builder.set_parameter_count(1); |
489 builder.LoadLiteral(name) | 566 builder.LoadLiteral(name) |
490 .LoadNamedProperty(builder.Parameter(0), vector->first_ic_slot_index(), | 567 .LoadNamedProperty(builder.Parameter(0), vector->first_ic_slot_index(), |
491 i::SLOPPY) | 568 i::SLOPPY) |
492 .Return(); | 569 .Return(); |
493 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 570 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
494 | 571 |
495 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); | 572 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); |
496 auto callable = tester.GetCallable<Handle<Object>>(); | 573 auto callable = tester.GetCallable<Handle<Object>>(); |
497 | 574 |
498 Handle<Object> object = tester.NewObject("({ val : 123 })"); | 575 Handle<Object> object = InterpreterTester::NewObject("({ val : 123 })"); |
499 // Test IC miss. | 576 // Test IC miss. |
500 Handle<Object> return_val = callable(object).ToHandleChecked(); | 577 Handle<Object> return_val = callable(object).ToHandleChecked(); |
501 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(123)); | 578 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(123)); |
502 | 579 |
503 // Test transition to monomorphic IC. | 580 // Test transition to monomorphic IC. |
504 return_val = callable(object).ToHandleChecked(); | 581 return_val = callable(object).ToHandleChecked(); |
505 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(123)); | 582 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(123)); |
506 | 583 |
507 // Test transition to polymorphic IC. | 584 // Test transition to polymorphic IC. |
508 Handle<Object> object2 = tester.NewObject("({ val : 456, other : 123 })"); | 585 Handle<Object> object2 = |
| 586 InterpreterTester::NewObject("({ val : 456, other : 123 })"); |
509 return_val = callable(object2).ToHandleChecked(); | 587 return_val = callable(object2).ToHandleChecked(); |
510 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(456)); | 588 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(456)); |
511 | 589 |
512 // Test transition to megamorphic IC. | 590 // Test transition to megamorphic IC. |
513 Handle<Object> object3 = tester.NewObject("({ val : 789, val2 : 123 })"); | 591 Handle<Object> object3 = |
| 592 InterpreterTester::NewObject("({ val : 789, val2 : 123 })"); |
514 callable(object3).ToHandleChecked(); | 593 callable(object3).ToHandleChecked(); |
515 Handle<Object> object4 = tester.NewObject("({ val : 789, val3 : 123 })"); | 594 Handle<Object> object4 = |
| 595 InterpreterTester::NewObject("({ val : 789, val3 : 123 })"); |
516 callable(object4).ToHandleChecked(); | 596 callable(object4).ToHandleChecked(); |
517 Handle<Object> object5 = tester.NewObject("({ val : 789, val4 : 123 })"); | 597 Handle<Object> object5 = |
| 598 InterpreterTester::NewObject("({ val : 789, val4 : 123 })"); |
518 return_val = callable(object5).ToHandleChecked(); | 599 return_val = callable(object5).ToHandleChecked(); |
519 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(789)); | 600 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(789)); |
520 } | 601 } |
521 | 602 |
522 | 603 |
523 TEST(InterpreterLoadKeyedProperty) { | 604 TEST(InterpreterLoadKeyedProperty) { |
524 HandleAndZoneScope handles; | 605 HandleAndZoneScope handles; |
525 i::Isolate* isolate = handles.main_isolate(); | 606 i::Isolate* isolate = handles.main_isolate(); |
526 i::Factory* factory = isolate->factory(); | 607 i::Factory* factory = isolate->factory(); |
527 | 608 |
(...skipping 10 matching lines...) Expand all Loading... |
538 builder.set_parameter_count(1); | 619 builder.set_parameter_count(1); |
539 builder.LoadLiteral(key) | 620 builder.LoadLiteral(key) |
540 .LoadKeyedProperty(builder.Parameter(0), vector->first_ic_slot_index(), | 621 .LoadKeyedProperty(builder.Parameter(0), vector->first_ic_slot_index(), |
541 i::SLOPPY) | 622 i::SLOPPY) |
542 .Return(); | 623 .Return(); |
543 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 624 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
544 | 625 |
545 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); | 626 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); |
546 auto callable = tester.GetCallable<Handle<Object>>(); | 627 auto callable = tester.GetCallable<Handle<Object>>(); |
547 | 628 |
548 Handle<Object> object = tester.NewObject("({ key : 123 })"); | 629 Handle<Object> object = InterpreterTester::NewObject("({ key : 123 })"); |
549 // Test IC miss. | 630 // Test IC miss. |
550 Handle<Object> return_val = callable(object).ToHandleChecked(); | 631 Handle<Object> return_val = callable(object).ToHandleChecked(); |
551 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(123)); | 632 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(123)); |
552 | 633 |
553 // Test transition to monomorphic IC. | 634 // Test transition to monomorphic IC. |
554 return_val = callable(object).ToHandleChecked(); | 635 return_val = callable(object).ToHandleChecked(); |
555 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(123)); | 636 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(123)); |
556 | 637 |
557 // Test transition to megamorphic IC. | 638 // Test transition to megamorphic IC. |
558 Handle<Object> object3 = tester.NewObject("({ key : 789, val2 : 123 })"); | 639 Handle<Object> object3 = |
| 640 InterpreterTester::NewObject("({ key : 789, val2 : 123 })"); |
559 return_val = callable(object3).ToHandleChecked(); | 641 return_val = callable(object3).ToHandleChecked(); |
560 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(789)); | 642 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(789)); |
561 } | 643 } |
562 | 644 |
563 | 645 |
564 TEST(InterpreterStoreNamedProperty) { | 646 TEST(InterpreterStoreNamedProperty) { |
565 HandleAndZoneScope handles; | 647 HandleAndZoneScope handles; |
566 i::Isolate* isolate = handles.main_isolate(); | 648 i::Isolate* isolate = handles.main_isolate(); |
567 i::Factory* factory = isolate->factory(); | 649 i::Factory* factory = isolate->factory(); |
568 | 650 |
(...skipping 11 matching lines...) Expand all Loading... |
580 builder.LoadLiteral(name) | 662 builder.LoadLiteral(name) |
581 .StoreAccumulatorInRegister(Register(0)) | 663 .StoreAccumulatorInRegister(Register(0)) |
582 .LoadLiteral(Smi::FromInt(999)) | 664 .LoadLiteral(Smi::FromInt(999)) |
583 .StoreNamedProperty(builder.Parameter(0), Register(0), | 665 .StoreNamedProperty(builder.Parameter(0), Register(0), |
584 vector->first_ic_slot_index(), i::SLOPPY) | 666 vector->first_ic_slot_index(), i::SLOPPY) |
585 .Return(); | 667 .Return(); |
586 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 668 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
587 | 669 |
588 InterpreterTester tester(isolate, bytecode_array, vector); | 670 InterpreterTester tester(isolate, bytecode_array, vector); |
589 auto callable = tester.GetCallable<Handle<Object>>(); | 671 auto callable = tester.GetCallable<Handle<Object>>(); |
590 Handle<Object> object = tester.NewObject("({ val : 123 })"); | 672 Handle<Object> object = InterpreterTester::NewObject("({ val : 123 })"); |
591 // Test IC miss. | 673 // Test IC miss. |
592 Handle<Object> result; | 674 Handle<Object> result; |
593 callable(object).ToHandleChecked(); | 675 callable(object).ToHandleChecked(); |
594 CHECK(Runtime::GetObjectProperty(isolate, object, name).ToHandle(&result)); | 676 CHECK(Runtime::GetObjectProperty(isolate, object, name).ToHandle(&result)); |
595 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999)); | 677 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999)); |
596 | 678 |
597 // Test transition to monomorphic IC. | 679 // Test transition to monomorphic IC. |
598 callable(object).ToHandleChecked(); | 680 callable(object).ToHandleChecked(); |
599 CHECK(Runtime::GetObjectProperty(isolate, object, name).ToHandle(&result)); | 681 CHECK(Runtime::GetObjectProperty(isolate, object, name).ToHandle(&result)); |
600 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999)); | 682 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999)); |
601 | 683 |
602 // Test transition to polymorphic IC. | 684 // Test transition to polymorphic IC. |
603 Handle<Object> object2 = tester.NewObject("({ val : 456, other : 123 })"); | 685 Handle<Object> object2 = |
| 686 InterpreterTester::NewObject("({ val : 456, other : 123 })"); |
604 callable(object2).ToHandleChecked(); | 687 callable(object2).ToHandleChecked(); |
605 CHECK(Runtime::GetObjectProperty(isolate, object2, name).ToHandle(&result)); | 688 CHECK(Runtime::GetObjectProperty(isolate, object2, name).ToHandle(&result)); |
606 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999)); | 689 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999)); |
607 | 690 |
608 // Test transition to megamorphic IC. | 691 // Test transition to megamorphic IC. |
609 Handle<Object> object3 = tester.NewObject("({ val : 789, val2 : 123 })"); | 692 Handle<Object> object3 = |
| 693 InterpreterTester::NewObject("({ val : 789, val2 : 123 })"); |
610 callable(object3).ToHandleChecked(); | 694 callable(object3).ToHandleChecked(); |
611 Handle<Object> object4 = tester.NewObject("({ val : 789, val3 : 123 })"); | 695 Handle<Object> object4 = |
| 696 InterpreterTester::NewObject("({ val : 789, val3 : 123 })"); |
612 callable(object4).ToHandleChecked(); | 697 callable(object4).ToHandleChecked(); |
613 Handle<Object> object5 = tester.NewObject("({ val : 789, val4 : 123 })"); | 698 Handle<Object> object5 = |
| 699 InterpreterTester::NewObject("({ val : 789, val4 : 123 })"); |
614 callable(object5).ToHandleChecked(); | 700 callable(object5).ToHandleChecked(); |
615 CHECK(Runtime::GetObjectProperty(isolate, object5, name).ToHandle(&result)); | 701 CHECK(Runtime::GetObjectProperty(isolate, object5, name).ToHandle(&result)); |
616 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999)); | 702 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999)); |
617 } | 703 } |
618 | 704 |
619 | 705 |
620 TEST(InterpreterStoreKeyedProperty) { | 706 TEST(InterpreterStoreKeyedProperty) { |
621 HandleAndZoneScope handles; | 707 HandleAndZoneScope handles; |
622 i::Isolate* isolate = handles.main_isolate(); | 708 i::Isolate* isolate = handles.main_isolate(); |
623 i::Factory* factory = isolate->factory(); | 709 i::Factory* factory = isolate->factory(); |
(...skipping 12 matching lines...) Expand all Loading... |
636 builder.LoadLiteral(name) | 722 builder.LoadLiteral(name) |
637 .StoreAccumulatorInRegister(Register(0)) | 723 .StoreAccumulatorInRegister(Register(0)) |
638 .LoadLiteral(Smi::FromInt(999)) | 724 .LoadLiteral(Smi::FromInt(999)) |
639 .StoreKeyedProperty(builder.Parameter(0), Register(0), | 725 .StoreKeyedProperty(builder.Parameter(0), Register(0), |
640 vector->first_ic_slot_index(), i::SLOPPY) | 726 vector->first_ic_slot_index(), i::SLOPPY) |
641 .Return(); | 727 .Return(); |
642 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 728 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
643 | 729 |
644 InterpreterTester tester(isolate, bytecode_array, vector); | 730 InterpreterTester tester(isolate, bytecode_array, vector); |
645 auto callable = tester.GetCallable<Handle<Object>>(); | 731 auto callable = tester.GetCallable<Handle<Object>>(); |
646 Handle<Object> object = tester.NewObject("({ val : 123 })"); | 732 Handle<Object> object = InterpreterTester::NewObject("({ val : 123 })"); |
647 // Test IC miss. | 733 // Test IC miss. |
648 Handle<Object> result; | 734 Handle<Object> result; |
649 callable(object).ToHandleChecked(); | 735 callable(object).ToHandleChecked(); |
650 CHECK(Runtime::GetObjectProperty(isolate, object, name).ToHandle(&result)); | 736 CHECK(Runtime::GetObjectProperty(isolate, object, name).ToHandle(&result)); |
651 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999)); | 737 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999)); |
652 | 738 |
653 // Test transition to monomorphic IC. | 739 // Test transition to monomorphic IC. |
654 callable(object).ToHandleChecked(); | 740 callable(object).ToHandleChecked(); |
655 CHECK(Runtime::GetObjectProperty(isolate, object, name).ToHandle(&result)); | 741 CHECK(Runtime::GetObjectProperty(isolate, object, name).ToHandle(&result)); |
656 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999)); | 742 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999)); |
657 | 743 |
658 // Test transition to megamorphic IC. | 744 // Test transition to megamorphic IC. |
659 Handle<Object> object2 = tester.NewObject("({ val : 456, other : 123 })"); | 745 Handle<Object> object2 = |
| 746 InterpreterTester::NewObject("({ val : 456, other : 123 })"); |
660 callable(object2).ToHandleChecked(); | 747 callable(object2).ToHandleChecked(); |
661 CHECK(Runtime::GetObjectProperty(isolate, object2, name).ToHandle(&result)); | 748 CHECK(Runtime::GetObjectProperty(isolate, object2, name).ToHandle(&result)); |
662 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999)); | 749 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999)); |
663 } | 750 } |
664 | 751 |
665 | 752 |
666 TEST(InterpreterCall) { | 753 TEST(InterpreterCall) { |
667 HandleAndZoneScope handles; | 754 HandleAndZoneScope handles; |
668 i::Isolate* isolate = handles.main_isolate(); | 755 i::Isolate* isolate = handles.main_isolate(); |
669 i::Factory* factory = isolate->factory(); | 756 i::Factory* factory = isolate->factory(); |
(...skipping 15 matching lines...) Expand all Loading... |
685 .LoadNamedProperty(builder.Parameter(0), vector->first_ic_slot_index(), | 772 .LoadNamedProperty(builder.Parameter(0), vector->first_ic_slot_index(), |
686 i::SLOPPY) | 773 i::SLOPPY) |
687 .StoreAccumulatorInRegister(Register(0)) | 774 .StoreAccumulatorInRegister(Register(0)) |
688 .Call(Register(0), builder.Parameter(0), 0) | 775 .Call(Register(0), builder.Parameter(0), 0) |
689 .Return(); | 776 .Return(); |
690 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 777 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
691 | 778 |
692 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); | 779 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); |
693 auto callable = tester.GetCallable<Handle<Object>>(); | 780 auto callable = tester.GetCallable<Handle<Object>>(); |
694 | 781 |
695 Handle<Object> object = tester.NewObject( | 782 Handle<Object> object = InterpreterTester::NewObject( |
696 "new (function Obj() { this.func = function() { return 0x265; }})()"); | 783 "new (function Obj() { this.func = function() { return 0x265; }})()"); |
697 Handle<Object> return_val = callable(object).ToHandleChecked(); | 784 Handle<Object> return_val = callable(object).ToHandleChecked(); |
698 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(0x265)); | 785 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(0x265)); |
699 } | 786 } |
700 | 787 |
701 // Check that receiver is passed properly. | 788 // Check that receiver is passed properly. |
702 { | 789 { |
703 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); | 790 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); |
704 builder.set_locals_count(1); | 791 builder.set_locals_count(1); |
705 builder.set_parameter_count(1); | 792 builder.set_parameter_count(1); |
706 builder.LoadLiteral(name) | 793 builder.LoadLiteral(name) |
707 .LoadNamedProperty(builder.Parameter(0), vector->first_ic_slot_index(), | 794 .LoadNamedProperty(builder.Parameter(0), vector->first_ic_slot_index(), |
708 i::SLOPPY) | 795 i::SLOPPY) |
709 .StoreAccumulatorInRegister(Register(0)) | 796 .StoreAccumulatorInRegister(Register(0)) |
710 .Call(Register(0), builder.Parameter(0), 0) | 797 .Call(Register(0), builder.Parameter(0), 0) |
711 .Return(); | 798 .Return(); |
712 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 799 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
713 | 800 |
714 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); | 801 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); |
715 auto callable = tester.GetCallable<Handle<Object>>(); | 802 auto callable = tester.GetCallable<Handle<Object>>(); |
716 | 803 |
717 Handle<Object> object = tester.NewObject( | 804 Handle<Object> object = InterpreterTester::NewObject( |
718 "new (function Obj() {" | 805 "new (function Obj() {" |
719 " this.val = 1234;" | 806 " this.val = 1234;" |
720 " this.func = function() { return this.val; };" | 807 " this.func = function() { return this.val; };" |
721 "})()"); | 808 "})()"); |
722 Handle<Object> return_val = callable(object).ToHandleChecked(); | 809 Handle<Object> return_val = callable(object).ToHandleChecked(); |
723 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(1234)); | 810 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(1234)); |
724 } | 811 } |
725 | 812 |
726 // Check with two parameters (+ receiver). | 813 // Check with two parameters (+ receiver). |
727 { | 814 { |
(...skipping 10 matching lines...) Expand all Loading... |
738 .StoreAccumulatorInRegister(Register(2)) | 825 .StoreAccumulatorInRegister(Register(2)) |
739 .LoadLiteral(Smi::FromInt(11)) | 826 .LoadLiteral(Smi::FromInt(11)) |
740 .StoreAccumulatorInRegister(Register(3)) | 827 .StoreAccumulatorInRegister(Register(3)) |
741 .Call(Register(0), Register(1), 2) | 828 .Call(Register(0), Register(1), 2) |
742 .Return(); | 829 .Return(); |
743 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 830 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
744 | 831 |
745 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); | 832 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); |
746 auto callable = tester.GetCallable<Handle<Object>>(); | 833 auto callable = tester.GetCallable<Handle<Object>>(); |
747 | 834 |
748 Handle<Object> object = tester.NewObject( | 835 Handle<Object> object = InterpreterTester::NewObject( |
749 "new (function Obj() { " | 836 "new (function Obj() { " |
750 " this.func = function(a, b) { return a - b; }" | 837 " this.func = function(a, b) { return a - b; }" |
751 "})()"); | 838 "})()"); |
752 Handle<Object> return_val = callable(object).ToHandleChecked(); | 839 Handle<Object> return_val = callable(object).ToHandleChecked(); |
753 CHECK(return_val->SameValue(Smi::FromInt(40))); | 840 CHECK(return_val->SameValue(Smi::FromInt(40))); |
754 } | 841 } |
755 | 842 |
756 // Check with 10 parameters (+ receiver). | 843 // Check with 10 parameters (+ receiver). |
757 { | 844 { |
758 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); | 845 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); |
(...skipping 25 matching lines...) Expand all Loading... |
784 .StoreAccumulatorInRegister(Register(10)) | 871 .StoreAccumulatorInRegister(Register(10)) |
785 .LoadLiteral(factory->NewStringFromAsciiChecked("j")) | 872 .LoadLiteral(factory->NewStringFromAsciiChecked("j")) |
786 .StoreAccumulatorInRegister(Register(11)) | 873 .StoreAccumulatorInRegister(Register(11)) |
787 .Call(Register(0), Register(1), 10) | 874 .Call(Register(0), Register(1), 10) |
788 .Return(); | 875 .Return(); |
789 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 876 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
790 | 877 |
791 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); | 878 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); |
792 auto callable = tester.GetCallable<Handle<Object>>(); | 879 auto callable = tester.GetCallable<Handle<Object>>(); |
793 | 880 |
794 Handle<Object> object = tester.NewObject( | 881 Handle<Object> object = InterpreterTester::NewObject( |
795 "new (function Obj() { " | 882 "new (function Obj() { " |
796 " this.prefix = \"prefix_\";" | 883 " this.prefix = \"prefix_\";" |
797 " this.func = function(a, b, c, d, e, f, g, h, i, j) {" | 884 " this.func = function(a, b, c, d, e, f, g, h, i, j) {" |
798 " return this.prefix + a + b + c + d + e + f + g + h + i + j;" | 885 " return this.prefix + a + b + c + d + e + f + g + h + i + j;" |
799 " }" | 886 " }" |
800 "})()"); | 887 "})()"); |
801 Handle<Object> return_val = callable(object).ToHandleChecked(); | 888 Handle<Object> return_val = callable(object).ToHandleChecked(); |
802 Handle<i::String> expected = | 889 Handle<i::String> expected = |
803 factory->NewStringFromAsciiChecked("prefix_abcdefghij"); | 890 factory->NewStringFromAsciiChecked("prefix_abcdefghij"); |
804 CHECK(i::String::cast(*return_val)->Equals(*expected)); | 891 CHECK(i::String::cast(*return_val)->Equals(*expected)); |
805 } | 892 } |
806 } | 893 } |
OLD | NEW |