| 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 Handle<Map> map = factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); | 83 Handle<Map> map = factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); |
| 84 Handle<JSObject> object = factory->NewJSObjectFromMap(map); | 84 Handle<JSObject> object = factory->NewJSObjectFromMap(map); |
| 85 key = global_handles->Create(*object); | 85 key = global_handles->Create(*object); |
| 86 } | 86 } |
| 87 CHECK(!global_handles->IsWeak(key.location())); | 87 CHECK(!global_handles->IsWeak(key.location())); |
| 88 | 88 |
| 89 // Put entry into weak set. | 89 // Put entry into weak set. |
| 90 { | 90 { |
| 91 HandleScope scope(isolate); | 91 HandleScope scope(isolate); |
| 92 Handle<Smi> smi(Smi::FromInt(23), isolate); | 92 Handle<Smi> smi(Smi::FromInt(23), isolate); |
| 93 Runtime::WeakCollectionSet(weakset, key, smi); | 93 int32_t hash = Object::GetOrCreateHash(isolate, key)->value(); |
| 94 Runtime::WeakCollectionSet(weakset, key, smi, hash); |
| 94 } | 95 } |
| 95 CHECK_EQ(1, ObjectHashTable::cast(weakset->table())->NumberOfElements()); | 96 CHECK_EQ(1, ObjectHashTable::cast(weakset->table())->NumberOfElements()); |
| 96 | 97 |
| 97 // Force a full GC. | 98 // Force a full GC. |
| 98 heap->CollectAllGarbage(false); | 99 heap->CollectAllGarbage(false); |
| 99 CHECK_EQ(0, NumberOfWeakCalls); | 100 CHECK_EQ(0, NumberOfWeakCalls); |
| 100 CHECK_EQ(1, ObjectHashTable::cast(weakset->table())->NumberOfElements()); | 101 CHECK_EQ(1, ObjectHashTable::cast(weakset->table())->NumberOfElements()); |
| 101 CHECK_EQ( | 102 CHECK_EQ( |
| 102 0, ObjectHashTable::cast(weakset->table())->NumberOfDeletedElements()); | 103 0, ObjectHashTable::cast(weakset->table())->NumberOfDeletedElements()); |
| 103 | 104 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 // Check initial capacity. | 139 // Check initial capacity. |
| 139 CHECK_EQ(32, ObjectHashTable::cast(weakset->table())->Capacity()); | 140 CHECK_EQ(32, ObjectHashTable::cast(weakset->table())->Capacity()); |
| 140 | 141 |
| 141 // Fill up weak set to trigger capacity change. | 142 // Fill up weak set to trigger capacity change. |
| 142 { | 143 { |
| 143 HandleScope scope(isolate); | 144 HandleScope scope(isolate); |
| 144 Handle<Map> map = factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); | 145 Handle<Map> map = factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); |
| 145 for (int i = 0; i < 32; i++) { | 146 for (int i = 0; i < 32; i++) { |
| 146 Handle<JSObject> object = factory->NewJSObjectFromMap(map); | 147 Handle<JSObject> object = factory->NewJSObjectFromMap(map); |
| 147 Handle<Smi> smi(Smi::FromInt(i), isolate); | 148 Handle<Smi> smi(Smi::FromInt(i), isolate); |
| 148 Runtime::WeakCollectionSet(weakset, object, smi); | 149 int32_t hash = Object::GetOrCreateHash(isolate, object)->value(); |
| 150 Runtime::WeakCollectionSet(weakset, object, smi, hash); |
| 149 } | 151 } |
| 150 } | 152 } |
| 151 | 153 |
| 152 // Check increased capacity. | 154 // Check increased capacity. |
| 153 CHECK_EQ(128, ObjectHashTable::cast(weakset->table())->Capacity()); | 155 CHECK_EQ(128, ObjectHashTable::cast(weakset->table())->Capacity()); |
| 154 | 156 |
| 155 // Force a full GC. | 157 // Force a full GC. |
| 156 CHECK_EQ(32, ObjectHashTable::cast(weakset->table())->NumberOfElements()); | 158 CHECK_EQ(32, ObjectHashTable::cast(weakset->table())->NumberOfElements()); |
| 157 CHECK_EQ( | 159 CHECK_EQ( |
| 158 0, ObjectHashTable::cast(weakset->table())->NumberOfDeletedElements()); | 160 0, ObjectHashTable::cast(weakset->table())->NumberOfDeletedElements()); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 186 int dummy_array_size = Page::kMaxRegularHeapObjectSize - 92 * KB; | 188 int dummy_array_size = Page::kMaxRegularHeapObjectSize - 92 * KB; |
| 187 factory->NewFixedArray(dummy_array_size / kPointerSize, TENURED); | 189 factory->NewFixedArray(dummy_array_size / kPointerSize, TENURED); |
| 188 | 190 |
| 189 // Fill up weak set with values on an evacuation candidate. | 191 // Fill up weak set with values on an evacuation candidate. |
| 190 { | 192 { |
| 191 HandleScope scope(isolate); | 193 HandleScope scope(isolate); |
| 192 for (int i = 0; i < 32; i++) { | 194 for (int i = 0; i < 32; i++) { |
| 193 Handle<JSObject> object = factory->NewJSObject(function, TENURED); | 195 Handle<JSObject> object = factory->NewJSObject(function, TENURED); |
| 194 CHECK(!heap->InNewSpace(object->address())); | 196 CHECK(!heap->InNewSpace(object->address())); |
| 195 CHECK(!first_page->Contains(object->address())); | 197 CHECK(!first_page->Contains(object->address())); |
| 196 Runtime::WeakCollectionSet(weakset, key, object); | 198 int32_t hash = Object::GetOrCreateHash(isolate, key)->value(); |
| 199 Runtime::WeakCollectionSet(weakset, key, object, hash); |
| 197 } | 200 } |
| 198 } | 201 } |
| 199 | 202 |
| 200 // Force compacting garbage collection. | 203 // Force compacting garbage collection. |
| 201 CHECK(FLAG_always_compact); | 204 CHECK(FLAG_always_compact); |
| 202 heap->CollectAllGarbage(); | 205 heap->CollectAllGarbage(); |
| 203 } | 206 } |
| 204 | 207 |
| 205 | 208 |
| 206 // Test that weak set keys on an evacuation candidate which are reachable by | 209 // Test that weak set keys on an evacuation candidate which are reachable by |
| (...skipping 21 matching lines...) Expand all Loading... |
| 228 // Fill up weak set with keys on an evacuation candidate. | 231 // Fill up weak set with keys on an evacuation candidate. |
| 229 Handle<JSObject> keys[32]; | 232 Handle<JSObject> keys[32]; |
| 230 for (int i = 0; i < 32; i++) { | 233 for (int i = 0; i < 32; i++) { |
| 231 keys[i] = factory->NewJSObject(function, TENURED); | 234 keys[i] = factory->NewJSObject(function, TENURED); |
| 232 CHECK(!heap->InNewSpace(keys[i]->address())); | 235 CHECK(!heap->InNewSpace(keys[i]->address())); |
| 233 CHECK(!first_page->Contains(keys[i]->address())); | 236 CHECK(!first_page->Contains(keys[i]->address())); |
| 234 } | 237 } |
| 235 Handle<JSWeakSet> weakset = AllocateJSWeakSet(isolate); | 238 Handle<JSWeakSet> weakset = AllocateJSWeakSet(isolate); |
| 236 for (int i = 0; i < 32; i++) { | 239 for (int i = 0; i < 32; i++) { |
| 237 Handle<Smi> smi(Smi::FromInt(i), isolate); | 240 Handle<Smi> smi(Smi::FromInt(i), isolate); |
| 238 Runtime::WeakCollectionSet(weakset, keys[i], smi); | 241 int32_t hash = Object::GetOrCreateHash(isolate, keys[i])->value(); |
| 242 Runtime::WeakCollectionSet(weakset, keys[i], smi, hash); |
| 239 } | 243 } |
| 240 | 244 |
| 241 // Force compacting garbage collection. The subsequent collections are used | 245 // Force compacting garbage collection. The subsequent collections are used |
| 242 // to verify that key references were actually updated. | 246 // to verify that key references were actually updated. |
| 243 CHECK(FLAG_always_compact); | 247 CHECK(FLAG_always_compact); |
| 244 heap->CollectAllGarbage(); | 248 heap->CollectAllGarbage(); |
| 245 heap->CollectAllGarbage(); | 249 heap->CollectAllGarbage(); |
| 246 heap->CollectAllGarbage(); | 250 heap->CollectAllGarbage(); |
| 247 } | 251 } |
| OLD | NEW |