Added a large object space.
1 /* vim: set ts=4 sw=4 tw=99 et:
3 * Copyright (C) 2012 David Anderson
5 * This file is part of JITCraft.
7 * JITCraft is free software: you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License as published by the Free
9 * Software Foundation, either version 3 of the License, or (at your option)
12 * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY
13 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with
17 * JITCraft. If not, see http://www.gnu.org/licenses/.
21 #include "Spaces-inl.h"
25 HeapStack::HeapStack()
32 HeapStack::~HeapStack()
35 OS::UnmapAlignedMemory(map_.base(), map_.size());
39 HeapStack::initialize()
41 map_ = OS::MapAlignedMemory(kStackSize, kStackSize, OS::Map_Commit);
45 buffer_ = map_.aligned();
47 end_ = buffer_ + kStackSize;
48 mask_ = kStackSize - 1;
53 HeapChunk::New(HeapChunk *prev, size_t size)
55 OS::AlignableMapping map =
56 OS::MapAlignedMemory(size, HeapChunk::kAlignment, OS::Map_Commit);
61 HeapChunk *chunk = reinterpret_cast<HeapChunk *>(map.aligned());
62 chunk->base_ = map.base();
63 chunk->end_ = map.base() + map.size();
64 chunk->cursor_ = chunk->first();
72 HeapChunk::Destroy(HeapChunk *chunk)
74 OS::UnmapAlignedMemory(chunk->base(), chunk->size());
84 OldSpace::initialize()
86 first_ = HeapChunk::New(first_, HeapChunk::kDefaultSize);
93 OldSpace::allocateSlow(size_t nbytes)
95 HeapChunk *chunk = HeapChunk::New(last_, HeapChunk::kDefaultSize);
99 return chunk->allocate(nbytes);
102 OldSpace::~OldSpace()
105 HeapChunk *temp = first_->next();
106 HeapChunk::Destroy(first_);
111 LargeObjectSpace::LargeObjectSpace()
117 LargeObjectSpace::~LargeObjectSpace()
120 HeapChunk *temp = first_->next();
121 HeapChunk::Destroy(first_);
127 LargeObjectSpace::initialize()
133 LargeObjectSpace::allocate(size_t nbytes)
135 assert(IsAligned(nbytes, kObjectAlignment));
137 // Always allocate a new chunk for large objects.
138 HeapChunk *chunk = HeapChunk::New(last_, nbytes);
146 Address address = chunk->allocate(nbytes);