mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 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 | */ |
weinig@apple.com | a963b96 | 2008-06-05 05:36:55 +0000 | [diff] [blame] | 28 | |
ggaren@apple.com | 901a8a2 | 2008-11-17 20:57:18 +0000 | [diff] [blame] | 29 | #ifndef Interpreter_h |
| 30 | #define Interpreter_h |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 31 | |
weinig@apple.com | 49b3250 | 2008-07-06 00:10:04 +0000 | [diff] [blame] | 32 | #include "ArgList.h" |
ggaren@apple.com | 1d72f77 | 2008-07-03 00:47:00 +0000 | [diff] [blame] | 33 | #include "JSCell.h" |
| 34 | #include "JSValue.h" |
ggaren@apple.com | bb63926 | 2009-02-20 06:04:21 +0000 | [diff] [blame] | 35 | #include "JSObject.h" |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 36 | #include "Opcode.h" |
ggaren@apple.com | 82a62d0 | 2008-06-27 22:35:33 +0000 | [diff] [blame] | 37 | #include "RegisterFile.h" |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 38 | |
hausmann@webkit.org | f71db05 | 2009-07-15 15:14:15 +0000 | [diff] [blame] | 39 | #include <wtf/HashMap.h> |
| 40 | |
cwzwarich@webkit.org | 3f782f6 | 2008-09-08 01:28:33 +0000 | [diff] [blame] | 41 | namespace JSC { |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 42 | |
| 43 | class CodeBlock; |
barraclough@apple.com | 83651156 | 2009-08-15 01:14:00 +0000 | [diff] [blame] | 44 | class EvalExecutable; |
barraclough@apple.com | 306bb12 | 2009-08-18 05:34:52 +0000 | [diff] [blame] | 45 | class FunctionExecutable; |
ggaren@apple.com | 82a62d0 | 2008-06-27 22:35:33 +0000 | [diff] [blame] | 46 | class JSFunction; |
oliver@apple.com | c8f3a75 | 2008-06-28 04:02:03 +0000 | [diff] [blame] | 47 | class JSGlobalObject; |
barraclough@apple.com | 83651156 | 2009-08-15 01:14:00 +0000 | [diff] [blame] | 48 | class ProgramExecutable; |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 49 | class Register; |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 50 | class ScopeChainNode; |
barraclough@apple.com | eb51bd9 | 2008-07-30 17:38:35 +0000 | [diff] [blame] | 51 | class SamplingTool; |
oliver@apple.com | ef1f5ce | 2009-04-15 07:31:48 +0000 | [diff] [blame] | 52 | struct CallFrameClosure; |
weinig@apple.com | 18064e7 | 2008-12-10 00:26:13 +0000 | [diff] [blame] | 53 | struct HandlerInfo; |
levin@chromium.org | 93604aa | 2009-07-29 08:04:19 +0000 | [diff] [blame] | 54 | struct Instruction; |
| 55 | |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 56 | enum DebugHookID { |
ggaren@apple.com | d0740c8 | 2008-05-28 20:47:13 +0000 | [diff] [blame] | 57 | WillExecuteProgram, |
| 58 | DidExecuteProgram, |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 59 | DidEnterCallFrame, |
oliver@apple.com | 139b529 | 2008-06-03 22:48:52 +0000 | [diff] [blame] | 60 | DidReachBreakpoint, |
ggaren@apple.com | d0740c8 | 2008-05-28 20:47:13 +0000 | [diff] [blame] | 61 | WillLeaveCallFrame, |
| 62 | WillExecuteStatement |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 63 | }; |
| 64 | |
commit-queue@webkit.org | 8481462 | 2011-08-25 01:25:38 +0000 | [diff] [blame^] | 65 | class TopCallFrameSetter { |
| 66 | public: |
| 67 | TopCallFrameSetter(JSGlobalData& global, CallFrame* callFrame) |
| 68 | : globalData(global) |
| 69 | , oldCallFrame(global.topCallFrame) |
| 70 | { |
| 71 | global.topCallFrame = callFrame; |
| 72 | } |
| 73 | |
| 74 | ~TopCallFrameSetter() |
| 75 | { |
| 76 | globalData.topCallFrame = oldCallFrame; |
| 77 | } |
| 78 | private: |
| 79 | JSGlobalData& globalData; |
| 80 | CallFrame* oldCallFrame; |
| 81 | }; |
| 82 | |
weinig@apple.com | 1d6ce27 | 2010-04-21 20:59:14 +0000 | [diff] [blame] | 83 | enum { MaxLargeThreadReentryDepth = 256, MaxSmallThreadReentryDepth = 32 }; |
ggaren@apple.com | 4668b2f | 2008-06-02 16:36:01 +0000 | [diff] [blame] | 84 | |
ossy@webkit.org | 95c1bc4 | 2011-01-20 16:30:54 +0000 | [diff] [blame] | 85 | class Interpreter { |
| 86 | WTF_MAKE_FAST_ALLOCATED; |
ggaren@apple.com | 4f7d7a9 | 2008-11-17 03:34:05 +0000 | [diff] [blame] | 87 | friend class JIT; |
oliver@apple.com | 9a4dea5 | 2009-04-15 07:13:25 +0000 | [diff] [blame] | 88 | friend class CachedCall; |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 89 | public: |
ggaren@apple.com | 99e9f3f | 2011-06-22 20:07:37 +0000 | [diff] [blame] | 90 | Interpreter(); |
barraclough@apple.com | 7c876fc | 2008-11-11 05:09:46 +0000 | [diff] [blame] | 91 | |
ggaren@apple.com | 82a62d0 | 2008-06-27 22:35:33 +0000 | [diff] [blame] | 92 | RegisterFile& registerFile() { return m_registerFile; } |
| 93 | |
ggaren@apple.com | 47d3f05 | 2008-11-15 21:37:49 +0000 | [diff] [blame] | 94 | Opcode getOpcode(OpcodeID id) |
ggaren@apple.com | e5af6d5 | 2008-09-26 22:43:16 +0000 | [diff] [blame] | 95 | { |
oliver@apple.com | 563fc0a | 2010-07-11 01:14:47 +0000 | [diff] [blame] | 96 | #if ENABLE(COMPUTED_GOTO_INTERPRETER) |
ggaren@apple.com | 47d3f05 | 2008-11-15 21:37:49 +0000 | [diff] [blame] | 97 | return m_opcodeTable[id]; |
ggaren@apple.com | e5af6d5 | 2008-09-26 22:43:16 +0000 | [diff] [blame] | 98 | #else |
| 99 | return id; |
| 100 | #endif |
| 101 | } |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 102 | |
ggaren@apple.com | 47d3f05 | 2008-11-15 21:37:49 +0000 | [diff] [blame] | 103 | OpcodeID getOpcodeID(Opcode opcode) |
weinig@apple.com | a963b96 | 2008-06-05 05:36:55 +0000 | [diff] [blame] | 104 | { |
oliver@apple.com | 563fc0a | 2010-07-11 01:14:47 +0000 | [diff] [blame] | 105 | #if ENABLE(COMPUTED_GOTO_INTERPRETER) |
ggaren@apple.com | 47d3f05 | 2008-11-15 21:37:49 +0000 | [diff] [blame] | 106 | ASSERT(isOpcode(opcode)); |
| 107 | return m_opcodeIDTable.get(opcode); |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 108 | #else |
ggaren@apple.com | 47d3f05 | 2008-11-15 21:37:49 +0000 | [diff] [blame] | 109 | return opcode; |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 110 | #endif |
| 111 | } |
| 112 | |
ggaren@apple.com | 47d3f05 | 2008-11-15 21:37:49 +0000 | [diff] [blame] | 113 | bool isOpcode(Opcode); |
barraclough@apple.com | 2607dd0 | 2010-10-27 20:46:09 +0000 | [diff] [blame] | 114 | |
| 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&); |
barraclough@apple.com | 19afece | 2011-07-15 19:51:49 +0000 | [diff] [blame] | 118 | JSValue execute(EvalExecutable* evalNode, CallFrame*, JSValue thisValue, ScopeChainNode*); |
weinig@apple.com | a963b96 | 2008-06-05 05:36:55 +0000 | [diff] [blame] | 119 | |
ggaren@apple.com | dc067b6 | 2009-05-01 22:43:39 +0000 | [diff] [blame] | 120 | JSValue retrieveArguments(CallFrame*, JSFunction*) const; |
kevino@webkit.org | 627fde7 | 2011-06-08 19:45:37 +0000 | [diff] [blame] | 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; |
ggaren@apple.com | 0c67773 | 2008-09-30 00:46:25 +0000 | [diff] [blame] | 123 | |
darin@apple.com | 8c2bac0 | 2008-10-09 00:40:43 +0000 | [diff] [blame] | 124 | void getArgumentsData(CallFrame*, JSFunction*&, ptrdiff_t& firstParameterIndex, Register*& argv, int& argc); |
oliver@apple.com | c8f3a75 | 2008-06-28 04:02:03 +0000 | [diff] [blame] | 125 | |
oliver@apple.com | ebd0b4c | 2009-09-29 21:48:52 +0000 | [diff] [blame] | 126 | SamplingTool* sampler() { return m_sampler.get(); } |
ggaren@apple.com | 82a62d0 | 2008-06-27 22:35:33 +0000 | [diff] [blame] | 127 | |
barraclough@apple.com | 2607dd0 | 2010-10-27 20:46:09 +0000 | [diff] [blame] | 128 | NEVER_INLINE JSValue callEval(CallFrame*, RegisterFile*, Register* argv, int argc, int registerOffset); |
barraclough@apple.com | 87dbd5e | 2010-11-19 02:35:25 +0000 | [diff] [blame] | 129 | NEVER_INLINE HandlerInfo* throwException(CallFrame*&, JSValue&, unsigned bytecodeOffset); |
barraclough@apple.com | 5b374fc | 2009-06-02 05:36:18 +0000 | [diff] [blame] | 130 | NEVER_INLINE void debug(CallFrame*, DebugHookID, int firstLine, int lastLine); |
| 131 | |
oliver@apple.com | ebd0b4c | 2009-09-29 21:48:52 +0000 | [diff] [blame] | 132 | void dumpSampleData(ExecState* exec); |
| 133 | void startSampling(); |
| 134 | void stopSampling(); |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 135 | private: |
weinig@apple.com | a963b96 | 2008-06-05 05:36:55 +0000 | [diff] [blame] | 136 | enum ExecutionFlag { Normal, InitializeAndReturn }; |
oliver@apple.com | 9a4dea5 | 2009-04-15 07:13:25 +0000 | [diff] [blame] | 137 | |
barraclough@apple.com | 2607dd0 | 2010-10-27 20:46:09 +0000 | [diff] [blame] | 138 | CallFrameClosure prepareForRepeatCall(FunctionExecutable*, CallFrame*, JSFunction*, int argCount, ScopeChainNode*); |
oliver@apple.com | 9a4dea5 | 2009-04-15 07:13:25 +0000 | [diff] [blame] | 139 | void endRepeatCall(CallFrameClosure&); |
barraclough@apple.com | 2607dd0 | 2010-10-27 20:46:09 +0000 | [diff] [blame] | 140 | JSValue execute(CallFrameClosure&); |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 141 | |
barraclough@apple.com | 19afece | 2011-07-15 19:51:49 +0000 | [diff] [blame] | 142 | JSValue execute(EvalExecutable*, CallFrame*, JSValue thisValue, int globalRegisterOffset, ScopeChainNode*); |
ggaren@apple.com | 82a62d0 | 2008-06-27 22:35:33 +0000 | [diff] [blame] | 143 | |
oliver@apple.com | 942e37d | 2010-07-07 01:35:56 +0000 | [diff] [blame] | 144 | #if ENABLE(INTERPRETER) |
ggaren@apple.com | dc067b6 | 2009-05-01 22:43:39 +0000 | [diff] [blame] | 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); |
oliver@apple.com | e9af124 | 2010-05-08 00:05:00 +0000 | [diff] [blame] | 148 | NEVER_INLINE bool resolveGlobalDynamic(CallFrame*, Instruction*, JSValue& exceptionValue); |
darin@apple.com | 8c2bac0 | 2008-10-09 00:40:43 +0000 | [diff] [blame] | 149 | NEVER_INLINE void resolveBase(CallFrame*, Instruction* vPC); |
ggaren@apple.com | dc067b6 | 2009-05-01 22:43:39 +0000 | [diff] [blame] | 150 | NEVER_INLINE bool resolveBaseAndProperty(CallFrame*, Instruction*, JSValue& exceptionValue); |
barraclough@apple.com | 19afece | 2011-07-15 19:51:49 +0000 | [diff] [blame] | 151 | NEVER_INLINE bool resolveThisAndProperty(CallFrame*, Instruction*, JSValue& exceptionValue); |
darin@apple.com | 8c2bac0 | 2008-10-09 00:40:43 +0000 | [diff] [blame] | 152 | NEVER_INLINE ScopeChainNode* createExceptionScope(CallFrame*, const Instruction* vPC); |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 153 | |
oliver@apple.com | 49bbd29 | 2009-05-23 11:08:58 +0000 | [diff] [blame] | 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); |
oliver@apple.com | 942e37d | 2010-07-07 01:35:56 +0000 | [diff] [blame] | 158 | #endif // ENABLE(INTERPRETER) |
oliver@apple.com | 49bbd29 | 2009-05-23 11:08:58 +0000 | [diff] [blame] | 159 | |
ggaren@apple.com | dc067b6 | 2009-05-01 22:43:39 +0000 | [diff] [blame] | 160 | NEVER_INLINE bool unwindCallFrame(CallFrame*&, JSValue, unsigned& bytecodeOffset, CodeBlock*&); |
weinig@apple.com | a963b96 | 2008-06-05 05:36:55 +0000 | [diff] [blame] | 161 | |
darin@apple.com | 8c2bac0 | 2008-10-09 00:40:43 +0000 | [diff] [blame] | 162 | static ALWAYS_INLINE CallFrame* slideRegisterWindowForCall(CodeBlock*, RegisterFile*, CallFrame*, size_t registerOffset, int argc); |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 163 | |
barraclough@apple.com | 4be541c | 2010-05-20 02:38:01 +0000 | [diff] [blame] | 164 | static CallFrame* findFunctionCallFrame(CallFrame*, JSFunction*); |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 165 | |
barraclough@apple.com | 2607dd0 | 2010-10-27 20:46:09 +0000 | [diff] [blame] | 166 | JSValue privateExecute(ExecutionFlag, RegisterFile*, CallFrame*); |
darin@apple.com | 8c2bac0 | 2008-10-09 00:40:43 +0000 | [diff] [blame] | 167 | |
ggaren@apple.com | 68313b0 | 2008-11-13 00:48:23 +0000 | [diff] [blame] | 168 | void dumpCallFrame(CallFrame*); |
| 169 | void dumpRegisters(CallFrame*); |
ggaren@apple.com | 4b8c0fb | 2008-10-20 16:48:30 +0000 | [diff] [blame] | 170 | |
ggaren@apple.com | 47d3f05 | 2008-11-15 21:37:49 +0000 | [diff] [blame] | 171 | bool isCallBytecode(Opcode opcode) { return opcode == getOpcode(op_call) || opcode == getOpcode(op_construct) || opcode == getOpcode(op_call_eval); } |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 172 | |
oliver@apple.com | ebd0b4c | 2009-09-29 21:48:52 +0000 | [diff] [blame] | 173 | void enableSampler(); |
| 174 | int m_sampleEntryDepth; |
| 175 | OwnPtr<SamplingTool> m_sampler; |
ggaren@apple.com | be95ccf | 2008-10-25 19:59:47 +0000 | [diff] [blame] | 176 | |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 177 | int m_reentryDepth; |
oliver@apple.com | c8f3a75 | 2008-06-28 04:02:03 +0000 | [diff] [blame] | 178 | |
ggaren@apple.com | 82a62d0 | 2008-06-27 22:35:33 +0000 | [diff] [blame] | 179 | RegisterFile m_registerFile; |
ggaren@apple.com | 1d72f77 | 2008-07-03 00:47:00 +0000 | [diff] [blame] | 180 | |
oliver@apple.com | 563fc0a | 2010-07-11 01:14:47 +0000 | [diff] [blame] | 181 | #if ENABLE(COMPUTED_GOTO_INTERPRETER) |
ggaren@apple.com | 47d3f05 | 2008-11-15 21:37:49 +0000 | [diff] [blame] | 182 | Opcode m_opcodeTable[numOpcodeIDs]; // Maps OpcodeID => Opcode for compiling |
| 183 | HashMap<Opcode, OpcodeID> m_opcodeIDTable; // Maps Opcode => OpcodeID for decompiling |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 184 | #endif |
| 185 | }; |
barraclough@apple.com | 19afece | 2011-07-15 19:51:49 +0000 | [diff] [blame] | 186 | |
| 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) |
| 189 | { |
| 190 | return !thisValue.isObject() || thisValue.toThisObject(exec) == thisValue; |
| 191 | } |
| 192 | |
cwzwarich@webkit.org | 3f782f6 | 2008-09-08 01:28:33 +0000 | [diff] [blame] | 193 | } // namespace JSC |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 194 | |
ggaren@apple.com | 901a8a2 | 2008-11-17 20:57:18 +0000 | [diff] [blame] | 195 | #endif // Interpreter_h |