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

Unified Diff: Source/heap/Heap.h

Issue 16267005: [oilpan] Add checks to new operator Base URL: svn://svn.chromium.org/blink/branches/oilpan
Patch Set: Created 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/dom/Node.h ('k') | Source/heap/tests/HeapTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/heap/Heap.h
diff --git a/Source/heap/Heap.h b/Source/heap/Heap.h
index 50ee7277b246623b2530160ae7c390e472e59188..a6b897ee4ffa98ad85aefcb10488b9772e0cfa4f 100644
--- a/Source/heap/Heap.h
+++ b/Source/heap/Heap.h
@@ -442,10 +442,36 @@ template<typename T>
class HeapAllocatedFinalized : public HeapAllocated<T> {
WTF_MAKE_NONCOPYABLE(HeapAllocatedFinalized);
+ // If this assert fails then you are inheriting this method instead of
Mads Ager (chromium) 2013/06/11 06:42:43 This comment seems to belong on the inherited new
+ // overriding it. This may be an issue because the inherited class
+ // specialization (T) is used to find the finalizer. This may mean that the
+ // wrong method is used in the allocateFinalized specialization below and
+ // the wrong accept method may be used to visit the method if there is a GC
+ // before the new object has been adopted.
+#define OVERRIDE_NEW(subClass) \
+ void* operator new(size_t size) \
+ { \
+ ASSERT(size == sizeof(class subClass)); \
+ return Heap::allocateFinalized<subClass>(size); \
+ }
+
+// Only use this for classes where we know that accept(Visitor*) is dynamic,
+// ie. it is virtual or uses a type field that is immediately initialized
+// in the constuctors. Similarly the finalizer must be the same for all
+// subclasses.
+#define OVERRIDE_NEW_ALL_SUBCLASSES_HAVE_DYNAMIC_ACCEPT(subClass) \
+ void* operator new(size_t size) \
+ { \
+ return Heap::allocateFinalized<subClass>(size); \
+ }
+
public:
// Override new to pass the finalizer.
void* operator new(size_t size)
{
+ // If this assert fails you probably need to use OVERRIDE_NEW
+ // (see above).
+ ASSERT(size == sizeof(T));
return Heap::allocateFinalized<T>(size);
}
« no previous file with comments | « Source/core/dom/Node.h ('k') | Source/heap/tests/HeapTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698