| 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 STATIC_ONLY(ObjectAliveTrait); | 96 STATIC_ONLY(ObjectAliveTrait); |
| 97 public: | 97 public: |
| 98 NO_LAZY_SWEEP_SANITIZE_ADDRESS | 98 NO_LAZY_SWEEP_SANITIZE_ADDRESS |
| 99 static bool isHeapObjectAlive(T* object) | 99 static bool isHeapObjectAlive(T* object) |
| 100 { | 100 { |
| 101 static_assert(sizeof(T), "T must be fully defined"); | 101 static_assert(sizeof(T), "T must be fully defined"); |
| 102 return object->isHeapObjectAlive(); | 102 return object->isHeapObjectAlive(); |
| 103 } | 103 } |
| 104 }; | 104 }; |
| 105 | 105 |
| 106 class PLATFORM_EXPORT ProcessHeap { |
| 107 STATIC_ONLY(ProcessHeap); |
| 108 public: |
| 109 static void init(); |
| 110 |
| 111 static CrossThreadPersistentRegion& crossThreadPersistentRegion(); |
| 112 |
| 113 static bool isLowEndDevice() { return s_isLowEndDevice; } |
| 114 static void increaseTotalAllocatedObjectSize(size_t delta) { atomicAdd(&s_to
talAllocatedObjectSize, static_cast<long>(delta)); } |
| 115 static void decreaseTotalAllocatedObjectSize(size_t delta) { atomicSubtract(
&s_totalAllocatedObjectSize, static_cast<long>(delta)); } |
| 116 static size_t totalAllocatedObjectSize() { return acquireLoad(&s_totalAlloca
tedObjectSize); } |
| 117 static void increaseTotalMarkedObjectSize(size_t delta) { atomicAdd(&s_total
MarkedObjectSize, static_cast<long>(delta)); } |
| 118 static size_t totalMarkedObjectSize() { return acquireLoad(&s_totalMarkedObj
ectSize); } |
| 119 static void increaseTotalAllocatedSpace(size_t delta) { atomicAdd(&s_totalAl
locatedSpace, static_cast<long>(delta)); } |
| 120 static void decreaseTotalAllocatedSpace(size_t delta) { atomicSubtract(&s_to
talAllocatedSpace, static_cast<long>(delta)); } |
| 121 static size_t totalAllocatedSpace() { return acquireLoad(&s_totalAllocatedSp
ace); } |
| 122 |
| 123 private: |
| 124 static bool s_isLowEndDevice; |
| 125 static size_t s_totalAllocatedSpace; |
| 126 static size_t s_totalAllocatedObjectSize; |
| 127 static size_t s_totalMarkedObjectSize; |
| 128 |
| 129 friend class ThreadState; |
| 130 }; |
| 131 |
| 106 class PLATFORM_EXPORT Heap { | 132 class PLATFORM_EXPORT Heap { |
| 107 STATIC_ONLY(Heap); | 133 STATIC_ONLY(Heap); |
| 108 public: | 134 public: |
| 109 static void init(); | 135 static void init(); |
| 110 static void shutdown(); | 136 static void shutdown(); |
| 111 | 137 |
| 112 static CrossThreadPersistentRegion& crossThreadPersistentRegion(); | |
| 113 | |
| 114 #if ENABLE(ASSERT) | 138 #if ENABLE(ASSERT) |
| 115 static BasePage* findPageFromAddress(Address); | 139 static BasePage* findPageFromAddress(Address); |
| 116 static BasePage* findPageFromAddress(const void* pointer) { return findPageF
romAddress(reinterpret_cast<Address>(const_cast<void*>(pointer))); } | 140 static BasePage* findPageFromAddress(const void* pointer) { return findPageF
romAddress(reinterpret_cast<Address>(const_cast<void*>(pointer))); } |
| 117 #endif | 141 #endif |
| 118 | 142 |
| 119 template<typename T> | 143 template<typename T> |
| 120 static inline bool isHeapObjectAlive(T* object) | 144 static inline bool isHeapObjectAlive(T* object) |
| 121 { | 145 { |
| 122 static_assert(sizeof(T), "T must be fully defined"); | 146 static_assert(sizeof(T), "T must be fully defined"); |
| 123 // The strongification of collections relies on the fact that once a | 147 // The strongification of collections relies on the fact that once a |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 ASSERT(gcInfoIndex >= 1); | 290 ASSERT(gcInfoIndex >= 1); |
| 267 ASSERT(gcInfoIndex < GCInfoTable::maxIndex); | 291 ASSERT(gcInfoIndex < GCInfoTable::maxIndex); |
| 268 ASSERT(s_gcInfoTable); | 292 ASSERT(s_gcInfoTable); |
| 269 const GCInfo* info = s_gcInfoTable[gcInfoIndex]; | 293 const GCInfo* info = s_gcInfoTable[gcInfoIndex]; |
| 270 ASSERT(info); | 294 ASSERT(info); |
| 271 return info; | 295 return info; |
| 272 } | 296 } |
| 273 | 297 |
| 274 static void setMarkedObjectSizeAtLastCompleteSweep(size_t size) { releaseSto
re(&s_markedObjectSizeAtLastCompleteSweep, size); } | 298 static void setMarkedObjectSizeAtLastCompleteSweep(size_t size) { releaseSto
re(&s_markedObjectSizeAtLastCompleteSweep, size); } |
| 275 static size_t markedObjectSizeAtLastCompleteSweep() { return acquireLoad(&s_
markedObjectSizeAtLastCompleteSweep); } | 299 static size_t markedObjectSizeAtLastCompleteSweep() { return acquireLoad(&s_
markedObjectSizeAtLastCompleteSweep); } |
| 276 static void increaseAllocatedObjectSize(size_t delta) { atomicAdd(&s_allocat
edObjectSize, static_cast<long>(delta)); } | 300 static void increaseAllocatedObjectSize(size_t delta) |
| 277 static void decreaseAllocatedObjectSize(size_t delta) { atomicSubtract(&s_al
locatedObjectSize, static_cast<long>(delta)); } | 301 { |
| 302 atomicAdd(&s_allocatedObjectSize, static_cast<long>(delta)); |
| 303 ProcessHeap::increaseTotalAllocatedObjectSize(delta); |
| 304 } |
| 305 static void decreaseAllocatedObjectSize(size_t delta) |
| 306 { |
| 307 atomicSubtract(&s_allocatedObjectSize, static_cast<long>(delta)); |
| 308 ProcessHeap::decreaseTotalAllocatedObjectSize(delta); |
| 309 } |
| 278 static size_t allocatedObjectSize() { return acquireLoad(&s_allocatedObjectS
ize); } | 310 static size_t allocatedObjectSize() { return acquireLoad(&s_allocatedObjectS
ize); } |
| 279 static void increaseMarkedObjectSize(size_t delta) { atomicAdd(&s_markedObje
ctSize, static_cast<long>(delta)); } | 311 static void increaseMarkedObjectSize(size_t delta) |
| 312 { |
| 313 atomicAdd(&s_markedObjectSize, static_cast<long>(delta)); |
| 314 ProcessHeap::increaseTotalMarkedObjectSize(delta); |
| 315 } |
| 280 static size_t markedObjectSize() { return acquireLoad(&s_markedObjectSize);
} | 316 static size_t markedObjectSize() { return acquireLoad(&s_markedObjectSize);
} |
| 281 static void increaseAllocatedSpace(size_t delta) { atomicAdd(&s_allocatedSpa
ce, static_cast<long>(delta)); } | 317 static void increaseAllocatedSpace(size_t delta) |
| 282 static void decreaseAllocatedSpace(size_t delta) { atomicSubtract(&s_allocat
edSpace, static_cast<long>(delta)); } | 318 { |
| 319 atomicAdd(&s_allocatedSpace, static_cast<long>(delta)); |
| 320 ProcessHeap::increaseTotalAllocatedSpace(delta); |
| 321 } |
| 322 static void decreaseAllocatedSpace(size_t delta) |
| 323 { |
| 324 atomicSubtract(&s_allocatedSpace, static_cast<long>(delta)); |
| 325 ProcessHeap::decreaseTotalAllocatedSpace(delta); |
| 326 } |
| 283 static size_t allocatedSpace() { return acquireLoad(&s_allocatedSpace); } | 327 static size_t allocatedSpace() { return acquireLoad(&s_allocatedSpace); } |
| 284 static size_t objectSizeAtLastGC() { return acquireLoad(&s_objectSizeAtLastG
C); } | 328 static size_t objectSizeAtLastGC() { return acquireLoad(&s_objectSizeAtLastG
C); } |
| 285 static void increaseWrapperCount(size_t delta) { atomicAdd(&s_wrapperCount,
static_cast<long>(delta)); } | 329 static void increaseWrapperCount(size_t delta) { atomicAdd(&s_wrapperCount,
static_cast<long>(delta)); } |
| 286 static void decreaseWrapperCount(size_t delta) { atomicSubtract(&s_wrapperCo
unt, static_cast<long>(delta)); } | 330 static void decreaseWrapperCount(size_t delta) { atomicSubtract(&s_wrapperCo
unt, static_cast<long>(delta)); } |
| 287 static size_t wrapperCount() { return acquireLoad(&s_wrapperCount); } | 331 static size_t wrapperCount() { return acquireLoad(&s_wrapperCount); } |
| 288 static size_t wrapperCountAtLastGC() { return acquireLoad(&s_wrapperCountAtL
astGC); } | 332 static size_t wrapperCountAtLastGC() { return acquireLoad(&s_wrapperCountAtL
astGC); } |
| 289 static void increaseCollectedWrapperCount(size_t delta) { atomicAdd(&s_colle
ctedWrapperCount, static_cast<long>(delta)); } | 333 static void increaseCollectedWrapperCount(size_t delta) { atomicAdd(&s_colle
ctedWrapperCount, static_cast<long>(delta)); } |
| 290 static size_t collectedWrapperCount() { return acquireLoad(&s_collectedWrapp
erCount); } | 334 static size_t collectedWrapperCount() { return acquireLoad(&s_collectedWrapp
erCount); } |
| 291 static size_t partitionAllocSizeAtLastGC() { return acquireLoad(&s_partition
AllocSizeAtLastGC); } | 335 static size_t partitionAllocSizeAtLastGC() { return acquireLoad(&s_partition
AllocSizeAtLastGC); } |
| 292 | 336 |
| 293 static double estimatedMarkingTime(); | 337 static double estimatedMarkingTime(); |
| 294 static void reportMemoryUsageHistogram(); | 338 static void reportMemoryUsageHistogram(); |
| 295 static void reportMemoryUsageForTracing(); | 339 static void reportMemoryUsageForTracing(); |
| 296 static bool isLowEndDevice() { return s_isLowEndDevice; } | |
| 297 static BlinkGC::GCReason lastGCReason() { return s_lastGCReason; } | 340 static BlinkGC::GCReason lastGCReason() { return s_lastGCReason; } |
| 298 | 341 |
| 299 #if ENABLE(ASSERT) | |
| 300 static uint16_t gcGeneration() { return s_gcGeneration; } | |
| 301 #endif | |
| 302 | |
| 303 private: | 342 private: |
| 304 // Reset counters that track live and allocated-since-last-GC sizes. | 343 // Reset counters that track live and allocated-since-last-GC sizes. |
| 305 static void resetHeapCounters(); | 344 static void resetHeapCounters(); |
| 306 | 345 |
| 307 static int arenaIndexForObjectSize(size_t); | 346 static int arenaIndexForObjectSize(size_t); |
| 308 static bool isNormalArenaIndex(int); | 347 static bool isNormalArenaIndex(int); |
| 309 | 348 |
| 310 static void decommitCallbackStacks(); | 349 static void decommitCallbackStacks(); |
| 311 | 350 |
| 312 static CallbackStack* s_markingStack; | 351 static CallbackStack* s_markingStack; |
| 313 static CallbackStack* s_postMarkingCallbackStack; | 352 static CallbackStack* s_postMarkingCallbackStack; |
| 314 static CallbackStack* s_globalWeakCallbackStack; | 353 static CallbackStack* s_globalWeakCallbackStack; |
| 315 static CallbackStack* s_ephemeronStack; | 354 static CallbackStack* s_ephemeronStack; |
| 316 static HeapDoesNotContainCache* s_heapDoesNotContainCache; | 355 static HeapDoesNotContainCache* s_heapDoesNotContainCache; |
| 317 static FreePagePool* s_freePagePool; | 356 static FreePagePool* s_freePagePool; |
| 318 static OrphanedPagePool* s_orphanedPagePool; | 357 static OrphanedPagePool* s_orphanedPagePool; |
| 319 static size_t s_allocatedSpace; | 358 static size_t s_allocatedSpace; |
| 320 static size_t s_allocatedObjectSize; | 359 static size_t s_allocatedObjectSize; |
| 321 static size_t s_objectSizeAtLastGC; | 360 static size_t s_objectSizeAtLastGC; |
| 322 static size_t s_markedObjectSize; | 361 static size_t s_markedObjectSize; |
| 323 static size_t s_markedObjectSizeAtLastCompleteSweep; | 362 static size_t s_markedObjectSizeAtLastCompleteSweep; |
| 324 static size_t s_wrapperCount; | 363 static size_t s_wrapperCount; |
| 325 static size_t s_wrapperCountAtLastGC; | 364 static size_t s_wrapperCountAtLastGC; |
| 326 static size_t s_collectedWrapperCount; | 365 static size_t s_collectedWrapperCount; |
| 327 static size_t s_partitionAllocSizeAtLastGC; | 366 static size_t s_partitionAllocSizeAtLastGC; |
| 328 static double s_estimatedMarkingTimePerByte; | 367 static double s_estimatedMarkingTimePerByte; |
| 329 static bool s_isLowEndDevice; | |
| 330 static BlinkGC::GCReason s_lastGCReason; | 368 static BlinkGC::GCReason s_lastGCReason; |
| 331 #if ENABLE(ASSERT) | |
| 332 static uint16_t s_gcGeneration; | |
| 333 #endif | |
| 334 | 369 |
| 335 friend class ThreadState; | 370 friend class ThreadState; |
| 336 }; | 371 }; |
| 337 | 372 |
| 338 template<typename T> | 373 template<typename T> |
| 339 struct IsEagerlyFinalizedType { | 374 struct IsEagerlyFinalizedType { |
| 340 STATIC_ONLY(IsEagerlyFinalizedType); | 375 STATIC_ONLY(IsEagerlyFinalizedType); |
| 341 private: | 376 private: |
| 342 typedef char YesType; | 377 typedef char YesType; |
| 343 struct NoType { | 378 struct NoType { |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 void VisitorHelper<Derived>::handleWeakCell(Visitor* self, void* object) | 565 void VisitorHelper<Derived>::handleWeakCell(Visitor* self, void* object) |
| 531 { | 566 { |
| 532 T** cell = reinterpret_cast<T**>(object); | 567 T** cell = reinterpret_cast<T**>(object); |
| 533 if (*cell && !ObjectAliveTrait<T>::isHeapObjectAlive(*cell)) | 568 if (*cell && !ObjectAliveTrait<T>::isHeapObjectAlive(*cell)) |
| 534 *cell = nullptr; | 569 *cell = nullptr; |
| 535 } | 570 } |
| 536 | 571 |
| 537 } // namespace blink | 572 } // namespace blink |
| 538 | 573 |
| 539 #endif // Heap_h | 574 #endif // Heap_h |
| OLD | NEW |