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

Last change on this file since 43383 was 43382, checked in by [email protected], 16 years ago

2009-05-07 Geoffrey Garen <[email protected]>

Reviewed by Cameron Zwarich.


Fixed a minor sequencing error introduced by recent Parser speedups.

  • runtime/JSGlobalData.cpp: (JSC::JSGlobalData::createNativeThunk): Missed a spot in my last patch.
  • Property svn:eol-style set to native
File size: 7.8 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 "Interpreter.h"
37#include "JSActivation.h"
38#include "JSArray.h"
39#include "JSByteArray.h"
40#include "JSClassRef.h"
41#include "JSFunction.h"
42#include "JSLock.h"
43#include "JSNotAnObject.h"
44#include "JSStaticScopeObject.h"
45#include "Parser.h"
46#include "Lexer.h"
47#include "Lookup.h"
48#include "Nodes.h"
49
50#if ENABLE(JSC_MULTIPLE_THREADS)
51#include <wtf/Threading.h>
52#endif
53
54#if PLATFORM(MAC)
55#include "ProfilerServer.h"
56#endif
57
58using namespace WTF;
59
60namespace JSC {
61
62extern const HashTable arrayTable;
63extern const HashTable dateTable;
64extern const HashTable mathTable;
65extern const HashTable numberTable;
66extern const HashTable regExpTable;
67extern const HashTable regExpConstructorTable;
68extern const HashTable stringTable;
69
70struct VPtrSet {
71 VPtrSet();
72
73 void* jsArrayVPtr;
74 void* jsByteArrayVPtr;
75 void* jsStringVPtr;
76 void* jsFunctionVPtr;
77};
78
79VPtrSet::VPtrSet()
80{
81 // Bizarrely, calling fastMalloc here is faster than allocating space on the stack.
82 void* storage = fastMalloc(sizeof(CollectorBlock));
83
84 JSCell* jsArray = new (storage) JSArray(JSArray::createStructure(jsNull()));
85 jsArrayVPtr = jsArray->vptr();
86 jsArray->~JSCell();
87
88 JSCell* jsByteArray = new (storage) JSByteArray(JSByteArray::VPtrStealingHack);
89 jsByteArrayVPtr = jsByteArray->vptr();
90 jsByteArray->~JSCell();
91
92 JSCell* jsString = new (storage) JSString(JSString::VPtrStealingHack);
93 jsStringVPtr = jsString->vptr();
94 jsString->~JSCell();
95
96 JSCell* jsFunction = new (storage) JSFunction(JSFunction::createStructure(jsNull()));
97 jsFunctionVPtr = jsFunction->vptr();
98 jsFunction->~JSCell();
99
100 fastFree(storage);
101}
102
103JSGlobalData::JSGlobalData(bool isShared, const VPtrSet& vptrSet)
104 : isSharedInstance(isShared)
105 , clientData(0)
106 , arrayTable(new HashTable(JSC::arrayTable))
107 , dateTable(new HashTable(JSC::dateTable))
108 , mathTable(new HashTable(JSC::mathTable))
109 , numberTable(new HashTable(JSC::numberTable))
110 , regExpTable(new HashTable(JSC::regExpTable))
111 , regExpConstructorTable(new HashTable(JSC::regExpConstructorTable))
112 , stringTable(new HashTable(JSC::stringTable))
113 , activationStructure(JSActivation::createStructure(jsNull()))
114 , interruptedExecutionErrorStructure(JSObject::createStructure(jsNull()))
115 , staticScopeStructure(JSStaticScopeObject::createStructure(jsNull()))
116 , stringStructure(JSString::createStructure(jsNull()))
117 , notAnObjectErrorStubStructure(JSNotAnObjectErrorStub::createStructure(jsNull()))
118 , notAnObjectStructure(JSNotAnObject::createStructure(jsNull()))
119#if !USE(ALTERNATE_JSIMMEDIATE)
120 , numberStructure(JSNumberCell::createStructure(jsNull()))
121#endif
122 , jsArrayVPtr(vptrSet.jsArrayVPtr)
123 , jsByteArrayVPtr(vptrSet.jsByteArrayVPtr)
124 , jsStringVPtr(vptrSet.jsStringVPtr)
125 , jsFunctionVPtr(vptrSet.jsFunctionVPtr)
126 , identifierTable(createIdentifierTable())
127 , propertyNames(new CommonIdentifiers(this))
128 , emptyList(new MarkedArgumentBuffer)
129 , lexer(new Lexer(this))
130 , parser(new Parser)
131 , interpreter(new Interpreter)
132#if ENABLE(JIT)
133 , jitStubs(this)
134#endif
135 , heap(this)
136 , initializingLazyNumericCompareFunction(false)
137 , head(0)
138 , dynamicGlobalObject(0)
139 , scopeNodeBeingReparsed(0)
140{
141#if PLATFORM(MAC)
142 startProfilerServerIfNeeded();
143#endif
144}
145
146JSGlobalData::~JSGlobalData()
147{
148 // By the time this is destroyed, heap.destroy() must already have been called.
149
150 delete interpreter;
151#ifndef NDEBUG
152 // Zeroing out to make the behavior more predictable when someone attempts to use a deleted instance.
153 interpreter = 0;
154#endif
155
156 arrayTable->deleteTable();
157 dateTable->deleteTable();
158 mathTable->deleteTable();
159 numberTable->deleteTable();
160 regExpTable->deleteTable();
161 regExpConstructorTable->deleteTable();
162 stringTable->deleteTable();
163#if ENABLE(JIT)
164 lazyNativeFunctionThunk.clear();
165#endif
166
167 delete arrayTable;
168 delete dateTable;
169 delete mathTable;
170 delete numberTable;
171 delete regExpTable;
172 delete regExpConstructorTable;
173 delete stringTable;
174
175 delete parser;
176 delete lexer;
177
178 deleteAllValues(opaqueJSClassData);
179
180 delete emptyList;
181
182 delete propertyNames;
183 deleteIdentifierTable(identifierTable);
184
185 delete clientData;
186
187 ASSERT(parserObjects.isEmpty());
188}
189
190PassRefPtr<JSGlobalData> JSGlobalData::create(bool isShared)
191{
192 return adoptRef(new JSGlobalData(isShared, VPtrSet()));
193}
194
195PassRefPtr<JSGlobalData> JSGlobalData::createLeaked()
196{
197#ifndef NDEBUG
198 Structure::startIgnoringLeaks();
199 RefPtr<JSGlobalData> data = create();
200 Structure::stopIgnoringLeaks();
201 return data.release();
202#else
203 return create();
204#endif
205}
206
207bool JSGlobalData::sharedInstanceExists()
208{
209 return sharedInstanceInternal();
210}
211
212JSGlobalData& JSGlobalData::sharedInstance()
213{
214 JSGlobalData*& instance = sharedInstanceInternal();
215 if (!instance) {
216 instance = create(true).releaseRef();
217#if ENABLE(JSC_MULTIPLE_THREADS)
218 instance->makeUsableFromMultipleThreads();
219#endif
220 }
221 return *instance;
222}
223
224JSGlobalData*& JSGlobalData::sharedInstanceInternal()
225{
226 ASSERT(JSLock::currentThreadIsHoldingLock());
227 static JSGlobalData* sharedInstance;
228 return sharedInstance;
229}
230
231void JSGlobalData::createNativeThunk()
232{
233#if ENABLE(JIT)
234 lazyNativeFunctionThunk = FunctionBodyNode::createNativeThunk(this);
235 parserObjects.shrink(0);
236#endif
237}
238
239// FIXME: We can also detect forms like v1 < v2 ? -1 : 0, reverse comparison, etc.
240const Vector<Instruction>& JSGlobalData::numericCompareFunction(ExecState* exec)
241{
242 if (!lazyNumericCompareFunction.size() && !initializingLazyNumericCompareFunction) {
243 initializingLazyNumericCompareFunction = true;
244 RefPtr<ProgramNode> programNode = parser->parse<ProgramNode>(exec, 0, makeSource(UString("(function (v1, v2) { return v1 - v2; })")), 0, 0);
245 RefPtr<FunctionBodyNode> functionBody = extractFunctionBody(programNode.get());
246 lazyNumericCompareFunction = functionBody->bytecode(exec->scopeChain()).instructions();
247 initializingLazyNumericCompareFunction = false;
248 }
249
250 return lazyNumericCompareFunction;
251}
252
253JSGlobalData::ClientData::~ClientData()
254{
255}
256
257
258} // namespace JSC
Note: See TracBrowser for help on using the repository browser.