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

Unified Diff: Source/heap/Handle.h

Issue 221823002: Oilpan: add explicit Persistent<T>(T&) and Member<T>(T&) constructors. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 9 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/frame/DOMWindow.cpp ('k') | Source/modules/websockets/WebSocketChannel.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/heap/Handle.h
diff --git a/Source/heap/Handle.h b/Source/heap/Handle.h
index 4025e95e89f2779d2529fd4a925d7d9bb3799fca..f0e312a4b21a8992ca4cbe91976e3d8b7fc42f5d 100644
--- a/Source/heap/Handle.h
+++ b/Source/heap/Handle.h
@@ -216,6 +216,17 @@ private:
friend class ThreadState;
};
+#ifndef NDEBUG
+ // For global persistent handles we cannot check that the
+ // pointer is in the heap because that would involve
+ // inspecting the heap of running threads.
+#define ASSERT_IS_VALID_PERSISTENT_POINTER(pointer) \
+ bool isGlobalPersistent = WTF::IsSubclass<RootsAccessor, GlobalPersistents>::value; \
+ ASSERT(!pointer || isGlobalPersistent || ThreadStateFor<ThreadingTrait<T>::Affinity>::state()->contains(pointer))
+#else
+#define ASSERT_IS_VALID_PERSISTENT_POINTER(raw)
+#endif
+
template<typename T>
class CrossThreadPersistent;
@@ -251,13 +262,13 @@ public:
Persistent(T* raw) : m_raw(raw)
{
COMPILE_ASSERT_IS_GARBAGE_COLLECTED(T, NonGarbageCollectedObjectInPersistent);
-#ifndef NDEBUG
- // For global persistent handles we cannot check that the
- // pointer is in the heap because that would involve
- // inspecting the heap of running threads.
- bool isGlobalPersistent = WTF::IsSubclass<RootsAccessor, GlobalPersistents>::value;
- ASSERT(!raw || isGlobalPersistent || ThreadStateFor<ThreadingTrait<T>::Affinity>::state()->contains(raw));
-#endif
+ ASSERT_IS_VALID_PERSISTENT_POINTER(m_raw);
+ }
+
+ explicit Persistent(T& raw) : m_raw(&raw)
+ {
+ COMPILE_ASSERT_IS_GARBAGE_COLLECTED(T, NonGarbageCollectedObjectInPersistent);
+ ASSERT_IS_VALID_PERSISTENT_POINTER(m_raw);
}
Persistent(const Persistent& other) : m_raw(other)
@@ -353,6 +364,8 @@ private:
friend class CrossThreadPersistent<T>;
};
+#undef ASSERT_IS_VALID_PERSISTENT_POINTER
+
// Unlike Persistent, we can destruct a CrossThreadPersistent in a thread
// different from the construction thread.
template<typename T>
@@ -432,6 +445,11 @@ public:
COMPILE_ASSERT_IS_GARBAGE_COLLECTED(T, NonGarbageCollectedObjectInMember);
}
+ explicit Member(T& raw) : m_raw(&raw)
+ {
+ COMPILE_ASSERT_IS_GARBAGE_COLLECTED(T, NonGarbageCollectedObjectInMember);
haraken 2014/04/02 07:49:41 Can we implement ASSERT_IS_VALID_MEMBER_POINTER as
sof 2014/04/02 08:05:50 Catching out cross-heap references would be useful
haraken 2014/04/02 08:09:29 Oh, sorry. Cross-heap references are allowed, so w
sof 2014/04/02 08:12:54 Interesting, what code relies on creating such cro
haraken 2014/04/02 08:15:41 I think some classes in webdatabase/ are using cro
Mads Ager (chromium) 2014/04/02 08:22:04 That is correct, we have cross thread pointers in
+ }
+
Member(WTF::HashTableDeletedValueType) : m_raw(reinterpret_cast<T*>(-1))
{
COMPILE_ASSERT_IS_GARBAGE_COLLECTED(T, NonGarbageCollectedObjectInMember);
« no previous file with comments | « Source/core/frame/DOMWindow.cpp ('k') | Source/modules/websockets/WebSocketChannel.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698