2 * Copyright (C) 2008, 2009 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
29 #ifndef JSGlobalData_h
30 #define JSGlobalData_h
32 #include "CachedTranscendentalFunction.h"
34 #include "DateInstanceCache.h"
35 #include "ExecutableAllocator.h"
39 #include "NumericStrings.h"
40 #include "SmallStrings.h"
41 #include "Terminator.h"
42 #include "TimeoutChecker.h"
43 #include "WeakRandom.h"
44 #include <wtf/BumpPointerAllocator.h>
45 #include <wtf/Forward.h>
46 #include <wtf/HashMap.h>
47 #include <wtf/RefCounted.h>
48 #include <wtf/ThreadSpecific.h>
49 #include <wtf/WTFThreadData.h>
50 #if ENABLE(REGEXP_TRACING)
51 #include <wtf/ListHashSet.h>
55 struct OpaqueJSClassContextData
;
60 class CommonIdentifiers
;
62 class IdentifierTable
;
67 class NativeExecutable
;
73 #if ENABLE(REGEXP_TRACING)
80 struct DSTOffsetCache
{
100 enum ThreadStackType
{
101 ThreadStackTypeLarge
,
105 class JSGlobalData
: public RefCounted
<JSGlobalData
> {
107 // WebCore has a one-to-one mapping of threads to JSGlobalDatas;
108 // either create() or createLeaked() should only be called once
109 // on a thread, this is the 'default' JSGlobalData (it uses the
110 // thread's default string uniquing table from wtfThreadData).
111 // API contexts created using the new context group aware interface
112 // create APIContextGroup objects which require less locking of JSC
113 // than the old singleton APIShared JSGlobalData created for use by
115 enum GlobalDataType
{ Default
, APIContextGroup
, APIShared
};
118 virtual ~ClientData() = 0;
121 bool isSharedInstance() { return globalDataType
== APIShared
; }
122 bool usingAPI() { return globalDataType
!= Default
; }
123 static bool sharedInstanceExists();
124 static JSGlobalData
& sharedInstance();
126 static PassRefPtr
<JSGlobalData
> create(ThreadStackType
);
127 static PassRefPtr
<JSGlobalData
> createLeaked(ThreadStackType
);
128 static PassRefPtr
<JSGlobalData
> createContextGroup(ThreadStackType
);
131 #if ENABLE(JSC_MULTIPLE_THREADS)
132 // Will start tracking threads that use the heap, which is resource-heavy.
133 void makeUsableFromMultipleThreads() { heap
.machineThreads().makeUsableFromMultipleThreads(); }
136 GlobalDataType globalDataType
;
137 ClientData
* clientData
;
139 const HashTable
* arrayConstructorTable
;
140 const HashTable
* arrayPrototypeTable
;
141 const HashTable
* booleanPrototypeTable
;
142 const HashTable
* dateTable
;
143 const HashTable
* dateConstructorTable
;
144 const HashTable
* errorPrototypeTable
;
145 const HashTable
* globalObjectTable
;
146 const HashTable
* jsonTable
;
147 const HashTable
* mathTable
;
148 const HashTable
* numberConstructorTable
;
149 const HashTable
* numberPrototypeTable
;
150 const HashTable
* objectConstructorTable
;
151 const HashTable
* objectPrototypeTable
;
152 const HashTable
* regExpTable
;
153 const HashTable
* regExpConstructorTable
;
154 const HashTable
* regExpPrototypeTable
;
155 const HashTable
* stringTable
;
156 const HashTable
* stringConstructorTable
;
158 Strong
<Structure
> structureStructure
;
159 Strong
<Structure
> debuggerActivationStructure
;
160 Strong
<Structure
> activationStructure
;
161 Strong
<Structure
> interruptedExecutionErrorStructure
;
162 Strong
<Structure
> terminatedExecutionErrorStructure
;
163 Strong
<Structure
> staticScopeStructure
;
164 Strong
<Structure
> strictEvalActivationStructure
;
165 Strong
<Structure
> stringStructure
;
166 Strong
<Structure
> notAnObjectStructure
;
167 Strong
<Structure
> propertyNameIteratorStructure
;
168 Strong
<Structure
> getterSetterStructure
;
169 Strong
<Structure
> apiWrapperStructure
;
170 Strong
<Structure
> scopeChainNodeStructure
;
171 Strong
<Structure
> executableStructure
;
172 Strong
<Structure
> nativeExecutableStructure
;
173 Strong
<Structure
> evalExecutableStructure
;
174 Strong
<Structure
> programExecutableStructure
;
175 Strong
<Structure
> functionExecutableStructure
;
176 Strong
<Structure
> dummyMarkableCellStructure
;
177 Strong
<Structure
> regExpStructure
;
178 Strong
<Structure
> structureChainStructure
;
180 #if ENABLE(JSC_ZOMBIES)
181 Strong
<Structure
> zombieStructure
;
184 static void storeVPtrs();
185 static JS_EXPORTDATA
void* jsArrayVPtr
;
186 static JS_EXPORTDATA
void* jsByteArrayVPtr
;
187 static JS_EXPORTDATA
void* jsStringVPtr
;
188 static JS_EXPORTDATA
void* jsFunctionVPtr
;
190 IdentifierTable
* identifierTable
;
191 CommonIdentifiers
* propertyNames
;
192 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.
193 SmallStrings smallStrings
;
194 NumericStrings numericStrings
;
195 DateInstanceCache dateInstanceCache
;
197 #if ENABLE(ASSEMBLER)
198 ExecutableAllocator executableAllocator
;
199 ExecutableAllocator regexAllocator
;
203 bool canUseJIT() { return false; } // interpreter only
204 #elif !ENABLE(INTERPRETER)
205 bool canUseJIT() { return true; } // jit only
207 bool canUseJIT() { return m_canUseJIT
; }
210 const StackBounds
& stack()
212 return wtfThreadData().stack();
217 Interpreter
* interpreter
;
219 OwnPtr
<JITThunks
> jitStubs
;
220 MacroAssemblerCodePtr
getCTIStub(ThunkGenerator generator
)
222 return jitStubs
->ctiStub(this, generator
);
224 NativeExecutable
* getHostFunction(NativeFunction
, ThunkGenerator
);
226 NativeExecutable
* getHostFunction(NativeFunction
);
228 TimeoutChecker timeoutChecker
;
229 Terminator terminator
;
234 ReturnAddressPtr exceptionLocation
;
237 HashMap
<OpaqueJSClass
*, OpaqueJSClassContextData
*> opaqueJSClassData
;
239 unsigned globalObjectCount
;
240 JSGlobalObject
* dynamicGlobalObject
;
242 HashSet
<JSObject
*> stringRecursionCheckVisitedObjects
;
244 double cachedUTCOffset
;
245 DSTOffsetCache dstOffsetCache
;
247 UString cachedDateString
;
248 double cachedDateStringValue
;
252 RegExpCache
* m_regExpCache
;
253 BumpPointerAllocator m_regExpAllocator
;
255 #if ENABLE(REGEXP_TRACING)
256 typedef ListHashSet
<RefPtr
<RegExp
> > RTTraceList
;
257 RTTraceList
* m_rtTraceList
;
261 ThreadIdentifier exclusiveThread
;
264 CachedTranscendentalFunction
<sin
> cachedSin
;
266 void resetDateCache();
268 void startSampling();
270 void dumpSampleData(ExecState
* exec
);
271 void recompileAllJSFunctions();
272 RegExpCache
* regExpCache() { return m_regExpCache
; }
273 #if ENABLE(REGEXP_TRACING)
274 void addRegExpToTrace(PassRefPtr
<RegExp
> regExp
);
276 void dumpRegExpTrace();
277 HandleSlot
allocateGlobalHandle() { return heap
.allocateGlobalHandle(); }
278 HandleSlot
allocateLocalHandle() { return heap
.allocateLocalHandle(); }
279 void clearBuiltinStructures();
281 bool isCollectorBusy() { return heap
.isBusy(); }
282 void releaseExecutableMemory();
285 JSGlobalData(GlobalDataType
, ThreadStackType
);
286 static JSGlobalData
*& sharedInstanceInternal();
287 void createNativeThunk();
288 #if ENABLE(JIT) && ENABLE(INTERPRETER)
294 inline HandleSlot
allocateGlobalHandle(JSGlobalData
& globalData
)
296 return globalData
.allocateGlobalHandle();
301 #endif // JSGlobalData_h