source: webkit/trunk/JavaScriptCore/runtime/JSGlobalData.h@ 58114

Last change on this file since 58114 was 58114, checked in by [email protected], 15 years ago

https://bugs.webkit.org/show_bug.cgi?id=37978
Unify JSC::IdentifierTable and WebCore::AtomicStringTable implementations.

Reviewed by Geoff Garen.

These two classes both implement a HashSet of uniqued StringImpls, with
translator classes to avoid unnecessary object creation. The only difference
between the classes is which flag (isIdentifier or inTable) is set.
Combine the two classes using a template predicated on which flag to use.

New class AtomicStringTable created, containing all the goodness from
IdentifierTable & AtomicStringTable, expect for Identifier's literalTable,
which has been moved onto JSGlobalData. Removed duplicate string translator
classes. Renamed StringImpl's inTable flag to more explicit 'isAtomic',
and set this on the empty string (which matches Identifier behaviour, and
removes a redundant check for zero-length).

(JSC::createLiteralTable):
(JSC::deleteLiteralTable):
(JSC::Identifier::add):
(JSC::Identifier::addSlowCase):

  • runtime/Identifier.h:
  • runtime/JSGlobalData.cpp:

(JSC::JSGlobalData::JSGlobalData):
(JSC::JSGlobalData::~JSGlobalData):

  • runtime/JSGlobalData.h:
  • wtf/WTFThreadData.cpp:

(WTF::WTFThreadData::WTFThreadData):
(WTF::WTFThreadData::~WTFThreadData):

  • wtf/WTFThreadData.h:

(WTF::WTFThreadData::atomicStringTable):

  • wtf/text/AtomicString.cpp:

(WebCore::table):
(WebCore::operator==):
(WebCore::AtomicString::add):
(WebCore::AtomicString::find):
(WebCore::AtomicString::remove):

  • wtf/text/AtomicStringTable.h: Added.

(WTF::CStringTranslator::hash):
(WTF::CStringTranslator::equal):
(WTF::CStringTranslator::translate):
(WTF::UCharBufferTranslator::hash):
(WTF::UCharBufferTranslator::equal):
(WTF::UCharBufferTranslator::translate):
(WTF::HashAndCharactersTranslator::hash):
(WTF::HashAndCharactersTranslator::equal):
(WTF::HashAndCharactersTranslator::translate):
(WTF::IdentifierOrAtomicStringTable::remove):
(WTF::::~IdentifierOrAtomicStringTable):
(WTF::::add):
(WTF::::find):

  • wtf/text/StringImpl.cpp:

(WebCore::StringImpl::~StringImpl):

  • wtf/text/StringImpl.h:

(WebCore::StringImpl::isAtomic):
(WebCore::StringImpl::setIsAtomic):
(WebCore::equal):

  • wtf/text/StringImplBase.h:

(WTF::StringImplBase::StringImplBase):

  • Property svn:eol-style set to native
File size: 6.6 KB
Line 
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
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 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 struct ClientData {
96 virtual ~ClientData() = 0;
97 };
98
99 static bool sharedInstanceExists();
100 static JSGlobalData& sharedInstance();
101
102 static PassRefPtr<JSGlobalData> create(ThreadStackType);
103 static PassRefPtr<JSGlobalData> createLeaked(ThreadStackType);
104 static PassRefPtr<JSGlobalData> createNonDefault(ThreadStackType);
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> terminatedExecutionErrorStructure;
127 RefPtr<Structure> staticScopeStructure;
128 RefPtr<Structure> stringStructure;
129 RefPtr<Structure> notAnObjectErrorStubStructure;
130 RefPtr<Structure> notAnObjectStructure;
131 RefPtr<Structure> propertyNameIteratorStructure;
132 RefPtr<Structure> getterSetterStructure;
133 RefPtr<Structure> apiWrapperStructure;
134 RefPtr<Structure> dummyMarkableCellStructure;
135
136#if USE(JSVALUE32)
137 RefPtr<Structure> numberStructure;
138#endif
139
140 static void storeVPtrs();
141 static JS_EXPORTDATA void* jsArrayVPtr;
142 static JS_EXPORTDATA void* jsByteArrayVPtr;
143 static JS_EXPORTDATA void* jsStringVPtr;
144 static JS_EXPORTDATA void* jsFunctionVPtr;
145
146 IdentifierTable* identifierTable;
147 LiteralTable* literalTable;
148 CommonIdentifiers* propertyNames;
149 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.
150 SmallStrings smallStrings;
151 NumericStrings numericStrings;
152 DateInstanceCache dateInstanceCache;
153
154#if ENABLE(ASSEMBLER)
155 ExecutableAllocator executableAllocator;
156#endif
157
158 Lexer* lexer;
159 Parser* parser;
160 Interpreter* interpreter;
161#if ENABLE(JIT)
162 JITThunks jitStubs;
163#endif
164 TimeoutChecker timeoutChecker;
165 Terminator terminator;
166 Heap heap;
167
168 JSValue exception;
169#if ENABLE(JIT)
170 ReturnAddressPtr exceptionLocation;
171#endif
172
173 const Vector<Instruction>& numericCompareFunction(ExecState*);
174 Vector<Instruction> lazyNumericCompareFunction;
175 bool initializingLazyNumericCompareFunction;
176
177 HashMap<OpaqueJSClass*, OpaqueJSClassContextData*> opaqueJSClassData;
178
179 JSGlobalObject* head;
180 JSGlobalObject* dynamicGlobalObject;
181
182 HashSet<JSObject*> arrayVisitedElements;
183
184 CodeBlock* functionCodeBlockBeingReparsed;
185 Stringifier* firstStringifierToMark;
186
187 MarkStack markStack;
188
189 double cachedUTCOffset;
190 DSTOffsetCache dstOffsetCache;
191
192 UString cachedDateString;
193 double cachedDateStringValue;
194
195 WeakRandom weakRandom;
196
197 int maxReentryDepth;
198#ifndef NDEBUG
199 ThreadIdentifier exclusiveThread;
200#endif
201
202 void resetDateCache();
203
204 void startSampling();
205 void stopSampling();
206 void dumpSampleData(ExecState* exec);
207 private:
208 JSGlobalData(bool isShared, ThreadStackType);
209 static JSGlobalData*& sharedInstanceInternal();
210 void createNativeThunk();
211 };
212
213} // namespace JSC
214
215#endif // JSGlobalData_h
Note: See TracBrowser for help on using the repository browser.