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

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

Issue 1999753002: [heap] Harden heap-related cctests (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix for win Created 4 years, 7 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-unboxed-doubles.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 13 matching lines...) Expand all
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #include <utility> 28 #include <utility>
29 29
30 #include "src/v8.h" 30 #include "src/v8.h"
31 31
32 #include "src/global-handles.h" 32 #include "src/global-handles.h"
33 #include "test/cctest/cctest.h" 33 #include "test/cctest/cctest.h"
34 #include "test/cctest/heap/utils-inl.h" 34 #include "test/cctest/heap/heap-utils.h"
35 35
36 using namespace v8::internal; 36 using namespace v8::internal;
37 37
38 static Isolate* GetIsolateFrom(LocalContext* context) { 38 static Isolate* GetIsolateFrom(LocalContext* context) {
39 return reinterpret_cast<Isolate*>((*context)->GetIsolate()); 39 return reinterpret_cast<Isolate*>((*context)->GetIsolate());
40 } 40 }
41 41
42 42
43 static Handle<JSWeakMap> AllocateJSWeakMap(Isolate* isolate) { 43 static Handle<JSWeakMap> AllocateJSWeakMap(Isolate* isolate) {
44 Handle<JSWeakMap> weakmap = isolate->factory()->NewJSWeakMap(); 44 Handle<JSWeakMap> weakmap = isolate->factory()->NewJSWeakMap();
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 Factory* factory = isolate->factory(); 170 Factory* factory = isolate->factory();
171 Heap* heap = isolate->heap(); 171 Heap* heap = isolate->heap();
172 HandleScope scope(isolate); 172 HandleScope scope(isolate);
173 Handle<JSFunction> function = factory->NewFunction( 173 Handle<JSFunction> function = factory->NewFunction(
174 factory->function_string()); 174 factory->function_string());
175 Handle<JSObject> key = factory->NewJSObject(function); 175 Handle<JSObject> key = factory->NewJSObject(function);
176 Handle<JSWeakMap> weakmap = AllocateJSWeakMap(isolate); 176 Handle<JSWeakMap> weakmap = AllocateJSWeakMap(isolate);
177 177
178 // Start second old-space page so that values land on evacuation candidate. 178 // Start second old-space page so that values land on evacuation candidate.
179 Page* first_page = heap->old_space()->anchor()->next_page(); 179 Page* first_page = heap->old_space()->anchor()->next_page();
180 SimulateFullSpace(heap->old_space()); 180 heap::SimulateFullSpace(heap->old_space());
181 181
182 // Fill up weak map with values on an evacuation candidate. 182 // Fill up weak map with values on an evacuation candidate.
183 { 183 {
184 HandleScope scope(isolate); 184 HandleScope scope(isolate);
185 for (int i = 0; i < 32; i++) { 185 for (int i = 0; i < 32; i++) {
186 Handle<JSObject> object = factory->NewJSObject(function, TENURED); 186 Handle<JSObject> object = factory->NewJSObject(function, TENURED);
187 CHECK(!heap->InNewSpace(*object)); 187 CHECK(!heap->InNewSpace(*object));
188 CHECK(!first_page->Contains(object->address())); 188 CHECK(!first_page->Contains(object->address()));
189 int32_t hash = Object::GetOrCreateHash(isolate, key)->value(); 189 int32_t hash = Object::GetOrCreateHash(isolate, key)->value();
190 JSWeakCollection::Set(weakmap, key, object, hash); 190 JSWeakCollection::Set(weakmap, key, object, hash);
(...skipping 18 matching lines...) Expand all
209 LocalContext context; 209 LocalContext context;
210 Isolate* isolate = GetIsolateFrom(&context); 210 Isolate* isolate = GetIsolateFrom(&context);
211 Factory* factory = isolate->factory(); 211 Factory* factory = isolate->factory();
212 Heap* heap = isolate->heap(); 212 Heap* heap = isolate->heap();
213 HandleScope scope(isolate); 213 HandleScope scope(isolate);
214 Handle<JSFunction> function = factory->NewFunction( 214 Handle<JSFunction> function = factory->NewFunction(
215 factory->function_string()); 215 factory->function_string());
216 216
217 // Start second old-space page so that keys land on evacuation candidate. 217 // Start second old-space page so that keys land on evacuation candidate.
218 Page* first_page = heap->old_space()->anchor()->next_page(); 218 Page* first_page = heap->old_space()->anchor()->next_page();
219 SimulateFullSpace(heap->old_space()); 219 heap::SimulateFullSpace(heap->old_space());
220 220
221 // Fill up weak map with keys on an evacuation candidate. 221 // Fill up weak map with keys on an evacuation candidate.
222 Handle<JSObject> keys[32]; 222 Handle<JSObject> keys[32];
223 for (int i = 0; i < 32; i++) { 223 for (int i = 0; i < 32; i++) {
224 keys[i] = factory->NewJSObject(function, TENURED); 224 keys[i] = factory->NewJSObject(function, TENURED);
225 CHECK(!heap->InNewSpace(*keys[i])); 225 CHECK(!heap->InNewSpace(*keys[i]));
226 CHECK(!first_page->Contains(keys[i]->address())); 226 CHECK(!first_page->Contains(keys[i]->address()));
227 } 227 }
228 Handle<JSWeakMap> weakmap = AllocateJSWeakMap(isolate); 228 Handle<JSWeakMap> weakmap = AllocateJSWeakMap(isolate);
229 for (int i = 0; i < 32; i++) { 229 for (int i = 0; i < 32; i++) {
(...skipping 12 matching lines...) Expand all
242 242
243 243
244 TEST(Regress399527) { 244 TEST(Regress399527) {
245 CcTest::InitializeVM(); 245 CcTest::InitializeVM();
246 v8::HandleScope scope(CcTest::isolate()); 246 v8::HandleScope scope(CcTest::isolate());
247 Isolate* isolate = CcTest::i_isolate(); 247 Isolate* isolate = CcTest::i_isolate();
248 Heap* heap = isolate->heap(); 248 Heap* heap = isolate->heap();
249 { 249 {
250 HandleScope scope(isolate); 250 HandleScope scope(isolate);
251 AllocateJSWeakMap(isolate); 251 AllocateJSWeakMap(isolate);
252 SimulateIncrementalMarking(heap); 252 heap::SimulateIncrementalMarking(heap);
253 } 253 }
254 // The weak map is marked black here but leaving the handle scope will make 254 // The weak map is marked black here but leaving the handle scope will make
255 // the object unreachable. Aborting incremental marking will clear all the 255 // the object unreachable. Aborting incremental marking will clear all the
256 // marking bits which makes the weak map garbage. 256 // marking bits which makes the weak map garbage.
257 heap->CollectAllGarbage(); 257 heap->CollectAllGarbage();
258 } 258 }
OLDNEW
« no previous file with comments | « test/cctest/test-unboxed-doubles.cc ('k') | test/cctest/test-weaksets.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698