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-weaksets.cc

Issue 900123003: Add NativeWeakMap to v8.h (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Applied r26428 Created 5 years, 10 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/cctest/test-weakmaps.cc ('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 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 Handle<JSWeakSet> weakset(JSWeakSet::cast(*weakset_obj)); 48 Handle<JSWeakSet> weakset(JSWeakSet::cast(*weakset_obj));
49 // Do not leak handles for the hash table, it would make entries strong. 49 // Do not leak handles for the hash table, it would make entries strong.
50 { 50 {
51 HandleScope scope(isolate); 51 HandleScope scope(isolate);
52 Handle<ObjectHashTable> table = ObjectHashTable::New(isolate, 1); 52 Handle<ObjectHashTable> table = ObjectHashTable::New(isolate, 1);
53 weakset->set_table(*table); 53 weakset->set_table(*table);
54 } 54 }
55 return weakset; 55 return weakset;
56 } 56 }
57 57
58 static void PutIntoWeakSet(Handle<JSWeakSet> weakset,
59 Handle<JSObject> key,
60 Handle<Object> value) {
61 Handle<ObjectHashTable> table = ObjectHashTable::Put(
62 Handle<ObjectHashTable>(ObjectHashTable::cast(weakset->table())),
63 Handle<JSObject>(JSObject::cast(*key)),
64 value);
65 weakset->set_table(*table);
66 }
67
68 static int NumberOfWeakCalls = 0; 58 static int NumberOfWeakCalls = 0;
69 static void WeakPointerCallback( 59 static void WeakPointerCallback(
70 const v8::WeakCallbackData<v8::Value, void>& data) { 60 const v8::WeakCallbackData<v8::Value, void>& data) {
71 std::pair<v8::Persistent<v8::Value>*, int>* p = 61 std::pair<v8::Persistent<v8::Value>*, int>* p =
72 reinterpret_cast<std::pair<v8::Persistent<v8::Value>*, int>*>( 62 reinterpret_cast<std::pair<v8::Persistent<v8::Value>*, int>*>(
73 data.GetParameter()); 63 data.GetParameter());
74 DCHECK_EQ(1234, p->second); 64 DCHECK_EQ(1234, p->second);
75 NumberOfWeakCalls++; 65 NumberOfWeakCalls++;
76 p->first->Reset(); 66 p->first->Reset();
77 } 67 }
(...skipping 15 matching lines...) Expand all
93 HandleScope scope(isolate); 83 HandleScope scope(isolate);
94 Handle<Map> map = factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); 84 Handle<Map> map = factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
95 Handle<JSObject> object = factory->NewJSObjectFromMap(map); 85 Handle<JSObject> object = factory->NewJSObjectFromMap(map);
96 key = global_handles->Create(*object); 86 key = global_handles->Create(*object);
97 } 87 }
98 CHECK(!global_handles->IsWeak(key.location())); 88 CHECK(!global_handles->IsWeak(key.location()));
99 89
100 // Put entry into weak set. 90 // Put entry into weak set.
101 { 91 {
102 HandleScope scope(isolate); 92 HandleScope scope(isolate);
103 PutIntoWeakSet(weakset, 93 Handle<Smi> smi(Smi::FromInt(23), isolate);
104 Handle<JSObject>(JSObject::cast(*key)), 94 Runtime::WeakCollectionSet(weakset, key, smi);
105 Handle<Smi>(Smi::FromInt(23), isolate));
106 } 95 }
107 CHECK_EQ(1, ObjectHashTable::cast(weakset->table())->NumberOfElements()); 96 CHECK_EQ(1, ObjectHashTable::cast(weakset->table())->NumberOfElements());
108 97
109 // Force a full GC. 98 // Force a full GC.
110 heap->CollectAllGarbage(false); 99 heap->CollectAllGarbage(false);
111 CHECK_EQ(0, NumberOfWeakCalls); 100 CHECK_EQ(0, NumberOfWeakCalls);
112 CHECK_EQ(1, ObjectHashTable::cast(weakset->table())->NumberOfElements()); 101 CHECK_EQ(1, ObjectHashTable::cast(weakset->table())->NumberOfElements());
113 CHECK_EQ( 102 CHECK_EQ(
114 0, ObjectHashTable::cast(weakset->table())->NumberOfDeletedElements()); 103 0, ObjectHashTable::cast(weakset->table())->NumberOfDeletedElements());
115 104
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 138
150 // Check initial capacity. 139 // Check initial capacity.
151 CHECK_EQ(32, ObjectHashTable::cast(weakset->table())->Capacity()); 140 CHECK_EQ(32, ObjectHashTable::cast(weakset->table())->Capacity());
152 141
153 // Fill up weak set to trigger capacity change. 142 // Fill up weak set to trigger capacity change.
154 { 143 {
155 HandleScope scope(isolate); 144 HandleScope scope(isolate);
156 Handle<Map> map = factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); 145 Handle<Map> map = factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
157 for (int i = 0; i < 32; i++) { 146 for (int i = 0; i < 32; i++) {
158 Handle<JSObject> object = factory->NewJSObjectFromMap(map); 147 Handle<JSObject> object = factory->NewJSObjectFromMap(map);
159 PutIntoWeakSet(weakset, object, Handle<Smi>(Smi::FromInt(i), isolate)); 148 Handle<Smi> smi(Smi::FromInt(i), isolate);
149 Runtime::WeakCollectionSet(weakset, object, smi);
160 } 150 }
161 } 151 }
162 152
163 // Check increased capacity. 153 // Check increased capacity.
164 CHECK_EQ(128, ObjectHashTable::cast(weakset->table())->Capacity()); 154 CHECK_EQ(128, ObjectHashTable::cast(weakset->table())->Capacity());
165 155
166 // Force a full GC. 156 // Force a full GC.
167 CHECK_EQ(32, ObjectHashTable::cast(weakset->table())->NumberOfElements()); 157 CHECK_EQ(32, ObjectHashTable::cast(weakset->table())->NumberOfElements());
168 CHECK_EQ( 158 CHECK_EQ(
169 0, ObjectHashTable::cast(weakset->table())->NumberOfDeletedElements()); 159 0, ObjectHashTable::cast(weakset->table())->NumberOfDeletedElements());
(...skipping 26 matching lines...) Expand all
196 Page* first_page = heap->old_pointer_space()->anchor()->next_page(); 186 Page* first_page = heap->old_pointer_space()->anchor()->next_page();
197 factory->NewFixedArray(900 * KB / kPointerSize, TENURED); 187 factory->NewFixedArray(900 * KB / kPointerSize, TENURED);
198 188
199 // Fill up weak set with values on an evacuation candidate. 189 // Fill up weak set with values on an evacuation candidate.
200 { 190 {
201 HandleScope scope(isolate); 191 HandleScope scope(isolate);
202 for (int i = 0; i < 32; i++) { 192 for (int i = 0; i < 32; i++) {
203 Handle<JSObject> object = factory->NewJSObject(function, TENURED); 193 Handle<JSObject> object = factory->NewJSObject(function, TENURED);
204 CHECK(!heap->InNewSpace(object->address())); 194 CHECK(!heap->InNewSpace(object->address()));
205 CHECK(!first_page->Contains(object->address())); 195 CHECK(!first_page->Contains(object->address()));
206 PutIntoWeakSet(weakset, key, object); 196 Runtime::WeakCollectionSet(weakset, key, object);
207 } 197 }
208 } 198 }
209 199
210 // Force compacting garbage collection. 200 // Force compacting garbage collection.
211 CHECK(FLAG_always_compact); 201 CHECK(FLAG_always_compact);
212 heap->CollectAllGarbage(Heap::kNoGCFlags); 202 heap->CollectAllGarbage(Heap::kNoGCFlags);
213 } 203 }
214 204
215 205
216 // Test that weak set keys on an evacuation candidate which are reachable by 206 // Test that weak set keys on an evacuation candidate which are reachable by
(...skipping 19 matching lines...) Expand all
236 226
237 // Fill up weak set with keys on an evacuation candidate. 227 // Fill up weak set with keys on an evacuation candidate.
238 Handle<JSObject> keys[32]; 228 Handle<JSObject> keys[32];
239 for (int i = 0; i < 32; i++) { 229 for (int i = 0; i < 32; i++) {
240 keys[i] = factory->NewJSObject(function, TENURED); 230 keys[i] = factory->NewJSObject(function, TENURED);
241 CHECK(!heap->InNewSpace(keys[i]->address())); 231 CHECK(!heap->InNewSpace(keys[i]->address()));
242 CHECK(!first_page->Contains(keys[i]->address())); 232 CHECK(!first_page->Contains(keys[i]->address()));
243 } 233 }
244 Handle<JSWeakSet> weakset = AllocateJSWeakSet(isolate); 234 Handle<JSWeakSet> weakset = AllocateJSWeakSet(isolate);
245 for (int i = 0; i < 32; i++) { 235 for (int i = 0; i < 32; i++) {
246 PutIntoWeakSet(weakset, 236 Handle<Smi> smi(Smi::FromInt(i), isolate);
247 keys[i], 237 Runtime::WeakCollectionSet(weakset, keys[i], smi);
248 Handle<Smi>(Smi::FromInt(i), isolate));
249 } 238 }
250 239
251 // Force compacting garbage collection. The subsequent collections are used 240 // Force compacting garbage collection. The subsequent collections are used
252 // to verify that key references were actually updated. 241 // to verify that key references were actually updated.
253 CHECK(FLAG_always_compact); 242 CHECK(FLAG_always_compact);
254 heap->CollectAllGarbage(Heap::kNoGCFlags); 243 heap->CollectAllGarbage(Heap::kNoGCFlags);
255 heap->CollectAllGarbage(Heap::kNoGCFlags); 244 heap->CollectAllGarbage(Heap::kNoGCFlags);
256 heap->CollectAllGarbage(Heap::kNoGCFlags); 245 heap->CollectAllGarbage(Heap::kNoGCFlags);
257 } 246 }
OLDNEW
« no previous file with comments | « test/cctest/test-weakmaps.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698