source: webkit/trunk/JavaScriptCore/interpreter/Interpreter.h@ 48662

Last change on this file since 48662 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:
File size: 6.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#ifndef Interpreter_h
30#define Interpreter_h
31
32#include "ArgList.h"
33#include "FastAllocBase.h"
34#include "JSCell.h"
35#include "JSValue.h"
36#include "JSObject.h"
37#include "Opcode.h"
38#include "RegisterFile.h"
39
40#include <wtf/HashMap.h>
41
42namespace JSC {
43
44 class CodeBlock;
45 class EvalExecutable;
46 class FunctionExecutable;
47 class InternalFunction;
48 class JSFunction;
49 class JSGlobalObject;
50 class ProgramExecutable;
51 class Register;
52 class ScopeChainNode;
53 class SamplingTool;
54 struct CallFrameClosure;
55 struct HandlerInfo;
56 struct Instruction;
57
58 enum DebugHookID {
59 WillExecuteProgram,
60 DidExecuteProgram,
61 DidEnterCallFrame,
62 DidReachBreakpoint,
63 WillLeaveCallFrame,
64 WillExecuteStatement
65 };
66
67 enum { MaxMainThreadReentryDepth = 256, MaxSecondaryThreadReentryDepth = 32 };
68
69 class Interpreter : public FastAllocBase {
70 friend class JIT;
71 friend class CachedCall;
72 public:
73 Interpreter();
74
75 RegisterFile& registerFile() { return m_registerFile; }
76
77 Opcode getOpcode(OpcodeID id)
78 {
79 #if HAVE(COMPUTED_GOTO)
80 return m_opcodeTable[id];
81 #else
82 return id;
83 #endif
84 }
85
86 OpcodeID getOpcodeID(Opcode opcode)
87 {
88 #if HAVE(COMPUTED_GOTO)
89 ASSERT(isOpcode(opcode));
90 return m_opcodeIDTable.get(opcode);
91 #else
92 return opcode;
93 #endif
94 }
95
96 bool isOpcode(Opcode);
97
98 JSValue execute(ProgramExecutable*, CallFrame*, ScopeChainNode*, JSObject* thisObj, JSValue* exception);
99 JSValue execute(FunctionExecutable*, CallFrame*, JSFunction*, JSObject* thisObj, const ArgList& args, ScopeChainNode*, JSValue* exception);
100 JSValue execute(EvalExecutable* evalNode, CallFrame* exec, JSObject* thisObj, ScopeChainNode* scopeChain, JSValue* exception);
101
102 JSValue retrieveArguments(CallFrame*, JSFunction*) const;
103 JSValue retrieveCaller(CallFrame*, InternalFunction*) const;
104 void retrieveLastCaller(CallFrame*, int& lineNumber, intptr_t& sourceID, UString& sourceURL, JSValue& function) const;
105
106 void getArgumentsData(CallFrame*, JSFunction*&, ptrdiff_t& firstParameterIndex, Register*& argv, int& argc);
107
108 void setSampler(SamplingTool* sampler) { m_sampler = sampler; }
109 SamplingTool* sampler() { return m_sampler; }
110
111 NEVER_INLINE JSValue callEval(CallFrame*, RegisterFile*, Register* argv, int argc, int registerOffset, JSValue& exceptionValue);
112 NEVER_INLINE HandlerInfo* throwException(CallFrame*&, JSValue&, unsigned bytecodeOffset, bool);
113 NEVER_INLINE void debug(CallFrame*, DebugHookID, int firstLine, int lastLine);
114
115 private:
116 enum ExecutionFlag { Normal, InitializeAndReturn };
117
118 CallFrameClosure prepareForRepeatCall(FunctionExecutable*, CallFrame*, JSFunction*, int argCount, ScopeChainNode*, JSValue* exception);
119 void endRepeatCall(CallFrameClosure&);
120 JSValue execute(CallFrameClosure&, JSValue* exception);
121
122 JSValue execute(EvalExecutable*, CallFrame*, JSObject* thisObject, int globalRegisterOffset, ScopeChainNode*, JSValue* exception);
123
124#if USE(INTERPRETER)
125 NEVER_INLINE bool resolve(CallFrame*, Instruction*, JSValue& exceptionValue);
126 NEVER_INLINE bool resolveSkip(CallFrame*, Instruction*, JSValue& exceptionValue);
127 NEVER_INLINE bool resolveGlobal(CallFrame*, Instruction*, JSValue& exceptionValue);
128 NEVER_INLINE void resolveBase(CallFrame*, Instruction* vPC);
129 NEVER_INLINE bool resolveBaseAndProperty(CallFrame*, Instruction*, JSValue& exceptionValue);
130 NEVER_INLINE bool resolveBaseAndFunc(CallFrame*, Instruction*, JSValue& exceptionValue);
131 NEVER_INLINE ScopeChainNode* createExceptionScope(CallFrame*, const Instruction* vPC);
132
133 void tryCacheGetByID(CallFrame*, CodeBlock*, Instruction*, JSValue baseValue, const Identifier& propertyName, const PropertySlot&);
134 void uncacheGetByID(CodeBlock*, Instruction* vPC);
135 void tryCachePutByID(CallFrame*, CodeBlock*, Instruction*, JSValue baseValue, const PutPropertySlot&);
136 void uncachePutByID(CodeBlock*, Instruction* vPC);
137#endif
138
139 NEVER_INLINE bool unwindCallFrame(CallFrame*&, JSValue, unsigned& bytecodeOffset, CodeBlock*&);
140
141 static ALWAYS_INLINE CallFrame* slideRegisterWindowForCall(CodeBlock*, RegisterFile*, CallFrame*, size_t registerOffset, int argc);
142
143 static CallFrame* findFunctionCallFrame(CallFrame*, InternalFunction*);
144
145 JSValue privateExecute(ExecutionFlag, RegisterFile*, CallFrame*, JSValue* exception);
146
147 void dumpCallFrame(CallFrame*);
148 void dumpRegisters(CallFrame*);
149
150 bool isCallBytecode(Opcode opcode) { return opcode == getOpcode(op_call) || opcode == getOpcode(op_construct) || opcode == getOpcode(op_call_eval); }
151
152 SamplingTool* m_sampler;
153
154 int m_reentryDepth;
155
156 RegisterFile m_registerFile;
157
158#if HAVE(COMPUTED_GOTO)
159 Opcode m_opcodeTable[numOpcodeIDs]; // Maps OpcodeID => Opcode for compiling
160 HashMap<Opcode, OpcodeID> m_opcodeIDTable; // Maps Opcode => OpcodeID for decompiling
161#endif
162 };
163
164} // namespace JSC
165
166#endif // Interpreter_h
Note: See TracBrowser for help on using the repository browser.