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

Side by Side Diff: test/cctest/interpreter/test-interpreter.cc

Issue 1319833004: [Interpreter] Add support for property store operations. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@int_implicit_ret
Patch Set: Add DCHECK Created 5 years, 3 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
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 "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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 52
53 53
54 class InterpreterTester { 54 class InterpreterTester {
55 public: 55 public:
56 InterpreterTester(Isolate* isolate, Handle<BytecodeArray> bytecode, 56 InterpreterTester(Isolate* isolate, Handle<BytecodeArray> bytecode,
57 MaybeHandle<TypeFeedbackVector> feedback_vector = 57 MaybeHandle<TypeFeedbackVector> feedback_vector =
58 MaybeHandle<TypeFeedbackVector>()) 58 MaybeHandle<TypeFeedbackVector>())
59 : isolate_(isolate), 59 : isolate_(isolate),
60 bytecode_(bytecode), 60 bytecode_(bytecode),
61 feedback_vector_(feedback_vector) { 61 feedback_vector_(feedback_vector) {
62 i::FLAG_vector_stores = true;
62 i::FLAG_ignition = true; 63 i::FLAG_ignition = true;
63 // Ensure handler table is generated. 64 // Ensure handler table is generated.
64 isolate->interpreter()->Initialize(); 65 isolate->interpreter()->Initialize();
65 } 66 }
66 virtual ~InterpreterTester() {} 67 virtual ~InterpreterTester() {}
67 68
68 template <class... A> 69 template <class... A>
69 InterpreterCallable<A...> GetCallable() { 70 InterpreterCallable<A...> GetCallable() {
70 return InterpreterCallable<A...>(isolate_, GetBytecodeFunction<A...>()); 71 return InterpreterCallable<A...>(isolate_, GetBytecodeFunction<A...>());
71 } 72 }
(...skipping 30 matching lines...) Expand all
102 DISALLOW_COPY_AND_ASSIGN(InterpreterTester); 103 DISALLOW_COPY_AND_ASSIGN(InterpreterTester);
103 }; 104 };
104 105
105 } // namespace interpreter 106 } // namespace interpreter
106 } // namespace internal 107 } // namespace internal
107 } // namespace v8 108 } // namespace v8
108 109
109 using v8::internal::BytecodeArray; 110 using v8::internal::BytecodeArray;
110 using v8::internal::Handle; 111 using v8::internal::Handle;
111 using v8::internal::Object; 112 using v8::internal::Object;
113 using v8::internal::Runtime;
112 using v8::internal::Smi; 114 using v8::internal::Smi;
113 using v8::internal::Token; 115 using v8::internal::Token;
114 using namespace v8::internal::interpreter; 116 using namespace v8::internal::interpreter;
115 117
116 TEST(InterpreterReturn) { 118 TEST(InterpreterReturn) {
117 HandleAndZoneScope handles; 119 HandleAndZoneScope handles;
118 Handle<Object> undefined_value = 120 Handle<Object> undefined_value =
119 handles.main_isolate()->factory()->undefined_value(); 121 handles.main_isolate()->factory()->undefined_value();
120 122
121 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); 123 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone());
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 553
552 // Test transition to monomorphic IC. 554 // Test transition to monomorphic IC.
553 return_val = callable(object).ToHandleChecked(); 555 return_val = callable(object).ToHandleChecked();
554 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(123)); 556 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(123));
555 557
556 // Test transition to megamorphic IC. 558 // Test transition to megamorphic IC.
557 Handle<Object> object3 = tester.NewObject("({ key : 789, val2 : 123 })"); 559 Handle<Object> object3 = tester.NewObject("({ key : 789, val2 : 123 })");
558 return_val = callable(object3).ToHandleChecked(); 560 return_val = callable(object3).ToHandleChecked();
559 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(789)); 561 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(789));
560 } 562 }
563
564
565 TEST(InterpreterStoreNamedProperty) {
566 HandleAndZoneScope handles;
567 i::Isolate* isolate = handles.main_isolate();
568 i::Factory* factory = isolate->factory();
569
570 i::Code::Kind ic_kinds[] = {i::Code::STORE_IC};
571 i::FeedbackVectorSpec feedback_spec(0, 1, ic_kinds);
572 Handle<i::TypeFeedbackVector> vector =
573 factory->NewTypeFeedbackVector(&feedback_spec);
574
575 Handle<i::String> name = factory->NewStringFromAsciiChecked("val");
576 name = factory->string_table()->LookupString(isolate, name);
577
578 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone());
579 builder.set_locals_count(1);
580 builder.set_parameter_count(1);
581 builder.LoadLiteral(name)
582 .StoreAccumulatorInRegister(Register(0))
583 .LoadLiteral(Smi::FromInt(999))
584 .StoreNamedProperty(builder.Parameter(0), Register(0),
585 vector->first_ic_slot_index(), i::SLOPPY)
586 .Return();
587 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
588
589 InterpreterTester tester(isolate, bytecode_array, vector);
590 auto callable = tester.GetCallable<Handle<Object>>();
591 Handle<Object> object = tester.NewObject("({ val : 123 })");
592 // Test IC miss.
593 Handle<Object> result;
594 callable(object).ToHandleChecked();
595 CHECK(Runtime::GetObjectProperty(isolate, object, name).ToHandle(&result));
596 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999));
597
598 // Test transition to monomorphic IC.
599 callable(object).ToHandleChecked();
600 CHECK(Runtime::GetObjectProperty(isolate, object, name).ToHandle(&result));
601 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999));
602
603 // Test transition to polymorphic IC.
604 Handle<Object> object2 = tester.NewObject("({ val : 456, other : 123 })");
605 callable(object2).ToHandleChecked();
606 CHECK(Runtime::GetObjectProperty(isolate, object2, name).ToHandle(&result));
607 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999));
608
609 // Test transition to megamorphic IC.
610 Handle<Object> object3 = tester.NewObject("({ val : 789, val2 : 123 })");
611 callable(object3).ToHandleChecked();
612 Handle<Object> object4 = tester.NewObject("({ val : 789, val3 : 123 })");
613 callable(object4).ToHandleChecked();
614 Handle<Object> object5 = tester.NewObject("({ val : 789, val4 : 123 })");
615 callable(object5).ToHandleChecked();
616 CHECK(Runtime::GetObjectProperty(isolate, object5, name).ToHandle(&result));
617 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999));
618 }
619
620
621 TEST(InterpreterStoreKeyedProperty) {
622 HandleAndZoneScope handles;
623 i::Isolate* isolate = handles.main_isolate();
624 i::Factory* factory = isolate->factory();
625
626 i::Code::Kind ic_kinds[] = {i::Code::KEYED_STORE_IC};
627 i::FeedbackVectorSpec feedback_spec(0, 1, ic_kinds);
628 Handle<i::TypeFeedbackVector> vector =
629 factory->NewTypeFeedbackVector(&feedback_spec);
630
631 Handle<i::String> name = factory->NewStringFromAsciiChecked("val");
632 name = factory->string_table()->LookupString(isolate, name);
633
634 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone());
635 builder.set_locals_count(1);
636 builder.set_parameter_count(1);
637 builder.LoadLiteral(name)
638 .StoreAccumulatorInRegister(Register(0))
639 .LoadLiteral(Smi::FromInt(999))
640 .StoreKeyedProperty(builder.Parameter(0), Register(0),
641 vector->first_ic_slot_index(), i::SLOPPY)
642 .Return();
643 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
644
645 InterpreterTester tester(isolate, bytecode_array, vector);
646 auto callable = tester.GetCallable<Handle<Object>>();
647 Handle<Object> object = tester.NewObject("({ val : 123 })");
648 // Test IC miss.
649 Handle<Object> result;
650 callable(object).ToHandleChecked();
651 CHECK(Runtime::GetObjectProperty(isolate, object, name).ToHandle(&result));
652 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999));
653
654 // Test transition to monomorphic IC.
655 callable(object).ToHandleChecked();
656 CHECK(Runtime::GetObjectProperty(isolate, object, name).ToHandle(&result));
657 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999));
658
659 // Test transition to megamorphic IC.
660 Handle<Object> object2 = tester.NewObject("({ val : 456, other : 123 })");
661 callable(object2).ToHandleChecked();
662 CHECK(Runtime::GetObjectProperty(isolate, object2, name).ToHandle(&result));
663 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999));
664 }
OLDNEW
« no previous file with comments | « test/cctest/interpreter/test-bytecode-generator.cc ('k') | test/unittests/interpreter/bytecode-array-builder-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698