source: webkit/trunk/JavaScriptCore/runtime/JSGlobalData.cpp@ 57829

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

https://bugs.webkit.org/show_bug.cgi?id=37745
Move string uniquing tables to (new) WTFThreadData class.

Reviewed by Sam Weinig.

Remove AtomicString's dependency on ThreadGlobalData so that we can move
WebCore's string classes up to WTF.

JavaScriptCore:

WTFThreadData.cpp/.h are based on ThreadGlobalData from WebCore.
Moved JSC & WebCore's string uniquing tables to this class.

This patch introduces a temporary layering violation in providing forward
declarations of classes from JSC and WTF; this will be resolved as we move
more string code up to WTF.

  • API/APIShims.h:

(JSC::APIEntryShimWithoutLock::APIEntryShimWithoutLock):
(JSC::APIEntryShimWithoutLock::~APIEntryShimWithoutLock):
(JSC::APICallbackShim::APICallbackShim):
(JSC::APICallbackShim::~APICallbackShim):

(JSC::checkSyntax):
(JSC::evaluate):

  • runtime/Identifier.cpp:

(JSC::Identifier::remove):
(JSC::Identifier::checkCurrentIdentifierTable):

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

(JSC::initializeThreadingOnce):

  • runtime/JSGlobalData.cpp:

(JSC::JSGlobalData::create):

  • wtf/WTFThreadData.cpp: Copied from WebCore/platform/ThreadGlobalData.cpp.

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

  • wtf/WTFThreadData.h: Copied from WebCore/platform/ThreadGlobalData.h.

(WTF::WTFThreadData::atomicStringTable):
(WTF::WTFThreadData::initializeIdentifierTable):
(WTF::WTFThreadData::currentIdentifierTable):
(WTF::WTFThreadData::setCurrentIdentifierTable):
(WTF::WTFThreadData::resetCurrentIdentifierTable):
(WTF::wtfThreadData):

JavaScriptGlue:

  • ForwardingHeaders/wtf/WTFThreadData.h: Added.
  • JSUtils.cpp: Update

(JSGlueAPIEntry::JSGlueAPIEntry):
(JSGlueAPIEntry::~JSGlueAPIEntry):
(JSGlueAPICallback::JSGlueAPICallback):
(JSGlueAPICallback::~JSGlueAPICallback):

WebCore:

  • ForwardingHeaders/wtf/WTFThreadData.h: Added.
  • platform/ThreadGlobalData.cpp: Remove m_atomicStringTable, all wtfThreadData() to ensure threadsafely initialized.

(WebCore::ThreadGlobalData::ThreadGlobalData):
(WebCore::ThreadGlobalData::~ThreadGlobalData):

  • platform/ThreadGlobalData.h: Remove m_atomicStringTable.

(WebCore::ThreadGlobalData::eventNames):

  • platform/text/AtomicString.cpp:

(WebCore::AtomicStringTable::create):
(WebCore::AtomicStringTable::table):
(WebCore::AtomicStringTable::destroy):
(WebCore::stringTable): Access the AtomicStringTable on wtfThreadData() rather then threadGlobalData().

  • Property svn:eol-style set to native
