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

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

2008-12-02 Geoffrey Garen <[email protected]>

Reviewed by Geoffrey Garen. (Patch by Cameron Zwarich <[email protected]>.)


Fixed https://bugs.webkit.org/show_bug.cgi?id=22482
REGRESSION (r37991): Occasionally see "Scene rendered incorrectly"
message when running the V8 Raytrace benchmark


Rolled out r37991. It didn't properly save xmm0, which is caller-save,
before calling helper functions.


SunSpider and v8 benchmarks show little change -- possibly a .2%
SunSpider regression, possibly a .2% v8 benchmark speedup.

  • assembler/X86Assembler.h: (JSC::X86Assembler::):
  • bytecode/CodeBlock.cpp: (JSC::CodeBlock::dump):
  • bytecode/Instruction.h: (JSC::Instruction::):
  • bytecompiler/BytecodeGenerator.cpp: (JSC::BytecodeGenerator::emitUnaryOp):
  • bytecompiler/BytecodeGenerator.h: (JSC::BytecodeGenerator::emitToJSNumber): (JSC::BytecodeGenerator::emitTypeOf): (JSC::BytecodeGenerator::emitGetPropertyNames):
  • interpreter/Interpreter.cpp: (JSC::Interpreter::privateExecute):
  • interpreter/Interpreter.h:
  • jit/JIT.cpp: (JSC::JIT::privateCompileMainPass): (JSC::JIT::privateCompileSlowCases):
  • jit/JIT.h:
  • parser/Nodes.cpp: (JSC::UnaryOpNode::emitBytecode): (JSC::BinaryOpNode::emitBytecode): (JSC::EqualNode::emitBytecode):
  • parser/ResultType.h: (JSC::ResultType::isReusable): (JSC::ResultType::mightBeNumber):
  • runtime/JSNumberCell.h:
