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 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 // traces only slots that are not zeroed out. This is because if | 378 // traces only slots that are not zeroed out. This is because if |
379 // the object has a vtable, the zeroed slot means that it is | 379 // the object has a vtable, the zeroed slot means that it is |
380 // an unused slot (Remember that the unused slots are guaranteed | 380 // an unused slot (Remember that the unused slots are guaranteed |
381 // to be zeroed out by VectorUnusedSlotClearer). | 381 // to be zeroed out by VectorUnusedSlotClearer). |
382 // | 382 // |
383 // - An object that can be initialized with memset. In this case, | 383 // - An object that can be initialized with memset. In this case, |
384 // HeapVectorBacking traces all slots including unused slots. | 384 // HeapVectorBacking traces all slots including unused slots. |
385 // This is fine because the fact that the object can be initialized | 385 // This is fine because the fact that the object can be initialized |
386 // with memset indicates that it is safe to treat the zerod slot | 386 // with memset indicates that it is safe to treat the zerod slot |
387 // as a valid object. | 387 // as a valid object. |
388 static_assert(!NeedsTracingTrait<Traits>::value || Traits::canClearUnuse
dSlotsWithMemset || WTF::IsPolymorphic<T>::value, "HeapVectorBacking doesn't sup
port objects that cannot be cleared as unused with memset."); | 388 static_assert(!NeedsTracingTrait<Traits>::value || Traits::canClearUnuse
dSlotsWithMemset || std::is_polymorphic<T>::value, "HeapVectorBacking doesn't su
pport objects that cannot be cleared as unused with memset."); |
389 | 389 |
390 // This trace method is instantiated for vectors where | 390 // This trace method is instantiated for vectors where |
391 // NeedsTracingTrait<Traits>::value is false, but the trace method | 391 // NeedsTracingTrait<Traits>::value is false, but the trace method |
392 // should not be called. Thus we cannot static-assert | 392 // should not be called. Thus we cannot static-assert |
393 // NeedsTracingTrait<Traits>::value but should runtime-assert it. | 393 // NeedsTracingTrait<Traits>::value but should runtime-assert it. |
394 ASSERT(NeedsTracingTrait<Traits>::value); | 394 ASSERT(NeedsTracingTrait<Traits>::value); |
395 | 395 |
396 T* array = reinterpret_cast<T*>(self); | 396 T* array = reinterpret_cast<T*>(self); |
397 blink::HeapObjectHeader* header = blink::HeapObjectHeader::fromPayload(s
elf); | 397 blink::HeapObjectHeader* header = blink::HeapObjectHeader::fromPayload(s
elf); |
398 ASSERT(header->checkHeader()); | 398 ASSERT(header->checkHeader()); |
399 // Use the payload size as recorded by the heap to determine how many | 399 // Use the payload size as recorded by the heap to determine how many |
400 // elements to trace. | 400 // elements to trace. |
401 size_t length = header->payloadSize() / sizeof(T); | 401 size_t length = header->payloadSize() / sizeof(T); |
402 if (WTF::IsPolymorphic<T>::value) { | 402 if (std::is_polymorphic<T>::value) { |
403 for (size_t i = 0; i < length; ++i) { | 403 for (size_t i = 0; i < length; ++i) { |
404 if (blink::vTableInitialized(&array[i])) | 404 if (blink::vTableInitialized(&array[i])) |
405 blink::TraceIfEnabled<T, NeedsTracingTrait<Traits>::value>::
trace(visitor, array[i]); | 405 blink::TraceIfEnabled<T, NeedsTracingTrait<Traits>::value>::
trace(visitor, array[i]); |
406 } | 406 } |
407 } else { | 407 } else { |
408 #ifdef ANNOTATE_CONTIGUOUS_CONTAINER | 408 #ifdef ANNOTATE_CONTIGUOUS_CONTAINER |
409 // As commented above, HeapVectorBacking can trace unused slots | 409 // As commented above, HeapVectorBacking can trace unused slots |
410 // (which are already zeroed out). | 410 // (which are already zeroed out). |
411 ANNOTATE_CHANGE_SIZE(array, length, 0, length); | 411 ANNOTATE_CHANGE_SIZE(array, length, 0, length); |
412 #endif | 412 #endif |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 // since iterating over the hash table backing will find the whole | 567 // since iterating over the hash table backing will find the whole |
568 // chain. | 568 // chain. |
569 visitor->markNoTracing(node); | 569 visitor->markNoTracing(node); |
570 return false; | 570 return false; |
571 } | 571 } |
572 }; | 572 }; |
573 | 573 |
574 } // namespace WTF | 574 } // namespace WTF |
575 | 575 |
576 #endif | 576 #endif |
OLD | NEW |