Implemented const for references and arrays.
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/.
20 #include "StringPool.h"
21 #include "TypeManager.h"
22 #include "GlobalRoots.h"
23 #include "AllocatorPolicies.h"
28 Zone *ke::SingleThreadedZone;
49 if (!stack_.initialize())
51 if (!heap_.initialize())
54 symbols_ = new StringPool(this);
55 if (!symbols_ || !symbols_->initialize())
58 globalRoots_ = new GlobalRoots(this);
59 if (!globalRoots_ || !globalRoots_->initialize())
62 maps_[MapKind_Meta] = heap_.metaMap();
63 if ((maps_[MapKind_Type] = allocateMap(MapKind_Type, sizeof(Map))) == NULL)
65 if ((maps_[MapKind_FixedArray] = allocateMap(MapKind_FixedArray, sizeof(Map))) == NULL)
67 if ((maps_[MapKind_ByteArray] = allocateMap(MapKind_ByteArray, sizeof(Map))) == NULL)
69 if ((maps_[MapKind_Code] = allocateMap(MapKind_Code, sizeof(Map))) == NULL)
71 if ((maps_[MapKind_Reference] = allocateMap(MapKind_Reference, sizeof(Map))) == NULL)
73 if ((maps_[MapKind_MetaArray] = allocateMap(MapKind_MetaArray, sizeof(Map))) == NULL)
75 if ((maps_[MapKind_Module] = allocateMap(MapKind_Module, sizeof(Map))) == NULL)
77 if ((maps_[MapKind_Function] = allocateMap(MapKind_Function, sizeof(Map))) == NULL)
79 if ((maps_[MapKind_String] = allocateMap(MapKind_String, sizeof(Map))) == NULL)
81 if ((maps_[MapKind_FreeRegion] = allocateMap(MapKind_FreeRegion, sizeof(Map))) == NULL)
84 types_ = new TypeManager(this);
85 if (!types_ || !types_->initialize())
88 // Create the cached array maps for generic arrays. This is for the API
89 // version of Invoke(), which needs to make arrays very quickly from C++.
91 // Generic "cell" array (contents do not matter, just non-gc things).
92 Local<Type> type(this, types_->getPrimitive(PrimitiveType_Int32));
96 type = types_->unsafeArray(type, Type::UNKNOWN_SIZE, false);
100 Local<ArrayMap> contained(this);
101 genericArrayMap_ = ArrayMap::New(this, type, contained);
102 if (!genericArrayMap_)
105 type = types_->getPrimitive(PrimitiveType_Char);
109 type = types_->unsafeArray(type, Type::UNKNOWN_SIZE, false);
113 charArrayMap_ = ArrayMap::New(this, type, contained);
122 Zone::allocateMap(MapKind kind, size_t bytes, MapKind parent)
124 assert(maps_[parent]);
125 Map *map = heap_.allocateMap(kind, bytes);
128 map->init(maps_[parent]);
133 Zone::accept(VirtualObjectVisitor *visitor)
135 for (unsigned i = 0; i < MapKinds_Total; i++)
136 visitor->visit(maps_[i].address());
137 visitor->visit(charArrayMap_.address());
138 visitor->visit(genericArrayMap_.address());
139 types()->accept(visitor);
141 Local<Object> *local = lastLocalRoot_;
143 visitor->visit(local->address());
144 local = local->prev();
147 globalRoots_->accept(visitor);
148 rootScopes_.accept(visitor);
150 stack_.accept(visitor);
154 Zone::makeSymbol(const char *str, size_t length)
156 return symbols_->add(str, length);
160 Zone::makeSymbol(const char *str)
162 return makeSymbol(str, strlen(str));
166 ZoneAllocatorPolicy::reportOutOfMemory()
173 ZoneAllocatorPolicy::reportAllocationOverflow()