| OLD | NEW |
| 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 class UntracedMember; | 86 class UntracedMember; |
| 87 | 87 |
| 88 template <typename T, bool = NeedsAdjustAndMark<T>::value> | 88 template <typename T, bool = NeedsAdjustAndMark<T>::value> |
| 89 class ObjectAliveTrait; | 89 class ObjectAliveTrait; |
| 90 | 90 |
| 91 template <typename T> | 91 template <typename T> |
| 92 class ObjectAliveTrait<T, false> { | 92 class ObjectAliveTrait<T, false> { |
| 93 STATIC_ONLY(ObjectAliveTrait); | 93 STATIC_ONLY(ObjectAliveTrait); |
| 94 | 94 |
| 95 public: | 95 public: |
| 96 static bool isHeapObjectAlive(T* object) { | 96 static bool isHeapObjectAlive(const T* object) { |
| 97 static_assert(sizeof(T), "T must be fully defined"); | 97 static_assert(sizeof(T), "T must be fully defined"); |
| 98 return HeapObjectHeader::fromPayload(object)->isMarked(); | 98 return HeapObjectHeader::fromPayload(object)->isMarked(); |
| 99 } | 99 } |
| 100 }; | 100 }; |
| 101 | 101 |
| 102 template <typename T> | 102 template <typename T> |
| 103 class ObjectAliveTrait<T, true> { | 103 class ObjectAliveTrait<T, true> { |
| 104 STATIC_ONLY(ObjectAliveTrait); | 104 STATIC_ONLY(ObjectAliveTrait); |
| 105 | 105 |
| 106 public: | 106 public: |
| 107 NO_SANITIZE_ADDRESS | 107 NO_SANITIZE_ADDRESS |
| 108 static bool isHeapObjectAlive(T* object) { | 108 static bool isHeapObjectAlive(const T* object) { |
| 109 static_assert(sizeof(T), "T must be fully defined"); | 109 static_assert(sizeof(T), "T must be fully defined"); |
| 110 return object->isHeapObjectAlive(); | 110 return object->isHeapObjectAlive(); |
| 111 } | 111 } |
| 112 }; | 112 }; |
| 113 | 113 |
| 114 class PLATFORM_EXPORT ProcessHeap { | 114 class PLATFORM_EXPORT ProcessHeap { |
| 115 STATIC_ONLY(ProcessHeap); | 115 STATIC_ONLY(ProcessHeap); |
| 116 | 116 |
| 117 public: | 117 public: |
| 118 static void init(); | 118 static void init(); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 // TODO(keishi): Per-thread-heap will return false. | 231 // TODO(keishi): Per-thread-heap will return false. |
| 232 bool isMainThreadHeap() { return this == ThreadHeap::mainThreadHeap(); } | 232 bool isMainThreadHeap() { return this == ThreadHeap::mainThreadHeap(); } |
| 233 static ThreadHeap* mainThreadHeap() { return s_mainThreadHeap; } | 233 static ThreadHeap* mainThreadHeap() { return s_mainThreadHeap; } |
| 234 | 234 |
| 235 #if ENABLE(ASSERT) | 235 #if ENABLE(ASSERT) |
| 236 bool isAtSafePoint(); | 236 bool isAtSafePoint(); |
| 237 BasePage* findPageFromAddress(Address); | 237 BasePage* findPageFromAddress(Address); |
| 238 #endif | 238 #endif |
| 239 | 239 |
| 240 template <typename T> | 240 template <typename T> |
| 241 static inline bool isHeapObjectAlive(T* object) { | 241 static inline bool isHeapObjectAlive(const T* object) { |
| 242 static_assert(sizeof(T), "T must be fully defined"); | 242 static_assert(sizeof(T), "T must be fully defined"); |
| 243 // The strongification of collections relies on the fact that once a | 243 // The strongification of collections relies on the fact that once a |
| 244 // collection has been strongified, there is no way that it can contain | 244 // collection has been strongified, there is no way that it can contain |
| 245 // non-live entries, so no entries will be removed. Since you can't set | 245 // non-live entries, so no entries will be removed. Since you can't set |
| 246 // the mark bit on a null pointer, that means that null pointers are | 246 // the mark bit on a null pointer, that means that null pointers are |
| 247 // always 'alive'. | 247 // always 'alive'. |
| 248 if (!object) | 248 if (!object) |
| 249 return true; | 249 return true; |
| 250 // TODO(keishi): some tests create CrossThreadPersistent on non attached | 250 // TODO(keishi): some tests create CrossThreadPersistent on non attached |
| 251 // threads. | 251 // threads. |
| 252 if (!ThreadState::current()) | 252 if (!ThreadState::current()) |
| 253 return true; | 253 return true; |
| 254 if (&ThreadState::current()->heap() != | 254 if (&ThreadState::current()->heap() != |
| 255 &pageFromObject(object)->arena()->getThreadState()->heap()) | 255 &pageFromObject(object)->arena()->getThreadState()->heap()) |
| 256 return true; | 256 return true; |
| 257 return ObjectAliveTrait<T>::isHeapObjectAlive(object); | 257 return ObjectAliveTrait<T>::isHeapObjectAlive(object); |
| 258 } | 258 } |
| 259 template <typename T> | 259 template <typename T> |
| 260 static inline bool isHeapObjectAlive(const Member<T>& member) { | 260 static inline bool isHeapObjectAlive(const Member<T>& member) { |
| 261 return isHeapObjectAlive(member.get()); | 261 return isHeapObjectAlive(member.get()); |
| 262 } | 262 } |
| 263 template <typename T> | 263 template <typename T> |
| 264 static inline bool isHeapObjectAlive(const WeakMember<T>& member) { | 264 static inline bool isHeapObjectAlive(const WeakMember<T>& member) { |
| 265 return isHeapObjectAlive(member.get()); | 265 return isHeapObjectAlive(member.get()); |
| 266 } | 266 } |
| 267 template <typename T> | 267 template <typename T> |
| 268 static inline bool isHeapObjectAlive(const UntracedMember<T>& member) { | 268 static inline bool isHeapObjectAlive(const UntracedMember<T>& member) { |
| 269 return isHeapObjectAlive(member.get()); | 269 return isHeapObjectAlive(member.get()); |
| 270 } | 270 } |
| 271 template <typename T> | |
| 272 static inline bool isHeapObjectAlive(const T*& ptr) { | |
| 273 return isHeapObjectAlive(ptr); | |
| 274 } | |
| 275 | 271 |
| 276 StackFrameDepth& stackFrameDepth() { return m_stackFrameDepth; } | 272 StackFrameDepth& stackFrameDepth() { return m_stackFrameDepth; } |
| 277 | 273 |
| 278 RecursiveMutex& threadAttachMutex() { return m_threadAttachMutex; } | 274 RecursiveMutex& threadAttachMutex() { return m_threadAttachMutex; } |
| 279 const ThreadStateSet& threads() const { return m_threads; } | 275 const ThreadStateSet& threads() const { return m_threads; } |
| 280 ThreadHeapStats& heapStats() { return m_stats; } | 276 ThreadHeapStats& heapStats() { return m_stats; } |
| 281 SafePointBarrier* safePointBarrier() { return m_safePointBarrier.get(); } | 277 SafePointBarrier* safePointBarrier() { return m_safePointBarrier.get(); } |
| 282 CallbackStack* markingStack() const { return m_markingStack.get(); } | 278 CallbackStack* markingStack() const { return m_markingStack.get(); } |
| 283 CallbackStack* postMarkingCallbackStack() const { | 279 CallbackStack* postMarkingCallbackStack() const { |
| 284 return m_postMarkingCallbackStack.get(); | 280 return m_postMarkingCallbackStack.get(); |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 673 template <typename T> | 669 template <typename T> |
| 674 void VisitorHelper<Derived>::handleWeakCell(Visitor* self, void* object) { | 670 void VisitorHelper<Derived>::handleWeakCell(Visitor* self, void* object) { |
| 675 T** cell = reinterpret_cast<T**>(object); | 671 T** cell = reinterpret_cast<T**>(object); |
| 676 if (*cell && !ObjectAliveTrait<T>::isHeapObjectAlive(*cell)) | 672 if (*cell && !ObjectAliveTrait<T>::isHeapObjectAlive(*cell)) |
| 677 *cell = nullptr; | 673 *cell = nullptr; |
| 678 } | 674 } |
| 679 | 675 |
| 680 } // namespace blink | 676 } // namespace blink |
| 681 | 677 |
| 682 #endif // Heap_h | 678 #endif // Heap_h |
| OLD | NEW |