2 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
3 * Copyright (C) 2001 Peter Kelly (pmk@post.com)
4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 #include "MachineStackMarker.h"
26 #include "MarkedBlock.h"
27 #include "PageAllocationAligned.h"
28 #include <wtf/Bitmap.h>
29 #include <wtf/FixedArray.h>
30 #include <wtf/HashCountedSet.h>
31 #include <wtf/Noncopyable.h>
32 #include <wtf/Vector.h>
39 class LiveObjectIterator;
43 struct CollectorHeap {
46 PageAllocationAligned* blocks;
54 MarkedBlock* collectorBlock(size_t index) const
56 return static_cast<MarkedBlock*>(blocks[index].base());
61 WTF_MAKE_NONCOPYABLE(MarkedSpace);
63 static Heap* heap(JSCell*);
65 static bool isMarked(const JSCell*);
66 static bool testAndSetMarked(const JSCell*);
67 static void setMarked(const JSCell*);
69 MarkedSpace(JSGlobalData*);
72 JSGlobalData* globalData() { return m_globalData; }
74 size_t highWaterMark() { return m_heap.highWaterMark; }
75 void setHighWaterMark(size_t highWaterMark) { m_heap.highWaterMark = highWaterMark; }
77 void* allocate(size_t);
83 size_t markedCells(size_t startBlock = 0, size_t startCell = 0) const;
86 size_t capacity() const;
87 size_t objectCount() const;
89 bool contains(const void*);
91 LiveObjectIterator primaryHeapBegin();
92 LiveObjectIterator primaryHeapEnd();
95 bool containsSlowCase(const void*);
97 NEVER_INLINE MarkedBlock* allocateBlock();
98 NEVER_INLINE void freeBlock(size_t);
100 void growBlocks(size_t neededBlocks);
101 void shrinkBlocks(size_t neededBlocks);
103 void clearMarkBits(MarkedBlock*);
105 CollectorHeap m_heap;
106 JSGlobalData* m_globalData;
109 inline Heap* MarkedSpace::heap(JSCell* cell)
111 return MarkedBlock::blockFor(cell)->heap;
114 inline bool MarkedSpace::isMarked(const JSCell* cell)
116 return MarkedBlock::blockFor(cell)->isMarked(cell);
119 inline bool MarkedSpace::testAndSetMarked(const JSCell* cell)
121 return MarkedBlock::blockFor(cell)->testAndSetMarked(cell);
124 inline void MarkedSpace::setMarked(const JSCell* cell)
126 MarkedBlock::blockFor(cell)->setMarked(cell);
129 inline bool MarkedSpace::contains(const void* x)
131 if (!MarkedBlock::isPossibleCell(x))
134 return containsSlowCase(x);
139 #endif // MarkedSpace_h