|
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 #include <wtf/ThreadSpecific.h> |
|
48 |
|
49 struct OpaqueJSClass; |
|
50 struct OpaqueJSClassContextData; |
|
51 |
|
52 namespace JSC { |
|
53 |
|
54 class CodeBlock; |
|
55 class CommonIdentifiers; |
|
56 class IdentifierTable; |
|
57 class Interpreter; |
|
58 class JSGlobalObject; |
|
59 class JSObject; |
|
60 class Lexer; |
|
61 class Parser; |
|
62 class RegExpCache; |
|
63 class Stringifier; |
|
64 class Structure; |
|
65 class UString; |
|
66 |
|
67 struct HashTable; |
|
68 struct Instruction; |
|
69 |
|
70 struct DSTOffsetCache { |
|
71 DSTOffsetCache() |
|
72 { |
|
73 reset(); |
|
74 } |
|
75 |
|
76 void reset() |
|
77 { |
|
78 offset = 0.0; |
|
79 start = 0.0; |
|
80 end = -1.0; |
|
81 increment = 0.0; |
|
82 } |
|
83 |
|
84 double offset; |
|
85 double start; |
|
86 double end; |
|
87 double increment; |
|
88 }; |
|
89 |
|
90 enum ThreadStackType { |
|
91 ThreadStackTypeLarge, |
|
92 ThreadStackTypeSmall |
|
93 }; |
|
94 |
|
95 class JSGlobalData : public RefCounted<JSGlobalData> { |
|
96 public: |
|
97 // WebCore has a one-to-one mapping of threads to JSGlobalDatas; |
|
98 // either create() or createLeaked() should only be called once |
|
99 // on a thread, this is the 'default' JSGlobalData (it uses the |
|
100 // thread's default string uniquing table from wtfThreadData). |
|
101 // API contexts created using the new context group aware interface |
|
102 // create APIContextGroup objects which require less locking of JSC |
|
103 // than the old singleton APIShared JSGlobalData created for use by |
|
104 // the original API. |
|
105 enum GlobalDataType { Default, APIContextGroup, APIShared }; |
|
106 |
|
107 struct ClientData { |
|
108 virtual ~ClientData() = 0; |
|
109 }; |
|
110 |
|
111 bool isSharedInstance() { return globalDataType == APIShared; } |
|
112 static bool sharedInstanceExists(); |
|
113 static JSGlobalData& sharedInstance(); |
|
114 |
|
115 static PassRefPtr<JSGlobalData> create(ThreadStackType); |
|
116 static PassRefPtr<JSGlobalData> createLeaked(ThreadStackType); |
|
117 static PassRefPtr<JSGlobalData> createContextGroup(ThreadStackType); |
|
118 ~JSGlobalData(); |
|
119 |
|
120 #if ENABLE(JSC_MULTIPLE_THREADS) |
|
121 // Will start tracking threads that use the heap, which is resource-heavy. |
|
122 void makeUsableFromMultipleThreads() { heap.makeUsableFromMultipleThreads(); } |
|
123 #endif |
|
124 |
|
125 GlobalDataType globalDataType; |
|
126 ClientData* clientData; |
|
127 |
|
128 const HashTable* arrayTable; |
|
129 const HashTable* dateTable; |
|
130 const HashTable* jsonTable; |
|
131 const HashTable* mathTable; |
|
132 const HashTable* numberTable; |
|
133 const HashTable* regExpTable; |
|
134 const HashTable* regExpConstructorTable; |
|
135 const HashTable* stringTable; |
|
136 |
|
137 RefPtr<Structure> activationStructure; |
|
138 RefPtr<Structure> interruptedExecutionErrorStructure; |
|
139 RefPtr<Structure> terminatedExecutionErrorStructure; |
|
140 RefPtr<Structure> staticScopeStructure; |
|
141 RefPtr<Structure> stringStructure; |
|
142 RefPtr<Structure> notAnObjectErrorStubStructure; |
|
143 RefPtr<Structure> notAnObjectStructure; |
|
144 RefPtr<Structure> propertyNameIteratorStructure; |
|
145 RefPtr<Structure> getterSetterStructure; |
|
146 RefPtr<Structure> apiWrapperStructure; |
|
147 RefPtr<Structure> dummyMarkableCellStructure; |
|
148 |
|
149 #if USE(JSVALUE32) |
|
150 RefPtr<Structure> numberStructure; |
|
151 #endif |
|
152 |
|
153 static void storeVPtrs(); |
|
154 static JS_EXPORTDATA void* jsArrayVPtr; |
|
155 static JS_EXPORTDATA void* jsByteArrayVPtr; |
|
156 static JS_EXPORTDATA void* jsStringVPtr; |
|
157 static JS_EXPORTDATA void* jsFunctionVPtr; |
|
158 |
|
159 IdentifierTable* identifierTable; |
|
160 CommonIdentifiers* propertyNames; |
|
161 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. |
|
162 SmallStrings smallStrings; |
|
163 NumericStrings numericStrings; |
|
164 DateInstanceCache dateInstanceCache; |
|
165 |
|
166 #if ENABLE(ASSEMBLER) |
|
167 ExecutableAllocator executableAllocator; |
|
168 #endif |
|
169 |
|
170 #if !ENABLE(JIT) |
|
171 bool canUseJIT() { return false; } // interpreter only |
|
172 #elif !ENABLE(INTERPRETER) |
|
173 bool canUseJIT() { return true; } // jit only |
|
174 #else |
|
175 bool canUseJIT() { return m_canUseJIT; } |
|
176 #endif |
|
177 Lexer* lexer; |
|
178 Parser* parser; |
|
179 Interpreter* interpreter; |
|
180 #if ENABLE(JIT) |
|
181 OwnPtr<JITThunks> jitStubs; |
|
182 MacroAssemblerCodePtr getCTIStub(ThunkGenerator generator) |
|
183 { |
|
184 return jitStubs->ctiStub(this, generator); |
|
185 } |
|
186 PassRefPtr<NativeExecutable> getHostFunction(NativeFunction function); |
|
187 PassRefPtr<NativeExecutable> getHostFunction(NativeFunction function, ThunkGenerator generator); |
|
188 #endif |
|
189 TimeoutChecker timeoutChecker; |
|
190 Terminator terminator; |
|
191 Heap heap; |
|
192 |
|
193 JSValue exception; |
|
194 #if ENABLE(JIT) |
|
195 ReturnAddressPtr exceptionLocation; |
|
196 #endif |
|
197 |
|
198 HashMap<OpaqueJSClass*, OpaqueJSClassContextData*> opaqueJSClassData; |
|
199 |
|
200 JSGlobalObject* head; |
|
201 JSGlobalObject* dynamicGlobalObject; |
|
202 |
|
203 HashSet<JSObject*> arrayVisitedElements; |
|
204 |
|
205 CodeBlock* functionCodeBlockBeingReparsed; |
|
206 Stringifier* firstStringifierToMark; |
|
207 |
|
208 MarkStack markStack; |
|
209 |
|
210 double cachedUTCOffset; |
|
211 DSTOffsetCache dstOffsetCache; |
|
212 |
|
213 UString cachedDateString; |
|
214 double cachedDateStringValue; |
|
215 |
|
216 WeakRandom weakRandom; |
|
217 |
|
218 int maxReentryDepth; |
|
219 |
|
220 RegExpCache* m_regExpCache; |
|
221 |
|
222 #ifndef NDEBUG |
|
223 ThreadIdentifier exclusiveThread; |
|
224 #endif |
|
225 |
|
226 CachedTranscendentalFunction<sin> cachedSin; |
|
227 WTF::ThreadSpecific<char*> stackGuards; |
|
228 |
|
229 void resetDateCache(); |
|
230 |
|
231 void startSampling(); |
|
232 void stopSampling(); |
|
233 void dumpSampleData(ExecState* exec); |
|
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 |