Chromium Code Reviews| Index: Source/platform/heap/PersistentNode.cpp |
| diff --git a/Source/platform/heap/PersistentNode.cpp b/Source/platform/heap/PersistentNode.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..417ea3b4d49bd0de5091dbd79bd99bb84e258b7a |
| --- /dev/null |
| +++ b/Source/platform/heap/PersistentNode.cpp |
| @@ -0,0 +1,93 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "config.h" |
| +#include "platform/heap/PersistentNode.h" |
| + |
| +namespace blink { |
| + |
| +PersistentRegion::~PersistentRegion() |
| +{ |
| + PersistentNodeSlots* slots = m_slots; |
| + while (slots) { |
| + PersistentNodeSlots* deadSlots = slots; |
| + slots = slots->m_next; |
| + delete deadSlots; |
| + } |
| +} |
| + |
| +int PersistentRegion::numberOfPersistents() |
| +{ |
| + int persistentCount = 0; |
| + for (PersistentNodeSlots* slots = m_slots; slots; slots = slots->m_next) { |
| + for (int i = 0; i < PersistentNodeSlots::slotCount; ++i) { |
| + if (!slots->m_slot[i].isFree()) |
| + ++persistentCount; |
| + } |
| + } |
| + 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.
|
| + return persistentCount; |
| +} |
| + |
| +void PersistentRegion::ensurePersistentNodeSlots(void* self, TraceCallback trace) |
| +{ |
| + ASSERT(!m_freeHead); |
| + PersistentNodeSlots* slots = new PersistentNodeSlots; |
| + for (int i = 0; i < PersistentNodeSlots::slotCount; ++i) { |
| + PersistentNode* node = &slots->m_slot[i]; |
| + node->setFreeNext(m_freeHead); |
| + m_freeHead = node; |
| + ASSERT(node->isFree()); |
| + } |
| + slots->m_next = m_slots; |
| + m_slots = slots; |
| +} |
| + |
| +// This function traces all PersistentNodes. If we encounter |
| +// a PersistentNodeSlot that contains only freed PersistentNodes, |
| +// we delete the PersistentNodeSlot. This function rebuilds the free |
| +// list of PersistentNodes. |
| +void PersistentRegion::tracePersistentNodes(Visitor* visitor) |
| +{ |
| + m_freeHead = nullptr; |
| + int persistentCount = 0; |
| + PersistentNodeSlots** prevNext = &m_slots; |
| + PersistentNodeSlots* slots = m_slots; |
| + while (slots) { |
| + PersistentNode* freeNext = nullptr; |
| + PersistentNode* freeLast = nullptr; |
| + int freeCount = 0; |
| + for (int i = 0; i < PersistentNodeSlots::slotCount; ++i) { |
| + PersistentNode* node = &slots->m_slot[i]; |
| + if (node->isFree()) { |
| + if (!freeNext) |
| + freeLast = node; |
| + node->setFreeNext(freeNext); |
| + freeNext = node; |
| + ++freeCount; |
| + } else { |
| + node->tracePersistentNode(visitor); |
| + ++persistentCount; |
| + } |
| + } |
| + if (freeCount == PersistentNodeSlots::slotCount) { |
| + PersistentNodeSlots* deadSlots = slots; |
| + *prevNext = slots->m_next; |
| + slots = slots->m_next; |
| + delete deadSlots; |
| + } else { |
| + if (freeLast) { |
| + ASSERT(freeNext); |
| + ASSERT(!freeLast->freeNext()); |
| + freeLast->setFreeNext(m_freeHead); |
| + m_freeHead = freeNext; |
| + } |
| + prevNext = &slots->m_next; |
| + slots = slots->m_next; |
| + } |
| + } |
| + ASSERT(persistentCount == m_persistentCount); |
| +} |
| + |
| +} // namespace blink |