2 * Copyright (C) 2008 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
37 #include "RegisterFile.h"
39 #include <wtf/HashMap.h>
45 class FunctionExecutable;
48 class ProgramExecutable;
52 struct CallFrameClosure;
65 class TopCallFrameSetter {
67 TopCallFrameSetter(JSGlobalData& global, CallFrame* callFrame)
69 , oldCallFrame(global.topCallFrame)
71 global.topCallFrame = callFrame;
76 globalData.topCallFrame = oldCallFrame;
79 JSGlobalData& globalData;
80 CallFrame* oldCallFrame;
83 enum { MaxLargeThreadReentryDepth = 256, MaxSmallThreadReentryDepth = 32 };
86 WTF_MAKE_FAST_ALLOCATED;
88 friend class CachedCall;
92 RegisterFile& registerFile() { return m_registerFile; }
94 Opcode getOpcode(OpcodeID id)
96 #if ENABLE(COMPUTED_GOTO_INTERPRETER)
97 return m_opcodeTable[id];
103 OpcodeID getOpcodeID(Opcode opcode)
105 #if ENABLE(COMPUTED_GOTO_INTERPRETER)
106 ASSERT(isOpcode(opcode));
107 return m_opcodeIDTable.get(opcode);
113 bool isOpcode(Opcode);
115 JSValue execute(ProgramExecutable*, CallFrame*, ScopeChainNode*, JSObject* thisObj);
116 JSValue executeCall(CallFrame*, JSObject* function, CallType, const CallData&, JSValue thisValue, const ArgList&);
117 JSObject* executeConstruct(CallFrame*, JSObject* function, ConstructType, const ConstructData&, const ArgList&);
118 JSValue execute(EvalExecutable* evalNode, CallFrame*, JSValue thisValue, ScopeChainNode*);
120 JSValue retrieveArguments(CallFrame*, JSFunction*) const;
121 JS_EXPORT_PRIVATE JSValue retrieveCaller(CallFrame*, JSFunction*) const;
122 JS_EXPORT_PRIVATE void retrieveLastCaller(CallFrame*, int& lineNumber, intptr_t& sourceID, UString& sourceURL, JSValue& function) const;
124 void getArgumentsData(CallFrame*, JSFunction*&, ptrdiff_t& firstParameterIndex, Register*& argv, int& argc);
126 SamplingTool* sampler() { return m_sampler.get(); }
128 NEVER_INLINE JSValue callEval(CallFrame*, RegisterFile*, Register* argv, int argc, int registerOffset);
129 NEVER_INLINE HandlerInfo* throwException(CallFrame*&, JSValue&, unsigned bytecodeOffset);
130 NEVER_INLINE void debug(CallFrame*, DebugHookID, int firstLine, int lastLine);
132 void dumpSampleData(ExecState* exec);
133 void startSampling();
136 enum ExecutionFlag { Normal, InitializeAndReturn };
138 CallFrameClosure prepareForRepeatCall(FunctionExecutable*, CallFrame*, JSFunction*, int argCount, ScopeChainNode*);
139 void endRepeatCall(CallFrameClosure&);
140 JSValue execute(CallFrameClosure&);
142 JSValue execute(EvalExecutable*, CallFrame*, JSValue thisValue, int globalRegisterOffset, ScopeChainNode*);
144 #if ENABLE(INTERPRETER)
145 NEVER_INLINE bool resolve(CallFrame*, Instruction*, JSValue& exceptionValue);
146 NEVER_INLINE bool resolveSkip(CallFrame*, Instruction*, JSValue& exceptionValue);
147 NEVER_INLINE bool resolveGlobal(CallFrame*, Instruction*, JSValue& exceptionValue);
148 NEVER_INLINE bool resolveGlobalDynamic(CallFrame*, Instruction*, JSValue& exceptionValue);
149 NEVER_INLINE void resolveBase(CallFrame*, Instruction* vPC);
150 NEVER_INLINE bool resolveBaseAndProperty(CallFrame*, Instruction*, JSValue& exceptionValue);
151 NEVER_INLINE bool resolveThisAndProperty(CallFrame*, Instruction*, JSValue& exceptionValue);
152 NEVER_INLINE ScopeChainNode* createExceptionScope(CallFrame*, const Instruction* vPC);
154 void tryCacheGetByID(CallFrame*, CodeBlock*, Instruction*, JSValue baseValue, const Identifier& propertyName, const PropertySlot&);
155 void uncacheGetByID(CodeBlock*, Instruction* vPC);
156 void tryCachePutByID(CallFrame*, CodeBlock*, Instruction*, JSValue baseValue, const PutPropertySlot&);
157 void uncachePutByID(CodeBlock*, Instruction* vPC);
158 #endif // ENABLE(INTERPRETER)
160 NEVER_INLINE bool unwindCallFrame(CallFrame*&, JSValue, unsigned& bytecodeOffset, CodeBlock*&);
162 static ALWAYS_INLINE CallFrame* slideRegisterWindowForCall(CodeBlock*, RegisterFile*, CallFrame*, size_t registerOffset, int argc);
164 static CallFrame* findFunctionCallFrame(CallFrame*, JSFunction*);
166 JSValue privateExecute(ExecutionFlag, RegisterFile*, CallFrame*);
168 void dumpCallFrame(CallFrame*);
169 void dumpRegisters(CallFrame*);
171 bool isCallBytecode(Opcode opcode) { return opcode == getOpcode(op_call) || opcode == getOpcode(op_construct) || opcode == getOpcode(op_call_eval); }
173 void enableSampler();
174 int m_sampleEntryDepth;
175 OwnPtr<SamplingTool> m_sampler;
179 RegisterFile m_registerFile;
181 #if ENABLE(COMPUTED_GOTO_INTERPRETER)
182 Opcode m_opcodeTable[numOpcodeIDs]; // Maps OpcodeID => Opcode for compiling
183 HashMap<Opcode, OpcodeID> m_opcodeIDTable; // Maps Opcode => OpcodeID for decompiling
187 // This value must not be an object that would require this conversion (WebCore's global object).
188 inline bool isValidThisObject(JSValue thisValue, ExecState* exec)
190 return !thisValue.isObject() || thisValue.toThisObject(exec) == thisValue;
195 #endif // Interpreter_h