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

Side by Side Diff: Source/heap/tests/HeapTest.cpp

Issue 16042013: [oilpan] Resurrect a loop-back persistent handle in RefCountedHeapAllocated (Closed) Base URL: svn://svn.chromium.org/blink/branches/oilpan
Patch Set: Created 7 years, 6 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 | « Source/heap/Heap.h ('k') | Source/wtf/RefCounted.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013, Google Inc. All rights reserved. 2 * Copyright (c) 2013, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 ASSERT_EQ(2, HeapTestSubClass::s_destructorCalls); 341 ASSERT_EQ(2, HeapTestSubClass::s_destructorCalls);
342 ASSERT_EQ(3, HeapTestSuperClass::s_destructorCalls); 342 ASSERT_EQ(3, HeapTestSuperClass::s_destructorCalls);
343 // Destructors not called again when sweeping again. 343 // Destructors not called again when sweeping again.
344 Heap::sweep(); 344 Heap::sweep();
345 ASSERT_EQ(2, HeapTestSubClass::s_destructorCalls); 345 ASSERT_EQ(2, HeapTestSubClass::s_destructorCalls);
346 ASSERT_EQ(3, HeapTestSuperClass::s_destructorCalls); 346 ASSERT_EQ(3, HeapTestSuperClass::s_destructorCalls);
347 } 347 }
348 348
349 static void refCountedHeapAllocatedTest() 349 static void refCountedHeapAllocatedTest()
350 { 350 {
351 RefCountedAndHeapAllocated::s_destructorCalls = 0;
352 RefCountedAndHeapAllocated2::s_destructorCalls = 0;
351 { 353 {
352 RefPtr<RefCountedAndHeapAllocated> o1 = RefCountedAndHeapAllocated:: create(); 354 RefPtr<RefCountedAndHeapAllocated> o1 = RefCountedAndHeapAllocated:: create();
353 RefPtr<RefCountedAndHeapAllocated> o2 = RefCountedAndHeapAllocated:: create(); 355 RefPtr<RefCountedAndHeapAllocated> o2 = RefCountedAndHeapAllocated:: create();
354 RefPtr<RefCountedAndHeapAllocated2> o3 = RefCountedAndHeapAllocated2 ::create(); 356 RefPtr<RefCountedAndHeapAllocated2> o3 = RefCountedAndHeapAllocated2 ::create();
355 RefPtr<RefCountedAndHeapAllocated2> o4 = RefCountedAndHeapAllocated2 ::create(); 357 RefPtr<RefCountedAndHeapAllocated2> o4 = RefCountedAndHeapAllocated2 ::create();
356 void* objects[4] = { o1.get(), o2.get(), o3.get(), o4.get() }; 358 void* objects[4] = { o1.get(), o2.get(), o3.get(), o4.get() };
357 RefCountedHeapAllocatedHandleVisitor visitor(4, objects); 359 RefCountedHeapAllocatedHandleVisitor visitor(4, objects);
358 PersistentBase::visitRoots(&visitor); 360 PersistentBase::visitRoots(&visitor);
359 ASSERT_TRUE(visitor.validate()); 361 ASSERT_TRUE(visitor.validate());
360 362
361 Heap::collectGarbage(); 363 Heap::collectGarbage();
362 ASSERT_EQ(0, RefCountedAndHeapAllocated::s_destructorCalls); 364 ASSERT_EQ(0, RefCountedAndHeapAllocated::s_destructorCalls);
363 ASSERT_EQ(0, RefCountedAndHeapAllocated2::s_destructorCalls); 365 ASSERT_EQ(0, RefCountedAndHeapAllocated2::s_destructorCalls);
364 } 366 }
365 Heap::collectGarbage(); 367 Heap::collectGarbage();
366 ASSERT_EQ(2, RefCountedAndHeapAllocated::s_destructorCalls); 368 ASSERT_EQ(2, RefCountedAndHeapAllocated::s_destructorCalls);
367 ASSERT_EQ(2, RefCountedAndHeapAllocated2::s_destructorCalls); 369 ASSERT_EQ(2, RefCountedAndHeapAllocated2::s_destructorCalls);
368 } 370 }
369 371
372 static void refCountedHeapAllocatedWithHandlesTest()
373 {
374 RefCountedAndHeapAllocated::s_destructorCalls = 0;
375 RefCountedAndHeapAllocated2::s_destructorCalls = 0;
376 {
377 HandleScope scope;
378 Handle<RefCountedAndHeapAllocated> handle1;
379 Handle<RefCountedAndHeapAllocated> handle2;
380 {
381 RefPtr<RefCountedAndHeapAllocated> object1 = RefCountedAndHeapAl located::create();
382 RefPtr<RefCountedAndHeapAllocated> object2 = RefCountedAndHeapAl located::create();
383 handle1 = Handle<RefCountedAndHeapAllocated>(object1.get());
384 handle2 = Handle<RefCountedAndHeapAllocated>(object2.get());
385 void* objects[2] = { object1.get(), object2.get() };
386 RefCountedHeapAllocatedHandleVisitor visitor(2, objects);
387 PersistentBase::visitRoots(&visitor);
388 ASSERT_TRUE(visitor.validate());
389
390 Heap::collectGarbage();
391 ASSERT_EQ(0, RefCountedAndHeapAllocated::s_destructorCalls);
392 }
393 Heap::collectGarbage();
394 ASSERT_EQ(0, RefCountedAndHeapAllocated::s_destructorCalls);
395
396 // At this point, the reference counts of object1 and object2 are 0.
397 // Only handle1 and handle2 keep references to object1 and object2.
Mads Ager (google) 2013/05/29 13:47:54 Maybe check that PersistentBase::visitRoots does n
398
399 {
400 RefPtr<RefCountedAndHeapAllocated> object1 = adoptRef(handle1.ra w());
401 RefPtr<RefCountedAndHeapAllocated> object2 = adoptRef(handle2.ra w());
402 handle1 = Handle<RefCountedAndHeapAllocated>(object1.get());
Mads Ager (google) 2013/05/29 13:47:54 These lines are just reassigning the same value to
haraken 2013/05/29 14:52:16 Good catch! I verified that PersistentBase::visitR
403 handle2 = Handle<RefCountedAndHeapAllocated>(object2.get());
404
405 Heap::collectGarbage();
406 ASSERT_EQ(0, RefCountedAndHeapAllocated::s_destructorCalls);
407 }
408
409 Heap::collectGarbage();
410 ASSERT_EQ(0, RefCountedAndHeapAllocated::s_destructorCalls);
411 }
412 Heap::collectGarbage();
413 ASSERT_EQ(2, RefCountedAndHeapAllocated::s_destructorCalls);
414 }
415
370 static void markTest(); 416 static void markTest();
371 static void deepTest(); 417 static void deepTest();
372 static void wideTest(); 418 static void wideTest();
373 static void memberTest(); 419 static void memberTest();
374 }; 420 };
375 421
376 class Bar { 422 class Bar {
377 DECLARE_GC_TYPE_MARKER 423 DECLARE_GC_TYPE_MARKER
378 public: 424 public:
379 Bar() 425 Bar()
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 TEST(heap, Finalization) 623 TEST(heap, Finalization)
578 { 624 {
579 HeapTester::finalizationTest(); 625 HeapTester::finalizationTest();
580 } 626 }
581 627
582 TEST(heap, RefCountedHeapAllocated) 628 TEST(heap, RefCountedHeapAllocated)
583 { 629 {
584 HeapTester::refCountedHeapAllocatedTest(); 630 HeapTester::refCountedHeapAllocatedTest();
585 } 631 }
586 632
633 TEST(heap, RefCountedHeapAllocatedWithHandles)
634 {
635 HeapTester::refCountedHeapAllocatedWithHandlesTest();
636 }
637
587 TEST(heap, Mark) 638 TEST(heap, Mark)
588 { 639 {
589 HeapTester::markTest(); 640 HeapTester::markTest();
590 } 641 }
591 642
592 TEST(heap, Deep) 643 TEST(heap, Deep)
593 { 644 {
594 HeapTester::deepTest(); 645 HeapTester::deepTest();
595 } 646 }
596 647
597 TEST(heap, Wide) 648 TEST(heap, Wide)
598 { 649 {
599 HeapTester::wideTest(); 650 HeapTester::wideTest();
600 } 651 }
601 652
602 TEST(heap, Member) 653 TEST(heap, Member)
603 { 654 {
604 HeapTester::memberTest(); 655 HeapTester::memberTest();
605 } 656 }
606 657
607 } // namespace WebCore 658 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/heap/Heap.h ('k') | Source/wtf/RefCounted.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698