Added global root API.
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"
27 Zone *ke::SingleThreadedZone;
48 if (!stack_.initialize())
50 if (!heap_.initialize())
53 symbols_ = new StringPool(this);
54 if (!symbols_ || !symbols_->initialize())
57 globalRoots_ = new GlobalRoots(this);
58 if (!globalRoots_ || !globalRoots_->initialize())
61 maps_[MapKind_Meta] = heap_.metaMap();
62 if ((maps_[MapKind_Type] = allocateMap(MapKind_Type, sizeof(Map))) == NULL)
64 if ((maps_[MapKind_FixedArray] = allocateMap(MapKind_FixedArray, sizeof(Map))) == NULL)
66 if ((maps_[MapKind_ByteArray] = allocateMap(MapKind_ByteArray, sizeof(Map))) == NULL)
68 if ((maps_[MapKind_Code] = allocateMap(MapKind_Code, sizeof(Map))) == NULL)
70 if ((maps_[MapKind_Reference] = allocateMap(MapKind_Reference, sizeof(Map))) == NULL)
72 if ((maps_[MapKind_MetaArray] = allocateMap(MapKind_MetaArray, sizeof(Map))) == NULL)
74 if ((maps_[MapKind_Module] = allocateMap(MapKind_Module, sizeof(Map))) == NULL)
76 if ((maps_[MapKind_Function] = allocateMap(MapKind_Function, sizeof(Map))) == NULL)
78 if ((maps_[MapKind_String] = allocateMap(MapKind_String, sizeof(Map))) == NULL)
80 if ((maps_[MapKind_FreeRegion] = allocateMap(MapKind_FreeRegion, sizeof(Map))) == NULL)
83 types_ = new TypeManager(this);
84 if (!types_ || !types_->initialize())
91 Zone::allocateMap(MapKind kind, size_t bytes, MapKind parent)
93 assert(maps_[parent]);
94 Map *map = heap_.allocateMap(kind, bytes);
97 map->init(maps_[parent]);
102 Zone::accept(VirtualObjectVisitor *visitor)
104 for (unsigned i = 0; i < MapKinds_Total; i++)
105 visitor->visit(maps_[i].address());
106 types()->accept(visitor);
108 Local<Object> *local = lastLocalRoot_;
110 visitor->visit(local->address());
111 local = local->prev();
114 globalRoots_->accept(visitor);
115 rootScopes_.accept(visitor);
117 stack_.accept(visitor);
121 Zone::makeSymbol(const char *str, size_t length)
123 return symbols_->add(str, length);
127 Zone::makeSymbol(const char *str)
129 return makeSymbol(str, strlen(str));
133 ZoneAllocatorPolicy::reportOutOfMemory()
140 ZoneAllocatorPolicy::reportAllocationOverflow()