| 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 if (UNLIKELY(!!freeHook)) | 74 if (UNLIKELY(!!freeHook)) |
| 75 freeHook(address); | 75 freeHook(address); |
| 76 } | 76 } |
| 77 | 77 |
| 78 private: | 78 private: |
| 79 static AllocationHook* m_allocationHook; | 79 static AllocationHook* m_allocationHook; |
| 80 static FreeHook* m_freeHook; | 80 static FreeHook* m_freeHook; |
| 81 }; | 81 }; |
| 82 | 82 |
| 83 class CrossThreadPersistentRegion; | 83 class CrossThreadPersistentRegion; |
| 84 class HeapCompact; |
| 84 template <typename T> | 85 template <typename T> |
| 85 class Member; | 86 class Member; |
| 86 template <typename T> | 87 template <typename T> |
| 87 class WeakMember; | 88 class WeakMember; |
| 88 template <typename T> | 89 template <typename T> |
| 89 class UntracedMember; | 90 class UntracedMember; |
| 90 | 91 |
| 91 template <typename T, bool = NeedsAdjustAndMark<T>::value> | 92 template <typename T, bool = NeedsAdjustAndMark<T>::value> |
| 92 class ObjectAliveTrait; | 93 class ObjectAliveTrait; |
| 93 | 94 |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 bool popAndInvokeGlobalWeakCallback(Visitor*); | 375 bool popAndInvokeGlobalWeakCallback(Visitor*); |
| 375 | 376 |
| 376 // Register an ephemeron table for fixed-point iteration. | 377 // Register an ephemeron table for fixed-point iteration. |
| 377 void registerWeakTable(void* containerObject, | 378 void registerWeakTable(void* containerObject, |
| 378 EphemeronCallback, | 379 EphemeronCallback, |
| 379 EphemeronCallback); | 380 EphemeronCallback); |
| 380 #if ENABLE(ASSERT) | 381 #if ENABLE(ASSERT) |
| 381 bool weakTableRegistered(const void*); | 382 bool weakTableRegistered(const void*); |
| 382 #endif | 383 #endif |
| 383 | 384 |
| 385 // Heap compaction registration methods: |
| 386 |
| 387 // Register |slot| as containing a reference to a movable heap object. |
| 388 // |
| 389 // When compaction moves the object pointed to by |*slot| to |newAddress|, |
| 390 // |*slot| must be updated to hold |newAddress| instead. |
| 391 void registerMovingObjectReference(MovableReference*); |
| 392 |
| 393 // Register a callback to be invoked upon moving the object starting at |
| 394 // |reference|; see |MovingObjectCallback| documentation for details. |
| 395 // |
| 396 // This callback mechanism is needed to account for backing store objects |
| 397 // containing intra-object pointers, all of which must be relocated/rebased |
| 398 // to be done wrt the moved-to location. |
| 399 // |
| 400 // For Blink, |LinkedHashSet<>| is currently the only abstraction which |
| 401 // relies on this feature. |
| 402 void registerMovingObjectCallback(MovableReference, |
| 403 MovingObjectCallback, |
| 404 void* callbackData); |
| 405 |
| 406 // Register an external relocation; when |*slot| is compacted and moved, |
| 407 // |slot| must be updated to point to |*slot|'s new location; |
| 408 // see HeapCompact::registerRelocation. |
| 409 void registerRelocation(MovableReference* slot); |
| 410 |
| 384 BlinkGC::GCReason lastGCReason() { return m_lastGCReason; } | 411 BlinkGC::GCReason lastGCReason() { return m_lastGCReason; } |
| 385 RegionTree* getRegionTree() { return m_regionTree.get(); } | 412 RegionTree* getRegionTree() { return m_regionTree.get(); } |
| 386 | 413 |
| 387 static inline size_t allocationSizeFromSize(size_t size) { | 414 static inline size_t allocationSizeFromSize(size_t size) { |
| 388 // Add space for header. | 415 // Add space for header. |
| 389 size_t allocationSize = size + sizeof(HeapObjectHeader); | 416 size_t allocationSize = size + sizeof(HeapObjectHeader); |
| 390 // The allocation size calculation can overflow for large sizes. | 417 // The allocation size calculation can overflow for large sizes. |
| 391 RELEASE_ASSERT(allocationSize > size); | 418 RELEASE_ASSERT(allocationSize > size); |
| 392 // Align size with allocation granularity. | 419 // Align size with allocation granularity. |
| 393 allocationSize = (allocationSize + allocationMask) & ~allocationMask; | 420 allocationSize = (allocationSize + allocationMask) & ~allocationMask; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 ASSERT(gcInfoIndex < GCInfoTable::maxIndex); | 458 ASSERT(gcInfoIndex < GCInfoTable::maxIndex); |
| 432 ASSERT(s_gcInfoTable); | 459 ASSERT(s_gcInfoTable); |
| 433 const GCInfo* info = s_gcInfoTable[gcInfoIndex]; | 460 const GCInfo* info = s_gcInfoTable[gcInfoIndex]; |
| 434 ASSERT(info); | 461 ASSERT(info); |
| 435 return info; | 462 return info; |
| 436 } | 463 } |
| 437 | 464 |
| 438 static void reportMemoryUsageHistogram(); | 465 static void reportMemoryUsageHistogram(); |
| 439 static void reportMemoryUsageForTracing(); | 466 static void reportMemoryUsageForTracing(); |
| 440 | 467 |
| 468 HeapCompact* compaction(); |
| 469 |
| 441 private: | 470 private: |
| 442 // Reset counters that track live and allocated-since-last-GC sizes. | 471 // Reset counters that track live and allocated-since-last-GC sizes. |
| 443 void resetHeapCounters(); | 472 void resetHeapCounters(); |
| 444 | 473 |
| 445 static int arenaIndexForObjectSize(size_t); | 474 static int arenaIndexForObjectSize(size_t); |
| 446 static bool isNormalArenaIndex(int); | 475 static bool isNormalArenaIndex(int); |
| 447 | 476 |
| 448 void commitCallbackStacks(); | 477 void commitCallbackStacks(); |
| 449 void decommitCallbackStacks(); | 478 void decommitCallbackStacks(); |
| 450 | 479 |
| 451 RecursiveMutex m_threadAttachMutex; | 480 RecursiveMutex m_threadAttachMutex; |
| 452 ThreadStateSet m_threads; | 481 ThreadStateSet m_threads; |
| 453 ThreadHeapStats m_stats; | 482 ThreadHeapStats m_stats; |
| 454 std::unique_ptr<RegionTree> m_regionTree; | 483 std::unique_ptr<RegionTree> m_regionTree; |
| 455 std::unique_ptr<HeapDoesNotContainCache> m_heapDoesNotContainCache; | 484 std::unique_ptr<HeapDoesNotContainCache> m_heapDoesNotContainCache; |
| 456 std::unique_ptr<SafePointBarrier> m_safePointBarrier; | 485 std::unique_ptr<SafePointBarrier> m_safePointBarrier; |
| 457 std::unique_ptr<FreePagePool> m_freePagePool; | 486 std::unique_ptr<FreePagePool> m_freePagePool; |
| 458 std::unique_ptr<OrphanedPagePool> m_orphanedPagePool; | 487 std::unique_ptr<OrphanedPagePool> m_orphanedPagePool; |
| 459 std::unique_ptr<CallbackStack> m_markingStack; | 488 std::unique_ptr<CallbackStack> m_markingStack; |
| 460 std::unique_ptr<CallbackStack> m_postMarkingCallbackStack; | 489 std::unique_ptr<CallbackStack> m_postMarkingCallbackStack; |
| 461 std::unique_ptr<CallbackStack> m_globalWeakCallbackStack; | 490 std::unique_ptr<CallbackStack> m_globalWeakCallbackStack; |
| 462 std::unique_ptr<CallbackStack> m_ephemeronStack; | 491 std::unique_ptr<CallbackStack> m_ephemeronStack; |
| 463 BlinkGC::GCReason m_lastGCReason; | 492 BlinkGC::GCReason m_lastGCReason; |
| 464 StackFrameDepth m_stackFrameDepth; | 493 StackFrameDepth m_stackFrameDepth; |
| 465 | 494 |
| 495 std::unique_ptr<HeapCompact> m_compaction; |
| 496 |
| 466 static ThreadHeap* s_mainThreadHeap; | 497 static ThreadHeap* s_mainThreadHeap; |
| 467 | 498 |
| 468 friend class ThreadState; | 499 friend class ThreadState; |
| 469 }; | 500 }; |
| 470 | 501 |
| 471 template <typename T> | 502 template <typename T> |
| 472 struct IsEagerlyFinalizedType { | 503 struct IsEagerlyFinalizedType { |
| 473 STATIC_ONLY(IsEagerlyFinalizedType); | 504 STATIC_ONLY(IsEagerlyFinalizedType); |
| 474 | 505 |
| 475 private: | 506 private: |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 template <typename T> | 701 template <typename T> |
| 671 void VisitorHelper<Derived>::handleWeakCell(Visitor* self, void* object) { | 702 void VisitorHelper<Derived>::handleWeakCell(Visitor* self, void* object) { |
| 672 T** cell = reinterpret_cast<T**>(object); | 703 T** cell = reinterpret_cast<T**>(object); |
| 673 if (*cell && !ObjectAliveTrait<T>::isHeapObjectAlive(*cell)) | 704 if (*cell && !ObjectAliveTrait<T>::isHeapObjectAlive(*cell)) |
| 674 *cell = nullptr; | 705 *cell = nullptr; |
| 675 } | 706 } |
| 676 | 707 |
| 677 } // namespace blink | 708 } // namespace blink |
| 678 | 709 |
| 679 #endif // Heap_h | 710 #endif // Heap_h |
| OLD | NEW |