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