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