File size: 15.4 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 "JSCell.h"
34#include "JSValue.h"
35#include "Opcode.h"
36#include "RegisterFile.h"
37#include <wtf/HashMap.h>
38
39namespace JSC {
40
41 class CodeBlock;
42 class EvalNode;
43 class FunctionBodyNode;
44 class Instruction;
45 class InternalFunction;
46 class AssemblerBuffer;
47 class JSFunction;
48 class JSGlobalObject;
49 class ProgramNode;
50 class Register;
51 class ScopeChainNode;
52 class SamplingTool;
53
54#if ENABLE(JIT)
55
56#if USE(CTI_ARGUMENT)
57#define CTI_ARGS void** args
58#define ARGS (args)
59#else
60#define CTI_ARGS void* args, ...
61#define ARGS (&args)
62#endif
63
64#if USE(FAST_CALL_CTI_ARGUMENT)
65
66#if COMPILER(MSVC)
67#define SFX_CALL __fastcall
68#elif COMPILER(GCC)
69#define SFX_CALL __attribute__ ((fastcall))
70#else
71#error Need to support fastcall calling convention in this compiler
72#endif
73
74#else
75
76#if COMPILER(MSVC)
77#define SFX_CALL __cdecl
78#else
79#define SFX_CALL
80#endif
81
82#endif
83
84 typedef uint64_t VoidPtrPair;
85
86 typedef union
87 {
88 struct { void* first; void* second; } s;
89 VoidPtrPair i;
90 } VoidPtrPairValue;
91#endif
92
93 enum DebugHookID {
94 WillExecuteProgram,
95 DidExecuteProgram,
96 DidEnterCallFrame,
97 DidReachBreakpoint,
98 WillLeaveCallFrame,
99 WillExecuteStatement
100 };
101
102 enum { MaxReentryDepth = 128 };
103
104 class Interpreter {
105 friend class JIT;
106 public:
107 Interpreter();
108 ~Interpreter();
109
110 void initialize(JSGlobalData*);
111
112 RegisterFile& registerFile() { return m_registerFile; }
113
114 Opcode getOpcode(OpcodeID id)
115 {
116 #if HAVE(COMPUTED_GOTO)
117 return m_opcodeTable[id];
118 #else
119 return id;
120 #endif
121 }
122
123 OpcodeID getOpcodeID(Opcode opcode)
124 {
125 #if HAVE(COMPUTED_GOTO)
126 ASSERT(isOpcode(opcode));
127 return m_opcodeIDTable.get(opcode);
128 #else
129 return opcode;
130 #endif
131 }
132
133 bool isOpcode(Opcode);
134
135 JSValue* execute(ProgramNode*, CallFrame*, ScopeChainNode*, JSObject* thisObj, JSValue** exception);
136 JSValue* execute(FunctionBodyNode*, CallFrame*, JSFunction*, JSObject* thisObj, const ArgList& args, ScopeChainNode*, JSValue** exception);
137 JSValue* execute(EvalNode* evalNode, CallFrame* exec, JSObject* thisObj, ScopeChainNode* scopeChain, JSValue** exception);
138
139 JSValue* retrieveArguments(CallFrame*, JSFunction*) const;
140 JSValue* retrieveCaller(CallFrame*, InternalFunction*) const;
141 void retrieveLastCaller(CallFrame*, int& lineNumber, intptr_t& sourceID, UString& sourceURL, JSValue*& function) const;
142
143 void getArgumentsData(CallFrame*, JSFunction*&, ptrdiff_t& firstParameterIndex, Register*& argv, int& argc);
144 void setTimeoutTime(unsigned timeoutTime) { m_timeoutTime = timeoutTime; }
145
146 void startTimeoutCheck()
147 {
148 if (!m_timeoutCheckCount)
149 resetTimeoutCheck();
150
151 ++m_timeoutCheckCount;
152 }
153
154 void stopTimeoutCheck()
155 {
156 ASSERT(m_timeoutCheckCount);
157 --m_timeoutCheckCount;
158 }
159
160 inline void initTimeout()
161 {
162 ASSERT(!m_timeoutCheckCount);
163 resetTimeoutCheck();
164 m_timeoutTime = 0;
165 m_timeoutCheckCount = 0;
166 }
167
168 void setSampler(SamplingTool* sampler) { m_sampler = sampler; }
169 SamplingTool* sampler() { return m_sampler; }
170
171#if ENABLE(JIT)
172
173 static void SFX_CALL cti_timeout_check(CTI_ARGS);
174 static void SFX_CALL cti_register_file_check(CTI_ARGS);
175
176 static JSObject* SFX_CALL cti_op_convert_this(CTI_ARGS);
177 static void SFX_CALL cti_op_end(CTI_ARGS);
178 static JSValue* SFX_CALL cti_op_add(CTI_ARGS);
179 static JSValue* SFX_CALL cti_op_pre_inc(CTI_ARGS);
180 static int SFX_CALL cti_op_loop_if_less(CTI_ARGS);
181 static int SFX_CALL cti_op_loop_if_lesseq(CTI_ARGS);
182 static JSObject* SFX_CALL cti_op_new_object(CTI_ARGS);
183 static void SFX_CALL cti_op_put_by_id(CTI_ARGS);
184 static void SFX_CALL cti_op_put_by_id_second(CTI_ARGS);
185 static void SFX_CALL cti_op_put_by_id_generic(CTI_ARGS);
186 static void SFX_CALL cti_op_put_by_id_fail(CTI_ARGS);
187 static JSValue* SFX_CALL cti_op_get_by_id(CTI_ARGS);
188 static JSValue* SFX_CALL cti_op_get_by_id_second(CTI_ARGS);
189 static JSValue* SFX_CALL cti_op_get_by_id_generic(CTI_ARGS);
190 static JSValue* SFX_CALL cti_op_get_by_id_self_fail(CTI_ARGS);
191 static JSValue* SFX_CALL cti_op_get_by_id_proto_list(CTI_ARGS);
192 static JSValue* SFX_CALL cti_op_get_by_id_proto_list_full(CTI_ARGS);
193 static JSValue* SFX_CALL cti_op_get_by_id_proto_fail(CTI_ARGS);
194 static JSValue* SFX_CALL cti_op_get_by_id_array_fail(CTI_ARGS);
195 static JSValue* SFX_CALL cti_op_get_by_id_string_fail(CTI_ARGS);
196 static JSValue* SFX_CALL cti_op_del_by_id(CTI_ARGS);
197 static JSValue* SFX_CALL cti_op_instanceof(CTI_ARGS);
198 static JSValue* SFX_CALL cti_op_mul(CTI_ARGS);
199 static JSObject* SFX_CALL cti_op_new_func(CTI_ARGS);
200 static void* SFX_CALL cti_op_call_JSFunction(CTI_ARGS);
201 static VoidPtrPair SFX_CALL cti_op_call_arityCheck(CTI_ARGS);
202 static JSValue* SFX_CALL cti_op_call_NotJSFunction(CTI_ARGS);
203 static void SFX_CALL cti_op_create_arguments(CTI_ARGS);
204 static void SFX_CALL cti_op_create_arguments_no_params(CTI_ARGS);
205 static void SFX_CALL cti_op_tear_off_activation(CTI_ARGS);
206 static void SFX_CALL cti_op_tear_off_arguments(CTI_ARGS);
207 static void SFX_CALL cti_op_profile_will_call(CTI_ARGS);
208 static void SFX_CALL cti_op_profile_did_call(CTI_ARGS);
209 static void SFX_CALL cti_op_ret_scopeChain(CTI_ARGS);
210 static JSObject* SFX_CALL cti_op_new_array(CTI_ARGS);
211 static JSValue* SFX_CALL cti_op_resolve(CTI_ARGS);
212 static JSValue* SFX_CALL cti_op_resolve_global(CTI_ARGS);
213 static JSObject* SFX_CALL cti_op_construct_JSConstruct(CTI_ARGS);
214 static JSValue* SFX_CALL cti_op_construct_NotJSConstruct(CTI_ARGS);
215 static JSValue* SFX_CALL cti_op_get_by_val(CTI_ARGS);
216 static VoidPtrPair SFX_CALL cti_op_resolve_func(CTI_ARGS);
217 static JSValue* SFX_CALL cti_op_sub(CTI_ARGS);
218 static void SFX_CALL cti_op_put_by_val(CTI_ARGS);
219 static void SFX_CALL cti_op_put_by_val_array(CTI_ARGS);
220 static JSValue* SFX_CALL cti_op_lesseq(CTI_ARGS);
221 static int SFX_CALL cti_op_loop_if_true(CTI_ARGS);
222 static JSValue* SFX_CALL cti_op_resolve_base(CTI_ARGS);
223 static JSValue* SFX_CALL cti_op_negate(CTI_ARGS);
224 static JSValue* SFX_CALL cti_op_resolve_skip(CTI_ARGS);
225 static JSValue* SFX_CALL cti_op_div(CTI_ARGS);
226 static JSValue* SFX_CALL cti_op_pre_dec(CTI_ARGS);
227 static int SFX_CALL cti_op_jless(CTI_ARGS);
228 static JSValue* SFX_CALL cti_op_not(CTI_ARGS);
229 static int SFX_CALL cti_op_jtrue(CTI_ARGS);
230 static VoidPtrPair SFX_CALL cti_op_post_inc(CTI_ARGS);
231 static JSValue* SFX_CALL cti_op_eq(CTI_ARGS);
232 static JSValue* SFX_CALL cti_op_lshift(CTI_ARGS);
233 static JSValue* SFX_CALL cti_op_bitand(CTI_ARGS);
234 static JSValue* SFX_CALL cti_op_rshift(CTI_ARGS);
235 static JSValue* SFX_CALL cti_op_bitnot(CTI_ARGS);
236 static VoidPtrPair SFX_CALL cti_op_resolve_with_base(CTI_ARGS);
237 static JSObject* SFX_CALL cti_op_new_func_exp(CTI_ARGS);
238 static JSValue* SFX_CALL cti_op_mod(CTI_ARGS);
239 static JSValue* SFX_CALL cti_op_less(CTI_ARGS);
240 static JSValue* SFX_CALL cti_op_neq(CTI_ARGS);
241 static VoidPtrPair SFX_CALL cti_op_post_dec(CTI_ARGS);
242 static JSValue* SFX_CALL cti_op_urshift(CTI_ARGS);
243 static JSValue* SFX_CALL cti_op_bitxor(CTI_ARGS);
244 static JSObject* SFX_CALL cti_op_new_regexp(CTI_ARGS);
245 static JSValue* SFX_CALL cti_op_bitor(CTI_ARGS);
246 static JSValue* SFX_CALL cti_op_call_eval(CTI_ARGS);
247 static JSValue* SFX_CALL cti_op_throw(CTI_ARGS);
248 static JSPropertyNameIterator* SFX_CALL cti_op_get_pnames(CTI_ARGS);
249 static JSValue* SFX_CALL cti_op_next_pname(CTI_ARGS);
250 static void SFX_CALL cti_op_push_scope(CTI_ARGS);
251 static void SFX_CALL cti_op_pop_scope(CTI_ARGS);
252 static JSValue* SFX_CALL cti_op_typeof(CTI_ARGS);
253 static JSValue* SFX_CALL cti_op_is_undefined(CTI_ARGS);
254 static JSValue* SFX_CALL cti_op_is_boolean(CTI_ARGS);
255 static JSValue* SFX_CALL cti_op_is_number(CTI_ARGS);
256 static JSValue* SFX_CALL cti_op_is_string(CTI_ARGS);
257 static JSValue* SFX_CALL cti_op_is_object(CTI_ARGS);
258 static JSValue* SFX_CALL cti_op_is_function(CTI_ARGS);
259 static JSValue* SFX_CALL cti_op_stricteq(CTI_ARGS);
260 static JSValue* SFX_CALL cti_op_nstricteq(CTI_ARGS);
261 static JSValue* SFX_CALL cti_op_to_jsnumber(CTI_ARGS);
262 static JSValue* SFX_CALL cti_op_in(CTI_ARGS);
263 static JSObject* SFX_CALL cti_op_push_new_scope(CTI_ARGS);
264 static void SFX_CALL cti_op_jmp_scopes(CTI_ARGS);
265 static void SFX_CALL cti_op_put_by_index(CTI_ARGS);
266 static void* SFX_CALL cti_op_switch_imm(CTI_ARGS);
267 static void* SFX_CALL cti_op_switch_char(CTI_ARGS);
268 static void* SFX_CALL cti_op_switch_string(CTI_ARGS);
269 static JSValue* SFX_CALL cti_op_del_by_val(CTI_ARGS);
270 static void SFX_CALL cti_op_put_getter(CTI_ARGS);
271 static void SFX_CALL cti_op_put_setter(CTI_ARGS);
272 static JSObject* SFX_CALL cti_op_new_error(CTI_ARGS);
273 static void SFX_CALL cti_op_debug(CTI_ARGS);
274
275 static JSValue* SFX_CALL cti_vm_throw(CTI_ARGS);
276 static void* SFX_CALL cti_vm_dontLazyLinkCall(CTI_ARGS);
277 static void* SFX_CALL cti_vm_lazyLinkCall(CTI_ARGS);
278 static JSObject* SFX_CALL cti_op_push_activation(CTI_ARGS);
279
280#endif // ENABLE(JIT)
281
282#if ENABLE(ASSEMBLER)
283 AssemblerBuffer* assemblerBuffer() const { return m_assemblerBuffer.get(); }
284#endif
285
286 // Default number of ticks before a timeout check should be done.
287 static const int initialTickCountThreshold = 1024;
288
289 bool isJSArray(JSValue* v) { return !JSImmediate::isImmediate(v) && v->asCell()->vptr() == m_jsArrayVptr; }
290 bool isJSString(JSValue* v) { return !JSImmediate::isImmediate(v) && v->asCell()->vptr() == m_jsStringVptr; }
291
292 private:
293 enum ExecutionFlag { Normal, InitializeAndReturn };
294
295 NEVER_INLINE JSValue* callEval(CallFrame*, RegisterFile*, Register* argv, int argc, int registerOffset, JSValue*& exceptionValue);
296 JSValue* execute(EvalNode*, CallFrame*, JSObject* thisObject, int globalRegisterOffset, ScopeChainNode*, JSValue** exception);
297
298 NEVER_INLINE void debug(CallFrame*, DebugHookID, int firstLine, int lastLine);
299
300 NEVER_INLINE bool resolve(CallFrame*, Instruction*, JSValue*& exceptionValue);
301 NEVER_INLINE bool resolveSkip(CallFrame*, Instruction*, JSValue*& exceptionValue);
302 NEVER_INLINE bool resolveGlobal(CallFrame*, Instruction*, JSValue*& exceptionValue);
303 NEVER_INLINE void resolveBase(CallFrame*, Instruction* vPC);
304 NEVER_INLINE bool resolveBaseAndProperty(CallFrame*, Instruction*, JSValue*& exceptionValue);
305 NEVER_INLINE ScopeChainNode* createExceptionScope(CallFrame*, const Instruction* vPC);
306
307 NEVER_INLINE bool unwindCallFrame(CallFrame*&, JSValue*, const Instruction*&, CodeBlock*&);
308 NEVER_INLINE Instruction* throwException(CallFrame*&, JSValue*&, const Instruction*, bool);
309 NEVER_INLINE bool resolveBaseAndFunc(CallFrame*, Instruction*, JSValue*& exceptionValue);
310
311 static ALWAYS_INLINE CallFrame* slideRegisterWindowForCall(CodeBlock*, RegisterFile*, CallFrame*, size_t registerOffset, int argc);
312
313 static CallFrame* findFunctionCallFrame(CallFrame*, InternalFunction*);
314
315 JSValue* privateExecute(ExecutionFlag, RegisterFile*, CallFrame*, JSValue** exception);
316
317 void dumpCallFrame(CallFrame*);
318 void dumpRegisters(CallFrame*);
319
320 JSValue* checkTimeout(JSGlobalObject*);
321 void resetTimeoutCheck();
322
323 void tryCacheGetByID(CallFrame*, CodeBlock*, Instruction*, JSValue* baseValue, const Identifier& propertyName, const PropertySlot&);
324 void uncacheGetByID(CodeBlock*, Instruction* vPC);
325 void tryCachePutByID(CallFrame*, CodeBlock*, Instruction*, JSValue* baseValue, const PutPropertySlot&);
326 void uncachePutByID(CodeBlock*, Instruction* vPC);
327
328 bool isCallBytecode(Opcode opcode) { return opcode == getOpcode(op_call) || opcode == getOpcode(op_construct) || opcode == getOpcode(op_call_eval); }
329
330#if ENABLE(JIT)
331 static void throwStackOverflowPreviousFrame(CallFrame**, JSGlobalData*, void*& returnAddress);
332
333 void tryCTICacheGetByID(CallFrame*, CodeBlock*, void* returnAddress, JSValue* baseValue, const Identifier& propertyName, const PropertySlot&);
334 void tryCTICachePutByID(CallFrame*, CodeBlock*, void* returnAddress, JSValue* baseValue, const PutPropertySlot&);
335#endif
336
337 SamplingTool* m_sampler;
338
339#if ENABLE(JIT)
340 void* m_ctiArrayLengthTrampoline;
341 void* m_ctiStringLengthTrampoline;
342 void* m_ctiVirtualCallPreLink;
343 void* m_ctiVirtualCallLink;
344 void* m_ctiVirtualCall;
345#endif
346
347#if ENABLE(ASSEMBLER)
348 OwnPtr<AssemblerBuffer> m_assemblerBuffer;
349#endif
350
351 int m_reentryDepth;
352 unsigned m_timeoutTime;
353 unsigned m_timeAtLastCheckTimeout;
354 unsigned m_timeExecuting;
355 unsigned m_timeoutCheckCount;
356 unsigned m_ticksUntilNextTimeoutCheck;
357
358 RegisterFile m_registerFile;
359
360 void* m_jsArrayVptr;
361 void* m_jsStringVptr;
362 void* m_jsFunctionVptr;
363
364#if HAVE(COMPUTED_GOTO)
365 Opcode m_opcodeTable[numOpcodeIDs]; // Maps OpcodeID => Opcode for compiling
366 HashMap<Opcode, OpcodeID> m_opcodeIDTable; // Maps Opcode => OpcodeID for decompiling
367#endif
368 };
369
370} // namespace JSC
371
372#endif // Interpreter_h
Note: See TracBrowser for help on using the repository browser.