Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "config.h" | |
| 6 #include "platform/heap/PersistentNode.h" | |
| 7 | |
| 8 namespace blink { | |
| 9 | |
| 10 PersistentRegion::~PersistentRegion() | |
| 11 { | |
| 12 PersistentNodeSlots* slots = m_slots; | |
| 13 while (slots) { | |
| 14 PersistentNodeSlots* deadSlots = slots; | |
| 15 slots = slots->m_next; | |
| 16 delete deadSlots; | |
| 17 } | |
| 18 } | |
| 19 | |
| 20 int PersistentRegion::numberOfPersistents() | |
| 21 { | |
| 22 int persistentCount = 0; | |
| 23 for (PersistentNodeSlots* slots = m_slots; slots; slots = slots->m_next) { | |
| 24 for (int i = 0; i < PersistentNodeSlots::slotCount; ++i) { | |
| 25 if (!slots->m_slot[i].isFree()) | |
| 26 ++persistentCount; | |
| 27 } | |
| 28 } | |
| 29 ASSERT(persistentCount == m_persistentCount); | |
|
sof
2015/06/30 09:19:39
Bots are complaining about this -- s/m_persistentC
haraken
2015/06/30 09:51:32
Done.
| |
| 30 return persistentCount; | |
| 31 } | |
| 32 | |
| 33 void PersistentRegion::ensurePersistentNodeSlots(void* self, TraceCallback trace ) | |
| 34 { | |
| 35 ASSERT(!m_freeHead); | |
| 36 PersistentNodeSlots* slots = new PersistentNodeSlots; | |
| 37 for (int i = 0; i < PersistentNodeSlots::slotCount; ++i) { | |
| 38 PersistentNode* node = &slots->m_slot[i]; | |
| 39 node->setFreeNext(m_freeHead); | |
| 40 m_freeHead = node; | |
| 41 ASSERT(node->isFree()); | |
| 42 } | |
| 43 slots->m_next = m_slots; | |
| 44 m_slots = slots; | |
| 45 } | |
| 46 | |
| 47 // This function traces all PersistentNodes. If we encounter | |
| 48 // a PersistentNodeSlot that contains only freed PersistentNodes, | |
| 49 // we delete the PersistentNodeSlot. This function rebuilds the free | |
| 50 // list of PersistentNodes. | |
| 51 void PersistentRegion::tracePersistentNodes(Visitor* visitor) | |
| 52 { | |
| 53 m_freeHead = nullptr; | |
| 54 int persistentCount = 0; | |
| 55 PersistentNodeSlots** prevNext = &m_slots; | |
| 56 PersistentNodeSlots* slots = m_slots; | |
| 57 while (slots) { | |
| 58 PersistentNode* freeNext = nullptr; | |
| 59 PersistentNode* freeLast = nullptr; | |
| 60 int freeCount = 0; | |
| 61 for (int i = 0; i < PersistentNodeSlots::slotCount; ++i) { | |
| 62 PersistentNode* node = &slots->m_slot[i]; | |
| 63 if (node->isFree()) { | |
| 64 if (!freeNext) | |
| 65 freeLast = node; | |
| 66 node->setFreeNext(freeNext); | |
| 67 freeNext = node; | |
| 68 ++freeCount; | |
| 69 } else { | |
| 70 node->tracePersistentNode(visitor); | |
| 71 ++persistentCount; | |
| 72 } | |
| 73 } | |
| 74 if (freeCount == PersistentNodeSlots::slotCount) { | |
| 75 PersistentNodeSlots* deadSlots = slots; | |
| 76 *prevNext = slots->m_next; | |
| 77 slots = slots->m_next; | |
| 78 delete deadSlots; | |
| 79 } else { | |
| 80 if (freeLast) { | |
| 81 ASSERT(freeNext); | |
| 82 ASSERT(!freeLast->freeNext()); | |
| 83 freeLast->setFreeNext(m_freeHead); | |
| 84 m_freeHead = freeNext; | |
| 85 } | |
| 86 prevNext = &slots->m_next; | |
| 87 slots = slots->m_next; | |
| 88 } | |
| 89 } | |
| 90 ASSERT(persistentCount == m_persistentCount); | |
| 91 } | |
| 92 | |
| 93 } // namespace blink | |
| OLD | NEW |