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

Side by Side Diff: Source/core/dom/TreeShared.h

Issue 262093006: Oilpan: Make the Node hierarchy RefCountedGarbageCollected instead of TreeShared. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Another build fix. Created 6 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007, 2009, 2010, 2012 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2009, 2010, 2012 Apple Inc. All rights reserved.
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 20 matching lines...) Expand all
31 #if SECURITY_ASSERT_ENABLED 31 #if SECURITY_ASSERT_ENABLED
32 template<typename NodeType> class TreeShared; 32 template<typename NodeType> class TreeShared;
33 template<typename NodeType> void adopted(TreeShared<NodeType>*); 33 template<typename NodeType> void adopted(TreeShared<NodeType>*);
34 #endif 34 #endif
35 35
36 template<typename NodeType> class TreeShared : public NoBaseWillBeGarbageCollect edFinalized<NodeType> { 36 template<typename NodeType> class TreeShared : public NoBaseWillBeGarbageCollect edFinalized<NodeType> {
37 WTF_MAKE_NONCOPYABLE(TreeShared); 37 WTF_MAKE_NONCOPYABLE(TreeShared);
38 protected: 38 protected:
39 TreeShared() 39 TreeShared()
40 : m_refCount(1) 40 : m_refCount(1)
41 #if ENABLE(OILPAN)
42 , m_keepAlive(adoptPtr(new Persistent<NodeType>(static_cast<NodeType*>(t his))))
43 #endif
44 #if SECURITY_ASSERT_ENABLED 41 #if SECURITY_ASSERT_ENABLED
45 , m_deletionHasBegun(false) 42 , m_deletionHasBegun(false)
46 #if ASSERT_ENABLED 43 #if ASSERT_ENABLED
47 , m_inRemovedLastRefFunction(false) 44 , m_inRemovedLastRefFunction(false)
48 , m_adoptionIsRequired(true) 45 , m_adoptionIsRequired(true)
49 #endif 46 #endif
50 #endif 47 #endif
51 { 48 {
52 ASSERT(isMainThread()); 49 ASSERT(isMainThread());
53 } 50 }
54 51
55 ~TreeShared() 52 ~TreeShared()
56 { 53 {
57 ASSERT(isMainThread()); 54 ASSERT(isMainThread());
58 ASSERT(!m_refCount); 55 ASSERT(!m_refCount);
59 #if !ENABLE(OILPAN)
60 ASSERT_WITH_SECURITY_IMPLICATION(m_deletionHasBegun); 56 ASSERT_WITH_SECURITY_IMPLICATION(m_deletionHasBegun);
61 #else
62 ASSERT(!m_keepAlive);
63 #endif
64 ASSERT(!m_adoptionIsRequired); 57 ASSERT(!m_adoptionIsRequired);
65 } 58 }
66 59
67 public: 60 public:
68 void ref() 61 void ref()
69 { 62 {
70 ASSERT(isMainThread()); 63 ASSERT(isMainThread());
71 #if !ENABLE(OILPAN)
72 ASSERT_WITH_SECURITY_IMPLICATION(!m_deletionHasBegun); 64 ASSERT_WITH_SECURITY_IMPLICATION(!m_deletionHasBegun);
73 ASSERT(!m_inRemovedLastRefFunction); 65 ASSERT(!m_inRemovedLastRefFunction);
74 #endif
75 ASSERT(!m_adoptionIsRequired); 66 ASSERT(!m_adoptionIsRequired);
76 ++m_refCount; 67 ++m_refCount;
77 #if ENABLE(OILPAN)
78 if (!m_keepAlive)
79 m_keepAlive = adoptPtr(new Persistent<NodeType>(static_cast<NodeType *>(this)));
80 #endif
81 } 68 }
82 69
83 void deref() 70 void deref()
84 { 71 {
85 ASSERT(isMainThread()); 72 ASSERT(isMainThread());
86 ASSERT(m_refCount > 0); 73 ASSERT(m_refCount > 0);
87 #if !ENABLE(OILPAN)
88 ASSERT_WITH_SECURITY_IMPLICATION(!m_deletionHasBegun); 74 ASSERT_WITH_SECURITY_IMPLICATION(!m_deletionHasBegun);
89 ASSERT(!m_inRemovedLastRefFunction); 75 ASSERT(!m_inRemovedLastRefFunction);
90 #endif
91 ASSERT(!m_adoptionIsRequired); 76 ASSERT(!m_adoptionIsRequired);
92 NodeType* thisNode = static_cast<NodeType*>(this); 77 NodeType* thisNode = static_cast<NodeType*>(this);
93 if (!--m_refCount && !thisNode->hasTreeSharedParent()) { 78 if (!--m_refCount && !thisNode->hasTreeSharedParent()) {
94 #if !ASSERT_DISABLED 79 #if !ASSERT_DISABLED
95 m_inRemovedLastRefFunction = true; 80 m_inRemovedLastRefFunction = true;
96 #endif 81 #endif
97 #if ENABLE(OILPAN)
98 clearKeepAlive();
99 #endif
100 thisNode->removedLastRef(); 82 thisNode->removedLastRef();
101 } 83 }
102 } 84 }
103 85
104 int refCount() const { return m_refCount; } 86 int refCount() const { return m_refCount; }
105 87
106 #if ENABLE(OILPAN)
107 void clearKeepAlive()
108 {
109 ASSERT(m_keepAlive);
110 m_keepAlive = nullptr;
111 }
112 #endif
113
114 private: 88 private:
115 int m_refCount; 89 int m_refCount;
116 90
117 #if ENABLE(OILPAN)
118 // With Oilpan, a non-zero reference count will keep the TreeShared object a live
119 // with a self-persistent handle. Whenever the ref count goes above zero
120 // we register the TreeShared as a root for garbage collection by allocating a
121 // persistent handle to the object itself. When the ref count goes to zero
122 // we deallocate the persistent handle again so the object can die if there
123 // are no other things keeping it alive.
124 //
125 // FIXME: Oilpan: Remove m_keepAlive and ref counting and use tracing instea d.
126 OwnPtr<Persistent<NodeType> > m_keepAlive;
127 #endif
128
129 #if SECURITY_ASSERT_ENABLED 91 #if SECURITY_ASSERT_ENABLED
130 public: 92 public:
131 bool m_deletionHasBegun; 93 bool m_deletionHasBegun;
132 #if ASSERT_ENABLED 94 #if ASSERT_ENABLED
133 bool m_inRemovedLastRefFunction; 95 bool m_inRemovedLastRefFunction;
134 96
135 private: 97 private:
136 friend void adopted<>(TreeShared<NodeType>*); 98 friend void adopted<>(TreeShared<NodeType>*);
137 bool m_adoptionIsRequired; 99 bool m_adoptionIsRequired;
138 #endif 100 #endif
(...skipping 10 matching lines...) Expand all
149 #if !ASSERT_DISABLED 111 #if !ASSERT_DISABLED
150 ASSERT(!object->m_inRemovedLastRefFunction); 112 ASSERT(!object->m_inRemovedLastRefFunction);
151 object->m_adoptionIsRequired = false; 113 object->m_adoptionIsRequired = false;
152 #endif 114 #endif
153 } 115 }
154 #endif 116 #endif
155 117
156 } 118 }
157 119
158 #endif // TreeShared.h 120 #endif // TreeShared.h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698