OLD | NEW |
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 18 matching lines...) Expand all Loading... |
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(zone(), isolate()->factory()->the_hole_value()); | 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(), static_cast<int>(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(zone(), isolate()->factory()->the_hole_value()); | 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); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 } | 126 } |
127 | 127 |
128 // Now make reservations, and commit them with unique entries. | 128 // Now make reservations, and commit them with unique entries. |
129 for (size_t i = 0; i < duplicates_in_idx8_space; i++) { | 129 for (size_t i = 0; i < duplicates_in_idx8_space; i++) { |
130 OperandSize operand_size = builder.CreateReservedEntry(); | 130 OperandSize operand_size = builder.CreateReservedEntry(); |
131 CHECK(operand_size == OperandSize::kByte); | 131 CHECK(operand_size == OperandSize::kByte); |
132 } | 132 } |
133 for (size_t i = 0; i < duplicates_in_idx8_space; i++) { | 133 for (size_t i = 0; i < duplicates_in_idx8_space; i++) { |
134 Smi* value = Smi::FromInt(static_cast<int>(2 * k8BitCapacity + i)); | 134 Smi* value = Smi::FromInt(static_cast<int>(2 * k8BitCapacity + i)); |
135 size_t index = builder.CommitReservedEntry(OperandSize::kByte, value); | 135 size_t index = builder.CommitReservedEntry(OperandSize::kByte, value); |
136 CHECK_EQ(static_cast<int>(index), k8BitCapacity - reserved + i); | 136 CHECK_EQ(index, k8BitCapacity - reserved + i); |
137 } | 137 } |
138 | 138 |
139 Handle<FixedArray> constant_array = builder.ToFixedArray(isolate()); | 139 Handle<FixedArray> constant_array = builder.ToFixedArray(isolate()); |
140 CHECK_EQ(constant_array->length(), 2 * k8BitCapacity + reserved); | 140 CHECK_EQ(constant_array->length(), |
| 141 static_cast<int>(2 * k8BitCapacity + reserved)); |
141 | 142 |
142 // Check all committed values match expected | 143 // Check all committed values match expected |
143 for (size_t i = 0; i < k8BitCapacity - reserved; i++) { | 144 for (size_t i = 0; i < k8BitCapacity - reserved; i++) { |
144 Object* value = constant_array->get(static_cast<int>(i)); | 145 Object* value = constant_array->get(static_cast<int>(i)); |
145 Smi* smi = Smi::FromInt(static_cast<int>(i)); | 146 Smi* smi = Smi::FromInt(static_cast<int>(i)); |
146 CHECK(value->SameValue(smi)); | 147 CHECK(value->SameValue(smi)); |
147 } | 148 } |
148 for (size_t i = k8BitCapacity; i < 2 * k8BitCapacity + reserved; i++) { | 149 for (size_t i = k8BitCapacity; i < 2 * k8BitCapacity + reserved; i++) { |
149 Object* value = constant_array->get(static_cast<int>(i)); | 150 Object* value = constant_array->get(static_cast<int>(i)); |
150 Smi* smi = Smi::FromInt(static_cast<int>(i - reserved)); | 151 Smi* smi = Smi::FromInt(static_cast<int>(i - reserved)); |
(...skipping 30 matching lines...) Expand all Loading... |
181 } | 182 } |
182 for (size_t i = k8BitCapacity; i < k8BitCapacity + reserved; i++) { | 183 for (size_t i = k8BitCapacity; i < k8BitCapacity + reserved; i++) { |
183 OperandSize operand_size = builder.CreateReservedEntry(); | 184 OperandSize operand_size = builder.CreateReservedEntry(); |
184 CHECK(operand_size == OperandSize::kShort); | 185 CHECK(operand_size == OperandSize::kShort); |
185 builder.CommitReservedEntry(operand_size, | 186 builder.CommitReservedEntry(operand_size, |
186 Smi::FromInt(static_cast<int>(i))); | 187 Smi::FromInt(static_cast<int>(i))); |
187 CHECK_EQ(builder.size(), i + 1); | 188 CHECK_EQ(builder.size(), i + 1); |
188 } | 189 } |
189 | 190 |
190 Handle<FixedArray> constant_array = builder.ToFixedArray(isolate()); | 191 Handle<FixedArray> constant_array = builder.ToFixedArray(isolate()); |
191 CHECK_EQ(constant_array->length(), k8BitCapacity + reserved); | 192 CHECK_EQ(constant_array->length(), |
| 193 static_cast<int>(k8BitCapacity + reserved)); |
192 for (size_t i = 0; i < k8BitCapacity + reserved; i++) { | 194 for (size_t i = 0; i < k8BitCapacity + reserved; i++) { |
193 Object* value = constant_array->get(static_cast<int>(i)); | 195 Object* value = constant_array->get(static_cast<int>(i)); |
194 CHECK(value->SameValue(*isolate()->factory()->NewNumberFromSize(i))); | 196 CHECK(value->SameValue(*isolate()->factory()->NewNumberFromSize(i))); |
195 } | 197 } |
196 } | 198 } |
197 } | 199 } |
198 | 200 |
199 TEST_F(ConstantArrayBuilderTest, GapFilledWhenLowReservationCommitted) { | 201 TEST_F(ConstantArrayBuilderTest, GapFilledWhenLowReservationCommitted) { |
200 CanonicalHandleScope canonical(isolate()); | 202 CanonicalHandleScope canonical(isolate()); |
201 ConstantArrayBuilder builder(zone(), isolate()->factory()->the_hole_value()); | 203 ConstantArrayBuilder builder(zone(), isolate()->factory()->the_hole_value()); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 } | 255 } |
254 | 256 |
255 TEST_F(ConstantArrayBuilderTest, HolesWithUnusedReservations) { | 257 TEST_F(ConstantArrayBuilderTest, HolesWithUnusedReservations) { |
256 CanonicalHandleScope canonical(isolate()); | 258 CanonicalHandleScope canonical(isolate()); |
257 static int kNumberOfHoles = 128; | 259 static int kNumberOfHoles = 128; |
258 ConstantArrayBuilder builder(zone(), isolate()->factory()->the_hole_value()); | 260 ConstantArrayBuilder builder(zone(), isolate()->factory()->the_hole_value()); |
259 for (int i = 0; i < kNumberOfHoles; ++i) { | 261 for (int i = 0; i < kNumberOfHoles; ++i) { |
260 CHECK_EQ(builder.CreateReservedEntry(), OperandSize::kByte); | 262 CHECK_EQ(builder.CreateReservedEntry(), OperandSize::kByte); |
261 } | 263 } |
262 for (int i = 0; i < 128; ++i) { | 264 for (int i = 0; i < 128; ++i) { |
263 CHECK_EQ(builder.Insert(isolate()->factory()->NewNumber(i)), i); | 265 CHECK_EQ(builder.Insert(isolate()->factory()->NewNumber(i)), |
| 266 static_cast<size_t>(i)); |
264 } | 267 } |
265 CHECK_EQ(builder.Insert(isolate()->factory()->NewNumber(256)), 256); | 268 CHECK_EQ(builder.Insert(isolate()->factory()->NewNumber(256)), 256); |
266 | 269 |
267 Handle<FixedArray> constant_array = builder.ToFixedArray(isolate()); | 270 Handle<FixedArray> constant_array = builder.ToFixedArray(isolate()); |
268 CHECK_EQ(constant_array->length(), 257); | 271 CHECK_EQ(constant_array->length(), 257); |
269 for (int i = 128; i < 256; i++) { | 272 for (int i = 128; i < 256; i++) { |
270 CHECK(constant_array->get(i)->SameValue( | 273 CHECK(constant_array->get(i)->SameValue( |
271 *isolate()->factory()->the_hole_value())); | 274 *isolate()->factory()->the_hole_value())); |
272 } | 275 } |
273 CHECK(!constant_array->get(127)->SameValue( | 276 CHECK(!constant_array->get(127)->SameValue( |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 } | 322 } |
320 CHECK_EQ(builder.size(), k16BitCapacity); | 323 CHECK_EQ(builder.size(), k16BitCapacity); |
321 | 324 |
322 // Check values before reserved entries are inserted. | 325 // Check values before reserved entries are inserted. |
323 for (size_t i = 0; i < k16BitCapacity; i++) { | 326 for (size_t i = 0; i < k16BitCapacity; i++) { |
324 if ((i % 2) == 0) { | 327 if ((i % 2) == 0) { |
325 // Check reserved values are the hole. | 328 // Check reserved values are the hole. |
326 Handle<Object> empty = builder.At(i); | 329 Handle<Object> empty = builder.At(i); |
327 CHECK(empty->SameValue(isolate()->heap()->the_hole_value())); | 330 CHECK(empty->SameValue(isolate()->heap()->the_hole_value())); |
328 } else { | 331 } else { |
329 CHECK_EQ(Handle<Smi>::cast(builder.At(i))->value(), i); | 332 CHECK_EQ(Handle<Smi>::cast(builder.At(i))->value(), static_cast<int>(i)); |
330 } | 333 } |
331 } | 334 } |
332 | 335 |
333 // Insert reserved entries. | 336 // Insert reserved entries. |
334 for (size_t i = 0; i < k16BitCapacity; i += 2) { | 337 for (size_t i = 0; i < k16BitCapacity; i += 2) { |
335 builder.InsertAllocatedEntry( | 338 builder.InsertAllocatedEntry( |
336 i, handle(Smi::FromInt(static_cast<int>(i)), isolate())); | 339 i, handle(Smi::FromInt(static_cast<int>(i)), isolate())); |
337 } | 340 } |
338 | 341 |
339 // Check values after reserved entries are inserted. | 342 // Check values after reserved entries are inserted. |
340 for (size_t i = 0; i < k16BitCapacity; i++) { | 343 for (size_t i = 0; i < k16BitCapacity; i++) { |
341 CHECK_EQ(Handle<Smi>::cast(builder.At(i))->value(), i); | 344 CHECK_EQ(Handle<Smi>::cast(builder.At(i))->value(), static_cast<int>(i)); |
342 } | 345 } |
343 } | 346 } |
344 | 347 |
345 } // namespace interpreter | 348 } // namespace interpreter |
346 } // namespace internal | 349 } // namespace internal |
347 } // namespace v8 | 350 } // namespace v8 |
OLD | NEW |