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

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

Powered by Google App Engine
This is Rietveld 408576698