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
24 #include "JSGlobalObject.h"
28 #include "ScopeChain.h"
34 NewSpace::NewSpace(Heap* heap)
35 : m_propertyStorageNursery(static_cast<char*>(fastMalloc(PropertyStorageNurserySize)))
36 , m_propertyStorageAllocationPoint(m_propertyStorageNursery)
41 for (size_t cellSize = preciseStep; cellSize < preciseCutoff; cellSize += preciseStep)
42 sizeClassFor(cellSize).cellSize = cellSize;
44 for (size_t cellSize = impreciseStep; cellSize < impreciseCutoff; cellSize += impreciseStep)
45 sizeClassFor(cellSize).cellSize = cellSize;
48 void NewSpace::addBlock(SizeClass& sizeClass, MarkedBlock* block)
50 block->setInNewSpace(true);
51 sizeClass.nextBlock = block;
52 sizeClass.blockList.append(block);
53 ASSERT(!sizeClass.currentBlock);
54 ASSERT(!sizeClass.firstFreeCell);
55 sizeClass.currentBlock = block;
56 sizeClass.firstFreeCell = block->blessNewBlockForFastPath();
59 void NewSpace::removeBlock(MarkedBlock* block)
61 block->setInNewSpace(false);
62 SizeClass& sizeClass = sizeClassFor(block->cellSize());
63 if (sizeClass.nextBlock == block)
64 sizeClass.nextBlock = block->next();
65 sizeClass.blockList.remove(block);
68 void NewSpace::resetAllocator()
72 for (size_t cellSize = preciseStep; cellSize < preciseCutoff; cellSize += preciseStep)
73 sizeClassFor(cellSize).resetAllocator();
75 for (size_t cellSize = impreciseStep; cellSize < impreciseCutoff; cellSize += impreciseStep)
76 sizeClassFor(cellSize).resetAllocator();
79 void NewSpace::canonicalizeBlocks()
81 for (size_t cellSize = preciseStep; cellSize < preciseCutoff; cellSize += preciseStep)
82 sizeClassFor(cellSize).canonicalizeBlock();
84 for (size_t cellSize = impreciseStep; cellSize < impreciseCutoff; cellSize += impreciseStep)
85 sizeClassFor(cellSize).canonicalizeBlock();