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

Side by Side Diff: test/cctest/test-ordered-hash-table.cc

Issue 220293002: OrderedHashTable implementation with Set and Map interfaces (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 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 | Annotate | Revision Log
« src/objects.cc ('K') | « test/cctest/cctest.gyp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #include <stdlib.h>
29
28 #include "v8.h" 30 #include "v8.h"
29 31
30 #include "api.h" 32 #include "cctest.h"
31 #include "debug.h"
32 #include "execution.h"
33 #include "factory.h" 33 #include "factory.h"
34 #include "macro-assembler.h" 34
35 #include "objects.h" 35 namespace {
36 #include "global-handles.h"
37 #include "cctest.h"
38 36
39 using namespace v8::internal; 37 using namespace v8::internal;
40 38
39 TEST(Set) {
40 LocalContext context;
41 Isolate* isolate = CcTest::i_isolate();
42 Factory* factory = isolate->factory();
43 HandleScope scope(isolate);
44 Handle<OrderedHashSet> ordered_set = factory->NewOrderedHashSet();
45 CHECK_EQ(2, ordered_set->NumberOfBuckets());
46 CHECK_EQ(0, ordered_set->NumberOfElements());
47 CHECK_EQ(0, ordered_set->NumberOfDeletedElements());
48
49 Handle<Map> map = factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
50 Handle<JSObject> obj = factory->NewJSObjectFromMap(map);
51 CHECK(!ordered_set->Contains(*obj));
52 ordered_set = OrderedHashSet::Add(ordered_set, obj);
53 CHECK_EQ(1, ordered_set->NumberOfElements());
54 CHECK(ordered_set->Contains(*obj));
55 ordered_set = OrderedHashSet::Remove(ordered_set, obj);
56 CHECK_EQ(0, ordered_set->NumberOfElements());
57 CHECK(!ordered_set->Contains(*obj));
58
59 // Test for collisions/chaining
60 Handle<JSObject> obj1 = factory->NewJSObjectFromMap(map);
61 ordered_set = OrderedHashSet::Add(ordered_set, obj1);
62 Handle<JSObject> obj2 = factory->NewJSObjectFromMap(map);
63 ordered_set = OrderedHashSet::Add(ordered_set, obj2);
64 Handle<JSObject> obj3 = factory->NewJSObjectFromMap(map);
65 ordered_set = OrderedHashSet::Add(ordered_set, obj3);
66 CHECK_EQ(3, ordered_set->NumberOfElements());
67 CHECK(ordered_set->Contains(*obj1));
68 CHECK(ordered_set->Contains(*obj2));
69 CHECK(ordered_set->Contains(*obj3));
70
71 // Test growth
72 ordered_set = OrderedHashSet::Add(ordered_set, obj);
73 Handle<JSObject> obj4 = factory->NewJSObjectFromMap(map);
74 ordered_set = OrderedHashSet::Add(ordered_set, obj4);
75 CHECK(ordered_set->Contains(*obj));
76 CHECK(ordered_set->Contains(*obj1));
77 CHECK(ordered_set->Contains(*obj2));
78 CHECK(ordered_set->Contains(*obj3));
79 CHECK(ordered_set->Contains(*obj4));
80 CHECK_EQ(5, ordered_set->NumberOfElements());
81 CHECK_EQ(0, ordered_set->NumberOfDeletedElements());
82 CHECK_EQ(4, ordered_set->NumberOfBuckets());
83
84 // Test shrinking
85 ordered_set = OrderedHashSet::Remove(ordered_set, obj);
86 ordered_set = OrderedHashSet::Remove(ordered_set, obj1);
87 ordered_set = OrderedHashSet::Remove(ordered_set, obj2);
88 ordered_set = OrderedHashSet::Remove(ordered_set, obj3);
89 CHECK_EQ(1, ordered_set->NumberOfElements());
90 CHECK_EQ(2, ordered_set->NumberOfBuckets());
91 }
92
93
94 TEST(Map) {
95 LocalContext context;
96 Isolate* isolate = CcTest::i_isolate();
97 Factory* factory = isolate->factory();
98 HandleScope scope(isolate);
99 Handle<OrderedHashMap> ordered_map = factory->NewOrderedHashMap();
100 CHECK_EQ(2, ordered_map->NumberOfBuckets());
101 CHECK_EQ(0, ordered_map->NumberOfElements());
102 CHECK_EQ(0, ordered_map->NumberOfDeletedElements());
103
104 Handle<Map> map = factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
105 Handle<JSObject> obj = factory->NewJSObjectFromMap(map);
106 Handle<JSObject> val = factory->NewJSObjectFromMap(map);
107 CHECK(ordered_map->Lookup(*obj)->IsTheHole());
108 ordered_map = OrderedHashMap::Put(ordered_map, obj, val);
109 CHECK_EQ(1, ordered_map->NumberOfElements());
110 CHECK(ordered_map->Lookup(*obj)->SameValue(*val));
111 ordered_map = OrderedHashMap::Put(
112 ordered_map, obj, factory->the_hole_value());
113 CHECK_EQ(0, ordered_map->NumberOfElements());
114 CHECK(ordered_map->Lookup(*obj)->IsTheHole());
115
116 // Test for collisions/chaining
117 Handle<JSObject> obj1 = factory->NewJSObjectFromMap(map);
118 Handle<JSObject> obj2 = factory->NewJSObjectFromMap(map);
119 Handle<JSObject> obj3 = factory->NewJSObjectFromMap(map);
120 Handle<JSObject> val1 = factory->NewJSObjectFromMap(map);
121 Handle<JSObject> val2 = factory->NewJSObjectFromMap(map);
122 Handle<JSObject> val3 = factory->NewJSObjectFromMap(map);
123 ordered_map = OrderedHashMap::Put(ordered_map, obj1, val1);
124 ordered_map = OrderedHashMap::Put(ordered_map, obj2, val2);
125 ordered_map = OrderedHashMap::Put(ordered_map, obj3, val3);
126 CHECK_EQ(3, ordered_map->NumberOfElements());
127 CHECK(ordered_map->Lookup(*obj1)->SameValue(*val1));
128 CHECK(ordered_map->Lookup(*obj2)->SameValue(*val2));
129 CHECK(ordered_map->Lookup(*obj3)->SameValue(*val3));
130
131 // Test growth
132 ordered_map = OrderedHashMap::Put(ordered_map, obj, val);
133 Handle<JSObject> obj4 = factory->NewJSObjectFromMap(map);
134 Handle<JSObject> val4 = factory->NewJSObjectFromMap(map);
135 ordered_map = OrderedHashMap::Put(ordered_map, obj4, val4);
136 CHECK(ordered_map->Lookup(*obj)->SameValue(*val));
137 CHECK(ordered_map->Lookup(*obj1)->SameValue(*val1));
138 CHECK(ordered_map->Lookup(*obj2)->SameValue(*val2));
139 CHECK(ordered_map->Lookup(*obj3)->SameValue(*val3));
140 CHECK(ordered_map->Lookup(*obj4)->SameValue(*val4));
141 CHECK_EQ(5, ordered_map->NumberOfElements());
142 CHECK_EQ(4, ordered_map->NumberOfBuckets());
143
144 // Test shrinking
145 ordered_map = OrderedHashMap::Put(
146 ordered_map, obj, factory->the_hole_value());
147 ordered_map = OrderedHashMap::Put(
148 ordered_map, obj1, factory->the_hole_value());
149 ordered_map = OrderedHashMap::Put(
150 ordered_map, obj2, factory->the_hole_value());
151 ordered_map = OrderedHashMap::Put(
152 ordered_map, obj3, factory->the_hole_value());
153 CHECK_EQ(1, ordered_map->NumberOfElements());
154 CHECK_EQ(2, ordered_map->NumberOfBuckets());
155 }
156
157
158 // BELOW THIS LINE TESTS WERE CONVERTED FROM test-dictionary.cc
Michael Starzinger 2014/04/02 12:09:37 It would be nice if we could avoid duplicating the
adamk 2014/04/02 22:01:10 Yeah, should be able to take care of this, will lo
159
41 160
42 TEST(ObjectHashTable) { 161 TEST(ObjectHashTable) {
43 LocalContext context; 162 LocalContext context;
44 Isolate* isolate = CcTest::i_isolate(); 163 Isolate* isolate = CcTest::i_isolate();
45 Factory* factory = isolate->factory(); 164 Factory* factory = isolate->factory();
46 v8::HandleScope scope(context->GetIsolate()); 165 v8::HandleScope scope(context->GetIsolate());
47 Handle<ObjectHashTable> table = factory->NewObjectHashTable(23); 166 Handle<OrderedHashMap> table = factory->NewOrderedHashMap();
48 Handle<JSObject> a = factory->NewJSArray(7); 167 Handle<JSObject> a = factory->NewJSArray(7);
49 Handle<JSObject> b = factory->NewJSArray(11); 168 Handle<JSObject> b = factory->NewJSArray(11);
50 table = ObjectHashTable::Put(table, a, b); 169 table = OrderedHashMap::Put(table, a, b);
51 CHECK_EQ(table->NumberOfElements(), 1); 170 CHECK_EQ(table->NumberOfElements(), 1);
52 CHECK_EQ(table->Lookup(*a), *b); 171 CHECK_EQ(table->Lookup(*a), *b);
53 CHECK_EQ(table->Lookup(*b), CcTest::heap()->the_hole_value()); 172 CHECK_EQ(table->Lookup(*b), CcTest::heap()->the_hole_value());
54 173
55 // Keys still have to be valid after objects were moved. 174 // Keys still have to be valid after objects were moved.
56 CcTest::heap()->CollectGarbage(NEW_SPACE); 175 CcTest::heap()->CollectGarbage(NEW_SPACE);
57 CHECK_EQ(table->NumberOfElements(), 1); 176 CHECK_EQ(table->NumberOfElements(), 1);
58 CHECK_EQ(table->Lookup(*a), *b); 177 CHECK_EQ(table->Lookup(*a), *b);
59 CHECK_EQ(table->Lookup(*b), CcTest::heap()->the_hole_value()); 178 CHECK_EQ(table->Lookup(*b), CcTest::heap()->the_hole_value());
60 179
61 // Keys that are overwritten should not change number of elements. 180 // Keys that are overwritten should not change number of elements.
62 table = ObjectHashTable::Put(table, a, factory->NewJSArray(13)); 181 table = OrderedHashMap::Put(table, a, factory->NewJSArray(13));
63 CHECK_EQ(table->NumberOfElements(), 1); 182 CHECK_EQ(table->NumberOfElements(), 1);
64 CHECK_NE(table->Lookup(*a), *b); 183 CHECK_NE(table->Lookup(*a), *b);
65 184
66 // Keys mapped to the hole should be removed permanently. 185 // Keys mapped to the hole should be removed permanently.
67 table = ObjectHashTable::Put(table, a, factory->the_hole_value()); 186 table = OrderedHashMap::Put(table, a, factory->the_hole_value());
68 CHECK_EQ(table->NumberOfElements(), 0); 187 CHECK_EQ(table->NumberOfElements(), 0);
69 CHECK_EQ(table->NumberOfDeletedElements(), 1);
70 CHECK_EQ(table->Lookup(*a), CcTest::heap()->the_hole_value()); 188 CHECK_EQ(table->Lookup(*a), CcTest::heap()->the_hole_value());
71 189
72 // Keys should map back to their respective values and also should get 190 // Keys should map back to their respective values and also should get
73 // an identity hash code generated. 191 // an identity hash code generated.
74 for (int i = 0; i < 100; i++) { 192 for (int i = 0; i < 100; i++) {
75 Handle<JSReceiver> key = factory->NewJSArray(7); 193 Handle<JSReceiver> key = factory->NewJSArray(7);
76 Handle<JSObject> value = factory->NewJSArray(11); 194 Handle<JSObject> value = factory->NewJSArray(11);
77 table = ObjectHashTable::Put(table, key, value); 195 table = OrderedHashMap::Put(table, key, value);
78 CHECK_EQ(table->NumberOfElements(), i + 1); 196 CHECK_EQ(table->NumberOfElements(), i + 1);
79 CHECK_NE(table->FindEntry(*key), ObjectHashTable::kNotFound); 197 CHECK_NE(table->FindEntry(*key), OrderedHashMap::kNotFound);
80 CHECK_EQ(table->Lookup(*key), *value); 198 CHECK_EQ(table->Lookup(*key), *value);
81 CHECK(key->GetIdentityHash()->IsSmi()); 199 CHECK(key->GetIdentityHash()->IsSmi());
82 } 200 }
83 201
84 // Keys never added to the map which already have an identity hash 202 // Keys never added to the map which already have an identity hash
85 // code should not be found. 203 // code should not be found.
86 for (int i = 0; i < 100; i++) { 204 for (int i = 0; i < 100; i++) {
87 Handle<JSReceiver> key = factory->NewJSArray(7); 205 Handle<JSReceiver> key = factory->NewJSArray(7);
88 CHECK(JSReceiver::GetOrCreateIdentityHash(key)->IsSmi()); 206 CHECK(JSReceiver::GetOrCreateIdentityHash(key)->IsSmi());
89 CHECK_EQ(table->FindEntry(*key), ObjectHashTable::kNotFound); 207 CHECK_EQ(table->FindEntry(*key), OrderedHashMap::kNotFound);
90 CHECK_EQ(table->Lookup(*key), CcTest::heap()->the_hole_value()); 208 CHECK_EQ(table->Lookup(*key), CcTest::heap()->the_hole_value());
91 CHECK(key->GetIdentityHash()->IsSmi()); 209 CHECK(key->GetIdentityHash()->IsSmi());
92 } 210 }
93 211
94 // Keys that don't have an identity hash should not be found and also 212 // Keys that don't have an identity hash should not be found and also
95 // should not get an identity hash code generated. 213 // should not get an identity hash code generated.
96 for (int i = 0; i < 100; i++) { 214 for (int i = 0; i < 100; i++) {
97 Handle<JSReceiver> key = factory->NewJSArray(7); 215 Handle<JSReceiver> key = factory->NewJSArray(7);
98 CHECK_EQ(table->Lookup(*key), CcTest::heap()->the_hole_value()); 216 CHECK_EQ(table->Lookup(*key), CcTest::heap()->the_hole_value());
99 CHECK_EQ(key->GetIdentityHash(), 217 CHECK_EQ(key->GetIdentityHash(),
100 CcTest::heap()->undefined_value()); 218 CcTest::heap()->undefined_value());
101 } 219 }
102 } 220 }
103 221
104 222
105 class ObjectHashTableTest: public ObjectHashTable {
106 public:
107 void insert(int entry, int key, int value) {
108 set(EntryToIndex(entry), Smi::FromInt(key));
109 set(EntryToIndex(entry) + 1, Smi::FromInt(value));
110 }
111
112 int lookup(int key) {
113 return Smi::cast(Lookup(Smi::FromInt(key)))->value();
114 }
115
116 int capacity() {
117 return Capacity();
118 }
119 };
120
121
122 TEST(HashTableRehash) {
123 LocalContext context;
124 Isolate* isolate = CcTest::i_isolate();
125 Factory* factory = isolate->factory();
126 v8::HandleScope scope(context->GetIsolate());
127 // Test almost filled table.
128 {
129 Handle<ObjectHashTable> table = factory->NewObjectHashTable(100);
130 ObjectHashTableTest* t = reinterpret_cast<ObjectHashTableTest*>(*table);
131 int capacity = t->capacity();
132 for (int i = 0; i < capacity - 1; i++) {
133 t->insert(i, i * i, i);
134 }
135 t->Rehash(Smi::FromInt(0));
136 for (int i = 0; i < capacity - 1; i++) {
137 CHECK_EQ(i, t->lookup(i * i));
138 }
139 }
140 // Test half-filled table.
141 {
142 Handle<ObjectHashTable> table = factory->NewObjectHashTable(100);
143 ObjectHashTableTest* t = reinterpret_cast<ObjectHashTableTest*>(*table);
144 int capacity = t->capacity();
145 for (int i = 0; i < capacity / 2; i++) {
146 t->insert(i, i * i, i);
147 }
148 t->Rehash(Smi::FromInt(0));
149 for (int i = 0; i < capacity / 2; i++) {
150 CHECK_EQ(i, t->lookup(i * i));
151 }
152 }
153 }
154
155
156 #ifdef DEBUG 223 #ifdef DEBUG
157 TEST(ObjectHashSetCausesGC) { 224 TEST(OrderedHashSetCausesGC) {
158 i::FLAG_stress_compaction = false; 225 i::FLAG_stress_compaction = false;
159 LocalContext context; 226 LocalContext context;
160 Isolate* isolate = CcTest::i_isolate(); 227 Isolate* isolate = CcTest::i_isolate();
161 Factory* factory = isolate->factory(); 228 Factory* factory = isolate->factory();
162 v8::HandleScope scope(context->GetIsolate()); 229 v8::HandleScope scope(context->GetIsolate());
163 Handle<ObjectHashSet> table = factory->NewObjectHashSet(1); 230 Handle<OrderedHashSet> table = factory->NewOrderedHashSet();
164 Handle<JSObject> key = factory->NewJSArray(0); 231 Handle<JSObject> key = factory->NewJSArray(0);
165 v8::Handle<v8::Object> key_obj = v8::Utils::ToLocal(key); 232 v8::Handle<v8::Object> key_obj = v8::Utils::ToLocal(key);
166 233
167 // Force allocation of hash table backing store for hidden properties. 234 // Force allocation of hash table backing store for hidden properties.
168 key_obj->SetHiddenValue(v8_str("key 1"), v8_str("val 1")); 235 key_obj->SetHiddenValue(v8_str("key 1"), v8_str("val 1"));
169 key_obj->SetHiddenValue(v8_str("key 2"), v8_str("val 2")); 236 key_obj->SetHiddenValue(v8_str("key 2"), v8_str("val 2"));
170 key_obj->SetHiddenValue(v8_str("key 3"), v8_str("val 3")); 237 key_obj->SetHiddenValue(v8_str("key 3"), v8_str("val 3"));
171 238
172 // Simulate a full heap so that generating an identity hash code 239 // Simulate a full heap so that generating an identity hash code
173 // in subsequent calls will request GC. 240 // in subsequent calls will request GC.
174 SimulateFullSpace(CcTest::heap()->new_space()); 241 SimulateFullSpace(CcTest::heap()->new_space());
175 SimulateFullSpace(CcTest::heap()->old_pointer_space()); 242 SimulateFullSpace(CcTest::heap()->old_pointer_space());
176 243
177 // Calling Contains() should not cause GC ever. 244 // Calling Contains() should not cause GC ever.
178 int gc_count = isolate->heap()->gc_count(); 245 int gc_count = isolate->heap()->gc_count();
179 CHECK(!table->Contains(*key)); 246 CHECK(!table->Contains(*key));
180 CHECK(gc_count == isolate->heap()->gc_count()); 247 CHECK(gc_count == isolate->heap()->gc_count());
181 248
182 // Calling Remove() will not cause GC in this case. 249 // Calling Remove() will not cause GC in this case.
183 table = ObjectHashSet::Remove(table, key); 250 table = OrderedHashSet::Remove(table, key);
184 CHECK(gc_count == isolate->heap()->gc_count()); 251 CHECK(gc_count == isolate->heap()->gc_count());
185 252
186 // Calling Add() should cause GC. 253 // Calling Add() should cause GC.
187 table = ObjectHashSet::Add(table, key); 254 table = OrderedHashSet::Add(table, key);
188 CHECK(gc_count < isolate->heap()->gc_count()); 255 CHECK(gc_count < isolate->heap()->gc_count());
189 } 256 }
190 #endif 257 #endif
191 258
192 259
193 #ifdef DEBUG 260 #ifdef DEBUG
194 TEST(ObjectHashTableCausesGC) { 261 TEST(OrderedHashMapCausesGC) {
195 i::FLAG_stress_compaction = false; 262 i::FLAG_stress_compaction = false;
196 LocalContext context; 263 LocalContext context;
197 Isolate* isolate = CcTest::i_isolate(); 264 Isolate* isolate = CcTest::i_isolate();
198 Factory* factory = isolate->factory(); 265 Factory* factory = isolate->factory();
199 v8::HandleScope scope(context->GetIsolate()); 266 v8::HandleScope scope(context->GetIsolate());
200 Handle<ObjectHashTable> table = factory->NewObjectHashTable(1); 267 Handle<OrderedHashMap> table = factory->NewOrderedHashMap();
201 Handle<JSObject> key = factory->NewJSArray(0); 268 Handle<JSObject> key = factory->NewJSArray(0);
202 v8::Handle<v8::Object> key_obj = v8::Utils::ToLocal(key); 269 v8::Handle<v8::Object> key_obj = v8::Utils::ToLocal(key);
203 270
204 // Force allocation of hash table backing store for hidden properties. 271 // Force allocation of hash table backing store for hidden properties.
205 key_obj->SetHiddenValue(v8_str("key 1"), v8_str("val 1")); 272 key_obj->SetHiddenValue(v8_str("key 1"), v8_str("val 1"));
206 key_obj->SetHiddenValue(v8_str("key 2"), v8_str("val 2")); 273 key_obj->SetHiddenValue(v8_str("key 2"), v8_str("val 2"));
207 key_obj->SetHiddenValue(v8_str("key 3"), v8_str("val 3")); 274 key_obj->SetHiddenValue(v8_str("key 3"), v8_str("val 3"));
208 275
209 // Simulate a full heap so that generating an identity hash code 276 // Simulate a full heap so that generating an identity hash code
210 // in subsequent calls will request GC. 277 // in subsequent calls will request GC.
211 SimulateFullSpace(CcTest::heap()->new_space()); 278 SimulateFullSpace(CcTest::heap()->new_space());
212 SimulateFullSpace(CcTest::heap()->old_pointer_space()); 279 SimulateFullSpace(CcTest::heap()->old_pointer_space());
213 280
214 // Calling Lookup() should not cause GC ever. 281 // Calling Lookup() should not cause GC ever.
215 CHECK(table->Lookup(*key)->IsTheHole()); 282 CHECK(table->Lookup(*key)->IsTheHole());
216 283
217 // Calling Put() should request GC by returning a failure. 284 // Calling Put() should request GC by returning a failure.
218 int gc_count = isolate->heap()->gc_count(); 285 int gc_count = isolate->heap()->gc_count();
219 ObjectHashTable::Put(table, key, key); 286 OrderedHashMap::Put(table, key, key);
220 CHECK(gc_count < isolate->heap()->gc_count()); 287 CHECK(gc_count < isolate->heap()->gc_count());
221 } 288 }
222 #endif 289 #endif
290
291 }
OLDNEW
« src/objects.cc ('K') | « test/cctest/cctest.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698