summaryrefslogtreecommitdiff
path: root/Source/JavaScriptCore/ftl/FTLThunks.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
commit1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch)
tree46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/JavaScriptCore/ftl/FTLThunks.cpp
parent32761a6cee1d0dee366b885b7b9c777e67885688 (diff)
downloadWebKitGtk-tarball-master.tar.gz
Diffstat (limited to 'Source/JavaScriptCore/ftl/FTLThunks.cpp')
-rw-r--r--Source/JavaScriptCore/ftl/FTLThunks.cpp125
1 files changed, 100 insertions, 25 deletions
diff --git a/Source/JavaScriptCore/ftl/FTLThunks.cpp b/Source/JavaScriptCore/ftl/FTLThunks.cpp
index bf04af02a..cfbc75b7c 100644
--- a/Source/JavaScriptCore/ftl/FTLThunks.cpp
+++ b/Source/JavaScriptCore/ftl/FTLThunks.cpp
@@ -29,8 +29,10 @@
#if ENABLE(FTL_JIT)
#include "AssemblyHelpers.h"
+#include "DFGOSRExitCompilerCommon.h"
#include "FPRInfo.h"
#include "FTLOSRExitCompiler.h"
+#include "FTLOperations.h"
#include "FTLSaveRestore.h"
#include "GPRInfo.h"
#include "LinkBuffer.h"
@@ -39,29 +41,51 @@ namespace JSC { namespace FTL {
using namespace DFG;
-MacroAssemblerCodeRef osrExitGenerationThunkGenerator(VM& vm, const Location& location)
+enum class FrameAndStackAdjustmentRequirement {
+ Needed,
+ NotNeeded
+};
+
+static MacroAssemblerCodeRef genericGenerationThunkGenerator(
+ VM* vm, FunctionPtr generationFunction, const char* name, unsigned extraPopsToRestore, FrameAndStackAdjustmentRequirement frameAndStackAdjustmentRequirement)
{
- AssemblyHelpers jit(&vm, 0);
+ AssemblyHelpers jit(vm, 0);
+
+ if (frameAndStackAdjustmentRequirement == FrameAndStackAdjustmentRequirement::Needed) {
+ // This needs to happen before we use the scratch buffer because this function also uses the scratch buffer.
+ adjustFrameAndStackInOSRExitCompilerThunk<FTL::JITCode>(jit, vm, JITCode::FTLJIT);
+ }
- // Note that the "return address" will be the OSR exit ID.
+ // Note that the "return address" will be the ID that we pass to the generation function.
+
+ ptrdiff_t stackMisalignment = MacroAssembler::pushToSaveByteOffset();
// Pretend that we're a C call frame.
- jit.push(MacroAssembler::framePointerRegister);
+ jit.pushToSave(MacroAssembler::framePointerRegister);
jit.move(MacroAssembler::stackPointerRegister, MacroAssembler::framePointerRegister);
- jit.push(GPRInfo::regT0);
- jit.push(GPRInfo::regT0);
+ stackMisalignment += MacroAssembler::pushToSaveByteOffset();
+
+ // Now create ourselves enough stack space to give saveAllRegisters() a scratch slot.
+ unsigned numberOfRequiredPops = 0;
+ do {
+ jit.pushToSave(GPRInfo::regT0);
+ stackMisalignment += MacroAssembler::pushToSaveByteOffset();
+ numberOfRequiredPops++;
+ } while (stackMisalignment % stackAlignmentBytes());
- ScratchBuffer* scratchBuffer = vm.scratchBufferForSize(requiredScratchMemorySizeInBytes());
+ ScratchBuffer* scratchBuffer = vm->scratchBufferForSize(requiredScratchMemorySizeInBytes());
char* buffer = static_cast<char*>(scratchBuffer->dataBuffer());
saveAllRegisters(jit, buffer);
// Tell GC mark phase how much of the scratch buffer is active during call.
- jit.move(MacroAssembler::TrustedImmPtr(scratchBuffer->activeLengthPtr()), GPRInfo::nonArgGPR1);
- jit.storePtr(MacroAssembler::TrustedImmPtr(requiredScratchMemorySizeInBytes()), GPRInfo::nonArgGPR1);
+ jit.move(MacroAssembler::TrustedImmPtr(scratchBuffer->activeLengthPtr()), GPRInfo::nonArgGPR0);
+ jit.storePtr(MacroAssembler::TrustedImmPtr(requiredScratchMemorySizeInBytes()), GPRInfo::nonArgGPR0);
- location.restoreInto(jit, buffer, GPRInfo::argumentGPR0, 1);
- jit.peek(GPRInfo::argumentGPR1, 3);
+ jit.loadPtr(GPRInfo::callFrameRegister, GPRInfo::argumentGPR0);
+ jit.peek(
+ GPRInfo::argumentGPR1,
+ (stackMisalignment - MacroAssembler::pushToSaveByteOffset()) / sizeof(void*));
MacroAssembler::Call functionCall = jit.call();
// At this point we want to make a tail call to what was returned to us in the
@@ -71,24 +95,73 @@ MacroAssemblerCodeRef osrExitGenerationThunkGenerator(VM& vm, const Location& lo
jit.move(GPRInfo::returnValueGPR, GPRInfo::regT0);
- // Prepare for tail call.
- jit.pop(GPRInfo::regT1);
- jit.pop(GPRInfo::regT1);
- jit.pop(MacroAssembler::framePointerRegister);
-
- // At this point we're sitting on the return address - so if we did a jump right now, the
- // tail-callee would be happy. Instead we'll stash the callee in the return address and then
- // restore all registers.
+ // Make sure we tell the GC that we're not using the scratch buffer anymore.
+ jit.move(MacroAssembler::TrustedImmPtr(scratchBuffer->activeLengthPtr()), GPRInfo::regT1);
+ jit.storePtr(MacroAssembler::TrustedImmPtr(0), GPRInfo::regT1);
+ // Prepare for tail call.
+ while (numberOfRequiredPops--)
+ jit.popToRestore(GPRInfo::regT1);
+ jit.popToRestore(MacroAssembler::framePointerRegister);
+
+ // When we came in here, there was an additional thing pushed to the stack. Some clients want it
+ // popped before proceeding.
+ while (extraPopsToRestore--)
+ jit.popToRestore(GPRInfo::regT1);
+
+ // Put the return address wherever the return instruction wants it. On all platforms, this
+ // ensures that the return address is out of the way of register restoration.
jit.restoreReturnAddressBeforeReturn(GPRInfo::regT0);
-
+
restoreAllRegisters(jit, buffer);
jit.ret();
- LinkBuffer patchBuffer(vm, &jit, GLOBAL_THUNK_ID);
- patchBuffer.link(functionCall, compileFTLOSRExit);
- return FINALIZE_CODE(patchBuffer, ("FTL OSR exit generation thunk for callFrame at %s", toCString(location).data()));
+ LinkBuffer patchBuffer(*vm, jit, GLOBAL_THUNK_ID);
+ patchBuffer.link(functionCall, generationFunction);
+ return FINALIZE_CODE(patchBuffer, ("%s", name));
+}
+
+MacroAssemblerCodeRef osrExitGenerationThunkGenerator(VM* vm)
+{
+ unsigned extraPopsToRestore = 0;
+ return genericGenerationThunkGenerator(
+ vm, compileFTLOSRExit, "FTL OSR exit generation thunk", extraPopsToRestore, FrameAndStackAdjustmentRequirement::Needed);
+}
+
+MacroAssemblerCodeRef lazySlowPathGenerationThunkGenerator(VM* vm)
+{
+ unsigned extraPopsToRestore = 1;
+ return genericGenerationThunkGenerator(
+ vm, compileFTLLazySlowPath, "FTL lazy slow path generation thunk", extraPopsToRestore, FrameAndStackAdjustmentRequirement::NotNeeded);
+}
+
+static void registerClobberCheck(AssemblyHelpers& jit, RegisterSet dontClobber)
+{
+ if (!Options::clobberAllRegsInFTLICSlowPath())
+ return;
+
+ RegisterSet clobber = RegisterSet::allRegisters();
+ clobber.exclude(RegisterSet::reservedHardwareRegisters());
+ clobber.exclude(RegisterSet::stackRegisters());
+ clobber.exclude(RegisterSet::calleeSaveRegisters());
+ clobber.exclude(dontClobber);
+
+ GPRReg someGPR;
+ for (Reg reg = Reg::first(); reg <= Reg::last(); reg = reg.next()) {
+ if (!clobber.get(reg) || !reg.isGPR())
+ continue;
+
+ jit.move(AssemblyHelpers::TrustedImm32(0x1337beef), reg.gpr());
+ someGPR = reg.gpr();
+ }
+
+ for (Reg reg = Reg::first(); reg <= Reg::last(); reg = reg.next()) {
+ if (!clobber.get(reg) || !reg.isFPR())
+ continue;
+
+ jit.move64ToDouble(someGPR, reg.fpr());
+ }
}
MacroAssemblerCodeRef slowPathCallThunkGenerator(VM& vm, const SlowPathCallKey& key)
@@ -122,8 +195,10 @@ MacroAssemblerCodeRef slowPathCallThunkGenerator(VM& vm, const SlowPathCallKey&
jit.preserveReturnAddressAfterCall(GPRInfo::nonArgGPR0);
jit.storePtr(GPRInfo::nonArgGPR0, AssemblyHelpers::Address(MacroAssembler::stackPointerRegister, key.offset()));
- JITCompiler::Call call = jit.call();
+ registerClobberCheck(jit, key.argumentRegisters());
+ AssemblyHelpers::Call call = jit.call();
+
jit.loadPtr(AssemblyHelpers::Address(MacroAssembler::stackPointerRegister, key.offset()), GPRInfo::nonPreservedNonReturnGPR);
jit.restoreReturnAddressBeforeReturn(GPRInfo::nonPreservedNonReturnGPR);
@@ -147,7 +222,7 @@ MacroAssemblerCodeRef slowPathCallThunkGenerator(VM& vm, const SlowPathCallKey&
jit.ret();
- LinkBuffer patchBuffer(vm, &jit, GLOBAL_THUNK_ID);
+ LinkBuffer patchBuffer(vm, jit, GLOBAL_THUNK_ID);
patchBuffer.link(call, FunctionPtr(key.callTarget()));
return FINALIZE_CODE(patchBuffer, ("FTL slow path call thunk for %s", toCString(key).data()));
}