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

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

No, silly runtime, AST nodes are not for you.

Reviewed by Sam Weinig.

We still use AST nodes (ScopeNodes, particularly FunctionBodyNodes) within
the runtime, which means that these nodes must be persisted outside of the
arena, contain both parser & runtime data, etc. This is all a bit of a mess.

Move functionality into a new FunctionExecutable class.

(JSC::CodeBlock::CodeBlock):
(JSC::CodeBlock::markAggregate):
(JSC::CodeBlock::reparseForExceptionInfoIfNecessary):
(JSC::CodeBlock::lineNumberForBytecodeOffset):
(JSC::CodeBlock::shrinkToFit):

  • bytecode/CodeBlock.h:

(JSC::CodeBlock::getBytecodeIndex):
(JSC::CodeBlock::discardBytecode):
(JSC::CodeBlock::instructionCount):
(JSC::CodeBlock::getJITCode):
(JSC::CodeBlock::executablePool):
(JSC::CodeBlock::ownerExecutable):
(JSC::CodeBlock::extractExceptionInfo):
(JSC::CodeBlock::addFunctionDecl):
(JSC::CodeBlock::functionDecl):
(JSC::CodeBlock::numberOfFunctionDecls):
(JSC::CodeBlock::addFunctionExpr):
(JSC::CodeBlock::functionExpr):
(JSC::GlobalCodeBlock::GlobalCodeBlock):
(JSC::ProgramCodeBlock::ProgramCodeBlock):
(JSC::EvalCodeBlock::EvalCodeBlock):
(JSC::FunctionCodeBlock::FunctionCodeBlock):
(JSC::NativeCodeBlock::NativeCodeBlock):

  • bytecode/EvalCodeCache.h:
  • bytecode/SamplingTool.cpp:

(JSC::SamplingTool::doRun):

  • bytecompiler/BytecodeGenerator.cpp:

(JSC::BytecodeGenerator::BytecodeGenerator):
(JSC::BytecodeGenerator::emitNewFunction):
(JSC::BytecodeGenerator::emitNewFunctionExpression):

  • bytecompiler/BytecodeGenerator.h:
  • debugger/Debugger.cpp:

(JSC::Debugger::recompileAllJSFunctions):

  • interpreter/CachedCall.h:

(JSC::CachedCall::CachedCall):

  • interpreter/CallFrameClosure.h:
  • interpreter/Interpreter.cpp:

(JSC::Interpreter::unwindCallFrame):
(JSC::Interpreter::throwException):
(JSC::Interpreter::execute):
(JSC::Interpreter::prepareForRepeatCall):
(JSC::Interpreter::debug):
(JSC::Interpreter::privateExecute):
(JSC::Interpreter::retrieveLastCaller):

  • interpreter/Interpreter.h:
  • jit/JIT.cpp:

(JSC::JIT::privateCompile):

  • jit/JIT.h:

(JSC::JIT::compile):

  • jit/JITOpcodes.cpp:

(JSC::JIT::privateCompileCTIMachineTrampolines):
(JSC::JIT::emit_op_new_func):
(JSC::JIT::emit_op_new_func_exp):

  • jit/JITStubs.cpp:

(JSC::DEFINE_STUB_FUNCTION):

  • jit/JITStubs.h:

(JSC::):

  • parser/Nodes.cpp:

(JSC::FunctionBodyNode::reparseDataIfNecessary):

  • parser/Nodes.h:

(JSC::EvalNode::partialDestroyData):

  • parser/Parser.h:
  • profiler/ProfileGenerator.cpp:
  • profiler/Profiler.cpp:

(JSC::Profiler::createCallIdentifier):
(JSC::createCallIdentifierFromFunctionImp):

  • runtime/Arguments.h:

(JSC::Arguments::getArgumentsData):
(JSC::Arguments::Arguments):
(JSC::JSActivation::copyRegisters):

  • runtime/ArrayPrototype.cpp:

(JSC::isNumericCompareFunction):

  • runtime/CallData.h:

(JSC::):

  • runtime/Collector.cpp:

