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

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

2009-02-23 Geoffrey Garen <[email protected]>

Reviewed by Sam Weinig.

Next step in splitting JIT functionality out of the Interpreter class:
Moved vptr storage from Interpreter to JSGlobalData, so it could be shared
between Interpreter and JITStubs, and moved the *Trampoline JIT stubs
into the JITStubs class. Also added a VPtrSet class to encapsulate vptr
hacks during JSGlobalData initialization.


SunSpider says 0.4% faster. Meh.

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