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

Unified Diff: third_party/WebKit/Source/platform/heap/Heap.h

Issue 1411603007: [Oilpan] Add use-after-free detector in Member<> Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Introduce gcGenerationUnchecked Created 5 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/platform/heap/Handle.h ('k') | third_party/WebKit/Source/platform/heap/Heap.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/platform/heap/Heap.h
diff --git a/third_party/WebKit/Source/platform/heap/Heap.h b/third_party/WebKit/Source/platform/heap/Heap.h
index 67a8bc873ef643166d19459cecc0c07fab89dab3..756fcb2638d988beda98f0b496753dbe6f973253 100644
--- a/third_party/WebKit/Source/platform/heap/Heap.h
+++ b/third_party/WebKit/Source/platform/heap/Heap.h
@@ -47,6 +47,8 @@ template<typename T> class Member;
template<typename T> class WeakMember;
template<typename T> class UntracedMember;
+// TODO(peria): Refactor following two sets of templates.
+
template<typename T, bool = NeedsAdjustAndMark<T>::value> class ObjectAliveTrait;
template<typename T>
@@ -64,11 +66,38 @@ class ObjectAliveTrait<T, true> {
public:
static bool isHeapObjectAlive(T* object)
{
- static_assert(sizeof(T), "T must be fully defined");
return object->isHeapObjectAlive();
}
};
+template<typename T, bool = IsGarbageCollectedMixin<T>::value> class HeapObjectHeaderTrait;
+
+template<typename T>
+class HeapObjectHeaderTrait<T, true> {
+public:
+ static HeapObjectHeader* heapObjectHeader(T* obj)
+ {
+ static_assert(sizeof(T), "T must be fully defined");
+ // TODO(peria): This ASSERT() is too restrictive. The ASSERT forbids
+ // to call heapObjectHeader() for an object while another
+ // (totally independent) mixin object is under construction.
+ ASSERT(!ThreadState::current()->isConstructingGCMixin());
+ return obj->heapObjectHeader();
+ }
+};
+
+template<typename T>
+class HeapObjectHeaderTrait<T, false> {
peria 2015/11/17 01:36:49 Yuta-san, Is it safe to instantiate HeapObjectHead
Yuta Kitamura 2015/11/17 06:25:12 If the lines 95-96 are NOT present, I think it's s
peria 2015/11/17 07:24:57 Thank you for the clarification and additional exp
+public:
+ static HeapObjectHeader* heapObjectHeader(T* obj)
+ {
+ ASSERT(!ThreadState::current()->isConstructingGCMixin());
+ if (!IsFullyDefined<T>::value)
+ return nullptr;
+ return HeapObjectHeader::fromPayload(obj);
+ }
+};
+
class PLATFORM_EXPORT Heap {
public:
static void init();
@@ -96,17 +125,17 @@ public:
template<typename T>
static inline bool isHeapObjectAlive(const Member<T>& member)
{
- return isHeapObjectAlive(member.get());
+ return isHeapObjectAlive(member.unsafeGet());
}
template<typename T>
static inline bool isHeapObjectAlive(const WeakMember<T>& member)
{
- return isHeapObjectAlive(member.get());
+ return isHeapObjectAlive(member.unsafeGet());
}
template<typename T>
static inline bool isHeapObjectAlive(const UntracedMember<T>& member)
{
- return isHeapObjectAlive(member.get());
+ return isHeapObjectAlive(member.unsafeGet());
}
template<typename T>
static inline bool isHeapObjectAlive(const RawPtr<T>& ptr)
@@ -259,9 +288,7 @@ public:
static void reportMemoryUsageHistogram();
static void reportMemoryUsageForTracing();
-#if ENABLE(ASSERT)
- static uint16_t gcGeneration() { return s_gcGeneration; }
-#endif
+ static uint32_t gcGeneration() { return s_gcGeneration; }
private:
// A RegionTree is a simple binary search tree of PageMemoryRegions sorted
@@ -308,9 +335,7 @@ private:
static size_t s_collectedWrapperCount;
static size_t s_partitionAllocSizeAtLastGC;
static double s_estimatedMarkingTimePerByte;
-#if ENABLE(ASSERT)
- static uint16_t s_gcGeneration;
-#endif
+ static uint32_t s_gcGeneration;
friend class ThreadState;
};
@@ -455,7 +480,7 @@ inline Address Heap::allocateOnHeapIndex(ThreadState* state, size_t size, int he
ASSERT(state->isAllocationAllowed());
ASSERT(heapIndex != BlinkGC::LargeObjectHeapIndex);
NormalPageHeap* heap = static_cast<NormalPageHeap*>(state->heap(heapIndex));
- return heap->allocateObject(allocationSizeFromSize(size), gcInfoIndex);
+ return heap->allocateObject(allocationSizeFromSize(size), gcInfoIndex, gcGeneration());
}
template<typename T>
« no previous file with comments | « third_party/WebKit/Source/platform/heap/Handle.h ('k') | third_party/WebKit/Source/platform/heap/Heap.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698