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

Side by Side Diff: test/unittests/interpreter/constant-array-builder-unittest.cc

Issue 2242193002: [Interpreter] Avoid accessing Isolate from during bytecode generation. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@offheap_sourceposition
Patch Set: Rebase Created 4 years, 4 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 | « test/unittests/interpreter/bytecode-register-optimizer-unittest.cc ('k') | 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 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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/factory.h" 7 #include "src/factory.h"
8 #include "src/handles-inl.h" 8 #include "src/handles-inl.h"
9 #include "src/interpreter/constant-array-builder.h" 9 #include "src/interpreter/constant-array-builder.h"
10 #include "src/isolate.h" 10 #include "src/isolate.h"
(...skipping 12 matching lines...) Expand all
23 static const size_t k16BitCapacity = ConstantArrayBuilder::k16BitCapacity; 23 static const size_t k16BitCapacity = ConstantArrayBuilder::k16BitCapacity;
24 }; 24 };
25 25
26 STATIC_CONST_MEMBER_DEFINITION const size_t 26 STATIC_CONST_MEMBER_DEFINITION const size_t
27 ConstantArrayBuilderTest::k16BitCapacity; 27 ConstantArrayBuilderTest::k16BitCapacity;
28 STATIC_CONST_MEMBER_DEFINITION const size_t 28 STATIC_CONST_MEMBER_DEFINITION const size_t
29 ConstantArrayBuilderTest::k8BitCapacity; 29 ConstantArrayBuilderTest::k8BitCapacity;
30 30
31 TEST_F(ConstantArrayBuilderTest, AllocateAllEntries) { 31 TEST_F(ConstantArrayBuilderTest, AllocateAllEntries) {
32 CanonicalHandleScope canonical(isolate()); 32 CanonicalHandleScope canonical(isolate());
33 ConstantArrayBuilder builder(isolate(), zone()); 33 ConstantArrayBuilder builder(zone(), isolate()->factory()->the_hole_value());
34 for (size_t i = 0; i < k16BitCapacity; i++) { 34 for (size_t i = 0; i < k16BitCapacity; i++) {
35 builder.Insert(handle(Smi::FromInt(static_cast<int>(i)), isolate())); 35 builder.Insert(handle(Smi::FromInt(static_cast<int>(i)), isolate()));
36 } 36 }
37 CHECK_EQ(builder.size(), k16BitCapacity); 37 CHECK_EQ(builder.size(), k16BitCapacity);
38 for (size_t i = 0; i < k16BitCapacity; i++) { 38 for (size_t i = 0; i < k16BitCapacity; i++) {
39 CHECK_EQ(Handle<Smi>::cast(builder.At(i))->value(), i); 39 CHECK_EQ(Handle<Smi>::cast(builder.At(i))->value(), i);
40 } 40 }
41 } 41 }
42 42
43 TEST_F(ConstantArrayBuilderTest, ToFixedArray) { 43 TEST_F(ConstantArrayBuilderTest, ToFixedArray) {
44 CanonicalHandleScope canonical(isolate()); 44 CanonicalHandleScope canonical(isolate());
45 ConstantArrayBuilder builder(isolate(), zone()); 45 ConstantArrayBuilder builder(zone(), isolate()->factory()->the_hole_value());
46 static const size_t kNumberOfElements = 37; 46 static const size_t kNumberOfElements = 37;
47 for (size_t i = 0; i < kNumberOfElements; i++) { 47 for (size_t i = 0; i < kNumberOfElements; i++) {
48 Handle<Object> object = isolate()->factory()->NewNumberFromSize(i); 48 Handle<Object> object = isolate()->factory()->NewNumberFromSize(i);
49 builder.Insert(object); 49 builder.Insert(object);
50 CHECK(builder.At(i)->SameValue(*object)); 50 CHECK(builder.At(i)->SameValue(*object));
51 } 51 }
52 Handle<FixedArray> constant_array = builder.ToFixedArray(); 52 Handle<FixedArray> constant_array = builder.ToFixedArray(isolate());
53 CHECK_EQ(constant_array->length(), kNumberOfElements); 53 CHECK_EQ(constant_array->length(), kNumberOfElements);
54 for (size_t i = 0; i < kNumberOfElements; i++) { 54 for (size_t i = 0; i < kNumberOfElements; i++) {
55 CHECK(constant_array->get(static_cast<int>(i))->SameValue(*builder.At(i))); 55 CHECK(constant_array->get(static_cast<int>(i))->SameValue(*builder.At(i)));
56 } 56 }
57 } 57 }
58 58
59 TEST_F(ConstantArrayBuilderTest, ToLargeFixedArray) { 59 TEST_F(ConstantArrayBuilderTest, ToLargeFixedArray) {
60 CanonicalHandleScope canonical(isolate()); 60 CanonicalHandleScope canonical(isolate());
61 ConstantArrayBuilder builder(isolate(), zone()); 61 ConstantArrayBuilder builder(zone(), isolate()->factory()->the_hole_value());
62 static const size_t kNumberOfElements = 37373; 62 static const size_t kNumberOfElements = 37373;
63 for (size_t i = 0; i < kNumberOfElements; i++) { 63 for (size_t i = 0; i < kNumberOfElements; i++) {
64 Handle<Object> object = isolate()->factory()->NewNumberFromSize(i); 64 Handle<Object> object = isolate()->factory()->NewNumberFromSize(i);
65 builder.Insert(object); 65 builder.Insert(object);
66 CHECK(builder.At(i)->SameValue(*object)); 66 CHECK(builder.At(i)->SameValue(*object));
67 } 67 }
68 Handle<FixedArray> constant_array = builder.ToFixedArray(); 68 Handle<FixedArray> constant_array = builder.ToFixedArray(isolate());
69 CHECK_EQ(constant_array->length(), kNumberOfElements); 69 CHECK_EQ(constant_array->length(), kNumberOfElements);
70 for (size_t i = 0; i < kNumberOfElements; i++) { 70 for (size_t i = 0; i < kNumberOfElements; i++) {
71 CHECK(constant_array->get(static_cast<int>(i))->SameValue(*builder.At(i))); 71 CHECK(constant_array->get(static_cast<int>(i))->SameValue(*builder.At(i)));
72 } 72 }
73 } 73 }
74 74
75 TEST_F(ConstantArrayBuilderTest, ToLargeFixedArrayWithReservations) { 75 TEST_F(ConstantArrayBuilderTest, ToLargeFixedArrayWithReservations) {
76 CanonicalHandleScope canonical(isolate()); 76 CanonicalHandleScope canonical(isolate());
77 ConstantArrayBuilder builder(isolate(), zone()); 77 ConstantArrayBuilder builder(zone(), isolate()->factory()->the_hole_value());
78 static const size_t kNumberOfElements = 37373; 78 static const size_t kNumberOfElements = 37373;
79 for (size_t i = 0; i < kNumberOfElements; i++) { 79 for (size_t i = 0; i < kNumberOfElements; i++) {
80 builder.CommitReservedEntry(builder.CreateReservedEntry(), 80 builder.CommitReservedEntry(builder.CreateReservedEntry(),
81 Smi::FromInt(static_cast<int>(i))); 81 Smi::FromInt(static_cast<int>(i)));
82 } 82 }
83 Handle<FixedArray> constant_array = builder.ToFixedArray(); 83 Handle<FixedArray> constant_array = builder.ToFixedArray(isolate());
84 CHECK_EQ(constant_array->length(), kNumberOfElements); 84 CHECK_EQ(constant_array->length(), kNumberOfElements);
85 for (size_t i = 0; i < kNumberOfElements; i++) { 85 for (size_t i = 0; i < kNumberOfElements; i++) {
86 CHECK(constant_array->get(static_cast<int>(i))->SameValue(*builder.At(i))); 86 CHECK(constant_array->get(static_cast<int>(i))->SameValue(*builder.At(i)));
87 } 87 }
88 } 88 }
89 89
90 TEST_F(ConstantArrayBuilderTest, AllocateEntriesWithIdx8Reservations) { 90 TEST_F(ConstantArrayBuilderTest, AllocateEntriesWithIdx8Reservations) {
91 CanonicalHandleScope canonical(isolate()); 91 CanonicalHandleScope canonical(isolate());
92 for (size_t reserved = 1; reserved < k8BitCapacity; reserved *= 3) { 92 for (size_t reserved = 1; reserved < k8BitCapacity; reserved *= 3) {
93 ConstantArrayBuilder builder(isolate(), zone()); 93 ConstantArrayBuilder builder(zone(),
94 isolate()->factory()->the_hole_value());
94 for (size_t i = 0; i < reserved; i++) { 95 for (size_t i = 0; i < reserved; i++) {
95 OperandSize operand_size = builder.CreateReservedEntry(); 96 OperandSize operand_size = builder.CreateReservedEntry();
96 CHECK(operand_size == OperandSize::kByte); 97 CHECK(operand_size == OperandSize::kByte);
97 } 98 }
98 for (size_t i = 0; i < 2 * k8BitCapacity; i++) { 99 for (size_t i = 0; i < 2 * k8BitCapacity; i++) {
99 builder.CommitReservedEntry(builder.CreateReservedEntry(), 100 builder.CommitReservedEntry(builder.CreateReservedEntry(),
100 Smi::FromInt(static_cast<int>(i))); 101 Smi::FromInt(static_cast<int>(i)));
101 if (i + reserved < k8BitCapacity) { 102 if (i + reserved < k8BitCapacity) {
102 CHECK_LE(builder.size(), k8BitCapacity); 103 CHECK_LE(builder.size(), k8BitCapacity);
103 CHECK_EQ(builder.size(), i + 1); 104 CHECK_EQ(builder.size(), i + 1);
(...skipping 24 matching lines...) Expand all
128 for (size_t i = 0; i < duplicates_in_idx8_space; i++) { 129 for (size_t i = 0; i < duplicates_in_idx8_space; i++) {
129 OperandSize operand_size = builder.CreateReservedEntry(); 130 OperandSize operand_size = builder.CreateReservedEntry();
130 CHECK(operand_size == OperandSize::kByte); 131 CHECK(operand_size == OperandSize::kByte);
131 } 132 }
132 for (size_t i = 0; i < duplicates_in_idx8_space; i++) { 133 for (size_t i = 0; i < duplicates_in_idx8_space; i++) {
133 Smi* value = Smi::FromInt(static_cast<int>(2 * k8BitCapacity + i)); 134 Smi* value = Smi::FromInt(static_cast<int>(2 * k8BitCapacity + i));
134 size_t index = builder.CommitReservedEntry(OperandSize::kByte, value); 135 size_t index = builder.CommitReservedEntry(OperandSize::kByte, value);
135 CHECK_EQ(static_cast<int>(index), k8BitCapacity - reserved + i); 136 CHECK_EQ(static_cast<int>(index), k8BitCapacity - reserved + i);
136 } 137 }
137 138
138 Handle<FixedArray> constant_array = builder.ToFixedArray(); 139 Handle<FixedArray> constant_array = builder.ToFixedArray(isolate());
139 CHECK_EQ(constant_array->length(), 2 * k8BitCapacity + reserved); 140 CHECK_EQ(constant_array->length(), 2 * k8BitCapacity + reserved);
140 141
141 // Check all committed values match expected 142 // Check all committed values match expected
142 for (size_t i = 0; i < k8BitCapacity - reserved; i++) { 143 for (size_t i = 0; i < k8BitCapacity - reserved; i++) {
143 Object* value = constant_array->get(static_cast<int>(i)); 144 Object* value = constant_array->get(static_cast<int>(i));
144 Smi* smi = Smi::FromInt(static_cast<int>(i)); 145 Smi* smi = Smi::FromInt(static_cast<int>(i));
145 CHECK(value->SameValue(smi)); 146 CHECK(value->SameValue(smi));
146 } 147 }
147 for (size_t i = k8BitCapacity; i < 2 * k8BitCapacity + reserved; i++) { 148 for (size_t i = k8BitCapacity; i < 2 * k8BitCapacity + reserved; i++) {
148 Object* value = constant_array->get(static_cast<int>(i)); 149 Object* value = constant_array->get(static_cast<int>(i));
149 Smi* smi = Smi::FromInt(static_cast<int>(i - reserved)); 150 Smi* smi = Smi::FromInt(static_cast<int>(i - reserved));
150 CHECK(value->SameValue(smi)); 151 CHECK(value->SameValue(smi));
151 } 152 }
152 } 153 }
153 } 154 }
154 155
155 TEST_F(ConstantArrayBuilderTest, AllocateEntriesWithWideReservations) { 156 TEST_F(ConstantArrayBuilderTest, AllocateEntriesWithWideReservations) {
156 CanonicalHandleScope canonical(isolate()); 157 CanonicalHandleScope canonical(isolate());
157 for (size_t reserved = 1; reserved < k8BitCapacity; reserved *= 3) { 158 for (size_t reserved = 1; reserved < k8BitCapacity; reserved *= 3) {
158 ConstantArrayBuilder builder(isolate(), zone()); 159 ConstantArrayBuilder builder(zone(),
160 isolate()->factory()->the_hole_value());
159 for (size_t i = 0; i < k8BitCapacity; i++) { 161 for (size_t i = 0; i < k8BitCapacity; i++) {
160 builder.CommitReservedEntry(builder.CreateReservedEntry(), 162 builder.CommitReservedEntry(builder.CreateReservedEntry(),
161 Smi::FromInt(static_cast<int>(i))); 163 Smi::FromInt(static_cast<int>(i)));
162 CHECK_EQ(builder.size(), i + 1); 164 CHECK_EQ(builder.size(), i + 1);
163 } 165 }
164 for (size_t i = 0; i < reserved; i++) { 166 for (size_t i = 0; i < reserved; i++) {
165 OperandSize operand_size = builder.CreateReservedEntry(); 167 OperandSize operand_size = builder.CreateReservedEntry();
166 CHECK(operand_size == OperandSize::kShort); 168 CHECK(operand_size == OperandSize::kShort);
167 CHECK_EQ(builder.size(), k8BitCapacity); 169 CHECK_EQ(builder.size(), k8BitCapacity);
168 } 170 }
169 for (size_t i = 0; i < reserved; i++) { 171 for (size_t i = 0; i < reserved; i++) {
170 builder.DiscardReservedEntry(OperandSize::kShort); 172 builder.DiscardReservedEntry(OperandSize::kShort);
171 CHECK_EQ(builder.size(), k8BitCapacity); 173 CHECK_EQ(builder.size(), k8BitCapacity);
172 } 174 }
173 for (size_t i = 0; i < reserved; i++) { 175 for (size_t i = 0; i < reserved; i++) {
174 OperandSize operand_size = builder.CreateReservedEntry(); 176 OperandSize operand_size = builder.CreateReservedEntry();
175 CHECK(operand_size == OperandSize::kShort); 177 CHECK(operand_size == OperandSize::kShort);
176 builder.CommitReservedEntry(operand_size, 178 builder.CommitReservedEntry(operand_size,
177 Smi::FromInt(static_cast<int>(i))); 179 Smi::FromInt(static_cast<int>(i)));
178 CHECK_EQ(builder.size(), k8BitCapacity); 180 CHECK_EQ(builder.size(), k8BitCapacity);
179 } 181 }
180 for (size_t i = k8BitCapacity; i < k8BitCapacity + reserved; i++) { 182 for (size_t i = k8BitCapacity; i < k8BitCapacity + reserved; i++) {
181 OperandSize operand_size = builder.CreateReservedEntry(); 183 OperandSize operand_size = builder.CreateReservedEntry();
182 CHECK(operand_size == OperandSize::kShort); 184 CHECK(operand_size == OperandSize::kShort);
183 builder.CommitReservedEntry(operand_size, 185 builder.CommitReservedEntry(operand_size,
184 Smi::FromInt(static_cast<int>(i))); 186 Smi::FromInt(static_cast<int>(i)));
185 CHECK_EQ(builder.size(), i + 1); 187 CHECK_EQ(builder.size(), i + 1);
186 } 188 }
187 189
188 Handle<FixedArray> constant_array = builder.ToFixedArray(); 190 Handle<FixedArray> constant_array = builder.ToFixedArray(isolate());
189 CHECK_EQ(constant_array->length(), k8BitCapacity + reserved); 191 CHECK_EQ(constant_array->length(), k8BitCapacity + reserved);
190 for (size_t i = 0; i < k8BitCapacity + reserved; i++) { 192 for (size_t i = 0; i < k8BitCapacity + reserved; i++) {
191 Object* value = constant_array->get(static_cast<int>(i)); 193 Object* value = constant_array->get(static_cast<int>(i));
192 CHECK(value->SameValue(*isolate()->factory()->NewNumberFromSize(i))); 194 CHECK(value->SameValue(*isolate()->factory()->NewNumberFromSize(i)));
193 } 195 }
194 } 196 }
195 } 197 }
196 198
197 TEST_F(ConstantArrayBuilderTest, GapFilledWhenLowReservationCommitted) { 199 TEST_F(ConstantArrayBuilderTest, GapFilledWhenLowReservationCommitted) {
198 CanonicalHandleScope canonical(isolate()); 200 CanonicalHandleScope canonical(isolate());
199 ConstantArrayBuilder builder(isolate(), zone()); 201 ConstantArrayBuilder builder(zone(), isolate()->factory()->the_hole_value());
200 for (size_t i = 0; i < k8BitCapacity; i++) { 202 for (size_t i = 0; i < k8BitCapacity; i++) {
201 OperandSize operand_size = builder.CreateReservedEntry(); 203 OperandSize operand_size = builder.CreateReservedEntry();
202 CHECK(OperandSize::kByte == operand_size); 204 CHECK(OperandSize::kByte == operand_size);
203 CHECK_EQ(builder.size(), 0); 205 CHECK_EQ(builder.size(), 0);
204 } 206 }
205 for (size_t i = 0; i < k8BitCapacity; i++) { 207 for (size_t i = 0; i < k8BitCapacity; i++) {
206 builder.CommitReservedEntry(builder.CreateReservedEntry(), 208 builder.CommitReservedEntry(builder.CreateReservedEntry(),
207 Smi::FromInt(static_cast<int>(i))); 209 Smi::FromInt(static_cast<int>(i)));
208 CHECK_EQ(builder.size(), i + k8BitCapacity + 1); 210 CHECK_EQ(builder.size(), i + k8BitCapacity + 1);
209 } 211 }
210 for (size_t i = 0; i < k8BitCapacity; i++) { 212 for (size_t i = 0; i < k8BitCapacity; i++) {
211 builder.CommitReservedEntry(OperandSize::kByte, 213 builder.CommitReservedEntry(OperandSize::kByte,
212 Smi::FromInt(static_cast<int>(i))); 214 Smi::FromInt(static_cast<int>(i)));
213 CHECK_EQ(builder.size(), 2 * k8BitCapacity); 215 CHECK_EQ(builder.size(), 2 * k8BitCapacity);
214 } 216 }
215 Handle<FixedArray> constant_array = builder.ToFixedArray(); 217 Handle<FixedArray> constant_array = builder.ToFixedArray(isolate());
216 CHECK_EQ(constant_array->length(), 2 * k8BitCapacity); 218 CHECK_EQ(constant_array->length(), 2 * k8BitCapacity);
217 for (size_t i = 0; i < k8BitCapacity; i++) { 219 for (size_t i = 0; i < k8BitCapacity; i++) {
218 Object* original = constant_array->get(static_cast<int>(k8BitCapacity + i)); 220 Object* original = constant_array->get(static_cast<int>(k8BitCapacity + i));
219 Object* duplicate = constant_array->get(static_cast<int>(i)); 221 Object* duplicate = constant_array->get(static_cast<int>(i));
220 CHECK(original->SameValue(duplicate)); 222 CHECK(original->SameValue(duplicate));
221 Handle<Object> reference = isolate()->factory()->NewNumberFromSize(i); 223 Handle<Object> reference = isolate()->factory()->NewNumberFromSize(i);
222 CHECK(original->SameValue(*reference)); 224 CHECK(original->SameValue(*reference));
223 } 225 }
224 } 226 }
225 227
226 TEST_F(ConstantArrayBuilderTest, GapNotFilledWhenLowReservationDiscarded) { 228 TEST_F(ConstantArrayBuilderTest, GapNotFilledWhenLowReservationDiscarded) {
227 CanonicalHandleScope canonical(isolate()); 229 CanonicalHandleScope canonical(isolate());
228 ConstantArrayBuilder builder(isolate(), zone()); 230 ConstantArrayBuilder builder(zone(), isolate()->factory()->the_hole_value());
229 for (size_t i = 0; i < k8BitCapacity; i++) { 231 for (size_t i = 0; i < k8BitCapacity; i++) {
230 OperandSize operand_size = builder.CreateReservedEntry(); 232 OperandSize operand_size = builder.CreateReservedEntry();
231 CHECK(OperandSize::kByte == operand_size); 233 CHECK(OperandSize::kByte == operand_size);
232 CHECK_EQ(builder.size(), 0); 234 CHECK_EQ(builder.size(), 0);
233 } 235 }
234 for (size_t i = 0; i < k8BitCapacity; i++) { 236 for (size_t i = 0; i < k8BitCapacity; i++) {
235 Handle<Object> object = isolate()->factory()->NewNumberFromSize(i); 237 Handle<Object> object = isolate()->factory()->NewNumberFromSize(i);
236 builder.Insert(object); 238 builder.Insert(object);
237 CHECK_EQ(builder.size(), i + k8BitCapacity + 1); 239 CHECK_EQ(builder.size(), i + k8BitCapacity + 1);
238 } 240 }
239 for (size_t i = 0; i < k8BitCapacity; i++) { 241 for (size_t i = 0; i < k8BitCapacity; i++) {
240 builder.DiscardReservedEntry(OperandSize::kByte); 242 builder.DiscardReservedEntry(OperandSize::kByte);
241 builder.Insert(builder.At(i + k8BitCapacity)); 243 builder.Insert(builder.At(i + k8BitCapacity));
242 CHECK_EQ(builder.size(), 2 * k8BitCapacity); 244 CHECK_EQ(builder.size(), 2 * k8BitCapacity);
243 } 245 }
244 for (size_t i = 0; i < k8BitCapacity; i++) { 246 for (size_t i = 0; i < k8BitCapacity; i++) {
245 Handle<Object> reference = isolate()->factory()->NewNumberFromSize(i); 247 Handle<Object> reference = isolate()->factory()->NewNumberFromSize(i);
246 Handle<Object> original = builder.At(k8BitCapacity + i); 248 Handle<Object> original = builder.At(k8BitCapacity + i);
247 CHECK(original->SameValue(*reference)); 249 CHECK(original->SameValue(*reference));
248 Handle<Object> duplicate = builder.At(i); 250 Handle<Object> duplicate = builder.At(i);
249 CHECK(duplicate->SameValue(*isolate()->factory()->the_hole_value())); 251 CHECK(duplicate->SameValue(*isolate()->factory()->the_hole_value()));
250 } 252 }
251 } 253 }
252 254
253 TEST_F(ConstantArrayBuilderTest, HolesWithUnusedReservations) { 255 TEST_F(ConstantArrayBuilderTest, HolesWithUnusedReservations) {
254 CanonicalHandleScope canonical(isolate()); 256 CanonicalHandleScope canonical(isolate());
255 static int kNumberOfHoles = 128; 257 static int kNumberOfHoles = 128;
256 ConstantArrayBuilder builder(isolate(), zone()); 258 ConstantArrayBuilder builder(zone(), isolate()->factory()->the_hole_value());
257 for (int i = 0; i < kNumberOfHoles; ++i) { 259 for (int i = 0; i < kNumberOfHoles; ++i) {
258 CHECK_EQ(builder.CreateReservedEntry(), OperandSize::kByte); 260 CHECK_EQ(builder.CreateReservedEntry(), OperandSize::kByte);
259 } 261 }
260 for (int i = 0; i < 128; ++i) { 262 for (int i = 0; i < 128; ++i) {
261 CHECK_EQ(builder.Insert(isolate()->factory()->NewNumber(i)), i); 263 CHECK_EQ(builder.Insert(isolate()->factory()->NewNumber(i)), i);
262 } 264 }
263 CHECK_EQ(builder.Insert(isolate()->factory()->NewNumber(256)), 256); 265 CHECK_EQ(builder.Insert(isolate()->factory()->NewNumber(256)), 256);
264 266
265 Handle<FixedArray> constant_array = builder.ToFixedArray(); 267 Handle<FixedArray> constant_array = builder.ToFixedArray(isolate());
266 CHECK_EQ(constant_array->length(), 257); 268 CHECK_EQ(constant_array->length(), 257);
267 for (int i = 128; i < 256; i++) { 269 for (int i = 128; i < 256; i++) {
268 CHECK(constant_array->get(i)->SameValue( 270 CHECK(constant_array->get(i)->SameValue(
269 *isolate()->factory()->the_hole_value())); 271 *isolate()->factory()->the_hole_value()));
270 } 272 }
271 CHECK(!constant_array->get(127)->SameValue( 273 CHECK(!constant_array->get(127)->SameValue(
272 *isolate()->factory()->the_hole_value())); 274 *isolate()->factory()->the_hole_value()));
273 CHECK(!constant_array->get(256)->SameValue( 275 CHECK(!constant_array->get(256)->SameValue(
274 *isolate()->factory()->the_hole_value())); 276 *isolate()->factory()->the_hole_value()));
275 } 277 }
276 278
277 TEST_F(ConstantArrayBuilderTest, ReservationsAtAllScales) { 279 TEST_F(ConstantArrayBuilderTest, ReservationsAtAllScales) {
278 CanonicalHandleScope canonical(isolate()); 280 CanonicalHandleScope canonical(isolate());
279 ConstantArrayBuilder builder(isolate(), zone()); 281 ConstantArrayBuilder builder(zone(), isolate()->factory()->the_hole_value());
280 for (int i = 0; i < 256; i++) { 282 for (int i = 0; i < 256; i++) {
281 CHECK_EQ(builder.CreateReservedEntry(), OperandSize::kByte); 283 CHECK_EQ(builder.CreateReservedEntry(), OperandSize::kByte);
282 } 284 }
283 for (int i = 256; i < 65536; ++i) { 285 for (int i = 256; i < 65536; ++i) {
284 CHECK_EQ(builder.CreateReservedEntry(), OperandSize::kShort); 286 CHECK_EQ(builder.CreateReservedEntry(), OperandSize::kShort);
285 } 287 }
286 for (int i = 65536; i < 131072; ++i) { 288 for (int i = 65536; i < 131072; ++i) {
287 CHECK_EQ(builder.CreateReservedEntry(), OperandSize::kQuad); 289 CHECK_EQ(builder.CreateReservedEntry(), OperandSize::kQuad);
288 } 290 }
289 CHECK_EQ(builder.CommitReservedEntry(OperandSize::kByte, Smi::FromInt(1)), 0); 291 CHECK_EQ(builder.CommitReservedEntry(OperandSize::kByte, Smi::FromInt(1)), 0);
290 CHECK_EQ(builder.CommitReservedEntry(OperandSize::kShort, Smi::FromInt(2)), 292 CHECK_EQ(builder.CommitReservedEntry(OperandSize::kShort, Smi::FromInt(2)),
291 256); 293 256);
292 CHECK_EQ(builder.CommitReservedEntry(OperandSize::kQuad, Smi::FromInt(3)), 294 CHECK_EQ(builder.CommitReservedEntry(OperandSize::kQuad, Smi::FromInt(3)),
293 65536); 295 65536);
294 Handle<FixedArray> constant_array = builder.ToFixedArray(); 296 Handle<FixedArray> constant_array = builder.ToFixedArray(isolate());
295 CHECK_EQ(constant_array->length(), 65537); 297 CHECK_EQ(constant_array->length(), 65537);
296 int count = 1; 298 int count = 1;
297 for (int i = 0; i < constant_array->length(); ++i) { 299 for (int i = 0; i < constant_array->length(); ++i) {
298 Handle<Object> expected; 300 Handle<Object> expected;
299 if (i == 0 || i == 256 || i == 65536) { 301 if (i == 0 || i == 256 || i == 65536) {
300 expected = isolate()->factory()->NewNumber(count++); 302 expected = isolate()->factory()->NewNumber(count++);
301 } else { 303 } else {
302 expected = isolate()->factory()->the_hole_value(); 304 expected = isolate()->factory()->the_hole_value();
303 } 305 }
304 CHECK(constant_array->get(i)->SameValue(*expected)); 306 CHECK(constant_array->get(i)->SameValue(*expected));
305 } 307 }
306 } 308 }
307 309
308 TEST_F(ConstantArrayBuilderTest, AllocateEntriesWithFixedReservations) { 310 TEST_F(ConstantArrayBuilderTest, AllocateEntriesWithFixedReservations) {
309 CanonicalHandleScope canonical(isolate()); 311 CanonicalHandleScope canonical(isolate());
310 ConstantArrayBuilder builder(isolate(), zone()); 312 ConstantArrayBuilder builder(zone(), isolate()->factory()->the_hole_value());
311 for (size_t i = 0; i < k16BitCapacity; i++) { 313 for (size_t i = 0; i < k16BitCapacity; i++) {
312 if ((i % 2) == 0) { 314 if ((i % 2) == 0) {
313 CHECK_EQ(i, builder.AllocateEntry()); 315 CHECK_EQ(i, builder.AllocateEntry());
314 } else { 316 } else {
315 builder.Insert(handle(Smi::FromInt(static_cast<int>(i)), isolate())); 317 builder.Insert(handle(Smi::FromInt(static_cast<int>(i)), isolate()));
316 } 318 }
317 } 319 }
318 CHECK_EQ(builder.size(), k16BitCapacity); 320 CHECK_EQ(builder.size(), k16BitCapacity);
319 321
320 // Check values before reserved entries are inserted. 322 // Check values before reserved entries are inserted.
(...skipping 15 matching lines...) Expand all
336 338
337 // Check values after reserved entries are inserted. 339 // Check values after reserved entries are inserted.
338 for (size_t i = 0; i < k16BitCapacity; i++) { 340 for (size_t i = 0; i < k16BitCapacity; i++) {
339 CHECK_EQ(Handle<Smi>::cast(builder.At(i))->value(), i); 341 CHECK_EQ(Handle<Smi>::cast(builder.At(i))->value(), i);
340 } 342 }
341 } 343 }
342 344
343 } // namespace interpreter 345 } // namespace interpreter
344 } // namespace internal 346 } // namespace internal
345 } // namespace v8 347 } // namespace v8
OLDNEW
« no previous file with comments | « test/unittests/interpreter/bytecode-register-optimizer-unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698