upload tizen1.0 source
[profile/ivi/webkit-efl.git] / Source / JavaScriptCore / jit / JIT.h
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  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
24  */
25
26 #ifndef JIT_h
27 #define JIT_h
28
29 #if ENABLE(JIT)
30
31 // Verbose logging of code generation
32 #define ENABLE_JIT_VERBOSE 0
33 // Verbose logging for OSR-related code.
34 #define ENABLE_JIT_VERBOSE_OSR 0
35
36 // We've run into some problems where changing the size of the class JIT leads to
37 // performance fluctuations.  Try forcing alignment in an attempt to stabalize this.
38 #if COMPILER(GCC)
39 #define JIT_CLASS_ALIGNMENT __attribute__ ((aligned (32)))
40 #else
41 #define JIT_CLASS_ALIGNMENT
42 #endif
43
44 #define ASSERT_JIT_OFFSET_UNUSED(variable, actual, expected) ASSERT_WITH_MESSAGE_UNUSED(variable, actual == expected, "JIT Offset \"%s\" should be %d, not %d.\n", #expected, static_cast<int>(expected), static_cast<int>(actual));
45 #define ASSERT_JIT_OFFSET(actual, expected) ASSERT_WITH_MESSAGE(actual == expected, "JIT Offset \"%s\" should be %d, not %d.\n", #expected, static_cast<int>(expected), static_cast<int>(actual));
46
47 #include "CodeBlock.h"
48 #include "CompactJITCodeMap.h"
49 #include "Interpreter.h"
50 #include "JSInterfaceJIT.h"
51 #include "Opcode.h"
52 #include "Profiler.h"
53 #include <bytecode/SamplingTool.h>
54
55 namespace JSC {
56
57     class CodeBlock;
58     class FunctionExecutable;
59     class JIT;
60     class JSPropertyNameIterator;
61     class Interpreter;
62     class Register;
63     class RegisterFile;
64     class ScopeChainNode;
65     class StructureChain;
66
67     struct CallLinkInfo;
68     struct Instruction;
69     struct OperandTypes;
70     struct PolymorphicAccessStructureList;
71     struct SimpleJumpTable;
72     struct StringJumpTable;
73     struct StructureStubInfo;
74
75     struct CallRecord {
76         MacroAssembler::Call from;
77         unsigned bytecodeOffset;
78         void* to;
79
80         CallRecord()
81         {
82         }
83
84         CallRecord(MacroAssembler::Call from, unsigned bytecodeOffset, void* to = 0)
85             : from(from)
86             , bytecodeOffset(bytecodeOffset)
87             , to(to)
88         {
89         }
90     };
91
92     struct JumpTable {
93         MacroAssembler::Jump from;
94         unsigned toBytecodeOffset;
95
96         JumpTable(MacroAssembler::Jump f, unsigned t)
97             : from(f)
98             , toBytecodeOffset(t)
99         {
100         }
101     };
102
103     struct SlowCaseEntry {
104         MacroAssembler::Jump from;
105         unsigned to;
106         unsigned hint;
107         
108         SlowCaseEntry(MacroAssembler::Jump f, unsigned t, unsigned h = 0)
109             : from(f)
110             , to(t)
111             , hint(h)
112         {
113         }
114     };
115
116     struct SwitchRecord {
117         enum Type {
118             Immediate,
119             Character,
120             String
121         };
122
123         Type type;
124
125         union {
126             SimpleJumpTable* simpleJumpTable;
127             StringJumpTable* stringJumpTable;
128         } jumpTable;
129
130         unsigned bytecodeOffset;
131         unsigned defaultOffset;
132
133         SwitchRecord(SimpleJumpTable* jumpTable, unsigned bytecodeOffset, unsigned defaultOffset, Type type)
134             : type(type)
135             , bytecodeOffset(bytecodeOffset)
136             , defaultOffset(defaultOffset)
137         {
138             this->jumpTable.simpleJumpTable = jumpTable;
139         }
140
141         SwitchRecord(StringJumpTable* jumpTable, unsigned bytecodeOffset, unsigned defaultOffset)
142             : type(String)
143             , bytecodeOffset(bytecodeOffset)
144             , defaultOffset(defaultOffset)
145         {
146             this->jumpTable.stringJumpTable = jumpTable;
147         }
148     };
149
150     struct PropertyStubCompilationInfo {
151         unsigned bytecodeIndex;
152         MacroAssembler::Call callReturnLocation;
153         MacroAssembler::Label hotPathBegin;
154         
155 #if !ASSERT_DISABLED
156         PropertyStubCompilationInfo()
157             : bytecodeIndex(std::numeric_limits<unsigned>::max())
158         {
159         }
160 #endif
161     };
162
163     struct StructureStubCompilationInfo {
164         MacroAssembler::DataLabelPtr hotPathBegin;
165         MacroAssembler::Call hotPathOther;
166         MacroAssembler::Call callReturnLocation;
167         CallLinkInfo::CallType callType;
168         unsigned bytecodeIndex;
169     };
170
171     struct MethodCallCompilationInfo {
172         MethodCallCompilationInfo(unsigned bytecodeIndex, unsigned propertyAccessIndex)
173             : bytecodeIndex(bytecodeIndex)
174             , propertyAccessIndex(propertyAccessIndex)
175         {
176         }
177
178         unsigned bytecodeIndex;
179         MacroAssembler::DataLabelPtr structureToCompare;
180         unsigned propertyAccessIndex;
181     };
182
183     // Near calls can only be patched to other JIT code, regular calls can be patched to JIT code or relinked to stub functions.
184     void ctiPatchNearCallByReturnAddress(CodeBlock* codeblock, ReturnAddressPtr returnAddress, MacroAssemblerCodePtr newCalleeFunction);
185     void ctiPatchCallByReturnAddress(CodeBlock* codeblock, ReturnAddressPtr returnAddress, MacroAssemblerCodePtr newCalleeFunction);
186     void ctiPatchCallByReturnAddress(CodeBlock* codeblock, ReturnAddressPtr returnAddress, FunctionPtr newCalleeFunction);
187
188     class JIT : private JSInterfaceJIT {
189         friend class JITStubCall;
190
191         using MacroAssembler::Jump;
192         using MacroAssembler::JumpList;
193         using MacroAssembler::Label;
194
195         static const int patchGetByIdDefaultStructure = -1;
196         static const int patchGetByIdDefaultOffset = 0;
197         // Magic number - initial offset cannot be representable as a signed 8bit value, or the X86Assembler
198         // will compress the displacement, and we may not be able to fit a patched offset.
199         static const int patchPutByIdDefaultOffset = 256;
200
201     public:
202         static JITCode compile(JSGlobalData* globalData, CodeBlock* codeBlock, CodePtr* functionEntryArityCheck = 0)
203         {
204             return JIT(globalData, codeBlock).privateCompile(functionEntryArityCheck);
205         }
206
207         static void compileGetByIdProto(JSGlobalData* globalData, CallFrame* callFrame, CodeBlock* codeBlock, StructureStubInfo* stubInfo, Structure* structure, Structure* prototypeStructure, const Identifier& ident, const PropertySlot& slot, size_t cachedOffset, ReturnAddressPtr returnAddress)
208         {
209             JIT jit(globalData, codeBlock);
210             jit.privateCompileGetByIdProto(stubInfo, structure, prototypeStructure, ident, slot, cachedOffset, returnAddress, callFrame);
211         }
212
213         static void compileGetByIdSelfList(JSGlobalData* globalData, CodeBlock* codeBlock, StructureStubInfo* stubInfo, PolymorphicAccessStructureList* polymorphicStructures, int currentIndex, Structure* structure, const Identifier& ident, const PropertySlot& slot, size_t cachedOffset)
214         {
215             JIT jit(globalData, codeBlock);
216             jit.privateCompileGetByIdSelfList(stubInfo, polymorphicStructures, currentIndex, structure, ident, slot, cachedOffset);
217         }
218         static void compileGetByIdProtoList(JSGlobalData* globalData, CallFrame* callFrame, CodeBlock* codeBlock, StructureStubInfo* stubInfo, PolymorphicAccessStructureList* prototypeStructureList, int currentIndex, Structure* structure, Structure* prototypeStructure, const Identifier& ident, const PropertySlot& slot, size_t cachedOffset)
219         {
220             JIT jit(globalData, codeBlock);
221             jit.privateCompileGetByIdProtoList(stubInfo, prototypeStructureList, currentIndex, structure, prototypeStructure, ident, slot, cachedOffset, callFrame);
222         }
223         static void compileGetByIdChainList(JSGlobalData* globalData, CallFrame* callFrame, CodeBlock* codeBlock, StructureStubInfo* stubInfo, PolymorphicAccessStructureList* prototypeStructureList, int currentIndex, Structure* structure, StructureChain* chain, size_t count, const Identifier& ident, const PropertySlot& slot, size_t cachedOffset)
224         {
225             JIT jit(globalData, codeBlock);
226             jit.privateCompileGetByIdChainList(stubInfo, prototypeStructureList, currentIndex, structure, chain, count, ident, slot, cachedOffset, callFrame);
227         }
228
229         static void compileGetByIdChain(JSGlobalData* globalData, CallFrame* callFrame, CodeBlock* codeBlock, StructureStubInfo* stubInfo, Structure* structure, StructureChain* chain, size_t count, const Identifier& ident, const PropertySlot& slot, size_t cachedOffset, ReturnAddressPtr returnAddress)
230         {
231             JIT jit(globalData, codeBlock);
232             jit.privateCompileGetByIdChain(stubInfo, structure, chain, count, ident, slot, cachedOffset, returnAddress, callFrame);
233         }
234         
235         static void compilePutByIdTransition(JSGlobalData* globalData, CodeBlock* codeBlock, StructureStubInfo* stubInfo, Structure* oldStructure, Structure* newStructure, size_t cachedOffset, StructureChain* chain, ReturnAddressPtr returnAddress, bool direct)
236         {
237             JIT jit(globalData, codeBlock);
238             jit.privateCompilePutByIdTransition(stubInfo, oldStructure, newStructure, cachedOffset, chain, returnAddress, direct);
239         }
240
241         static PassRefPtr<ExecutableMemoryHandle> compileCTIMachineTrampolines(JSGlobalData* globalData, TrampolineStructure *trampolines)
242         {
243             if (!globalData->canUseJIT())
244                 return 0;
245             JIT jit(globalData, 0);
246             return jit.privateCompileCTIMachineTrampolines(globalData, trampolines);
247         }
248
249         static CodeRef compileCTINativeCall(JSGlobalData* globalData, NativeFunction func)
250         {
251             if (!globalData->canUseJIT())
252                 return CodeRef();
253             JIT jit(globalData, 0);
254             return jit.privateCompileCTINativeCall(globalData, func);
255         }
256
257         static void resetPatchGetById(RepatchBuffer&, StructureStubInfo*);
258         static void resetPatchPutById(RepatchBuffer&, StructureStubInfo*);
259         static void patchGetByIdSelf(CodeBlock* codeblock, StructureStubInfo*, Structure*, size_t cachedOffset, ReturnAddressPtr returnAddress);
260         static void patchPutByIdReplace(CodeBlock* codeblock, StructureStubInfo*, Structure*, size_t cachedOffset, ReturnAddressPtr returnAddress, bool direct);
261         static void patchMethodCallProto(JSGlobalData&, CodeBlock* codeblock, MethodCallLinkInfo&, JSObject*, Structure*, JSObject*, ReturnAddressPtr);
262
263         static void compilePatchGetArrayLength(JSGlobalData* globalData, CodeBlock* codeBlock, ReturnAddressPtr returnAddress)
264         {
265             JIT jit(globalData, codeBlock);
266             return jit.privateCompilePatchGetArrayLength(returnAddress);
267         }
268
269         static void linkFor(JSFunction* callee, CodeBlock* callerCodeBlock, CodeBlock* calleeCodeBlock, CodePtr, CallLinkInfo*, JSGlobalData*, CodeSpecializationKind);
270
271     private:
272         struct JSRInfo {
273             DataLabelPtr storeLocation;
274             Label target;
275
276             JSRInfo(DataLabelPtr storeLocation, Label targetLocation)
277                 : storeLocation(storeLocation)
278                 , target(targetLocation)
279             {
280             }
281         };
282
283         JIT(JSGlobalData*, CodeBlock* = 0);
284
285         void privateCompileMainPass();
286         void privateCompileLinkPass();
287         void privateCompileSlowCases();
288         JITCode privateCompile(CodePtr* functionEntryArityCheck);
289         void privateCompileGetByIdProto(StructureStubInfo*, Structure*, Structure* prototypeStructure, const Identifier&, const PropertySlot&, size_t cachedOffset, ReturnAddressPtr returnAddress, CallFrame* callFrame);
290         void privateCompileGetByIdSelfList(StructureStubInfo*, PolymorphicAccessStructureList*, int, Structure*, const Identifier&, const PropertySlot&, size_t cachedOffset);
291         void privateCompileGetByIdProtoList(StructureStubInfo*, PolymorphicAccessStructureList*, int, Structure*, Structure* prototypeStructure, const Identifier&, const PropertySlot&, size_t cachedOffset, CallFrame* callFrame);
292         void privateCompileGetByIdChainList(StructureStubInfo*, PolymorphicAccessStructureList*, int, Structure*, StructureChain* chain, size_t count, const Identifier&, const PropertySlot&, size_t cachedOffset, CallFrame* callFrame);
293         void privateCompileGetByIdChain(StructureStubInfo*, Structure*, StructureChain*, size_t count, const Identifier&, const PropertySlot&, size_t cachedOffset, ReturnAddressPtr returnAddress, CallFrame* callFrame);
294         void privateCompilePutByIdTransition(StructureStubInfo*, Structure*, Structure*, size_t cachedOffset, StructureChain*, ReturnAddressPtr returnAddress, bool direct);
295
296         PassRefPtr<ExecutableMemoryHandle> privateCompileCTIMachineTrampolines(JSGlobalData*, TrampolineStructure*);
297         Label privateCompileCTINativeCall(JSGlobalData*, bool isConstruct = false);
298         CodeRef privateCompileCTINativeCall(JSGlobalData*, NativeFunction);
299         void privateCompilePatchGetArrayLength(ReturnAddressPtr returnAddress);
300
301         static bool isDirectPutById(StructureStubInfo*);
302
303         void addSlowCase(Jump);
304         void addSlowCase(JumpList);
305         void addSlowCase();
306         void addJump(Jump, int);
307         void emitJumpSlowToHot(Jump, int);
308
309         void compileOpCall(OpcodeID, Instruction*, unsigned callLinkInfoIndex);
310         void compileOpCallSlowCase(OpcodeID, Instruction*, Vector<SlowCaseEntry>::iterator&, unsigned callLinkInfoIndex);
311         void compileLoadVarargs(Instruction*);
312         void compileCallEval();
313         void compileCallEvalSlowCase(Vector<SlowCaseEntry>::iterator&);
314
315         enum CompileOpStrictEqType { OpStrictEq, OpNStrictEq };
316         void compileOpStrictEq(Instruction* instruction, CompileOpStrictEqType type);
317         bool isOperandConstantImmediateDouble(unsigned src);
318         
319         void emitLoadDouble(int index, FPRegisterID value);
320         void emitLoadInt32ToDouble(int index, FPRegisterID value);
321         Jump emitJumpIfNotObject(RegisterID structureReg);
322         Jump emitJumpIfNotType(RegisterID baseReg, RegisterID scratchReg, JSType);
323
324         void testPrototype(JSValue, JumpList& failureCases);
325
326         enum WriteBarrierMode { UnconditionalWriteBarrier, ShouldFilterImmediates };
327         // value register in write barrier is used before any scratch registers
328         // so may safely be the same as either of the scratch registers.
329         void emitWriteBarrier(RegisterID owner, RegisterID valueTag, RegisterID scratch, RegisterID scratch2, WriteBarrierMode, WriteBarrierUseKind);
330         void emitWriteBarrier(JSCell* owner, RegisterID value, RegisterID scratch, WriteBarrierMode, WriteBarrierUseKind);
331
332         template<typename ClassType, typename StructureType> void emitAllocateBasicJSObject(StructureType, RegisterID result, RegisterID storagePtr);
333         template<typename T> void emitAllocateJSFinalObject(T structure, RegisterID result, RegisterID storagePtr);
334         void emitAllocateJSFunction(FunctionExecutable*, RegisterID scopeChain, RegisterID result, RegisterID storagePtr);
335         
336         enum ValueProfilingSiteKind { FirstProfilingSite, SubsequentProfilingSite };
337 #if ENABLE(VALUE_PROFILER)
338         // This assumes that the value to profile is in regT0 and that regT3 is available for
339         // scratch.
340         void emitValueProfilingSite(ValueProfile*);
341         void emitValueProfilingSite(ValueProfilingSiteKind);
342 #else
343         void emitValueProfilingSite(ValueProfilingSiteKind) { }
344 #endif
345
346 #if USE(JSVALUE32_64)
347         bool getOperandConstantImmediateInt(unsigned op1, unsigned op2, unsigned& op, int32_t& constant);
348
349         void emitLoadTag(int index, RegisterID tag);
350         void emitLoadPayload(int index, RegisterID payload);
351
352         void emitLoad(const JSValue& v, RegisterID tag, RegisterID payload);
353         void emitLoad(int index, RegisterID tag, RegisterID payload, RegisterID base = callFrameRegister);
354         void emitLoad2(int index1, RegisterID tag1, RegisterID payload1, int index2, RegisterID tag2, RegisterID payload2);
355
356         void emitStore(int index, RegisterID tag, RegisterID payload, RegisterID base = callFrameRegister);
357         void emitStore(int index, const JSValue constant, RegisterID base = callFrameRegister);
358         void emitStoreInt32(int index, RegisterID payload, bool indexIsInt32 = false);
359         void emitStoreInt32(int index, TrustedImm32 payload, bool indexIsInt32 = false);
360         void emitStoreAndMapInt32(int index, RegisterID tag, RegisterID payload, bool indexIsInt32, size_t opcodeLength);
361         void emitStoreCell(int index, RegisterID payload, bool indexIsCell = false);
362         void emitStoreBool(int index, RegisterID payload, bool indexIsBool = false);
363         void emitStoreDouble(int index, FPRegisterID value);
364
365         bool isLabeled(unsigned bytecodeOffset);
366         void map(unsigned bytecodeOffset, int virtualRegisterIndex, RegisterID tag, RegisterID payload);
367         void unmap(RegisterID);
368         void unmap();
369         bool isMapped(int virtualRegisterIndex);
370         bool getMappedPayload(int virtualRegisterIndex, RegisterID& payload);
371         bool getMappedTag(int virtualRegisterIndex, RegisterID& tag);
372
373         void emitJumpSlowCaseIfNotJSCell(int virtualRegisterIndex);
374         void emitJumpSlowCaseIfNotJSCell(int virtualRegisterIndex, RegisterID tag);
375
376         void compileGetByIdHotPath();
377         void compileGetByIdSlowCase(int resultVReg, int baseVReg, Identifier* ident, Vector<SlowCaseEntry>::iterator& iter, bool isMethodCheck = false);
378         void compileGetDirectOffset(RegisterID base, RegisterID resultTag, RegisterID resultPayload, size_t cachedOffset);
379         void compileGetDirectOffset(JSObject* base, RegisterID resultTag, RegisterID resultPayload, size_t cachedOffset);
380         void compileGetDirectOffset(RegisterID base, RegisterID resultTag, RegisterID resultPayload, RegisterID offset);
381         void compilePutDirectOffset(RegisterID base, RegisterID valueTag, RegisterID valuePayload, size_t cachedOffset);
382
383         // Arithmetic opcode helpers
384         void emitAdd32Constant(unsigned dst, unsigned op, int32_t constant, ResultType opType);
385         void emitSub32Constant(unsigned dst, unsigned op, int32_t constant, ResultType opType);
386         void emitBinaryDoubleOp(OpcodeID, unsigned dst, unsigned op1, unsigned op2, OperandTypes, JumpList& notInt32Op1, JumpList& notInt32Op2, bool op1IsInRegisters = true, bool op2IsInRegisters = true);
387
388 #if CPU(X86)
389         // These architecture specific value are used to enable patching - see comment on op_put_by_id.
390         static const int patchOffsetPutByIdStructure = 7;
391         static const int patchOffsetPutByIdPropertyMapOffset1 = 22;
392         static const int patchOffsetPutByIdPropertyMapOffset2 = 28;
393         // These architecture specific value are used to enable patching - see comment on op_get_by_id.
394         static const int patchOffsetGetByIdStructure = 7;
395         static const int patchOffsetGetByIdBranchToSlowCase = 13;
396         static const int patchOffsetGetByIdPropertyMapOffset1 = 19;
397         static const int patchOffsetGetByIdPropertyMapOffset2 = 22;
398         static const int patchOffsetGetByIdPutResult = 22;
399 #if ENABLE(OPCODE_SAMPLING)
400         static const int patchOffsetGetByIdSlowCaseCall = 37;
401 #else
402         static const int patchOffsetGetByIdSlowCaseCall = 33;
403 #endif
404         static const int patchOffsetOpCallCompareToJump = 6;
405
406         static const int patchOffsetMethodCheckProtoObj = 11;
407         static const int patchOffsetMethodCheckProtoStruct = 18;
408         static const int patchOffsetMethodCheckPutFunction = 29;
409 #elif CPU(ARM_TRADITIONAL)
410         // These architecture specific value are used to enable patching - see comment on op_put_by_id.
411         static const int patchOffsetPutByIdStructure = 4;
412         static const int patchOffsetPutByIdPropertyMapOffset1 = 20;
413         static const int patchOffsetPutByIdPropertyMapOffset2 = 28;
414         // These architecture specific value are used to enable patching - see comment on op_get_by_id.
415         static const int patchOffsetGetByIdStructure = 4;
416         static const int patchOffsetGetByIdBranchToSlowCase = 16;
417         static const int patchOffsetGetByIdPropertyMapOffset1 = 20;
418         static const int patchOffsetGetByIdPropertyMapOffset2 = 28;
419         static const int patchOffsetGetByIdPutResult = 36;
420 #if ENABLE(OPCODE_SAMPLING)
421         #error "OPCODE_SAMPLING is not yet supported"
422 #else
423         static const int patchOffsetGetByIdSlowCaseCall = 40;
424 #endif
425         static const int patchOffsetOpCallCompareToJump = 12;
426
427         static const int patchOffsetMethodCheckProtoObj = 12;
428         static const int patchOffsetMethodCheckProtoStruct = 20;
429         static const int patchOffsetMethodCheckPutFunction = 32;
430
431         // sequenceOpCall
432         static const int sequenceOpCallInstructionSpace = 12;
433         static const int sequenceOpCallConstantSpace = 2;
434         // sequenceMethodCheck
435         static const int sequenceMethodCheckInstructionSpace = 40;
436         static const int sequenceMethodCheckConstantSpace = 6;
437         // sequenceGetByIdHotPath
438         static const int sequenceGetByIdHotPathInstructionSpace = 36;
439         static const int sequenceGetByIdHotPathConstantSpace = 4;
440         // sequenceGetByIdSlowCase
441         static const int sequenceGetByIdSlowCaseInstructionSpace = 56;
442         static const int sequenceGetByIdSlowCaseConstantSpace = 3;
443         // sequencePutById
444         static const int sequencePutByIdInstructionSpace = 36;
445         static const int sequencePutByIdConstantSpace = 4;
446 #elif CPU(ARM_THUMB2)
447         // These architecture specific value are used to enable patching - see comment on op_put_by_id.
448         static const int patchOffsetPutByIdStructure = 10;
449         static const int patchOffsetPutByIdPropertyMapOffset1 = 36;
450         static const int patchOffsetPutByIdPropertyMapOffset2 = 48;
451         // These architecture specific value are used to enable patching - see comment on op_get_by_id.
452         static const int patchOffsetGetByIdStructure = 10;
453         static const int patchOffsetGetByIdBranchToSlowCase = 26;
454         static const int patchOffsetGetByIdPropertyMapOffset1 = 28;
455         static const int patchOffsetGetByIdPropertyMapOffset2 = 30;
456         static const int patchOffsetGetByIdPutResult = 32;
457 #if ENABLE(OPCODE_SAMPLING)
458         #error "OPCODE_SAMPLING is not yet supported"
459 #else
460         static const int patchOffsetGetByIdSlowCaseCall = 40;
461 #endif
462         static const int patchOffsetOpCallCompareToJump = 16;
463
464         static const int patchOffsetMethodCheckProtoObj = 24;
465         static const int patchOffsetMethodCheckProtoStruct = 34;
466         static const int patchOffsetMethodCheckPutFunction = 58;
467
468         // sequenceOpCall
469         static const int sequenceOpCallInstructionSpace = 12;
470         static const int sequenceOpCallConstantSpace = 2;
471         // sequenceMethodCheck
472         static const int sequenceMethodCheckInstructionSpace = 40;
473         static const int sequenceMethodCheckConstantSpace = 6;
474         // sequenceGetByIdHotPath
475         static const int sequenceGetByIdHotPathInstructionSpace = 36;
476         static const int sequenceGetByIdHotPathConstantSpace = 4;
477         // sequenceGetByIdSlowCase
478         static const int sequenceGetByIdSlowCaseInstructionSpace = 40;
479         static const int sequenceGetByIdSlowCaseConstantSpace = 2;
480         // sequencePutById
481         static const int sequencePutByIdInstructionSpace = 36;
482         static const int sequencePutByIdConstantSpace = 4;
483 #elif CPU(MIPS)
484 #if WTF_MIPS_ISA(1)
485         static const int patchOffsetPutByIdStructure = 16;
486         static const int patchOffsetPutByIdPropertyMapOffset1 = 56;
487         static const int patchOffsetPutByIdPropertyMapOffset2 = 72;
488         static const int patchOffsetGetByIdStructure = 16;
489         static const int patchOffsetGetByIdBranchToSlowCase = 48;
490         static const int patchOffsetGetByIdPropertyMapOffset1 = 56;
491         static const int patchOffsetGetByIdPropertyMapOffset2 = 76;
492         static const int patchOffsetGetByIdPutResult = 96;
493 #if ENABLE(OPCODE_SAMPLING)
494         #error "OPCODE_SAMPLING is not yet supported"
495 #else
496         static const int patchOffsetGetByIdSlowCaseCall = 56;
497 #endif
498         static const int patchOffsetOpCallCompareToJump = 32;
499         static const int patchOffsetMethodCheckProtoObj = 32;
500         static const int patchOffsetMethodCheckProtoStruct = 56;
501         static const int patchOffsetMethodCheckPutFunction = 88;
502 #else // WTF_MIPS_ISA(1)
503         static const int patchOffsetPutByIdStructure = 12;
504         static const int patchOffsetPutByIdPropertyMapOffset1 = 48;
505         static const int patchOffsetPutByIdPropertyMapOffset2 = 64;
506         static const int patchOffsetGetByIdStructure = 12;
507         static const int patchOffsetGetByIdBranchToSlowCase = 44;
508         static const int patchOffsetGetByIdPropertyMapOffset1 = 48;
509         static const int patchOffsetGetByIdPropertyMapOffset2 = 64;
510         static const int patchOffsetGetByIdPutResult = 80;
511 #if ENABLE(OPCODE_SAMPLING)
512         #error "OPCODE_SAMPLING is not yet supported"
513 #else
514         static const int patchOffsetGetByIdSlowCaseCall = 56;
515 #endif
516         static const int patchOffsetOpCallCompareToJump = 32;
517         static const int patchOffsetMethodCheckProtoObj = 32;
518         static const int patchOffsetMethodCheckProtoStruct = 52;
519         static const int patchOffsetMethodCheckPutFunction = 84;
520 #endif
521 #elif CPU(SH4)
522        // These architecture specific value are used to enable patching - see comment on op_put_by_id.
523         static const int patchOffsetGetByIdStructure = 6;
524         static const int patchOffsetPutByIdPropertyMapOffset = 24;
525         static const int patchOffsetPutByIdStructure = 6;
526         // These architecture specific value are used to enable patching - see comment on op_get_by_id.
527         static const int patchOffsetGetByIdBranchToSlowCase = 10;
528         static const int patchOffsetGetByIdPropertyMapOffset = 24;
529         static const int patchOffsetGetByIdPutResult = 24;
530
531         // sequenceOpCall
532         static const int sequenceOpCallInstructionSpace = 12;
533         static const int sequenceOpCallConstantSpace = 2;
534         // sequenceMethodCheck
535         static const int sequenceMethodCheckInstructionSpace = 40;
536         static const int sequenceMethodCheckConstantSpace = 6;
537         // sequenceGetByIdHotPath
538         static const int sequenceGetByIdHotPathInstructionSpace = 36;
539         static const int sequenceGetByIdHotPathConstantSpace = 5;
540         // sequenceGetByIdSlowCase
541         static const int sequenceGetByIdSlowCaseInstructionSpace = 30;
542         static const int sequenceGetByIdSlowCaseConstantSpace = 3;
543         // sequencePutById
544         static const int sequencePutByIdInstructionSpace = 36;
545         static const int sequencePutByIdConstantSpace = 5;
546
547         static const int patchOffsetGetByIdPropertyMapOffset1 = 20;
548         static const int patchOffsetGetByIdPropertyMapOffset2 = 22;
549
550         static const int patchOffsetPutByIdPropertyMapOffset1 = 20;
551         static const int patchOffsetPutByIdPropertyMapOffset2 = 26;
552
553 #if ENABLE(OPCODE_SAMPLING)
554         static const int patchOffsetGetByIdSlowCaseCall = 0; // FIMXE
555 #else
556         static const int patchOffsetGetByIdSlowCaseCall = 26;
557 #endif
558         static const int patchOffsetOpCallCompareToJump = 4;
559
560         static const int patchOffsetMethodCheckProtoObj = 12;
561         static const int patchOffsetMethodCheckProtoStruct = 20;
562         static const int patchOffsetMethodCheckPutFunction = 32;
563 #else
564 #error "JSVALUE32_64 not supported on this platform."
565 #endif
566
567 #else // USE(JSVALUE32_64)
568         void emitGetVirtualRegister(int src, RegisterID dst);
569         void emitGetVirtualRegisters(int src1, RegisterID dst1, int src2, RegisterID dst2);
570         void emitPutVirtualRegister(unsigned dst, RegisterID from = regT0);
571         void emitStoreCell(unsigned dst, RegisterID payload, bool /* only used in JSValue32_64 */ = false)
572         {
573             emitPutVirtualRegister(dst, payload);
574         }
575
576         int32_t getConstantOperandImmediateInt(unsigned src);
577
578         void killLastResultRegister();
579
580         Jump emitJumpIfJSCell(RegisterID);
581         Jump emitJumpIfBothJSCells(RegisterID, RegisterID, RegisterID);
582         void emitJumpSlowCaseIfJSCell(RegisterID);
583         Jump emitJumpIfNotJSCell(RegisterID);
584         void emitJumpSlowCaseIfNotJSCell(RegisterID);
585         void emitJumpSlowCaseIfNotJSCell(RegisterID, int VReg);
586 #if USE(JSVALUE32_64)
587         JIT::Jump emitJumpIfImmediateNumber(RegisterID reg)
588         {
589             return emitJumpIfImmediateInteger(reg);
590         }
591         
592         JIT::Jump emitJumpIfNotImmediateNumber(RegisterID reg)
593         {
594             return emitJumpIfNotImmediateInteger(reg);
595         }
596 #endif
597         Jump emitJumpIfImmediateInteger(RegisterID);
598         Jump emitJumpIfNotImmediateInteger(RegisterID);
599         Jump emitJumpIfNotImmediateIntegers(RegisterID, RegisterID, RegisterID);
600         void emitJumpSlowCaseIfNotImmediateInteger(RegisterID);
601         void emitJumpSlowCaseIfNotImmediateNumber(RegisterID);
602         void emitJumpSlowCaseIfNotImmediateIntegers(RegisterID, RegisterID, RegisterID);
603
604 #if USE(JSVALUE32_64)
605         void emitFastArithDeTagImmediate(RegisterID);
606         Jump emitFastArithDeTagImmediateJumpIfZero(RegisterID);
607 #endif
608         void emitFastArithReTagImmediate(RegisterID src, RegisterID dest);
609         void emitFastArithIntToImmNoCheck(RegisterID src, RegisterID dest);
610
611         void emitTagAsBoolImmediate(RegisterID reg);
612         void compileBinaryArithOp(OpcodeID, unsigned dst, unsigned src1, unsigned src2, OperandTypes opi);
613 #if USE(JSVALUE64)
614         void compileBinaryArithOpSlowCase(OpcodeID, Vector<SlowCaseEntry>::iterator&, unsigned dst, unsigned src1, unsigned src2, OperandTypes, bool op1HasImmediateIntFastCase, bool op2HasImmediateIntFastCase);
615 #else
616         void compileBinaryArithOpSlowCase(OpcodeID, Vector<SlowCaseEntry>::iterator&, unsigned dst, unsigned src1, unsigned src2, OperandTypes);
617 #endif
618
619         void compileGetByIdHotPath(int baseVReg, Identifier*);
620         void compileGetByIdSlowCase(int resultVReg, int baseVReg, Identifier* ident, Vector<SlowCaseEntry>::iterator& iter, bool isMethodCheck = false);
621         void compileGetDirectOffset(RegisterID base, RegisterID result, size_t cachedOffset);
622         void compileGetDirectOffset(JSObject* base, RegisterID result, size_t cachedOffset);
623         void compileGetDirectOffset(RegisterID base, RegisterID result, RegisterID offset, RegisterID scratch);
624         void compilePutDirectOffset(RegisterID base, RegisterID value, size_t cachedOffset);
625
626 #if CPU(X86_64)
627         // These architecture specific value are used to enable patching - see comment on op_put_by_id.
628         static const int patchOffsetPutByIdStructure = 10;
629         static const int patchOffsetPutByIdPropertyMapOffset = 31;
630         // These architecture specific value are used to enable patching - see comment on op_get_by_id.
631         static const int patchOffsetGetByIdStructure = 10;
632         static const int patchOffsetGetByIdBranchToSlowCase = 20;
633         static const int patchOffsetGetByIdPropertyMapOffset = 28;
634         static const int patchOffsetGetByIdPutResult = 28;
635 #if ENABLE(OPCODE_SAMPLING)
636         static const int patchOffsetGetByIdSlowCaseCall = 64;
637 #else
638         static const int patchOffsetGetByIdSlowCaseCall = 54;
639 #endif
640         static const int patchOffsetOpCallCompareToJump = 9;
641
642         static const int patchOffsetMethodCheckProtoObj = 20;
643         static const int patchOffsetMethodCheckProtoStruct = 30;
644         static const int patchOffsetMethodCheckPutFunction = 50;
645 #elif CPU(X86)
646         // These architecture specific value are used to enable patching - see comment on op_put_by_id.
647         static const int patchOffsetPutByIdStructure = 7;
648         static const int patchOffsetPutByIdPropertyMapOffset = 22;
649         // These architecture specific value are used to enable patching - see comment on op_get_by_id.
650         static const int patchOffsetGetByIdStructure = 7;
651         static const int patchOffsetGetByIdBranchToSlowCase = 13;
652         static const int patchOffsetGetByIdPropertyMapOffset = 22;
653         static const int patchOffsetGetByIdPutResult = 22;
654 #if ENABLE(OPCODE_SAMPLING)
655         static const int patchOffsetGetByIdSlowCaseCall = 33;
656 #else
657         static const int patchOffsetGetByIdSlowCaseCall = 23;
658 #endif
659         static const int patchOffsetOpCallCompareToJump = 6;
660
661         static const int patchOffsetMethodCheckProtoObj = 11;
662         static const int patchOffsetMethodCheckProtoStruct = 18;
663         static const int patchOffsetMethodCheckPutFunction = 29;
664 #elif CPU(ARM_THUMB2)
665         // These architecture specific value are used to enable patching - see comment on op_put_by_id.
666         static const int patchOffsetPutByIdStructure = 10;
667         static const int patchOffsetPutByIdPropertyMapOffset = 46;
668         // These architecture specific value are used to enable patching - see comment on op_get_by_id.
669         static const int patchOffsetGetByIdStructure = 10;
670         static const int patchOffsetGetByIdBranchToSlowCase = 26;
671         static const int patchOffsetGetByIdPropertyMapOffset = 46;
672         static const int patchOffsetGetByIdPutResult = 50;
673 #if ENABLE(OPCODE_SAMPLING)
674         static const int patchOffsetGetByIdSlowCaseCall = 0; // FIMXE
675 #else
676         static const int patchOffsetGetByIdSlowCaseCall = 28;
677 #endif
678         static const int patchOffsetOpCallCompareToJump = 16;
679
680         static const int patchOffsetMethodCheckProtoObj = 24;
681         static const int patchOffsetMethodCheckProtoStruct = 34;
682         static const int patchOffsetMethodCheckPutFunction = 58;
683 #elif CPU(ARM_TRADITIONAL)
684         // These architecture specific value are used to enable patching - see comment on op_put_by_id.
685         static const int patchOffsetPutByIdStructure = 4;
686         static const int patchOffsetPutByIdPropertyMapOffset = 20;
687         // These architecture specific value are used to enable patching - see comment on op_get_by_id.
688         static const int patchOffsetGetByIdStructure = 4;
689         static const int patchOffsetGetByIdBranchToSlowCase = 16;
690         static const int patchOffsetGetByIdPropertyMapOffset = 20;
691         static const int patchOffsetGetByIdPutResult = 28;
692 #if ENABLE(OPCODE_SAMPLING)
693         #error "OPCODE_SAMPLING is not yet supported"
694 #else
695         static const int patchOffsetGetByIdSlowCaseCall = 28;
696 #endif
697         static const int patchOffsetOpCallCompareToJump = 12;
698
699         static const int patchOffsetMethodCheckProtoObj = 12;
700         static const int patchOffsetMethodCheckProtoStruct = 20;
701         static const int patchOffsetMethodCheckPutFunction = 32;
702
703         // sequenceOpCall
704         static const int sequenceOpCallInstructionSpace = 12;
705         static const int sequenceOpCallConstantSpace = 2;
706         // sequenceMethodCheck
707         static const int sequenceMethodCheckInstructionSpace = 40;
708         static const int sequenceMethodCheckConstantSpace = 6;
709         // sequenceGetByIdHotPath
710         static const int sequenceGetByIdHotPathInstructionSpace = 28;
711         static const int sequenceGetByIdHotPathConstantSpace = 3;
712         // sequenceGetByIdSlowCase
713         static const int sequenceGetByIdSlowCaseInstructionSpace = 32;
714         static const int sequenceGetByIdSlowCaseConstantSpace = 2;
715         // sequencePutById
716         static const int sequencePutByIdInstructionSpace = 28;
717         static const int sequencePutByIdConstantSpace = 3;
718 #elif CPU(MIPS)
719 #if WTF_MIPS_ISA(1)
720         static const int patchOffsetPutByIdStructure = 16;
721         static const int patchOffsetPutByIdPropertyMapOffset = 68;
722         static const int patchOffsetGetByIdStructure = 16;
723         static const int patchOffsetGetByIdBranchToSlowCase = 48;
724         static const int patchOffsetGetByIdPropertyMapOffset = 68;
725         static const int patchOffsetGetByIdPutResult = 88;
726 #if ENABLE(OPCODE_SAMPLING)
727         #error "OPCODE_SAMPLING is not yet supported"
728 #else
729         static const int patchOffsetGetByIdSlowCaseCall = 40;
730 #endif
731         static const int patchOffsetOpCallCompareToJump = 32;
732         static const int patchOffsetMethodCheckProtoObj = 32;
733         static const int patchOffsetMethodCheckProtoStruct = 56;
734         static const int patchOffsetMethodCheckPutFunction = 88;
735 #else // WTF_MIPS_ISA(1)
736         static const int patchOffsetPutByIdStructure = 12;
737         static const int patchOffsetPutByIdPropertyMapOffset = 60;
738         static const int patchOffsetGetByIdStructure = 12;
739         static const int patchOffsetGetByIdBranchToSlowCase = 44;
740         static const int patchOffsetGetByIdPropertyMapOffset = 60;
741         static const int patchOffsetGetByIdPutResult = 76;
742 #if ENABLE(OPCODE_SAMPLING)
743         #error "OPCODE_SAMPLING is not yet supported"
744 #else
745         static const int patchOffsetGetByIdSlowCaseCall = 40;
746 #endif
747         static const int patchOffsetOpCallCompareToJump = 32;
748         static const int patchOffsetMethodCheckProtoObj = 32;
749         static const int patchOffsetMethodCheckProtoStruct = 52;
750         static const int patchOffsetMethodCheckPutFunction = 84;
751 #endif
752 #endif
753 #endif // USE(JSVALUE32_64)
754
755 #if (defined(ASSEMBLER_HAS_CONSTANT_POOL) && ASSEMBLER_HAS_CONSTANT_POOL)
756 #define BEGIN_UNINTERRUPTED_SEQUENCE(name) do { beginUninterruptedSequence(name ## InstructionSpace, name ## ConstantSpace); } while (false)
757 #define END_UNINTERRUPTED_SEQUENCE_FOR_PUT(name, dst) do { endUninterruptedSequence(name ## InstructionSpace, name ## ConstantSpace, dst); } while (false)
758 #define END_UNINTERRUPTED_SEQUENCE(name) END_UNINTERRUPTED_SEQUENCE_FOR_PUT(name, 0)
759
760         void beginUninterruptedSequence(int, int);
761         void endUninterruptedSequence(int, int, int);
762
763 #else
764 #define BEGIN_UNINTERRUPTED_SEQUENCE(name)  do { beginUninterruptedSequence(); } while (false)
765 #define END_UNINTERRUPTED_SEQUENCE(name)  do { endUninterruptedSequence(); } while (false)
766 #define END_UNINTERRUPTED_SEQUENCE_FOR_PUT(name, dst) do { endUninterruptedSequence(); } while (false)
767 #endif
768
769         void emit_compareAndJump(OpcodeID, unsigned op1, unsigned op2, unsigned target, RelationalCondition);
770         void emit_compareAndJumpSlow(unsigned op1, unsigned op2, unsigned target, DoubleCondition, int (JIT_STUB *stub)(STUB_ARGS_DECLARATION), bool invert, Vector<SlowCaseEntry>::iterator&);
771
772         void emit_op_add(Instruction*);
773         void emit_op_bitand(Instruction*);
774         void emit_op_bitnot(Instruction*);
775         void emit_op_bitor(Instruction*);
776         void emit_op_bitxor(Instruction*);
777         void emit_op_call(Instruction*);
778         void emit_op_call_eval(Instruction*);
779         void emit_op_call_varargs(Instruction*);
780         void emit_op_call_put_result(Instruction*);
781         void emit_op_catch(Instruction*);
782         void emit_op_construct(Instruction*);
783         void emit_op_get_callee(Instruction*);
784         void emit_op_create_this(Instruction*);
785         void emit_op_convert_this(Instruction*);
786         void emit_op_create_arguments(Instruction*);
787         void emit_op_debug(Instruction*);
788         void emit_op_del_by_id(Instruction*);
789         void emit_op_div(Instruction*);
790         void emit_op_end(Instruction*);
791         void emit_op_enter(Instruction*);
792         void emit_op_create_activation(Instruction*);
793         void emit_op_eq(Instruction*);
794         void emit_op_eq_null(Instruction*);
795         void emit_op_get_by_id(Instruction*);
796         void emit_op_get_arguments_length(Instruction*);
797         void emit_op_get_by_val(Instruction*);
798         void emit_op_get_argument_by_val(Instruction*);
799         void emit_op_get_by_pname(Instruction*);
800         void emit_op_get_global_var(Instruction*);
801         void emit_op_get_scoped_var(Instruction*);
802         void emit_op_init_lazy_reg(Instruction*);
803         void emit_op_check_has_instance(Instruction*);
804         void emit_op_instanceof(Instruction*);
805         void emit_op_jeq_null(Instruction*);
806         void emit_op_jfalse(Instruction*);
807         void emit_op_jmp(Instruction*);
808         void emit_op_jmp_scopes(Instruction*);
809         void emit_op_jneq_null(Instruction*);
810         void emit_op_jneq_ptr(Instruction*);
811         void emit_op_jless(Instruction*);
812         void emit_op_jlesseq(Instruction*);
813         void emit_op_jgreater(Instruction*);
814         void emit_op_jgreatereq(Instruction*);
815         void emit_op_jnless(Instruction*);
816         void emit_op_jnlesseq(Instruction*);
817         void emit_op_jngreater(Instruction*);
818         void emit_op_jngreatereq(Instruction*);
819         void emit_op_jsr(Instruction*);
820         void emit_op_jtrue(Instruction*);
821         void emit_op_loop(Instruction*);
822         void emit_op_loop_hint(Instruction*);
823         void emit_op_loop_if_less(Instruction*);
824         void emit_op_loop_if_lesseq(Instruction*);
825         void emit_op_loop_if_greater(Instruction*);
826         void emit_op_loop_if_greatereq(Instruction*);
827         void emit_op_loop_if_true(Instruction*);
828         void emit_op_loop_if_false(Instruction*);
829         void emit_op_lshift(Instruction*);
830         void emit_op_method_check(Instruction*);
831         void emit_op_mod(Instruction*);
832         void emit_op_mov(Instruction*);
833         void emit_op_mul(Instruction*);
834         void emit_op_negate(Instruction*);
835         void emit_op_neq(Instruction*);
836         void emit_op_neq_null(Instruction*);
837         void emit_op_new_array(Instruction*);
838         void emit_op_new_array_buffer(Instruction*);
839         void emit_op_new_func(Instruction*);
840         void emit_op_new_func_exp(Instruction*);
841         void emit_op_new_object(Instruction*);
842         void emit_op_new_regexp(Instruction*);
843         void emit_op_get_pnames(Instruction*);
844         void emit_op_next_pname(Instruction*);
845         void emit_op_not(Instruction*);
846         void emit_op_nstricteq(Instruction*);
847         void emit_op_pop_scope(Instruction*);
848         void emit_op_post_dec(Instruction*);
849         void emit_op_post_inc(Instruction*);
850         void emit_op_pre_dec(Instruction*);
851         void emit_op_pre_inc(Instruction*);
852         void emit_op_profile_did_call(Instruction*);
853         void emit_op_profile_will_call(Instruction*);
854         void emit_op_push_new_scope(Instruction*);
855         void emit_op_push_scope(Instruction*);
856         void emit_op_put_by_id(Instruction*);
857         void emit_op_put_by_index(Instruction*);
858         void emit_op_put_by_val(Instruction*);
859         void emit_op_put_getter(Instruction*);
860         void emit_op_put_global_var(Instruction*);
861         void emit_op_put_scoped_var(Instruction*);
862         void emit_op_put_setter(Instruction*);
863         void emit_op_resolve(Instruction*);
864         void emit_op_resolve_base(Instruction*);
865         void emit_op_ensure_property_exists(Instruction*);
866         void emit_op_resolve_global(Instruction*, bool dynamic = false);
867         void emit_op_resolve_global_dynamic(Instruction*);
868         void emit_op_resolve_skip(Instruction*);
869         void emit_op_resolve_with_base(Instruction*);
870         void emit_op_resolve_with_this(Instruction*);
871         void emit_op_ret(Instruction*);
872         void emit_op_ret_object_or_this(Instruction*);
873         void emit_op_rshift(Instruction*);
874         void emit_op_sret(Instruction*);
875         void emit_op_strcat(Instruction*);
876         void emit_op_stricteq(Instruction*);
877         void emit_op_sub(Instruction*);
878         void emit_op_switch_char(Instruction*);
879         void emit_op_switch_imm(Instruction*);
880         void emit_op_switch_string(Instruction*);
881         void emit_op_tear_off_activation(Instruction*);
882         void emit_op_tear_off_arguments(Instruction*);
883         void emit_op_throw(Instruction*);
884         void emit_op_throw_reference_error(Instruction*);
885         void emit_op_to_jsnumber(Instruction*);
886         void emit_op_to_primitive(Instruction*);
887         void emit_op_unexpected_load(Instruction*);
888         void emit_op_urshift(Instruction*);
889 #if ENABLE(JIT_USE_SOFT_MODULO)
890         void softModulo();
891 #endif
892
893         void emitSlow_op_add(Instruction*, Vector<SlowCaseEntry>::iterator&);
894         void emitSlow_op_bitand(Instruction*, Vector<SlowCaseEntry>::iterator&);
895         void emitSlow_op_bitnot(Instruction*, Vector<SlowCaseEntry>::iterator&);
896         void emitSlow_op_bitor(Instruction*, Vector<SlowCaseEntry>::iterator&);
897         void emitSlow_op_bitxor(Instruction*, Vector<SlowCaseEntry>::iterator&);
898         void emitSlow_op_call(Instruction*, Vector<SlowCaseEntry>::iterator&);
899         void emitSlow_op_call_eval(Instruction*, Vector<SlowCaseEntry>::iterator&);
900         void emitSlow_op_call_varargs(Instruction*, Vector<SlowCaseEntry>::iterator&);
901         void emitSlow_op_construct(Instruction*, Vector<SlowCaseEntry>::iterator&);
902         void emitSlow_op_convert_this(Instruction*, Vector<SlowCaseEntry>::iterator&);
903         void emitSlow_op_create_this(Instruction*, Vector<SlowCaseEntry>::iterator&);
904         void emitSlow_op_div(Instruction*, Vector<SlowCaseEntry>::iterator&);
905         void emitSlow_op_eq(Instruction*, Vector<SlowCaseEntry>::iterator&);
906         void emitSlow_op_get_by_id(Instruction*, Vector<SlowCaseEntry>::iterator&);
907         void emitSlow_op_get_arguments_length(Instruction*, Vector<SlowCaseEntry>::iterator&);
908         void emitSlow_op_get_by_val(Instruction*, Vector<SlowCaseEntry>::iterator&);
909         void emitSlow_op_get_argument_by_val(Instruction*, Vector<SlowCaseEntry>::iterator&);
910         void emitSlow_op_get_by_pname(Instruction*, Vector<SlowCaseEntry>::iterator&);
911         void emitSlow_op_check_has_instance(Instruction*, Vector<SlowCaseEntry>::iterator&);
912         void emitSlow_op_instanceof(Instruction*, Vector<SlowCaseEntry>::iterator&);
913         void emitSlow_op_jfalse(Instruction*, Vector<SlowCaseEntry>::iterator&);
914         void emitSlow_op_jless(Instruction*, Vector<SlowCaseEntry>::iterator&);
915         void emitSlow_op_jlesseq(Instruction*, Vector<SlowCaseEntry>::iterator&);
916         void emitSlow_op_jgreater(Instruction*, Vector<SlowCaseEntry>::iterator&);
917         void emitSlow_op_jgreatereq(Instruction*, Vector<SlowCaseEntry>::iterator&);
918         void emitSlow_op_jnless(Instruction*, Vector<SlowCaseEntry>::iterator&);
919         void emitSlow_op_jnlesseq(Instruction*, Vector<SlowCaseEntry>::iterator&);
920         void emitSlow_op_jngreater(Instruction*, Vector<SlowCaseEntry>::iterator&);
921         void emitSlow_op_jngreatereq(Instruction*, Vector<SlowCaseEntry>::iterator&);
922         void emitSlow_op_jtrue(Instruction*, Vector<SlowCaseEntry>::iterator&);
923         void emitSlow_op_loop_if_less(Instruction*, Vector<SlowCaseEntry>::iterator&);
924         void emitSlow_op_loop_if_lesseq(Instruction*, Vector<SlowCaseEntry>::iterator&);
925         void emitSlow_op_loop_if_greater(Instruction*, Vector<SlowCaseEntry>::iterator&);
926         void emitSlow_op_loop_if_greatereq(Instruction*, Vector<SlowCaseEntry>::iterator&);
927         void emitSlow_op_loop_if_true(Instruction*, Vector<SlowCaseEntry>::iterator&);
928         void emitSlow_op_loop_if_false(Instruction*, Vector<SlowCaseEntry>::iterator&);
929         void emitSlow_op_lshift(Instruction*, Vector<SlowCaseEntry>::iterator&);
930         void emitSlow_op_method_check(Instruction*, Vector<SlowCaseEntry>::iterator&);
931         void emitSlow_op_mod(Instruction*, Vector<SlowCaseEntry>::iterator&);
932         void emitSlow_op_mul(Instruction*, Vector<SlowCaseEntry>::iterator&);
933         void emitSlow_op_negate(Instruction*, Vector<SlowCaseEntry>::iterator&);
934         void emitSlow_op_neq(Instruction*, Vector<SlowCaseEntry>::iterator&);
935         void emitSlow_op_new_object(Instruction*, Vector<SlowCaseEntry>::iterator&);
936         void emitSlow_op_not(Instruction*, Vector<SlowCaseEntry>::iterator&);
937         void emitSlow_op_nstricteq(Instruction*, Vector<SlowCaseEntry>::iterator&);
938         void emitSlow_op_post_dec(Instruction*, Vector<SlowCaseEntry>::iterator&);
939         void emitSlow_op_post_inc(Instruction*, Vector<SlowCaseEntry>::iterator&);
940         void emitSlow_op_pre_dec(Instruction*, Vector<SlowCaseEntry>::iterator&);
941         void emitSlow_op_pre_inc(Instruction*, Vector<SlowCaseEntry>::iterator&);
942         void emitSlow_op_put_by_id(Instruction*, Vector<SlowCaseEntry>::iterator&);
943         void emitSlow_op_put_by_val(Instruction*, Vector<SlowCaseEntry>::iterator&);
944         void emitSlow_op_resolve_global(Instruction*, Vector<SlowCaseEntry>::iterator&);
945         void emitSlow_op_resolve_global_dynamic(Instruction*, Vector<SlowCaseEntry>::iterator&);
946         void emitSlow_op_rshift(Instruction*, Vector<SlowCaseEntry>::iterator&);
947         void emitSlow_op_stricteq(Instruction*, Vector<SlowCaseEntry>::iterator&);
948         void emitSlow_op_sub(Instruction*, Vector<SlowCaseEntry>::iterator&);
949         void emitSlow_op_to_jsnumber(Instruction*, Vector<SlowCaseEntry>::iterator&);
950         void emitSlow_op_to_primitive(Instruction*, Vector<SlowCaseEntry>::iterator&);
951         void emitSlow_op_urshift(Instruction*, Vector<SlowCaseEntry>::iterator&);
952         void emitSlow_op_new_func(Instruction*, Vector<SlowCaseEntry>::iterator&);
953         void emitSlow_op_new_func_exp(Instruction*, Vector<SlowCaseEntry>::iterator&);
954
955         
956         void emitRightShift(Instruction*, bool isUnsigned);
957         void emitRightShiftSlowCase(Instruction*, Vector<SlowCaseEntry>::iterator&, bool isUnsigned);
958
959         /* This function is deprecated. */
960         void emitGetJITStubArg(unsigned argumentNumber, RegisterID dst);
961
962         void emitInitRegister(unsigned dst);
963
964         void emitPutToCallFrameHeader(RegisterID from, RegisterFile::CallFrameHeaderEntry entry);
965         void emitPutCellToCallFrameHeader(RegisterID from, RegisterFile::CallFrameHeaderEntry);
966         void emitPutIntToCallFrameHeader(RegisterID from, RegisterFile::CallFrameHeaderEntry);
967         void emitPutImmediateToCallFrameHeader(void* value, RegisterFile::CallFrameHeaderEntry entry);
968         void emitGetFromCallFrameHeaderPtr(RegisterFile::CallFrameHeaderEntry entry, RegisterID to, RegisterID from = callFrameRegister);
969         void emitGetFromCallFrameHeader32(RegisterFile::CallFrameHeaderEntry entry, RegisterID to, RegisterID from = callFrameRegister);
970
971         JSValue getConstantOperand(unsigned src);
972         bool isOperandConstantImmediateInt(unsigned src);
973         bool isOperandConstantImmediateChar(unsigned src);
974
975         bool atJumpTarget();
976
977         Jump getSlowCase(Vector<SlowCaseEntry>::iterator& iter)
978         {
979             return iter++->from;
980         }
981         void linkSlowCase(Vector<SlowCaseEntry>::iterator& iter)
982         {
983             iter->from.link(this);
984             ++iter;
985         }
986         void linkDummySlowCase(Vector<SlowCaseEntry>::iterator& iter)
987         {
988             ASSERT(!iter->from.isSet());
989             ++iter;
990         }
991         void linkSlowCaseIfNotJSCell(Vector<SlowCaseEntry>::iterator&, int virtualRegisterIndex);
992
993         Jump checkStructure(RegisterID reg, Structure* structure);
994
995         void restoreArgumentReference();
996         void restoreArgumentReferenceForTrampoline();
997         void updateTopCallFrame();
998
999         Call emitNakedCall(CodePtr function = CodePtr());
1000
1001         void preserveReturnAddressAfterCall(RegisterID);
1002         void restoreReturnAddressBeforeReturn(RegisterID);
1003         void restoreReturnAddressBeforeReturn(Address);
1004
1005         // Loads the character value of a single character string into dst.
1006         void emitLoadCharacterString(RegisterID src, RegisterID dst, JumpList& failures);
1007         
1008         enum OptimizationCheckKind { LoopOptimizationCheck, RetOptimizationCheck };
1009 #if ENABLE(DFG_JIT)
1010         void emitOptimizationCheck(OptimizationCheckKind);
1011 #else
1012         void emitOptimizationCheck(OptimizationCheckKind) { }
1013 #endif
1014         
1015         void emitTimeoutCheck();
1016 #ifndef NDEBUG
1017         void printBytecodeOperandTypes(unsigned src1, unsigned src2);
1018 #endif
1019
1020 #if ENABLE(SAMPLING_FLAGS)
1021         void setSamplingFlag(int32_t);
1022         void clearSamplingFlag(int32_t);
1023 #endif
1024
1025 #if ENABLE(SAMPLING_COUNTERS)
1026         void emitCount(AbstractSamplingCounter&, int32_t = 1);
1027 #endif
1028
1029 #if ENABLE(OPCODE_SAMPLING)
1030         void sampleInstruction(Instruction*, bool = false);
1031 #endif
1032
1033 #if ENABLE(CODEBLOCK_SAMPLING)
1034         void sampleCodeBlock(CodeBlock*);
1035 #else
1036         void sampleCodeBlock(CodeBlock*) {}
1037 #endif
1038
1039 #if ENABLE(DFG_JIT)
1040         bool canBeOptimized() { return m_canBeOptimized; }
1041         bool shouldEmitProfiling() { return m_canBeOptimized; }
1042 #else
1043         bool canBeOptimized() { return false; }
1044         // Enables use of value profiler with tiered compilation turned off,
1045         // in which case all code gets profiled.
1046         bool shouldEmitProfiling() { return true; }
1047 #endif
1048
1049         Interpreter* m_interpreter;
1050         JSGlobalData* m_globalData;
1051         CodeBlock* m_codeBlock;
1052
1053         Vector<CallRecord> m_calls;
1054         Vector<Label> m_labels;
1055         Vector<PropertyStubCompilationInfo> m_propertyAccessCompilationInfo;
1056         Vector<StructureStubCompilationInfo> m_callStructureStubCompilationInfo;
1057         Vector<MethodCallCompilationInfo> m_methodCallCompilationInfo;
1058         Vector<JumpTable> m_jmpTable;
1059
1060         unsigned m_bytecodeOffset;
1061         Vector<JSRInfo> m_jsrSites;
1062         Vector<SlowCaseEntry> m_slowCases;
1063         Vector<SwitchRecord> m_switches;
1064
1065         unsigned m_propertyAccessInstructionIndex;
1066         unsigned m_globalResolveInfoIndex;
1067         unsigned m_callLinkInfoIndex;
1068
1069 #if USE(JSVALUE32_64)
1070         unsigned m_jumpTargetIndex;
1071         unsigned m_mappedBytecodeOffset;
1072         int m_mappedVirtualRegisterIndex;
1073         RegisterID m_mappedTag;
1074         RegisterID m_mappedPayload;
1075 #else
1076         int m_lastResultBytecodeRegister;
1077 #endif
1078         unsigned m_jumpTargetsPosition;
1079
1080 #ifndef NDEBUG
1081 #if defined(ASSEMBLER_HAS_CONSTANT_POOL) && ASSEMBLER_HAS_CONSTANT_POOL
1082         Label m_uninterruptedInstructionSequenceBegin;
1083         int m_uninterruptedConstantSequenceBegin;
1084 #endif
1085 #endif
1086         WeakRandom m_randomGenerator;
1087         static CodeRef stringGetByValStubGenerator(JSGlobalData*);
1088
1089 #if ENABLE(VALUE_PROFILER)
1090         bool m_canBeOptimized;
1091 #endif
1092     } JIT_CLASS_ALIGNMENT;
1093
1094     inline void JIT::emit_op_loop(Instruction* currentInstruction)
1095     {
1096         emitTimeoutCheck();
1097         emit_op_jmp(currentInstruction);
1098     }
1099
1100     inline void JIT::emit_op_loop_hint(Instruction*)
1101     {
1102         emitOptimizationCheck(LoopOptimizationCheck);
1103     }
1104
1105     inline void JIT::emit_op_loop_if_true(Instruction* currentInstruction)
1106     {
1107         emitTimeoutCheck();
1108         emit_op_jtrue(currentInstruction);
1109     }
1110
1111     inline void JIT::emitSlow_op_loop_if_true(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
1112     {
1113         emitSlow_op_jtrue(currentInstruction, iter);
1114     }
1115
1116     inline void JIT::emit_op_loop_if_false(Instruction* currentInstruction)
1117     {
1118         emitTimeoutCheck();
1119         emit_op_jfalse(currentInstruction);
1120     }
1121
1122     inline void JIT::emitSlow_op_loop_if_false(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
1123     {
1124         emitSlow_op_jfalse(currentInstruction, iter);
1125     }
1126
1127     inline void JIT::emit_op_loop_if_less(Instruction* currentInstruction)
1128     {
1129         emitTimeoutCheck();
1130         emit_op_jless(currentInstruction);
1131     }
1132
1133     inline void JIT::emitSlow_op_loop_if_less(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
1134     {
1135         emitSlow_op_jless(currentInstruction, iter);
1136     }
1137
1138     inline void JIT::emit_op_loop_if_lesseq(Instruction* currentInstruction)
1139     {
1140         emitTimeoutCheck();
1141         emit_op_jlesseq(currentInstruction);
1142     }
1143
1144     inline void JIT::emitSlow_op_loop_if_lesseq(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
1145     {
1146         emitSlow_op_jlesseq(currentInstruction, iter);
1147     }
1148
1149     inline void JIT::emit_op_loop_if_greater(Instruction* currentInstruction)
1150     {
1151         emitTimeoutCheck();
1152         emit_op_jgreater(currentInstruction);
1153     }
1154
1155     inline void JIT::emitSlow_op_loop_if_greater(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
1156     {
1157         emitSlow_op_jgreater(currentInstruction, iter);
1158     }
1159
1160     inline void JIT::emit_op_loop_if_greatereq(Instruction* currentInstruction)
1161     {
1162         emitTimeoutCheck();
1163         emit_op_jgreatereq(currentInstruction);
1164     }
1165
1166     inline void JIT::emitSlow_op_loop_if_greatereq(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
1167     {
1168         emitSlow_op_jgreatereq(currentInstruction, iter);
1169     }
1170
1171 } // namespace JSC
1172
1173 #endif // ENABLE(JIT)
1174
1175 #endif // JIT_h