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

source code of qtscript/src/3rdparty/javascriptcore/JavaScriptCore/runtime/JSGlobalData.h