diff options
Diffstat (limited to 'deps/v8/test/cctest/test-identity-map.cc')
-rw-r--r-- | deps/v8/test/cctest/test-identity-map.cc | 153 |
1 files changed, 80 insertions, 73 deletions
diff --git a/deps/v8/test/cctest/test-identity-map.cc b/deps/v8/test/cctest/test-identity-map.cc index 23cc8a71bf..7207c86452 100644 --- a/deps/v8/test/cctest/test-identity-map.cc +++ b/deps/v8/test/cctest/test-identity-map.cc @@ -26,45 +26,48 @@ class IdentityMapTester : public HandleAndZoneScope { Heap* heap() { return isolate()->heap(); } Isolate* isolate() { return main_isolate(); } - void TestGetFind(Handle<Object> key1, void* val1, Handle<Object> key2, - void* val2) { + void TestInsertFind(Handle<Object> key1, void* val1, Handle<Object> key2, + void* val2) { CHECK_NULL(map.Find(key1)); CHECK_NULL(map.Find(key2)); // Set {key1} the first time. - void** entry = map.Get(key1); - CHECK_NOT_NULL(entry); - *entry = val1; + auto find_result = map.FindOrInsert(key1); + CHECK_NOT_NULL(find_result.entry); + CHECK(!find_result.already_exists); + *find_result.entry = val1; for (int i = 0; i < 3; i++) { // Get and find {key1} K times. { - void** nentry = map.Get(key1); - CHECK_EQ(entry, nentry); - CHECK_EQ(val1, *nentry); + auto new_find_result = map.FindOrInsert(key1); + CHECK(new_find_result.already_exists); + CHECK_EQ(find_result.entry, new_find_result.entry); + CHECK_EQ(val1, *new_find_result.entry); CHECK_NULL(map.Find(key2)); } { void** nentry = map.Find(key1); - CHECK_EQ(entry, nentry); + CHECK_EQ(find_result.entry, nentry); CHECK_EQ(val1, *nentry); CHECK_NULL(map.Find(key2)); } } // Set {key2} the first time. - void** entry2 = map.Get(key2); - CHECK_NOT_NULL(entry2); - *entry2 = val2; + auto find_result2 = map.FindOrInsert(key2); + CHECK_NOT_NULL(find_result2.entry); + CHECK(!find_result2.already_exists); + *find_result2.entry = val2; for (int i = 0; i < 3; i++) { // Get and find {key1} and {key2} K times. { - void** nentry = map.Get(key2); - CHECK_EQ(entry2, nentry); - CHECK_EQ(val2, *nentry); + auto new_find_result = map.FindOrInsert(key2); + CHECK_EQ(find_result2.entry, new_find_result.entry); + CHECK_EQ(val2, *new_find_result.entry); } { void** nentry = map.Find(key2); - CHECK_EQ(entry2, nentry); + CHECK_EQ(find_result2.entry, nentry); CHECK_EQ(val2, *nentry); } { @@ -80,12 +83,14 @@ class IdentityMapTester : public HandleAndZoneScope { CHECK_NULL(map.Find(key2)); // Set {key1} and {key2} for the first time. - void** entry1 = map.Get(key1); - CHECK_NOT_NULL(entry1); - *entry1 = val1; - void** entry2 = map.Get(key2); - CHECK_NOT_NULL(entry2); - *entry2 = val2; + auto find_result1 = map.FindOrInsert(key1); + CHECK(!find_result1.already_exists); + CHECK_NOT_NULL(find_result1.entry); + *find_result1.entry = val1; + auto find_result2 = map.FindOrInsert(key2); + CHECK(!find_result1.already_exists); + CHECK_NOT_NULL(find_result2.entry); + *find_result2.entry = val2; for (int i = 0; i < 3; i++) { // Find {key1} and {key2} 3 times. { @@ -157,10 +162,11 @@ class IdentityMapTester : public HandleAndZoneScope { CHECK_EQ(value, *entry); } - void CheckGet(Handle<Object> key, void* value) { - void** entry = map.Get(key); - CHECK_NOT_NULL(entry); - CHECK_EQ(value, *entry); + void CheckFindOrInsert(Handle<Object> key, void* value) { + auto find_result = map.FindOrInsert(key); + CHECK(find_result.already_exists); + CHECK_NOT_NULL(find_result.entry); + CHECK_EQ(value, *find_result.entry); } void CheckDelete(Handle<Object> key, void* value) { @@ -219,17 +225,17 @@ TEST(Delete_num_not_found) { TEST(GetFind_smi_0) { IdentityMapTester t; - t.TestGetFind(t.smi(0), t.isolate(), t.smi(1), t.heap()); + t.TestInsertFind(t.smi(0), t.isolate(), t.smi(1), t.heap()); } TEST(GetFind_smi_13) { IdentityMapTester t; - t.TestGetFind(t.smi(13), t.isolate(), t.smi(17), t.heap()); + t.TestInsertFind(t.smi(13), t.isolate(), t.smi(17), t.heap()); } TEST(GetFind_num_13) { IdentityMapTester t; - t.TestGetFind(t.num(13.1), t.isolate(), t.num(17.1), t.heap()); + t.TestInsertFind(t.num(13.1), t.isolate(), t.num(17.1), t.heap()); } TEST(Delete_smi_13) { @@ -250,7 +256,7 @@ TEST(GetFind_smi_17m) { IdentityMapTester t; for (int i = 1; i < 100; i += kInterval) { - t.map.Set(t.smi(i), reinterpret_cast<void*>(i + kShift)); + t.map.Insert(t.smi(i), reinterpret_cast<void*>(i + kShift)); } for (int i = 1; i < 100; i += kInterval) { @@ -258,7 +264,7 @@ TEST(GetFind_smi_17m) { } for (int i = 1; i < 100; i += kInterval) { - t.CheckGet(t.smi(i), reinterpret_cast<void*>(i + kShift)); + t.CheckFindOrInsert(t.smi(i), reinterpret_cast<void*>(i + kShift)); } for (int i = 1; i < 100; i++) { @@ -278,7 +284,7 @@ TEST(Delete_smi_17m) { IdentityMapTester t; for (int i = 1; i < 100; i += kInterval) { - t.map.Set(t.smi(i), reinterpret_cast<void*>(i + kShift)); + t.map.Insert(t.smi(i), reinterpret_cast<void*>(i + kShift)); } for (int i = 1; i < 100; i += kInterval) { @@ -288,7 +294,7 @@ TEST(Delete_smi_17m) { for (int i = 1; i < 100; i += kInterval) { t.CheckDelete(t.smi(i), reinterpret_cast<void*>(i + kShift)); for (int j = 1; j < 100; j += kInterval) { - void** entry = t.map.Find(t.smi(j)); + auto entry = t.map.Find(t.smi(j)); if (j <= i) { CHECK_NULL(entry); } else { @@ -306,7 +312,7 @@ TEST(GetFind_num_1000) { int val2; for (int i = 0; i < 1000; i++) { - t.TestGetFind(t.smi(i * kPrime), &val1, t.smi(i * kPrime + 1), &val2); + t.TestInsertFind(t.smi(i * kPrime), &val1, t.smi(i * kPrime + 1), &val2); } } @@ -315,7 +321,7 @@ TEST(Delete_num_1000) { IdentityMapTester t; for (int i = 0; i < 1000; i++) { - t.map.Set(t.smi(i * kPrime), reinterpret_cast<void*>(i * kPrime)); + t.map.Insert(t.smi(i * kPrime), reinterpret_cast<void*>(i * kPrime)); } // Delete every second value in reverse. @@ -326,7 +332,7 @@ TEST(Delete_num_1000) { } for (int i = 0; i < 1000; i++) { - void** entry = t.map.Find(t.smi(i * kPrime)); + auto entry = t.map.Find(t.smi(i * kPrime)); if (i % 2) { CHECK_NULL(entry); } else { @@ -343,7 +349,7 @@ TEST(Delete_num_1000) { } for (int i = 0; i < 1000; i++) { - void** entry = t.map.Find(t.smi(i * kPrime)); + auto entry = t.map.Find(t.smi(i * kPrime)); CHECK_NULL(entry); } } @@ -353,10 +359,10 @@ TEST(GetFind_smi_gc) { const int kShift = 1211; IdentityMapTester t; - t.map.Set(t.smi(kKey), &t); + t.map.Insert(t.smi(kKey), &t); t.SimulateGCByIncrementingSmisBy(kShift); t.CheckFind(t.smi(kKey + kShift), &t); - t.CheckGet(t.smi(kKey + kShift), &t); + t.CheckFindOrInsert(t.smi(kKey + kShift), &t); } TEST(Delete_smi_gc) { @@ -364,7 +370,7 @@ TEST(Delete_smi_gc) { const int kShift = 1211; IdentityMapTester t; - t.map.Set(t.smi(kKey), &t); + t.map.Insert(t.smi(kKey), &t); t.SimulateGCByIncrementingSmisBy(kShift); t.CheckDelete(t.smi(kKey + kShift), &t); } @@ -375,13 +381,13 @@ TEST(GetFind_smi_gc2) { const int kShift = 1211; IdentityMapTester t; - t.map.Set(t.smi(kKey1), &kKey1); - t.map.Set(t.smi(kKey2), &kKey2); + t.map.Insert(t.smi(kKey1), &kKey1); + t.map.Insert(t.smi(kKey2), &kKey2); t.SimulateGCByIncrementingSmisBy(kShift); t.CheckFind(t.smi(kKey1 + kShift), &kKey1); - t.CheckGet(t.smi(kKey1 + kShift), &kKey1); + t.CheckFindOrInsert(t.smi(kKey1 + kShift), &kKey1); t.CheckFind(t.smi(kKey2 + kShift), &kKey2); - t.CheckGet(t.smi(kKey2 + kShift), &kKey2); + t.CheckFindOrInsert(t.smi(kKey2 + kShift), &kKey2); } TEST(Delete_smi_gc2) { @@ -390,8 +396,8 @@ TEST(Delete_smi_gc2) { const int kShift = 1211; IdentityMapTester t; - t.map.Set(t.smi(kKey1), &kKey1); - t.map.Set(t.smi(kKey2), &kKey2); + t.map.Insert(t.smi(kKey1), &kKey1); + t.map.Insert(t.smi(kKey2), &kKey2); t.SimulateGCByIncrementingSmisBy(kShift); t.CheckDelete(t.smi(kKey1 + kShift), &kKey1); t.CheckDelete(t.smi(kKey2 + kShift), &kKey2); @@ -404,7 +410,8 @@ TEST(GetFind_smi_gc_n) { 1 + 32, 2 + 32, 7 + 32, 8 + 32, 15 + 32, 23 + 32}; // Initialize the map first. for (size_t i = 0; i < arraysize(keys); i += 2) { - t.TestGetFind(t.smi(keys[i]), &keys[i], t.smi(keys[i + 1]), &keys[i + 1]); + t.TestInsertFind(t.smi(keys[i]), &keys[i], t.smi(keys[i + 1]), + &keys[i + 1]); } // Check the above initialization. for (size_t i = 0; i < arraysize(keys); i++) { @@ -418,7 +425,7 @@ TEST(GetFind_smi_gc_n) { } // Check that searching for the incremented smis gets the same values. for (size_t i = 0; i < arraysize(keys); i++) { - t.CheckGet(t.smi(keys[i] + kShift), &keys[i]); + t.CheckFindOrInsert(t.smi(keys[i] + kShift), &keys[i]); } } @@ -429,7 +436,7 @@ TEST(Delete_smi_gc_n) { 1 + 32, 2 + 32, 7 + 32, 8 + 32, 15 + 32, 23 + 32}; // Initialize the map first. for (size_t i = 0; i < arraysize(keys); i++) { - t.map.Set(t.smi(keys[i]), &keys[i]); + t.map.Insert(t.smi(keys[i]), &keys[i]); } // Simulate a GC by "moving" the smis in the internal keys array. t.SimulateGCByIncrementingSmisBy(kShift); @@ -448,10 +455,10 @@ TEST(GetFind_smi_num_gc_n) { t.num(9.9), t.num(10.1)}; // Initialize the map first. for (size_t i = 0; i < arraysize(smi_keys); i++) { - t.map.Set(t.smi(smi_keys[i]), &smi_keys[i]); + t.map.Insert(t.smi(smi_keys[i]), &smi_keys[i]); } for (size_t i = 0; i < arraysize(num_keys); i++) { - t.map.Set(num_keys[i], &num_keys[i]); + t.map.Insert(num_keys[i], &num_keys[i]); } // Check the above initialization. for (size_t i = 0; i < arraysize(smi_keys); i++) { @@ -468,13 +475,13 @@ TEST(GetFind_smi_num_gc_n) { // Check that searching for the incremented smis finds the same values. for (size_t i = 0; i < arraysize(smi_keys); i++) { t.CheckFind(t.smi(smi_keys[i] + kShift), &smi_keys[i]); - t.CheckGet(t.smi(smi_keys[i] + kShift), &smi_keys[i]); + t.CheckFindOrInsert(t.smi(smi_keys[i] + kShift), &smi_keys[i]); } // Check that searching for the numbers finds the same values. for (size_t i = 0; i < arraysize(num_keys); i++) { t.CheckFind(num_keys[i], &num_keys[i]); - t.CheckGet(num_keys[i], &num_keys[i]); + t.CheckFindOrInsert(num_keys[i], &num_keys[i]); } } @@ -487,10 +494,10 @@ TEST(Delete_smi_num_gc_n) { t.num(9.9), t.num(10.1)}; // Initialize the map first. for (size_t i = 0; i < arraysize(smi_keys); i++) { - t.map.Set(t.smi(smi_keys[i]), &smi_keys[i]); + t.map.Insert(t.smi(smi_keys[i]), &smi_keys[i]); } for (size_t i = 0; i < arraysize(num_keys); i++) { - t.map.Set(num_keys[i], &num_keys[i]); + t.map.Insert(num_keys[i], &num_keys[i]); } // Simulate a GC by moving SMIs. @@ -514,14 +521,14 @@ TEST(Delete_smi_resizes) { IdentityMapTester t; // Insert one element to initialize map. - t.map.Set(t.smi(0), reinterpret_cast<void*>(kValueOffset)); + t.map.Insert(t.smi(0), reinterpret_cast<void*>(kValueOffset)); int initial_capacity = t.map.capacity(); CHECK_LT(initial_capacity, kKeyCount); // Insert another kKeyCount - 1 keys. for (int i = 1; i < kKeyCount; i++) { - t.map.Set(t.smi(i), reinterpret_cast<void*>(i + kValueOffset)); + t.map.Insert(t.smi(i), reinterpret_cast<void*>(i + kValueOffset)); } // Check capacity increased. @@ -545,10 +552,10 @@ TEST(Iterator_smi_num) { t.num(9.9), t.num(10.1)}; // Initialize the map. for (size_t i = 0; i < arraysize(smi_keys); i++) { - t.map.Set(t.smi(smi_keys[i]), reinterpret_cast<void*>(i)); + t.map.Insert(t.smi(smi_keys[i]), reinterpret_cast<void*>(i)); } for (size_t i = 0; i < arraysize(num_keys); i++) { - t.map.Set(num_keys[i], reinterpret_cast<void*>(i + 5)); + t.map.Insert(num_keys[i], reinterpret_cast<void*>(i + 5)); } // Check iterator sees all values once. @@ -574,10 +581,10 @@ TEST(Iterator_smi_num_gc) { t.num(9.9), t.num(10.1)}; // Initialize the map. for (size_t i = 0; i < arraysize(smi_keys); i++) { - t.map.Set(t.smi(smi_keys[i]), reinterpret_cast<void*>(i)); + t.map.Insert(t.smi(smi_keys[i]), reinterpret_cast<void*>(i)); } for (size_t i = 0; i < arraysize(num_keys); i++) { - t.map.Set(num_keys[i], reinterpret_cast<void*>(i + 5)); + t.map.Insert(num_keys[i], reinterpret_cast<void*>(i + 5)); } // Simulate GC by moving the SMIs. @@ -605,7 +612,7 @@ void IterateCollisionTest(int stride) { HandleScope scope(t.isolate()); int next = 1; for (int i = 0; i < load; i++) { - t.map.Set(t.smi(next), reinterpret_cast<void*>(next)); + t.map.Insert(t.smi(next), reinterpret_cast<void*>(next)); t.CheckFind(t.smi(next), reinterpret_cast<void*>(next)); next = next + stride; } @@ -627,7 +634,7 @@ void IterateCollisionTest(int stride) { for (int i = 0; i < load; i++) { CHECK(seen.find(next) != seen.end()); t.CheckFind(t.smi(next), reinterpret_cast<void*>(next)); - t.CheckGet(t.smi(next), reinterpret_cast<void*>(next)); + t.CheckFindOrInsert(t.smi(next), reinterpret_cast<void*>(next)); next = next + stride; } } @@ -648,7 +655,7 @@ void CollisionTest(int stride, bool rehash = false, bool resize = false) { HandleScope scope(t.isolate()); int next = 1; for (int i = 0; i < load; i++) { - t.map.Set(t.smi(next), reinterpret_cast<void*>(next)); + t.map.Insert(t.smi(next), reinterpret_cast<void*>(next)); t.CheckFind(t.smi(next), reinterpret_cast<void*>(next)); next = next + stride; } @@ -660,7 +667,7 @@ void CollisionTest(int stride, bool rehash = false, bool resize = false) { int next = 1; for (int i = 0; i < load; i++) { t.CheckFind(t.smi(next), reinterpret_cast<void*>(next)); - t.CheckGet(t.smi(next), reinterpret_cast<void*>(next)); + t.CheckFindOrInsert(t.smi(next), reinterpret_cast<void*>(next)); next = next + stride; } } @@ -683,7 +690,7 @@ TEST(ExplicitGC) { // Insert some objects that should be in new space. for (size_t i = 0; i < arraysize(num_keys); i++) { - t.map.Set(num_keys[i], &num_keys[i]); + t.map.Insert(num_keys[i], &num_keys[i]); } // Do an explicit, real GC. @@ -692,7 +699,7 @@ TEST(ExplicitGC) { // Check that searching for the numbers finds the same values. for (size_t i = 0; i < arraysize(num_keys); i++) { t.CheckFind(num_keys[i], &num_keys[i]); - t.CheckGet(num_keys[i], &num_keys[i]); + t.CheckFindOrInsert(num_keys[i], &num_keys[i]); } } @@ -790,7 +797,7 @@ TEST(GCShortCutting) { // greater to capacity_ if not corrected by IdentityMap // (see crbug.com/704132). for (int j = 0; j < i; j++) { - t.map.Set(t.smi(j), reinterpret_cast<void*>(kDummyValue)); + t.map.Insert(t.smi(j), reinterpret_cast<void*>(kDummyValue)); } Handle<String> thin_string = @@ -801,8 +808,8 @@ TEST(GCShortCutting) { DCHECK_NE(*thin_string, *internalized_string); // Insert both keys into the map. - t.map.Set(thin_string, &thin_string); - t.map.Set(internalized_string, &internalized_string); + t.map.Insert(thin_string, &thin_string); + t.map.Insert(internalized_string, &internalized_string); // Do an explicit, real GC, this should short-cut the thin string to point // to the internalized string. @@ -812,16 +819,16 @@ TEST(GCShortCutting) { *thin_string == *internalized_string); // Check that getting the object points to one of the handles. - void** thin_string_entry = t.map.Get(thin_string); + void** thin_string_entry = t.map.Find(thin_string); CHECK(*thin_string_entry == &thin_string || *thin_string_entry == &internalized_string); - void** internalized_string_entry = t.map.Get(internalized_string); + void** internalized_string_entry = t.map.Find(internalized_string); CHECK(*internalized_string_entry == &thin_string || *internalized_string_entry == &internalized_string); // Trigger resize. for (int j = 0; j < 16; j++) { - t.map.Set(t.smi(j + 16), reinterpret_cast<void*>(kDummyValue)); + t.map.Insert(t.smi(j + 16), reinterpret_cast<void*>(kDummyValue)); } t.map.Clear(); } |