Trigger a build.
1 /* vim: set ts=4 sw=4 tw=99 et:
3 * Copyright (C) 2012 David Anderson
5 * This file is part of SourcePawn.
7 * SourcePawn 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 * SourcePawn 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 * SourcePawn. If not, see http://www.gnu.org/licenses/.
19 #ifndef _include_jitcraft_thread_h_
20 #define _include_jitcraft_thread_h_
23 #include "PoolAllocator.h"
29 #include "RootScopes.h"
30 #include "VirtualObjectVisitor.h"
49 Unbarriered<Map> maps_[MapKinds_Total];
50 Unbarriered<ArrayMap> externalGenericArrayMap_;
51 Unbarriered<ArrayMap> externalCharArrayMap_;
55 GlobalRoots *globalRoots_;
56 NativeTable *nativeTable_;
59 Local<Object> *lastLocalRoot_;
60 RootScopeManager rootScopes_;
61 AutoRooted *specialRoots_;
64 bool hasPendingException_;
65 Ke::IMessageReporter *reporter_;
67 Ke::IPublicFunctionListener *publicFunctionListener_;
70 Zone *thisFromCtor() {
79 PoolAllocator &pool() {
88 Object *allocate(MapKind kind, size_t bytes, Heap::Tenure tenure = Heap::Tenure_Default) {
90 Local<Map> map(this, maps_[kind]);
91 return allocate(map, bytes, tenure);
93 Object *allocate(Handle<Map> map, size_t bytes, Heap::Tenure tenure = Heap::Tenure_Default) {
94 return heap_.allocate(map, bytes, tenure);
96 Map *getMap(MapKind kind) {
99 Map *allocateMap(MapKind kind, size_t bytes, MapKind parent = MapKind_Meta);
101 ArrayMap *externalGenericArrayMap() {
102 return externalGenericArrayMap_;
104 ArrayMap *externalCharArrayMap() {
105 return externalCharArrayMap_;
108 TypeManager *types() const {
111 AutoRooted **lastSpecialRoot() {
112 return &specialRoots_;
114 Local<Object> **lastLocalRoot() {
115 return &lastLocalRoot_;
117 Object **makeScopedRoot(Object *ptr) {
118 return rootScopes_.make(ptr);
120 RootScopeManager &rootScopes() {
123 StringPool *symbols() {
126 GlobalRoots *globalRoots() {
129 NativeTable *nativeTable() {
133 String *makeSymbol(const char *string, size_t length);
134 String *makeSymbol(const char *string);
136 void reportOutOfMemory();
137 void reportAllocationOverflow();
138 void reportError(Message message, ...);
139 void reportErrorVA(Message message, va_list ap);
140 bool hasPendingException();
141 void clearPendingException();
142 void installErrorReporter(Ke::IMessageReporter *reporter);
143 void beginCompilationErrors(const char *file);
144 void reportCompilationError(Message message, unsigned line, unsigned col, va_list ap);
145 void endCompilationErrors();
147 void accept(VirtualObjectVisitor *visitor);
149 void setPublicFunctionListener(Ke::IPublicFunctionListener *listener);
150 void registerPublic(Handle<Function> fun);
151 void unregisterPublic(Handle<Function> fun);
154 // In a multi-threaded system, this would be a TLS variable.
155 // In the interest of simplicity, we are single-threaded for now.
156 extern Zone *SingleThreadedZone;
158 static inline Zone *ZONE()
160 return SingleThreadedZone;
163 template <typename T>
164 Local<T>::Local(Zone *zone, T *thing)
167 prev_(*zone->lastLocalRoot())
169 *zone->lastLocalRoot() = toRaw();
172 template <typename T>
176 assert(*zone_->lastLocalRoot() == toRaw());
177 *zone_->lastLocalRoot() = prev_;
180 template <typename T>
181 ScopedRoot<T>::ScopedRoot()
182 : thingp_(make(NULL))
186 template <typename T>
187 ScopedRoot<T>::ScopedRoot(T *thing)
188 : thingp_(make(thing))
190 // Type check that T is an Object.
191 (void)static_cast<Object *>(thing);
194 template <typename T> T **
195 ScopedRoot<T>::make(T *other)
197 return reinterpret_cast<T **>(ZONE()->makeScopedRoot(other));
200 RootScope::RootScope(Zone *zone)
201 : Ke::HandleScope(zone, zone->rootScopes().position(), *zone->rootScopes().scope())
207 #endif // _include_jitcraft_thread_h_