Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Side by Side Diff: Source/wtf/Vector.h

Issue 1088973006: Oilpan: Correct static_asserts about VectorTraits::canInitializeWithMemset (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« Source/platform/heap/Heap.h ('K') | « Source/platform/heap/Heap.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 static void clear(T*, T*) { } 83 static void clear(T*, T*) { }
84 #if ENABLE(ASSERT) 84 #if ENABLE(ASSERT)
85 static void checkCleared(const T*, const T*) { } 85 static void checkCleared(const T*, const T*) { }
86 #endif 86 #endif
87 }; 87 };
88 88
89 template<typename T> 89 template<typename T>
90 struct VectorUnusedSlotClearer<true, T> { 90 struct VectorUnusedSlotClearer<true, T> {
91 static void clear(T* begin, T* end) 91 static void clear(T* begin, T* end)
92 { 92 {
93 // We clear out unused slots so that the visitor and the finalizer
94 // do not visit them (or at least it does not matter if they do).
95 memset(begin, 0, sizeof(T) * (end - begin)); 93 memset(begin, 0, sizeof(T) * (end - begin));
96 } 94 }
97 95
98 #if ENABLE(ASSERT) 96 #if ENABLE(ASSERT)
99 static void checkCleared(const T* begin, const T* end) 97 static void checkCleared(const T* begin, const T* end)
100 { 98 {
101 const unsigned char* unusedArea = reinterpret_cast<const unsigned ch ar*>(begin); 99 const unsigned char* unusedArea = reinterpret_cast<const unsigned ch ar*>(begin);
102 const unsigned char* endAddress = reinterpret_cast<const unsigned ch ar*>(end); 100 const unsigned char* endAddress = reinterpret_cast<const unsigned ch ar*>(end);
103 ASSERT(endAddress >= unusedArea); 101 ASSERT(endAddress >= unusedArea);
104 for (int i = 0; i < endAddress - unusedArea; ++i) 102 for (int i = 0; i < endAddress - unusedArea; ++i)
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 { 335 {
338 return Allocator::Quantizer::template quantizedSize<T>(capacity); 336 return Allocator::Quantizer::template quantizedSize<T>(capacity);
339 } 337 }
340 338
341 T* buffer() { return m_buffer; } 339 T* buffer() { return m_buffer; }
342 const T* buffer() const { return m_buffer; } 340 const T* buffer() const { return m_buffer; }
343 size_t capacity() const { return m_capacity; } 341 size_t capacity() const { return m_capacity; }
344 342
345 void clearUnusedSlots(T* from, T* to) 343 void clearUnusedSlots(T* from, T* to)
346 { 344 {
345 // If the vector backing is garbage-collected and needs tracing
346 // or finalizing, we clear out the unused slots so that the visitor
347 // or the finalizer does not cause a problem when visiting the
348 // unused slots.
347 VectorUnusedSlotClearer<Allocator::isGarbageCollected && (VectorTrai ts<T>::needsDestruction || ShouldBeTraced<VectorTraits<T>>::value), T>::clear(fr om, to); 349 VectorUnusedSlotClearer<Allocator::isGarbageCollected && (VectorTrai ts<T>::needsDestruction || ShouldBeTraced<VectorTraits<T>>::value), T>::clear(fr om, to);
348 } 350 }
349 351
350 void checkUnusedSlots(const T* from, const T* to) 352 void checkUnusedSlots(const T* from, const T* to)
351 { 353 {
352 #if ENABLE(ASSERT) && !defined(ANNOTATE_CONTIGUOUS_CONTAINER) 354 #if ENABLE(ASSERT) && !defined(ANNOTATE_CONTIGUOUS_CONTAINER)
353 VectorUnusedSlotClearer<Allocator::isGarbageCollected && (VectorTrai ts<T>::needsDestruction || ShouldBeTraced<VectorTraits<T>>::value), T>::checkCle ared(from, to); 355 VectorUnusedSlotClearer<Allocator::isGarbageCollected && (VectorTrai ts<T>::needsDestruction || ShouldBeTraced<VectorTraits<T>>::value), T>::checkCle ared(from, to);
354 #endif 356 #endif
355 } 357 }
356 358
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 public: 630 public:
629 typedef T ValueType; 631 typedef T ValueType;
630 632
631 typedef T* iterator; 633 typedef T* iterator;
632 typedef const T* const_iterator; 634 typedef const T* const_iterator;
633 typedef std::reverse_iterator<iterator> reverse_iterator; 635 typedef std::reverse_iterator<iterator> reverse_iterator;
634 typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 636 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
635 637
636 Vector() 638 Vector()
637 { 639 {
638 // Unused slots are initialized to zero so that the visitor and the 640 static_assert(!WTF::IsPolymorphic<T>::value || !VectorTraits<T>::can InitializeWithMemset, "Cannot initialize with memset if there is a vtable");
639 // finalizer can visit them safely. canInitializeWithMemset tells us
640 // that the class does not expect matching constructor and
641 // destructor calls as long as the memory is zeroed.
642 static_assert(!Allocator::isGarbageCollected || !VectorTraits<T>::ne edsDestruction || VectorTraits<T>::canInitializeWithMemset, "class has problems with finalizers called on cleared memory");
643 static_assert(!WTF::IsPolymorphic<T>::value || !VectorTraits<T>::can InitializeWithMemset, "cannot initialize with memset if there is a vtable");
644 ANNOTATE_NEW_BUFFER(begin(), capacity(), 0); 641 ANNOTATE_NEW_BUFFER(begin(), capacity(), 0);
645 m_size = 0; 642 m_size = 0;
646 } 643 }
647 644
648 explicit Vector(size_t size) 645 explicit Vector(size_t size)
649 : Base(size) 646 : Base(size)
650 { 647 {
651 // Unused slots are initialized to zero so that the visitor and the 648 static_assert(!WTF::IsPolymorphic<T>::value || !VectorTraits<T>::can InitializeWithMemset, "Cannot initialize with memset if there is a vtable");
652 // finalizer can visit them safely. canInitializeWithMemset tells us
653 // that the class does not expect matching constructor and
654 // destructor calls as long as the memory is zeroed.
655 static_assert(!Allocator::isGarbageCollected || !VectorTraits<T>::ne edsDestruction || VectorTraits<T>::canInitializeWithMemset, "class has problems with finalizers called on cleared memory");
656 ANNOTATE_NEW_BUFFER(begin(), capacity(), size); 649 ANNOTATE_NEW_BUFFER(begin(), capacity(), size);
657 m_size = size; 650 m_size = size;
658 TypeOperations::initialize(begin(), end()); 651 TypeOperations::initialize(begin(), end());
659 } 652 }
660 653
661 // Off-GC-heap vectors: Destructor should be called. 654 // Off-GC-heap vectors: Destructor should be called.
662 // On-GC-heap vectors: Destructor should be called for inline buffers 655 // On-GC-heap vectors: Destructor should be called for inline buffers
663 // (if any) but destructor shouldn't be called for vector backing since 656 // (if any) but destructor shouldn't be called for vector backing since
664 // it is managed by the traced GC heap. 657 // it is managed by the traced GC heap.
665 void finalize() 658 void finalize()
(...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after
1330 struct NeedsTracing<Vector<T, N>> { 1323 struct NeedsTracing<Vector<T, N>> {
1331 static const bool value = false; 1324 static const bool value = false;
1332 }; 1325 };
1333 #endif 1326 #endif
1334 1327
1335 } // namespace WTF 1328 } // namespace WTF
1336 1329
1337 using WTF::Vector; 1330 using WTF::Vector;
1338 1331
1339 #endif // WTF_Vector_h 1332 #endif // WTF_Vector_h
OLDNEW
« Source/platform/heap/Heap.h ('K') | « Source/platform/heap/Heap.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698