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

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

Issue 2226333002: [Interpreter] Avoid allocating handles in bytecode-array-writer (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@offheap_varchecks
Patch Set: [Interpreter] Avoid allocating handles in bytecode-array-writer 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/interpreter/constant-array-builder.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/unittests/interpreter/constant-array-builder-unittest.cc
diff --git a/test/unittests/interpreter/constant-array-builder-unittest.cc b/test/unittests/interpreter/constant-array-builder-unittest.cc
index ee77423175d8e8213ce8d8add1f6465933cafc88..263c809fcdf884b5fbd23558bb3f5c57c43d9833 100644
--- a/test/unittests/interpreter/constant-array-builder-unittest.cc
+++ b/test/unittests/interpreter/constant-array-builder-unittest.cc
@@ -40,6 +40,53 @@ TEST_F(ConstantArrayBuilderTest, AllocateAllEntries) {
}
}
+TEST_F(ConstantArrayBuilderTest, ToFixedArray) {
+ CanonicalHandleScope canonical(isolate());
+ ConstantArrayBuilder builder(isolate(), zone());
+ static const size_t kNumberOfElements = 37;
+ for (size_t i = 0; i < kNumberOfElements; i++) {
+ Handle<Object> object = isolate()->factory()->NewNumberFromSize(i);
+ builder.Insert(object);
+ CHECK(builder.At(i)->SameValue(*object));
+ }
+ Handle<FixedArray> constant_array = builder.ToFixedArray();
+ CHECK_EQ(constant_array->length(), kNumberOfElements);
+ for (size_t i = 0; i < kNumberOfElements; i++) {
+ CHECK(constant_array->get(static_cast<int>(i))->SameValue(*builder.At(i)));
+ }
+}
+
+TEST_F(ConstantArrayBuilderTest, ToLargeFixedArray) {
+ CanonicalHandleScope canonical(isolate());
+ ConstantArrayBuilder builder(isolate(), zone());
+ static const size_t kNumberOfElements = 37373;
+ for (size_t i = 0; i < kNumberOfElements; i++) {
+ Handle<Object> object = isolate()->factory()->NewNumberFromSize(i);
+ builder.Insert(object);
+ CHECK(builder.At(i)->SameValue(*object));
+ }
+ Handle<FixedArray> constant_array = builder.ToFixedArray();
+ CHECK_EQ(constant_array->length(), kNumberOfElements);
+ for (size_t i = 0; i < kNumberOfElements; i++) {
+ CHECK(constant_array->get(static_cast<int>(i))->SameValue(*builder.At(i)));
+ }
+}
+
+TEST_F(ConstantArrayBuilderTest, ToLargeFixedArrayWithReservations) {
+ CanonicalHandleScope canonical(isolate());
+ ConstantArrayBuilder builder(isolate(), zone());
+ static const size_t kNumberOfElements = 37373;
+ for (size_t i = 0; i < kNumberOfElements; i++) {
+ builder.CommitReservedEntry(builder.CreateReservedEntry(),
+ Smi::FromInt(static_cast<int>(i)));
+ }
+ Handle<FixedArray> constant_array = builder.ToFixedArray();
+ CHECK_EQ(constant_array->length(), kNumberOfElements);
+ for (size_t i = 0; i < kNumberOfElements; i++) {
+ CHECK(constant_array->get(static_cast<int>(i))->SameValue(*builder.At(i)));
+ }
+}
+
TEST_F(ConstantArrayBuilderTest, AllocateEntriesWithIdx8Reservations) {
CanonicalHandleScope canonical(isolate());
for (size_t reserved = 1; reserved < k8BitCapacity; reserved *= 3) {
@@ -49,16 +96,14 @@ TEST_F(ConstantArrayBuilderTest, AllocateEntriesWithIdx8Reservations) {
CHECK(operand_size == OperandSize::kByte);
}
for (size_t i = 0; i < 2 * k8BitCapacity; i++) {
- Handle<Object> object = isolate()->factory()->NewNumberFromSize(i);
- builder.Insert(object);
+ builder.CommitReservedEntry(builder.CreateReservedEntry(),
+ Smi::FromInt(static_cast<int>(i)));
if (i + reserved < k8BitCapacity) {
CHECK_LE(builder.size(), k8BitCapacity);
CHECK_EQ(builder.size(), i + 1);
- CHECK(builder.At(i)->SameValue(*object));
} else {
CHECK_GE(builder.size(), k8BitCapacity);
CHECK_EQ(builder.size(), i + reserved + 1);
- CHECK(builder.At(i + reserved)->SameValue(*object));
}
}
CHECK_EQ(builder.size(), 2 * k8BitCapacity + reserved);
@@ -69,44 +114,41 @@ TEST_F(ConstantArrayBuilderTest, AllocateEntriesWithIdx8Reservations) {
CHECK(empty->SameValue(isolate()->heap()->the_hole_value()));
}
- // Commmit reserved entries with duplicates and check size does not change.
+ // Commit reserved entries with duplicates and check size does not change.
DCHECK_EQ(reserved + 2 * k8BitCapacity, builder.size());
size_t duplicates_in_idx8_space =
std::min(reserved, k8BitCapacity - reserved);
for (size_t i = 0; i < duplicates_in_idx8_space; i++) {
builder.CommitReservedEntry(OperandSize::kByte,
- isolate()->factory()->NewNumberFromSize(i));
+ Smi::FromInt(static_cast<int>(i)));
DCHECK_EQ(reserved + 2 * k8BitCapacity, builder.size());
}
- // Check all committed values match expected (holes where
- // duplicates_in_idx8_space allocated).
- for (size_t i = 0; i < k8BitCapacity - reserved; i++) {
- Smi* smi = Smi::FromInt(static_cast<int>(i));
- CHECK(Handle<Smi>::cast(builder.At(i))->SameValue(smi));
- }
- for (size_t i = k8BitCapacity; i < 2 * k8BitCapacity + reserved; i++) {
- Smi* smi = Smi::FromInt(static_cast<int>(i - reserved));
- CHECK(Handle<Smi>::cast(builder.At(i))->SameValue(smi));
- }
- for (size_t i = 0; i < reserved; i++) {
- size_t index = k8BitCapacity - reserved + i;
- CHECK(builder.At(index)->IsTheHole(isolate()));
- }
-
// Now make reservations, and commit them with unique entries.
for (size_t i = 0; i < duplicates_in_idx8_space; i++) {
OperandSize operand_size = builder.CreateReservedEntry();
CHECK(operand_size == OperandSize::kByte);
}
for (size_t i = 0; i < duplicates_in_idx8_space; i++) {
- Handle<Object> object =
- isolate()->factory()->NewNumberFromSize(2 * k8BitCapacity + i);
- size_t index = builder.CommitReservedEntry(OperandSize::kByte, object);
+ Smi* value = Smi::FromInt(static_cast<int>(2 * k8BitCapacity + i));
+ size_t index = builder.CommitReservedEntry(OperandSize::kByte, value);
CHECK_EQ(static_cast<int>(index), k8BitCapacity - reserved + i);
- CHECK(builder.At(static_cast<int>(index))->SameValue(*object));
}
- CHECK_EQ(builder.size(), 2 * k8BitCapacity + reserved);
+
+ Handle<FixedArray> constant_array = builder.ToFixedArray();
+ CHECK_EQ(constant_array->length(), 2 * k8BitCapacity + reserved);
+
+ // Check all committed values match expected
+ for (size_t i = 0; i < k8BitCapacity - reserved; i++) {
+ Object* value = constant_array->get(static_cast<int>(i));
+ Smi* smi = Smi::FromInt(static_cast<int>(i));
+ CHECK(value->SameValue(smi));
+ }
+ for (size_t i = k8BitCapacity; i < 2 * k8BitCapacity + reserved; i++) {
+ Object* value = constant_array->get(static_cast<int>(i));
+ Smi* smi = Smi::FromInt(static_cast<int>(i - reserved));
+ CHECK(value->SameValue(smi));
+ }
}
}
@@ -115,9 +157,8 @@ TEST_F(ConstantArrayBuilderTest, AllocateEntriesWithWideReservations) {
for (size_t reserved = 1; reserved < k8BitCapacity; reserved *= 3) {
ConstantArrayBuilder builder(isolate(), zone());
for (size_t i = 0; i < k8BitCapacity; i++) {
- Handle<Object> object = isolate()->factory()->NewNumberFromSize(i);
- builder.Insert(object);
- CHECK(builder.At(i)->SameValue(*object));
+ builder.CommitReservedEntry(builder.CreateReservedEntry(),
+ Smi::FromInt(static_cast<int>(i)));
CHECK_EQ(builder.size(), i + 1);
}
for (size_t i = 0; i < reserved; i++) {
@@ -132,50 +173,24 @@ TEST_F(ConstantArrayBuilderTest, AllocateEntriesWithWideReservations) {
for (size_t i = 0; i < reserved; i++) {
OperandSize operand_size = builder.CreateReservedEntry();
CHECK(operand_size == OperandSize::kShort);
- Handle<Object> object = isolate()->factory()->NewNumberFromSize(i);
- builder.CommitReservedEntry(operand_size, object);
+ builder.CommitReservedEntry(operand_size,
+ Smi::FromInt(static_cast<int>(i)));
CHECK_EQ(builder.size(), k8BitCapacity);
}
for (size_t i = k8BitCapacity; i < k8BitCapacity + reserved; i++) {
OperandSize operand_size = builder.CreateReservedEntry();
CHECK(operand_size == OperandSize::kShort);
- Handle<Object> object = isolate()->factory()->NewNumberFromSize(i);
- builder.CommitReservedEntry(operand_size, object);
+ builder.CommitReservedEntry(operand_size,
+ Smi::FromInt(static_cast<int>(i)));
CHECK_EQ(builder.size(), i + 1);
}
- }
-}
-
-
-TEST_F(ConstantArrayBuilderTest, ToFixedArray) {
- CanonicalHandleScope canonical(isolate());
- ConstantArrayBuilder builder(isolate(), zone());
- static const size_t kNumberOfElements = 37;
- for (size_t i = 0; i < kNumberOfElements; i++) {
- Handle<Object> object = isolate()->factory()->NewNumberFromSize(i);
- builder.Insert(object);
- CHECK(builder.At(i)->SameValue(*object));
- }
- Handle<FixedArray> constant_array = builder.ToFixedArray();
- CHECK_EQ(constant_array->length(), kNumberOfElements);
- for (size_t i = 0; i < kNumberOfElements; i++) {
- CHECK(constant_array->get(static_cast<int>(i))->SameValue(*builder.At(i)));
- }
-}
-TEST_F(ConstantArrayBuilderTest, ToLargeFixedArray) {
- CanonicalHandleScope canonical(isolate());
- ConstantArrayBuilder builder(isolate(), zone());
- static const size_t kNumberOfElements = 37373;
- for (size_t i = 0; i < kNumberOfElements; i++) {
- Handle<Object> object = isolate()->factory()->NewNumberFromSize(i);
- builder.Insert(object);
- CHECK(builder.At(i)->SameValue(*object));
- }
- Handle<FixedArray> constant_array = builder.ToFixedArray();
- CHECK_EQ(constant_array->length(), kNumberOfElements);
- for (size_t i = 0; i < kNumberOfElements; i++) {
- CHECK(constant_array->get(static_cast<int>(i))->SameValue(*builder.At(i)));
+ Handle<FixedArray> constant_array = builder.ToFixedArray();
+ CHECK_EQ(constant_array->length(), k8BitCapacity + reserved);
+ for (size_t i = 0; i < k8BitCapacity + reserved; i++) {
+ Object* value = constant_array->get(static_cast<int>(i));
+ CHECK(value->SameValue(*isolate()->factory()->NewNumberFromSize(i)));
+ }
}
}
@@ -188,19 +203,21 @@ TEST_F(ConstantArrayBuilderTest, GapFilledWhenLowReservationCommitted) {
CHECK_EQ(builder.size(), 0);
}
for (size_t i = 0; i < k8BitCapacity; i++) {
- Handle<Object> object = isolate()->factory()->NewNumberFromSize(i);
- builder.Insert(object);
+ builder.CommitReservedEntry(builder.CreateReservedEntry(),
+ Smi::FromInt(static_cast<int>(i)));
CHECK_EQ(builder.size(), i + k8BitCapacity + 1);
}
for (size_t i = 0; i < k8BitCapacity; i++) {
builder.CommitReservedEntry(OperandSize::kByte,
- builder.At(i + k8BitCapacity));
+ Smi::FromInt(static_cast<int>(i)));
CHECK_EQ(builder.size(), 2 * k8BitCapacity);
}
+ Handle<FixedArray> constant_array = builder.ToFixedArray();
+ CHECK_EQ(constant_array->length(), 2 * k8BitCapacity);
for (size_t i = 0; i < k8BitCapacity; i++) {
- Handle<Object> original = builder.At(k8BitCapacity + i);
- Handle<Object> duplicate = builder.At(i);
- CHECK(original->SameValue(*duplicate));
+ Object* original = constant_array->get(static_cast<int>(k8BitCapacity + i));
+ Object* duplicate = constant_array->get(static_cast<int>(i));
+ CHECK(original->SameValue(duplicate));
Handle<Object> reference = isolate()->factory()->NewNumberFromSize(i);
CHECK(original->SameValue(*reference));
}
@@ -269,14 +286,10 @@ TEST_F(ConstantArrayBuilderTest, ReservationsAtAllScales) {
for (int i = 65536; i < 131072; ++i) {
CHECK_EQ(builder.CreateReservedEntry(), OperandSize::kQuad);
}
- CHECK_EQ(builder.CommitReservedEntry(OperandSize::kByte,
- isolate()->factory()->NewNumber(1)),
- 0);
- CHECK_EQ(builder.CommitReservedEntry(OperandSize::kShort,
- isolate()->factory()->NewNumber(2)),
+ CHECK_EQ(builder.CommitReservedEntry(OperandSize::kByte, Smi::FromInt(1)), 0);
+ CHECK_EQ(builder.CommitReservedEntry(OperandSize::kShort, Smi::FromInt(2)),
256);
- CHECK_EQ(builder.CommitReservedEntry(OperandSize::kQuad,
- isolate()->factory()->NewNumber(3)),
+ CHECK_EQ(builder.CommitReservedEntry(OperandSize::kQuad, Smi::FromInt(3)),
65536);
Handle<FixedArray> constant_array = builder.ToFixedArray();
CHECK_EQ(constant_array->length(), 65537);
« no previous file with comments | « src/interpreter/constant-array-builder.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698