]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (C) 2008, 2009 Apple Inc. All rights reserved. | |
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 | ||
32 | #include "CachedTranscendentalFunction.h" | |
33 | #include "Collector.h" | |
34 | #include "DateInstanceCache.h" | |
35 | #include "ExecutableAllocator.h" | |
36 | #include "JITStubs.h" | |
37 | #include "JSValue.h" | |
38 | #include "MarkStack.h" | |
39 | #include "NumericStrings.h" | |
40 | #include "SmallStrings.h" | |
41 | #include "Terminator.h" | |
42 | #include "TimeoutChecker.h" | |
43 | #include "WeakRandom.h" | |
44 | #include <wtf/Forward.h> | |
45 | #include <wtf/HashMap.h> | |
46 | #include <wtf/RefCounted.h> | |
47 | ||
48 | struct OpaqueJSClass; | |
49 | struct OpaqueJSClassContextData; | |
50 | ||
51 | namespace JSC { | |
52 | ||
53 | class CodeBlock; | |
54 | class CommonIdentifiers; | |
55 | class IdentifierTable; | |
56 | class Interpreter; | |
57 | class JSGlobalObject; | |
58 | class JSObject; | |
59 | class Lexer; | |
60 | class Parser; | |
61 | class RegExpCache; | |
62 | class Stringifier; | |
63 | class Structure; | |
64 | class UString; | |
65 | ||
66 | struct HashTable; | |
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 | }; | |
88 | ||
89 | enum ThreadStackType { | |
90 | ThreadStackTypeLarge, | |
91 | ThreadStackTypeSmall | |
92 | }; | |
93 | ||
94 | class JSGlobalData : public RefCounted<JSGlobalData> { | |
95 | public: | |
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 | ||
106 | struct ClientData { | |
107 | virtual ~ClientData() = 0; | |
108 | }; | |
109 | ||
110 | bool isSharedInstance() { return globalDataType == APIShared; } | |
111 | static bool sharedInstanceExists(); | |
112 | static JSGlobalData& sharedInstance(); | |
113 | ||
114 | static PassRefPtr<JSGlobalData> create(ThreadStackType); | |
115 | static PassRefPtr<JSGlobalData> createLeaked(ThreadStackType); | |
116 | static PassRefPtr<JSGlobalData> createContextGroup(ThreadStackType); | |
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 | ||
124 | GlobalDataType globalDataType; | |
125 | ClientData* clientData; | |
126 | ||
127 | const HashTable* arrayTable; | |
128 | const HashTable* dateTable; | |
129 | const HashTable* jsonTable; | |
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; | |
138 | RefPtr<Structure> terminatedExecutionErrorStructure; | |
139 | RefPtr<Structure> staticScopeStructure; | |
140 | RefPtr<Structure> stringStructure; | |
141 | RefPtr<Structure> notAnObjectErrorStubStructure; | |
142 | RefPtr<Structure> notAnObjectStructure; | |
143 | RefPtr<Structure> propertyNameIteratorStructure; | |
144 | RefPtr<Structure> getterSetterStructure; | |
145 | RefPtr<Structure> apiWrapperStructure; | |
146 | RefPtr<Structure> dummyMarkableCellStructure; | |
147 | ||
148 | #if USE(JSVALUE32) | |
149 | RefPtr<Structure> numberStructure; | |
150 | #endif | |
151 | ||
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; | |
157 | ||
158 | IdentifierTable* identifierTable; | |
159 | CommonIdentifiers* propertyNames; | |
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. | |
161 | SmallStrings smallStrings; | |
162 | NumericStrings numericStrings; | |
163 | DateInstanceCache dateInstanceCache; | |
164 | ||
165 | #if ENABLE(ASSEMBLER) | |
166 | ExecutableAllocator executableAllocator; | |
167 | ExecutableAllocator regexAllocator; | |
168 | #endif | |
169 | ||
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 | |
177 | Lexer* lexer; | |
178 | Parser* parser; | |
179 | Interpreter* interpreter; | |
180 | #if ENABLE(JIT) | |
181 | OwnPtr<JITThunks> jitStubs; | |
182 | NativeExecutable* getThunk(ThunkGenerator generator) | |
183 | { | |
184 | return jitStubs->specializedThunk(this, generator); | |
185 | } | |
186 | #endif | |
187 | TimeoutChecker timeoutChecker; | |
188 | Terminator terminator; | |
189 | Heap heap; | |
190 | ||
191 | JSValue exception; | |
192 | #if ENABLE(JIT) | |
193 | ReturnAddressPtr exceptionLocation; | |
194 | #endif | |
195 | ||
196 | const Vector<Instruction>& numericCompareFunction(ExecState*); | |
197 | Vector<Instruction> lazyNumericCompareFunction; | |
198 | bool initializingLazyNumericCompareFunction; | |
199 | ||
200 | HashMap<OpaqueJSClass*, OpaqueJSClassContextData*> opaqueJSClassData; | |
201 | ||
202 | JSGlobalObject* head; | |
203 | JSGlobalObject* dynamicGlobalObject; | |
204 | ||
205 | HashSet<JSObject*> arrayVisitedElements; | |
206 | ||
207 | CodeBlock* functionCodeBlockBeingReparsed; | |
208 | Stringifier* firstStringifierToMark; | |
209 | ||
210 | MarkStack markStack; | |
211 | ||
212 | double cachedUTCOffset; | |
213 | DSTOffsetCache dstOffsetCache; | |
214 | ||
215 | UString cachedDateString; | |
216 | double cachedDateStringValue; | |
217 | ||
218 | int maxReentryDepth; | |
219 | ||
220 | RegExpCache* m_regExpCache; | |
221 | ||
222 | #ifndef NDEBUG | |
223 | ThreadIdentifier exclusiveThread; | |
224 | #endif | |
225 | ||
226 | CachedTranscendentalFunction<sin> cachedSin; | |
227 | ||
228 | void resetDateCache(); | |
229 | ||
230 | void startSampling(); | |
231 | void stopSampling(); | |
232 | void dumpSampleData(ExecState* exec); | |
233 | void recompileAllJSFunctions(); | |
234 | RegExpCache* regExpCache() { return m_regExpCache; } | |
235 | private: | |
236 | JSGlobalData(GlobalDataType, ThreadStackType); | |
237 | static JSGlobalData*& sharedInstanceInternal(); | |
238 | void createNativeThunk(); | |
239 | #if ENABLE(JIT) && ENABLE(INTERPRETER) | |
240 | bool m_canUseJIT; | |
241 | #endif | |
242 | }; | |
243 | ||
244 | } // namespace JSC | |
245 | ||
246 | #endif // JSGlobalData_h |