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

Side by Side Diff: Source/heap/Heap.h

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
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 16 matching lines...) Expand all
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #ifndef Heap_h 31 #ifndef Heap_h
32 #define Heap_h 32 #define Heap_h
33 33
34 #include "heap/Visitor.h" 34 #include "heap/Visitor.h"
35 #include <new> 35 #include <new>
36 #include <stddef.h> 36 #include <stddef.h>
37 #include <stdio.h>
Mads Ager (chromium) 2013/05/29 16:46:38 Remove.
haraken 2013/05/29 16:49:02 Done.
37 #include <wtf/Assertions.h> 38 #include <wtf/Assertions.h>
38 #include <wtf/Noncopyable.h> 39 #include <wtf/Noncopyable.h>
39 #include <wtf/RefCounted.h> 40 #include <wtf/RefCounted.h>
40 41
41 namespace WebCore { 42 namespace WebCore {
42 43
43 const size_t pageSizeLog2 = 17; 44 const size_t pageSizeLog2 = 17;
44 const size_t pageSize = 1 << pageSizeLog2; 45 const size_t pageSize = 1 << pageSizeLog2;
45 const size_t allocationGranularity = 8; 46 const size_t allocationGranularity = 8;
46 const size_t allocationMask = allocationGranularity - 1; 47 const size_t allocationMask = allocationGranularity - 1;
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 class RefCountedHeapAllocated : public RefCounted<T>, public HeapAllocatedFinali zed<T> { 431 class RefCountedHeapAllocated : public RefCounted<T>, public HeapAllocatedFinali zed<T> {
431 WTF_MAKE_NONCOPYABLE(RefCountedHeapAllocated); 432 WTF_MAKE_NONCOPYABLE(RefCountedHeapAllocated);
432 433
433 public: 434 public:
434 RefCountedHeapAllocated() 435 RefCountedHeapAllocated()
435 { 436 {
436 ASSERT(Heap::contains(reinterpret_cast<Address>(this))); 437 ASSERT(Heap::contains(reinterpret_cast<Address>(this)));
437 m_keepAlive = new Persistent<T>(static_cast<T*>(this)); 438 m_keepAlive = new Persistent<T>(static_cast<T*>(this));
438 } 439 }
439 440
441 // Override ref to deal with a case where a reference count goes up
442 // from 0 to 1. This can happen in the following scenario:
443 // (1) The reference count becomes 0, but Handles keep references to the obj ect.
444 // (2) The Handle is assigned to a RefPtr. The reference count becomes 1.
445 // In this case, we have to resurrect m_keepAlive.
446 void ref()
447 {
448 if (UNLIKELY(!RefCounted<T>::refCount())) {
449 ASSERT(!m_keepAlive);
450 ASSERT(Heap::contains(reinterpret_cast<Address>(this)));
451 m_keepAlive = new Persistent<T>(static_cast<T*>(this));
452 }
453 RefCounted<T>::refBase();
454 }
455
440 // Override deref to deal with our own deallocation based on ref counting. 456 // Override deref to deal with our own deallocation based on ref counting.
441 void deref() 457 void deref()
442 { 458 {
443 if (RefCounted<T>::derefBase()) 459 if (RefCounted<T>::derefBase()) {
444 delete m_keepAlive; 460 delete m_keepAlive;
461 m_keepAlive = 0;
462 }
445 } 463 }
446 464
447 // For now we don't trace through things that are still ref counted, so 465 // For now we don't trace through things that are still ref counted, so
448 // there is nothing to do in the accept method. 466 // there is nothing to do in the accept method.
449 void accept(Visitor*) { } 467 void accept(Visitor*) { }
450 468
451 protected: 469 protected:
452 ~RefCountedHeapAllocated() { } 470 ~RefCountedHeapAllocated() { }
453 471
454 private: 472 private:
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 // You can't mark an object that isn't in the heap. 578 // You can't mark an object that isn't in the heap.
561 ASSERT(contains(header)); 579 ASSERT(contains(header));
562 // End of object should also be in the heap. 580 // End of object should also be in the heap.
563 ASSERT(contains(header->payloadEnd() - 1)); 581 ASSERT(contains(header->payloadEnd() - 1));
564 header->mark(); 582 header->mark();
565 } 583 }
566 584
567 } // namespace WebCore 585 } // namespace WebCore
568 586
569 #endif 587 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698