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