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 29 matching lines...) Expand all Loading... | |
40 #include "wtf/Assertions.h" | 40 #include "wtf/Assertions.h" |
41 #include "wtf/Atomics.h" | 41 #include "wtf/Atomics.h" |
42 #include "wtf/Forward.h" | 42 #include "wtf/Forward.h" |
43 | 43 |
44 namespace blink { | 44 namespace blink { |
45 | 45 |
46 template<typename T> class Member; | 46 template<typename T> class Member; |
47 template<typename T> class WeakMember; | 47 template<typename T> class WeakMember; |
48 template<typename T> class UntracedMember; | 48 template<typename T> class UntracedMember; |
49 | 49 |
50 // TODO(peria): Refactor following two sets of template. | |
haraken
2015/11/16 09:38:20
templates
peria
2015/11/16 12:28:45
Done.
| |
51 | |
50 template<typename T, bool = NeedsAdjustAndMark<T>::value> class ObjectAliveTrait ; | 52 template<typename T, bool = NeedsAdjustAndMark<T>::value> class ObjectAliveTrait ; |
51 | 53 |
52 template<typename T> | 54 template<typename T> |
53 class ObjectAliveTrait<T, false> { | 55 class ObjectAliveTrait<T, false> { |
54 public: | 56 public: |
55 static bool isHeapObjectAlive(T* object) | 57 static bool isHeapObjectAlive(T* object) |
56 { | 58 { |
57 static_assert(sizeof(T), "T must be fully defined"); | 59 static_assert(sizeof(T), "T must be fully defined"); |
58 return HeapObjectHeader::fromPayload(object)->isMarked(); | 60 return HeapObjectHeader::fromPayload(object)->isMarked(); |
59 } | 61 } |
60 }; | 62 }; |
61 | 63 |
62 template<typename T> | 64 template<typename T> |
63 class ObjectAliveTrait<T, true> { | 65 class ObjectAliveTrait<T, true> { |
64 public: | 66 public: |
65 static bool isHeapObjectAlive(T* object) | 67 static bool isHeapObjectAlive(T* object) |
66 { | 68 { |
69 return object->isHeapObjectAlive(); | |
70 } | |
71 }; | |
72 | |
73 template<typename T, bool = IsGarbageCollectedMixin<T>::value> class HeapObjectH eaderTrait; | |
74 | |
75 template<typename T> | |
76 class HeapObjectHeaderTrait<T, true> { | |
77 public: | |
78 static HeapObjectHeader* heapObjectHeader(T* obj) | |
79 { | |
67 static_assert(sizeof(T), "T must be fully defined"); | 80 static_assert(sizeof(T), "T must be fully defined"); |
68 return object->isHeapObjectAlive(); | 81 // TODO(peria): Update thi ASSERT() to check if |obj| is begin construct ed. |
82 // We can use this method for other GCMixin objects. | |
haraken
2015/11/16 09:38:20
Slightly better:
// TODO(peria): This ASSERT is t
peria
2015/11/16 12:28:45
Done.
| |
83 ASSERT(!ThreadState::current()->isConstructingGCMixin()); | |
84 return obj->heapObjectHeader(); | |
85 } | |
86 }; | |
87 | |
88 template<typename T> | |
89 class HeapObjectHeaderTrait<T, false> { | |
90 public: | |
91 static HeapObjectHeader* heapObjectHeader(T* obj) | |
92 { | |
haraken
2015/11/16 09:38:20
Add ASSERT(!ThreadState::current()->isConstructing
peria
2015/11/16 12:28:45
Done.
| |
93 if (!IsFullyDefined<T>::value) | |
haraken
2015/11/16 09:38:20
What happens if you use static_assert(sizeof(T)) ?
peria
2015/11/16 12:28:45
It fails in compiling some header files which call
| |
94 return nullptr; | |
95 return HeapObjectHeader::fromPayload(obj); | |
69 } | 96 } |
70 }; | 97 }; |
71 | 98 |
72 class PLATFORM_EXPORT Heap { | 99 class PLATFORM_EXPORT Heap { |
73 public: | 100 public: |
74 static void init(); | 101 static void init(); |
75 static void shutdown(); | 102 static void shutdown(); |
76 static void doShutdown(); | 103 static void doShutdown(); |
77 | 104 |
78 #if ENABLE(ASSERT) | 105 #if ENABLE(ASSERT) |
(...skipping 10 matching lines...) Expand all Loading... | |
89 // non-live entries, so no entries will be removed. Since you can't set | 116 // non-live entries, so no entries will be removed. Since you can't set |
90 // the mark bit on a null pointer, that means that null pointers are | 117 // the mark bit on a null pointer, that means that null pointers are |
91 // always 'alive'. | 118 // always 'alive'. |
92 if (!object) | 119 if (!object) |
93 return true; | 120 return true; |
94 return ObjectAliveTrait<T>::isHeapObjectAlive(object); | 121 return ObjectAliveTrait<T>::isHeapObjectAlive(object); |
95 } | 122 } |
96 template<typename T> | 123 template<typename T> |
97 static inline bool isHeapObjectAlive(const Member<T>& member) | 124 static inline bool isHeapObjectAlive(const Member<T>& member) |
98 { | 125 { |
99 return isHeapObjectAlive(member.get()); | 126 return isHeapObjectAlive(member.unsafeGet()); |
100 } | 127 } |
101 template<typename T> | 128 template<typename T> |
102 static inline bool isHeapObjectAlive(const WeakMember<T>& member) | 129 static inline bool isHeapObjectAlive(const WeakMember<T>& member) |
103 { | 130 { |
104 return isHeapObjectAlive(member.get()); | 131 return isHeapObjectAlive(member.unsafeGet()); |
105 } | 132 } |
106 template<typename T> | 133 template<typename T> |
107 static inline bool isHeapObjectAlive(const UntracedMember<T>& member) | 134 static inline bool isHeapObjectAlive(const UntracedMember<T>& member) |
108 { | 135 { |
109 return isHeapObjectAlive(member.get()); | 136 return isHeapObjectAlive(member.unsafeGet()); |
110 } | 137 } |
111 template<typename T> | 138 template<typename T> |
112 static inline bool isHeapObjectAlive(const RawPtr<T>& ptr) | 139 static inline bool isHeapObjectAlive(const RawPtr<T>& ptr) |
113 { | 140 { |
114 return isHeapObjectAlive(ptr.get()); | 141 return isHeapObjectAlive(ptr.get()); |
115 } | 142 } |
116 | 143 |
117 // Is the finalizable GC object still alive, but slated for lazy sweeping? | 144 // Is the finalizable GC object still alive, but slated for lazy sweeping? |
118 // If a lazy sweep is in progress, returns true if the object was found | 145 // If a lazy sweep is in progress, returns true if the object was found |
119 // to be not reachable during the marking phase, but it has yet to be swept | 146 // to be not reachable during the marking phase, but it has yet to be swept |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
252 static size_t wrapperCount() { return acquireLoad(&s_wrapperCount); } | 279 static size_t wrapperCount() { return acquireLoad(&s_wrapperCount); } |
253 static size_t wrapperCountAtLastGC() { return acquireLoad(&s_wrapperCountAtL astGC); } | 280 static size_t wrapperCountAtLastGC() { return acquireLoad(&s_wrapperCountAtL astGC); } |
254 static void increaseCollectedWrapperCount(size_t delta) { atomicAdd(&s_colle ctedWrapperCount, static_cast<long>(delta)); } | 281 static void increaseCollectedWrapperCount(size_t delta) { atomicAdd(&s_colle ctedWrapperCount, static_cast<long>(delta)); } |
255 static size_t collectedWrapperCount() { return acquireLoad(&s_collectedWrapp erCount); } | 282 static size_t collectedWrapperCount() { return acquireLoad(&s_collectedWrapp erCount); } |
256 static size_t partitionAllocSizeAtLastGC() { return acquireLoad(&s_partition AllocSizeAtLastGC); } | 283 static size_t partitionAllocSizeAtLastGC() { return acquireLoad(&s_partition AllocSizeAtLastGC); } |
257 | 284 |
258 static double estimatedMarkingTime(); | 285 static double estimatedMarkingTime(); |
259 static void reportMemoryUsageHistogram(); | 286 static void reportMemoryUsageHistogram(); |
260 static void reportMemoryUsageForTracing(); | 287 static void reportMemoryUsageForTracing(); |
261 | 288 |
262 #if ENABLE(ASSERT) | 289 static uint32_t gcGeneration() { return s_gcGeneration; } |
263 static uint16_t gcGeneration() { return s_gcGeneration; } | |
264 #endif | |
265 | 290 |
266 private: | 291 private: |
267 // A RegionTree is a simple binary search tree of PageMemoryRegions sorted | 292 // A RegionTree is a simple binary search tree of PageMemoryRegions sorted |
268 // by base addresses. | 293 // by base addresses. |
269 class RegionTree { | 294 class RegionTree { |
270 public: | 295 public: |
271 explicit RegionTree(PageMemoryRegion* region) : m_region(region), m_left (nullptr), m_right(nullptr) { } | 296 explicit RegionTree(PageMemoryRegion* region) : m_region(region), m_left (nullptr), m_right(nullptr) { } |
272 ~RegionTree() | 297 ~RegionTree() |
273 { | 298 { |
274 delete m_left; | 299 delete m_left; |
(...skipping 26 matching lines...) Expand all Loading... | |
301 static size_t s_allocatedSpace; | 326 static size_t s_allocatedSpace; |
302 static size_t s_allocatedObjectSize; | 327 static size_t s_allocatedObjectSize; |
303 static size_t s_objectSizeAtLastGC; | 328 static size_t s_objectSizeAtLastGC; |
304 static size_t s_markedObjectSize; | 329 static size_t s_markedObjectSize; |
305 static size_t s_markedObjectSizeAtLastCompleteSweep; | 330 static size_t s_markedObjectSizeAtLastCompleteSweep; |
306 static size_t s_wrapperCount; | 331 static size_t s_wrapperCount; |
307 static size_t s_wrapperCountAtLastGC; | 332 static size_t s_wrapperCountAtLastGC; |
308 static size_t s_collectedWrapperCount; | 333 static size_t s_collectedWrapperCount; |
309 static size_t s_partitionAllocSizeAtLastGC; | 334 static size_t s_partitionAllocSizeAtLastGC; |
310 static double s_estimatedMarkingTimePerByte; | 335 static double s_estimatedMarkingTimePerByte; |
311 #if ENABLE(ASSERT) | 336 static uint32_t s_gcGeneration; |
312 static uint16_t s_gcGeneration; | |
313 #endif | |
314 | 337 |
315 friend class ThreadState; | 338 friend class ThreadState; |
316 }; | 339 }; |
317 | 340 |
318 template<typename T> | 341 template<typename T> |
319 struct IsEagerlyFinalizedType { | 342 struct IsEagerlyFinalizedType { |
320 private: | 343 private: |
321 typedef char YesType; | 344 typedef char YesType; |
322 struct NoType { | 345 struct NoType { |
323 char padding[8]; | 346 char padding[8]; |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
448 #define EAGERLY_FINALIZE_WILL_BE_REMOVED() EAGERLY_FINALIZE() | 471 #define EAGERLY_FINALIZE_WILL_BE_REMOVED() EAGERLY_FINALIZE() |
449 #else | 472 #else |
450 #define EAGERLY_FINALIZE_WILL_BE_REMOVED() | 473 #define EAGERLY_FINALIZE_WILL_BE_REMOVED() |
451 #endif | 474 #endif |
452 | 475 |
453 inline Address Heap::allocateOnHeapIndex(ThreadState* state, size_t size, int he apIndex, size_t gcInfoIndex) | 476 inline Address Heap::allocateOnHeapIndex(ThreadState* state, size_t size, int he apIndex, size_t gcInfoIndex) |
454 { | 477 { |
455 ASSERT(state->isAllocationAllowed()); | 478 ASSERT(state->isAllocationAllowed()); |
456 ASSERT(heapIndex != BlinkGC::LargeObjectHeapIndex); | 479 ASSERT(heapIndex != BlinkGC::LargeObjectHeapIndex); |
457 NormalPageHeap* heap = static_cast<NormalPageHeap*>(state->heap(heapIndex)); | 480 NormalPageHeap* heap = static_cast<NormalPageHeap*>(state->heap(heapIndex)); |
458 return heap->allocateObject(allocationSizeFromSize(size), gcInfoIndex); | 481 return heap->allocateObject(allocationSizeFromSize(size), gcInfoIndex, gcGen eration()); |
459 } | 482 } |
460 | 483 |
461 template<typename T> | 484 template<typename T> |
462 Address Heap::allocate(size_t size, bool eagerlySweep) | 485 Address Heap::allocate(size_t size, bool eagerlySweep) |
463 { | 486 { |
464 ThreadState* state = ThreadStateFor<ThreadingTrait<T>::Affinity>::state(); | 487 ThreadState* state = ThreadStateFor<ThreadingTrait<T>::Affinity>::state(); |
465 return Heap::allocateOnHeapIndex(state, size, eagerlySweep ? BlinkGC::EagerS weepHeapIndex : Heap::heapIndexForObjectSize(size), GCInfoTrait<T>::index()); | 488 return Heap::allocateOnHeapIndex(state, size, eagerlySweep ? BlinkGC::EagerS weepHeapIndex : Heap::heapIndexForObjectSize(size), GCInfoTrait<T>::index()); |
466 } | 489 } |
467 | 490 |
468 template<typename T> | 491 template<typename T> |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
503 void VisitorHelper<Derived>::handleWeakCell(Visitor* self, void* object) | 526 void VisitorHelper<Derived>::handleWeakCell(Visitor* self, void* object) |
504 { | 527 { |
505 T** cell = reinterpret_cast<T**>(object); | 528 T** cell = reinterpret_cast<T**>(object); |
506 if (*cell && !ObjectAliveTrait<T>::isHeapObjectAlive(*cell)) | 529 if (*cell && !ObjectAliveTrait<T>::isHeapObjectAlive(*cell)) |
507 *cell = nullptr; | 530 *cell = nullptr; |
508 } | 531 } |
509 | 532 |
510 } // namespace blink | 533 } // namespace blink |
511 | 534 |
512 #endif // Heap_h | 535 #endif // Heap_h |
OLD | NEW |