| 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/StackFrameDepth.h" | 10 #include "platform/heap/StackFrameDepth.h" |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 template <typename VisitorDispatcher> | 200 template <typename VisitorDispatcher> |
| 201 static void mark(VisitorDispatcher visitor, const T* t) { | 201 static void mark(VisitorDispatcher visitor, const T* t) { |
| 202 AdjustAndMarkTrait<T>::mark(visitor, t); | 202 AdjustAndMarkTrait<T>::mark(visitor, t); |
| 203 } | 203 } |
| 204 | 204 |
| 205 private: | 205 private: |
| 206 static const T* ToWrapperTracingType(const void* t) { | 206 static const T* ToWrapperTracingType(const void* t) { |
| 207 static_assert(!NeedsAdjustAndMark<T>::value, | 207 static_assert(!NeedsAdjustAndMark<T>::value, |
| 208 "wrapper tracing is not supported within mixins"); | 208 "wrapper tracing is not supported within mixins"); |
| 209 #if DCHECK_IS_ON() | 209 #if DCHECK_IS_ON() |
| 210 HeapObjectHeader::fromPayload(t)->checkHeader(); | 210 // |fromPayload| checks the integrity of the |HeapObjectHeader|. |
| 211 (void)HeapObjectHeader::fromPayload(t); |
| 211 #endif | 212 #endif |
| 212 return reinterpret_cast<const T*>(t); | 213 return reinterpret_cast<const T*>(t); |
| 213 } | 214 } |
| 214 }; | 215 }; |
| 215 | 216 |
| 216 template <typename T> | 217 template <typename T> |
| 217 class TraceTrait<const T> : public TraceTrait<T> {}; | 218 class TraceTrait<const T> : public TraceTrait<T> {}; |
| 218 | 219 |
| 219 template <typename T> | 220 template <typename T> |
| 220 void TraceTrait<T>::trace(Visitor* visitor, void* self) { | 221 void TraceTrait<T>::trace(Visitor* visitor, void* self) { |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 | 503 |
| 503 // This trace method is instantiated for vectors where | 504 // This trace method is instantiated for vectors where |
| 504 // IsTraceableInCollectionTrait<Traits>::value is false, but the trace | 505 // IsTraceableInCollectionTrait<Traits>::value is false, but the trace |
| 505 // method should not be called. Thus we cannot static-assert | 506 // method should not be called. Thus we cannot static-assert |
| 506 // IsTraceableInCollectionTrait<Traits>::value but should runtime-assert it. | 507 // IsTraceableInCollectionTrait<Traits>::value but should runtime-assert it. |
| 507 DCHECK(IsTraceableInCollectionTrait<Traits>::value); | 508 DCHECK(IsTraceableInCollectionTrait<Traits>::value); |
| 508 | 509 |
| 509 T* array = reinterpret_cast<T*>(self); | 510 T* array = reinterpret_cast<T*>(self); |
| 510 blink::HeapObjectHeader* header = | 511 blink::HeapObjectHeader* header = |
| 511 blink::HeapObjectHeader::fromPayload(self); | 512 blink::HeapObjectHeader::fromPayload(self); |
| 512 header->checkHeader(); | |
| 513 // Use the payload size as recorded by the heap to determine how many | 513 // Use the payload size as recorded by the heap to determine how many |
| 514 // elements to trace. | 514 // elements to trace. |
| 515 size_t length = header->payloadSize() / sizeof(T); | 515 size_t length = header->payloadSize() / sizeof(T); |
| 516 #ifdef ANNOTATE_CONTIGUOUS_CONTAINER | 516 #ifdef ANNOTATE_CONTIGUOUS_CONTAINER |
| 517 // As commented above, HeapVectorBacking can trace unused slots | 517 // As commented above, HeapVectorBacking can trace unused slots |
| 518 // (which are already zeroed out). | 518 // (which are already zeroed out). |
| 519 ANNOTATE_CHANGE_SIZE(array, length, 0, length); | 519 ANNOTATE_CHANGE_SIZE(array, length, 0, length); |
| 520 #endif | 520 #endif |
| 521 if (std::is_polymorphic<T>::value) { | 521 if (std::is_polymorphic<T>::value) { |
| 522 char* pointer = reinterpret_cast<char*>(array); | 522 char* pointer = reinterpret_cast<char*>(array); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 550 template <typename VisitorDispatcher> | 550 template <typename VisitorDispatcher> |
| 551 static bool trace(VisitorDispatcher visitor, void* self) { | 551 static bool trace(VisitorDispatcher visitor, void* self) { |
| 552 static_assert(strongify == WTF::WeakPointersActStrong, | 552 static_assert(strongify == WTF::WeakPointersActStrong, |
| 553 "An on-stack HeapHashTable needs to be visited strongly."); | 553 "An on-stack HeapHashTable needs to be visited strongly."); |
| 554 | 554 |
| 555 DCHECK(IsTraceableInCollectionTrait<Traits>::value || | 555 DCHECK(IsTraceableInCollectionTrait<Traits>::value || |
| 556 Traits::weakHandlingFlag == WeakHandlingInCollections); | 556 Traits::weakHandlingFlag == WeakHandlingInCollections); |
| 557 Value* array = reinterpret_cast<Value*>(self); | 557 Value* array = reinterpret_cast<Value*>(self); |
| 558 blink::HeapObjectHeader* header = | 558 blink::HeapObjectHeader* header = |
| 559 blink::HeapObjectHeader::fromPayload(self); | 559 blink::HeapObjectHeader::fromPayload(self); |
| 560 header->checkHeader(); | |
| 561 // Use the payload size as recorded by the heap to determine how many | 560 // Use the payload size as recorded by the heap to determine how many |
| 562 // elements to trace. | 561 // elements to trace. |
| 563 size_t length = header->payloadSize() / sizeof(Value); | 562 size_t length = header->payloadSize() / sizeof(Value); |
| 564 for (size_t i = 0; i < length; ++i) { | 563 for (size_t i = 0; i < length; ++i) { |
| 565 if (!HashTableHelper< | 564 if (!HashTableHelper< |
| 566 Value, typename Table::ExtractorType, | 565 Value, typename Table::ExtractorType, |
| 567 typename Table::KeyTraitsType>::isEmptyOrDeletedBucket(array[i])) | 566 typename Table::KeyTraitsType>::isEmptyOrDeletedBucket(array[i])) |
| 568 blink::TraceCollectionIfEnabled< | 567 blink::TraceCollectionIfEnabled< |
| 569 IsTraceableInCollectionTrait<Traits>::value, | 568 IsTraceableInCollectionTrait<Traits>::value, |
| 570 Traits::weakHandlingFlag, strongify, Value, | 569 Traits::weakHandlingFlag, strongify, Value, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 using Node = | 603 using Node = |
| 605 ListHashSetNode<NodeContents, | 604 ListHashSetNode<NodeContents, |
| 606 blink::HeapListHashSetAllocator<T, inlineCapacity>>; | 605 blink::HeapListHashSetAllocator<T, inlineCapacity>>; |
| 607 using Table = HashTable<Node*, U, V, W, X, Y, blink::HeapAllocator>; | 606 using Table = HashTable<Node*, U, V, W, X, Y, blink::HeapAllocator>; |
| 608 | 607 |
| 609 template <typename VisitorDispatcher> | 608 template <typename VisitorDispatcher> |
| 610 static bool trace(VisitorDispatcher visitor, void* self) { | 609 static bool trace(VisitorDispatcher visitor, void* self) { |
| 611 Node** array = reinterpret_cast<Node**>(self); | 610 Node** array = reinterpret_cast<Node**>(self); |
| 612 blink::HeapObjectHeader* header = | 611 blink::HeapObjectHeader* header = |
| 613 blink::HeapObjectHeader::fromPayload(self); | 612 blink::HeapObjectHeader::fromPayload(self); |
| 614 header->checkHeader(); | |
| 615 size_t length = header->payloadSize() / sizeof(Node*); | 613 size_t length = header->payloadSize() / sizeof(Node*); |
| 616 for (size_t i = 0; i < length; ++i) { | 614 for (size_t i = 0; i < length; ++i) { |
| 617 if (!HashTableHelper<Node*, typename Table::ExtractorType, | 615 if (!HashTableHelper<Node*, typename Table::ExtractorType, |
| 618 typename Table::KeyTraitsType>:: | 616 typename Table::KeyTraitsType>:: |
| 619 isEmptyOrDeletedBucket(array[i])) { | 617 isEmptyOrDeletedBucket(array[i])) { |
| 620 traceListHashSetValue(visitor, array[i]->m_value); | 618 traceListHashSetValue(visitor, array[i]->m_value); |
| 621 // Just mark the node without tracing because we already traced | 619 // Just mark the node without tracing because we already traced |
| 622 // the contents, and there is no need to trace the next and | 620 // the contents, and there is no need to trace the next and |
| 623 // prev fields since iterating over the hash table backing will | 621 // prev fields since iterating over the hash table backing will |
| 624 // find the whole chain. | 622 // find the whole chain. |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 781 // since iterating over the hash table backing will find the whole | 779 // since iterating over the hash table backing will find the whole |
| 782 // chain. | 780 // chain. |
| 783 visitor->markNoTracing(node); | 781 visitor->markNoTracing(node); |
| 784 return false; | 782 return false; |
| 785 } | 783 } |
| 786 }; | 784 }; |
| 787 | 785 |
| 788 } // namespace WTF | 786 } // namespace WTF |
| 789 | 787 |
| 790 #endif | 788 #endif |
| OLD | NEW |