OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 key = global_handles->Create(*object); | 82 key = global_handles->Create(*object); |
83 } | 83 } |
84 CHECK(!global_handles->IsWeak(key.location())); | 84 CHECK(!global_handles->IsWeak(key.location())); |
85 | 85 |
86 // Put two chained entries into weak map. | 86 // Put two chained entries into weak map. |
87 { | 87 { |
88 HandleScope scope(isolate); | 88 HandleScope scope(isolate); |
89 Handle<Map> map = factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); | 89 Handle<Map> map = factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); |
90 Handle<JSObject> object = factory->NewJSObjectFromMap(map); | 90 Handle<JSObject> object = factory->NewJSObjectFromMap(map); |
91 Handle<Smi> smi(Smi::FromInt(23), isolate); | 91 Handle<Smi> smi(Smi::FromInt(23), isolate); |
92 Runtime::WeakCollectionSet(weakmap, key, object); | 92 int32_t hash = Object::GetOrCreateHash(isolate, key)->value(); |
93 Runtime::WeakCollectionSet(weakmap, object, smi); | 93 Runtime::WeakCollectionSet(weakmap, key, object, hash); |
| 94 int32_t object_hash = Object::GetOrCreateHash(isolate, object)->value(); |
| 95 Runtime::WeakCollectionSet(weakmap, object, smi, object_hash); |
94 } | 96 } |
95 CHECK_EQ(2, ObjectHashTable::cast(weakmap->table())->NumberOfElements()); | 97 CHECK_EQ(2, ObjectHashTable::cast(weakmap->table())->NumberOfElements()); |
96 | 98 |
97 // Force a full GC. | 99 // Force a full GC. |
98 heap->CollectAllGarbage(false); | 100 heap->CollectAllGarbage(false); |
99 CHECK_EQ(0, NumberOfWeakCalls); | 101 CHECK_EQ(0, NumberOfWeakCalls); |
100 CHECK_EQ(2, ObjectHashTable::cast(weakmap->table())->NumberOfElements()); | 102 CHECK_EQ(2, ObjectHashTable::cast(weakmap->table())->NumberOfElements()); |
101 CHECK_EQ( | 103 CHECK_EQ( |
102 0, ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements()); | 104 0, ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements()); |
103 | 105 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 // Check initial capacity. | 140 // Check initial capacity. |
139 CHECK_EQ(32, ObjectHashTable::cast(weakmap->table())->Capacity()); | 141 CHECK_EQ(32, ObjectHashTable::cast(weakmap->table())->Capacity()); |
140 | 142 |
141 // Fill up weak map to trigger capacity change. | 143 // Fill up weak map to trigger capacity change. |
142 { | 144 { |
143 HandleScope scope(isolate); | 145 HandleScope scope(isolate); |
144 Handle<Map> map = factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); | 146 Handle<Map> map = factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); |
145 for (int i = 0; i < 32; i++) { | 147 for (int i = 0; i < 32; i++) { |
146 Handle<JSObject> object = factory->NewJSObjectFromMap(map); | 148 Handle<JSObject> object = factory->NewJSObjectFromMap(map); |
147 Handle<Smi> smi(Smi::FromInt(i), isolate); | 149 Handle<Smi> smi(Smi::FromInt(i), isolate); |
148 Runtime::WeakCollectionSet(weakmap, object, smi); | 150 int32_t object_hash = Object::GetOrCreateHash(isolate, object)->value(); |
| 151 Runtime::WeakCollectionSet(weakmap, object, smi, object_hash); |
149 } | 152 } |
150 } | 153 } |
151 | 154 |
152 // Check increased capacity. | 155 // Check increased capacity. |
153 CHECK_EQ(128, ObjectHashTable::cast(weakmap->table())->Capacity()); | 156 CHECK_EQ(128, ObjectHashTable::cast(weakmap->table())->Capacity()); |
154 | 157 |
155 // Force a full GC. | 158 // Force a full GC. |
156 CHECK_EQ(32, ObjectHashTable::cast(weakmap->table())->NumberOfElements()); | 159 CHECK_EQ(32, ObjectHashTable::cast(weakmap->table())->NumberOfElements()); |
157 CHECK_EQ( | 160 CHECK_EQ( |
158 0, ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements()); | 161 0, ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements()); |
(...skipping 27 matching lines...) Expand all Loading... |
186 int dummy_array_size = Page::kMaxRegularHeapObjectSize - 92 * KB; | 189 int dummy_array_size = Page::kMaxRegularHeapObjectSize - 92 * KB; |
187 factory->NewFixedArray(dummy_array_size / kPointerSize, TENURED); | 190 factory->NewFixedArray(dummy_array_size / kPointerSize, TENURED); |
188 | 191 |
189 // Fill up weak map with values on an evacuation candidate. | 192 // Fill up weak map with values on an evacuation candidate. |
190 { | 193 { |
191 HandleScope scope(isolate); | 194 HandleScope scope(isolate); |
192 for (int i = 0; i < 32; i++) { | 195 for (int i = 0; i < 32; i++) { |
193 Handle<JSObject> object = factory->NewJSObject(function, TENURED); | 196 Handle<JSObject> object = factory->NewJSObject(function, TENURED); |
194 CHECK(!heap->InNewSpace(object->address())); | 197 CHECK(!heap->InNewSpace(object->address())); |
195 CHECK(!first_page->Contains(object->address())); | 198 CHECK(!first_page->Contains(object->address())); |
196 Runtime::WeakCollectionSet(weakmap, key, object); | 199 int32_t hash = Object::GetOrCreateHash(isolate, key)->value(); |
| 200 Runtime::WeakCollectionSet(weakmap, key, object, hash); |
197 } | 201 } |
198 } | 202 } |
199 | 203 |
200 // Force compacting garbage collection. | 204 // Force compacting garbage collection. |
201 CHECK(FLAG_always_compact); | 205 CHECK(FLAG_always_compact); |
202 heap->CollectAllGarbage(); | 206 heap->CollectAllGarbage(); |
203 } | 207 } |
204 | 208 |
205 | 209 |
206 // Test that weak map keys on an evacuation candidate which are reachable by | 210 // Test that weak map keys on an evacuation candidate which are reachable by |
(...skipping 21 matching lines...) Expand all Loading... |
228 // Fill up weak map with keys on an evacuation candidate. | 232 // Fill up weak map with keys on an evacuation candidate. |
229 Handle<JSObject> keys[32]; | 233 Handle<JSObject> keys[32]; |
230 for (int i = 0; i < 32; i++) { | 234 for (int i = 0; i < 32; i++) { |
231 keys[i] = factory->NewJSObject(function, TENURED); | 235 keys[i] = factory->NewJSObject(function, TENURED); |
232 CHECK(!heap->InNewSpace(keys[i]->address())); | 236 CHECK(!heap->InNewSpace(keys[i]->address())); |
233 CHECK(!first_page->Contains(keys[i]->address())); | 237 CHECK(!first_page->Contains(keys[i]->address())); |
234 } | 238 } |
235 Handle<JSWeakMap> weakmap = AllocateJSWeakMap(isolate); | 239 Handle<JSWeakMap> weakmap = AllocateJSWeakMap(isolate); |
236 for (int i = 0; i < 32; i++) { | 240 for (int i = 0; i < 32; i++) { |
237 Handle<Smi> smi(Smi::FromInt(i), isolate); | 241 Handle<Smi> smi(Smi::FromInt(i), isolate); |
238 Runtime::WeakCollectionSet(weakmap, keys[i], smi); | 242 int32_t hash = Object::GetOrCreateHash(isolate, keys[i])->value(); |
| 243 Runtime::WeakCollectionSet(weakmap, keys[i], smi, hash); |
239 } | 244 } |
240 | 245 |
241 // Force compacting garbage collection. The subsequent collections are used | 246 // Force compacting garbage collection. The subsequent collections are used |
242 // to verify that key references were actually updated. | 247 // to verify that key references were actually updated. |
243 CHECK(FLAG_always_compact); | 248 CHECK(FLAG_always_compact); |
244 heap->CollectAllGarbage(); | 249 heap->CollectAllGarbage(); |
245 heap->CollectAllGarbage(); | 250 heap->CollectAllGarbage(); |
246 heap->CollectAllGarbage(); | 251 heap->CollectAllGarbage(); |
247 } | 252 } |
248 | 253 |
249 | 254 |
250 TEST(Regress399527) { | 255 TEST(Regress399527) { |
251 CcTest::InitializeVM(); | 256 CcTest::InitializeVM(); |
252 v8::HandleScope scope(CcTest::isolate()); | 257 v8::HandleScope scope(CcTest::isolate()); |
253 Isolate* isolate = CcTest::i_isolate(); | 258 Isolate* isolate = CcTest::i_isolate(); |
254 Heap* heap = isolate->heap(); | 259 Heap* heap = isolate->heap(); |
255 { | 260 { |
256 HandleScope scope(isolate); | 261 HandleScope scope(isolate); |
257 AllocateJSWeakMap(isolate); | 262 AllocateJSWeakMap(isolate); |
258 SimulateIncrementalMarking(heap); | 263 SimulateIncrementalMarking(heap); |
259 } | 264 } |
260 // The weak map is marked black here but leaving the handle scope will make | 265 // The weak map is marked black here but leaving the handle scope will make |
261 // the object unreachable. Aborting incremental marking will clear all the | 266 // the object unreachable. Aborting incremental marking will clear all the |
262 // marking bits which makes the weak map garbage. | 267 // marking bits which makes the weak map garbage. |
263 heap->CollectAllGarbage(); | 268 heap->CollectAllGarbage(); |
264 } | 269 } |
OLD | NEW |