Skip to content
Permalink
Browse files
Change callToJavaScript thunk into an offline assembled stub
https://bugs.webkit.org/show_bug.cgi?id=124251

Reviewed by Geoffrey Garen.

Changed callToJavaScript and throwNotCaught into stubs generated by the offline assembler.
Added popCalleeSaves and pushCalleeSaves pseudo ops to the offline assembler to handle
the saving and restoring of callee save registers.  Fixed callFrameRegister differences
between arm traditional (r11) and arm Thumb2 (r7) in GPRInfo.h.  Also fixed implementation
of pop & push in arm.rb.

Since the offline assembler and therefore the LLInt don't work on Windows, the Windows stubs
are handled as inline assembly in JITStubsX86.h and JITStubsMSVC64.asm.

* dfg/DFGDriver.cpp:
(JSC::DFG::compileImpl):
* jit/GPRInfo.h:
(JSC::GPRInfo::toIndex):
(JSC::GPRInfo::debugName):
* jit/JITCode.cpp:
(JSC::JITCode::execute):
* jit/JITExceptions.cpp:
(JSC::genericUnwind):
* jit/JITStubs.h:
* jit/JITStubsMSVC64.asm:
* jit/JITStubsX86.h:
* jit/ThunkGenerators.cpp:
* jit/ThunkGenerators.h:
* llint/LLIntThunks.h:
* llint/LowLevelInterpreter.asm:
* llint/LowLevelInterpreter32_64.asm:
* llint/LowLevelInterpreter64.asm:
* offlineasm/arm.rb:
* offlineasm/arm64.rb:
* offlineasm/instructions.rb:
* offlineasm/mips.rb:
* offlineasm/registers.rb:
* offlineasm/sh4.rb:
* offlineasm/x86.rb:
* runtime/VM.cpp:
(JSC::VM::VM):
* runtime/VM.h:


Canonical link: https://commits.webkit.org/142547@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@159276 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
msaboff committed Nov 14, 2013
1 parent 4735c2e commit a0798c113d58df7ea1de65fd368620f1ac96bd0e
@@ -1,3 +1,48 @@
2013-11-13 Michael Saboff <msaboff@apple.com>

Change callToJavaScript thunk into an offline assembled stub
https://bugs.webkit.org/show_bug.cgi?id=124251

Reviewed by Geoffrey Garen.

Changed callToJavaScript and throwNotCaught into stubs generated by the offline assembler.
Added popCalleeSaves and pushCalleeSaves pseudo ops to the offline assembler to handle
the saving and restoring of callee save registers. Fixed callFrameRegister differences
between arm traditional (r11) and arm Thumb2 (r7) in GPRInfo.h. Also fixed implementation
of pop & push in arm.rb.

Since the offline assembler and therefore the LLInt don't work on Windows, the Windows stubs
are handled as inline assembly in JITStubsX86.h and JITStubsMSVC64.asm.

* dfg/DFGDriver.cpp:
(JSC::DFG::compileImpl):
* jit/GPRInfo.h:
(JSC::GPRInfo::toIndex):
(JSC::GPRInfo::debugName):
* jit/JITCode.cpp:
(JSC::JITCode::execute):
* jit/JITExceptions.cpp:
(JSC::genericUnwind):
* jit/JITStubs.h:
* jit/JITStubsMSVC64.asm:
* jit/JITStubsX86.h:
* jit/ThunkGenerators.cpp:
* jit/ThunkGenerators.h:
* llint/LLIntThunks.h:
* llint/LowLevelInterpreter.asm:
* llint/LowLevelInterpreter32_64.asm:
* llint/LowLevelInterpreter64.asm:
* offlineasm/arm.rb:
* offlineasm/arm64.rb:
* offlineasm/instructions.rb:
* offlineasm/mips.rb:
* offlineasm/registers.rb:
* offlineasm/sh4.rb:
* offlineasm/x86.rb:
* runtime/VM.cpp:
(JSC::VM::VM):
* runtime/VM.h:

2013-11-13 Andy Estes <aestes@apple.com>

