OLD | NEW |
---|---|
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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
53 template<typename A, typename B, typename C, typename D, typename E, typename F, typename G> class HashTableConstIterator; | 53 template<typename A, typename B, typename C, typename D, typename E, typename F, typename G> class HashTableConstIterator; |
54 | 54 |
55 } | 55 } |
56 | 56 |
57 namespace WebCore { | 57 namespace WebCore { |
58 | 58 |
59 // Forward declarations. | 59 // Forward declarations. |
60 template<typename T> class Member; | 60 template<typename T> class Member; |
61 template<typename T> class WeakMember; | 61 template<typename T> class WeakMember; |
62 template<typename T> struct HeapObjectHash; | 62 template<typename T> struct HeapObjectHash; |
63 template<typename T> struct CollectionVisitingTrait; | 63 template<typename T> struct OffHeapCollectionTraceTrait; |
wibling-chromium
2013/12/05 12:37:17
NIT: Shouldn't this be OffHeapCollectionMarkTrait?
Mads Ager (chromium)
2013/12/05 12:41:17
I found it more fitting to call it a TraceTrait. T
| |
64 | 64 |
65 #if defined(TRACE_GC_MARKING) && TRACE_GC_MARKING | 65 #if defined(TRACE_GC_MARKING) && TRACE_GC_MARKING |
66 // To print root names during marking for CollectionPersistent and Persistent ha ndles | 66 // To print root names during marking for CollectionPersistent and Persistent ha ndles |
67 // we prepend annotation objects to this fields using ANNOTATED_FIELD macro. | 67 // we prepend annotation objects to this fields using ANNOTATED_FIELD macro. |
68 // Annotation object must directly preceed Persistent handles in memory. | 68 // Annotation object must directly preceed Persistent handles in memory. |
69 // It is conservatively detected by the presence of magic. This can have some | 69 // It is conservatively detected by the presence of magic. This can have some |
70 // false-positives but TRACE_GC_MARKING is debugging functionality so | 70 // false-positives but TRACE_GC_MARKING is debugging functionality so |
71 // we don't care. | 71 // we don't care. |
72 typedef const char* (*NameCallback)(); | 72 typedef const char* (*NameCallback)(); |
73 | 73 |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
279 { | 279 { |
280 m_raw = 0; | 280 m_raw = 0; |
281 } | 281 } |
282 | 282 |
283 template<typename U> | 283 template<typename U> |
284 U* as() const | 284 U* as() const |
285 { | 285 { |
286 return static_cast<U*>(m_raw); | 286 return static_cast<U*>(m_raw); |
287 } | 287 } |
288 | 288 |
289 void trace(Visitor* visitor) { visitor->visit(m_raw); } | 289 void trace(Visitor* visitor) { visitor->mark(m_raw); } |
290 | 290 |
291 T* clear() | 291 T* clear() |
292 { | 292 { |
293 T* result = m_raw; | 293 T* result = m_raw; |
294 m_raw = 0; | 294 m_raw = 0; |
295 return result; | 295 return result; |
296 } | 296 } |
297 | 297 |
298 T* raw() const { return m_raw; } | 298 T* raw() const { return m_raw; } |
299 T& operator*() const { return *raw(); } | 299 T& operator*() const { return *raw(); } |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
488 template<typename U, typename V> friend bool operator!=(const Persistent<U>& , const Member<V>&); | 488 template<typename U, typename V> friend bool operator!=(const Persistent<U>& , const Member<V>&); |
489 template<typename U, typename V> friend bool operator==(const Member<U>&, co nst Member<V>&); | 489 template<typename U, typename V> friend bool operator==(const Member<U>&, co nst Member<V>&); |
490 template<typename U, typename V> friend bool operator!=(const Member<U>&, co nst Member<V>&); | 490 template<typename U, typename V> friend bool operator!=(const Member<U>&, co nst Member<V>&); |
491 }; | 491 }; |
492 | 492 |
493 template<typename T> | 493 template<typename T> |
494 class TraceTrait<Member<T> > { | 494 class TraceTrait<Member<T> > { |
495 public: | 495 public: |
496 static void trace(Visitor* visitor, void* self) | 496 static void trace(Visitor* visitor, void* self) |
497 { | 497 { |
498 TraceTrait<T>::visit(visitor, static_cast<Member<T>*>(self)->raw()); | 498 TraceTrait<T>::mark(visitor, static_cast<Member<T>*>(self)->raw()); |
499 } | 499 } |
500 }; | 500 }; |
501 | 501 |
502 template<typename T> | 502 template<typename T> |
503 class WeakMember : public Member<T> { | 503 class WeakMember : public Member<T> { |
504 public: | 504 public: |
505 WeakMember() : Member<T>() { } | 505 WeakMember() : Member<T>() { } |
506 | 506 |
507 WeakMember(T* raw) : Member<T>(raw) { } | 507 WeakMember(T* raw) : Member<T>(raw) { } |
508 | 508 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
590 explicit CollectionPersistent(const Collection& collection) : m_collection(c ollection) { } | 590 explicit CollectionPersistent(const Collection& collection) : m_collection(c ollection) { } |
591 CollectionPersistent& operator=(const Collection& collection) { m_collection = collection; return *this; } | 591 CollectionPersistent& operator=(const Collection& collection) { m_collection = collection; return *this; } |
592 | 592 |
593 Collection* operator->() { return &m_collection; } | 593 Collection* operator->() { return &m_collection; } |
594 const Collection* operator->() const { return &m_collection; } | 594 const Collection* operator->() const { return &m_collection; } |
595 Collection& operator*() { return m_collection; } | 595 Collection& operator*() { return m_collection; } |
596 const Collection& operator*() const { return m_collection; } | 596 const Collection& operator*() const { return m_collection; } |
597 | 597 |
598 void trace(Visitor* visitor) | 598 void trace(Visitor* visitor) |
599 { | 599 { |
600 CollectionVisitingTrait<Collection>::visit(visitor, m_collection); | 600 OffHeapCollectionTraceTrait<Collection>::mark(visitor, m_collection); |
601 } | 601 } |
602 | 602 |
603 #if defined(TRACE_GC_MARKING) && TRACE_GC_MARKING | 603 #if defined(TRACE_GC_MARKING) && TRACE_GC_MARKING |
604 virtual const char* name() OVERRIDE | 604 virtual const char* name() OVERRIDE |
605 { | 605 { |
606 ASSERT(this == static_cast<PersistentNode*>(this)); | 606 ASSERT(this == static_cast<PersistentNode*>(this)); |
607 const char* n = FieldAnnotationBase::fromAddress(this); | 607 const char* n = FieldAnnotationBase::fromAddress(this); |
608 return n ? n : "CollectionPersistent"; | 608 return n ? n : "CollectionPersistent"; |
609 } | 609 } |
610 #endif | 610 #endif |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
710 } | 710 } |
711 | 711 |
712 static const bool heapAllocation = true; | 712 static const bool heapAllocation = true; |
713 | 713 |
714 typedef NoAllocation<MainThreadOnly> NoAllocationObject; | 714 typedef NoAllocation<MainThreadOnly> NoAllocationObject; |
715 | 715 |
716 typedef WebCore::Visitor Visitor; | 716 typedef WebCore::Visitor Visitor; |
717 | 717 |
718 static void visitHeapPointer(Visitor* visitor, const void* buffer) | 718 static void visitHeapPointer(Visitor* visitor, const void* buffer) |
719 { | 719 { |
720 visitor->visit(buffer, FinalizedHeapObjectHeader::fromPayload(buffer)->t raceCallback()); | 720 visitor->mark(buffer, FinalizedHeapObjectHeader::fromPayload(buffer)->tr aceCallback()); |
721 } | 721 } |
722 | 722 |
723 static void visitWith(Visitor* visitor, const void* t) | 723 static void adjustAndMark(Visitor* visitor, const void* t) |
724 { | 724 { |
725 visitor->visit(t); | 725 visitor->mark(t); |
726 } | 726 } |
727 | 727 |
728 template<typename T, typename Traits> | 728 template<typename T, typename Traits> |
729 static void visitWith(Visitor* visitor, T& t) | 729 static void adjustAndMark(Visitor* visitor, T& t) |
730 { | 730 { |
731 VisitCollectionBackingTrait<Traits::needsVisiting, Traits::isWeak, false , T, Traits>::visit(visitor, t); | 731 CollectionBackingTraceTrait<Traits::needsMarking, Traits::isWeak, false, T, Traits>::mark(visitor, t); |
732 } | 732 } |
733 | 733 |
734 template<typename T> | 734 template<typename T> |
735 static bool hasDeadMember(Visitor* visitor, const T& t) | 735 static bool hasDeadMember(Visitor* visitor, const T& t) |
736 { | 736 { |
737 return false; | 737 return false; |
738 } | 738 } |
739 | 739 |
740 template<typename T> | 740 template<typename T> |
741 static bool hasDeadMember(Visitor* visitor, const Member<T>& t) | 741 static bool hasDeadMember(Visitor* visitor, const Member<T>& t) |
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1278 // HeapObjectHash<T> instead. | 1278 // HeapObjectHash<T> instead. |
1279 template<typename T> struct DefaultHash<WebCore::Member<T> > { | 1279 template<typename T> struct DefaultHash<WebCore::Member<T> > { |
1280 typedef PtrHash<WebCore::Member<T> > Hash; | 1280 typedef PtrHash<WebCore::Member<T> > Hash; |
1281 }; | 1281 }; |
1282 | 1282 |
1283 template<typename T> struct DefaultHash<WebCore::WeakMember<T> > { | 1283 template<typename T> struct DefaultHash<WebCore::WeakMember<T> > { |
1284 typedef PtrHash<WebCore::WeakMember<T> > Hash; | 1284 typedef PtrHash<WebCore::WeakMember<T> > Hash; |
1285 }; | 1285 }; |
1286 | 1286 |
1287 template<typename T> | 1287 template<typename T> |
1288 struct NeedsVisiting<WebCore::Member<T> > { | 1288 struct NeedsMarking<WebCore::Member<T> > { |
1289 static const bool value = true; | 1289 static const bool value = true; |
1290 }; | 1290 }; |
1291 | 1291 |
1292 template<typename T> | 1292 template<typename T> |
1293 struct IsWeak<WebCore::WeakMember<T> > { | 1293 struct IsWeak<WebCore::WeakMember<T> > { |
1294 static const bool value = true; | 1294 static const bool value = true; |
1295 }; | 1295 }; |
1296 | 1296 |
1297 template<typename T, size_t inlinedCapacity> | 1297 template<typename T, size_t inlinedCapacity> |
1298 struct IsPod<WebCore::HeapVector<T, inlinedCapacity> > { | 1298 struct IsPod<WebCore::HeapVector<T, inlinedCapacity> > { |
1299 static const bool value = true; | 1299 static const bool value = true; |
1300 }; | 1300 }; |
1301 | 1301 |
1302 template<typename T, size_t inlinedCapacity> | 1302 template<typename T, size_t inlinedCapacity> |
1303 struct NeedsVisiting<WebCore::HeapVector<T, inlinedCapacity> > { | 1303 struct NeedsMarking<WebCore::HeapVector<T, inlinedCapacity> > { |
1304 static const bool value = true; | 1304 static const bool value = true; |
1305 }; | 1305 }; |
1306 | 1306 |
1307 #if TRACE_GC_USING_CLASSOF | 1307 #if TRACE_GC_USING_CLASSOF |
1308 #define DEFINE_CLASS_NAME(Type) \ | 1308 #define DEFINE_CLASS_NAME(Type) \ |
1309 virtual const char* className() { return #Type; } | 1309 virtual const char* className() { return #Type; } |
1310 #else | 1310 #else |
1311 #define DEFINE_CLASS_NAME(Type) | 1311 #define DEFINE_CLASS_NAME(Type) |
1312 #endif | 1312 #endif |
1313 | 1313 |
(...skipping 11 matching lines...) Expand all Loading... | |
1325 // inject virtual className() getter into heap allocated types. | 1325 // inject virtual className() getter into heap allocated types. |
1326 // FIXME(oilpan): Rename DEFINE_SELF_HANDLE to DEFINE_CLASS_NAME. | 1326 // FIXME(oilpan): Rename DEFINE_SELF_HANDLE to DEFINE_CLASS_NAME. |
1327 #define DEFINE_SELF_HANDLE(Type) \ | 1327 #define DEFINE_SELF_HANDLE(Type) \ |
1328 public: \ | 1328 public: \ |
1329 DEFINE_CLASS_NAME(Type) \ | 1329 DEFINE_CLASS_NAME(Type) \ |
1330 Type* nonConstSelfHandle() const { return const_cast<Type*>(this); } | 1330 Type* nonConstSelfHandle() const { return const_cast<Type*>(this); } |
1331 | 1331 |
1332 } | 1332 } |
1333 | 1333 |
1334 #endif | 1334 #endif |
OLD | NEW |