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

Side by Side Diff: test/cctest/test-weakmaps.cc

Issue 1314053003: Move runtime helper for JSWeakCollection onto objects. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@local_cleanup-runtime-helpers-1
Patch Set: Created 5 years, 3 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 | « src/runtime/runtime-collections.cc ('k') | test/cctest/test-weaksets.cc » ('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 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
82 } 82 }
83 CHECK(!global_handles->IsWeak(key.location())); 83 CHECK(!global_handles->IsWeak(key.location()));
84 84
85 // Put two chained entries into weak map. 85 // Put two chained entries into weak map.
86 { 86 {
87 HandleScope scope(isolate); 87 HandleScope scope(isolate);
88 Handle<Map> map = factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); 88 Handle<Map> map = factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
89 Handle<JSObject> object = factory->NewJSObjectFromMap(map); 89 Handle<JSObject> object = factory->NewJSObjectFromMap(map);
90 Handle<Smi> smi(Smi::FromInt(23), isolate); 90 Handle<Smi> smi(Smi::FromInt(23), isolate);
91 int32_t hash = Object::GetOrCreateHash(isolate, key)->value(); 91 int32_t hash = Object::GetOrCreateHash(isolate, key)->value();
92 Runtime::WeakCollectionSet(weakmap, key, object, hash); 92 JSWeakCollection::Set(weakmap, key, object, hash);
93 int32_t object_hash = Object::GetOrCreateHash(isolate, object)->value(); 93 int32_t object_hash = Object::GetOrCreateHash(isolate, object)->value();
94 Runtime::WeakCollectionSet(weakmap, object, smi, object_hash); 94 JSWeakCollection::Set(weakmap, object, smi, object_hash);
95 } 95 }
96 CHECK_EQ(2, ObjectHashTable::cast(weakmap->table())->NumberOfElements()); 96 CHECK_EQ(2, ObjectHashTable::cast(weakmap->table())->NumberOfElements());
97 97
98 // Force a full GC. 98 // Force a full GC.
99 heap->CollectAllGarbage(false); 99 heap->CollectAllGarbage(false);
100 CHECK_EQ(0, NumberOfWeakCalls); 100 CHECK_EQ(0, NumberOfWeakCalls);
101 CHECK_EQ(2, ObjectHashTable::cast(weakmap->table())->NumberOfElements()); 101 CHECK_EQ(2, ObjectHashTable::cast(weakmap->table())->NumberOfElements());
102 CHECK_EQ( 102 CHECK_EQ(
103 0, ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements()); 103 0, ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements());
104 104
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 CHECK_EQ(32, ObjectHashTable::cast(weakmap->table())->Capacity()); 140 CHECK_EQ(32, ObjectHashTable::cast(weakmap->table())->Capacity());
141 141
142 // Fill up weak map to trigger capacity change. 142 // Fill up weak map to trigger capacity change.
143 { 143 {
144 HandleScope scope(isolate); 144 HandleScope scope(isolate);
145 Handle<Map> map = factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); 145 Handle<Map> map = factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
146 for (int i = 0; i < 32; i++) { 146 for (int i = 0; i < 32; i++) {
147 Handle<JSObject> object = factory->NewJSObjectFromMap(map); 147 Handle<JSObject> object = factory->NewJSObjectFromMap(map);
148 Handle<Smi> smi(Smi::FromInt(i), isolate); 148 Handle<Smi> smi(Smi::FromInt(i), isolate);
149 int32_t object_hash = Object::GetOrCreateHash(isolate, object)->value(); 149 int32_t object_hash = Object::GetOrCreateHash(isolate, object)->value();
150 Runtime::WeakCollectionSet(weakmap, object, smi, object_hash); 150 JSWeakCollection::Set(weakmap, object, smi, object_hash);
151 } 151 }
152 } 152 }
153 153
154 // Check increased capacity. 154 // Check increased capacity.
155 CHECK_EQ(128, ObjectHashTable::cast(weakmap->table())->Capacity()); 155 CHECK_EQ(128, ObjectHashTable::cast(weakmap->table())->Capacity());
156 156
157 // Force a full GC. 157 // Force a full GC.
158 CHECK_EQ(32, ObjectHashTable::cast(weakmap->table())->NumberOfElements()); 158 CHECK_EQ(32, ObjectHashTable::cast(weakmap->table())->NumberOfElements());
159 CHECK_EQ( 159 CHECK_EQ(
160 0, ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements()); 160 0, ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements());
(...skipping 28 matching lines...) Expand all
189 factory->NewFixedArray(dummy_array_size / kPointerSize, TENURED); 189 factory->NewFixedArray(dummy_array_size / kPointerSize, TENURED);
190 190
191 // Fill up weak map with values on an evacuation candidate. 191 // Fill up weak map with values on an evacuation candidate.
192 { 192 {
193 HandleScope scope(isolate); 193 HandleScope scope(isolate);
194 for (int i = 0; i < 32; i++) { 194 for (int i = 0; i < 32; i++) {
195 Handle<JSObject> object = factory->NewJSObject(function, TENURED); 195 Handle<JSObject> object = factory->NewJSObject(function, TENURED);
196 CHECK(!heap->InNewSpace(object->address())); 196 CHECK(!heap->InNewSpace(object->address()));
197 CHECK(!first_page->Contains(object->address())); 197 CHECK(!first_page->Contains(object->address()));
198 int32_t hash = Object::GetOrCreateHash(isolate, key)->value(); 198 int32_t hash = Object::GetOrCreateHash(isolate, key)->value();
199 Runtime::WeakCollectionSet(weakmap, key, object, hash); 199 JSWeakCollection::Set(weakmap, key, object, hash);
200 } 200 }
201 } 201 }
202 202
203 // Force compacting garbage collection. 203 // Force compacting garbage collection.
204 CHECK(FLAG_always_compact); 204 CHECK(FLAG_always_compact);
205 heap->CollectAllGarbage(); 205 heap->CollectAllGarbage();
206 } 206 }
207 207
208 208
209 // Test that weak map keys on an evacuation candidate which are reachable by 209 // Test that weak map keys on an evacuation candidate which are reachable by
(...skipping 22 matching lines...) Expand all
232 Handle<JSObject> keys[32]; 232 Handle<JSObject> keys[32];
233 for (int i = 0; i < 32; i++) { 233 for (int i = 0; i < 32; i++) {
234 keys[i] = factory->NewJSObject(function, TENURED); 234 keys[i] = factory->NewJSObject(function, TENURED);
235 CHECK(!heap->InNewSpace(keys[i]->address())); 235 CHECK(!heap->InNewSpace(keys[i]->address()));
236 CHECK(!first_page->Contains(keys[i]->address())); 236 CHECK(!first_page->Contains(keys[i]->address()));
237 } 237 }
238 Handle<JSWeakMap> weakmap = AllocateJSWeakMap(isolate); 238 Handle<JSWeakMap> weakmap = AllocateJSWeakMap(isolate);
239 for (int i = 0; i < 32; i++) { 239 for (int i = 0; i < 32; i++) {
240 Handle<Smi> smi(Smi::FromInt(i), isolate); 240 Handle<Smi> smi(Smi::FromInt(i), isolate);
241 int32_t hash = Object::GetOrCreateHash(isolate, keys[i])->value(); 241 int32_t hash = Object::GetOrCreateHash(isolate, keys[i])->value();
242 Runtime::WeakCollectionSet(weakmap, keys[i], smi, hash); 242 JSWeakCollection::Set(weakmap, keys[i], smi, hash);
243 } 243 }
244 244
245 // Force compacting garbage collection. The subsequent collections are used 245 // Force compacting garbage collection. The subsequent collections are used
246 // to verify that key references were actually updated. 246 // to verify that key references were actually updated.
247 CHECK(FLAG_always_compact); 247 CHECK(FLAG_always_compact);
248 heap->CollectAllGarbage(); 248 heap->CollectAllGarbage();
249 heap->CollectAllGarbage(); 249 heap->CollectAllGarbage();
250 heap->CollectAllGarbage(); 250 heap->CollectAllGarbage();
251 } 251 }
252 252
253 253
254 TEST(Regress399527) { 254 TEST(Regress399527) {
255 CcTest::InitializeVM(); 255 CcTest::InitializeVM();
256 v8::HandleScope scope(CcTest::isolate()); 256 v8::HandleScope scope(CcTest::isolate());
257 Isolate* isolate = CcTest::i_isolate(); 257 Isolate* isolate = CcTest::i_isolate();
258 Heap* heap = isolate->heap(); 258 Heap* heap = isolate->heap();
259 { 259 {
260 HandleScope scope(isolate); 260 HandleScope scope(isolate);
261 AllocateJSWeakMap(isolate); 261 AllocateJSWeakMap(isolate);
262 SimulateIncrementalMarking(heap); 262 SimulateIncrementalMarking(heap);
263 } 263 }
264 // The weak map is marked black here but leaving the handle scope will make 264 // The weak map is marked black here but leaving the handle scope will make
265 // the object unreachable. Aborting incremental marking will clear all the 265 // the object unreachable. Aborting incremental marking will clear all the
266 // marking bits which makes the weak map garbage. 266 // marking bits which makes the weak map garbage.
267 heap->CollectAllGarbage(); 267 heap->CollectAllGarbage();
268 } 268 }
OLDNEW
« no previous file with comments | « src/runtime/runtime-collections.cc ('k') | test/cctest/test-weaksets.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698