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

Side by Side Diff: test/cctest/test-mark-compact.cc

Issue 6815029: Merge (7180:7265] from bleeding_edge to the experimental/gc branch.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/gc/
Patch Set: Created 9 years, 8 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
« no previous file with comments | « test/cctest/test-api.cc ('k') | test/cctest/testcfg.py » ('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 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 CHECK_EQ(gc_ends, gc_starts); 295 CHECK_EQ(gc_ends, gc_starts);
296 296
297 Heap::CollectGarbage(OLD_POINTER_SPACE); 297 Heap::CollectGarbage(OLD_POINTER_SPACE);
298 CHECK_EQ(1, gc_starts); 298 CHECK_EQ(1, gc_starts);
299 CHECK_EQ(gc_ends, gc_starts); 299 CHECK_EQ(gc_ends, gc_starts);
300 } 300 }
301 301
302 302
303 static int NumberOfWeakCalls = 0; 303 static int NumberOfWeakCalls = 0;
304 static void WeakPointerCallback(v8::Persistent<v8::Value> handle, void* id) { 304 static void WeakPointerCallback(v8::Persistent<v8::Value> handle, void* id) {
305 ASSERT(id == reinterpret_cast<void*>(1234));
305 NumberOfWeakCalls++; 306 NumberOfWeakCalls++;
306 handle.Dispose(); 307 handle.Dispose();
307 } 308 }
308 309
309 TEST(ObjectGroups) { 310 TEST(ObjectGroups) {
310 InitializeVM(); 311 InitializeVM();
311 312
312 NumberOfWeakCalls = 0; 313 NumberOfWeakCalls = 0;
313 v8::HandleScope handle_scope; 314 v8::HandleScope handle_scope;
314 315
315 Handle<Object> g1s1 = 316 Handle<Object> g1s1 =
316 GlobalHandles::Create(Heap::AllocateFixedArray(1)->ToObjectChecked()); 317 GlobalHandles::Create(Heap::AllocateFixedArray(1)->ToObjectChecked());
317 Handle<Object> g1s2 = 318 Handle<Object> g1s2 =
318 GlobalHandles::Create(Heap::AllocateFixedArray(1)->ToObjectChecked()); 319 GlobalHandles::Create(Heap::AllocateFixedArray(1)->ToObjectChecked());
320 Handle<Object> g1c1 =
321 GlobalHandles::Create(Heap::AllocateFixedArray(1)->ToObjectChecked());
319 GlobalHandles::MakeWeak(g1s1.location(), 322 GlobalHandles::MakeWeak(g1s1.location(),
320 reinterpret_cast<void*>(1234), 323 reinterpret_cast<void*>(1234),
321 &WeakPointerCallback); 324 &WeakPointerCallback);
322 GlobalHandles::MakeWeak(g1s2.location(), 325 GlobalHandles::MakeWeak(g1s2.location(),
323 reinterpret_cast<void*>(1234), 326 reinterpret_cast<void*>(1234),
324 &WeakPointerCallback); 327 &WeakPointerCallback);
328 GlobalHandles::MakeWeak(g1c1.location(),
329 reinterpret_cast<void*>(1234),
330 &WeakPointerCallback);
325 331
326 Handle<Object> g2s1 = 332 Handle<Object> g2s1 =
327 GlobalHandles::Create(Heap::AllocateFixedArray(1)->ToObjectChecked()); 333 GlobalHandles::Create(Heap::AllocateFixedArray(1)->ToObjectChecked());
328 Handle<Object> g2s2 = 334 Handle<Object> g2s2 =
329 GlobalHandles::Create(Heap::AllocateFixedArray(1)->ToObjectChecked()); 335 GlobalHandles::Create(Heap::AllocateFixedArray(1)->ToObjectChecked());
336 Handle<Object> g2c1 =
337 GlobalHandles::Create(Heap::AllocateFixedArray(1)->ToObjectChecked());
330 GlobalHandles::MakeWeak(g2s1.location(), 338 GlobalHandles::MakeWeak(g2s1.location(),
331 reinterpret_cast<void*>(1234), 339 reinterpret_cast<void*>(1234),
332 &WeakPointerCallback); 340 &WeakPointerCallback);
333 GlobalHandles::MakeWeak(g2s2.location(), 341 GlobalHandles::MakeWeak(g2s2.location(),
334 reinterpret_cast<void*>(1234), 342 reinterpret_cast<void*>(1234),
335 &WeakPointerCallback); 343 &WeakPointerCallback);
344 GlobalHandles::MakeWeak(g2c1.location(),
345 reinterpret_cast<void*>(1234),
346 &WeakPointerCallback);
336 347
337 Handle<Object> root = GlobalHandles::Create(*g1s1); // make a root. 348 Handle<Object> root = GlobalHandles::Create(*g1s1); // make a root.
338 349
339 // Connect group 1 and 2, make a cycle. 350 // Connect group 1 and 2, make a cycle.
340 Handle<FixedArray>::cast(g1s2)->set(0, *g2s2); 351 Handle<FixedArray>::cast(g1s2)->set(0, *g2s2);
341 Handle<FixedArray>::cast(g2s1)->set(0, *g1s1); 352 Handle<FixedArray>::cast(g2s1)->set(0, *g1s1);
342 353
343 { 354 {
344 Object** g1_objects[] = { g1s1.location(), g1s2.location() }; 355 Object** g1_objects[] = { g1s1.location(), g1s2.location() };
356 Object** g1_children[] = { g1c1.location() };
345 Object** g2_objects[] = { g2s1.location(), g2s2.location() }; 357 Object** g2_objects[] = { g2s1.location(), g2s2.location() };
346 GlobalHandles::AddGroup(g1_objects, 2, NULL); 358 Object** g2_children[] = { g2c1.location() };
347 GlobalHandles::AddGroup(g2_objects, 2, NULL); 359 GlobalHandles::AddObjectGroup(g1_objects, 2, NULL);
360 GlobalHandles::AddImplicitReferences(HeapObject::cast(*g1s1),
361 g1_children, 1);
362 GlobalHandles::AddObjectGroup(g2_objects, 2, NULL);
363 GlobalHandles::AddImplicitReferences(HeapObject::cast(*g2s2),
364 g2_children, 1);
348 } 365 }
349 // Do a full GC 366 // Do a full GC
350 Heap::CollectGarbage(OLD_POINTER_SPACE); 367 Heap::CollectGarbage(OLD_POINTER_SPACE);
351 368
352 // All object should be alive. 369 // All object should be alive.
353 CHECK_EQ(0, NumberOfWeakCalls); 370 CHECK_EQ(0, NumberOfWeakCalls);
354 371
355 // Weaken the root. 372 // Weaken the root.
356 GlobalHandles::MakeWeak(root.location(), 373 GlobalHandles::MakeWeak(root.location(),
357 reinterpret_cast<void*>(1234), 374 reinterpret_cast<void*>(1234),
358 &WeakPointerCallback); 375 &WeakPointerCallback);
376 // But make children strong roots---all the objects (except for children)
377 // should be collectable now.
378 GlobalHandles::ClearWeakness(g1c1.location());
379 GlobalHandles::ClearWeakness(g2c1.location());
359 380
360 // Groups are deleted, rebuild groups. 381 // Groups are deleted, rebuild groups.
361 { 382 {
362 Object** g1_objects[] = { g1s1.location(), g1s2.location() }; 383 Object** g1_objects[] = { g1s1.location(), g1s2.location() };
384 Object** g1_children[] = { g1c1.location() };
363 Object** g2_objects[] = { g2s1.location(), g2s2.location() }; 385 Object** g2_objects[] = { g2s1.location(), g2s2.location() };
364 GlobalHandles::AddGroup(g1_objects, 2, NULL); 386 Object** g2_children[] = { g2c1.location() };
365 GlobalHandles::AddGroup(g2_objects, 2, NULL); 387 GlobalHandles::AddObjectGroup(g1_objects, 2, NULL);
388 GlobalHandles::AddImplicitReferences(HeapObject::cast(*g1s1),
389 g1_children, 1);
390 GlobalHandles::AddObjectGroup(g2_objects, 2, NULL);
391 GlobalHandles::AddImplicitReferences(HeapObject::cast(*g2s2),
392 g2_children, 1);
366 } 393 }
367 394
368 Heap::CollectGarbage(OLD_POINTER_SPACE); 395 Heap::CollectGarbage(OLD_POINTER_SPACE);
369 396
370 // All objects should be gone. 5 global handles in total. 397 // All objects should be gone. 5 global handles in total.
371 CHECK_EQ(5, NumberOfWeakCalls); 398 CHECK_EQ(5, NumberOfWeakCalls);
399
400 // And now make children weak again and collect them.
401 GlobalHandles::MakeWeak(g1c1.location(),
402 reinterpret_cast<void*>(1234),
403 &WeakPointerCallback);
404 GlobalHandles::MakeWeak(g2c1.location(),
405 reinterpret_cast<void*>(1234),
406 &WeakPointerCallback);
407
408 Heap::CollectGarbage(OLD_POINTER_SPACE);
409 CHECK_EQ(7, NumberOfWeakCalls);
372 } 410 }
OLDNEW
« no previous file with comments | « test/cctest/test-api.cc ('k') | test/cctest/testcfg.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698