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

Side by Side Diff: test/unittests/object-unittest.cc

Issue 2827263004: Fix HashTable growth strategy to be 2x instead of 4x (Closed)
Patch Set: update CSA; fix test Created 3 years, 8 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/mjsunit/ensure-growing-store-learns.js ('k') | tools/dev/gm.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 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 <cmath> 5 #include <cmath>
6 #include <iostream> 6 #include <iostream>
7 #include <limits> 7 #include <limits>
8 8
9 #include "src/objects-inl.h" 9 #include "src/objects-inl.h"
10 #include "src/objects.h" 10 #include "src/objects.h"
11 #include "test/unittests/test-utils.h"
11 12
12 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
13 14
14 namespace v8 { 15 namespace v8 {
15 namespace internal { 16 namespace internal {
16 17
17 TEST(Object, InstanceTypeListOrder) { 18 TEST(Object, InstanceTypeListOrder) {
18 int current = 0; 19 int current = 0;
19 int last = -1; 20 int last = -1;
20 InstanceType current_type = static_cast<InstanceType>(current); 21 InstanceType current_type = static_cast<InstanceType>(current);
(...skipping 25 matching lines...) Expand all
46 EXPECT_EQ(last + 1, current) \ 47 EXPECT_EQ(last + 1, current) \
47 << " STRUCT_LIST is not ordered: " \ 48 << " STRUCT_LIST is not ordered: " \
48 << " last = " << static_cast<InstanceType>(last) \ 49 << " last = " << static_cast<InstanceType>(last) \
49 << " vs. current = " << current_type; \ 50 << " vs. current = " << current_type; \
50 last = current; 51 last = current;
51 52
52 STRUCT_LIST(TEST_STRUCT) 53 STRUCT_LIST(TEST_STRUCT)
53 #undef TEST_STRUCT 54 #undef TEST_STRUCT
54 } 55 }
55 56
57 typedef TestWithIsolate ObjectWithIsolate;
58
59 TEST_F(ObjectWithIsolate, DictionaryGrowth) {
60 Handle<SeededNumberDictionary> dict =
61 SeededNumberDictionary::New(isolate(), 1);
62 Handle<Object> value = isolate()->factory()->null_value();
63 PropertyDetails details = PropertyDetails::Empty();
64
65 // This test documents the expected growth behavior of a dictionary getting
66 // elements added to it one by one.
67 STATIC_ASSERT(HashTableBase::kMinCapacity == 4);
68 uint32_t i = 1;
69 // 3 elements fit into the initial capacity.
70 for (; i <= 3; i++) {
71 dict = SeededNumberDictionary::Add(dict, i, value, details);
72 CHECK_EQ(4, dict->Capacity());
73 }
74 // 4th element triggers growth.
75 DCHECK_EQ(4, i);
76 for (; i <= 5; i++) {
77 dict = SeededNumberDictionary::Add(dict, i, value, details);
78 CHECK_EQ(8, dict->Capacity());
79 }
80 // 6th element triggers growth.
81 DCHECK_EQ(6, i);
82 for (; i <= 11; i++) {
83 dict = SeededNumberDictionary::Add(dict, i, value, details);
84 CHECK_EQ(16, dict->Capacity());
85 }
86 // 12th element triggers growth.
87 DCHECK_EQ(12, i);
88 for (; i <= 21; i++) {
89 dict = SeededNumberDictionary::Add(dict, i, value, details);
90 CHECK_EQ(32, dict->Capacity());
91 }
92 // 22nd element triggers growth.
93 DCHECK_EQ(22, i);
94 for (; i <= 43; i++) {
95 dict = SeededNumberDictionary::Add(dict, i, value, details);
96 CHECK_EQ(64, dict->Capacity());
97 }
98 // 44th element triggers growth.
99 DCHECK_EQ(44, i);
100 for (; i <= 50; i++) {
101 dict = SeededNumberDictionary::Add(dict, i, value, details);
102 CHECK_EQ(128, dict->Capacity());
103 }
104
105 // If we grow by larger chunks, the next (sufficiently big) power of 2 is
106 // chosen as the capacity.
107 dict = SeededNumberDictionary::New(isolate(), 1);
108 dict = SeededNumberDictionary::EnsureCapacity(dict, 65, 1);
109 CHECK_EQ(128, dict->Capacity());
110
111 dict = SeededNumberDictionary::New(isolate(), 1);
112 dict = SeededNumberDictionary::EnsureCapacity(dict, 30, 1);
113 CHECK_EQ(64, dict->Capacity());
114 }
115
56 } // namespace internal 116 } // namespace internal
57 } // namespace v8 117 } // namespace v8
OLDNEW
« no previous file with comments | « test/mjsunit/ensure-growing-store-learns.js ('k') | tools/dev/gm.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698