| 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; |
| 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::needsTracing, 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 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1273 // HeapObjectHash<T> instead. | 1273 // HeapObjectHash<T> instead. |
| 1274 template<typename T> struct DefaultHash<WebCore::Member<T> > { | 1274 template<typename T> struct DefaultHash<WebCore::Member<T> > { |
| 1275 typedef PtrHash<WebCore::Member<T> > Hash; | 1275 typedef PtrHash<WebCore::Member<T> > Hash; |
| 1276 }; | 1276 }; |
| 1277 | 1277 |
| 1278 template<typename T> struct DefaultHash<WebCore::WeakMember<T> > { | 1278 template<typename T> struct DefaultHash<WebCore::WeakMember<T> > { |
| 1279 typedef PtrHash<WebCore::WeakMember<T> > Hash; | 1279 typedef PtrHash<WebCore::WeakMember<T> > Hash; |
| 1280 }; | 1280 }; |
| 1281 | 1281 |
| 1282 template<typename T> | 1282 template<typename T> |
| 1283 struct NeedsVisiting<WebCore::Member<T> > { | 1283 struct NeedsTracing<WebCore::Member<T> > { |
| 1284 static const bool value = true; | 1284 static const bool value = true; |
| 1285 }; | 1285 }; |
| 1286 | 1286 |
| 1287 template<typename T> | 1287 template<typename T> |
| 1288 struct IsWeak<WebCore::WeakMember<T> > { | 1288 struct IsWeak<WebCore::WeakMember<T> > { |
| 1289 static const bool value = true; | 1289 static const bool value = true; |
| 1290 }; | 1290 }; |
| 1291 | 1291 |
| 1292 template<typename T, size_t inlinedCapacity> | 1292 template<typename T, size_t inlinedCapacity> |
| 1293 struct IsPod<WebCore::HeapVector<T, inlinedCapacity> > { | 1293 struct IsPod<WebCore::HeapVector<T, inlinedCapacity> > { |
| 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 NeedsVisiting<WebCore::HeapVector<T, inlinedCapacity> > { | 1298 struct NeedsTracing<WebCore::HeapVector<T, inlinedCapacity> > { |
| 1299 static const bool value = true; | 1299 static const bool value = true; |
| 1300 }; | 1300 }; |
| 1301 | 1301 |
| 1302 #if TRACE_GC_USING_CLASSOF | 1302 #if TRACE_GC_USING_CLASSOF |
| 1303 #define DEFINE_CLASS_NAME(Type) \ | 1303 #define DEFINE_CLASS_NAME(Type) \ |
| 1304 virtual const char* className() { return #Type; } | 1304 virtual const char* className() { return #Type; } |
| 1305 #else | 1305 #else |
| 1306 #define DEFINE_CLASS_NAME(Type) | 1306 #define DEFINE_CLASS_NAME(Type) |
| 1307 #endif | 1307 #endif |
| 1308 | 1308 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1320 // inject virtual className() getter into heap allocated types. | 1320 // inject virtual className() getter into heap allocated types. |
| 1321 // FIXME(oilpan): Rename DEFINE_SELF_HANDLE to DEFINE_CLASS_NAME. | 1321 // FIXME(oilpan): Rename DEFINE_SELF_HANDLE to DEFINE_CLASS_NAME. |
| 1322 #define DEFINE_SELF_HANDLE(Type)
\ | 1322 #define DEFINE_SELF_HANDLE(Type)
\ |
| 1323 public:
\ | 1323 public:
\ |
| 1324 DEFINE_CLASS_NAME(Type)
\ | 1324 DEFINE_CLASS_NAME(Type)
\ |
| 1325 Type* nonConstSelfHandle() const { return const_cast<Type*>(this); } | 1325 Type* nonConstSelfHandle() const { return const_cast<Type*>(this); } |
| 1326 | 1326 |
| 1327 } | 1327 } |
| 1328 | 1328 |
| 1329 #endif | 1329 #endif |
| OLD | NEW |