• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "ExecutableAllocator.h"
34 #include "JITStubs.h"
35 #include "JSValue.h"
36 #include "MarkStack.h"
37 #include "SmallStrings.h"
38 #include "TimeoutChecker.h"
39 #include <wtf/Forward.h>
40 #include <wtf/HashMap.h>
41 #include <wtf/RefCounted.h>
42 
43 struct OpaqueJSClass;
44 struct OpaqueJSClassContextData;
45 
46 namespace JSC {
47 
48     class CommonIdentifiers;
49     class FunctionBodyNode;
50     class IdentifierTable;
51     class Interpreter;
52     class JSGlobalObject;
53     class JSObject;
54     class Lexer;
55     class Parser;
56     class ScopeNode;
57     class Stringifier;
58     class Structure;
59     class UString;
60 
61     struct HashTable;
62     struct Instruction;
63     struct VPtrSet;
64 
65     class JSGlobalData : public RefCounted<JSGlobalData> {
66     public:
67         struct ClientData {
68             virtual ~ClientData() = 0;
69         };
70 
71         static bool sharedInstanceExists();
72         static JSGlobalData& sharedInstance();
73 
74         static PassRefPtr<JSGlobalData> create(bool isShared = false);
75         static PassRefPtr<JSGlobalData> createLeaked();
76         ~JSGlobalData();
77 
78 #if ENABLE(JSC_MULTIPLE_THREADS)
79         // Will start tracking threads that use the heap, which is resource-heavy.
makeUsableFromMultipleThreads()80         void makeUsableFromMultipleThreads() { heap.makeUsableFromMultipleThreads(); }
81 #endif
82 
83         bool isSharedInstance;
84         ClientData* clientData;
85 
86         const HashTable* arrayTable;
87         const HashTable* dateTable;
88         const HashTable* jsonTable;
89         const HashTable* mathTable;
90         const HashTable* numberTable;
91         const HashTable* regExpTable;
92         const HashTable* regExpConstructorTable;
93         const HashTable* stringTable;
94 
95         RefPtr<Structure> activationStructure;
96         RefPtr<Structure> interruptedExecutionErrorStructure;
97         RefPtr<Structure> staticScopeStructure;
98         RefPtr<Structure> stringStructure;
99         RefPtr<Structure> notAnObjectErrorStubStructure;
100         RefPtr<Structure> notAnObjectStructure;
101         RefPtr<Structure> propertyNameIteratorStructure;
102         RefPtr<Structure> getterSetterStructure;
103         RefPtr<Structure> apiWrapperStructure;
104 
105 #if USE(JSVALUE32)
106         RefPtr<Structure> numberStructure;
107 #endif
108 
109         void* jsArrayVPtr;
110         void* jsByteArrayVPtr;
111         void* jsStringVPtr;
112         void* jsFunctionVPtr;
113 
114         IdentifierTable* identifierTable;
115         CommonIdentifiers* propertyNames;
116         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.
117         SmallStrings smallStrings;
118 
119 #if ENABLE(ASSEMBLER)
120         ExecutableAllocator executableAllocator;
121 #endif
122 
123         Lexer* lexer;
124         Parser* parser;
125         Interpreter* interpreter;
126 #if ENABLE(JIT)
127         JITThunks jitStubs;
128 #endif
129         TimeoutChecker timeoutChecker;
130         Heap heap;
131 
132         JSValue exception;
133 #if ENABLE(JIT)
134         ReturnAddressPtr exceptionLocation;
135 #endif
136 
137         const Vector<Instruction>& numericCompareFunction(ExecState*);
138         Vector<Instruction> lazyNumericCompareFunction;
139         bool initializingLazyNumericCompareFunction;
140 
141         HashMap<OpaqueJSClass*, OpaqueJSClassContextData*> opaqueJSClassData;
142 
143         JSGlobalObject* head;
144         JSGlobalObject* dynamicGlobalObject;
145 
146         HashSet<JSObject*> arrayVisitedElements;
147 
148         ScopeNode* scopeNodeBeingReparsed;
149         Stringifier* firstStringifierToMark;
150 
151         MarkStack markStack;
152     private:
153         JSGlobalData(bool isShared, const VPtrSet&);
154         static JSGlobalData*& sharedInstanceInternal();
155         void createNativeThunk();
156     };
157 
158 } // namespace JSC
159 
160 #endif // JSGlobalData_h
161