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 "TimeoutChecker.h"
41#include "WeakRandom.h"
42#include <wtf/Forward.h>
43#include <wtf/HashMap.h>
44#include <wtf/RefCounted.h>
45
46struct OpaqueJSClass;
47struct OpaqueJSClassContextData;
48
49namespace JSC {
50
51 class CodeBlock;
52 class CommonIdentifiers;
53 class IdentifierTable;
54 class Interpreter;
55 class JSGlobalObject;
56 class JSObject;
57 class Lexer;
58 class Parser;
59 class Stringifier;
60 class Structure;
61 class UString;
62
63 struct HashTable;
64 struct Instruction;
65
66 struct DSTOffsetCache {
67 DSTOffsetCache()
68 {
69 reset();
70 }
71
72 void reset()
73 {
74 offset = 0.0;
75 start = 0.0;
76 end = -1.0;
77 increment = 0.0;
78 }
79
80 double offset;
81 double start;
82 double end;
83 double increment;
84 };
85
86 class JSGlobalData : public RefCounted<JSGlobalData> {
87 public:
88 struct ClientData {
89 virtual ~ClientData() = 0;
90#ifdef QT_BUILD_SCRIPT_LIB
91 virtual void mark(MarkStack&) {}
92#endif
93 };
94
95 static bool sharedInstanceExists();
96 static JSGlobalData& sharedInstance();
97
98 static PassRefPtr<JSGlobalData> create();
99 static PassRefPtr<JSGlobalData> createLeaked();
100 static PassRefPtr<JSGlobalData> createNonDefault();
101 ~JSGlobalData();
102
103#if ENABLE(JSC_MULTIPLE_THREADS)
104 // Will start tracking threads that use the heap, which is resource-heavy.
105 void makeUsableFromMultipleThreads() { heap.makeUsableFromMultipleThreads(); }
106#endif
107
108 bool isSharedInstance;
109 ClientData* clientData;
110
111 const HashTable* arrayTable;
112 const HashTable* dateTable;
113 const HashTable* jsonTable;
114 const HashTable* mathTable;
115 const HashTable* numberTable;
116 const HashTable* regExpTable;
117 const HashTable* regExpConstructorTable;
118 const HashTable* stringTable;
119
120 RefPtr<Structure> activationStructure;
121 RefPtr<Structure> interruptedExecutionErrorStructure;
122 RefPtr<Structure> staticScopeStructure;
123 RefPtr<Structure> stringStructure;
124 RefPtr<Structure> notAnObjectErrorStubStructure;
125 RefPtr<Structure> notAnObjectStructure;
126 RefPtr<Structure> propertyNameIteratorStructure;
127 RefPtr<Structure> getterSetterStructure;
128 RefPtr<Structure> apiWrapperStructure;
129 RefPtr<Structure> dummyMarkableCellStructure;
130
131#if USE(JSVALUE32)
132 RefPtr<Structure> numberStructure;
133#endif
134
135 static void storeVPtrs();
136 static JS_EXPORTDATA void* jsArrayVPtr;
137 static JS_EXPORTDATA void* jsByteArrayVPtr;
138 static JS_EXPORTDATA void* jsStringVPtr;
139 static JS_EXPORTDATA void* jsFunctionVPtr;
140
141 IdentifierTable* identifierTable;
142 CommonIdentifiers* propertyNames;
143 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.
144 SmallStrings smallStrings;
145 NumericStrings numericStrings;
146 DateInstanceCache dateInstanceCache;
147
148#if ENABLE(ASSEMBLER)
149 ExecutableAllocator executableAllocator;
150#endif
151
152 Lexer* lexer;
153 Parser* parser;
154 Interpreter* interpreter;
155#if ENABLE(JIT)
156 JITThunks jitStubs;
157#endif
158 TimeoutChecker* timeoutChecker;
159 Heap heap;
160
161 JSValue exception;
162#if ENABLE(JIT)
163 ReturnAddressPtr exceptionLocation;
164#endif
165
166 const Vector<Instruction>& numericCompareFunction(ExecState*);
167 Vector<Instruction> lazyNumericCompareFunction;
168 bool initializingLazyNumericCompareFunction;
169
170 HashMap<OpaqueJSClass*, OpaqueJSClassContextData*> opaqueJSClassData;
171
172 JSGlobalObject* head;
173 JSGlobalObject* dynamicGlobalObject;
174
175 HashSet<JSObject*> arrayVisitedElements;
176
177 CodeBlock* functionCodeBlockBeingReparsed;
178 Stringifier* firstStringifierToMark;
179
180 MarkStack markStack;
181
182 double cachedUTCOffset;
183 DSTOffsetCache dstOffsetCache;
184
185 UString cachedDateString;
186 double cachedDateStringValue;
187
188#ifndef NDEBUG
189 bool mainThreadOnly;
190#endif
191
192 void resetDateCache();
193
194 void startSampling();
195 void stopSampling();
196 void dumpSampleData(ExecState* exec);
197 private:
198 JSGlobalData(bool isShared);
199 static JSGlobalData*& sharedInstanceInternal();
200 void createNativeThunk();
201 };
202
203} // namespace JSC
204
205#endif // JSGlobalData_h
206