| 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 21 matching lines...) Expand all Loading... |
| 32 ConstantArrayBuilder builder(isolate(), zone()); | 32 ConstantArrayBuilder builder(isolate(), zone()); |
| 33 for (size_t i = 0; i < k16BitCapacity; i++) { | 33 for (size_t i = 0; i < k16BitCapacity; i++) { |
| 34 builder.Insert(handle(Smi::FromInt(static_cast<int>(i)), isolate())); | 34 builder.Insert(handle(Smi::FromInt(static_cast<int>(i)), isolate())); |
| 35 } | 35 } |
| 36 CHECK_EQ(builder.size(), k16BitCapacity); | 36 CHECK_EQ(builder.size(), k16BitCapacity); |
| 37 for (size_t i = 0; i < k16BitCapacity; i++) { | 37 for (size_t i = 0; i < k16BitCapacity; i++) { |
| 38 CHECK_EQ(Handle<Smi>::cast(builder.At(i))->value(), i); | 38 CHECK_EQ(Handle<Smi>::cast(builder.At(i))->value(), i); |
| 39 } | 39 } |
| 40 } | 40 } |
| 41 | 41 |
| 42 | |
| 43 TEST_F(ConstantArrayBuilderTest, AllocateEntriesWithIdx8Reservations) { | 42 TEST_F(ConstantArrayBuilderTest, AllocateEntriesWithIdx8Reservations) { |
| 44 for (size_t reserved = 1; reserved < k8BitCapacity; reserved *= 3) { | 43 for (size_t reserved = 1; reserved < k8BitCapacity; reserved *= 3) { |
| 45 ConstantArrayBuilder builder(isolate(), zone()); | 44 ConstantArrayBuilder builder(isolate(), zone()); |
| 46 for (size_t i = 0; i < reserved; i++) { | 45 for (size_t i = 0; i < reserved; i++) { |
| 47 OperandSize operand_size = builder.CreateReservedEntry(); | 46 OperandSize operand_size = builder.CreateReservedEntry(); |
| 48 CHECK(operand_size == OperandSize::kByte); | 47 CHECK(operand_size == OperandSize::kByte); |
| 49 } | 48 } |
| 50 for (size_t i = 0; i < 2 * k8BitCapacity; i++) { | 49 for (size_t i = 0; i < 2 * k8BitCapacity; i++) { |
| 51 Handle<Object> object = isolate()->factory()->NewNumberFromSize(i); | 50 Handle<Object> object = isolate()->factory()->NewNumberFromSize(i); |
| 52 builder.Insert(object); | 51 builder.Insert(object); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 } | 193 } |
| 195 for (size_t i = 0; i < k8BitCapacity; i++) { | 194 for (size_t i = 0; i < k8BitCapacity; i++) { |
| 196 Handle<Object> original = builder.At(k8BitCapacity + i); | 195 Handle<Object> original = builder.At(k8BitCapacity + i); |
| 197 Handle<Object> duplicate = builder.At(i); | 196 Handle<Object> duplicate = builder.At(i); |
| 198 CHECK(original->SameValue(*duplicate)); | 197 CHECK(original->SameValue(*duplicate)); |
| 199 Handle<Object> reference = isolate()->factory()->NewNumberFromSize(i); | 198 Handle<Object> reference = isolate()->factory()->NewNumberFromSize(i); |
| 200 CHECK(original->SameValue(*reference)); | 199 CHECK(original->SameValue(*reference)); |
| 201 } | 200 } |
| 202 } | 201 } |
| 203 | 202 |
| 204 | |
| 205 TEST_F(ConstantArrayBuilderTest, GapNotFilledWhenLowReservationDiscarded) { | 203 TEST_F(ConstantArrayBuilderTest, GapNotFilledWhenLowReservationDiscarded) { |
| 206 ConstantArrayBuilder builder(isolate(), zone()); | 204 ConstantArrayBuilder builder(isolate(), zone()); |
| 207 for (size_t i = 0; i < k8BitCapacity; i++) { | 205 for (size_t i = 0; i < k8BitCapacity; i++) { |
| 208 OperandSize operand_size = builder.CreateReservedEntry(); | 206 OperandSize operand_size = builder.CreateReservedEntry(); |
| 209 CHECK(OperandSize::kByte == operand_size); | 207 CHECK(OperandSize::kByte == operand_size); |
| 210 CHECK_EQ(builder.size(), 0); | 208 CHECK_EQ(builder.size(), 0); |
| 211 } | 209 } |
| 212 for (size_t i = 0; i < k8BitCapacity; i++) { | 210 for (size_t i = 0; i < k8BitCapacity; i++) { |
| 213 Handle<Object> object = isolate()->factory()->NewNumberFromSize(i); | 211 Handle<Object> object = isolate()->factory()->NewNumberFromSize(i); |
| 214 builder.Insert(object); | 212 builder.Insert(object); |
| 215 CHECK_EQ(builder.size(), i + k8BitCapacity + 1); | 213 CHECK_EQ(builder.size(), i + k8BitCapacity + 1); |
| 216 } | 214 } |
| 217 for (size_t i = 0; i < k8BitCapacity; i++) { | 215 for (size_t i = 0; i < k8BitCapacity; i++) { |
| 218 builder.DiscardReservedEntry(OperandSize::kByte); | 216 builder.DiscardReservedEntry(OperandSize::kByte); |
| 219 builder.Insert(builder.At(i + k8BitCapacity)); | 217 builder.Insert(builder.At(i + k8BitCapacity)); |
| 220 CHECK_EQ(builder.size(), 2 * k8BitCapacity); | 218 CHECK_EQ(builder.size(), 2 * k8BitCapacity); |
| 221 } | 219 } |
| 222 for (size_t i = 0; i < k8BitCapacity; i++) { | 220 for (size_t i = 0; i < k8BitCapacity; i++) { |
| 223 Handle<Object> reference = isolate()->factory()->NewNumberFromSize(i); | 221 Handle<Object> reference = isolate()->factory()->NewNumberFromSize(i); |
| 224 Handle<Object> original = builder.At(k8BitCapacity + i); | 222 Handle<Object> original = builder.At(k8BitCapacity + i); |
| 225 CHECK(original->SameValue(*reference)); | 223 CHECK(original->SameValue(*reference)); |
| 226 Handle<Object> duplicate = builder.At(i); | 224 Handle<Object> duplicate = builder.At(i); |
| 227 CHECK(duplicate->SameValue(*isolate()->factory()->the_hole_value())); | 225 CHECK(duplicate->SameValue(*isolate()->factory()->the_hole_value())); |
| 228 } | 226 } |
| 229 } | 227 } |
| 230 | 228 |
| 229 TEST_F(ConstantArrayBuilderTest, HolesWithUnusedReservations) { |
| 230 static int kNumberOfHoles = 128; |
| 231 ConstantArrayBuilder builder(isolate(), zone()); |
| 232 for (int i = 0; i < kNumberOfHoles; ++i) { |
| 233 CHECK_EQ(builder.CreateReservedEntry(), OperandSize::kByte); |
| 234 } |
| 235 for (int i = 0; i < 128; ++i) { |
| 236 CHECK_EQ(builder.Insert(isolate()->factory()->NewNumber(i)), i); |
| 237 } |
| 238 CHECK_EQ(builder.Insert(isolate()->factory()->NewNumber(256)), 256); |
| 239 |
| 240 Handle<FixedArray> constant_array = builder.ToFixedArray(); |
| 241 CHECK_EQ(constant_array->length(), 257); |
| 242 for (int i = 128; i < 256; i++) { |
| 243 CHECK(constant_array->get(i)->SameValue( |
| 244 *isolate()->factory()->the_hole_value())); |
| 245 } |
| 246 CHECK(!constant_array->get(127)->SameValue( |
| 247 *isolate()->factory()->the_hole_value())); |
| 248 CHECK(!constant_array->get(256)->SameValue( |
| 249 *isolate()->factory()->the_hole_value())); |
| 250 } |
| 251 |
| 252 TEST_F(ConstantArrayBuilderTest, ReservationsAtAllScales) { |
| 253 ConstantArrayBuilder builder(isolate(), zone()); |
| 254 for (int i = 0; i < 256; i++) { |
| 255 CHECK_EQ(builder.CreateReservedEntry(), OperandSize::kByte); |
| 256 } |
| 257 for (int i = 256; i < 65536; ++i) { |
| 258 CHECK_EQ(builder.CreateReservedEntry(), OperandSize::kShort); |
| 259 } |
| 260 for (int i = 65536; i < 131072; ++i) { |
| 261 CHECK_EQ(builder.CreateReservedEntry(), OperandSize::kQuad); |
| 262 } |
| 263 CHECK_EQ(builder.CommitReservedEntry(OperandSize::kByte, |
| 264 isolate()->factory()->NewNumber(1)), |
| 265 0); |
| 266 CHECK_EQ(builder.CommitReservedEntry(OperandSize::kShort, |
| 267 isolate()->factory()->NewNumber(2)), |
| 268 256); |
| 269 CHECK_EQ(builder.CommitReservedEntry(OperandSize::kQuad, |
| 270 isolate()->factory()->NewNumber(3)), |
| 271 65536); |
| 272 Handle<FixedArray> constant_array = builder.ToFixedArray(); |
| 273 CHECK_EQ(constant_array->length(), 65537); |
| 274 int count = 1; |
| 275 for (int i = 0; i < constant_array->length(); ++i) { |
| 276 Handle<Object> expected; |
| 277 if (i == 0 || i == 256 || i == 65536) { |
| 278 expected = isolate()->factory()->NewNumber(count++); |
| 279 } else { |
| 280 expected = isolate()->factory()->the_hole_value(); |
| 281 } |
| 282 CHECK(constant_array->get(i)->SameValue(*expected)); |
| 283 } |
| 284 } |
| 285 |
| 231 } // namespace interpreter | 286 } // namespace interpreter |
| 232 } // namespace internal | 287 } // namespace internal |
| 233 } // namespace v8 | 288 } // namespace v8 |
| OLD | NEW |