]>
Commit | Line | Data |
---|---|---|
9dae56ea | 1 | /* |
ba379fdc | 2 | * Copyright (C) 2008, 2009 Apple Inc. All rights reserved. |
9dae56ea A |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without | |
5 | * modification, are permitted provided that the following conditions | |
6 | * are met: | |
7 | * | |
8 | * 1. Redistributions of source code must retain the above copyright | |
9 | * notice, this list of conditions and the following disclaimer. | |
10 | * 2. Redistributions in binary form must reproduce the above copyright | |
11 | * notice, this list of conditions and the following disclaimer in the | |
12 | * documentation and/or other materials provided with the distribution. | |
13 | * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of | |
14 | * its contributors may be used to endorse or promote products derived | |
15 | * from this software without specific prior written permission. | |
16 | * | |
17 | * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY | |
18 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
19 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
20 | * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY | |
21 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
22 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
23 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
24 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
27 | */ | |
28 | ||
29 | #ifndef JSGlobalData_h | |
30 | #define JSGlobalData_h | |
31 | ||
4e4e5a6f | 32 | #include "CachedTranscendentalFunction.h" |
9dae56ea | 33 | #include "Collector.h" |
f9bf01c6 | 34 | #include "DateInstanceCache.h" |
9dae56ea | 35 | #include "ExecutableAllocator.h" |
ba379fdc | 36 | #include "JITStubs.h" |
9dae56ea | 37 | #include "JSValue.h" |
f9bf01c6 A |
38 | #include "MarkStack.h" |
39 | #include "NumericStrings.h" | |
ba379fdc | 40 | #include "SmallStrings.h" |
4e4e5a6f | 41 | #include "Terminator.h" |
ba379fdc | 42 | #include "TimeoutChecker.h" |
f9bf01c6 | 43 | #include "WeakRandom.h" |
ba379fdc A |
44 | #include <wtf/Forward.h> |
45 | #include <wtf/HashMap.h> | |
46 | #include <wtf/RefCounted.h> | |
9dae56ea A |
47 | |
48 | struct OpaqueJSClass; | |
49 | struct OpaqueJSClassContextData; | |
50 | ||
51 | namespace JSC { | |
52 | ||
f9bf01c6 | 53 | class CodeBlock; |
9dae56ea | 54 | class CommonIdentifiers; |
9dae56ea | 55 | class IdentifierTable; |
9dae56ea A |
56 | class Interpreter; |
57 | class JSGlobalObject; | |
58 | class JSObject; | |
59 | class Lexer; | |
60 | class Parser; | |
4e4e5a6f | 61 | class RegExpCache; |
ba379fdc | 62 | class Stringifier; |
9dae56ea A |
63 | class Structure; |
64 | class UString; | |
ba379fdc | 65 | |
9dae56ea | 66 | struct HashTable; |
f9bf01c6 A |
67 | struct Instruction; |
68 | ||
69 | struct DSTOffsetCache { | |
70 | DSTOffsetCache() | |
71 | { | |
72 | reset(); | |
73 | } | |
74 | ||
75 | void reset() | |
76 | { | |
77 | offset = 0.0; | |
78 | start = 0.0; | |
79 | end = -1.0; | |
80 | increment = 0.0; | |
81 | } | |
82 | ||
83 | double offset; | |
84 | double start; | |
85 | double end; | |
86 | double increment; | |
87 | }; | |
9dae56ea | 88 | |
4e4e5a6f A |
89 | enum ThreadStackType { |
90 | ThreadStackTypeLarge, | |
91 | ThreadStackTypeSmall | |
92 | }; | |
93 | ||
9dae56ea A |
94 | class JSGlobalData : public RefCounted<JSGlobalData> { |
95 | public: | |
4e4e5a6f A |
96 | // WebCore has a one-to-one mapping of threads to JSGlobalDatas; |
97 | // either create() or createLeaked() should only be called once | |
98 | // on a thread, this is the 'default' JSGlobalData (it uses the | |
99 | // thread's default string uniquing table from wtfThreadData). | |
100 | // API contexts created using the new context group aware interface | |
101 | // create APIContextGroup objects which require less locking of JSC | |
102 | // than the old singleton APIShared JSGlobalData created for use by | |
103 | // the original API. | |
104 | enum GlobalDataType { Default, APIContextGroup, APIShared }; | |
105 | ||
ba379fdc A |
106 | struct ClientData { |
107 | virtual ~ClientData() = 0; | |
108 | }; | |
109 | ||
4e4e5a6f | 110 | bool isSharedInstance() { return globalDataType == APIShared; } |
9dae56ea A |
111 | static bool sharedInstanceExists(); |
112 | static JSGlobalData& sharedInstance(); | |
113 | ||
4e4e5a6f A |
114 | static PassRefPtr<JSGlobalData> create(ThreadStackType); |
115 | static PassRefPtr<JSGlobalData> createLeaked(ThreadStackType); | |
116 | static PassRefPtr<JSGlobalData> createContextGroup(ThreadStackType); | |
9dae56ea A |
117 | ~JSGlobalData(); |
118 | ||
119 | #if ENABLE(JSC_MULTIPLE_THREADS) | |
120 | // Will start tracking threads that use the heap, which is resource-heavy. | |
121 | void makeUsableFromMultipleThreads() { heap.makeUsableFromMultipleThreads(); } | |
122 | #endif | |
123 | ||
4e4e5a6f | 124 | GlobalDataType globalDataType; |
ba379fdc | 125 | ClientData* clientData; |
9dae56ea A |
126 | |
127 | const HashTable* arrayTable; | |
128 | const HashTable* dateTable; | |
ba379fdc | 129 | const HashTable* jsonTable; |
9dae56ea A |
130 | const HashTable* mathTable; |
131 | const HashTable* numberTable; | |
132 | const HashTable* regExpTable; | |
133 | const HashTable* regExpConstructorTable; | |
134 | const HashTable* stringTable; | |
135 | ||
136 | RefPtr<Structure> activationStructure; | |
137 | RefPtr<Structure> interruptedExecutionErrorStructure; | |
4e4e5a6f | 138 | RefPtr<Structure> terminatedExecutionErrorStructure; |
9dae56ea A |
139 | RefPtr<Structure> staticScopeStructure; |
140 | RefPtr<Structure> stringStructure; | |
141 | RefPtr<Structure> notAnObjectErrorStubStructure; | |
142 | RefPtr<Structure> notAnObjectStructure; | |
f9bf01c6 A |
143 | RefPtr<Structure> propertyNameIteratorStructure; |
144 | RefPtr<Structure> getterSetterStructure; | |
145 | RefPtr<Structure> apiWrapperStructure; | |
146 | RefPtr<Structure> dummyMarkableCellStructure; | |
147 | ||
ba379fdc | 148 | #if USE(JSVALUE32) |
9dae56ea A |
149 | RefPtr<Structure> numberStructure; |
150 | #endif | |
151 | ||
f9bf01c6 A |
152 | static void storeVPtrs(); |
153 | static JS_EXPORTDATA void* jsArrayVPtr; | |
154 | static JS_EXPORTDATA void* jsByteArrayVPtr; | |
155 | static JS_EXPORTDATA void* jsStringVPtr; | |
156 | static JS_EXPORTDATA void* jsFunctionVPtr; | |
ba379fdc | 157 | |
9dae56ea A |
158 | IdentifierTable* identifierTable; |
159 | CommonIdentifiers* propertyNames; | |
ba379fdc | 160 | const MarkedArgumentBuffer* emptyList; // Lists are supposed to be allocated on the stack to have their elements properly marked, which is not the case here - but this list has nothing to mark. |
9dae56ea | 161 | SmallStrings smallStrings; |
f9bf01c6 A |
162 | NumericStrings numericStrings; |
163 | DateInstanceCache dateInstanceCache; | |
164 | ||
ba379fdc A |
165 | #if ENABLE(ASSEMBLER) |
166 | ExecutableAllocator executableAllocator; | |
b80e6193 | 167 | ExecutableAllocator regexAllocator; |
ba379fdc | 168 | #endif |
9dae56ea | 169 | |
4e4e5a6f A |
170 | #if ENABLE(JIT) |
171 | #if ENABLE(INTERPRETER) | |
172 | bool canUseJIT() { return m_canUseJIT; } | |
173 | #endif | |
174 | #else | |
175 | bool canUseJIT() { return false; } | |
176 | #endif | |
9dae56ea A |
177 | Lexer* lexer; |
178 | Parser* parser; | |
ba379fdc A |
179 | Interpreter* interpreter; |
180 | #if ENABLE(JIT) | |
4e4e5a6f A |
181 | OwnPtr<JITThunks> jitStubs; |
182 | NativeExecutable* getThunk(ThunkGenerator generator) | |
183 | { | |
184 | return jitStubs->specializedThunk(this, generator); | |
185 | } | |
ba379fdc A |
186 | #endif |
187 | TimeoutChecker timeoutChecker; | |
4e4e5a6f | 188 | Terminator terminator; |
ba379fdc | 189 | Heap heap; |
9dae56ea | 190 | |
ba379fdc A |
191 | JSValue exception; |
192 | #if ENABLE(JIT) | |
193 | ReturnAddressPtr exceptionLocation; | |
194 | #endif | |
9dae56ea | 195 | |
ba379fdc A |
196 | const Vector<Instruction>& numericCompareFunction(ExecState*); |
197 | Vector<Instruction> lazyNumericCompareFunction; | |
198 | bool initializingLazyNumericCompareFunction; | |
9dae56ea | 199 | |
ba379fdc | 200 | HashMap<OpaqueJSClass*, OpaqueJSClassContextData*> opaqueJSClassData; |
9dae56ea | 201 | |
ba379fdc A |
202 | JSGlobalObject* head; |
203 | JSGlobalObject* dynamicGlobalObject; | |
9dae56ea A |
204 | |
205 | HashSet<JSObject*> arrayVisitedElements; | |
206 | ||
f9bf01c6 | 207 | CodeBlock* functionCodeBlockBeingReparsed; |
ba379fdc | 208 | Stringifier* firstStringifierToMark; |
9dae56ea | 209 | |
f9bf01c6 A |
210 | MarkStack markStack; |
211 | ||
212 | double cachedUTCOffset; | |
213 | DSTOffsetCache dstOffsetCache; | |
214 | ||
215 | UString cachedDateString; | |
216 | double cachedDateStringValue; | |
4e4e5a6f A |
217 | |
218 | int maxReentryDepth; | |
219 | ||
220 | RegExpCache* m_regExpCache; | |
f9bf01c6 A |
221 | |
222 | #ifndef NDEBUG | |
4e4e5a6f | 223 | ThreadIdentifier exclusiveThread; |
f9bf01c6 A |
224 | #endif |
225 | ||
4e4e5a6f A |
226 | CachedTranscendentalFunction<sin> cachedSin; |
227 | ||
f9bf01c6 A |
228 | void resetDateCache(); |
229 | ||
230 | void startSampling(); | |
231 | void stopSampling(); | |
232 | void dumpSampleData(ExecState* exec); | |
b80e6193 | 233 | void recompileAllJSFunctions(); |
4e4e5a6f | 234 | RegExpCache* regExpCache() { return m_regExpCache; } |
9dae56ea | 235 | private: |
4e4e5a6f | 236 | JSGlobalData(GlobalDataType, ThreadStackType); |
9dae56ea | 237 | static JSGlobalData*& sharedInstanceInternal(); |
ba379fdc | 238 | void createNativeThunk(); |
4e4e5a6f A |
239 | #if ENABLE(JIT) && ENABLE(INTERPRETER) |
240 | bool m_canUseJIT; | |
241 | #endif | |
9dae56ea | 242 | }; |
4e4e5a6f | 243 | |
ba379fdc | 244 | } // namespace JSC |
9dae56ea | 245 | |
ba379fdc | 246 | #endif // JSGlobalData_h |