]>
git.saurik.com Git - apple/javascriptcore.git/blob - heap/MarkedSpace.cpp
405ed571a08bfa4e52d43e63fdb4911226e9eb82
2 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2007 Eric Seidel <eric@webkit.org>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "MarkedSpace.h"
24 #include "JSGlobalObject.h"
27 #include "ScopeChain.h"
33 MarkedSpace::MarkedSpace(Heap
* heap
)
36 for (size_t cellSize
= preciseStep
; cellSize
<= preciseCutoff
; cellSize
+= preciseStep
) {
37 allocatorFor(cellSize
).init(heap
, this, cellSize
, false);
38 destructorAllocatorFor(cellSize
).init(heap
, this, cellSize
, true);
41 for (size_t cellSize
= impreciseStep
; cellSize
<= impreciseCutoff
; cellSize
+= impreciseStep
) {
42 allocatorFor(cellSize
).init(heap
, this, cellSize
, false);
43 destructorAllocatorFor(cellSize
).init(heap
, this, cellSize
, true);
47 void MarkedSpace::resetAllocators()
49 for (size_t cellSize
= preciseStep
; cellSize
<= preciseCutoff
; cellSize
+= preciseStep
) {
50 allocatorFor(cellSize
).reset();
51 destructorAllocatorFor(cellSize
).reset();
54 for (size_t cellSize
= impreciseStep
; cellSize
<= impreciseCutoff
; cellSize
+= impreciseStep
) {
55 allocatorFor(cellSize
).reset();
56 destructorAllocatorFor(cellSize
).reset();
60 void MarkedSpace::canonicalizeCellLivenessData()
62 for (size_t cellSize
= preciseStep
; cellSize
<= preciseCutoff
; cellSize
+= preciseStep
) {
63 allocatorFor(cellSize
).zapFreeList();
64 destructorAllocatorFor(cellSize
).zapFreeList();
67 for (size_t cellSize
= impreciseStep
; cellSize
<= impreciseCutoff
; cellSize
+= impreciseStep
) {
68 allocatorFor(cellSize
).zapFreeList();
69 destructorAllocatorFor(cellSize
).zapFreeList();
73 bool MarkedSpace::isPagedOut(double deadline
)
75 for (size_t cellSize
= preciseStep
; cellSize
<= preciseCutoff
; cellSize
+= preciseStep
) {
76 if (allocatorFor(cellSize
).isPagedOut(deadline
) || destructorAllocatorFor(cellSize
).isPagedOut(deadline
))
80 for (size_t cellSize
= impreciseStep
; cellSize
<= impreciseCutoff
; cellSize
+= impreciseStep
) {
81 if (allocatorFor(cellSize
).isPagedOut(deadline
) || destructorAllocatorFor(cellSize
).isPagedOut(deadline
))
88 void MarkedSpace::freeBlocks(MarkedBlock
* head
)
91 for (MarkedBlock
* block
= head
; block
; block
= next
) {
92 next
= static_cast<MarkedBlock
*>(block
->next());
94 m_blocks
.remove(block
);
97 m_heap
->blockAllocator().deallocate(block
);
101 class TakeIfUnmarked
{
103 typedef MarkedBlock
* ReturnType
;
105 TakeIfUnmarked(MarkedSpace
*);
106 void operator()(MarkedBlock
*);
107 ReturnType
returnValue();
110 MarkedSpace
* m_markedSpace
;
111 DoublyLinkedList
<MarkedBlock
> m_empties
;
114 inline TakeIfUnmarked::TakeIfUnmarked(MarkedSpace
* newSpace
)
115 : m_markedSpace(newSpace
)
119 inline void TakeIfUnmarked::operator()(MarkedBlock
* block
)
121 if (!block
->markCountIsZero())
124 m_markedSpace
->allocatorFor(block
).removeBlock(block
);
125 m_empties
.append(block
);
128 inline TakeIfUnmarked::ReturnType
TakeIfUnmarked::returnValue()
130 return m_empties
.head();
133 void MarkedSpace::shrink()
135 // We record a temporary list of empties to avoid modifying m_blocks while iterating it.
136 TakeIfUnmarked
takeIfUnmarked(this);
137 freeBlocks(forEachBlock(takeIfUnmarked
));
141 class GatherDirtyCells
{
142 WTF_MAKE_NONCOPYABLE(GatherDirtyCells
);
144 typedef void* ReturnType
;
146 explicit GatherDirtyCells(MarkedBlock::DirtyCellVector
*);
147 void operator()(MarkedBlock
*);
148 ReturnType
returnValue() { return 0; }
151 MarkedBlock::DirtyCellVector
* m_dirtyCells
;
154 inline GatherDirtyCells::GatherDirtyCells(MarkedBlock::DirtyCellVector
* dirtyCells
)
155 : m_dirtyCells(dirtyCells
)
159 inline void GatherDirtyCells::operator()(MarkedBlock
* block
)
161 block
->gatherDirtyCells(*m_dirtyCells
);
164 void MarkedSpace::gatherDirtyCells(MarkedBlock::DirtyCellVector
& dirtyCells
)
166 GatherDirtyCells
gatherDirtyCells(&dirtyCells
);
167 forEachBlock(gatherDirtyCells
);