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

Side by Side Diff: sky/engine/platform/heap/Handle.h

Issue 686783002: Remove almost all of Oilpan (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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 | « sky/engine/platform/heap/DEPS ('k') | sky/engine/platform/heap/ThreadState.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) 2014 Google Inc. All rights reserved. 2 * Copyright (C) 2014 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 13 matching lines...) Expand all
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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 Handle_h 31 #ifndef Handle_h
32 #define Handle_h 32 #define Handle_h
33 33
34 #include "platform/heap/ThreadState.h"
35 #include "platform/heap/Visitor.h"
36 #include "wtf/Functional.h" 34 #include "wtf/Functional.h"
37 #include "wtf/HashFunctions.h" 35 #include "wtf/HashFunctions.h"
38 #include "wtf/Locker.h" 36 #include "wtf/PassOwnPtr.h"
39 #include "wtf/RawPtr.h" 37 #include "wtf/RawPtr.h"
40 #include "wtf/RefCounted.h" 38 #include "wtf/RefCounted.h"
41 #include "wtf/TypeTraits.h" 39 #include "wtf/TypeTraits.h"
40 #include "wtf/text/AtomicString.h"
42 41
43 // Classes that contain heap references but aren't themselves heap 42 // Classes that contain heap references but aren't themselves heap
44 // allocated, have some extra macros available which allows their use 43 // allocated, have some extra macros available which allows their use
45 // to be restricted to cases where the garbage collector is able 44 // to be restricted to cases where the garbage collector is able
46 // to discover their heap references. 45 // to discover their heap references.
47 // 46 //
48 // STACK_ALLOCATED(): Use if the object is only stack allocated. Heap objects 47 // STACK_ALLOCATED(): Use if the object is only stack allocated. Heap objects
49 // should be in Members but you do not need the trace method as they are on 48 // should be in Members but you do not need the trace method as they are on
50 // the stack. (Down the line these might turn in to raw pointers, but for 49 // the stack. (Down the line these might turn in to raw pointers, but for
51 // now Members indicates that we have thought about them and explicitly 50 // now Members indicates that we have thought about them and explicitly
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 void* operator new(size_t) = delete; \ 90 void* operator new(size_t) = delete; \
92 void* operator new(size_t, NotNullTag, void*) = delete; \ 91 void* operator new(size_t, NotNullTag, void*) = delete; \
93 void* operator new(size_t, void*) = delete; 92 void* operator new(size_t, void*) = delete;
94 93
95 #else 94 #else
96 #define STACK_ALLOCATED() DISALLOW_ALLOCATION() 95 #define STACK_ALLOCATED() DISALLOW_ALLOCATION()
97 #endif 96 #endif
98 97
99 namespace blink { 98 namespace blink {
100 99
101 template<typename T> class HeapTerminatedArray; 100 class Visitor {
102
103 template<typename T> class Member;
104
105 class PersistentNode {
106 public: 101 public:
107 explicit PersistentNode(TraceCallback trace) 102 template<typename T>
108 : m_trace(trace) 103 void mark(T* t)
109 { 104 {
110 } 105 }
111 106 template<typename T>
112 bool isAlive() { return m_trace; } 107 void trace(const T* t)
113
114 virtual ~PersistentNode()
115 {
116 ASSERT(isAlive());
117 m_trace = 0;
118 }
119
120 // Ideally the trace method should be virtual and automatically dispatch
121 // to the most specific implementation. However having a virtual method
122 // on PersistentNode leads to too eager template instantiation with MSVC
123 // which leads to include cycles.
124 // Instead we call the constructor with a TraceCallback which knows the
125 // type of the most specific child and calls trace directly. See
126 // TraceMethodDelegate in Visitor.h for how this is done.
127 void trace(Visitor* visitor)
128 {
129 m_trace(visitor, this);
130 }
131
132 protected:
133 TraceCallback m_trace;
134
135 private:
136 PersistentNode* m_next;
137 PersistentNode* m_prev;
138
139 template<typename RootsAccessor, typename Owner> friend class PersistentBase ;
140 friend class PersistentAnchor;
141 };
142
143
144 // RootsAccessor for Persistent that provides access to thread-local list
145 // of persistent handles. Can only be used to create handles that
146 // are constructed and destructed on the same thread.
147 template<ThreadAffinity Affinity>
148 class ThreadLocalPersistents {
149 public:
150 static PersistentNode* roots() { return state()->roots(); }
151
152 // No locking required. Just check that we are at the right thread.
153 class Lock {
154 public:
155 Lock() { state()->checkThread(); }
156 };
157
158 private:
159 static ThreadState* state() { return ThreadStateFor<Affinity>::state(); }
160 };
161
162 // Base class for persistent handles. RootsAccessor specifies which list to
163 // link resulting handle into. Owner specifies the class containing trace
164 // method.
165 template<typename RootsAccessor, typename Owner>
166 class PersistentBase : public PersistentNode {
167 public:
168 ~PersistentBase()
169 {
170 typename RootsAccessor::Lock lock;
171 ASSERT(m_roots == RootsAccessor::roots()); // Check that the thread is u sing the same roots list.
172 ASSERT(isAlive());
173 ASSERT(m_next->isAlive());
174 ASSERT(m_prev->isAlive());
175 m_next->m_prev = m_prev;
176 m_prev->m_next = m_next;
177 }
178
179 protected:
180 inline PersistentBase()
181 : PersistentNode(TraceMethodDelegate<Owner, &Owner::trace>::trampoline)
182 #if ENABLE(ASSERT)
183 , m_roots(RootsAccessor::roots())
184 #endif
185 {
186 typename RootsAccessor::Lock lock;
187 m_prev = RootsAccessor::roots();
188 m_next = m_prev->m_next;
189 m_prev->m_next = this;
190 m_next->m_prev = this;
191 }
192
193 inline explicit PersistentBase(const PersistentBase& otherref)
194 : PersistentNode(otherref.m_trace)
195 #if ENABLE(ASSERT)
196 , m_roots(RootsAccessor::roots())
197 #endif
198 {
199 // We don't support allocation of thread local Persistents while doing
200 // thread shutdown/cleanup.
201 typename RootsAccessor::Lock lock;
202 ASSERT(otherref.m_roots == m_roots); // Handles must belong to the same list.
203 PersistentBase* other = const_cast<PersistentBase*>(&otherref);
204 m_prev = other;
205 m_next = other->m_next;
206 other->m_next = this;
207 m_next->m_prev = this;
208 }
209
210 inline PersistentBase& operator=(const PersistentBase& otherref) { return *t his; }
211
212 #if ENABLE(ASSERT)
213 private:
214 PersistentNode* m_roots;
215 #endif
216 };
217
218 // A dummy Persistent handle that ensures the list of persistents is never null.
219 // This removes a test from a hot path.
220 class PersistentAnchor : public PersistentNode {
221 public:
222 void trace(Visitor* visitor)
223 {
224 for (PersistentNode* current = m_next; current != this; current = curren t->m_next)
225 current->trace(visitor);
226 }
227
228 int numberOfPersistents()
229 {
230 int numberOfPersistents = 0;
231 for (PersistentNode* current = m_next; current != this; current = curren t->m_next)
232 ++numberOfPersistents;
233 return numberOfPersistents;
234 }
235
236 virtual ~PersistentAnchor()
237 {
238 // FIXME: oilpan: Ideally we should have no left-over persistents at thi s point. However currently there is a
239 // large number of objects leaked when we tear down the main thread. Sin ce some of these might contain a
240 // persistent or e.g. be RefCountedGarbageCollected we cannot guarantee there are no remaining Persistents at
241 // this point.
242 }
243
244 private:
245 PersistentAnchor() : PersistentNode(TraceMethodDelegate<PersistentAnchor, &P ersistentAnchor::trace>::trampoline)
246 {
247 m_next = this;
248 m_prev = this;
249 }
250
251 friend class ThreadState;
252 };
253
254 // Persistent handles are used to store pointers into the
255 // managed heap. As long as the Persistent handle is alive
256 // the GC will keep the object pointed to alive. Persistent
257 // handles can be stored in objects and they are not scoped.
258 // Persistent handles must not be used to contain pointers
259 // between objects that are in the managed heap. They are only
260 // meant to point to managed heap objects from variables/members
261 // outside the managed heap.
262 //
263 // A Persistent is always a GC root from the point of view of
264 // the garbage collector.
265 //
266 // We have to construct and destruct Persistent with default RootsAccessor in
267 // the same thread.
268 template<typename T, typename RootsAccessor = ThreadLocalPersistents<ThreadingTr ait<T>::Affinity > >
269 class Persistent : public PersistentBase<RootsAccessor, Persistent<T, RootsAcces sor> > {
270 WTF_DISALLOW_CONSTRUCTION_FROM_ZERO(Persistent);
271 WTF_DISALLOW_ZERO_ASSIGNMENT(Persistent);
272 public:
273 Persistent() : m_raw(0) { }
274
275 Persistent(std::nullptr_t) : m_raw(0) { }
276
277 Persistent(T* raw) : m_raw(raw)
278 {
279 recordBacktrace();
280 }
281
282 explicit Persistent(T& raw) : m_raw(&raw)
283 {
284 recordBacktrace();
285 }
286
287 Persistent(const Persistent& other) : m_raw(other) { recordBacktrace(); }
288
289 template<typename U>
290 Persistent(const Persistent<U, RootsAccessor>& other) : m_raw(other) { recor dBacktrace(); }
291
292 template<typename U>
293 Persistent(const Member<U>& other) : m_raw(other) { recordBacktrace(); }
294
295 template<typename U>
296 Persistent(const RawPtr<U>& other) : m_raw(other.get()) { recordBacktrace(); }
297
298 template<typename U>
299 Persistent& operator=(U* other)
300 {
301 m_raw = other;
302 recordBacktrace();
303 return *this;
304 }
305
306 Persistent& operator=(std::nullptr_t)
307 {
308 m_raw = 0;
309 return *this;
310 }
311
312 void clear() { m_raw = 0; }
313
314 virtual ~Persistent()
315 {
316 m_raw = 0;
317 }
318
319 template<typename U>
320 U* as() const
321 {
322 return static_cast<U*>(m_raw);
323 }
324
325 void trace(Visitor* visitor)
326 {
327 #if ENABLE(GC_PROFILE_MARKING)
328 visitor->setHostInfo(this, m_tracingName.isEmpty() ? "Persistent" : m_tr acingName);
329 #endif
330 visitor->mark(m_raw);
331 }
332
333 RawPtr<T> release()
334 {
335 RawPtr<T> result = m_raw;
336 m_raw = 0;
337 return result;
338 }
339
340 T& operator*() const { return *m_raw; }
341
342 bool operator!() const { return !m_raw; }
343
344 operator T*() const { return m_raw; }
345 operator RawPtr<T>() const { return m_raw; }
346
347 T* operator->() const { return *this; }
348
349 Persistent& operator=(const Persistent& other)
350 {
351 m_raw = other;
352 recordBacktrace();
353 return *this;
354 }
355
356 template<typename U>
357 Persistent& operator=(const Persistent<U, RootsAccessor>& other)
358 {
359 m_raw = other;
360 recordBacktrace();
361 return *this;
362 }
363
364 template<typename U>
365 Persistent& operator=(const Member<U>& other)
366 {
367 m_raw = other;
368 recordBacktrace();
369 return *this;
370 }
371
372 template<typename U>
373 Persistent& operator=(const RawPtr<U>& other)
374 {
375 m_raw = other;
376 recordBacktrace();
377 return *this;
378 }
379
380 T* get() const { return m_raw; }
381
382 private:
383 inline void recordBacktrace() const { }
384 T* m_raw;
385 };
386
387 // Members are used in classes to contain strong pointers to other oilpan heap
388 // allocated objects.
389 // All Member fields of a class must be traced in the class' trace method.
390 // During the mark phase of the GC all live objects are marked as live and
391 // all Member fields of a live object will be traced marked as live as well.
392 template<typename T>
393 class Member {
394 WTF_DISALLOW_CONSTRUCTION_FROM_ZERO(Member);
395 WTF_DISALLOW_ZERO_ASSIGNMENT(Member);
396 public:
397 Member() : m_raw(0)
398 { 108 {
399 } 109 }
400 110 template<typename T>
401 Member(std::nullptr_t) : m_raw(0) 111 void trace(T* t)
402 { 112 {
403 } 113 }
404 114 template<typename T>
405 Member(T* raw) : m_raw(raw) 115 void trace(const T& t)
406 {
407 }
408
409 explicit Member(T& raw) : m_raw(&raw)
410 {
411 }
412
413 template<typename U>
414 Member(const RawPtr<U>& other) : m_raw(other.get())
415 {
416 }
417
418 Member(WTF::HashTableDeletedValueType) : m_raw(reinterpret_cast<T*>(-1))
419 {
420 }
421
422 bool isHashTableDeletedValue() const { return m_raw == reinterpret_cast<T*>( -1); }
423
424 template<typename U>
425 Member(const Persistent<U>& other) : m_raw(other) { }
426
427 Member(const Member& other) : m_raw(other) { }
428
429 template<typename U>
430 Member(const Member<U>& other) : m_raw(other) { }
431
432 T* release()
433 {
434 T* result = m_raw;
435 m_raw = 0;
436 return result;
437 }
438
439 template<typename U>
440 U* as() const
441 {
442 return static_cast<U*>(m_raw);
443 }
444
445 bool operator!() const { return !m_raw; }
446
447 operator T*() const { return m_raw; }
448
449 T* operator->() const { return m_raw; }
450 T& operator*() const { return *m_raw; }
451 template<typename U>
452 operator RawPtr<U>() const { return m_raw; }
453
454 template<typename U>
455 Member& operator=(const Persistent<U>& other)
456 {
457 m_raw = other;
458 return *this;
459 }
460
461 template<typename U>
462 Member& operator=(const Member<U>& other)
463 {
464 m_raw = other;
465 return *this;
466 }
467
468 template<typename U>
469 Member& operator=(U* other)
470 {
471 m_raw = other;
472 return *this;
473 }
474
475 template<typename U>
476 Member& operator=(RawPtr<U> other)
477 {
478 m_raw = other;
479 return *this;
480 }
481
482 Member& operator=(std::nullptr_t)
483 {
484 m_raw = 0;
485 return *this;
486 }
487
488 void swap(Member<T>& other) { std::swap(m_raw, other.m_raw); }
489
490 T* get() const { return m_raw; }
491
492 void clear() { m_raw = 0; }
493
494
495 protected:
496 void verifyTypeIsGarbageCollected() const
497 {
498 }
499
500 T* m_raw;
501
502 friend class Visitor;
503 };
504
505 template<typename T>
506 class TraceTrait<Member<T> > {
507 public:
508 static void trace(Visitor* visitor, void* self)
509 {
510 TraceTrait<T>::mark(visitor, *static_cast<Member<T>*>(self));
511 }
512 };
513
514 // TraceTrait to allow compilation of trace method bodies when oilpan is disable d.
515 // This should never be called, but is needed to compile.
516 template<typename T>
517 class TraceTrait<RefPtr<T> > {
518 public:
519 static void trace(Visitor*, void*)
520 {
521 ASSERT_NOT_REACHED();
522 }
523 };
524
525 template<typename T>
526 class TraceTrait<OwnPtr<T> > {
527 public:
528 static void trace(Visitor* visitor, OwnPtr<T>* ptr)
529 {
530 ASSERT_NOT_REACHED();
531 }
532 };
533
534 template <typename T> struct RemoveHeapPointerWrapperTypes {
535 typedef typename WTF::RemoveTemplate<typename WTF::RemoveTemplate<typename W TF::RemoveTemplate<T, Member>::Type, WeakMember>::Type, RawPtr>::Type Type;
536 };
537
538 // This trace trait for std::pair will null weak members if their referent is
539 // collected. If you have a collection that contain weakness it does not remove
540 // entries from the collection that contain nulled weak members.
541 template<typename T, typename U>
542 class TraceTrait<std::pair<T, U> > {
543 public:
544 static void trace(Visitor* visitor, std::pair<T, U>* pair)
545 { 116 {
546 } 117 }
547 }; 118 };
548 119
549 // WeakMember is similar to Member in that it is used to point to other oilpan 120 #define WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(TYPE)
550 // heap allocated objects.
551 // However instead of creating a strong pointer to the object, the WeakMember cr eates
552 // a weak pointer, which does not keep the pointee alive. Hence if all pointers to
553 // to a heap allocated object are weak the object will be garbage collected. At the
554 // time of GC the weak pointers will automatically be set to null.
555 template<typename T>
556 class WeakMember : public Member<T> {
557 WTF_DISALLOW_CONSTRUCTION_FROM_ZERO(WeakMember);
558 WTF_DISALLOW_ZERO_ASSIGNMENT(WeakMember);
559 public:
560 WeakMember() : Member<T>() { }
561
562 WeakMember(std::nullptr_t) : Member<T>(nullptr) { }
563
564 WeakMember(T* raw) : Member<T>(raw) { }
565
566 WeakMember(WTF::HashTableDeletedValueType x) : Member<T>(x) { }
567
568 template<typename U>
569 WeakMember(const Persistent<U>& other) : Member<T>(other) { }
570
571 template<typename U>
572 WeakMember(const Member<U>& other) : Member<T>(other) { }
573
574 template<typename U>
575 WeakMember& operator=(const Persistent<U>& other)
576 {
577 this->m_raw = other;
578 return *this;
579 }
580
581 template<typename U>
582 WeakMember& operator=(const Member<U>& other)
583 {
584 this->m_raw = other;
585 return *this;
586 }
587
588 template<typename U>
589 WeakMember& operator=(U* other)
590 {
591 this->m_raw = other;
592 return *this;
593 }
594
595 template<typename U>
596 WeakMember& operator=(const RawPtr<U>& other)
597 {
598 this->m_raw = other;
599 return *this;
600 }
601
602 WeakMember& operator=(std::nullptr_t)
603 {
604 this->m_raw = 0;
605 return *this;
606 }
607
608 private:
609 T** cell() const { return const_cast<T**>(&this->m_raw); }
610
611 friend class Visitor;
612 };
613
614 // Comparison operators between (Weak)Members and Persistents
615 template<typename T, typename U> inline bool operator==(const Member<T>& a, cons t Member<U>& b) { return a.get() == b.get(); }
616 template<typename T, typename U> inline bool operator!=(const Member<T>& a, cons t Member<U>& b) { return a.get() != b.get(); }
617 template<typename T, typename U> inline bool operator==(const Member<T>& a, cons t Persistent<U>& b) { return a.get() == b.get(); }
618 template<typename T, typename U> inline bool operator!=(const Member<T>& a, cons t Persistent<U>& b) { return a.get() != b.get(); }
619 template<typename T, typename U> inline bool operator==(const Persistent<T>& a, const Member<U>& b) { return a.get() == b.get(); }
620 template<typename T, typename U> inline bool operator!=(const Persistent<T>& a, const Member<U>& b) { return a.get() != b.get(); }
621 template<typename T, typename U> inline bool operator==(const Persistent<T>& a, const Persistent<U>& b) { return a.get() == b.get(); }
622 template<typename T, typename U> inline bool operator!=(const Persistent<T>& a, const Persistent<U>& b) { return a.get() != b.get(); }
623
624 121
625 template<typename T> 122 template<typename T>
626 class DummyBase { 123 class DummyBase {
627 public: 124 public:
628 DummyBase() { } 125 DummyBase() { }
629 ~DummyBase() { } 126 ~DummyBase() { }
630 }; 127 };
631 128
632 #define WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED WTF_MAKE_FAST_ALLOCATED 129 #define WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED WTF_MAKE_FAST_ALLOCATED
633 #define DECLARE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(type) \ 130 #define DECLARE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(type) \
634 public: \ 131 public: \
635 ~type(); \ 132 ~type(); \
636 private: 133 private:
637 #define DECLARE_EMPTY_VIRTUAL_DESTRUCTOR_WILL_BE_REMOVED(type) \ 134 #define DECLARE_EMPTY_VIRTUAL_DESTRUCTOR_WILL_BE_REMOVED(type) \
638 public: \ 135 public: \
639 virtual ~type(); \ 136 virtual ~type(); \
640 private: 137 private:
641 138
642 #define DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(type) \ 139 #define DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(type) \
643 type::~type() { } 140 type::~type() { }
644 141
645 #define DEFINE_STATIC_REF_WILL_BE_PERSISTENT(type, name, arguments) \ 142 #define DEFINE_STATIC_REF_WILL_BE_PERSISTENT(type, name, arguments) \
646 DEFINE_STATIC_REF(type, name, arguments) 143 DEFINE_STATIC_REF(type, name, arguments)
647 144
648 } // namespace blink 145 } // namespace blink
649 146
650 namespace WTF { 147 namespace WTF {
651 148
652 template <typename T> struct VectorTraits<blink::Member<T> > : VectorTraitsBase< blink::Member<T> > {
653 static const bool needsDestruction = false;
654 static const bool canInitializeWithMemset = true;
655 static const bool canMoveWithMemcpy = true;
656 };
657
658 template <typename T> struct VectorTraits<blink::WeakMember<T> > : VectorTraitsB ase<blink::WeakMember<T> > {
659 static const bool needsDestruction = false;
660 static const bool canInitializeWithMemset = true;
661 static const bool canMoveWithMemcpy = true;
662 };
663
664 template<typename T> struct HashTraits<blink::Member<T> > : SimpleClassHashTrait s<blink::Member<T> > {
665 static const bool needsDestruction = false;
666 // FIXME: The distinction between PeekInType and PassInType is there for
667 // the sake of the reference counting handles. When they are gone the two
668 // types can be merged into PassInType.
669 // FIXME: Implement proper const'ness for iterator types. Requires support
670 // in the marking Visitor.
671 typedef RawPtr<T> PeekInType;
672 typedef RawPtr<T> PassInType;
673 typedef blink::Member<T>* IteratorGetType;
674 typedef const blink::Member<T>* IteratorConstGetType;
675 typedef blink::Member<T>& IteratorReferenceType;
676 typedef T* const IteratorConstReferenceType;
677 static IteratorReferenceType getToReferenceConversion(IteratorGetType x) { r eturn *x; }
678 static IteratorConstReferenceType getToReferenceConstConversion(IteratorCons tGetType x) { return x->get(); }
679 // FIXME: Similarly, there is no need for a distinction between PeekOutType
680 // and PassOutType without reference counting.
681 typedef T* PeekOutType;
682 typedef T* PassOutType;
683
684 template<typename U>
685 static void store(const U& value, blink::Member<T>& storage) { storage = val ue; }
686
687 static PeekOutType peek(const blink::Member<T>& value) { return value; }
688 static PassOutType passOut(const blink::Member<T>& value) { return value; }
689 };
690
691 template<typename T> struct HashTraits<blink::WeakMember<T> > : SimpleClassHashT raits<blink::WeakMember<T> > {
692 static const bool needsDestruction = false;
693 // FIXME: The distinction between PeekInType and PassInType is there for
694 // the sake of the reference counting handles. When they are gone the two
695 // types can be merged into PassInType.
696 // FIXME: Implement proper const'ness for iterator types. Requires support
697 // in the marking Visitor.
698 typedef RawPtr<T> PeekInType;
699 typedef RawPtr<T> PassInType;
700 typedef blink::WeakMember<T>* IteratorGetType;
701 typedef const blink::WeakMember<T>* IteratorConstGetType;
702 typedef blink::WeakMember<T>& IteratorReferenceType;
703 typedef T* const IteratorConstReferenceType;
704 static IteratorReferenceType getToReferenceConversion(IteratorGetType x) { r eturn *x; }
705 static IteratorConstReferenceType getToReferenceConstConversion(IteratorCons tGetType x) { return x->get(); }
706 // FIXME: Similarly, there is no need for a distinction between PeekOutType
707 // and PassOutType without reference counting.
708 typedef T* PeekOutType;
709 typedef T* PassOutType;
710
711 template<typename U>
712 static void store(const U& value, blink::WeakMember<T>& storage) { storage = value; }
713
714 static PeekOutType peek(const blink::WeakMember<T>& value) { return value; }
715 static PassOutType passOut(const blink::WeakMember<T>& value) { return value ; }
716 static bool traceInCollection(blink::Visitor* visitor, blink::WeakMember<T>& weakMember, ShouldWeakPointersBeMarkedStrongly strongify)
717 {
718 }
719 };
720
721 template<typename T> struct PtrHash<blink::Member<T> > : PtrHash<T*> {
722 template<typename U>
723 static unsigned hash(const U& key) { return PtrHash<T*>::hash(key); }
724 static bool equal(T* a, const blink::Member<T>& b) { return a == b; }
725 static bool equal(const blink::Member<T>& a, T* b) { return a == b; }
726 template<typename U, typename V>
727 static bool equal(const U& a, const V& b) { return a == b; }
728 };
729
730 template<typename T> struct PtrHash<blink::WeakMember<T> > : PtrHash<blink::Memb er<T> > {
731 };
732
733 template<typename P> struct PtrHash<blink::Persistent<P> > : PtrHash<P*> {
734 using PtrHash<P*>::hash;
735 static unsigned hash(const RefPtr<P>& key) { return hash(key.get()); }
736 using PtrHash<P*>::equal;
737 static bool equal(const RefPtr<P>& a, const RefPtr<P>& b) { return a == b; }
738 static bool equal(P* a, const RefPtr<P>& b) { return a == b; }
739 static bool equal(const RefPtr<P>& a, P* b) { return a == b; }
740 };
741
742 // PtrHash is the default hash for hash tables with members.
743 template<typename T> struct DefaultHash<blink::Member<T> > {
744 typedef PtrHash<blink::Member<T> > Hash;
745 };
746
747 template<typename T> struct DefaultHash<blink::WeakMember<T> > {
748 typedef PtrHash<blink::WeakMember<T> > Hash;
749 };
750
751 template<typename T> struct DefaultHash<blink::Persistent<T> > {
752 typedef PtrHash<blink::Persistent<T> > Hash;
753 };
754
755 template<typename T>
756 struct NeedsTracing<blink::Member<T> > {
757 static const bool value = true;
758 };
759
760 template<typename T>
761 struct IsWeak<blink::WeakMember<T> > {
762 static const bool value = true;
763 };
764
765 template<typename T> inline T* getPtr(const blink::Member<T>& p)
766 {
767 return p.get();
768 }
769
770 template<typename T> inline T* getPtr(const blink::Persistent<T>& p)
771 {
772 return p.get();
773 }
774
775 // For wtf/Functional.h 149 // For wtf/Functional.h
776 template<typename T, bool isGarbageCollected> struct PointerParamStorageTraits; 150 template<typename T, bool isGarbageCollected> struct PointerParamStorageTraits;
777 151
778 template<typename T> 152 template<typename T>
779 struct PointerParamStorageTraits<T*, false> { 153 struct PointerParamStorageTraits<T*, false> {
780 typedef T* StorageType; 154 typedef T* StorageType;
781 155
782 static StorageType wrap(T* value) { return value; } 156 static StorageType wrap(T* value) { return value; }
783 static T* unwrap(const StorageType& value) { return value; } 157 static T* unwrap(const StorageType& value) { return value; }
784 }; 158 };
785 159
786 template<typename T> 160 template<typename T>
787 struct ParamStorageTraits<T*> : public PointerParamStorageTraits<T*, false> { 161 struct ParamStorageTraits<T*> : public PointerParamStorageTraits<T*, false> {
788 }; 162 };
789 163
790 template<typename T> 164 template<typename T>
791 struct ParamStorageTraits<RawPtr<T> > : public PointerParamStorageTraits<T*, fal se> { 165 struct ParamStorageTraits<RawPtr<T> > : public PointerParamStorageTraits<T*, fal se> {
792 }; 166 };
793 167
794 } // namespace WTF 168 } // namespace WTF
795 169
796 #endif 170 #endif
OLDNEW
« no previous file with comments | « sky/engine/platform/heap/DEPS ('k') | sky/engine/platform/heap/ThreadState.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698