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 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 static_assert(!ShouldBeTraced<Traits>::value || Traits::canClearUnusedSl
otsWithMemset || WTF::IsPolymorphic<T>::value, "HeapVectorBacking doesn't suppor
t objects that cannot be cleared as unused with memset."); | 364 static_assert(!ShouldBeTraced<Traits>::value || Traits::canClearUnusedSl
otsWithMemset || WTF::IsPolymorphic<T>::value, "HeapVectorBacking doesn't suppor
t objects that cannot be cleared as unused with memset."); |
365 | 365 |
366 // This trace method is instantiated for vectors where | 366 // This trace method is instantiated for vectors where |
367 // ShouldBeTraced<Traits>::value is false, but the trace method | 367 // ShouldBeTraced<Traits>::value is false, but the trace method |
368 // should not be called. Thus we cannot static-assert | 368 // should not be called. Thus we cannot static-assert |
369 // ShouldBeTraced<Traits>::value but should runtime-assert it. | 369 // ShouldBeTraced<Traits>::value but should runtime-assert it. |
370 ASSERT(ShouldBeTraced<Traits>::value); | 370 ASSERT(ShouldBeTraced<Traits>::value); |
371 | 371 |
372 T* array = reinterpret_cast<T*>(self); | 372 T* array = reinterpret_cast<T*>(self); |
373 blink::HeapObjectHeader* header = blink::HeapObjectHeader::fromPayload(s
elf); | 373 blink::HeapObjectHeader* header = blink::HeapObjectHeader::fromPayload(s
elf); |
374 header->checkHeader(); | 374 ASSERT(header->checkHeader()); |
375 // Use the payload size as recorded by the heap to determine how many | 375 // Use the payload size as recorded by the heap to determine how many |
376 // elements to trace. | 376 // elements to trace. |
377 size_t length = header->payloadSize() / sizeof(T); | 377 size_t length = header->payloadSize() / sizeof(T); |
378 if (WTF::IsPolymorphic<T>::value) { | 378 if (WTF::IsPolymorphic<T>::value) { |
379 for (size_t i = 0; i < length; ++i) { | 379 for (size_t i = 0; i < length; ++i) { |
380 if (blink::vTableInitialized(&array[i])) | 380 if (blink::vTableInitialized(&array[i])) |
381 blink::TraceIfEnabled<T, ShouldBeTraced<Traits>::value>::tra
ce(visitor, array[i]); | 381 blink::TraceIfEnabled<T, ShouldBeTraced<Traits>::value>::tra
ce(visitor, array[i]); |
382 } | 382 } |
383 } else { | 383 } else { |
384 #ifdef ANNOTATE_CONTIGUOUS_CONTAINER | 384 #ifdef ANNOTATE_CONTIGUOUS_CONTAINER |
(...skipping 15 matching lines...) Expand all Loading... |
400 using Value = typename Table::ValueType; | 400 using Value = typename Table::ValueType; |
401 using Traits = typename Table::ValueTraits; | 401 using Traits = typename Table::ValueTraits; |
402 | 402 |
403 template<typename VisitorDispatcher> | 403 template<typename VisitorDispatcher> |
404 static bool trace(VisitorDispatcher visitor, void* self) | 404 static bool trace(VisitorDispatcher visitor, void* self) |
405 { | 405 { |
406 static_assert(strongify == WTF::WeakPointersActStrong, "An on-stack Heap
HashTable needs to be visited strongly."); | 406 static_assert(strongify == WTF::WeakPointersActStrong, "An on-stack Heap
HashTable needs to be visited strongly."); |
407 | 407 |
408 Value* array = reinterpret_cast<Value*>(self); | 408 Value* array = reinterpret_cast<Value*>(self); |
409 blink::HeapObjectHeader* header = blink::HeapObjectHeader::fromPayload(s
elf); | 409 blink::HeapObjectHeader* header = blink::HeapObjectHeader::fromPayload(s
elf); |
410 header->checkHeader(); | 410 ASSERT(header->checkHeader()); |
411 // Use the payload size as recorded by the heap to determine how many | 411 // Use the payload size as recorded by the heap to determine how many |
412 // elements to trace. | 412 // elements to trace. |
413 size_t length = header->payloadSize() / sizeof(Value); | 413 size_t length = header->payloadSize() / sizeof(Value); |
414 for (size_t i = 0; i < length; ++i) { | 414 for (size_t i = 0; i < length; ++i) { |
415 if (!HashTableHelper<Value, typename Table::ExtractorType, typename
Table::KeyTraitsType>::isEmptyOrDeletedBucket(array[i])) | 415 if (!HashTableHelper<Value, typename Table::ExtractorType, typename
Table::KeyTraitsType>::isEmptyOrDeletedBucket(array[i])) |
416 blink::TraceCollectionIfEnabled<ShouldBeTraced<Traits>::value, T
raits::weakHandlingFlag, strongify, Value, Traits>::trace(visitor, array[i]); | 416 blink::TraceCollectionIfEnabled<ShouldBeTraced<Traits>::value, T
raits::weakHandlingFlag, strongify, Value, Traits>::trace(visitor, array[i]); |
417 } | 417 } |
418 return false; | 418 return false; |
419 } | 419 } |
420 }; | 420 }; |
421 | 421 |
422 // This specialization of TraceInCollectionTrait is for the backing of | 422 // This specialization of TraceInCollectionTrait is for the backing of |
423 // HeapListHashSet. This is for the case that we find a reference to the | 423 // HeapListHashSet. This is for the case that we find a reference to the |
424 // backing from the stack. That probably means we have a GC while we are in a | 424 // backing from the stack. That probably means we have a GC while we are in a |
425 // ListHashSet method since normal API use does not put pointers to the backing | 425 // ListHashSet method since normal API use does not put pointers to the backing |
426 // on the stack. | 426 // on the stack. |
427 template<ShouldWeakPointersBeMarkedStrongly strongify, typename NodeContents, si
ze_t inlineCapacity, typename T, typename U, typename V, typename W, typename X,
typename Y> | 427 template<ShouldWeakPointersBeMarkedStrongly strongify, typename NodeContents, si
ze_t inlineCapacity, typename T, typename U, typename V, typename W, typename X,
typename Y> |
428 struct TraceInCollectionTrait<NoWeakHandlingInCollections, strongify, blink::Hea
pHashTableBacking<HashTable<ListHashSetNode<NodeContents, blink::HeapListHashSet
Allocator<T, inlineCapacity>>*, U, V, W, X, Y, blink::HeapAllocator>>, void> { | 428 struct TraceInCollectionTrait<NoWeakHandlingInCollections, strongify, blink::Hea
pHashTableBacking<HashTable<ListHashSetNode<NodeContents, blink::HeapListHashSet
Allocator<T, inlineCapacity>>*, U, V, W, X, Y, blink::HeapAllocator>>, void> { |
429 using Node = ListHashSetNode<NodeContents, blink::HeapListHashSetAllocator<T
, inlineCapacity>>; | 429 using Node = ListHashSetNode<NodeContents, blink::HeapListHashSetAllocator<T
, inlineCapacity>>; |
430 using Table = HashTable<Node*, U, V, W, X, Y, blink::HeapAllocator>; | 430 using Table = HashTable<Node*, U, V, W, X, Y, blink::HeapAllocator>; |
431 | 431 |
432 template<typename VisitorDispatcher> | 432 template<typename VisitorDispatcher> |
433 static bool trace(VisitorDispatcher visitor, void* self) | 433 static bool trace(VisitorDispatcher visitor, void* self) |
434 { | 434 { |
435 Node** array = reinterpret_cast<Node**>(self); | 435 Node** array = reinterpret_cast<Node**>(self); |
436 blink::HeapObjectHeader* header = blink::HeapObjectHeader::fromPayload(s
elf); | 436 blink::HeapObjectHeader* header = blink::HeapObjectHeader::fromPayload(s
elf); |
437 header->checkHeader(); | 437 ASSERT(header->checkHeader()); |
438 size_t length = header->payloadSize() / sizeof(Node*); | 438 size_t length = header->payloadSize() / sizeof(Node*); |
439 for (size_t i = 0; i < length; ++i) { | 439 for (size_t i = 0; i < length; ++i) { |
440 if (!HashTableHelper<Node*, typename Table::ExtractorType, typename
Table::KeyTraitsType>::isEmptyOrDeletedBucket(array[i])) { | 440 if (!HashTableHelper<Node*, typename Table::ExtractorType, typename
Table::KeyTraitsType>::isEmptyOrDeletedBucket(array[i])) { |
441 traceListHashSetValue(visitor, array[i]->m_value); | 441 traceListHashSetValue(visitor, array[i]->m_value); |
442 // Just mark the node without tracing because we already traced | 442 // Just mark the node without tracing because we already traced |
443 // the contents, and there is no need to trace the next and | 443 // the contents, and there is no need to trace the next and |
444 // prev fields since iterating over the hash table backing will | 444 // prev fields since iterating over the hash table backing will |
445 // find the whole chain. | 445 // find the whole chain. |
446 visitor->markNoTracing(array[i]); | 446 visitor->markNoTracing(array[i]); |
447 } | 447 } |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 // since iterating over the hash table backing will find the whole | 541 // since iterating over the hash table backing will find the whole |
542 // chain. | 542 // chain. |
543 visitor->markNoTracing(node); | 543 visitor->markNoTracing(node); |
544 return false; | 544 return false; |
545 } | 545 } |
546 }; | 546 }; |
547 | 547 |
548 } // namespace WTF | 548 } // namespace WTF |
549 | 549 |
550 #endif | 550 #endif |
OLD | NEW |