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

Side by Side Diff: Source/platform/heap/Heap.h

Issue 1166623002: Oilpan: Remove a visitor parameter from isHeapObjectAlive (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 6 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 787 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 // FIXME: Remove PLATFORM_EXPORT once we get a proper public interface to our 798 // FIXME: Remove PLATFORM_EXPORT once we get a proper public interface to our
799 // typed heaps. This is only exported to enable tests in HeapTest.cpp. 799 // typed heaps. This is only exported to enable tests in HeapTest.cpp.
800 PLATFORM_EXPORT inline BasePage* pageFromObject(const void* object) 800 PLATFORM_EXPORT inline BasePage* pageFromObject(const void* object)
801 { 801 {
802 Address address = reinterpret_cast<Address>(const_cast<void*>(object)); 802 Address address = reinterpret_cast<Address>(const_cast<void*>(object));
803 BasePage* page = reinterpret_cast<BasePage*>(blinkPageAddress(address) + WTF ::kSystemPageSize); 803 BasePage* page = reinterpret_cast<BasePage*>(blinkPageAddress(address) + WTF ::kSystemPageSize);
804 ASSERT(page->contains(address)); 804 ASSERT(page->contains(address));
805 return page; 805 return page;
806 } 806 }
807 807
808 template<typename T, bool = NeedsAdjustAndMark<T>::value> class ObjectAliveTrait ;
809
810 template<typename T>
811 class ObjectAliveTrait<T, false> {
812 public:
813 static bool isHeapObjectAlive(T* object)
814 {
815 static_assert(sizeof(T), "T must be fully defined");
816 return HeapObjectHeader::fromPayload(object)->isMarked();
817 }
818 };
819
820 template<typename T>
821 class ObjectAliveTrait<T, true> {
822 public:
823 static bool isHeapObjectAlive(T* object)
824 {
825 static_assert(sizeof(T), "T must be fully defined");
826 return object->isHeapObjectAlive();
827 }
828 };
829
808 class PLATFORM_EXPORT Heap { 830 class PLATFORM_EXPORT Heap {
809 public: 831 public:
810 static void init(); 832 static void init();
811 static void shutdown(); 833 static void shutdown();
812 static void doShutdown(); 834 static void doShutdown();
813 835
814 #if ENABLE(ASSERT) || ENABLE(GC_PROFILING) 836 #if ENABLE(ASSERT) || ENABLE(GC_PROFILING)
815 static BasePage* findPageFromAddress(Address); 837 static BasePage* findPageFromAddress(Address);
816 static BasePage* findPageFromAddress(const void* pointer) { return findPageF romAddress(reinterpret_cast<Address>(const_cast<void*>(pointer))); } 838 static BasePage* findPageFromAddress(const void* pointer) { return findPageF romAddress(reinterpret_cast<Address>(const_cast<void*>(pointer))); }
817 #endif 839 #endif
818 840
841 template<typename T>
842 static inline bool isHeapObjectAlive(T* object)
843 {
844 static_assert(sizeof(T), "T must be fully defined");
845 // The strongification of collections relies on the fact that once a
846 // collection has been strongified, there is no way that it can contain
847 // non-live entries, so no entries will be removed. Since you can't set
848 // the mark bit on a null pointer, that means that null pointers are
849 // always 'alive'.
850 if (!object)
851 return true;
852 return ObjectAliveTrait<T>::isHeapObjectAlive(object);
853 }
854 template<typename T>
855 static inline bool isHeapObjectAlive(const Member<T>& member)
856 {
857 return isHeapObjectAlive(member.get());
858 }
859 template<typename T>
860 static inline bool isHeapObjectAlive(const WeakMember<T>& member)
861 {
862 return isHeapObjectAlive(member.get());
863 }
864 template<typename T>
865 static inline bool isHeapObjectAlive(const RawPtr<T>& ptr)
866 {
867 return isHeapObjectAlive(ptr.get());
868 }
869
819 // Is the finalizable GC object still alive, but slated for lazy sweeping? 870 // Is the finalizable GC object still alive, but slated for lazy sweeping?
820 // If a lazy sweep is in progress, returns true if the object was found 871 // If a lazy sweep is in progress, returns true if the object was found
821 // to be not reachable during the marking phase, but it has yet to be swept 872 // to be not reachable during the marking phase, but it has yet to be swept
822 // and finalized. The predicate returns false in all other cases. 873 // and finalized. The predicate returns false in all other cases.
823 // 874 //
824 // Holding a reference to an already-dead object is not a valid state 875 // Holding a reference to an already-dead object is not a valid state
825 // to be in; willObjectBeLazilySwept() has undefined behavior if passed 876 // to be in; willObjectBeLazilySwept() has undefined behavior if passed
826 // such a reference. 877 // such a reference.
827 template<typename T> 878 template<typename T>
828 NO_LAZY_SWEEP_SANITIZE_ADDRESS 879 NO_LAZY_SWEEP_SANITIZE_ADDRESS
829 static bool willObjectBeLazilySwept(const T* objectPointer) 880 static bool willObjectBeLazilySwept(const T* objectPointer)
830 { 881 {
831 static_assert(IsGarbageCollectedType<T>::value, "only objects deriving f rom GarbageCollected can be used."); 882 static_assert(IsGarbageCollectedType<T>::value, "only objects deriving f rom GarbageCollected can be used.");
832 #if ENABLE_LAZY_SWEEPING 883 #if ENABLE_LAZY_SWEEPING
833 BasePage* page = pageFromObject(objectPointer); 884 BasePage* page = pageFromObject(objectPointer);
834 if (page->hasBeenSwept()) 885 if (page->hasBeenSwept())
835 return false; 886 return false;
836 ASSERT(page->heap()->threadState()->isSweepingInProgress()); 887 ASSERT(page->heap()->threadState()->isSweepingInProgress());
837 888
838 return !ObjectAliveTrait<T>::isHeapObjectAlive(s_markingVisitor, const_c ast<T*>(objectPointer)); 889 return !Heap::isHeapObjectAlive(const_cast<T*>(objectPointer));
839 #else 890 #else
840 return false; 891 return false;
841 #endif 892 #endif
842 } 893 }
843 894
844 // Push a trace callback on the marking stack. 895 // Push a trace callback on the marking stack.
845 static void pushTraceCallback(void* containerObject, TraceCallback); 896 static void pushTraceCallback(void* containerObject, TraceCallback);
846 897
847 // Push a trace callback on the post-marking callback stack. These 898 // Push a trace callback on the post-marking callback stack. These
848 // callbacks are called after normal marking (including ephemeron 899 // callbacks are called after normal marking (including ephemeron
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
1248 1299
1249 // Unpoison the memory used for the object (payload). 1300 // Unpoison the memory used for the object (payload).
1250 ASAN_UNPOISON_MEMORY_REGION(result, allocationSize - sizeof(HeapObjectHe ader)); 1301 ASAN_UNPOISON_MEMORY_REGION(result, allocationSize - sizeof(HeapObjectHe ader));
1251 FILL_ZERO_IF_NOT_PRODUCTION(result, allocationSize - sizeof(HeapObjectHe ader)); 1302 FILL_ZERO_IF_NOT_PRODUCTION(result, allocationSize - sizeof(HeapObjectHe ader));
1252 ASSERT(findPageFromAddress(headerAddress + allocationSize - 1)); 1303 ASSERT(findPageFromAddress(headerAddress + allocationSize - 1));
1253 return result; 1304 return result;
1254 } 1305 }
1255 return outOfLineAllocate(allocationSize, gcInfoIndex); 1306 return outOfLineAllocate(allocationSize, gcInfoIndex);
1256 } 1307 }
1257 1308
1309 template<typename Derived>
1310 template<typename T>
1311 void VisitorHelper<Derived>::handleWeakCell(Visitor* self, void* object)
1312 {
1313 T** cell = reinterpret_cast<T**>(object);
1314 if (*cell && !ObjectAliveTrait<T>::isHeapObjectAlive(*cell))
1315 *cell = nullptr;
1316 }
1317
1258 inline Address Heap::allocateOnHeapIndex(ThreadState* state, size_t size, int he apIndex, size_t gcInfoIndex) 1318 inline Address Heap::allocateOnHeapIndex(ThreadState* state, size_t size, int he apIndex, size_t gcInfoIndex)
1259 { 1319 {
1260 ASSERT(state->isAllocationAllowed()); 1320 ASSERT(state->isAllocationAllowed());
1261 ASSERT(heapIndex != LargeObjectHeapIndex); 1321 ASSERT(heapIndex != LargeObjectHeapIndex);
1262 NormalPageHeap* heap = static_cast<NormalPageHeap*>(state->heap(heapIndex)); 1322 NormalPageHeap* heap = static_cast<NormalPageHeap*>(state->heap(heapIndex));
1263 return heap->allocateObject(allocationSizeFromSize(size), gcInfoIndex); 1323 return heap->allocateObject(allocationSizeFromSize(size), gcInfoIndex);
1264 } 1324 }
1265 1325
1266 template<typename T> 1326 template<typename T>
1267 Address Heap::allocate(size_t size) 1327 Address Heap::allocate(size_t size)
(...skipping 25 matching lines...) Expand all
1293 size_t copySize = previousHeader->payloadSize(); 1353 size_t copySize = previousHeader->payloadSize();
1294 if (copySize > size) 1354 if (copySize > size)
1295 copySize = size; 1355 copySize = size;
1296 memcpy(address, previous, copySize); 1356 memcpy(address, previous, copySize);
1297 return address; 1357 return address;
1298 } 1358 }
1299 1359
1300 } // namespace blink 1360 } // namespace blink
1301 1361
1302 #endif // Heap_h 1362 #endif // Heap_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698