Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Ben Murdoch | 8c569c4 | 2011-03-10 11:43:29 +0000 | [diff] [blame] | 4 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 5 | #include "src/v8.h" |
Ben Murdoch | 8c569c4 | 2011-03-10 11:43:29 +0000 | [diff] [blame] | 6 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 7 | #if V8_TARGET_ARCH_X64 |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 8 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 9 | #include "src/codegen.h" |
| 10 | #include "src/deoptimizer.h" |
| 11 | #include "src/full-codegen.h" |
| 12 | #include "src/safepoint-table.h" |
Ben Murdoch | 8c569c4 | 2011-03-10 11:43:29 +0000 | [diff] [blame] | 13 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 14 | namespace v8 { |
| 15 | namespace internal { |
Ben Murdoch | 8c569c4 | 2011-03-10 11:43:29 +0000 | [diff] [blame] | 16 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 17 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 18 | const int Deoptimizer::table_entry_size_ = 10; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 19 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 20 | |
| 21 | int Deoptimizer::patch_size() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 22 | return Assembler::kCallSequenceLength; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 26 | void Deoptimizer::PatchCodeForDeoptimization(Isolate* isolate, Code* code) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 27 | // Invalidate the relocation information, as it will become invalid by the |
| 28 | // code patching below, and is not needed any more. |
| 29 | code->InvalidateRelocation(); |
| 30 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 31 | if (FLAG_zap_code_space) { |
| 32 | // Fail hard and early if we enter this code object again. |
| 33 | byte* pointer = code->FindCodeAgeSequence(); |
| 34 | if (pointer != NULL) { |
| 35 | pointer += kNoCodeAgeSequenceLength; |
| 36 | } else { |
| 37 | pointer = code->instruction_start(); |
| 38 | } |
| 39 | CodePatcher patcher(pointer, 1); |
| 40 | patcher.masm()->int3(); |
| 41 | |
| 42 | DeoptimizationInputData* data = |
| 43 | DeoptimizationInputData::cast(code->deoptimization_data()); |
| 44 | int osr_offset = data->OsrPcOffset()->value(); |
| 45 | if (osr_offset > 0) { |
| 46 | CodePatcher osr_patcher(code->instruction_start() + osr_offset, 1); |
| 47 | osr_patcher.masm()->int3(); |
| 48 | } |
| 49 | } |
| 50 | |
Ben Murdoch | 2b4ba11 | 2012-01-20 14:57:15 +0000 | [diff] [blame] | 51 | // For each LLazyBailout instruction insert a absolute call to the |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 52 | // corresponding deoptimization entry, or a short call to an absolute |
| 53 | // jump if space is short. The absolute jumps are put in a table just |
| 54 | // before the safepoint table (space was allocated there when the Code |
| 55 | // object was created, if necessary). |
| 56 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 57 | Address instruction_start = code->instruction_start(); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 58 | #ifdef DEBUG |
Ben Murdoch | 2b4ba11 | 2012-01-20 14:57:15 +0000 | [diff] [blame] | 59 | Address prev_call_address = NULL; |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 60 | #endif |
Ben Murdoch | 2b4ba11 | 2012-01-20 14:57:15 +0000 | [diff] [blame] | 61 | DeoptimizationInputData* deopt_data = |
| 62 | DeoptimizationInputData::cast(code->deoptimization_data()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 63 | deopt_data->SetSharedFunctionInfo(Smi::FromInt(0)); |
| 64 | // For each LLazyBailout instruction insert a call to the corresponding |
| 65 | // deoptimization entry. |
Ben Murdoch | 2b4ba11 | 2012-01-20 14:57:15 +0000 | [diff] [blame] | 66 | for (int i = 0; i < deopt_data->DeoptCount(); i++) { |
| 67 | if (deopt_data->Pc(i)->value() == -1) continue; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 68 | // Position where Call will be patched in. |
Ben Murdoch | 2b4ba11 | 2012-01-20 14:57:15 +0000 | [diff] [blame] | 69 | Address call_address = instruction_start + deopt_data->Pc(i)->value(); |
| 70 | // There is room enough to write a long call instruction because we pad |
| 71 | // LLazyBailout instructions with nops if necessary. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 72 | CodePatcher patcher(call_address, Assembler::kCallSequenceLength); |
| 73 | patcher.masm()->Call(GetDeoptimizationEntry(isolate, i, LAZY), |
| 74 | Assembler::RelocInfoNone()); |
| 75 | DCHECK(prev_call_address == NULL || |
Ben Murdoch | 2b4ba11 | 2012-01-20 14:57:15 +0000 | [diff] [blame] | 76 | call_address >= prev_call_address + patch_size()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 77 | DCHECK(call_address + patch_size() <= code->instruction_end()); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 78 | #ifdef DEBUG |
Ben Murdoch | 2b4ba11 | 2012-01-20 14:57:15 +0000 | [diff] [blame] | 79 | prev_call_address = call_address; |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 80 | #endif |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 81 | } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 85 | void Deoptimizer::FillInputFrame(Address tos, JavaScriptFrame* frame) { |
| 86 | // Set the register values. The values are not important as there are no |
| 87 | // callee saved registers in JavaScript frames, so all registers are |
| 88 | // spilled. Registers rbp and rsp are set to the correct values though. |
| 89 | for (int i = 0; i < Register::kNumRegisters; i++) { |
| 90 | input_->SetRegister(i, i * 4); |
| 91 | } |
| 92 | input_->SetRegister(rsp.code(), reinterpret_cast<intptr_t>(frame->sp())); |
| 93 | input_->SetRegister(rbp.code(), reinterpret_cast<intptr_t>(frame->fp())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 94 | for (int i = 0; i < DoubleRegister::NumAllocatableRegisters(); i++) { |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 95 | input_->SetDoubleRegister(i, 0.0); |
| 96 | } |
| 97 | |
| 98 | // Fill the frame content from the actual data on the frame. |
| 99 | for (unsigned i = 0; i < input_->GetFrameSize(); i += kPointerSize) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 100 | input_->SetFrameSlot(i, Memory::uintptr_at(tos + i)); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 101 | } |
| 102 | } |
| 103 | |
| 104 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 105 | void Deoptimizer::SetPlatformCompiledStubRegisters( |
| 106 | FrameDescription* output_frame, CodeStubDescriptor* descriptor) { |
| 107 | intptr_t handler = |
| 108 | reinterpret_cast<intptr_t>(descriptor->deoptimization_handler()); |
| 109 | int params = descriptor->GetHandlerParameterCount(); |
| 110 | output_frame->SetRegister(rax.code(), params); |
| 111 | output_frame->SetRegister(rbx.code(), handler); |
| 112 | } |
| 113 | |
| 114 | |
| 115 | void Deoptimizer::CopyDoubleRegisters(FrameDescription* output_frame) { |
| 116 | for (int i = 0; i < XMMRegister::NumAllocatableRegisters(); ++i) { |
| 117 | double double_value = input_->GetDoubleRegister(i); |
| 118 | output_frame->SetDoubleRegister(i, double_value); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | |
| 123 | bool Deoptimizer::HasAlignmentPadding(JSFunction* function) { |
| 124 | // There is no dynamic alignment padding on x64 in the input frame. |
| 125 | return false; |
| 126 | } |
| 127 | |
| 128 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 129 | #define __ masm()-> |
| 130 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 131 | void Deoptimizer::EntryGenerator::Generate() { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 132 | GeneratePrologue(); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 133 | |
| 134 | // Save all general purpose registers before messing with them. |
| 135 | const int kNumberOfRegisters = Register::kNumRegisters; |
| 136 | |
| 137 | const int kDoubleRegsSize = kDoubleSize * |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 138 | XMMRegister::NumAllocatableRegisters(); |
| 139 | __ subp(rsp, Immediate(kDoubleRegsSize)); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 140 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 141 | for (int i = 0; i < XMMRegister::NumAllocatableRegisters(); ++i) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 142 | XMMRegister xmm_reg = XMMRegister::FromAllocationIndex(i); |
| 143 | int offset = i * kDoubleSize; |
| 144 | __ movsd(Operand(rsp, offset), xmm_reg); |
| 145 | } |
| 146 | |
| 147 | // We push all registers onto the stack, even though we do not need |
| 148 | // to restore all later. |
| 149 | for (int i = 0; i < kNumberOfRegisters; i++) { |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 150 | Register r = Register::from_code(i); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 151 | __ pushq(r); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 152 | } |
| 153 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 154 | const int kSavedRegistersAreaSize = kNumberOfRegisters * kRegisterSize + |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 155 | kDoubleRegsSize; |
| 156 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 157 | // We use this to keep the value of the fifth argument temporarily. |
| 158 | // Unfortunately we can't store it directly in r8 (used for passing |
| 159 | // this on linux), since it is another parameter passing register on windows. |
| 160 | Register arg5 = r11; |
| 161 | |
| 162 | // Get the bailout id from the stack. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 163 | __ movp(arg_reg_3, Operand(rsp, kSavedRegistersAreaSize)); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 164 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 165 | // Get the address of the location in the code object |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 166 | // and compute the fp-to-sp delta in register arg5. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 167 | __ movp(arg_reg_4, Operand(rsp, kSavedRegistersAreaSize + 1 * kRegisterSize)); |
| 168 | __ leap(arg5, Operand(rsp, kSavedRegistersAreaSize + 1 * kRegisterSize + |
| 169 | kPCOnStackSize)); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 170 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 171 | __ subp(arg5, rbp); |
| 172 | __ negp(arg5); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 173 | |
| 174 | // Allocate a new deoptimizer object. |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 175 | __ PrepareCallCFunction(6); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 176 | __ movp(rax, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); |
| 177 | __ movp(arg_reg_1, rax); |
| 178 | __ Set(arg_reg_2, type()); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 179 | // Args 3 and 4 are already in the right registers. |
| 180 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 181 | // On windows put the arguments on the stack (PrepareCallCFunction |
| 182 | // has created space for this). On linux pass the arguments in r8 and r9. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 183 | #ifdef _WIN64 |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 184 | __ movq(Operand(rsp, 4 * kRegisterSize), arg5); |
| 185 | __ LoadAddress(arg5, ExternalReference::isolate_address(isolate())); |
| 186 | __ movq(Operand(rsp, 5 * kRegisterSize), arg5); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 187 | #else |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 188 | __ movp(r8, arg5); |
| 189 | __ LoadAddress(r9, ExternalReference::isolate_address(isolate())); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 190 | #endif |
| 191 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 192 | { AllowExternalCallThatCantCauseGC scope(masm()); |
| 193 | __ CallCFunction(ExternalReference::new_deoptimizer_function(isolate()), 6); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 194 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 195 | // Preserve deoptimizer object in register rax and get the input |
| 196 | // frame descriptor pointer. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 197 | __ movp(rbx, Operand(rax, Deoptimizer::input_offset())); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 198 | |
| 199 | // Fill in the input registers. |
| 200 | for (int i = kNumberOfRegisters -1; i >= 0; i--) { |
| 201 | int offset = (i * kPointerSize) + FrameDescription::registers_offset(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 202 | __ PopQuad(Operand(rbx, offset)); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | // Fill in the double input registers. |
| 206 | int double_regs_offset = FrameDescription::double_registers_offset(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 207 | for (int i = 0; i < XMMRegister::NumAllocatableRegisters(); i++) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 208 | int dst_offset = i * kDoubleSize + double_regs_offset; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 209 | __ popq(Operand(rbx, dst_offset)); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 210 | } |
| 211 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 212 | // Remove the bailout id and return address from the stack. |
| 213 | __ addp(rsp, Immediate(1 * kRegisterSize + kPCOnStackSize)); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 214 | |
| 215 | // Compute a pointer to the unwinding limit in register rcx; that is |
| 216 | // the first stack slot not part of the input frame. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 217 | __ movp(rcx, Operand(rbx, FrameDescription::frame_size_offset())); |
| 218 | __ addp(rcx, rsp); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 219 | |
| 220 | // Unwind the stack down to - but not including - the unwinding |
| 221 | // limit and copy the contents of the activation frame to the input |
| 222 | // frame description. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 223 | __ leap(rdx, Operand(rbx, FrameDescription::frame_content_offset())); |
| 224 | Label pop_loop_header; |
| 225 | __ jmp(&pop_loop_header); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 226 | Label pop_loop; |
| 227 | __ bind(&pop_loop); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 228 | __ Pop(Operand(rdx, 0)); |
| 229 | __ addp(rdx, Immediate(sizeof(intptr_t))); |
| 230 | __ bind(&pop_loop_header); |
| 231 | __ cmpp(rcx, rsp); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 232 | __ j(not_equal, &pop_loop); |
| 233 | |
| 234 | // Compute the output frame in the deoptimizer. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 235 | __ pushq(rax); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 236 | __ PrepareCallCFunction(2); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 237 | __ movp(arg_reg_1, rax); |
| 238 | __ LoadAddress(arg_reg_2, ExternalReference::isolate_address(isolate())); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 239 | { |
| 240 | AllowExternalCallThatCantCauseGC scope(masm()); |
| 241 | __ CallCFunction( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 242 | ExternalReference::compute_output_frames_function(isolate()), 2); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 243 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 244 | __ popq(rax); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 245 | |
| 246 | // Replace the current frame with the output frames. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 247 | Label outer_push_loop, inner_push_loop, |
| 248 | outer_loop_header, inner_loop_header; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 249 | // Outer loop state: rax = current FrameDescription**, rdx = one past the |
| 250 | // last FrameDescription**. |
| 251 | __ movl(rdx, Operand(rax, Deoptimizer::output_count_offset())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 252 | __ movp(rax, Operand(rax, Deoptimizer::output_offset())); |
| 253 | __ leap(rdx, Operand(rax, rdx, times_pointer_size, 0)); |
| 254 | __ jmp(&outer_loop_header); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 255 | __ bind(&outer_push_loop); |
| 256 | // Inner loop state: rbx = current FrameDescription*, rcx = loop index. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 257 | __ movp(rbx, Operand(rax, 0)); |
| 258 | __ movp(rcx, Operand(rbx, FrameDescription::frame_size_offset())); |
| 259 | __ jmp(&inner_loop_header); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 260 | __ bind(&inner_push_loop); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 261 | __ subp(rcx, Immediate(sizeof(intptr_t))); |
| 262 | __ Push(Operand(rbx, rcx, times_1, FrameDescription::frame_content_offset())); |
| 263 | __ bind(&inner_loop_header); |
| 264 | __ testp(rcx, rcx); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 265 | __ j(not_zero, &inner_push_loop); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 266 | __ addp(rax, Immediate(kPointerSize)); |
| 267 | __ bind(&outer_loop_header); |
| 268 | __ cmpp(rax, rdx); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 269 | __ j(below, &outer_push_loop); |
| 270 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 271 | for (int i = 0; i < XMMRegister::NumAllocatableRegisters(); ++i) { |
| 272 | XMMRegister xmm_reg = XMMRegister::FromAllocationIndex(i); |
| 273 | int src_offset = i * kDoubleSize + double_regs_offset; |
| 274 | __ movsd(xmm_reg, Operand(rbx, src_offset)); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | // Push state, pc, and continuation from the last output frame. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 278 | __ Push(Operand(rbx, FrameDescription::state_offset())); |
| 279 | __ PushQuad(Operand(rbx, FrameDescription::pc_offset())); |
| 280 | __ PushQuad(Operand(rbx, FrameDescription::continuation_offset())); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 281 | |
| 282 | // Push the registers from the last output frame. |
| 283 | for (int i = 0; i < kNumberOfRegisters; i++) { |
| 284 | int offset = (i * kPointerSize) + FrameDescription::registers_offset(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 285 | __ PushQuad(Operand(rbx, offset)); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | // Restore the registers from the stack. |
| 289 | for (int i = kNumberOfRegisters - 1; i >= 0 ; i--) { |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 290 | Register r = Register::from_code(i); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 291 | // Do not restore rsp, simply pop the value into the next register |
| 292 | // and overwrite this afterwards. |
| 293 | if (r.is(rsp)) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 294 | DCHECK(i > 0); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 295 | r = Register::from_code(i - 1); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 296 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 297 | __ popq(r); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | // Set up the roots register. |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 301 | __ InitializeRootRegister(); |
| 302 | __ InitializeSmiConstantRegister(); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 303 | |
| 304 | // Return to the continuation point. |
| 305 | __ ret(0); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | |
| 309 | void Deoptimizer::TableEntryGenerator::GeneratePrologue() { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 310 | // Create a sequence of deoptimization entries. |
| 311 | Label done; |
| 312 | for (int i = 0; i < count(); i++) { |
| 313 | int start = masm()->pc_offset(); |
| 314 | USE(start); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 315 | __ pushq_imm32(i); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 316 | __ jmp(&done); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 317 | DCHECK(masm()->pc_offset() - start == table_entry_size_); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 318 | } |
| 319 | __ bind(&done); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 320 | } |
| 321 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 322 | |
| 323 | void FrameDescription::SetCallerPc(unsigned offset, intptr_t value) { |
| 324 | if (kPCOnStackSize == 2 * kPointerSize) { |
| 325 | // Zero out the high-32 bit of PC for x32 port. |
| 326 | SetFrameSlot(offset + kPointerSize, 0); |
| 327 | } |
| 328 | SetFrameSlot(offset, value); |
| 329 | } |
| 330 | |
| 331 | |
| 332 | void FrameDescription::SetCallerFp(unsigned offset, intptr_t value) { |
| 333 | if (kFPOnStackSize == 2 * kPointerSize) { |
| 334 | // Zero out the high-32 bit of FP for x32 port. |
| 335 | SetFrameSlot(offset + kPointerSize, 0); |
| 336 | } |
| 337 | SetFrameSlot(offset, value); |
| 338 | } |
| 339 | |
| 340 | |
| 341 | void FrameDescription::SetCallerConstantPool(unsigned offset, intptr_t value) { |
| 342 | // No out-of-line constant pool support. |
| 343 | UNREACHABLE(); |
| 344 | } |
| 345 | |
| 346 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 347 | #undef __ |
| 348 | |
| 349 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 350 | } } // namespace v8::internal |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 351 | |
| 352 | #endif // V8_TARGET_ARCH_X64 |