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"
33 #include "Collector.h"
34 #include "DateInstanceCache.h"
35 #include "ExecutableAllocator.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>
49 struct OpaqueJSClassContextData
;
54 class CommonIdentifiers
;
55 class IdentifierTable
;
69 struct DSTOffsetCache
{
89 enum ThreadStackType
{
94 class JSGlobalData
: public RefCounted
<JSGlobalData
> {
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
104 enum GlobalDataType
{ Default
, APIContextGroup
, APIShared
};
107 virtual ~ClientData() = 0;
110 bool isSharedInstance() { return globalDataType
== APIShared
; }
111 static bool sharedInstanceExists();
112 static JSGlobalData
& sharedInstance();
114 static PassRefPtr
<JSGlobalData
> create(ThreadStackType
);
115 static PassRefPtr
<JSGlobalData
> createLeaked(ThreadStackType
);
116 static PassRefPtr
<JSGlobalData
> createContextGroup(ThreadStackType
);
119 #if ENABLE(JSC_MULTIPLE_THREADS)
120 // Will start tracking threads that use the heap, which is resource-heavy.
121 void makeUsableFromMultipleThreads() { heap
.makeUsableFromMultipleThreads(); }
124 GlobalDataType globalDataType
;
125 ClientData
* clientData
;
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
;
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
;
149 RefPtr
<Structure
> numberStructure
;
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
;
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
;
165 #if ENABLE(ASSEMBLER)
166 ExecutableAllocator executableAllocator
;
167 ExecutableAllocator regexAllocator
;
171 #if ENABLE(INTERPRETER)
172 bool canUseJIT() { return m_canUseJIT
; }
175 bool canUseJIT() { return false; }
179 Interpreter
* interpreter
;
181 OwnPtr
<JITThunks
> jitStubs
;
182 NativeExecutable
* getThunk(ThunkGenerator generator
)
184 return jitStubs
->specializedThunk(this, generator
);
187 TimeoutChecker timeoutChecker
;
188 Terminator terminator
;
193 ReturnAddressPtr exceptionLocation
;
196 const Vector
<Instruction
>& numericCompareFunction(ExecState
*);
197 Vector
<Instruction
> lazyNumericCompareFunction
;
198 bool initializingLazyNumericCompareFunction
;
200 HashMap
<OpaqueJSClass
*, OpaqueJSClassContextData
*> opaqueJSClassData
;
202 JSGlobalObject
* head
;
203 JSGlobalObject
* dynamicGlobalObject
;
205 HashSet
<JSObject
*> arrayVisitedElements
;
207 CodeBlock
* functionCodeBlockBeingReparsed
;
208 Stringifier
* firstStringifierToMark
;
212 double cachedUTCOffset
;
213 DSTOffsetCache dstOffsetCache
;
215 UString cachedDateString
;
216 double cachedDateStringValue
;
220 RegExpCache
* m_regExpCache
;
223 ThreadIdentifier exclusiveThread
;
226 CachedTranscendentalFunction
<sin
> cachedSin
;
228 void resetDateCache();
230 void startSampling();
232 void dumpSampleData(ExecState
* exec
);
233 void recompileAllJSFunctions();
234 RegExpCache
* regExpCache() { return m_regExpCache
; }
236 JSGlobalData(GlobalDataType
, ThreadStackType
);
237 static JSGlobalData
*& sharedInstanceInternal();
238 void createNativeThunk();
239 #if ENABLE(JIT) && ENABLE(INTERPRETER)
246 #endif // JSGlobalData_h