Fix the ARM64 build after recent JavaScriptCore changes
@@ -78,8 +78,6 @@ static CompilationResult compileImpl(

// Make sure that any stubs that the DFG is going to use are initialized. We want to
// make sure that all JIT code generation does finalization on the main thread.
vm.getCTIStub(callToJavaScript);
vm.getCTIStub(throwNotCaught);
vm.getCTIStub(osrExitGenerationThunkGenerator);
vm.getCTIStub(throwExceptionFromCallSlowPathGenerator);
vm.getCTIStub(linkCallThunkGenerator);
@@ -460,7 +460,11 @@ class GPRInfo {
static const GPRReg regT4 = ARMRegisters::r8;
static const GPRReg regT5 = ARMRegisters::r9;
static const GPRReg regT6 = ARMRegisters::r10;
static const GPRReg regT7 = ARMRegisters::r5;
#if CPU(ARM_THUMB2)
static const GPRReg regT7 = ARMRegisters::r11;
#else
static const GPRReg regT7 = ARMRegisters::r7;
#endif
static const GPRReg regT8 = ARMRegisters::r3;
// These registers match the baseline JIT.
static const GPRReg cachedResultRegister = regT0;
@@ -488,8 +492,13 @@ class GPRInfo {
static unsigned toIndex(GPRReg reg)
{
ASSERT(reg != InvalidGPRReg);
ASSERT(reg < 16);
static const unsigned indexForRegister[16] = { 0, 1, 2, 8, 3, 7, InvalidIndex, InvalidIndex, 4, 5, 6, InvalidIndex, InvalidIndex, InvalidIndex, InvalidIndex, InvalidIndex };
ASSERT(static_cast<int>(reg) < 16);
static const unsigned indexForRegister[16] =
#if CPU(ARM_THUMB2)
{ 0, 1, 2, 8, 3, 9, InvalidIndex, InvalidIndex, 4, 5, 6, 7, InvalidIndex, InvalidIndex, InvalidIndex, InvalidIndex };
#else
{ 0, 1, 2, 8, 3, 9, InvalidIndex, 7, 4, 5, 6, InvalidIndex, InvalidIndex, InvalidIndex, InvalidIndex, InvalidIndex };
#endif
unsigned result = indexForRegister[reg];
ASSERT(result != InvalidIndex);
return result;
@@ -498,7 +507,7 @@ class GPRInfo {
static const char* debugName(GPRReg reg)
{
ASSERT(reg != InvalidGPRReg);
ASSERT(reg < 16);
ASSERT(static_cast<int>(reg) < 16);
static const char* nameForRegister[16] = {
"r0", "r1", "r2", "r3",
"r4", "r5", "r6", "r7",
@@ -26,8 +26,8 @@
#include "config.h"
#include "JITCode.h"

#include "LLIntThunks.h"
#include "Operations.h"
#include "ThunkGenerators.h"
#include <wtf/PrintStream.h>

namespace JSC {
@@ -46,7 +46,7 @@ JSValue JITCode::execute(JSStack* stack, CallFrame* callFrame, VM* vm)
{
UNUSED_PARAM(stack);

JSValue result = JSValue::decode(vm->callJavaScriptJITFunction(executableAddress(), callFrame));
JSValue result = JSValue::decode(callToJavaScript(executableAddress(), callFrame));
return vm->exception() ? jsNull() : result;
}
#endif
@@ -30,7 +30,9 @@
#include "CallFrameInlines.h"
#include "CodeBlock.h"
#include "Interpreter.h"
#include "JITStubs.h"
#include "JSCJSValue.h"
#include "LLIntThunks.h"
#include "VM.h"
#include "Operations.h"

@@ -49,7 +51,7 @@ void genericUnwind(VM* vm, ExecState* callFrame, JSValue exceptionValue)
catchPCForInterpreter = &callFrame->codeBlock()->instructions()[handler->target];
catchRoutine = ExecutableBase::catchRoutineFor(handler, catchPCForInterpreter);
} else
catchRoutine = vm->getCTIStub(throwNotCaught).code().executableAddress();
catchRoutine = FunctionPtr(LLInt::getCodePtr(returnFromJavaScript)).value();

vm->callFrameForThrow = callFrame;
vm->targetMachinePCForThrow = catchRoutine;
@@ -30,10 +30,21 @@
#ifndef JITStubs_h
#define JITStubs_h

#include "JSCJSValue.h"

namespace JSC {

#if ENABLE(JIT)

#if OS(WINDOWS)
class ExecState;

extern "C" {
EncodedJSValue callToJavaScript(void*, ExecState*);
void returnFromJavaScript();
}
#endif

#if USE(MASM_PROBE)
extern "C" void ctiMasmProbeTrampoline();
#endif
@@ -25,10 +25,54 @@

EXTERN getHostCallReturnValueWithExecState : near

PUBLIC callToJavaScript
PUBLIC returnFromJavaScript
PUBLIC getHostCallReturnValue

_TEXT SEGMENT

callToJavaScript PROC
push rbp
mov rbp, rax ; Save previous frame pointer
mov rbp, rsp
push r12
push r13
push r14
push r15
push rbx

; JIT operations can use up to 6 args (4 in registers and 2 on the stack).
; In addition, X86_64 ABI specifies that the worse case stack alignment
; requirement is 32 bytes. Based on these factors, we need to pad the stack
; an additional 28h bytes.
sub rsp, 28h
mov rbp, rdx
mov r11, qword ptr[rbp] ; Put the previous frame pointer in the sentinel call frame above us
mov qword ptr[r11], rax
mov r14, 0FFFF000000000000h
mov r15, 0FFFF000000000002h
call rcx
add rsp, 28h
pop rbx
pop r15
pop r14
pop r13
pop r12
pop rbp
ret
callToJavaScript ENDP

returnFromJavaScript PROC
add rsp, 28h
pop rbx
pop r15
pop r14
pop r13
pop r12
pop rbp
ret
returnFromJavaScript ENDP
getHostCallReturnValue PROC
sub r13, 40
mov r13, rdi
@@ -200,6 +200,50 @@ SYMBOL_STRING(ctiMasmProbeTrampolineEnd) ":" "\n"

#endif // COMPILER(GCC)

#if COMPILER(MSVC)

extern "C" {

// FIXME: Since Windows doesn't use the LLInt, we have inline stubs here.
// Until the LLInt is changed to support Windows, these stub needs to be updated.
__declspec(naked) EncodedJSValue callToJavaScript(void* code, ExecState*)
{
__asm {
push ebp;
mov eax, ebp;
mov ebp, esp;
push esi;
push edi;
push ebx;
sub esp, 0x1c;
mov ebp, [esp + 0x34];
mov ebx, [ebp];
mov [ebx], eax;
call [esp + 0x30];
add esp, 0x1c;
pop ebx;
pop edi;
pop esi;
pop ebp;
ret;
}
}

__declspec(naked) void returnFromJavaScript()
{
__asm {
add esp, 0x1c;
pop ebx;
pop edi;
pop esi;
pop ebp;
ret;
}
}
}

#endif // COMPILER(MSVC)

} // namespace JSC

#endif // JITStubsX86_h

0 comments on commit a0798c1

Please sign in to comment.