| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef TraceTraits_h | 5 #ifndef TraceTraits_h |
| 6 #define TraceTraits_h | 6 #define TraceTraits_h |
| 7 | 7 |
| 8 #include "platform/heap/GCInfo.h" | 8 #include "platform/heap/GCInfo.h" |
| 9 #include "platform/heap/Heap.h" | 9 #include "platform/heap/Heap.h" |
| 10 #include "platform/heap/InlinedGlobalMarkingVisitor.h" | 10 #include "platform/heap/InlinedGlobalMarkingVisitor.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 template <typename T, bool = NeedsAdjustAndMark<T>::value> | 42 template <typename T, bool = NeedsAdjustAndMark<T>::value> |
| 43 class AdjustAndMarkTrait; | 43 class AdjustAndMarkTrait; |
| 44 | 44 |
| 45 template <typename T> | 45 template <typename T> |
| 46 class AdjustAndMarkTrait<T, false> { | 46 class AdjustAndMarkTrait<T, false> { |
| 47 STATIC_ONLY(AdjustAndMarkTrait); | 47 STATIC_ONLY(AdjustAndMarkTrait); |
| 48 | 48 |
| 49 public: | 49 public: |
| 50 template <typename VisitorDispatcher> | 50 template <typename VisitorDispatcher> |
| 51 static void mark(VisitorDispatcher visitor, const T* t) { | 51 static void mark(VisitorDispatcher visitor, const T* t) { |
| 52 #if ENABLE(ASSERT) | 52 #if DCHECK_IS_ON() |
| 53 assertObjectHasGCInfo(const_cast<T*>(t), GCInfoTrait<T>::index()); | 53 assertObjectHasGCInfo(const_cast<T*>(t), GCInfoTrait<T>::index()); |
| 54 #endif | 54 #endif |
| 55 // Default mark method of the trait just calls the two-argument mark | 55 // Default mark method of the trait just calls the two-argument mark |
| 56 // method on the visitor. The second argument is the static trace method | 56 // method on the visitor. The second argument is the static trace method |
| 57 // of the trait, which by default calls the instance method | 57 // of the trait, which by default calls the instance method |
| 58 // trace(Visitor*) on the object. | 58 // trace(Visitor*) on the object. |
| 59 // | 59 // |
| 60 // If the trait allows it, invoke the trace callback right here on the | 60 // If the trait allows it, invoke the trace callback right here on the |
| 61 // not-yet-marked object. | 61 // not-yet-marked object. |
| 62 if (TraceEagerlyTrait<T>::value) { | 62 if (TraceEagerlyTrait<T>::value) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 87 template <typename T> | 87 template <typename T> |
| 88 class AdjustAndMarkTrait<T, true> { | 88 class AdjustAndMarkTrait<T, true> { |
| 89 STATIC_ONLY(AdjustAndMarkTrait); | 89 STATIC_ONLY(AdjustAndMarkTrait); |
| 90 | 90 |
| 91 public: | 91 public: |
| 92 template <typename VisitorDispatcher> | 92 template <typename VisitorDispatcher> |
| 93 static void mark(VisitorDispatcher visitor, const T* self) { | 93 static void mark(VisitorDispatcher visitor, const T* self) { |
| 94 if (!self) | 94 if (!self) |
| 95 return; | 95 return; |
| 96 | 96 |
| 97 // If you hit this ASSERT, it means that there is a dangling pointer | 97 // If you hit this DCHECK, it means that there is a dangling pointer |
| 98 // from a live thread heap to a dead thread heap. We must eliminate | 98 // from a live thread heap to a dead thread heap. We must eliminate |
| 99 // the dangling pointer. | 99 // the dangling pointer. |
| 100 // Release builds don't have the ASSERT, but it is OK because | 100 // Release builds don't have the DCHECK, but it is OK because |
| 101 // release builds will crash at the following self->adjustAndMark | 101 // release builds will crash at the following self->adjustAndMark |
| 102 // because all the entries of the orphaned arenas are zeroed out and | 102 // because all the entries of the orphaned arenas are zeroed out and |
| 103 // thus the item does not have a valid vtable. | 103 // thus the item does not have a valid vtable. |
| 104 ASSERT(!pageFromObject(self)->orphaned()); | 104 DCHECK(!pageFromObject(self)->orphaned()); |
| 105 self->adjustAndMark(visitor); | 105 self->adjustAndMark(visitor); |
| 106 } | 106 } |
| 107 }; | 107 }; |
| 108 | 108 |
| 109 template <typename T, bool isTraceable> | 109 template <typename T, bool isTraceable> |
| 110 struct TraceIfEnabled; | 110 struct TraceIfEnabled; |
| 111 | 111 |
| 112 template <typename T> | 112 template <typename T> |
| 113 struct TraceIfEnabled<T, false> { | 113 struct TraceIfEnabled<T, false> { |
| 114 STATIC_ONLY(TraceIfEnabled); | 114 STATIC_ONLY(TraceIfEnabled); |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 | 512 |
| 513 // This trace method is instantiated for vectors where | 513 // This trace method is instantiated for vectors where |
| 514 // IsTraceableInCollectionTrait<Traits>::value is false, but the trace | 514 // IsTraceableInCollectionTrait<Traits>::value is false, but the trace |
| 515 // method should not be called. Thus we cannot static-assert | 515 // method should not be called. Thus we cannot static-assert |
| 516 // IsTraceableInCollectionTrait<Traits>::value but should runtime-assert it. | 516 // IsTraceableInCollectionTrait<Traits>::value but should runtime-assert it. |
| 517 DCHECK(IsTraceableInCollectionTrait<Traits>::value); | 517 DCHECK(IsTraceableInCollectionTrait<Traits>::value); |
| 518 | 518 |
| 519 T* array = reinterpret_cast<T*>(self); | 519 T* array = reinterpret_cast<T*>(self); |
| 520 blink::HeapObjectHeader* header = | 520 blink::HeapObjectHeader* header = |
| 521 blink::HeapObjectHeader::fromPayload(self); | 521 blink::HeapObjectHeader::fromPayload(self); |
| 522 ASSERT(header->checkHeader()); | 522 DCHECK(header->checkHeader()); |
| 523 // Use the payload size as recorded by the heap to determine how many | 523 // Use the payload size as recorded by the heap to determine how many |
| 524 // elements to trace. | 524 // elements to trace. |
| 525 size_t length = header->payloadSize() / sizeof(T); | 525 size_t length = header->payloadSize() / sizeof(T); |
| 526 #ifdef ANNOTATE_CONTIGUOUS_CONTAINER | 526 #ifdef ANNOTATE_CONTIGUOUS_CONTAINER |
| 527 // As commented above, HeapVectorBacking can trace unused slots | 527 // As commented above, HeapVectorBacking can trace unused slots |
| 528 // (which are already zeroed out). | 528 // (which are already zeroed out). |
| 529 ANNOTATE_CHANGE_SIZE(array, length, 0, length); | 529 ANNOTATE_CHANGE_SIZE(array, length, 0, length); |
| 530 #endif | 530 #endif |
| 531 if (std::is_polymorphic<T>::value) { | 531 if (std::is_polymorphic<T>::value) { |
| 532 char* pointer = reinterpret_cast<char*>(array); | 532 char* pointer = reinterpret_cast<char*>(array); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 560 template <typename VisitorDispatcher> | 560 template <typename VisitorDispatcher> |
| 561 static bool trace(VisitorDispatcher visitor, void* self) { | 561 static bool trace(VisitorDispatcher visitor, void* self) { |
| 562 static_assert(strongify == WTF::WeakPointersActStrong, | 562 static_assert(strongify == WTF::WeakPointersActStrong, |
| 563 "An on-stack HeapHashTable needs to be visited strongly."); | 563 "An on-stack HeapHashTable needs to be visited strongly."); |
| 564 | 564 |
| 565 DCHECK(IsTraceableInCollectionTrait<Traits>::value || | 565 DCHECK(IsTraceableInCollectionTrait<Traits>::value || |
| 566 Traits::weakHandlingFlag == WeakHandlingInCollections); | 566 Traits::weakHandlingFlag == WeakHandlingInCollections); |
| 567 Value* array = reinterpret_cast<Value*>(self); | 567 Value* array = reinterpret_cast<Value*>(self); |
| 568 blink::HeapObjectHeader* header = | 568 blink::HeapObjectHeader* header = |
| 569 blink::HeapObjectHeader::fromPayload(self); | 569 blink::HeapObjectHeader::fromPayload(self); |
| 570 ASSERT(header->checkHeader()); | 570 DCHECK(header->checkHeader()); |
| 571 // Use the payload size as recorded by the heap to determine how many | 571 // Use the payload size as recorded by the heap to determine how many |
| 572 // elements to trace. | 572 // elements to trace. |
| 573 size_t length = header->payloadSize() / sizeof(Value); | 573 size_t length = header->payloadSize() / sizeof(Value); |
| 574 for (size_t i = 0; i < length; ++i) { | 574 for (size_t i = 0; i < length; ++i) { |
| 575 if (!HashTableHelper< | 575 if (!HashTableHelper< |
| 576 Value, typename Table::ExtractorType, | 576 Value, typename Table::ExtractorType, |
| 577 typename Table::KeyTraitsType>::isEmptyOrDeletedBucket(array[i])) | 577 typename Table::KeyTraitsType>::isEmptyOrDeletedBucket(array[i])) |
| 578 blink::TraceCollectionIfEnabled< | 578 blink::TraceCollectionIfEnabled< |
| 579 IsTraceableInCollectionTrait<Traits>::value, | 579 IsTraceableInCollectionTrait<Traits>::value, |
| 580 Traits::weakHandlingFlag, strongify, Value, | 580 Traits::weakHandlingFlag, strongify, Value, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 614 using Node = | 614 using Node = |
| 615 ListHashSetNode<NodeContents, | 615 ListHashSetNode<NodeContents, |
| 616 blink::HeapListHashSetAllocator<T, inlineCapacity>>; | 616 blink::HeapListHashSetAllocator<T, inlineCapacity>>; |
| 617 using Table = HashTable<Node*, U, V, W, X, Y, blink::HeapAllocator>; | 617 using Table = HashTable<Node*, U, V, W, X, Y, blink::HeapAllocator>; |
| 618 | 618 |
| 619 template <typename VisitorDispatcher> | 619 template <typename VisitorDispatcher> |
| 620 static bool trace(VisitorDispatcher visitor, void* self) { | 620 static bool trace(VisitorDispatcher visitor, void* self) { |
| 621 Node** array = reinterpret_cast<Node**>(self); | 621 Node** array = reinterpret_cast<Node**>(self); |
| 622 blink::HeapObjectHeader* header = | 622 blink::HeapObjectHeader* header = |
| 623 blink::HeapObjectHeader::fromPayload(self); | 623 blink::HeapObjectHeader::fromPayload(self); |
| 624 ASSERT(header->checkHeader()); | 624 DCHECK(header->checkHeader()); |
| 625 size_t length = header->payloadSize() / sizeof(Node*); | 625 size_t length = header->payloadSize() / sizeof(Node*); |
| 626 for (size_t i = 0; i < length; ++i) { | 626 for (size_t i = 0; i < length; ++i) { |
| 627 if (!HashTableHelper<Node*, typename Table::ExtractorType, | 627 if (!HashTableHelper<Node*, typename Table::ExtractorType, |
| 628 typename Table::KeyTraitsType>:: | 628 typename Table::KeyTraitsType>:: |
| 629 isEmptyOrDeletedBucket(array[i])) { | 629 isEmptyOrDeletedBucket(array[i])) { |
| 630 traceListHashSetValue(visitor, array[i]->m_value); | 630 traceListHashSetValue(visitor, array[i]->m_value); |
| 631 // Just mark the node without tracing because we already traced | 631 // Just mark the node without tracing because we already traced |
| 632 // the contents, and there is no need to trace the next and | 632 // the contents, and there is no need to trace the next and |
| 633 // prev fields since iterating over the hash table backing will | 633 // prev fields since iterating over the hash table backing will |
| 634 // find the whole chain. | 634 // find the whole chain. |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 791 // since iterating over the hash table backing will find the whole | 791 // since iterating over the hash table backing will find the whole |
| 792 // chain. | 792 // chain. |
| 793 visitor->markNoTracing(node); | 793 visitor->markNoTracing(node); |
| 794 return false; | 794 return false; |
| 795 } | 795 } |
| 796 }; | 796 }; |
| 797 | 797 |
| 798 } // namespace WTF | 798 } // namespace WTF |
| 799 | 799 |
| 800 #endif | 800 #endif |
| OLD | NEW |