oliver@apple.com | b900914 | 2013-07-25 03:58:26 +0000 | [diff] [blame] | 1 | /* |
fpizlo@apple.com | da834ae | 2015-03-26 04:28:43 +0000 | [diff] [blame] | 2 | * Copyright (C) 2013, 2015 Apple Inc. All rights reserved. |
oliver@apple.com | b900914 | 2013-07-25 03:58:26 +0000 | [diff] [blame] | 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 DFGOSRExitCompilerCommon_h |
| 27 | #define DFGOSRExitCompilerCommon_h |
| 28 | |
oliver@apple.com | b900914 | 2013-07-25 03:58:26 +0000 | [diff] [blame] | 29 | #if ENABLE(DFG_JIT) |
| 30 | |
fpizlo@apple.com | cd8eb2c | 2013-09-20 18:42:41 +0000 | [diff] [blame] | 31 | #include "CCallHelpers.h" |
oliver@apple.com | b900914 | 2013-07-25 03:58:26 +0000 | [diff] [blame] | 32 | #include "DFGOSRExit.h" |
sbarati@apple.com | a582c18 | 2015-12-05 00:04:01 +0000 | [diff] [blame] | 33 | #include "DFGCommonData.h" |
| 34 | #include "DFGJITCode.h" |
| 35 | #include "FTLJITCode.h" |
commit-queue@webkit.org | dad321b | 2016-01-28 00:29:09 +0000 | [diff] [blame] | 36 | #include "RegisterSet.h" |
oliver@apple.com | b900914 | 2013-07-25 03:58:26 +0000 | [diff] [blame] | 37 | |
| 38 | namespace JSC { namespace DFG { |
| 39 | |
oliver@apple.com | ea77149 | 2013-07-25 03:58:38 +0000 | [diff] [blame] | 40 | void handleExitCounts(CCallHelpers&, const OSRExitBase&); |
| 41 | void reifyInlinedCallFrames(CCallHelpers&, const OSRExitBase&); |
sbarati@apple.com | fb6a8e2 | 2016-01-29 19:46:01 +0000 | [diff] [blame] | 42 | void adjustAndJumpToTarget(CCallHelpers&, const OSRExitBase&); |
oliver@apple.com | b900914 | 2013-07-25 03:58:26 +0000 | [diff] [blame] | 43 | |
sbarati@apple.com | a582c18 | 2015-12-05 00:04:01 +0000 | [diff] [blame] | 44 | template <typename JITCodeType> |
| 45 | void adjustFrameAndStackInOSRExitCompilerThunk(MacroAssembler& jit, VM* vm, JITCode::JITType jitType) |
| 46 | { |
| 47 | ASSERT(jitType == JITCode::DFGJIT || jitType == JITCode::FTLJIT); |
commit-queue@webkit.org | dad321b | 2016-01-28 00:29:09 +0000 | [diff] [blame] | 48 | |
sbarati@apple.com | a582c18 | 2015-12-05 00:04:01 +0000 | [diff] [blame] | 49 | bool isFTLOSRExit = jitType == JITCode::FTLJIT; |
commit-queue@webkit.org | dad321b | 2016-01-28 00:29:09 +0000 | [diff] [blame] | 50 | RegisterSet registersToPreserve; |
| 51 | registersToPreserve.set(GPRInfo::regT0); |
| 52 | if (isFTLOSRExit) { |
| 53 | // FTL can use the scratch registers for values. The code below uses |
| 54 | // the scratch registers. We need to preserve them before doing anything. |
| 55 | registersToPreserve.merge(RegisterSet::macroScratchRegisters()); |
| 56 | } |
| 57 | |
| 58 | size_t scratchSize = sizeof(void*) * registersToPreserve.numberOfSetGPRs(); |
sbarati@apple.com | a582c18 | 2015-12-05 00:04:01 +0000 | [diff] [blame] | 59 | if (isFTLOSRExit) |
| 60 | scratchSize += sizeof(void*); |
| 61 | |
| 62 | ScratchBuffer* scratchBuffer = vm->scratchBufferForSize(scratchSize); |
| 63 | char* buffer = static_cast<char*>(scratchBuffer->dataBuffer()); |
commit-queue@webkit.org | dad321b | 2016-01-28 00:29:09 +0000 | [diff] [blame] | 64 | |
| 65 | jit.pushToSave(GPRInfo::regT1); |
| 66 | jit.move(MacroAssembler::TrustedImmPtr(buffer), GPRInfo::regT1); |
| 67 | |
| 68 | unsigned storeOffset = 0; |
| 69 | registersToPreserve.forEach([&](Reg reg) { |
| 70 | jit.storePtr(reg.gpr(), MacroAssembler::Address(GPRInfo::regT1, storeOffset)); |
| 71 | storeOffset += sizeof(void*); |
| 72 | }); |
sbarati@apple.com | a582c18 | 2015-12-05 00:04:01 +0000 | [diff] [blame] | 73 | |
| 74 | if (isFTLOSRExit) { |
| 75 | // FTL OSRExits are entered via the code FTLExitThunkGenerator emits which does |
| 76 | // pushToSaveImmediateWithoutTouchRegisters with the OSR exit index. We need to load |
| 77 | // that top value and then push it back when we reset our SP. |
commit-queue@webkit.org | dad321b | 2016-01-28 00:29:09 +0000 | [diff] [blame] | 78 | jit.loadPtr(MacroAssembler::Address(MacroAssembler::stackPointerRegister, MacroAssembler::pushToSaveByteOffset()), GPRInfo::regT0); |
| 79 | jit.storePtr(GPRInfo::regT0, MacroAssembler::Address(GPRInfo::regT1, registersToPreserve.numberOfSetGPRs() * sizeof(void*))); |
sbarati@apple.com | a582c18 | 2015-12-05 00:04:01 +0000 | [diff] [blame] | 80 | } |
commit-queue@webkit.org | dad321b | 2016-01-28 00:29:09 +0000 | [diff] [blame] | 81 | jit.popToRestore(GPRInfo::regT1); |
sbarati@apple.com | a582c18 | 2015-12-05 00:04:01 +0000 | [diff] [blame] | 82 | |
| 83 | // We need to reset FP in the case of an exception. |
| 84 | jit.loadPtr(vm->addressOfCallFrameForCatch(), GPRInfo::regT0); |
| 85 | MacroAssembler::Jump didNotHaveException = jit.branchTestPtr(MacroAssembler::Zero, GPRInfo::regT0); |
| 86 | jit.move(GPRInfo::regT0, GPRInfo::callFrameRegister); |
| 87 | didNotHaveException.link(&jit); |
| 88 | // We need to make sure SP is correct in case of an exception. |
| 89 | jit.loadPtr(MacroAssembler::Address(GPRInfo::callFrameRegister, JSStack::CodeBlock * static_cast<int>(sizeof(Register))), GPRInfo::regT0); |
| 90 | jit.loadPtr(MacroAssembler::Address(GPRInfo::regT0, CodeBlock::jitCodeOffset()), GPRInfo::regT0); |
| 91 | jit.addPtr(MacroAssembler::TrustedImm32(JITCodeType::commonDataOffset()), GPRInfo::regT0); |
| 92 | jit.load32(MacroAssembler::Address(GPRInfo::regT0, CommonData::frameRegisterCountOffset()), GPRInfo::regT0); |
| 93 | // This does virtualRegisterForLocal(frameRegisterCount - 1)*sizeof(Register) where: |
| 94 | // virtualRegisterForLocal(frameRegisterCount - 1) |
| 95 | // = VirtualRegister::localToOperand(frameRegisterCount - 1) |
| 96 | // = -1 - (frameRegisterCount - 1) |
| 97 | // = -frameRegisterCount |
| 98 | jit.neg32(GPRInfo::regT0); |
| 99 | jit.mul32(MacroAssembler::TrustedImm32(sizeof(Register)), GPRInfo::regT0, GPRInfo::regT0); |
| 100 | #if USE(JSVALUE64) |
| 101 | jit.signExtend32ToPtr(GPRInfo::regT0, GPRInfo::regT0); |
| 102 | #endif |
| 103 | jit.addPtr(GPRInfo::callFrameRegister, GPRInfo::regT0); |
| 104 | jit.move(GPRInfo::regT0, MacroAssembler::stackPointerRegister); |
| 105 | |
| 106 | if (isFTLOSRExit) { |
commit-queue@webkit.org | dad321b | 2016-01-28 00:29:09 +0000 | [diff] [blame] | 107 | // Leave space for saving the OSR Exit Index. |
| 108 | jit.subPtr(MacroAssembler::TrustedImm32(MacroAssembler::pushToSaveByteOffset()), MacroAssembler::stackPointerRegister); |
| 109 | } |
| 110 | jit.pushToSave(GPRInfo::regT1); |
| 111 | |
| 112 | jit.move(MacroAssembler::TrustedImmPtr(buffer), GPRInfo::regT1); |
| 113 | if (isFTLOSRExit) { |
sbarati@apple.com | a582c18 | 2015-12-05 00:04:01 +0000 | [diff] [blame] | 114 | // FTL OSRExits are entered via FTLExitThunkGenerator code with does |
| 115 | // pushToSaveImmediateWithoutTouchRegisters. We need to load that top |
| 116 | // register and then store it back when we have our SP back to a safe value. |
commit-queue@webkit.org | dad321b | 2016-01-28 00:29:09 +0000 | [diff] [blame] | 117 | jit.loadPtr(MacroAssembler::Address(GPRInfo::regT1, registersToPreserve.numberOfSetGPRs() * sizeof(void*)), GPRInfo::regT0); |
| 118 | jit.storePtr(GPRInfo::regT0, MacroAssembler::Address(MacroAssembler::stackPointerRegister, MacroAssembler::pushToSaveByteOffset())); |
sbarati@apple.com | a582c18 | 2015-12-05 00:04:01 +0000 | [diff] [blame] | 119 | } |
| 120 | |
commit-queue@webkit.org | dad321b | 2016-01-28 00:29:09 +0000 | [diff] [blame] | 121 | unsigned loadOffset = 0; |
| 122 | registersToPreserve.forEach([&](Reg reg) { |
| 123 | jit.loadPtr(MacroAssembler::Address(GPRInfo::regT1, loadOffset), reg.gpr()); |
| 124 | loadOffset += sizeof(void*); |
| 125 | }); |
| 126 | jit.popToRestore(GPRInfo::regT1); |
sbarati@apple.com | a582c18 | 2015-12-05 00:04:01 +0000 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | |
oliver@apple.com | b900914 | 2013-07-25 03:58:26 +0000 | [diff] [blame] | 130 | } } // namespace JSC::DFG |
| 131 | |
| 132 | #endif // ENABLE(DFG_JIT) |
| 133 | |
| 134 | #endif // DFGOSRExitCompilerCommon_h |
| 135 | |