X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/9dae56ea45a0f5f8136a5c93d6f3a7f99399ca73..217a6308cd6a1dc049a0bb69263bd4c91f91c4d0:/jit/JIT.h diff --git a/jit/JIT.h b/jit/JIT.h index d13fbb5..df8a19f 100644 --- a/jit/JIT.h +++ b/jit/JIT.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008 Apple Inc. All rights reserved. + * Copyright (C) 2008, 2012, 2013 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,104 +26,67 @@ #ifndef JIT_h #define JIT_h -#include -#include - #if ENABLE(JIT) -#define WTF_USE_CTI_REPATCH_PIC 1 +// Verbose logging of code generation +#define ENABLE_JIT_VERBOSE 0 +// Verbose logging for OSR-related code. +#define ENABLE_JIT_VERBOSE_OSR 0 -#include "Interpreter.h" -#include "Opcode.h" -#include "RegisterFile.h" -#include "MacroAssembler.h" -#include "Profiler.h" -#include -#include - -#if PLATFORM(X86_64) -#define STUB_ARGS_offset 0x10 +// We've run into some problems where changing the size of the class JIT leads to +// performance fluctuations. Try forcing alignment in an attempt to stabalize this. +#if COMPILER(GCC) +#define JIT_CLASS_ALIGNMENT __attribute__ ((aligned (32))) #else -#define STUB_ARGS_offset 0x0C +#define JIT_CLASS_ALIGNMENT #endif -#define STUB_ARGS_code (STUB_ARGS_offset) -#define STUB_ARGS_registerFile (STUB_ARGS_offset + 1) -#define STUB_ARGS_callFrame (STUB_ARGS_offset + 2) -#define STUB_ARGS_exception (STUB_ARGS_offset + 3) -#define STUB_ARGS_profilerReference (STUB_ARGS_offset + 4) -#define STUB_ARGS_globalData (STUB_ARGS_offset + 5) - -#define ARG_callFrame static_cast(ARGS[STUB_ARGS_callFrame]) -#define ARG_registerFile static_cast(ARGS[STUB_ARGS_registerFile]) -#define ARG_exception static_cast(ARGS[STUB_ARGS_exception]) -#define ARG_profilerReference static_cast(ARGS[STUB_ARGS_profilerReference]) -#define ARG_globalData static_cast(ARGS[STUB_ARGS_globalData]) - -#define ARG_setCallFrame(newCallFrame) (ARGS[STUB_ARGS_callFrame] = (newCallFrame)) - -#define ARG_src1 JSValuePtr::decode(static_cast(ARGS[1])) -#define ARG_src2 JSValuePtr::decode(static_cast(ARGS[2])) -#define ARG_src3 JSValuePtr::decode(static_cast(ARGS[3])) -#define ARG_src4 JSValuePtr::decode(static_cast(ARGS[4])) -#define ARG_src5 JSValuePtr::decode(static_cast(ARGS[5])) -#define ARG_id1 static_cast(ARGS[1]) -#define ARG_id2 static_cast(ARGS[2]) -#define ARG_id3 static_cast(ARGS[3]) -#define ARG_id4 static_cast(ARGS[4]) -#define ARG_int1 static_cast(reinterpret_cast(ARGS[1])) -#define ARG_int2 static_cast(reinterpret_cast(ARGS[2])) -#define ARG_int3 static_cast(reinterpret_cast(ARGS[3])) -#define ARG_int4 static_cast(reinterpret_cast(ARGS[4])) -#define ARG_int5 static_cast(reinterpret_cast(ARGS[5])) -#define ARG_int6 static_cast(reinterpret_cast(ARGS[6])) -#define ARG_func1 static_cast(ARGS[1]) -#define ARG_funcexp1 static_cast(ARGS[1]) -#define ARG_regexp1 static_cast(ARGS[1]) -#define ARG_pni1 static_cast(ARGS[1]) -#define ARG_returnAddress2 static_cast(ARGS[2]) -#define ARG_codeBlock4 static_cast(ARGS[4]) - -#define STUB_RETURN_ADDRESS_SLOT (ARGS[-1]) +#define ASSERT_JIT_OFFSET(actual, expected) ASSERT_WITH_MESSAGE(actual == expected, "JIT Offset \"%s\" should be %d, not %d.\n", #expected, static_cast(expected), static_cast(actual)); + +#include "CodeBlock.h" +#include "CompactJITCodeMap.h" +#include "Interpreter.h" +#include "JITDisassembler.h" +#include "JSInterfaceJIT.h" +#include "LegacyProfiler.h" +#include "Opcode.h" +#include "ResultType.h" +#include "UnusedPointer.h" +#include namespace JSC { class CodeBlock; + class FunctionExecutable; + class JIT; class JSPropertyNameIterator; class Interpreter; + class JSScope; + class JSStack; + class MarkedAllocator; class Register; - class RegisterFile; - class ScopeChainNode; - class SimpleJumpTable; - class StringJumpTable; class StructureChain; struct CallLinkInfo; struct Instruction; struct OperandTypes; struct PolymorphicAccessStructureList; + struct SimpleJumpTable; + struct StringJumpTable; struct StructureStubInfo; - typedef JSValueEncodedAsPointer* (JIT_STUB *CTIHelper_j)(STUB_ARGS); - typedef JSObject* (JIT_STUB *CTIHelper_o)(STUB_ARGS); - typedef JSPropertyNameIterator* (JIT_STUB *CTIHelper_p)(STUB_ARGS); - typedef void (JIT_STUB *CTIHelper_v)(STUB_ARGS); - typedef void* (JIT_STUB *CTIHelper_s)(STUB_ARGS); - typedef int (JIT_STUB *CTIHelper_b)(STUB_ARGS); - typedef VoidPtrPair (JIT_STUB *CTIHelper_2)(STUB_ARGS); - struct CallRecord { - MacroAssembler::Jump from; - unsigned bytecodeIndex; + MacroAssembler::Call from; + unsigned bytecodeOffset; void* to; CallRecord() { } - CallRecord(MacroAssembler::Jump from, unsigned bytecodeIndex, void* to = 0) + CallRecord(MacroAssembler::Call from, unsigned bytecodeOffset, void* to = 0) : from(from) - , bytecodeIndex(bytecodeIndex) + , bytecodeOffset(bytecodeOffset) , to(to) { } @@ -131,11 +94,11 @@ namespace JSC { struct JumpTable { MacroAssembler::Jump from; - unsigned toBytecodeIndex; + unsigned toBytecodeOffset; JumpTable(MacroAssembler::Jump f, unsigned t) : from(f) - , toBytecodeIndex(t) + , toBytecodeOffset(t) { } }; @@ -167,299 +130,698 @@ namespace JSC { StringJumpTable* stringJumpTable; } jumpTable; - unsigned bytecodeIndex; + unsigned bytecodeOffset; unsigned defaultOffset; - SwitchRecord(SimpleJumpTable* jumpTable, unsigned bytecodeIndex, unsigned defaultOffset, Type type) + SwitchRecord(SimpleJumpTable* jumpTable, unsigned bytecodeOffset, unsigned defaultOffset, Type type) : type(type) - , bytecodeIndex(bytecodeIndex) + , bytecodeOffset(bytecodeOffset) , defaultOffset(defaultOffset) { this->jumpTable.simpleJumpTable = jumpTable; } - SwitchRecord(StringJumpTable* jumpTable, unsigned bytecodeIndex, unsigned defaultOffset) + SwitchRecord(StringJumpTable* jumpTable, unsigned bytecodeOffset, unsigned defaultOffset) : type(String) - , bytecodeIndex(bytecodeIndex) + , bytecodeOffset(bytecodeOffset) , defaultOffset(defaultOffset) { this->jumpTable.stringJumpTable = jumpTable; } }; + enum PropertyStubGetById_T { PropertyStubGetById }; + enum PropertyStubPutById_T { PropertyStubPutById }; + struct PropertyStubCompilationInfo { - MacroAssembler::Jump callReturnLocation; + enum Type { GetById, PutById } m_type; + + unsigned bytecodeIndex; + MacroAssembler::Call callReturnLocation; MacroAssembler::Label hotPathBegin; - }; - - struct StructureStubCompilationInfo { - MacroAssembler::DataLabelPtr hotPathBegin; - MacroAssembler::Jump hotPathOther; - MacroAssembler::Jump callReturnLocation; - MacroAssembler::Label coldPathOther; - }; - - extern "C" { - JSValueEncodedAsPointer* ctiTrampoline( -#if PLATFORM(X86_64) - // FIXME: (bug #22910) this will force all arguments onto the stack (regparm(0) does not appear to have any effect). - // We can allow register passing here, and move the writes of these values into the trampoline. - void*, void*, void*, void*, void*, void*, + MacroAssembler::DataLabelPtr getStructureToCompare; + MacroAssembler::PatchableJump getStructureCheck; + MacroAssembler::ConvertibleLoadLabel propertyStorageLoad; +#if USE(JSVALUE64) + MacroAssembler::DataLabelCompact getDisplacementLabel; +#else + MacroAssembler::DataLabelCompact getDisplacementLabel1; + MacroAssembler::DataLabelCompact getDisplacementLabel2; #endif - void* code, RegisterFile*, CallFrame*, JSValuePtr* exception, Profiler**, JSGlobalData*); - void ctiVMThrowTrampoline(); - }; - - void ctiSetReturnAddress(void** where, void* what); - void ctiPatchCallByReturnAddress(void* where, void* what); - - class JIT : private MacroAssembler { - using MacroAssembler::Jump; - using MacroAssembler::JumpList; - using MacroAssembler::Label; - -#if PLATFORM(X86_64) - static const RegisterID timeoutCheckRegister = X86::r12; - static const RegisterID callFrameRegister = X86::r13; - static const RegisterID tagTypeNumberRegister = X86::r14; - static const RegisterID tagMaskRegister = X86::r15; + MacroAssembler::Label getPutResult; + MacroAssembler::Label getColdPathBegin; + MacroAssembler::DataLabelPtr putStructureToCompare; +#if USE(JSVALUE64) + MacroAssembler::DataLabel32 putDisplacementLabel; #else - static const RegisterID timeoutCheckRegister = X86::esi; - static const RegisterID callFrameRegister = X86::edi; + MacroAssembler::DataLabel32 putDisplacementLabel1; + MacroAssembler::DataLabel32 putDisplacementLabel2; #endif - static const int patchGetByIdDefaultStructure = -1; - // Magic number - initial offset cannot be representable as a signed 8bit value, or the X86Assembler - // will compress the displacement, and we may not be able to fit a patched offset. - static const int patchGetByIdDefaultOffset = 256; +#if !ASSERT_DISABLED + PropertyStubCompilationInfo() + : bytecodeIndex(std::numeric_limits::max()) + { + } +#endif -#if USE(JIT_STUB_ARGUMENT_REGISTER) -#if PLATFORM(X86_64) - static const int ctiArgumentInitSize = 6; + + PropertyStubCompilationInfo( + PropertyStubGetById_T, unsigned bytecodeIndex, MacroAssembler::Label hotPathBegin, + MacroAssembler::DataLabelPtr structureToCompare, + MacroAssembler::PatchableJump structureCheck, + MacroAssembler::ConvertibleLoadLabel propertyStorageLoad, +#if USE(JSVALUE64) + MacroAssembler::DataLabelCompact displacementLabel, #else - static const int ctiArgumentInitSize = 2; + MacroAssembler::DataLabelCompact displacementLabel1, + MacroAssembler::DataLabelCompact displacementLabel2, #endif -#elif USE(JIT_STUB_ARGUMENT_STACK) - static const int ctiArgumentInitSize = 4; -#else // JIT_STUB_ARGUMENT_VA_LIST - static const int ctiArgumentInitSize = 0; + MacroAssembler::Label putResult) + : m_type(GetById) + , bytecodeIndex(bytecodeIndex) + , hotPathBegin(hotPathBegin) + , getStructureToCompare(structureToCompare) + , getStructureCheck(structureCheck) + , propertyStorageLoad(propertyStorageLoad) +#if USE(JSVALUE64) + , getDisplacementLabel(displacementLabel) +#else + , getDisplacementLabel1(displacementLabel1) + , getDisplacementLabel2(displacementLabel2) #endif + , getPutResult(putResult) + { + } -#if PLATFORM(X86_64) - // These architecture specific value are used to enable patching - see comment on op_put_by_id. - static const int patchOffsetPutByIdStructure = 10; - static const int patchOffsetPutByIdPropertyMapOffset = 31; - // These architecture specific value are used to enable patching - see comment on op_get_by_id. - static const int patchOffsetGetByIdStructure = 10; - static const int patchOffsetGetByIdBranchToSlowCase = 20; - static const int patchOffsetGetByIdPropertyMapOffset = 31; - static const int patchOffsetGetByIdPutResult = 31; -#if ENABLE(OPCODE_SAMPLING) - static const int patchOffsetGetByIdSlowCaseCall = 53 + ctiArgumentInitSize; + PropertyStubCompilationInfo( + PropertyStubPutById_T, unsigned bytecodeIndex, MacroAssembler::Label hotPathBegin, + MacroAssembler::DataLabelPtr structureToCompare, + MacroAssembler::ConvertibleLoadLabel propertyStorageLoad, +#if USE(JSVALUE64) + MacroAssembler::DataLabel32 displacementLabel #else - static const int patchOffsetGetByIdSlowCaseCall = 30 + ctiArgumentInitSize; + MacroAssembler::DataLabel32 displacementLabel1, + MacroAssembler::DataLabel32 displacementLabel2 #endif - static const int patchOffsetOpCallCompareToJump = 9; -#else - // These architecture specific value are used to enable patching - see comment on op_put_by_id. - static const int patchOffsetPutByIdStructure = 7; - static const int patchOffsetPutByIdPropertyMapOffset = 22; - // These architecture specific value are used to enable patching - see comment on op_get_by_id. - static const int patchOffsetGetByIdStructure = 7; - static const int patchOffsetGetByIdBranchToSlowCase = 13; - static const int patchOffsetGetByIdPropertyMapOffset = 22; - static const int patchOffsetGetByIdPutResult = 22; -#if ENABLE(OPCODE_SAMPLING) - static const int patchOffsetGetByIdSlowCaseCall = 31 + ctiArgumentInitSize; + ) + : m_type(PutById) + , bytecodeIndex(bytecodeIndex) + , hotPathBegin(hotPathBegin) + , propertyStorageLoad(propertyStorageLoad) + , putStructureToCompare(structureToCompare) +#if USE(JSVALUE64) + , putDisplacementLabel(displacementLabel) #else - static const int patchOffsetGetByIdSlowCaseCall = 21 + ctiArgumentInitSize; -#endif - static const int patchOffsetOpCallCompareToJump = 6; + , putDisplacementLabel1(displacementLabel1) + , putDisplacementLabel2(displacementLabel2) #endif + { + } - public: - static void compile(JSGlobalData* globalData, CodeBlock* codeBlock) + void slowCaseInfo(PropertyStubGetById_T, MacroAssembler::Label coldPathBegin, MacroAssembler::Call call) { - JIT jit(globalData, codeBlock); - jit.privateCompile(); + ASSERT(m_type == GetById); + callReturnLocation = call; + getColdPathBegin = coldPathBegin; } - static void compileGetByIdSelf(JSGlobalData* globalData, CodeBlock* codeBlock, StructureStubInfo* stubInfo, Structure* structure, size_t cachedOffset, void* returnAddress) + void slowCaseInfo(PropertyStubPutById_T, MacroAssembler::Call call) { - JIT jit(globalData, codeBlock); - jit.privateCompileGetByIdSelf(stubInfo, structure, cachedOffset, returnAddress); + ASSERT(m_type == PutById); + callReturnLocation = call; } - static void compileGetByIdProto(JSGlobalData* globalData, CallFrame* callFrame, CodeBlock* codeBlock, StructureStubInfo* stubInfo, Structure* structure, Structure* prototypeStructure, size_t cachedOffset, void* returnAddress) + void copyToStubInfo(StructureStubInfo& info, LinkBuffer &patchBuffer); + }; + + struct ByValCompilationInfo { + ByValCompilationInfo() { } + + ByValCompilationInfo(unsigned bytecodeIndex, MacroAssembler::PatchableJump badTypeJump, JITArrayMode arrayMode, MacroAssembler::Label doneTarget) + : bytecodeIndex(bytecodeIndex) + , badTypeJump(badTypeJump) + , arrayMode(arrayMode) + , doneTarget(doneTarget) { - JIT jit(globalData, codeBlock); - jit.privateCompileGetByIdProto(stubInfo, structure, prototypeStructure, cachedOffset, returnAddress, callFrame); } + + unsigned bytecodeIndex; + MacroAssembler::PatchableJump badTypeJump; + JITArrayMode arrayMode; + MacroAssembler::Label doneTarget; + MacroAssembler::Label slowPathTarget; + MacroAssembler::Call returnAddress; + }; + + struct StructureStubCompilationInfo { + MacroAssembler::DataLabelPtr hotPathBegin; + MacroAssembler::Call hotPathOther; + MacroAssembler::Call callReturnLocation; + CallLinkInfo::CallType callType; + unsigned bytecodeIndex; + }; + + // Near calls can only be patched to other JIT code, regular calls can be patched to JIT code or relinked to stub functions. + void ctiPatchNearCallByReturnAddress(CodeBlock* codeblock, ReturnAddressPtr returnAddress, MacroAssemblerCodePtr newCalleeFunction); + void ctiPatchCallByReturnAddress(CodeBlock* codeblock, ReturnAddressPtr returnAddress, MacroAssemblerCodePtr newCalleeFunction); + void ctiPatchCallByReturnAddress(CodeBlock* codeblock, ReturnAddressPtr returnAddress, FunctionPtr newCalleeFunction); + + class JIT : private JSInterfaceJIT { + friend class JITStubCall; + friend struct PropertyStubCompilationInfo; + + using MacroAssembler::Jump; + using MacroAssembler::JumpList; + using MacroAssembler::Label; + + static const uintptr_t patchGetByIdDefaultStructure = unusedPointer; + static const int patchGetByIdDefaultOffset = 0; + // Magic number - initial offset cannot be representable as a signed 8bit value, or the X86Assembler + // will compress the displacement, and we may not be able to fit a patched offset. + static const int patchPutByIdDefaultOffset = 256; -#if USE(CTI_REPATCH_PIC) - static void compileGetByIdSelfList(JSGlobalData* globalData, CodeBlock* codeBlock, StructureStubInfo* stubInfo, PolymorphicAccessStructureList* polymorphicStructures, int currentIndex, Structure* structure, size_t cachedOffset) + public: + static JITCode compile(VM* vm, CodeBlock* codeBlock, JITCompilationEffort effort, CodePtr* functionEntryArityCheck = 0) { - JIT jit(globalData, codeBlock); - jit.privateCompileGetByIdSelfList(stubInfo, polymorphicStructures, currentIndex, structure, cachedOffset); + return JIT(vm, codeBlock).privateCompile(functionEntryArityCheck, effort); } - static void compileGetByIdProtoList(JSGlobalData* globalData, CallFrame* callFrame, CodeBlock* codeBlock, StructureStubInfo* stubInfo, PolymorphicAccessStructureList* prototypeStructureList, int currentIndex, Structure* structure, Structure* prototypeStructure, size_t cachedOffset) + + static void compileClosureCall(VM* vm, CallLinkInfo* callLinkInfo, CodeBlock* callerCodeBlock, CodeBlock* calleeCodeBlock, Structure* expectedStructure, ExecutableBase* expectedExecutable, MacroAssemblerCodePtr codePtr) { - JIT jit(globalData, codeBlock); - jit.privateCompileGetByIdProtoList(stubInfo, prototypeStructureList, currentIndex, structure, prototypeStructure, cachedOffset, callFrame); + JIT jit(vm, callerCodeBlock); + jit.m_bytecodeOffset = callLinkInfo->codeOrigin.bytecodeIndex; + jit.privateCompileClosureCall(callLinkInfo, calleeCodeBlock, expectedStructure, expectedExecutable, codePtr); } - static void compileGetByIdChainList(JSGlobalData* globalData, CallFrame* callFrame, CodeBlock* codeBlock, StructureStubInfo* stubInfo, PolymorphicAccessStructureList* prototypeStructureList, int currentIndex, Structure* structure, StructureChain* chain, size_t count, size_t cachedOffset) + + static void compileGetByIdProto(VM* vm, CallFrame* callFrame, CodeBlock* codeBlock, StructureStubInfo* stubInfo, Structure* structure, Structure* prototypeStructure, const Identifier& ident, const PropertySlot& slot, PropertyOffset cachedOffset, ReturnAddressPtr returnAddress) { - JIT jit(globalData, codeBlock); - jit.privateCompileGetByIdChainList(stubInfo, prototypeStructureList, currentIndex, structure, chain, count, cachedOffset, callFrame); + JIT jit(vm, codeBlock); + jit.m_bytecodeOffset = stubInfo->bytecodeIndex; + jit.privateCompileGetByIdProto(stubInfo, structure, prototypeStructure, ident, slot, cachedOffset, returnAddress, callFrame); } -#endif - static void compileGetByIdChain(JSGlobalData* globalData, CallFrame* callFrame, CodeBlock* codeBlock, StructureStubInfo* stubInfo, Structure* structure, StructureChain* chain, size_t count, size_t cachedOffset, void* returnAddress) + static void compileGetByIdSelfList(VM* vm, CodeBlock* codeBlock, StructureStubInfo* stubInfo, PolymorphicAccessStructureList* polymorphicStructures, int currentIndex, Structure* structure, const Identifier& ident, const PropertySlot& slot, PropertyOffset cachedOffset) + { + JIT jit(vm, codeBlock); + jit.m_bytecodeOffset = stubInfo->bytecodeIndex; + jit.privateCompileGetByIdSelfList(stubInfo, polymorphicStructures, currentIndex, structure, ident, slot, cachedOffset); + } + static void compileGetByIdProtoList(VM* vm, CallFrame* callFrame, CodeBlock* codeBlock, StructureStubInfo* stubInfo, PolymorphicAccessStructureList* prototypeStructureList, int currentIndex, Structure* structure, Structure* prototypeStructure, const Identifier& ident, const PropertySlot& slot, PropertyOffset cachedOffset) + { + JIT jit(vm, codeBlock); + jit.m_bytecodeOffset = stubInfo->bytecodeIndex; + jit.privateCompileGetByIdProtoList(stubInfo, prototypeStructureList, currentIndex, structure, prototypeStructure, ident, slot, cachedOffset, callFrame); + } + static void compileGetByIdChainList(VM* vm, CallFrame* callFrame, CodeBlock* codeBlock, StructureStubInfo* stubInfo, PolymorphicAccessStructureList* prototypeStructureList, int currentIndex, Structure* structure, StructureChain* chain, size_t count, const Identifier& ident, const PropertySlot& slot, PropertyOffset cachedOffset) { - JIT jit(globalData, codeBlock); - jit.privateCompileGetByIdChain(stubInfo, structure, chain, count, cachedOffset, returnAddress, callFrame); + JIT jit(vm, codeBlock); + jit.m_bytecodeOffset = stubInfo->bytecodeIndex; + jit.privateCompileGetByIdChainList(stubInfo, prototypeStructureList, currentIndex, structure, chain, count, ident, slot, cachedOffset, callFrame); } - static void compilePutByIdReplace(JSGlobalData* globalData, CodeBlock* codeBlock, StructureStubInfo* stubInfo, Structure* structure, size_t cachedOffset, void* returnAddress) + static void compileGetByIdChain(VM* vm, CallFrame* callFrame, CodeBlock* codeBlock, StructureStubInfo* stubInfo, Structure* structure, StructureChain* chain, size_t count, const Identifier& ident, const PropertySlot& slot, PropertyOffset cachedOffset, ReturnAddressPtr returnAddress) { - JIT jit(globalData, codeBlock); - jit.privateCompilePutByIdReplace(stubInfo, structure, cachedOffset, returnAddress); + JIT jit(vm, codeBlock); + jit.m_bytecodeOffset = stubInfo->bytecodeIndex; + jit.privateCompileGetByIdChain(stubInfo, structure, chain, count, ident, slot, cachedOffset, returnAddress, callFrame); } - static void compilePutByIdTransition(JSGlobalData* globalData, CodeBlock* codeBlock, StructureStubInfo* stubInfo, Structure* oldStructure, Structure* newStructure, size_t cachedOffset, StructureChain* chain, void* returnAddress) + static void compilePutByIdTransition(VM* vm, CodeBlock* codeBlock, StructureStubInfo* stubInfo, Structure* oldStructure, Structure* newStructure, PropertyOffset cachedOffset, StructureChain* chain, ReturnAddressPtr returnAddress, bool direct) { - JIT jit(globalData, codeBlock); - jit.privateCompilePutByIdTransition(stubInfo, oldStructure, newStructure, cachedOffset, chain, returnAddress); + JIT jit(vm, codeBlock); + jit.m_bytecodeOffset = stubInfo->bytecodeIndex; + jit.privateCompilePutByIdTransition(stubInfo, oldStructure, newStructure, cachedOffset, chain, returnAddress, direct); } - - static void compileCTIMachineTrampolines(JSGlobalData* globalData) + + static void compileGetByVal(VM* vm, CodeBlock* codeBlock, ByValInfo* byValInfo, ReturnAddressPtr returnAddress, JITArrayMode arrayMode) { - JIT jit(globalData); - jit.privateCompileCTIMachineTrampolines(); + JIT jit(vm, codeBlock); + jit.m_bytecodeOffset = byValInfo->bytecodeIndex; + jit.privateCompileGetByVal(byValInfo, returnAddress, arrayMode); } - static void patchGetByIdSelf(StructureStubInfo*, Structure*, size_t cachedOffset, void* returnAddress); - static void patchPutByIdReplace(StructureStubInfo*, Structure*, size_t cachedOffset, void* returnAddress); + static void compilePutByVal(VM* vm, CodeBlock* codeBlock, ByValInfo* byValInfo, ReturnAddressPtr returnAddress, JITArrayMode arrayMode) + { + JIT jit(vm, codeBlock); + jit.m_bytecodeOffset = byValInfo->bytecodeIndex; + jit.privateCompilePutByVal(byValInfo, returnAddress, arrayMode); + } - static void compilePatchGetArrayLength(JSGlobalData* globalData, CodeBlock* codeBlock, void* returnAddress) + static CodeRef compileCTINativeCall(VM* vm, NativeFunction func) { - JIT jit(globalData, codeBlock); - return jit.privateCompilePatchGetArrayLength(returnAddress); + if (!vm->canUseJIT()) { +#if ENABLE(LLINT) + return CodeRef::createLLIntCodeRef(llint_native_call_trampoline); +#else + return CodeRef(); +#endif + } + JIT jit(vm, 0); + return jit.privateCompileCTINativeCall(vm, func); } - static void linkCall(JSFunction* callee, CodeBlock* calleeCodeBlock, void* ctiCode, CallLinkInfo* callLinkInfo, int callerArgCount); - static void unlinkCall(CallLinkInfo*); + static void resetPatchGetById(RepatchBuffer&, StructureStubInfo*); + static void resetPatchPutById(RepatchBuffer&, StructureStubInfo*); + static void patchGetByIdSelf(CodeBlock*, StructureStubInfo*, Structure*, PropertyOffset cachedOffset, ReturnAddressPtr); + static void patchPutByIdReplace(CodeBlock*, StructureStubInfo*, Structure*, PropertyOffset cachedOffset, ReturnAddressPtr, bool direct); - inline static JSValuePtr execute(void* code, RegisterFile* registerFile, CallFrame* callFrame, JSGlobalData* globalData, JSValuePtr* exception) + static void compilePatchGetArrayLength(VM* vm, CodeBlock* codeBlock, ReturnAddressPtr returnAddress) { - return JSValuePtr::decode(ctiTrampoline( -#if PLATFORM(X86_64) - 0, 0, 0, 0, 0, 0, -#endif - code, registerFile, callFrame, exception, Profiler::enabledProfilerReference(), globalData)); + JIT jit(vm, codeBlock); +#if ENABLE(DFG_JIT) + // Force profiling to be enabled during stub generation. + jit.m_canBeOptimized = true; + jit.m_canBeOptimizedOrInlined = true; + jit.m_shouldEmitProfiling = true; +#endif // ENABLE(DFG_JIT) + return jit.privateCompilePatchGetArrayLength(returnAddress); } + static void linkFor(JSFunction* callee, CodeBlock* callerCodeBlock, CodeBlock* calleeCodeBlock, CodePtr, CallLinkInfo*, VM*, CodeSpecializationKind); + static void linkSlowCall(CodeBlock* callerCodeBlock, CallLinkInfo*); + private: - JIT(JSGlobalData*, CodeBlock* = 0); + JIT(VM*, CodeBlock* = 0); void privateCompileMainPass(); void privateCompileLinkPass(); void privateCompileSlowCases(); - void privateCompile(); - void privateCompileGetByIdSelf(StructureStubInfo*, Structure*, size_t cachedOffset, void* returnAddress); - void privateCompileGetByIdProto(StructureStubInfo*, Structure*, Structure* prototypeStructure, size_t cachedOffset, void* returnAddress, CallFrame* callFrame); -#if USE(CTI_REPATCH_PIC) - void privateCompileGetByIdSelfList(StructureStubInfo*, PolymorphicAccessStructureList*, int, Structure*, size_t cachedOffset); - void privateCompileGetByIdProtoList(StructureStubInfo*, PolymorphicAccessStructureList*, int, Structure*, Structure* prototypeStructure, size_t cachedOffset, CallFrame* callFrame); - void privateCompileGetByIdChainList(StructureStubInfo*, PolymorphicAccessStructureList*, int, Structure*, StructureChain* chain, size_t count, size_t cachedOffset, CallFrame* callFrame); -#endif - void privateCompileGetByIdChain(StructureStubInfo*, Structure*, StructureChain*, size_t count, size_t cachedOffset, void* returnAddress, CallFrame* callFrame); - void privateCompilePutByIdReplace(StructureStubInfo*, Structure*, size_t cachedOffset, void* returnAddress); - void privateCompilePutByIdTransition(StructureStubInfo*, Structure*, Structure*, size_t cachedOffset, StructureChain*, void* returnAddress); + JITCode privateCompile(CodePtr* functionEntryArityCheck, JITCompilationEffort); + + void privateCompileClosureCall(CallLinkInfo*, CodeBlock* calleeCodeBlock, Structure*, ExecutableBase*, MacroAssemblerCodePtr); + + void privateCompileGetByIdProto(StructureStubInfo*, Structure*, Structure* prototypeStructure, const Identifier&, const PropertySlot&, PropertyOffset cachedOffset, ReturnAddressPtr, CallFrame*); + void privateCompileGetByIdSelfList(StructureStubInfo*, PolymorphicAccessStructureList*, int, Structure*, const Identifier&, const PropertySlot&, PropertyOffset cachedOffset); + void privateCompileGetByIdProtoList(StructureStubInfo*, PolymorphicAccessStructureList*, int, Structure*, Structure* prototypeStructure, const Identifier&, const PropertySlot&, PropertyOffset cachedOffset, CallFrame*); + void privateCompileGetByIdChainList(StructureStubInfo*, PolymorphicAccessStructureList*, int, Structure*, StructureChain*, size_t count, const Identifier&, const PropertySlot&, PropertyOffset cachedOffset, CallFrame*); + void privateCompileGetByIdChain(StructureStubInfo*, Structure*, StructureChain*, size_t count, const Identifier&, const PropertySlot&, PropertyOffset cachedOffset, ReturnAddressPtr, CallFrame*); + void privateCompilePutByIdTransition(StructureStubInfo*, Structure*, Structure*, PropertyOffset cachedOffset, StructureChain*, ReturnAddressPtr, bool direct); + + void privateCompileGetByVal(ByValInfo*, ReturnAddressPtr, JITArrayMode); + void privateCompilePutByVal(ByValInfo*, ReturnAddressPtr, JITArrayMode); - void privateCompileCTIMachineTrampolines(); - void privateCompilePatchGetArrayLength(void* returnAddress); + Label privateCompileCTINativeCall(VM*, bool isConstruct = false); + CodeRef privateCompileCTINativeCall(VM*, NativeFunction); + void privateCompilePatchGetArrayLength(ReturnAddressPtr returnAddress); + + static bool isDirectPutById(StructureStubInfo*); void addSlowCase(Jump); + void addSlowCase(JumpList); + void addSlowCase(); void addJump(Jump, int); void emitJumpSlowToHot(Jump, int); - void compileGetByIdHotPath(int resultVReg, int baseVReg, Identifier* ident, unsigned propertyAccessInstructionIndex); - void compileGetByIdSlowCase(int resultVReg, int baseVReg, Identifier* ident, Vector::iterator& iter, unsigned propertyAccessInstructionIndex); - void compilePutByIdHotPath(int baseVReg, Identifier* ident, int valueVReg, unsigned propertyAccessInstructionIndex); - void compilePutByIdSlowCase(int baseVReg, Identifier* ident, int valueVReg, Vector::iterator& iter, unsigned propertyAccessInstructionIndex); - void compileOpCall(OpcodeID, Instruction* instruction, unsigned callLinkInfoIndex); - void compileOpCallInitializeCallFrame(); - void compileOpCallSetupArgs(Instruction*); - void compileOpCallEvalSetupArgs(Instruction*); - void compileOpCallSlowCase(Instruction* instruction, Vector::iterator& iter, unsigned callLinkInfoIndex, OpcodeID opcodeID); - void compileOpConstructSetupArgs(Instruction*); + void compileOpCall(OpcodeID, Instruction*, unsigned callLinkInfoIndex); + void compileOpCallSlowCase(OpcodeID, Instruction*, Vector::iterator&, unsigned callLinkInfoIndex); + void compileLoadVarargs(Instruction*); + void compileCallEval(); + void compileCallEvalSlowCase(Vector::iterator&); + enum CompileOpStrictEqType { OpStrictEq, OpNStrictEq }; void compileOpStrictEq(Instruction* instruction, CompileOpStrictEqType type); - void putDoubleResultToJSNumberCellOrJSImmediate(X86Assembler::XMMRegisterID xmmSource, RegisterID jsNumberCell, unsigned dst, X86Assembler::JmpSrc* wroteJSNumberCell, X86Assembler::XMMRegisterID tempXmm, RegisterID tempReg1, RegisterID tempReg2); - - void compileFastArith_op_add(Instruction*); - void compileFastArith_op_sub(Instruction*); - void compileFastArith_op_mul(Instruction*); - void compileFastArith_op_mod(unsigned result, unsigned op1, unsigned op2); - void compileFastArith_op_bitand(unsigned result, unsigned op1, unsigned op2); - void compileFastArith_op_lshift(unsigned result, unsigned op1, unsigned op2); - void compileFastArith_op_rshift(unsigned result, unsigned op1, unsigned op2); - void compileFastArith_op_pre_inc(unsigned srcDst); - void compileFastArith_op_pre_dec(unsigned srcDst); - void compileFastArith_op_post_inc(unsigned result, unsigned srcDst); - void compileFastArith_op_post_dec(unsigned result, unsigned srcDst); - void compileFastArithSlow_op_add(Instruction*, Vector::iterator&); - void compileFastArithSlow_op_sub(Instruction*, Vector::iterator&); - void compileFastArithSlow_op_mul(Instruction*, Vector::iterator&); - void compileFastArithSlow_op_mod(unsigned result, unsigned op1, unsigned op2, Vector::iterator&); - void compileFastArithSlow_op_bitand(unsigned result, unsigned op1, unsigned op2, Vector::iterator&); - void compileFastArithSlow_op_lshift(unsigned result, unsigned op1, unsigned op2, Vector::iterator&); - void compileFastArithSlow_op_rshift(unsigned result, unsigned op1, unsigned op2, Vector::iterator&); - void compileFastArithSlow_op_pre_inc(unsigned srcDst, Vector::iterator&); - void compileFastArithSlow_op_pre_dec(unsigned srcDst, Vector::iterator&); - void compileFastArithSlow_op_post_inc(unsigned result, unsigned srcDst, Vector::iterator&); - void compileFastArithSlow_op_post_dec(unsigned result, unsigned srcDst, Vector::iterator&); -#if ENABLE(JIT_OPTIMIZE_ARITHMETIC) - void compileBinaryArithOp(OpcodeID, unsigned dst, unsigned src1, unsigned src2, OperandTypes opi); - void compileBinaryArithOpSlowCase(OpcodeID, Vector::iterator&, unsigned dst, unsigned src1, unsigned src2, OperandTypes opi); + bool isOperandConstantImmediateDouble(unsigned src); + + void emitLoadDouble(int index, FPRegisterID value); + void emitLoadInt32ToDouble(int index, FPRegisterID value); + Jump emitJumpIfNotObject(RegisterID structureReg); + + Jump addStructureTransitionCheck(JSCell*, Structure*, StructureStubInfo*, RegisterID scratch); + void addStructureTransitionCheck(JSCell*, Structure*, StructureStubInfo*, JumpList& failureCases, RegisterID scratch); + void testPrototype(JSValue, JumpList& failureCases, StructureStubInfo*); + + enum WriteBarrierMode { UnconditionalWriteBarrier, ShouldFilterImmediates }; + // value register in write barrier is used before any scratch registers + // so may safely be the same as either of the scratch registers. + void emitWriteBarrier(RegisterID owner, RegisterID valueTag, RegisterID scratch, RegisterID scratch2, WriteBarrierMode, WriteBarrierUseKind); + void emitWriteBarrier(JSCell* owner, RegisterID value, RegisterID scratch, WriteBarrierMode, WriteBarrierUseKind); + + template // StructureType can be RegisterID or ImmPtr. + void emitAllocateJSObject(RegisterID allocator, StructureType, RegisterID result, RegisterID scratch); + +#if ENABLE(VALUE_PROFILER) + // This assumes that the value to profile is in regT0 and that regT3 is available for + // scratch. + void emitValueProfilingSite(ValueProfile*); + void emitValueProfilingSite(unsigned bytecodeOffset); + void emitValueProfilingSite(); +#else + void emitValueProfilingSite(unsigned) { } + void emitValueProfilingSite() { } +#endif + void emitArrayProfilingSite(RegisterID structureAndIndexingType, RegisterID scratch, ArrayProfile*); + void emitArrayProfilingSiteForBytecodeIndex(RegisterID structureAndIndexingType, RegisterID scratch, unsigned bytecodeIndex); + void emitArrayProfileStoreToHoleSpecialCase(ArrayProfile*); + void emitArrayProfileOutOfBoundsSpecialCase(ArrayProfile*); + + JITArrayMode chooseArrayMode(ArrayProfile*); + + // Property is in regT1, base is in regT0. regT2 contains indexing type. + // Property is int-checked and zero extended. Base is cell checked. + // Structure is already profiled. Returns the slow cases. Fall-through + // case contains result in regT0, and it is not yet profiled. + JumpList emitInt32GetByVal(Instruction* instruction, PatchableJump& badType) { return emitContiguousGetByVal(instruction, badType, Int32Shape); } + JumpList emitDoubleGetByVal(Instruction*, PatchableJump& badType); + JumpList emitContiguousGetByVal(Instruction*, PatchableJump& badType, IndexingType expectedShape = ContiguousShape); + JumpList emitArrayStorageGetByVal(Instruction*, PatchableJump& badType); + JumpList emitIntTypedArrayGetByVal(Instruction*, PatchableJump& badType, const TypedArrayDescriptor&, size_t elementSize, TypedArraySignedness); + JumpList emitFloatTypedArrayGetByVal(Instruction*, PatchableJump& badType, const TypedArrayDescriptor&, size_t elementSize); + + // Property is in regT0, base is in regT0. regT2 contains indecing type. + // The value to store is not yet loaded. Property is int-checked and + // zero-extended. Base is cell checked. Structure is already profiled. + // returns the slow cases. + JumpList emitInt32PutByVal(Instruction* currentInstruction, PatchableJump& badType) + { + return emitGenericContiguousPutByVal(currentInstruction, badType, Int32Shape); + } + JumpList emitDoublePutByVal(Instruction* currentInstruction, PatchableJump& badType) + { + return emitGenericContiguousPutByVal(currentInstruction, badType, DoubleShape); + } + JumpList emitContiguousPutByVal(Instruction* currentInstruction, PatchableJump& badType) + { + return emitGenericContiguousPutByVal(currentInstruction, badType); + } + JumpList emitGenericContiguousPutByVal(Instruction*, PatchableJump& badType, IndexingType indexingShape = ContiguousShape); + JumpList emitArrayStoragePutByVal(Instruction*, PatchableJump& badType); + JumpList emitIntTypedArrayPutByVal(Instruction*, PatchableJump& badType, const TypedArrayDescriptor&, size_t elementSize, TypedArraySignedness, TypedArrayRounding); + JumpList emitFloatTypedArrayPutByVal(Instruction*, PatchableJump& badType, const TypedArrayDescriptor&, size_t elementSize); + + enum FinalObjectMode { MayBeFinal, KnownNotFinal }; + +#if USE(JSVALUE32_64) + bool getOperandConstantImmediateInt(unsigned op1, unsigned op2, unsigned& op, int32_t& constant); + + void emitLoadTag(int index, RegisterID tag); + void emitLoadPayload(int index, RegisterID payload); + + void emitLoad(const JSValue& v, RegisterID tag, RegisterID payload); + void emitLoad(int index, RegisterID tag, RegisterID payload, RegisterID base = callFrameRegister); + void emitLoad2(int index1, RegisterID tag1, RegisterID payload1, int index2, RegisterID tag2, RegisterID payload2); + + void emitStore(int index, RegisterID tag, RegisterID payload, RegisterID base = callFrameRegister); + void emitStore(int index, const JSValue constant, RegisterID base = callFrameRegister); + void emitStoreInt32(int index, RegisterID payload, bool indexIsInt32 = false); + void emitStoreInt32(int index, TrustedImm32 payload, bool indexIsInt32 = false); + void emitStoreAndMapInt32(int index, RegisterID tag, RegisterID payload, bool indexIsInt32, size_t opcodeLength); + void emitStoreCell(int index, RegisterID payload, bool indexIsCell = false); + void emitStoreBool(int index, RegisterID payload, bool indexIsBool = false); + void emitStoreDouble(int index, FPRegisterID value); + + bool isLabeled(unsigned bytecodeOffset); + void map(unsigned bytecodeOffset, int virtualRegisterIndex, RegisterID tag, RegisterID payload); + void unmap(RegisterID); + void unmap(); + bool isMapped(int virtualRegisterIndex); + bool getMappedPayload(int virtualRegisterIndex, RegisterID& payload); + bool getMappedTag(int virtualRegisterIndex, RegisterID& tag); + + void emitJumpSlowCaseIfNotJSCell(int virtualRegisterIndex); + void emitJumpSlowCaseIfNotJSCell(int virtualRegisterIndex, RegisterID tag); + + void compileGetByIdHotPath(Identifier*); + void compileGetByIdSlowCase(int resultVReg, int baseVReg, Identifier*, Vector::iterator&); + void compileGetDirectOffset(RegisterID base, RegisterID resultTag, RegisterID resultPayload, PropertyOffset cachedOffset); + void compileGetDirectOffset(JSObject* base, RegisterID resultTag, RegisterID resultPayload, PropertyOffset cachedOffset); + void compileGetDirectOffset(RegisterID base, RegisterID resultTag, RegisterID resultPayload, RegisterID offset, FinalObjectMode = MayBeFinal); + void compilePutDirectOffset(RegisterID base, RegisterID valueTag, RegisterID valuePayload, PropertyOffset cachedOffset); + + // Arithmetic opcode helpers + void emitAdd32Constant(unsigned dst, unsigned op, int32_t constant, ResultType opType); + void emitSub32Constant(unsigned dst, unsigned op, int32_t constant, ResultType opType); + void emitBinaryDoubleOp(OpcodeID, unsigned dst, unsigned op1, unsigned op2, OperandTypes, JumpList& notInt32Op1, JumpList& notInt32Op2, bool op1IsInRegisters = true, bool op2IsInRegisters = true); + +#if CPU(ARM_TRADITIONAL) + // sequenceOpCall + static const int sequenceOpCallInstructionSpace = 12; + static const int sequenceOpCallConstantSpace = 2; + // sequenceGetByIdHotPath + static const int sequenceGetByIdHotPathInstructionSpace = 36; + static const int sequenceGetByIdHotPathConstantSpace = 4; + // sequenceGetByIdSlowCase + static const int sequenceGetByIdSlowCaseInstructionSpace = 80; + static const int sequenceGetByIdSlowCaseConstantSpace = 4; + // sequencePutById + static const int sequencePutByIdInstructionSpace = 36; + static const int sequencePutByIdConstantSpace = 4; +#elif CPU(SH4) + // sequenceOpCall + static const int sequenceOpCallInstructionSpace = 12; + static const int sequenceOpCallConstantSpace = 2; + // sequenceGetByIdHotPath + static const int sequenceGetByIdHotPathInstructionSpace = 36; + static const int sequenceGetByIdHotPathConstantSpace = 5; + // sequenceGetByIdSlowCase + static const int sequenceGetByIdSlowCaseInstructionSpace = 38; + static const int sequenceGetByIdSlowCaseConstantSpace = 4; + // sequencePutById + static const int sequencePutByIdInstructionSpace = 36; + static const int sequencePutByIdConstantSpace = 5; #endif - void emitGetVirtualRegister(int src, RegisterID dst); - void emitGetVirtualRegisters(int src1, RegisterID dst1, int src2, RegisterID dst2); - void emitPutVirtualRegister(unsigned dst, RegisterID from = X86::eax); - - void emitPutJITStubArg(RegisterID src, unsigned argumentNumber); - void emitPutJITStubArgFromVirtualRegister(unsigned src, unsigned argumentNumber, RegisterID scratch); - void emitPutJITStubArgConstant(unsigned value, unsigned argumentNumber); - void emitPutJITStubArgConstant(void* value, unsigned argumentNumber); +#else // USE(JSVALUE32_64) + /* This function is deprecated. */ void emitGetJITStubArg(unsigned argumentNumber, RegisterID dst); - void emitInitRegister(unsigned dst); - - void emitPutCTIParam(void* value, unsigned name); - void emitPutCTIParam(RegisterID from, unsigned name); - void emitGetCTIParam(unsigned name, RegisterID to); - - void emitPutToCallFrameHeader(RegisterID from, RegisterFile::CallFrameHeaderEntry entry); - void emitPutImmediateToCallFrameHeader(void* value, RegisterFile::CallFrameHeaderEntry entry); - void emitGetFromCallFrameHeader(RegisterFile::CallFrameHeaderEntry entry, RegisterID to); + void emitGetVirtualRegister(int src, RegisterID dst); + void emitGetVirtualRegisters(int src1, RegisterID dst1, int src2, RegisterID dst2); + void emitPutVirtualRegister(unsigned dst, RegisterID from = regT0); + void emitStoreCell(unsigned dst, RegisterID payload, bool /* only used in JSValue32_64 */ = false) + { + emitPutVirtualRegister(dst, payload); + } - JSValuePtr getConstantOperand(unsigned src); int32_t getConstantOperandImmediateInt(unsigned src); - bool isOperandConstantImmediateInt(unsigned src); + + void killLastResultRegister(); Jump emitJumpIfJSCell(RegisterID); Jump emitJumpIfBothJSCells(RegisterID, RegisterID, RegisterID); void emitJumpSlowCaseIfJSCell(RegisterID); - Jump emitJumpIfNotJSCell(RegisterID); void emitJumpSlowCaseIfNotJSCell(RegisterID); void emitJumpSlowCaseIfNotJSCell(RegisterID, int VReg); -#if USE(ALTERNATE_JSIMMEDIATE) - JIT::Jump emitJumpIfImmediateNumber(RegisterID); - JIT::Jump emitJumpIfNotImmediateNumber(RegisterID); + Jump emitJumpIfImmediateInteger(RegisterID); + Jump emitJumpIfNotImmediateInteger(RegisterID); + Jump emitJumpIfNotImmediateIntegers(RegisterID, RegisterID, RegisterID); + void emitJumpSlowCaseIfNotImmediateInteger(RegisterID); + void emitJumpSlowCaseIfNotImmediateNumber(RegisterID); + void emitJumpSlowCaseIfNotImmediateIntegers(RegisterID, RegisterID, RegisterID); + + void emitFastArithReTagImmediate(RegisterID src, RegisterID dest); + + void emitTagAsBoolImmediate(RegisterID reg); + void compileBinaryArithOp(OpcodeID, unsigned dst, unsigned src1, unsigned src2, OperandTypes opi); + void compileBinaryArithOpSlowCase(OpcodeID, Vector::iterator&, unsigned dst, unsigned src1, unsigned src2, OperandTypes, bool op1HasImmediateIntFastCase, bool op2HasImmediateIntFastCase); + + void compileGetByIdHotPath(int baseVReg, Identifier*); + void compileGetByIdSlowCase(int resultVReg, int baseVReg, Identifier*, Vector::iterator&); + void compileGetDirectOffset(RegisterID base, RegisterID result, PropertyOffset cachedOffset); + void compileGetDirectOffset(JSObject* base, RegisterID result, PropertyOffset cachedOffset); + void compileGetDirectOffset(RegisterID base, RegisterID result, RegisterID offset, RegisterID scratch, FinalObjectMode = MayBeFinal); + void compilePutDirectOffset(RegisterID base, RegisterID value, PropertyOffset cachedOffset); + +#endif // USE(JSVALUE32_64) + +#if (defined(ASSEMBLER_HAS_CONSTANT_POOL) && ASSEMBLER_HAS_CONSTANT_POOL) +#define BEGIN_UNINTERRUPTED_SEQUENCE(name) do { beginUninterruptedSequence(name ## InstructionSpace, name ## ConstantSpace); } while (false) +#define END_UNINTERRUPTED_SEQUENCE_FOR_PUT(name, dst) do { endUninterruptedSequence(name ## InstructionSpace, name ## ConstantSpace, dst); } while (false) +#define END_UNINTERRUPTED_SEQUENCE(name) END_UNINTERRUPTED_SEQUENCE_FOR_PUT(name, 0) + + void beginUninterruptedSequence(int, int); + void endUninterruptedSequence(int, int, int); + +#else +#define BEGIN_UNINTERRUPTED_SEQUENCE(name) +#define END_UNINTERRUPTED_SEQUENCE(name) +#define END_UNINTERRUPTED_SEQUENCE_FOR_PUT(name, dst) +#endif + + void emit_compareAndJump(OpcodeID, unsigned op1, unsigned op2, unsigned target, RelationalCondition); + void emit_compareAndJumpSlow(unsigned op1, unsigned op2, unsigned target, DoubleCondition, int (JIT_STUB *stub)(STUB_ARGS_DECLARATION), bool invert, Vector::iterator&); + + void emit_op_add(Instruction*); + void emit_op_bitand(Instruction*); + void emit_op_bitor(Instruction*); + void emit_op_bitxor(Instruction*); + void emit_op_call(Instruction*); + void emit_op_call_eval(Instruction*); + void emit_op_call_varargs(Instruction*); + void emit_op_call_put_result(Instruction*); + void emit_op_catch(Instruction*); + void emit_op_construct(Instruction*); + void emit_op_get_callee(Instruction*); + void emit_op_create_this(Instruction*); + void emit_op_convert_this(Instruction*); + void emit_op_create_arguments(Instruction*); + void emit_op_debug(Instruction*); + void emit_op_del_by_id(Instruction*); + void emit_op_div(Instruction*); + void emit_op_end(Instruction*); + void emit_op_enter(Instruction*); + void emit_op_create_activation(Instruction*); + void emit_op_eq(Instruction*); + void emit_op_eq_null(Instruction*); + void emit_op_get_by_id(Instruction*); + void emit_op_get_arguments_length(Instruction*); + void emit_op_get_by_val(Instruction*); + void emit_op_get_argument_by_val(Instruction*); + void emit_op_get_by_pname(Instruction*); + void emit_op_init_lazy_reg(Instruction*); + void emit_op_check_has_instance(Instruction*); + void emit_op_instanceof(Instruction*); + void emit_op_is_undefined(Instruction*); + void emit_op_is_boolean(Instruction*); + void emit_op_is_number(Instruction*); + void emit_op_is_string(Instruction*); + void emit_op_jeq_null(Instruction*); + void emit_op_jfalse(Instruction*); + void emit_op_jmp(Instruction*); + void emit_op_jneq_null(Instruction*); + void emit_op_jneq_ptr(Instruction*); + void emit_op_jless(Instruction*); + void emit_op_jlesseq(Instruction*); + void emit_op_jgreater(Instruction*); + void emit_op_jgreatereq(Instruction*); + void emit_op_jnless(Instruction*); + void emit_op_jnlesseq(Instruction*); + void emit_op_jngreater(Instruction*); + void emit_op_jngreatereq(Instruction*); + void emit_op_jtrue(Instruction*); + void emit_op_loop_hint(Instruction*); + void emit_op_lshift(Instruction*); + void emit_op_mod(Instruction*); + void emit_op_mov(Instruction*); + void emit_op_mul(Instruction*); + void emit_op_negate(Instruction*); + void emit_op_neq(Instruction*); + void emit_op_neq_null(Instruction*); + void emit_op_new_array(Instruction*); + void emit_op_new_array_with_size(Instruction*); + void emit_op_new_array_buffer(Instruction*); + void emit_op_new_func(Instruction*); + void emit_op_new_func_exp(Instruction*); + void emit_op_new_object(Instruction*); + void emit_op_new_regexp(Instruction*); + void emit_op_get_pnames(Instruction*); + void emit_op_next_pname(Instruction*); + void emit_op_not(Instruction*); + void emit_op_nstricteq(Instruction*); + void emit_op_pop_scope(Instruction*); + void emit_op_dec(Instruction*); + void emit_op_inc(Instruction*); + void emit_op_profile_did_call(Instruction*); + void emit_op_profile_will_call(Instruction*); + void emit_op_push_name_scope(Instruction*); + void emit_op_push_with_scope(Instruction*); + void emit_op_put_by_id(Instruction*); + void emit_op_put_by_index(Instruction*); + void emit_op_put_by_val(Instruction*); + void emit_op_put_getter_setter(Instruction*); + void emit_op_init_global_const(Instruction*); + void emit_op_init_global_const_check(Instruction*); + void emit_resolve_operations(ResolveOperations*, const int* base, const int* value); + void emitSlow_link_resolve_operations(ResolveOperations*, Vector::iterator&); + void emit_op_resolve(Instruction*); + void emit_op_resolve_base(Instruction*); + void emit_op_resolve_with_base(Instruction*); + void emit_op_resolve_with_this(Instruction*); + void emit_op_put_to_base(Instruction*); + void emit_op_ret(Instruction*); + void emit_op_ret_object_or_this(Instruction*); + void emit_op_rshift(Instruction*); + void emit_op_strcat(Instruction*); + void emit_op_stricteq(Instruction*); + void emit_op_sub(Instruction*); + void emit_op_switch_char(Instruction*); + void emit_op_switch_imm(Instruction*); + void emit_op_switch_string(Instruction*); + void emit_op_tear_off_activation(Instruction*); + void emit_op_tear_off_arguments(Instruction*); + void emit_op_throw(Instruction*); + void emit_op_throw_static_error(Instruction*); + void emit_op_to_number(Instruction*); + void emit_op_to_primitive(Instruction*); + void emit_op_unexpected_load(Instruction*); + void emit_op_urshift(Instruction*); + void emit_op_get_scoped_var(Instruction*); + void emit_op_put_scoped_var(Instruction*); + + void emitSlow_op_add(Instruction*, Vector::iterator&); + void emitSlow_op_bitand(Instruction*, Vector::iterator&); + void emitSlow_op_bitor(Instruction*, Vector::iterator&); + void emitSlow_op_bitxor(Instruction*, Vector::iterator&); + void emitSlow_op_call(Instruction*, Vector::iterator&); + void emitSlow_op_call_eval(Instruction*, Vector::iterator&); + void emitSlow_op_call_varargs(Instruction*, Vector::iterator&); + void emitSlow_op_construct(Instruction*, Vector::iterator&); + void emitSlow_op_convert_this(Instruction*, Vector::iterator&); + void emitSlow_op_create_this(Instruction*, Vector::iterator&); + void emitSlow_op_div(Instruction*, Vector::iterator&); + void emitSlow_op_eq(Instruction*, Vector::iterator&); + void emitSlow_op_get_by_id(Instruction*, Vector::iterator&); + void emitSlow_op_get_arguments_length(Instruction*, Vector::iterator&); + void emitSlow_op_get_by_val(Instruction*, Vector::iterator&); + void emitSlow_op_get_argument_by_val(Instruction*, Vector::iterator&); + void emitSlow_op_get_by_pname(Instruction*, Vector::iterator&); + void emitSlow_op_check_has_instance(Instruction*, Vector::iterator&); + void emitSlow_op_instanceof(Instruction*, Vector::iterator&); + void emitSlow_op_jfalse(Instruction*, Vector::iterator&); + void emitSlow_op_jless(Instruction*, Vector::iterator&); + void emitSlow_op_jlesseq(Instruction*, Vector::iterator&); + void emitSlow_op_jgreater(Instruction*, Vector::iterator&); + void emitSlow_op_jgreatereq(Instruction*, Vector::iterator&); + void emitSlow_op_jnless(Instruction*, Vector::iterator&); + void emitSlow_op_jnlesseq(Instruction*, Vector::iterator&); + void emitSlow_op_jngreater(Instruction*, Vector::iterator&); + void emitSlow_op_jngreatereq(Instruction*, Vector::iterator&); + void emitSlow_op_jtrue(Instruction*, Vector::iterator&); + void emitSlow_op_loop_hint(Instruction*, Vector::iterator&); + void emitSlow_op_lshift(Instruction*, Vector::iterator&); + void emitSlow_op_mod(Instruction*, Vector::iterator&); + void emitSlow_op_mul(Instruction*, Vector::iterator&); + void emitSlow_op_negate(Instruction*, Vector::iterator&); + void emitSlow_op_neq(Instruction*, Vector::iterator&); + void emitSlow_op_new_object(Instruction*, Vector::iterator&); + void emitSlow_op_not(Instruction*, Vector::iterator&); + void emitSlow_op_nstricteq(Instruction*, Vector::iterator&); + void emitSlow_op_dec(Instruction*, Vector::iterator&); + void emitSlow_op_inc(Instruction*, Vector::iterator&); + void emitSlow_op_put_by_id(Instruction*, Vector::iterator&); + void emitSlow_op_put_by_val(Instruction*, Vector::iterator&); + void emitSlow_op_init_global_const_check(Instruction*, Vector::iterator&); + void emitSlow_op_rshift(Instruction*, Vector::iterator&); + void emitSlow_op_stricteq(Instruction*, Vector::iterator&); + void emitSlow_op_sub(Instruction*, Vector::iterator&); + void emitSlow_op_to_number(Instruction*, Vector::iterator&); + void emitSlow_op_to_primitive(Instruction*, Vector::iterator&); + void emitSlow_op_urshift(Instruction*, Vector::iterator&); + + void emitSlow_op_resolve(Instruction*, Vector::iterator&); + void emitSlow_op_resolve_base(Instruction*, Vector::iterator&); + void emitSlow_op_resolve_with_base(Instruction*, Vector::iterator&); + void emitSlow_op_resolve_with_this(Instruction*, Vector::iterator&); + void emitSlow_op_put_to_base(Instruction*, Vector::iterator&); + + void emitRightShift(Instruction*, bool isUnsigned); + void emitRightShiftSlowCase(Instruction*, Vector::iterator&, bool isUnsigned); + + void emitInitRegister(unsigned dst); + + void emitPutIntToCallFrameHeader(RegisterID from, JSStack::CallFrameHeaderEntry); + void emitGetFromCallFrameHeaderPtr(JSStack::CallFrameHeaderEntry, RegisterID to, RegisterID from = callFrameRegister); + void emitGetFromCallFrameHeader32(JSStack::CallFrameHeaderEntry, RegisterID to, RegisterID from = callFrameRegister); +#if USE(JSVALUE64) + void emitGetFromCallFrameHeader64(JSStack::CallFrameHeaderEntry, RegisterID to, RegisterID from = callFrameRegister); #endif + JSValue getConstantOperand(unsigned src); + bool isOperandConstantImmediateInt(unsigned src); + bool isOperandConstantImmediateChar(unsigned src); + + bool atJumpTarget(); + Jump getSlowCase(Vector::iterator& iter) { return iter++->from; @@ -469,108 +831,114 @@ namespace JSC { iter->from.link(this); ++iter; } - void linkSlowCaseIfNotJSCell(Vector::iterator&, int vReg); - - JIT::Jump emitJumpIfImmediateInteger(RegisterID); - JIT::Jump emitJumpIfNotImmediateInteger(RegisterID); - JIT::Jump emitJumpIfNotImmediateIntegers(RegisterID, RegisterID, RegisterID); - void emitJumpSlowCaseIfNotImmediateInteger(RegisterID); - void emitJumpSlowCaseIfNotImmediateIntegers(RegisterID, RegisterID, RegisterID); + void linkDummySlowCase(Vector::iterator& iter) + { + ASSERT(!iter->from.isSet()); + ++iter; + } + void linkSlowCaseIfNotJSCell(Vector::iterator&, int virtualRegisterIndex); Jump checkStructure(RegisterID reg, Structure* structure); -#if !USE(ALTERNATE_JSIMMEDIATE) - void emitFastArithDeTagImmediate(RegisterID); - Jump emitFastArithDeTagImmediateJumpIfZero(RegisterID); -#endif - void emitFastArithReTagImmediate(RegisterID src, RegisterID dest); - void emitFastArithImmToInt(RegisterID); - void emitFastArithIntToImmNoCheck(RegisterID src, RegisterID dest); - - void emitTagAsBoolImmediate(RegisterID reg); - - void restoreArgumentReference(); void restoreArgumentReferenceForTrampoline(); + void updateTopCallFrame(); + + Call emitNakedCall(CodePtr function = CodePtr()); - Jump emitNakedCall(RegisterID); - Jump emitNakedCall(void* function); - Jump emitCTICall_internal(void*); - Jump emitCTICall(CTIHelper_j helper) { return emitCTICall_internal(reinterpret_cast(helper)); } - Jump emitCTICall(CTIHelper_o helper) { return emitCTICall_internal(reinterpret_cast(helper)); } - Jump emitCTICall(CTIHelper_p helper) { return emitCTICall_internal(reinterpret_cast(helper)); } - Jump emitCTICall(CTIHelper_v helper) { return emitCTICall_internal(reinterpret_cast(helper)); } - Jump emitCTICall(CTIHelper_s helper) { return emitCTICall_internal(reinterpret_cast(helper)); } - Jump emitCTICall(CTIHelper_b helper) { return emitCTICall_internal(reinterpret_cast(helper)); } - Jump emitCTICall(CTIHelper_2 helper) { return emitCTICall_internal(reinterpret_cast(helper)); } - - void emitGetVariableObjectRegister(RegisterID variableObject, int index, RegisterID dst); - void emitPutVariableObjectRegister(RegisterID src, RegisterID variableObject, int index); + // Loads the character value of a single character string into dst. + void emitLoadCharacterString(RegisterID src, RegisterID dst, JumpList& failures); - void emitSlowScriptCheck(); +#if ENABLE(DFG_JIT) + void emitEnterOptimizationCheck(); +#else + void emitEnterOptimizationCheck() { } +#endif + #ifndef NDEBUG void printBytecodeOperandTypes(unsigned src1, unsigned src2); #endif - void killLastResultRegister(); - -#if ENABLE(CODEBLOCK_SAMPLING) - void sampleCodeBlock(CodeBlock* codeBlock) - { -#if PLATFORM(X86_64) - move(ImmPtr(m_interpreter->sampler()->codeBlockSlot()), X86::ecx); - storePtr(ImmPtr(codeBlock), X86::ecx); -#else - storePtr(ImmPtr(codeBlock), m_interpreter->sampler()->codeBlockSlot()); +#if ENABLE(SAMPLING_FLAGS) + void setSamplingFlag(int32_t); + void clearSamplingFlag(int32_t); #endif - } -#else - void sampleCodeBlock(CodeBlock*) {} + +#if ENABLE(SAMPLING_COUNTERS) + void emitCount(AbstractSamplingCounter&, int32_t = 1); #endif #if ENABLE(OPCODE_SAMPLING) - void sampleInstruction(Instruction* instruction, bool inHostFunction=false) - { -#if PLATFORM(X86_64) - move(ImmPtr(m_interpreter->sampler()->sampleSlot()), X86::ecx); - storePtr(ImmPtr(m_interpreter->sampler()->encodeSample(instruction, inHostFunction)), X86::ecx); + void sampleInstruction(Instruction*, bool = false); +#endif + +#if ENABLE(CODEBLOCK_SAMPLING) + void sampleCodeBlock(CodeBlock*); #else - storePtr(ImmPtr(m_interpreter->sampler()->encodeSample(instruction, inHostFunction)), m_interpreter->sampler()->sampleSlot()); + void sampleCodeBlock(CodeBlock*) {} #endif - } + +#if ENABLE(DFG_JIT) + bool canBeOptimized() { return m_canBeOptimized; } + bool canBeOptimizedOrInlined() { return m_canBeOptimizedOrInlined; } + bool shouldEmitProfiling() { return m_shouldEmitProfiling; } #else - void sampleInstruction(Instruction*, bool) {} + bool canBeOptimized() { return false; } + bool canBeOptimizedOrInlined() { return false; } + // Enables use of value profiler with tiered compilation turned off, + // in which case all code gets profiled. + bool shouldEmitProfiling() { return false; } #endif Interpreter* m_interpreter; - JSGlobalData* m_globalData; + VM* m_vm; CodeBlock* m_codeBlock; Vector m_calls; Vector