| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/heap/HeapCompact.h" | 5 #include "platform/heap/HeapCompact.h" |
| 6 | 6 |
| 7 #include "platform/Histogram.h" | 7 #include "platform/Histogram.h" |
| 8 #include "platform/RuntimeEnabledFeatures.h" | 8 #include "platform/RuntimeEnabledFeatures.h" |
| 9 #include "platform/heap/Heap.h" | 9 #include "platform/heap/Heap.h" |
| 10 #include "platform/heap/SparseHeapBitmap.h" | 10 #include "platform/heap/SparseHeapBitmap.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 m_relocatablePages.insert(page); | 40 m_relocatablePages.insert(page); |
| 41 } | 41 } |
| 42 | 42 |
| 43 void addInteriorFixup(MovableReference* slot) { | 43 void addInteriorFixup(MovableReference* slot) { |
| 44 auto it = m_interiorFixups.find(slot); | 44 auto it = m_interiorFixups.find(slot); |
| 45 // Ephemeron fixpoint iterations may cause repeated registrations. | 45 // Ephemeron fixpoint iterations may cause repeated registrations. |
| 46 if (UNLIKELY(it != m_interiorFixups.end())) { | 46 if (UNLIKELY(it != m_interiorFixups.end())) { |
| 47 DCHECK(!it->value); | 47 DCHECK(!it->value); |
| 48 return; | 48 return; |
| 49 } | 49 } |
| 50 m_interiorFixups.add(slot, nullptr); | 50 m_interiorFixups.insert(slot, nullptr); |
| 51 LOG_HEAP_COMPACTION("Interior slot: %p\n", slot); | 51 LOG_HEAP_COMPACTION("Interior slot: %p\n", slot); |
| 52 Address slotAddress = reinterpret_cast<Address>(slot); | 52 Address slotAddress = reinterpret_cast<Address>(slot); |
| 53 if (!m_interiors) { | 53 if (!m_interiors) { |
| 54 m_interiors = SparseHeapBitmap::create(slotAddress); | 54 m_interiors = SparseHeapBitmap::create(slotAddress); |
| 55 return; | 55 return; |
| 56 } | 56 } |
| 57 m_interiors->add(slotAddress); | 57 m_interiors->add(slotAddress); |
| 58 } | 58 } |
| 59 | 59 |
| 60 void add(MovableReference* slot) { | 60 void add(MovableReference* slot) { |
| 61 MovableReference reference = *slot; | 61 MovableReference reference = *slot; |
| 62 BasePage* refPage = pageFromObject(reference); | 62 BasePage* refPage = pageFromObject(reference); |
| 63 // Nothing to compact on a large object's page. | 63 // Nothing to compact on a large object's page. |
| 64 if (refPage->isLargeObjectPage()) | 64 if (refPage->isLargeObjectPage()) |
| 65 return; | 65 return; |
| 66 | 66 |
| 67 #if DCHECK_IS_ON() | 67 #if DCHECK_IS_ON() |
| 68 DCHECK(HeapCompact::isCompactableArena(refPage->arena()->arenaIndex())); | 68 DCHECK(HeapCompact::isCompactableArena(refPage->arena()->arenaIndex())); |
| 69 auto it = m_fixups.find(reference); | 69 auto it = m_fixups.find(reference); |
| 70 DCHECK(it == m_fixups.end() || it->value == slot); | 70 DCHECK(it == m_fixups.end() || it->value == slot); |
| 71 #endif | 71 #endif |
| 72 | 72 |
| 73 // TODO: when updateHeapResidency() becomes more discriminating about | 73 // TODO: when updateHeapResidency() becomes more discriminating about |
| 74 // leaving out arenas that aren't worth compacting, a check for | 74 // leaving out arenas that aren't worth compacting, a check for |
| 75 // isCompactingArena() would be appropriate here, leaving early if | 75 // isCompactingArena() would be appropriate here, leaving early if |
| 76 // |refPage|'s arena isn't in the set. | 76 // |refPage|'s arena isn't in the set. |
| 77 | 77 |
| 78 m_fixups.add(reference, slot); | 78 m_fixups.insert(reference, slot); |
| 79 | 79 |
| 80 // Note: |slot| will reside outside the Oilpan heap if it is a | 80 // Note: |slot| will reside outside the Oilpan heap if it is a |
| 81 // PersistentHeapCollectionBase. Hence pageFromObject() cannot be | 81 // PersistentHeapCollectionBase. Hence pageFromObject() cannot be |
| 82 // used, as it sanity checks the |BasePage| it returns. Simply | 82 // used, as it sanity checks the |BasePage| it returns. Simply |
| 83 // derive the raw BasePage address here and check if it is a member | 83 // derive the raw BasePage address here and check if it is a member |
| 84 // of the compactable and relocatable page address set. | 84 // of the compactable and relocatable page address set. |
| 85 Address slotAddress = reinterpret_cast<Address>(slot); | 85 Address slotAddress = reinterpret_cast<Address>(slot); |
| 86 void* slotPageAddress = blinkPageAddress(slotAddress) + blinkGuardPageSize; | 86 void* slotPageAddress = blinkPageAddress(slotAddress) + blinkGuardPageSize; |
| 87 if (LIKELY(!m_relocatablePages.contains(slotPageAddress))) | 87 if (LIKELY(!m_relocatablePages.contains(slotPageAddress))) |
| 88 return; | 88 return; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 100 // "interior" bitmap. This bitmap is used when moving a backing | 100 // "interior" bitmap. This bitmap is used when moving a backing |
| 101 // store, quickly/ier checking if interior slots will have to | 101 // store, quickly/ier checking if interior slots will have to |
| 102 // be additionally redirected. | 102 // be additionally redirected. |
| 103 addInteriorFixup(slot); | 103 addInteriorFixup(slot); |
| 104 } | 104 } |
| 105 | 105 |
| 106 void addFixupCallback(MovableReference reference, | 106 void addFixupCallback(MovableReference reference, |
| 107 MovingObjectCallback callback, | 107 MovingObjectCallback callback, |
| 108 void* callbackData) { | 108 void* callbackData) { |
| 109 DCHECK(!m_fixupCallbacks.contains(reference)); | 109 DCHECK(!m_fixupCallbacks.contains(reference)); |
| 110 m_fixupCallbacks.add(reference, std::pair<void*, MovingObjectCallback>( | 110 m_fixupCallbacks.insert(reference, std::pair<void*, MovingObjectCallback>( |
| 111 callbackData, callback)); | 111 callbackData, callback)); |
| 112 } | 112 } |
| 113 | 113 |
| 114 void relocateInteriorFixups(Address from, Address to, size_t size) { | 114 void relocateInteriorFixups(Address from, Address to, size_t size) { |
| 115 SparseHeapBitmap* range = m_interiors->hasRange(from, size); | 115 SparseHeapBitmap* range = m_interiors->hasRange(from, size); |
| 116 if (LIKELY(!range)) | 116 if (LIKELY(!range)) |
| 117 return; | 117 return; |
| 118 | 118 |
| 119 // Scan through the payload, looking for interior pointer slots | 119 // Scan through the payload, looking for interior pointer slots |
| 120 // to adjust. If the backing store of such an interior slot hasn't | 120 // to adjust. If the backing store of such an interior slot hasn't |
| 121 // been moved already, update the slot -> real location mapping. | 121 // been moved already, update the slot -> real location mapping. |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 fixups().addCompactingPage(page); | 460 fixups().addCompactingPage(page); |
| 461 } | 461 } |
| 462 | 462 |
| 463 bool HeapCompact::scheduleCompactionGCForTesting(bool value) { | 463 bool HeapCompact::scheduleCompactionGCForTesting(bool value) { |
| 464 bool current = s_forceCompactionGC; | 464 bool current = s_forceCompactionGC; |
| 465 s_forceCompactionGC = value; | 465 s_forceCompactionGC = value; |
| 466 return current; | 466 return current; |
| 467 } | 467 } |
| 468 | 468 |
| 469 } // namespace blink | 469 } // namespace blink |
| OLD | NEW |