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

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

Fix the interpreter after r59637
https://bugs.webkit.org/show_bug.cgi?id=39287

Reviewed by Darin Adler.

  • runtime/Executable.h:
  • runtime/JSFunction.cpp:

(JSC::JSFunction::JSFunction):
(JSC::JSFunction::getCallData):

  • runtime/JSGlobalData.cpp:
  • runtime/JSGlobalData.h:
  • Property svn:eol-style set to native
File size: 10.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(GlobalDataType globalDataType, ThreadStackType threadStackType)
107 : globalDataType(globalDataType)
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(globalDataType == Default ? wtfThreadData().currentIdentifierTable() : 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 , maxReentryDepth(threadStackType == ThreadStackTypeSmall ? MaxSmallThreadReentryDepth : MaxLargeThreadReentryDepth)
150#ifndef NDEBUG
151 , exclusiveThread(0)
152#endif
153{
154#if PLATFORM(MAC)
155 startProfilerServerIfNeeded();
156#endif
157}
158
159JSGlobalData::~JSGlobalData()
160{
161 // By the time this is destroyed, heap.destroy() must already have been called.
162
163 delete interpreter;
164#ifndef NDEBUG
165 // Zeroing out to make the behavior more predictable when someone attempts to use a deleted instance.
166 interpreter = 0;
167#endif
168
169 arrayTable->deleteTable();
170 dateTable->deleteTable();
171 jsonTable->deleteTable();
172 mathTable->deleteTable();
173 numberTable->deleteTable();
174 regExpTable->deleteTable();
175 regExpConstructorTable->deleteTable();
176 stringTable->deleteTable();
177
178 fastDelete(const_cast<HashTable*>(arrayTable));
179 fastDelete(const_cast<HashTable*>(dateTable));
180 fastDelete(const_cast<HashTable*>(jsonTable));
181 fastDelete(const_cast<HashTable*>(mathTable));
182 fastDelete(const_cast<HashTable*>(numberTable));
183 fastDelete(const_cast<HashTable*>(regExpTable));
184 fastDelete(const_cast<HashTable*>(regExpConstructorTable));
185 fastDelete(const_cast<HashTable*>(stringTable));
186
187 delete parser;
188 delete lexer;
189
190 deleteAllValues(opaqueJSClassData);
191
192 delete emptyList;
193
194 delete propertyNames;
195 if (globalDataType != Default)
196 deleteIdentifierTable(identifierTable);
197
198 delete clientData;
199}
200
201PassRefPtr<JSGlobalData> JSGlobalData::createContextGroup(ThreadStackType type)
202{
203 return adoptRef(new JSGlobalData(APIContextGroup, type));
204}
205
206PassRefPtr<JSGlobalData> JSGlobalData::create(ThreadStackType type)
207{
208 return adoptRef(new JSGlobalData(Default, type));
209}
210
211PassRefPtr<JSGlobalData> JSGlobalData::createLeaked(ThreadStackType type)
212{
213 Structure::startIgnoringLeaks();
214 RefPtr<JSGlobalData> data = create(type);
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(APIShared, ThreadStackTypeSmall);
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->bytecodeForCall(exec, exec->scopeChain()).instructions();
250 initializingLazyNumericCompareFunction = false;
251 }
252
253 return lazyNumericCompareFunction;
254}
255
256#if ENABLE(JIT)
257PassRefPtr<NativeExecutable> JSGlobalData::getNativeExecutable(NativeFunction function)
258{
259 std::pair<NativeExecutableMap::iterator, bool> entry = m_nativeExecutableMap.add(function, 0);
260 if (entry.second)
261 entry.first->second = NativeExecutable::create(jitStubs.ctiNativeCall(), function);
262 return entry.first->second;
263}
264
265PassRefPtr<NativeExecutable> JSGlobalData::getNativeExecutable(NativeFunction function, ThunkGenerator generator)
266{
267 std::pair<NativeExecutableMap::iterator, bool> entry = m_nativeExecutableMap.add(function, 0);
268 if (entry.second)
269 entry.first->second = NativeExecutable::create(getThunk(generator), function);
270 return entry.first->second;
271}
272#endif
273
274JSGlobalData::ClientData::~ClientData()
275{
276}
277
278void JSGlobalData::resetDateCache()
279{
280 cachedUTCOffset = NaN;
281 dstOffsetCache.reset();
282 cachedDateString = UString();
283 dateInstanceCache.reset();
284}
285
286void JSGlobalData::startSampling()
287{
288 interpreter->startSampling();
289}
290
291void JSGlobalData::stopSampling()
292{
293 interpreter->stopSampling();
294}
295
296void JSGlobalData::dumpSampleData(ExecState* exec)
297{
298 interpreter->dumpSampleData(exec);
299}
300
301} // namespace JSC
Note: See TracBrowser for help on using the repository browser.