| 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" |
| 11 #include "test/cctest/cctest.h" | 11 #include "test/cctest/cctest.h" |
| 12 #include "test/cctest/test-feedback-vector.h" |
| 12 | 13 |
| 13 namespace v8 { | 14 namespace v8 { |
| 14 namespace internal { | 15 namespace internal { |
| 15 namespace interpreter { | 16 namespace interpreter { |
| 16 | 17 |
| 17 | 18 |
| 18 static MaybeHandle<Object> CallInterpreter(Isolate* isolate, | 19 static MaybeHandle<Object> CallInterpreter(Isolate* isolate, |
| 19 Handle<JSFunction> function) { | 20 Handle<JSFunction> function) { |
| 20 return Execution::Call(isolate, function, | 21 return Execution::Call(isolate, function, |
| 21 isolate->factory()->undefined_value(), 0, nullptr); | 22 isolate->factory()->undefined_value(), 0, nullptr); |
| (...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 TEST(InterpreterLoadNamedProperty) { | 591 TEST(InterpreterLoadNamedProperty) { |
| 591 HandleAndZoneScope handles; | 592 HandleAndZoneScope handles; |
| 592 i::Isolate* isolate = handles.main_isolate(); | 593 i::Isolate* isolate = handles.main_isolate(); |
| 593 i::Factory* factory = isolate->factory(); | 594 i::Factory* factory = isolate->factory(); |
| 594 i::Zone zone; | 595 i::Zone zone; |
| 595 | 596 |
| 596 i::FeedbackVectorSpec feedback_spec(&zone); | 597 i::FeedbackVectorSpec feedback_spec(&zone); |
| 597 i::FeedbackVectorSlot slot = feedback_spec.AddLoadICSlot(); | 598 i::FeedbackVectorSlot slot = feedback_spec.AddLoadICSlot(); |
| 598 | 599 |
| 599 Handle<i::TypeFeedbackVector> vector = | 600 Handle<i::TypeFeedbackVector> vector = |
| 600 i::TypeFeedbackVector::New(isolate, &feedback_spec); | 601 i::NewTypeFeedbackVector(isolate, &feedback_spec); |
| 601 | 602 |
| 602 Handle<i::String> name = factory->NewStringFromAsciiChecked("val"); | 603 Handle<i::String> name = factory->NewStringFromAsciiChecked("val"); |
| 603 name = factory->string_table()->LookupString(isolate, name); | 604 name = factory->string_table()->LookupString(isolate, name); |
| 604 | 605 |
| 605 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); | 606 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); |
| 606 builder.set_locals_count(0); | 607 builder.set_locals_count(0); |
| 607 builder.set_parameter_count(1); | 608 builder.set_parameter_count(1); |
| 608 builder.LoadLiteral(name) | 609 builder.LoadLiteral(name) |
| 609 .LoadNamedProperty(builder.Parameter(0), vector->GetIndex(slot), | 610 .LoadNamedProperty(builder.Parameter(0), vector->GetIndex(slot), |
| 610 i::SLOPPY) | 611 i::SLOPPY) |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 646 TEST(InterpreterLoadKeyedProperty) { | 647 TEST(InterpreterLoadKeyedProperty) { |
| 647 HandleAndZoneScope handles; | 648 HandleAndZoneScope handles; |
| 648 i::Isolate* isolate = handles.main_isolate(); | 649 i::Isolate* isolate = handles.main_isolate(); |
| 649 i::Factory* factory = isolate->factory(); | 650 i::Factory* factory = isolate->factory(); |
| 650 i::Zone zone; | 651 i::Zone zone; |
| 651 | 652 |
| 652 i::FeedbackVectorSpec feedback_spec(&zone); | 653 i::FeedbackVectorSpec feedback_spec(&zone); |
| 653 i::FeedbackVectorSlot slot = feedback_spec.AddKeyedLoadICSlot(); | 654 i::FeedbackVectorSlot slot = feedback_spec.AddKeyedLoadICSlot(); |
| 654 | 655 |
| 655 Handle<i::TypeFeedbackVector> vector = | 656 Handle<i::TypeFeedbackVector> vector = |
| 656 i::TypeFeedbackVector::New(isolate, &feedback_spec); | 657 i::NewTypeFeedbackVector(isolate, &feedback_spec); |
| 657 | 658 |
| 658 Handle<i::String> key = factory->NewStringFromAsciiChecked("key"); | 659 Handle<i::String> key = factory->NewStringFromAsciiChecked("key"); |
| 659 key = factory->string_table()->LookupString(isolate, key); | 660 key = factory->string_table()->LookupString(isolate, key); |
| 660 | 661 |
| 661 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); | 662 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); |
| 662 builder.set_locals_count(1); | 663 builder.set_locals_count(1); |
| 663 builder.set_parameter_count(1); | 664 builder.set_parameter_count(1); |
| 664 builder.LoadLiteral(key) | 665 builder.LoadLiteral(key) |
| 665 .LoadKeyedProperty(builder.Parameter(0), vector->GetIndex(slot), | 666 .LoadKeyedProperty(builder.Parameter(0), vector->GetIndex(slot), |
| 666 i::SLOPPY) | 667 i::SLOPPY) |
| (...skipping 23 matching lines...) Expand all Loading... |
| 690 TEST(InterpreterStoreNamedProperty) { | 691 TEST(InterpreterStoreNamedProperty) { |
| 691 HandleAndZoneScope handles; | 692 HandleAndZoneScope handles; |
| 692 i::Isolate* isolate = handles.main_isolate(); | 693 i::Isolate* isolate = handles.main_isolate(); |
| 693 i::Factory* factory = isolate->factory(); | 694 i::Factory* factory = isolate->factory(); |
| 694 i::Zone zone; | 695 i::Zone zone; |
| 695 | 696 |
| 696 i::FeedbackVectorSpec feedback_spec(&zone); | 697 i::FeedbackVectorSpec feedback_spec(&zone); |
| 697 i::FeedbackVectorSlot slot = feedback_spec.AddStoreICSlot(); | 698 i::FeedbackVectorSlot slot = feedback_spec.AddStoreICSlot(); |
| 698 | 699 |
| 699 Handle<i::TypeFeedbackVector> vector = | 700 Handle<i::TypeFeedbackVector> vector = |
| 700 i::TypeFeedbackVector::New(isolate, &feedback_spec); | 701 i::NewTypeFeedbackVector(isolate, &feedback_spec); |
| 701 | 702 |
| 702 Handle<i::String> name = factory->NewStringFromAsciiChecked("val"); | 703 Handle<i::String> name = factory->NewStringFromAsciiChecked("val"); |
| 703 name = factory->string_table()->LookupString(isolate, name); | 704 name = factory->string_table()->LookupString(isolate, name); |
| 704 | 705 |
| 705 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); | 706 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); |
| 706 builder.set_locals_count(1); | 707 builder.set_locals_count(1); |
| 707 builder.set_parameter_count(1); | 708 builder.set_parameter_count(1); |
| 708 builder.LoadLiteral(name) | 709 builder.LoadLiteral(name) |
| 709 .StoreAccumulatorInRegister(Register(0)) | 710 .StoreAccumulatorInRegister(Register(0)) |
| 710 .LoadLiteral(Smi::FromInt(999)) | 711 .LoadLiteral(Smi::FromInt(999)) |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 752 TEST(InterpreterStoreKeyedProperty) { | 753 TEST(InterpreterStoreKeyedProperty) { |
| 753 HandleAndZoneScope handles; | 754 HandleAndZoneScope handles; |
| 754 i::Isolate* isolate = handles.main_isolate(); | 755 i::Isolate* isolate = handles.main_isolate(); |
| 755 i::Factory* factory = isolate->factory(); | 756 i::Factory* factory = isolate->factory(); |
| 756 i::Zone zone; | 757 i::Zone zone; |
| 757 | 758 |
| 758 i::FeedbackVectorSpec feedback_spec(&zone); | 759 i::FeedbackVectorSpec feedback_spec(&zone); |
| 759 i::FeedbackVectorSlot slot = feedback_spec.AddKeyedStoreICSlot(); | 760 i::FeedbackVectorSlot slot = feedback_spec.AddKeyedStoreICSlot(); |
| 760 | 761 |
| 761 Handle<i::TypeFeedbackVector> vector = | 762 Handle<i::TypeFeedbackVector> vector = |
| 762 i::TypeFeedbackVector::New(isolate, &feedback_spec); | 763 i::NewTypeFeedbackVector(isolate, &feedback_spec); |
| 763 | 764 |
| 764 Handle<i::String> name = factory->NewStringFromAsciiChecked("val"); | 765 Handle<i::String> name = factory->NewStringFromAsciiChecked("val"); |
| 765 name = factory->string_table()->LookupString(isolate, name); | 766 name = factory->string_table()->LookupString(isolate, name); |
| 766 | 767 |
| 767 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); | 768 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); |
| 768 builder.set_locals_count(1); | 769 builder.set_locals_count(1); |
| 769 builder.set_parameter_count(1); | 770 builder.set_parameter_count(1); |
| 770 builder.LoadLiteral(name) | 771 builder.LoadLiteral(name) |
| 771 .StoreAccumulatorInRegister(Register(0)) | 772 .StoreAccumulatorInRegister(Register(0)) |
| 772 .LoadLiteral(Smi::FromInt(999)) | 773 .LoadLiteral(Smi::FromInt(999)) |
| (...skipping 28 matching lines...) Expand all Loading... |
| 801 TEST(InterpreterCall) { | 802 TEST(InterpreterCall) { |
| 802 HandleAndZoneScope handles; | 803 HandleAndZoneScope handles; |
| 803 i::Isolate* isolate = handles.main_isolate(); | 804 i::Isolate* isolate = handles.main_isolate(); |
| 804 i::Factory* factory = isolate->factory(); | 805 i::Factory* factory = isolate->factory(); |
| 805 i::Zone zone; | 806 i::Zone zone; |
| 806 | 807 |
| 807 i::FeedbackVectorSpec feedback_spec(&zone); | 808 i::FeedbackVectorSpec feedback_spec(&zone); |
| 808 i::FeedbackVectorSlot slot = feedback_spec.AddLoadICSlot(); | 809 i::FeedbackVectorSlot slot = feedback_spec.AddLoadICSlot(); |
| 809 | 810 |
| 810 Handle<i::TypeFeedbackVector> vector = | 811 Handle<i::TypeFeedbackVector> vector = |
| 811 i::TypeFeedbackVector::New(isolate, &feedback_spec); | 812 i::NewTypeFeedbackVector(isolate, &feedback_spec); |
| 812 int slot_index = vector->GetIndex(slot); | 813 int slot_index = vector->GetIndex(slot); |
| 813 | 814 |
| 814 Handle<i::String> name = factory->NewStringFromAsciiChecked("func"); | 815 Handle<i::String> name = factory->NewStringFromAsciiChecked("func"); |
| 815 name = factory->string_table()->LookupString(isolate, name); | 816 name = factory->string_table()->LookupString(isolate, name); |
| 816 | 817 |
| 817 // Check with no args. | 818 // Check with no args. |
| 818 { | 819 { |
| 819 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); | 820 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); |
| 820 builder.set_locals_count(1); | 821 builder.set_locals_count(1); |
| 821 builder.set_parameter_count(1); | 822 builder.set_parameter_count(1); |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1304 .CallRuntime(Runtime::kAdd, Register(0), 2) | 1305 .CallRuntime(Runtime::kAdd, Register(0), 2) |
| 1305 .Return(); | 1306 .Return(); |
| 1306 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 1307 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| 1307 | 1308 |
| 1308 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 1309 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
| 1309 auto callable = tester.GetCallable<>(); | 1310 auto callable = tester.GetCallable<>(); |
| 1310 | 1311 |
| 1311 Handle<Object> return_val = callable().ToHandleChecked(); | 1312 Handle<Object> return_val = callable().ToHandleChecked(); |
| 1312 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(55)); | 1313 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(55)); |
| 1313 } | 1314 } |
| OLD | NEW |