Rubber-stamped by Brady Eidson.
[webbrowser.git] / JavaScriptCore / runtime / JSGlobalData.h
blob9f725c6b990aa37b192357283fcd27feffbed22f
1 /*
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
6 * are met:
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 "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>
46 struct OpaqueJSClass;
47 struct OpaqueJSClassContextData;
49 namespace JSC {
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;
63 struct HashTable;
64 struct Instruction;
65 struct VPtrSet;
67 struct DSTOffsetCache {
68 DSTOffsetCache()
70 reset();
73 void reset()
75 offset = 0.0;
76 start = 0.0;
77 end = -1.0;
78 increment = 0.0;
81 double offset;
82 double start;
83 double end;
84 double increment;
87 class JSGlobalData : public RefCounted<JSGlobalData> {
88 public:
89 struct ClientData {
90 virtual ~ClientData() = 0;
93 static bool sharedInstanceExists();
94 static JSGlobalData& sharedInstance();
96 static PassRefPtr<JSGlobalData> create(bool isShared = false);
97 static PassRefPtr<JSGlobalData> createLeaked();
98 ~JSGlobalData();
100 #if ENABLE(JSC_MULTIPLE_THREADS)
101 // Will start tracking threads that use the heap, which is resource-heavy.
102 void makeUsableFromMultipleThreads() { heap.makeUsableFromMultipleThreads(); }
103 #endif
105 bool isSharedInstance;
106 ClientData* clientData;
108 const HashTable* arrayTable;
109 const HashTable* dateTable;
110 const HashTable* jsonTable;
111 const HashTable* mathTable;
112 const HashTable* numberTable;
113 const HashTable* regExpTable;
114 const HashTable* regExpConstructorTable;
115 const HashTable* stringTable;
117 RefPtr<Structure> activationStructure;
118 RefPtr<Structure> interruptedExecutionErrorStructure;
119 RefPtr<Structure> staticScopeStructure;
120 RefPtr<Structure> stringStructure;
121 RefPtr<Structure> notAnObjectErrorStubStructure;
122 RefPtr<Structure> notAnObjectStructure;
123 RefPtr<Structure> propertyNameIteratorStructure;
124 RefPtr<Structure> getterSetterStructure;
125 RefPtr<Structure> apiWrapperStructure;
126 RefPtr<Structure> dummyMarkableCellStructure;
128 #if USE(JSVALUE32)
129 RefPtr<Structure> numberStructure;
130 #endif
132 void* jsArrayVPtr;
133 void* jsByteArrayVPtr;
134 void* jsStringVPtr;
135 void* jsFunctionVPtr;
137 IdentifierTable* identifierTable;
138 CommonIdentifiers* propertyNames;
139 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.
140 SmallStrings smallStrings;
141 NumericStrings numericStrings;
142 DateInstanceCache dateInstanceCache;
144 #if ENABLE(ASSEMBLER)
145 ExecutableAllocator executableAllocator;
146 #endif
148 Lexer* lexer;
149 Parser* parser;
150 Interpreter* interpreter;
151 #if ENABLE(JIT)
152 JITThunks jitStubs;
153 #endif
154 TimeoutChecker timeoutChecker;
155 Heap heap;
157 JSValue exception;
158 #if ENABLE(JIT)
159 ReturnAddressPtr exceptionLocation;
160 #endif
162 const Vector<Instruction>& numericCompareFunction(ExecState*);
163 Vector<Instruction> lazyNumericCompareFunction;
164 bool initializingLazyNumericCompareFunction;
166 HashMap<OpaqueJSClass*, OpaqueJSClassContextData*> opaqueJSClassData;
168 JSGlobalObject* head;
169 JSGlobalObject* dynamicGlobalObject;
171 HashSet<JSObject*> arrayVisitedElements;
173 CodeBlock* functionCodeBlockBeingReparsed;
174 Stringifier* firstStringifierToMark;
176 MarkStack markStack;
178 double cachedUTCOffset;
179 DSTOffsetCache dstOffsetCache;
181 UString cachedDateString;
182 double cachedDateStringValue;
184 WeakRandom weakRandom;
186 #ifndef NDEBUG
187 bool mainThreadOnly;
188 #endif
190 void resetDateCache();
192 void startSampling();
193 void stopSampling();
194 void dumpSampleData(ExecState* exec);
195 private:
196 JSGlobalData(bool isShared, const VPtrSet&);
197 static JSGlobalData*& sharedInstanceInternal();
198 void createNativeThunk();
201 } // namespace JSC
203 #endif // JSGlobalData_h