(JSC::Heap::collect):

  • runtime/ConstructData.h:

(JSC::):

  • runtime/ExceptionHelpers.cpp:

(JSC::createUndefinedVariableError):
(JSC::createInvalidParamError):
(JSC::createNotAConstructorError):
(JSC::createNotAFunctionError):
(JSC::createNotAnObjectError):

  • runtime/Executable.cpp: Added.

(JSC::EvalExecutable::generateBytecode):
(JSC::ProgramExecutable::generateBytecode):
(JSC::FunctionExecutable::generateBytecode):
(JSC::EvalExecutable::generateJITCode):
(JSC::ProgramExecutable::generateJITCode):
(JSC::FunctionExecutable::generateJITCode):
(JSC::FunctionExecutable::isHostFunction):
(JSC::FunctionExecutable::markAggregate):
(JSC::FunctionExecutable::reparseExceptionInfo):
(JSC::EvalExecutable::reparseExceptionInfo):
(JSC::FunctionExecutable::recompile):
(JSC::FunctionExecutable::FunctionExecutable):

  • runtime/Executable.h:

(JSC::ExecutableBase::~ExecutableBase):
(JSC::ExecutableBase::ExecutableBase):
(JSC::ExecutableBase::source):
(JSC::ExecutableBase::sourceID):
(JSC::ExecutableBase::lastLine):
(JSC::ExecutableBase::usesEval):
(JSC::ExecutableBase::usesArguments):
(JSC::ExecutableBase::needsActivation):
(JSC::ExecutableBase::astNode):
(JSC::ExecutableBase::generatedJITCode):
(JSC::ExecutableBase::getExecutablePool):
(JSC::EvalExecutable::EvalExecutable):
(JSC::EvalExecutable::bytecode):
(JSC::EvalExecutable::varStack):
(JSC::EvalExecutable::evalNode):
(JSC::EvalExecutable::jitCode):
(JSC::ProgramExecutable::ProgramExecutable):
(JSC::ProgramExecutable::reparseExceptionInfo):
(JSC::ProgramExecutable::bytecode):
(JSC::ProgramExecutable::programNode):
(JSC::ProgramExecutable::jitCode):
(JSC::FunctionExecutable::FunctionExecutable):
(JSC::FunctionExecutable::name):
(JSC::FunctionExecutable::bytecode):
(JSC::FunctionExecutable::generatedBytecode):
(JSC::FunctionExecutable::usesEval):
(JSC::FunctionExecutable::usesArguments):
(JSC::FunctionExecutable::parameterCount):
(JSC::FunctionExecutable::paramString):
(JSC::FunctionExecutable::isGenerated):
(JSC::FunctionExecutable::body):
(JSC::FunctionExecutable::jitCode):
(JSC::FunctionExecutable::createNativeThunk):

  • runtime/FunctionConstructor.cpp:

(JSC::constructFunction):

  • runtime/FunctionPrototype.cpp:

(JSC::functionProtoFuncToString):

  • runtime/JSActivation.cpp:

(JSC::JSActivation::JSActivation):
(JSC::JSActivation::markChildren):
(JSC::JSActivation::isDynamicScope):
(JSC::JSActivation::argumentsGetter):

  • runtime/JSActivation.h:

(JSC::JSActivation::JSActivationData::JSActivationData):

  • runtime/JSFunction.cpp:

(JSC::JSFunction::isHostFunction):
(JSC::JSFunction::JSFunction):
(JSC::JSFunction::~JSFunction):
(JSC::JSFunction::markChildren):
(JSC::JSFunction::getCallData):
(JSC::JSFunction::call):
(JSC::JSFunction::lengthGetter):
(JSC::JSFunction::getConstructData):
(JSC::JSFunction::construct):

  • runtime/JSFunction.h:

(JSC::JSFunction::executable):
(JSC::FunctionExecutable::make):

  • runtime/JSGlobalData.cpp:

(JSC::JSGlobalData::JSGlobalData):
(JSC::JSGlobalData::numericCompareFunction):

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