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

Side by Side Diff: test/unittests/interpreter/bytecode-array-iterator-unittest.cc

Issue 1845313002: [interpreter] A few code coverage improvements. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 8 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/interpreter/bytecode-array-builder.h" 7 #include "src/interpreter/bytecode-array-builder.h"
8 #include "src/interpreter/bytecode-array-iterator.h" 8 #include "src/interpreter/bytecode-array-iterator.h"
9 #include "test/unittests/test-utils.h" 9 #include "test/unittests/test-utils.h"
10 10
11 namespace v8 { 11 namespace v8 {
12 namespace internal { 12 namespace internal {
13 namespace interpreter { 13 namespace interpreter {
14 14
15 class BytecodeArrayIteratorTest : public TestWithIsolateAndZone { 15 class BytecodeArrayIteratorTest : public TestWithIsolateAndZone {
16 public: 16 public:
17 BytecodeArrayIteratorTest() {} 17 BytecodeArrayIteratorTest() {}
18 ~BytecodeArrayIteratorTest() override {} 18 ~BytecodeArrayIteratorTest() override {}
19 }; 19 };
20 20
21 21
22 TEST_F(BytecodeArrayIteratorTest, IteratesBytecodeArray) { 22 TEST_F(BytecodeArrayIteratorTest, IteratesBytecodeArray) {
23 // Use a builder to create an array with containing multiple bytecodes 23 // Use a builder to create an array with containing multiple bytecodes
24 // with 0, 1 and 2 operands. 24 // with 0, 1 and 2 operands.
25 BytecodeArrayBuilder builder(isolate(), zone(), 3, 2, 0); 25 BytecodeArrayBuilder builder(isolate(), zone(), 3, 3, 0);
26 Factory* factory = isolate()->factory(); 26 Factory* factory = isolate()->factory();
27 Handle<HeapObject> heap_num_0 = factory->NewHeapNumber(2.718); 27 Handle<HeapObject> heap_num_0 = factory->NewHeapNumber(2.718);
28 Handle<HeapObject> heap_num_1 = factory->NewHeapNumber(2147483647); 28 Handle<HeapObject> heap_num_1 = factory->NewHeapNumber(2147483647);
29 Smi* zero = Smi::FromInt(0); 29 Smi* zero = Smi::FromInt(0);
30 Smi* smi_0 = Smi::FromInt(64); 30 Smi* smi_0 = Smi::FromInt(64);
31 Smi* smi_1 = Smi::FromInt(-65536); 31 Smi* smi_1 = Smi::FromInt(-65536);
32 Register reg_0(0); 32 Register reg_0(0);
33 Register reg_1(1); 33 Register reg_1(1);
34 Register reg_2 = Register::FromParameterIndex(2, builder.parameter_count()); 34 Register param = Register::FromParameterIndex(2, builder.parameter_count());
35 Handle<String> name = factory->NewStringFromStaticChars("abc"); 35 Handle<String> name = factory->NewStringFromStaticChars("abc");
36 int name_index = 2; 36 int name_index = 2;
37 int feedback_slot = 97; 37 int feedback_slot = 97;
38 38
39 builder.LoadLiteral(heap_num_0) 39 builder.LoadLiteral(heap_num_0)
40 .LoadLiteral(heap_num_1) 40 .LoadLiteral(heap_num_1)
41 .LoadLiteral(zero) 41 .LoadLiteral(zero)
42 .LoadLiteral(smi_0) 42 .LoadLiteral(smi_0)
43 .LoadLiteral(smi_1) 43 .LoadLiteral(smi_1)
44 .LoadAccumulatorWithRegister(reg_0) 44 .LoadAccumulatorWithRegister(reg_0)
45 .LoadNamedProperty(reg_1, name, feedback_slot) 45 .LoadNamedProperty(reg_1, name, feedback_slot)
46 .StoreAccumulatorInRegister(reg_2) 46 .StoreAccumulatorInRegister(param)
47 .CallRuntimeForPair(Runtime::kLoadLookupSlotForCall, param, 1, reg_0)
48 .ForInPrepare(reg_0)
47 .CallRuntime(Runtime::kLoadIC_Miss, reg_0, 1) 49 .CallRuntime(Runtime::kLoadIC_Miss, reg_0, 1)
48 .Debugger() 50 .Debugger()
49 .LoadGlobal(name, 0x10000000, TypeofMode::NOT_INSIDE_TYPEOF) 51 .LoadGlobal(name, 0x10000000, TypeofMode::NOT_INSIDE_TYPEOF)
50 .Return(); 52 .Return();
51 53
52 // Test iterator sees the expected output from the builder. 54 // Test iterator sees the expected output from the builder.
53 BytecodeArrayIterator iterator(builder.ToBytecodeArray()); 55 BytecodeArrayIterator iterator(builder.ToBytecodeArray());
56 const int kPrefixByteSize = 1;
57 int offset = 0;
58
54 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaConstant); 59 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaConstant);
60 CHECK_EQ(iterator.current_offset(), offset);
55 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); 61 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
56 CHECK(iterator.GetConstantForIndexOperand(0).is_identical_to(heap_num_0)); 62 CHECK(iterator.GetConstantForIndexOperand(0).is_identical_to(heap_num_0));
57 CHECK(!iterator.done()); 63 CHECK(!iterator.done());
64 offset += Bytecodes::Size(Bytecode::kLdaConstant, OperandScale::kSingle);
58 iterator.Advance(); 65 iterator.Advance();
59 66
60 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaConstant); 67 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaConstant);
68 CHECK_EQ(iterator.current_offset(), offset);
61 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); 69 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
62 CHECK(iterator.GetConstantForIndexOperand(0).is_identical_to(heap_num_1)); 70 CHECK(iterator.GetConstantForIndexOperand(0).is_identical_to(heap_num_1));
63 CHECK(!iterator.done()); 71 CHECK(!iterator.done());
72 offset += Bytecodes::Size(Bytecode::kLdaConstant, OperandScale::kSingle);
64 iterator.Advance(); 73 iterator.Advance();
65 74
66 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaZero); 75 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaZero);
76 CHECK_EQ(iterator.current_offset(), offset);
67 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); 77 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
68 CHECK(!iterator.done()); 78 CHECK(!iterator.done());
79 offset += Bytecodes::Size(Bytecode::kLdaZero, OperandScale::kSingle);
69 iterator.Advance(); 80 iterator.Advance();
70 81
71 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaSmi); 82 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaSmi);
83 CHECK_EQ(iterator.current_offset(), offset);
72 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); 84 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
73 CHECK_EQ(Smi::FromInt(iterator.GetImmediateOperand(0)), smi_0); 85 CHECK_EQ(Smi::FromInt(iterator.GetImmediateOperand(0)), smi_0);
74 CHECK(!iterator.done()); 86 CHECK(!iterator.done());
87 offset += Bytecodes::Size(Bytecode::kLdaSmi, OperandScale::kSingle);
75 iterator.Advance(); 88 iterator.Advance();
76 89
77 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaSmi); 90 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaSmi);
91 CHECK_EQ(iterator.current_offset(), offset);
78 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kQuadruple); 92 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kQuadruple);
79 CHECK_EQ(Smi::FromInt(iterator.GetImmediateOperand(0)), smi_1); 93 CHECK_EQ(Smi::FromInt(iterator.GetImmediateOperand(0)), smi_1);
80 CHECK(!iterator.done()); 94 CHECK(!iterator.done());
95 offset += Bytecodes::Size(Bytecode::kLdaSmi, OperandScale::kQuadruple) +
96 kPrefixByteSize;
81 iterator.Advance(); 97 iterator.Advance();
82 98
83 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdar); 99 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdar);
100 CHECK_EQ(iterator.current_offset(), offset);
84 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); 101 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
85 CHECK_EQ(iterator.GetRegisterOperand(0).index(), reg_0.index()); 102 CHECK_EQ(iterator.GetRegisterOperand(0).index(), reg_0.index());
86 CHECK(!iterator.done()); 103 CHECK(!iterator.done());
104 offset += Bytecodes::Size(Bytecode::kLdar, OperandScale::kSingle);
87 iterator.Advance(); 105 iterator.Advance();
88 106
89 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLoadIC); 107 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLoadIC);
108 CHECK_EQ(iterator.current_offset(), offset);
90 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); 109 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
91 CHECK_EQ(iterator.GetRegisterOperand(0).index(), reg_1.index()); 110 CHECK_EQ(iterator.GetRegisterOperand(0).index(), reg_1.index());
92 CHECK_EQ(iterator.GetIndexOperand(1), name_index); 111 CHECK_EQ(iterator.GetIndexOperand(1), name_index);
93 CHECK_EQ(iterator.GetIndexOperand(2), feedback_slot); 112 CHECK_EQ(iterator.GetIndexOperand(2), feedback_slot);
94 CHECK(!iterator.done()); 113 CHECK(!iterator.done());
114 offset += Bytecodes::Size(Bytecode::kLoadIC, OperandScale::kSingle);
95 iterator.Advance(); 115 iterator.Advance();
96 116
97 CHECK_EQ(iterator.current_bytecode(), Bytecode::kStar); 117 CHECK_EQ(iterator.current_bytecode(), Bytecode::kStar);
118 CHECK_EQ(iterator.current_offset(), offset);
98 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); 119 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
99 CHECK_EQ(iterator.GetRegisterOperand(0).index(), reg_2.index()); 120 CHECK_EQ(iterator.GetRegisterOperand(0).index(), param.index());
121 CHECK_EQ(iterator.GetRegisterOperandRange(0), 1);
100 CHECK(!iterator.done()); 122 CHECK(!iterator.done());
123 offset += Bytecodes::Size(Bytecode::kStar, OperandScale::kSingle);
124 iterator.Advance();
125
126 CHECK_EQ(iterator.current_bytecode(), Bytecode::kCallRuntimeForPair);
127 CHECK_EQ(iterator.current_offset(), offset);
128 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
129 CHECK_EQ(iterator.GetRuntimeIdOperand(0), Runtime::kLoadLookupSlotForCall);
130 CHECK_EQ(iterator.GetRegisterOperand(1).index(), param.index());
131 CHECK_EQ(iterator.GetRegisterOperandRange(1), 1);
132 CHECK_EQ(iterator.GetRegisterCountOperand(2), 1);
133 CHECK_EQ(iterator.GetRegisterOperand(3).index(), reg_0.index());
134 CHECK_EQ(iterator.GetRegisterOperandRange(3), 2);
135 CHECK(!iterator.done());
136 offset +=
137 Bytecodes::Size(Bytecode::kCallRuntimeForPair, OperandScale::kSingle);
138 iterator.Advance();
139
140 CHECK_EQ(iterator.current_bytecode(), Bytecode::kForInPrepare);
141 CHECK_EQ(iterator.current_offset(), offset);
142 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
143 CHECK_EQ(iterator.GetRegisterOperand(0).index(), reg_0.index());
144 CHECK_EQ(iterator.GetRegisterOperandRange(0), 3);
145 CHECK(!iterator.done());
146 offset += Bytecodes::Size(Bytecode::kForInPrepare, OperandScale::kSingle);
101 iterator.Advance(); 147 iterator.Advance();
102 148
103 CHECK_EQ(iterator.current_bytecode(), Bytecode::kCallRuntime); 149 CHECK_EQ(iterator.current_bytecode(), Bytecode::kCallRuntime);
150 CHECK_EQ(iterator.current_offset(), offset);
104 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); 151 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
105 CHECK_EQ(static_cast<Runtime::FunctionId>(iterator.GetRuntimeIdOperand(0)), 152 CHECK_EQ(static_cast<Runtime::FunctionId>(iterator.GetRuntimeIdOperand(0)),
106 Runtime::kLoadIC_Miss); 153 Runtime::kLoadIC_Miss);
107 CHECK_EQ(iterator.GetRegisterOperand(1).index(), reg_0.index()); 154 CHECK_EQ(iterator.GetRegisterOperand(1).index(), reg_0.index());
108 CHECK_EQ(iterator.GetRegisterCountOperand(2), 1); 155 CHECK_EQ(iterator.GetRegisterCountOperand(2), 1);
109 CHECK(!iterator.done()); 156 CHECK(!iterator.done());
157 offset += Bytecodes::Size(Bytecode::kCallRuntime, OperandScale::kSingle);
110 iterator.Advance(); 158 iterator.Advance();
111 159
112 CHECK_EQ(iterator.current_bytecode(), Bytecode::kDebugger); 160 CHECK_EQ(iterator.current_bytecode(), Bytecode::kDebugger);
161 CHECK_EQ(iterator.current_offset(), offset);
162 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
163 CHECK(!iterator.done());
164 offset += Bytecodes::Size(Bytecode::kDebugger, OperandScale::kSingle);
165 iterator.Advance();
166
167 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaGlobal);
168 CHECK_EQ(iterator.current_offset(), offset);
169 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kQuadruple);
170 CHECK_EQ(iterator.current_bytecode_size(), 10);
171 CHECK_EQ(iterator.GetIndexOperand(1), 0x10000000);
172 offset += Bytecodes::Size(Bytecode::kLdaGlobal, OperandScale::kQuadruple) +
173 kPrefixByteSize;
174 iterator.Advance();
175
176 CHECK_EQ(iterator.current_bytecode(), Bytecode::kReturn);
177 CHECK_EQ(iterator.current_offset(), offset);
113 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); 178 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
114 CHECK(!iterator.done()); 179 CHECK(!iterator.done());
115 iterator.Advance(); 180 iterator.Advance();
116
117 CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaGlobal);
118 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kQuadruple);
119 CHECK_EQ(iterator.current_bytecode_size(), 10);
120 CHECK_EQ(iterator.GetIndexOperand(1), 0x10000000);
121 iterator.Advance();
122
123 CHECK_EQ(iterator.current_bytecode(), Bytecode::kReturn);
124 CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
125 CHECK(!iterator.done());
126 iterator.Advance();
127 CHECK(iterator.done()); 181 CHECK(iterator.done());
128 } 182 }
129 183
130 } // namespace interpreter 184 } // namespace interpreter
131 } // namespace internal 185 } // namespace internal
132 } // namespace v8 186 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698