File size: 9.4 KB
Line 
1/*
2 * Copyright (C) 2008 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#include "config.h"
30#include "JSGlobalData.h"
31
32#include "ArgList.h"
33#include "Collector.h"
34#include "CommonIdentifiers.h"
35#include "FunctionConstructor.h"
36#include "GetterSetter.h"
37#include "Interpreter.h"
38#include "JSActivation.h"
39#include "JSAPIValueWrapper.h"
40#include "JSArray.h"
41#include "JSByteArray.h"
42#include "JSClassRef.h"
43#include "JSFunction.h"
44#include "JSLock.h"
45#include "JSNotAnObject.h"
46#include "JSPropertyNameIterator.h"
47#include "JSStaticScopeObject.h"
48#include "Lexer.h"
49#include "Lookup.h"
50#include "Nodes.h"
51#include "Parser.h"
52#include <wtf/WTFThreadData.h>
53
54#if ENABLE(JSC_MULTIPLE_THREADS)
55#include <wtf/Threading.h>
56#endif
57
58#if PLATFORM(MAC)
59#include "ProfilerServer.h"
60#endif
61
62using namespace WTF;
63
64namespace JSC {
65
66extern JSC_CONST_HASHTABLE HashTable arrayTable;
67extern JSC_CONST_HASHTABLE HashTable jsonTable;
68extern JSC_CONST_HASHTABLE HashTable dateTable;
69extern JSC_CONST_HASHTABLE HashTable mathTable;
70extern JSC_CONST_HASHTABLE HashTable numberTable;
71extern JSC_CONST_HASHTABLE HashTable regExpTable;
72extern JSC_CONST_HASHTABLE HashTable regExpConstructorTable;
73extern JSC_CONST_HASHTABLE HashTable stringTable;
74
75void* JSGlobalData::jsArrayVPtr;
76void* JSGlobalData::jsByteArrayVPtr;
77void* JSGlobalData::jsStringVPtr;
78void* JSGlobalData::jsFunctionVPtr;
79
80void JSGlobalData::storeVPtrs()
81{
82 CollectorCell cell;
83 void* storage = &cell;
84
85 COMPILE_ASSERT(sizeof(JSArray) <= sizeof(CollectorCell), sizeof_JSArray_must_be_less_than_CollectorCell);
86 JSCell* jsArray = new (storage) JSArray(JSArray::createStructure(jsNull()));
87 JSGlobalData::jsArrayVPtr = jsArray->vptr();
88 jsArray->~JSCell();
89
90 COMPILE_ASSERT(sizeof(JSByteArray) <= sizeof(CollectorCell), sizeof_JSByteArray_must_be_less_than_CollectorCell);
91 JSCell* jsByteArray = new (storage) JSByteArray(JSByteArray::VPtrStealingHack);
92 JSGlobalData::jsByteArrayVPtr = jsByteArray->vptr();
93 jsByteArray->~JSCell();
94
95 COMPILE_ASSERT(sizeof(JSString) <= sizeof(CollectorCell), sizeof_JSString_must_be_less_than_CollectorCell);
96 JSCell* jsString = new (storage) JSString(JSString::VPtrStealingHack);
97 JSGlobalData::jsStringVPtr = jsString->vptr();
98 jsString->~JSCell();
99
100 COMPILE_ASSERT(sizeof(JSFunction) <= sizeof(CollectorCell), sizeof_JSFunction_must_be_less_than_CollectorCell);
101 JSCell* jsFunction = new (storage) JSFunction(JSFunction::createStructure(jsNull()));
102 JSGlobalData::jsFunctionVPtr = jsFunction->vptr();
103 jsFunction->~JSCell();
104}
105
106JSGlobalData::JSGlobalData(bool isShared)
107 : isSharedInstance(isShared)
108 , clientData(0)
109 , arrayTable(fastNew<HashTable>(JSC::arrayTable))
110 , dateTable(fastNew<HashTable>(JSC::dateTable))
111 , jsonTable(fastNew<HashTable>(JSC::jsonTable))
112 , mathTable(fastNew<HashTable>(JSC::mathTable))
113 , numberTable(fastNew<HashTable>(JSC::numberTable))
114 , regExpTable(fastNew<HashTable>(JSC::regExpTable))
115 , regExpConstructorTable(fastNew<HashTable>(JSC::regExpConstructorTable))
116 , stringTable(fastNew<HashTable>(JSC::stringTable))
117 , activationStructure(JSActivation::createStructure(jsNull()))
118 , interruptedExecutionErrorStructure(JSObject::createStructure(jsNull()))
119 , terminatedExecutionErrorStructure(JSObject::createStructure(jsNull()))
120 , staticScopeStructure(JSStaticScopeObject::createStructure(jsNull()))
121 , stringStructure(JSString::createStructure(jsNull()))
122 , notAnObjectErrorStubStructure(JSNotAnObjectErrorStub::createStructure(jsNull()))
123 , notAnObjectStructure(JSNotAnObject::createStructure(jsNull()))
124 , propertyNameIteratorStructure(JSPropertyNameIterator::createStructure(jsNull()))
125 , getterSetterStructure(GetterSetter::createStructure(jsNull()))
126 , apiWrapperStructure(JSAPIValueWrapper::createStructure(jsNull()))
127 , dummyMarkableCellStructure(JSCell::createDummyStructure())
128#if USE(JSVALUE32)
129 , numberStructure(JSNumberCell::createStructure(jsNull()))
130#endif
131 , identifierTable(createIdentifierTable())
132 , propertyNames(new CommonIdentifiers(this))
133 , emptyList(new MarkedArgumentBuffer)
134 , lexer(new Lexer(this))
135 , parser(new Parser)
136 , interpreter(new Interpreter)
137#if ENABLE(JIT)
138 , jitStubs(this)
139#endif
140 , heap(this)
141 , initializingLazyNumericCompareFunction(false)
142 , head(0)
143 , dynamicGlobalObject(0)
144 , functionCodeBlockBeingReparsed(0)
145 , firstStringifierToMark(0)
146 , markStack(jsArrayVPtr)
147 , cachedUTCOffset(NaN)
148 , weakRandom(static_cast<int>(currentTime()))
149#ifndef NDEBUG
150 , mainThreadOnly(false)
151#endif
152{
153#if PLATFORM(MAC)
154 startProfilerServerIfNeeded();
155#endif
156}
157
158JSGlobalData::~JSGlobalData()
159{
160 // By the time this is destroyed, heap.destroy() must already have been called.
161
162 delete interpreter;
163#ifndef NDEBUG
164 // Zeroing out to make the behavior more predictable when someone attempts to use a deleted instance.
165 interpreter = 0;
166#endif
167
168 arrayTable->deleteTable();
169 dateTable->deleteTable();
170 jsonTable->deleteTable();
171 mathTable->deleteTable();
172 numberTable->deleteTable();
173 regExpTable->deleteTable();
174 regExpConstructorTable->deleteTable();
175 stringTable->deleteTable();
176
177 fastDelete(const_cast<HashTable*>(arrayTable));
178 fastDelete(const_cast<HashTable*>(dateTable));
179 fastDelete(const_cast<HashTable*>(jsonTable));
180 fastDelete(const_cast<HashTable*>(mathTable));
181 fastDelete(const_cast<HashTable*>(numberTable));
182 fastDelete(const_cast<HashTable*>(regExpTable));
183 fastDelete(const_cast<HashTable*>(regExpConstructorTable));
184 fastDelete(const_cast<HashTable*>(stringTable));
185
186 delete parser;
187 delete lexer;
188
189 deleteAllValues(opaqueJSClassData);
190
191 delete emptyList;
192
193 delete propertyNames;
194 deleteIdentifierTable(identifierTable);
195
196 delete clientData;
197}
198
199PassRefPtr<JSGlobalData> JSGlobalData::createNonDefault()
200{
201 return adoptRef(new JSGlobalData(false));
202}
203
204PassRefPtr<JSGlobalData> JSGlobalData::create()
205{
206 JSGlobalData* globalData = new JSGlobalData(false);
207 wtfThreadData().initializeIdentifierTable(globalData->identifierTable);
208 return adoptRef(globalData);
209}
210
211PassRefPtr<JSGlobalData> JSGlobalData::createLeaked()
212{
213 Structure::startIgnoringLeaks();
214 RefPtr<JSGlobalData> data = create();
215 Structure::stopIgnoringLeaks();
216 return data.release();
217}
218
219bool JSGlobalData::sharedInstanceExists()
220{
221 return sharedInstanceInternal();
222}
223
224JSGlobalData& JSGlobalData::sharedInstance()
225{
226 JSGlobalData*& instance = sharedInstanceInternal();
227 if (!instance) {
228 instance = new JSGlobalData(true);
229#if ENABLE(JSC_MULTIPLE_THREADS)
230 instance->makeUsableFromMultipleThreads();
231#endif
232 }
233 return *instance;
234}
235
236JSGlobalData*& JSGlobalData::sharedInstanceInternal()
237{
238 ASSERT(JSLock::currentThreadIsHoldingLock());
239 static JSGlobalData* sharedInstance;
240 return sharedInstance;
241}
242
243// FIXME: We can also detect forms like v1 < v2 ? -1 : 0, reverse comparison, etc.
244const Vector<Instruction>& JSGlobalData::numericCompareFunction(ExecState* exec)
245{
246 if (!lazyNumericCompareFunction.size() && !initializingLazyNumericCompareFunction) {
247 initializingLazyNumericCompareFunction = true;
248 RefPtr<FunctionExecutable> function = FunctionExecutable::fromGlobalCode(Identifier(exec, "numericCompare"), exec, 0, makeSource(UString("(function (v1, v2) { return v1 - v2; })")), 0, 0);
249 lazyNumericCompareFunction = function->bytecode(exec, exec->scopeChain()).instructions();
250 initializingLazyNumericCompareFunction = false;
251 }
252
253 return lazyNumericCompareFunction;
254}
255
256JSGlobalData::ClientData::~ClientData()
257{
258}
259
260void JSGlobalData::resetDateCache()
261{
262 cachedUTCOffset = NaN;
263 dstOffsetCache.reset();
264 cachedDateString = UString();
265 dateInstanceCache.reset();
266}
267
268void JSGlobalData::startSampling()
269{
270 interpreter->startSampling();
271}
272
273void JSGlobalData::stopSampling()
274{
275 interpreter->stopSampling();
276}
277
278void JSGlobalData::dumpSampleData(ExecState* exec)
279{
280 interpreter->dumpSampleData(exec);
281}
282
283} // namespace JSC
Note: See TracBrowser for help on using the repository browser.