Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(203)

Side by Side Diff: Source/platform/heap/PersistentNode.cpp

Issue 1213133002: Oilpan: Reduce sizeof(Persistent) to 16 byte (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/platform/heap/PersistentNode.h ('k') | Source/platform/heap/ThreadState.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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].isUnused())
26 ++persistentCount;
27 }
28 }
29 ASSERT(persistentCount == m_persistentCount);
30 return persistentCount;
31 }
32
33 void PersistentRegion::ensurePersistentNodeSlots(void* self, TraceCallback trace )
34 {
35 ASSERT(!m_freeListHead);
36 PersistentNodeSlots* slots = new PersistentNodeSlots;
37 for (int i = 0; i < PersistentNodeSlots::slotCount; ++i) {
38 PersistentNode* node = &slots->m_slot[i];
39 node->setFreeListNext(m_freeListHead);
40 m_freeListHead = node;
41 ASSERT(node->isUnused());
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_freeListHead = nullptr;
54 int persistentCount = 0;
55 PersistentNodeSlots** prevNext = &m_slots;
56 PersistentNodeSlots* slots = m_slots;
57 while (slots) {
58 PersistentNode* freeListNext = nullptr;
59 PersistentNode* freeListLast = nullptr;
60 int freeCount = 0;
61 for (int i = 0; i < PersistentNodeSlots::slotCount; ++i) {
62 PersistentNode* node = &slots->m_slot[i];
63 if (node->isUnused()) {
64 if (!freeListNext)
65 freeListLast = node;
66 node->setFreeListNext(freeListNext);
67 freeListNext = 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 (freeListLast) {
81 ASSERT(freeListNext);
82 ASSERT(!freeListLast->freeListNext());
83 freeListLast->setFreeListNext(m_freeListHead);
84 m_freeListHead = freeListNext;
85 }
86 prevNext = &slots->m_next;
87 slots = slots->m_next;
88 }
89 }
90 ASSERT(persistentCount == m_persistentCount);
91 }
92
93 } // namespace blink
OLDNEW
« no previous file with comments | « Source/platform/heap/PersistentNode.h ('k') | Source/platform/heap/ThreadState.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698