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

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

Issue 12716010: Added a version of the v8::HandleScope constructor with an Isolate and use that consistently. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fixed rest Created 7 years, 9 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
« test/cctest/test-api.cc ('K') | « test/cctest/test-threads.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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 handle.Dispose(isolate); 72 handle.Dispose(isolate);
73 } 73 }
74 74
75 75
76 TEST(Weakness) { 76 TEST(Weakness) {
77 FLAG_incremental_marking = false; 77 FLAG_incremental_marking = false;
78 LocalContext context; 78 LocalContext context;
79 Isolate* isolate = GetIsolateFrom(&context); 79 Isolate* isolate = GetIsolateFrom(&context);
80 Factory* factory = isolate->factory(); 80 Factory* factory = isolate->factory();
81 Heap* heap = isolate->heap(); 81 Heap* heap = isolate->heap();
82 v8::HandleScope scope; 82 HandleScope scope(isolate);
83 Handle<JSWeakMap> weakmap = AllocateJSWeakMap(isolate); 83 Handle<JSWeakMap> weakmap = AllocateJSWeakMap(isolate);
84 GlobalHandles* global_handles = isolate->global_handles(); 84 GlobalHandles* global_handles = isolate->global_handles();
85 85
86 // Keep global reference to the key. 86 // Keep global reference to the key.
87 Handle<Object> key; 87 Handle<Object> key;
88 { 88 {
89 v8::HandleScope scope; 89 HandleScope scope(isolate);
90 Handle<Map> map = factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); 90 Handle<Map> map = factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
91 Handle<JSObject> object = factory->NewJSObjectFromMap(map); 91 Handle<JSObject> object = factory->NewJSObjectFromMap(map);
92 key = global_handles->Create(*object); 92 key = global_handles->Create(*object);
93 } 93 }
94 CHECK(!global_handles->IsWeak(key.location())); 94 CHECK(!global_handles->IsWeak(key.location()));
95 95
96 // Put entry into weak map. 96 // Put entry into weak map.
97 { 97 {
98 v8::HandleScope scope; 98 HandleScope scope(isolate);
99 PutIntoWeakMap(weakmap, 99 PutIntoWeakMap(weakmap,
100 Handle<JSObject>(JSObject::cast(*key)), 100 Handle<JSObject>(JSObject::cast(*key)),
101 Handle<Smi>(Smi::FromInt(23), isolate)); 101 Handle<Smi>(Smi::FromInt(23), isolate));
102 } 102 }
103 CHECK_EQ(1, ObjectHashTable::cast(weakmap->table())->NumberOfElements()); 103 CHECK_EQ(1, ObjectHashTable::cast(weakmap->table())->NumberOfElements());
104 104
105 // Force a full GC. 105 // Force a full GC.
106 heap->CollectAllGarbage(false); 106 heap->CollectAllGarbage(false);
107 CHECK_EQ(0, NumberOfWeakCalls); 107 CHECK_EQ(0, NumberOfWeakCalls);
108 CHECK_EQ(1, ObjectHashTable::cast(weakmap->table())->NumberOfElements()); 108 CHECK_EQ(1, ObjectHashTable::cast(weakmap->table())->NumberOfElements());
109 CHECK_EQ( 109 CHECK_EQ(
110 0, ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements()); 110 0, ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements());
111 111
112 // Make the global reference to the key weak. 112 // Make the global reference to the key weak.
113 { 113 {
114 v8::HandleScope scope; 114 HandleScope scope(isolate);
115 global_handles->MakeWeak(key.location(), 115 global_handles->MakeWeak(key.location(),
116 reinterpret_cast<void*>(1234), 116 reinterpret_cast<void*>(1234),
117 NULL, 117 NULL,
118 &WeakPointerCallback); 118 &WeakPointerCallback);
119 } 119 }
120 CHECK(global_handles->IsWeak(key.location())); 120 CHECK(global_handles->IsWeak(key.location()));
121 121
122 // Force a full GC. 122 // Force a full GC.
123 // Perform two consecutive GCs because the first one will only clear 123 // Perform two consecutive GCs because the first one will only clear
124 // weak references whereas the second one will also clear weak maps. 124 // weak references whereas the second one will also clear weak maps.
125 heap->CollectAllGarbage(false); 125 heap->CollectAllGarbage(false);
126 CHECK_EQ(1, NumberOfWeakCalls); 126 CHECK_EQ(1, NumberOfWeakCalls);
127 CHECK_EQ(1, ObjectHashTable::cast(weakmap->table())->NumberOfElements()); 127 CHECK_EQ(1, ObjectHashTable::cast(weakmap->table())->NumberOfElements());
128 CHECK_EQ( 128 CHECK_EQ(
129 0, ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements()); 129 0, ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements());
130 heap->CollectAllGarbage(false); 130 heap->CollectAllGarbage(false);
131 CHECK_EQ(1, NumberOfWeakCalls); 131 CHECK_EQ(1, NumberOfWeakCalls);
132 CHECK_EQ(0, ObjectHashTable::cast(weakmap->table())->NumberOfElements()); 132 CHECK_EQ(0, ObjectHashTable::cast(weakmap->table())->NumberOfElements());
133 CHECK_EQ( 133 CHECK_EQ(
134 1, ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements()); 134 1, ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements());
135 } 135 }
136 136
137 137
138 TEST(Shrinking) { 138 TEST(Shrinking) {
139 LocalContext context; 139 LocalContext context;
140 Isolate* isolate = GetIsolateFrom(&context); 140 Isolate* isolate = GetIsolateFrom(&context);
141 Factory* factory = isolate->factory(); 141 Factory* factory = isolate->factory();
142 Heap* heap = isolate->heap(); 142 Heap* heap = isolate->heap();
143 v8::HandleScope scope; 143 HandleScope scope(isolate);
144 Handle<JSWeakMap> weakmap = AllocateJSWeakMap(isolate); 144 Handle<JSWeakMap> weakmap = AllocateJSWeakMap(isolate);
145 145
146 // Check initial capacity. 146 // Check initial capacity.
147 CHECK_EQ(32, ObjectHashTable::cast(weakmap->table())->Capacity()); 147 CHECK_EQ(32, ObjectHashTable::cast(weakmap->table())->Capacity());
148 148
149 // Fill up weak map to trigger capacity change. 149 // Fill up weak map to trigger capacity change.
150 { 150 {
151 v8::HandleScope scope; 151 HandleScope scope(isolate);
152 Handle<Map> map = factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); 152 Handle<Map> map = factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
153 for (int i = 0; i < 32; i++) { 153 for (int i = 0; i < 32; i++) {
154 Handle<JSObject> object = factory->NewJSObjectFromMap(map); 154 Handle<JSObject> object = factory->NewJSObjectFromMap(map);
155 PutIntoWeakMap(weakmap, object, Handle<Smi>(Smi::FromInt(i), isolate)); 155 PutIntoWeakMap(weakmap, object, Handle<Smi>(Smi::FromInt(i), isolate));
156 } 156 }
157 } 157 }
158 158
159 // Check increased capacity. 159 // Check increased capacity.
160 CHECK_EQ(128, ObjectHashTable::cast(weakmap->table())->Capacity()); 160 CHECK_EQ(128, ObjectHashTable::cast(weakmap->table())->Capacity());
161 161
(...skipping 12 matching lines...) Expand all
174 174
175 175
176 // Test that weak map values on an evacuation candidate which are not reachable 176 // Test that weak map values on an evacuation candidate which are not reachable
177 // by other paths are correctly recorded in the slots buffer. 177 // by other paths are correctly recorded in the slots buffer.
178 TEST(Regress2060a) { 178 TEST(Regress2060a) {
179 FLAG_always_compact = true; 179 FLAG_always_compact = true;
180 LocalContext context; 180 LocalContext context;
181 Isolate* isolate = GetIsolateFrom(&context); 181 Isolate* isolate = GetIsolateFrom(&context);
182 Factory* factory = isolate->factory(); 182 Factory* factory = isolate->factory();
183 Heap* heap = isolate->heap(); 183 Heap* heap = isolate->heap();
184 v8::HandleScope scope; 184 HandleScope scope(isolate);
185 Handle<JSFunction> function = 185 Handle<JSFunction> function =
186 factory->NewFunction(factory->function_string(), factory->null_value()); 186 factory->NewFunction(factory->function_string(), factory->null_value());
187 Handle<JSObject> key = factory->NewJSObject(function); 187 Handle<JSObject> key = factory->NewJSObject(function);
188 Handle<JSWeakMap> weakmap = AllocateJSWeakMap(isolate); 188 Handle<JSWeakMap> weakmap = AllocateJSWeakMap(isolate);
189 189
190 // Start second old-space page so that values land on evacuation candidate. 190 // Start second old-space page so that values land on evacuation candidate.
191 Page* first_page = heap->old_pointer_space()->anchor()->next_page(); 191 Page* first_page = heap->old_pointer_space()->anchor()->next_page();
192 factory->NewFixedArray(900 * KB / kPointerSize, TENURED); 192 factory->NewFixedArray(900 * KB / kPointerSize, TENURED);
193 193
194 // Fill up weak map with values on an evacuation candidate. 194 // Fill up weak map with values on an evacuation candidate.
195 { 195 {
196 v8::HandleScope scope; 196 HandleScope scope(isolate);
197 for (int i = 0; i < 32; i++) { 197 for (int i = 0; i < 32; i++) {
198 Handle<JSObject> object = factory->NewJSObject(function, TENURED); 198 Handle<JSObject> object = factory->NewJSObject(function, TENURED);
199 CHECK(!heap->InNewSpace(object->address())); 199 CHECK(!heap->InNewSpace(object->address()));
200 CHECK(!first_page->Contains(object->address())); 200 CHECK(!first_page->Contains(object->address()));
201 PutIntoWeakMap(weakmap, key, object); 201 PutIntoWeakMap(weakmap, key, object);
202 } 202 }
203 } 203 }
204 204
205 // Force compacting garbage collection. 205 // Force compacting garbage collection.
206 CHECK(FLAG_always_compact); 206 CHECK(FLAG_always_compact);
207 heap->CollectAllGarbage(Heap::kNoGCFlags); 207 heap->CollectAllGarbage(Heap::kNoGCFlags);
208 } 208 }
209 209
210 210
211 // Test that weak map keys on an evacuation candidate which are reachable by 211 // Test that weak map keys on an evacuation candidate which are reachable by
212 // other strong paths are correctly recorded in the slots buffer. 212 // other strong paths are correctly recorded in the slots buffer.
213 TEST(Regress2060b) { 213 TEST(Regress2060b) {
214 FLAG_always_compact = true; 214 FLAG_always_compact = true;
215 #ifdef VERIFY_HEAP 215 #ifdef VERIFY_HEAP
216 FLAG_verify_heap = true; 216 FLAG_verify_heap = true;
217 #endif 217 #endif
218 218
219 LocalContext context; 219 LocalContext context;
220 Isolate* isolate = GetIsolateFrom(&context); 220 Isolate* isolate = GetIsolateFrom(&context);
221 Factory* factory = isolate->factory(); 221 Factory* factory = isolate->factory();
222 Heap* heap = isolate->heap(); 222 Heap* heap = isolate->heap();
223 v8::HandleScope scope; 223 HandleScope scope(isolate);
224 Handle<JSFunction> function = 224 Handle<JSFunction> function =
225 factory->NewFunction(factory->function_string(), factory->null_value()); 225 factory->NewFunction(factory->function_string(), factory->null_value());
226 226
227 // Start second old-space page so that keys land on evacuation candidate. 227 // Start second old-space page so that keys land on evacuation candidate.
228 Page* first_page = heap->old_pointer_space()->anchor()->next_page(); 228 Page* first_page = heap->old_pointer_space()->anchor()->next_page();
229 factory->NewFixedArray(900 * KB / kPointerSize, TENURED); 229 factory->NewFixedArray(900 * KB / kPointerSize, TENURED);
230 230
231 // Fill up weak map with keys on an evacuation candidate. 231 // Fill up weak map with keys on an evacuation candidate.
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 PutIntoWeakMap(weakmap, 240 PutIntoWeakMap(weakmap,
241 keys[i], 241 keys[i],
242 Handle<Smi>(Smi::FromInt(i), isolate)); 242 Handle<Smi>(Smi::FromInt(i), isolate));
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(Heap::kNoGCFlags); 248 heap->CollectAllGarbage(Heap::kNoGCFlags);
249 heap->CollectAllGarbage(Heap::kNoGCFlags); 249 heap->CollectAllGarbage(Heap::kNoGCFlags);
250 heap->CollectAllGarbage(Heap::kNoGCFlags); 250 heap->CollectAllGarbage(Heap::kNoGCFlags);
251 } 251 }
OLDNEW
« test/cctest/test-api.cc ('K') | « test/cctest/test-threads.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698