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 20 matching lines...) Expand all Loading... |
31 #ifndef Heap_h | 31 #ifndef Heap_h |
32 #define Heap_h | 32 #define Heap_h |
33 | 33 |
34 #include "platform/PlatformExport.h" | 34 #include "platform/PlatformExport.h" |
35 #include "platform/heap/GCInfo.h" | 35 #include "platform/heap/GCInfo.h" |
36 #include "platform/heap/HeapPage.h" | 36 #include "platform/heap/HeapPage.h" |
37 #include "platform/heap/PageMemory.h" | 37 #include "platform/heap/PageMemory.h" |
38 #include "platform/heap/ThreadState.h" | 38 #include "platform/heap/ThreadState.h" |
39 #include "platform/heap/Visitor.h" | 39 #include "platform/heap/Visitor.h" |
40 #include "wtf/AddressSanitizer.h" | 40 #include "wtf/AddressSanitizer.h" |
| 41 #include "wtf/Allocator.h" |
41 #include "wtf/Assertions.h" | 42 #include "wtf/Assertions.h" |
42 #include "wtf/Atomics.h" | 43 #include "wtf/Atomics.h" |
43 #include "wtf/Forward.h" | 44 #include "wtf/Forward.h" |
44 | 45 |
45 namespace blink { | 46 namespace blink { |
46 | 47 |
47 class CrossThreadPersistentRegion; | 48 class CrossThreadPersistentRegion; |
48 template<typename T> class Member; | 49 template<typename T> class Member; |
49 template<typename T> class WeakMember; | 50 template<typename T> class WeakMember; |
50 template<typename T> class UntracedMember; | 51 template<typename T> class UntracedMember; |
51 | 52 |
52 template<typename T, bool = NeedsAdjustAndMark<T>::value> class ObjectAliveTrait
; | 53 template<typename T, bool = NeedsAdjustAndMark<T>::value> class ObjectAliveTrait
; |
53 | 54 |
54 template<typename T> | 55 template<typename T> |
55 class ObjectAliveTrait<T, false> { | 56 class ObjectAliveTrait<T, false> { |
| 57 STATIC_ONLY(ObjectAliveTrait); |
56 public: | 58 public: |
57 static bool isHeapObjectAlive(T* object) | 59 static bool isHeapObjectAlive(T* object) |
58 { | 60 { |
59 static_assert(sizeof(T), "T must be fully defined"); | 61 static_assert(sizeof(T), "T must be fully defined"); |
60 return HeapObjectHeader::fromPayload(object)->isMarked(); | 62 return HeapObjectHeader::fromPayload(object)->isMarked(); |
61 } | 63 } |
62 }; | 64 }; |
63 | 65 |
64 template<typename T> | 66 template<typename T> |
65 class ObjectAliveTrait<T, true> { | 67 class ObjectAliveTrait<T, true> { |
| 68 STATIC_ONLY(ObjectAliveTrait); |
66 public: | 69 public: |
67 static bool isHeapObjectAlive(T* object) | 70 static bool isHeapObjectAlive(T* object) |
68 { | 71 { |
69 static_assert(sizeof(T), "T must be fully defined"); | 72 static_assert(sizeof(T), "T must be fully defined"); |
70 return object->isHeapObjectAlive(); | 73 return object->isHeapObjectAlive(); |
71 } | 74 } |
72 }; | 75 }; |
73 | 76 |
74 class PLATFORM_EXPORT Heap { | 77 class PLATFORM_EXPORT Heap { |
| 78 STATIC_ONLY(Heap); |
75 public: | 79 public: |
76 static void init(); | 80 static void init(); |
77 static void shutdown(); | 81 static void shutdown(); |
78 static void doShutdown(); | 82 static void doShutdown(); |
79 | 83 |
80 static CrossThreadPersistentRegion& crossThreadPersistentRegion(); | 84 static CrossThreadPersistentRegion& crossThreadPersistentRegion(); |
81 | 85 |
82 #if ENABLE(ASSERT) | 86 #if ENABLE(ASSERT) |
83 static BasePage* findPageFromAddress(Address); | 87 static BasePage* findPageFromAddress(Address); |
84 static BasePage* findPageFromAddress(const void* pointer) { return findPageF
romAddress(reinterpret_cast<Address>(const_cast<void*>(pointer))); } | 88 static BasePage* findPageFromAddress(const void* pointer) { return findPageF
romAddress(reinterpret_cast<Address>(const_cast<void*>(pointer))); } |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 static double s_estimatedMarkingTimePerByte; | 299 static double s_estimatedMarkingTimePerByte; |
296 #if ENABLE(ASSERT) | 300 #if ENABLE(ASSERT) |
297 static uint16_t s_gcGeneration; | 301 static uint16_t s_gcGeneration; |
298 #endif | 302 #endif |
299 | 303 |
300 friend class ThreadState; | 304 friend class ThreadState; |
301 }; | 305 }; |
302 | 306 |
303 template<typename T> | 307 template<typename T> |
304 struct IsEagerlyFinalizedType { | 308 struct IsEagerlyFinalizedType { |
| 309 STATIC_ONLY(IsEagerlyFinalizedType); |
305 private: | 310 private: |
306 typedef char YesType; | 311 typedef char YesType; |
307 struct NoType { | 312 struct NoType { |
308 char padding[8]; | 313 char padding[8]; |
309 }; | 314 }; |
310 | 315 |
311 template <typename U> static YesType checkMarker(typename U::IsEagerlyFinali
zedMarker*); | 316 template <typename U> static YesType checkMarker(typename U::IsEagerlyFinali
zedMarker*); |
312 template <typename U> static NoType checkMarker(...); | 317 template <typename U> static NoType checkMarker(...); |
313 | 318 |
314 public: | 319 public: |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 public: \ | 404 public: \ |
400 GC_PLUGIN_IGNORE("491488") \ | 405 GC_PLUGIN_IGNORE("491488") \ |
401 void* operator new(size_t size) \ | 406 void* operator new(size_t size) \ |
402 { \ | 407 { \ |
403 return allocateObject(size, true); \ | 408 return allocateObject(size, true); \ |
404 } | 409 } |
405 | 410 |
406 #define IS_EAGERLY_FINALIZED() (pageFromObject(this)->heap()->heapIndex() == Bli
nkGC::EagerSweepHeapIndex) | 411 #define IS_EAGERLY_FINALIZED() (pageFromObject(this)->heap()->heapIndex() == Bli
nkGC::EagerSweepHeapIndex) |
407 #if ENABLE(ASSERT) && ENABLE(OILPAN) | 412 #if ENABLE(ASSERT) && ENABLE(OILPAN) |
408 class VerifyEagerFinalization { | 413 class VerifyEagerFinalization { |
| 414 DISALLOW_NEW(); |
409 public: | 415 public: |
410 ~VerifyEagerFinalization() | 416 ~VerifyEagerFinalization() |
411 { | 417 { |
412 // If this assert triggers, the class annotated as eagerly | 418 // If this assert triggers, the class annotated as eagerly |
413 // finalized ended up not being allocated on the heap | 419 // finalized ended up not being allocated on the heap |
414 // set aside for eager finalization. The reason is most | 420 // set aside for eager finalization. The reason is most |
415 // likely that the effective 'operator new' overload for | 421 // likely that the effective 'operator new' overload for |
416 // this class' leftmost base is for a class that is not | 422 // this class' leftmost base is for a class that is not |
417 // eagerly finalized. Declaring and defining an 'operator new' | 423 // eagerly finalized. Declaring and defining an 'operator new' |
418 // for this class is what's required -- consider using | 424 // for this class is what's required -- consider using |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 void VisitorHelper<Derived>::handleWeakCell(Visitor* self, void* object) | 494 void VisitorHelper<Derived>::handleWeakCell(Visitor* self, void* object) |
489 { | 495 { |
490 T** cell = reinterpret_cast<T**>(object); | 496 T** cell = reinterpret_cast<T**>(object); |
491 if (*cell && !ObjectAliveTrait<T>::isHeapObjectAlive(*cell)) | 497 if (*cell && !ObjectAliveTrait<T>::isHeapObjectAlive(*cell)) |
492 *cell = nullptr; | 498 *cell = nullptr; |
493 } | 499 } |
494 | 500 |
495 } // namespace blink | 501 } // namespace blink |
496 | 502 |
497 #endif // Heap_h | 503 #endif // Heap_h |
OLD | NEW |