blob: a3756ae443b81bc697c8442cfa8822279f3e0d2f [file] [log] [blame]
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001// Copyright 2012 the V8 project authors. All rights reserved.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Ben Murdochb0fe1622011-05-05 13:52:32 +01004
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005#if V8_TARGET_ARCH_IA32
Ben Murdochb8e0da22011-05-16 14:20:40 +01006
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007#include "src/codegen.h"
8#include "src/deoptimizer.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00009#include "src/full-codegen/full-codegen.h"
10#include "src/ia32/frames-ia32.h"
11#include "src/register-configuration.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000012#include "src/safepoint-table.h"
Ben Murdochb0fe1622011-05-05 13:52:32 +010013
14namespace v8 {
15namespace internal {
16
Ben Murdoch69a99ed2011-11-30 16:03:39 +000017const int Deoptimizer::table_entry_size_ = 10;
Ben Murdochb0fe1622011-05-05 13:52:32 +010018
Steve Block1e0659c2011-05-24 12:43:12 +010019
20int Deoptimizer::patch_size() {
21 return Assembler::kCallInstructionLength;
22}
23
24
Steve Block44f0eee2011-05-26 01:26:41 +010025void Deoptimizer::EnsureRelocSpaceForLazyDeoptimization(Handle<Code> code) {
26 Isolate* isolate = code->GetIsolate();
27 HandleScope scope(isolate);
Ben Murdochb0fe1622011-05-05 13:52:32 +010028
Steve Block44f0eee2011-05-26 01:26:41 +010029 // Compute the size of relocation information needed for the code
Emily Bernierd0a1eb72015-03-24 16:35:39 -040030 // patching in Deoptimizer::PatchCodeForDeoptimization below.
Steve Block44f0eee2011-05-26 01:26:41 +010031 int min_reloc_size = 0;
Ben Murdoch2b4ba112012-01-20 14:57:15 +000032 int prev_pc_offset = 0;
33 DeoptimizationInputData* deopt_data =
34 DeoptimizationInputData::cast(code->deoptimization_data());
35 for (int i = 0; i < deopt_data->DeoptCount(); i++) {
36 int pc_offset = deopt_data->Pc(i)->value();
37 if (pc_offset == -1) continue;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000038 DCHECK_GE(pc_offset, prev_pc_offset);
Ben Murdoch2b4ba112012-01-20 14:57:15 +000039 int pc_delta = pc_offset - prev_pc_offset;
40 // We use RUNTIME_ENTRY reloc info which has a size of 2 bytes
41 // if encodable with small pc delta encoding and up to 6 bytes
42 // otherwise.
43 if (pc_delta <= RelocInfo::kMaxSmallPCDelta) {
44 min_reloc_size += 2;
45 } else {
46 min_reloc_size += 6;
Steve Block44f0eee2011-05-26 01:26:41 +010047 }
Ben Murdoch2b4ba112012-01-20 14:57:15 +000048 prev_pc_offset = pc_offset;
Steve Block44f0eee2011-05-26 01:26:41 +010049 }
50
51 // If the relocation information is not big enough we create a new
52 // relocation info object that is padded with comments to make it
53 // big enough for lazy doptimization.
54 int reloc_length = code->relocation_info()->length();
55 if (min_reloc_size > reloc_length) {
56 int comment_reloc_size = RelocInfo::kMinRelocCommentSize;
57 // Padding needed.
58 int min_padding = min_reloc_size - reloc_length;
59 // Number of comments needed to take up at least that much space.
60 int additional_comments =
61 (min_padding + comment_reloc_size - 1) / comment_reloc_size;
62 // Actual padding size.
63 int padding = additional_comments * comment_reloc_size;
64 // Allocate new relocation info and copy old relocation to the end
65 // of the new relocation info array because relocation info is
66 // written and read backwards.
67 Factory* factory = isolate->factory();
68 Handle<ByteArray> new_reloc =
69 factory->NewByteArray(reloc_length + padding, TENURED);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000070 MemCopy(new_reloc->GetDataStartAddress() + padding,
71 code->relocation_info()->GetDataStartAddress(), reloc_length);
Steve Block44f0eee2011-05-26 01:26:41 +010072 // Create a relocation writer to write the comments in the padding
73 // space. Use position 0 for everything to ensure short encoding.
74 RelocInfoWriter reloc_info_writer(
75 new_reloc->GetDataStartAddress() + padding, 0);
76 intptr_t comment_string
77 = reinterpret_cast<intptr_t>(RelocInfo::kFillerCommentString);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000078 RelocInfo rinfo(isolate, 0, RelocInfo::COMMENT, comment_string, NULL);
Steve Block44f0eee2011-05-26 01:26:41 +010079 for (int i = 0; i < additional_comments; ++i) {
80#ifdef DEBUG
81 byte* pos_before = reloc_info_writer.pos();
82#endif
83 reloc_info_writer.Write(&rinfo);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000084 DCHECK(RelocInfo::kMinRelocCommentSize ==
Steve Block44f0eee2011-05-26 01:26:41 +010085 pos_before - reloc_info_writer.pos());
86 }
87 // Replace relocation information on the code object.
88 code->set_relocation_info(*new_reloc);
89 }
90}
91
92
Ben Murdochb8a8cc12014-11-26 15:28:44 +000093void Deoptimizer::PatchCodeForDeoptimization(Isolate* isolate, Code* code) {
Steve Block1e0659c2011-05-24 12:43:12 +010094 Address code_start_address = code->instruction_start();
Ben Murdochb0fe1622011-05-05 13:52:32 +010095
Ben Murdochb8a8cc12014-11-26 15:28:44 +000096 if (FLAG_zap_code_space) {
97 // Fail hard and early if we enter this code object again.
98 byte* pointer = code->FindCodeAgeSequence();
99 if (pointer != NULL) {
100 pointer += kNoCodeAgeSequenceLength;
101 } else {
102 pointer = code->instruction_start();
103 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000104 CodePatcher patcher(isolate, pointer, 1);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000105 patcher.masm()->int3();
106
107 DeoptimizationInputData* data =
108 DeoptimizationInputData::cast(code->deoptimization_data());
109 int osr_offset = data->OsrPcOffset()->value();
110 if (osr_offset > 0) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000111 CodePatcher osr_patcher(isolate, code->instruction_start() + osr_offset,
112 1);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000113 osr_patcher.masm()->int3();
114 }
115 }
116
Steve Block1e0659c2011-05-24 12:43:12 +0100117 // We will overwrite the code's relocation info in-place. Relocation info
118 // is written backward. The relocation info is the payload of a byte
119 // array. Later on we will slide this to the start of the byte array and
120 // create a filler object in the remaining space.
121 ByteArray* reloc_info = code->relocation_info();
122 Address reloc_end_address = reloc_info->address() + reloc_info->Size();
123 RelocInfoWriter reloc_info_writer(reloc_end_address, code_start_address);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100124
Ben Murdoch2b4ba112012-01-20 14:57:15 +0000125 // Since the call is a relative encoding, write new
Steve Block1e0659c2011-05-24 12:43:12 +0100126 // reloc info. We do not need any of the existing reloc info because the
127 // existing code will not be used again (we zap it in debug builds).
Ben Murdoch2b4ba112012-01-20 14:57:15 +0000128 //
129 // Emit call to lazy deoptimization at all lazy deopt points.
130 DeoptimizationInputData* deopt_data =
131 DeoptimizationInputData::cast(code->deoptimization_data());
132#ifdef DEBUG
133 Address prev_call_address = NULL;
134#endif
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000135 // For each LLazyBailout instruction insert a call to the corresponding
136 // deoptimization entry.
Ben Murdoch2b4ba112012-01-20 14:57:15 +0000137 for (int i = 0; i < deopt_data->DeoptCount(); i++) {
138 if (deopt_data->Pc(i)->value() == -1) continue;
139 // Patch lazy deoptimization entry.
140 Address call_address = code_start_address + deopt_data->Pc(i)->value();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000141 CodePatcher patcher(isolate, call_address, patch_size());
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000142 Address deopt_entry = GetDeoptimizationEntry(isolate, i, LAZY);
143 patcher.masm()->call(deopt_entry, RelocInfo::NONE32);
Ben Murdoch2b4ba112012-01-20 14:57:15 +0000144 // We use RUNTIME_ENTRY for deoptimization bailouts.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000145 RelocInfo rinfo(isolate, call_address + 1, // 1 after the call opcode.
Ben Murdoch2b4ba112012-01-20 14:57:15 +0000146 RelocInfo::RUNTIME_ENTRY,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000147 reinterpret_cast<intptr_t>(deopt_entry), NULL);
Ben Murdoch2b4ba112012-01-20 14:57:15 +0000148 reloc_info_writer.Write(&rinfo);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000149 DCHECK_GE(reloc_info_writer.pos(),
Ben Murdoch2b4ba112012-01-20 14:57:15 +0000150 reloc_info->address() + ByteArray::kHeaderSize);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000151 DCHECK(prev_call_address == NULL ||
Ben Murdoch2b4ba112012-01-20 14:57:15 +0000152 call_address >= prev_call_address + patch_size());
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000153 DCHECK(call_address + patch_size() <= code->instruction_end());
Ben Murdoch2b4ba112012-01-20 14:57:15 +0000154#ifdef DEBUG
155 prev_call_address = call_address;
156#endif
Ben Murdochb0fe1622011-05-05 13:52:32 +0100157 }
Steve Block1e0659c2011-05-24 12:43:12 +0100158
159 // Move the relocation info to the beginning of the byte array.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000160 const int new_reloc_length = reloc_end_address - reloc_info_writer.pos();
161 MemMove(code->relocation_start(), reloc_info_writer.pos(), new_reloc_length);
Steve Block1e0659c2011-05-24 12:43:12 +0100162
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000163 // Right trim the relocation info to free up remaining space.
164 const int delta = reloc_info->length() - new_reloc_length;
165 if (delta > 0) {
166 isolate->heap()->RightTrimFixedArray<Heap::SEQUENTIAL_TO_SWEEPER>(
167 reloc_info, delta);
168 }
Ben Murdochb0fe1622011-05-05 13:52:32 +0100169}
170
171
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000172void Deoptimizer::SetPlatformCompiledStubRegisters(
173 FrameDescription* output_frame, CodeStubDescriptor* descriptor) {
174 intptr_t handler =
175 reinterpret_cast<intptr_t>(descriptor->deoptimization_handler());
176 int params = descriptor->GetHandlerParameterCount();
177 output_frame->SetRegister(eax.code(), params);
178 output_frame->SetRegister(ebx.code(), handler);
179}
180
181
182void Deoptimizer::CopyDoubleRegisters(FrameDescription* output_frame) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000183 for (int i = 0; i < XMMRegister::kMaxNumRegisters; ++i) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000184 double double_value = input_->GetDoubleRegister(i);
185 output_frame->SetDoubleRegister(i, double_value);
186 }
187}
188
Ben Murdoch097c5b22016-05-18 11:27:45 +0100189bool Deoptimizer::HasAlignmentPadding(SharedFunctionInfo* shared) {
190 int parameter_count = shared->internal_formal_parameter_count() + 1;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000191 unsigned input_frame_size = input_->GetFrameSize();
192 unsigned alignment_state_offset =
193 input_frame_size - parameter_count * kPointerSize -
194 StandardFrameConstants::kFixedFrameSize -
195 kPointerSize;
196 DCHECK(JavaScriptFrameConstants::kDynamicAlignmentStateOffset ==
197 JavaScriptFrameConstants::kLocal0Offset);
198 int32_t alignment_state = input_->GetFrameSlot(alignment_state_offset);
199 return (alignment_state == kAlignmentPaddingPushed);
200}
201
202
Ben Murdochb0fe1622011-05-05 13:52:32 +0100203#define __ masm()->
204
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000205void Deoptimizer::TableEntryGenerator::Generate() {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100206 GeneratePrologue();
Steve Block44f0eee2011-05-26 01:26:41 +0100207
Ben Murdochb0fe1622011-05-05 13:52:32 +0100208 // Save all general purpose registers before messing with them.
209 const int kNumberOfRegisters = Register::kNumRegisters;
210
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000211 const int kDoubleRegsSize = kDoubleSize * XMMRegister::kMaxNumRegisters;
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100212 __ sub(esp, Immediate(kDoubleRegsSize));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000213 const RegisterConfiguration* config =
214 RegisterConfiguration::ArchDefault(RegisterConfiguration::CRANKSHAFT);
215 for (int i = 0; i < config->num_allocatable_double_registers(); ++i) {
216 int code = config->GetAllocatableDoubleCode(i);
217 XMMRegister xmm_reg = XMMRegister::from_code(code);
218 int offset = code * kDoubleSize;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000219 __ movsd(Operand(esp, offset), xmm_reg);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100220 }
221
222 __ pushad();
223
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000224 ExternalReference c_entry_fp_address(Isolate::kCEntryFPAddress, isolate());
225 __ mov(Operand::StaticVariable(c_entry_fp_address), ebp);
226
Ben Murdochb0fe1622011-05-05 13:52:32 +0100227 const int kSavedRegistersAreaSize = kNumberOfRegisters * kPointerSize +
228 kDoubleRegsSize;
229
230 // Get the bailout id from the stack.
231 __ mov(ebx, Operand(esp, kSavedRegistersAreaSize));
232
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000233 // Get the address of the location in the code object
Ben Murdochb0fe1622011-05-05 13:52:32 +0100234 // and compute the fp-to-sp delta in register edx.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000235 __ mov(ecx, Operand(esp, kSavedRegistersAreaSize + 1 * kPointerSize));
236 __ lea(edx, Operand(esp, kSavedRegistersAreaSize + 2 * kPointerSize));
237
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100238 __ sub(edx, ebp);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100239 __ neg(edx);
240
241 // Allocate a new deoptimizer object.
Ben Murdoch8b112d22011-06-08 16:22:53 +0100242 __ PrepareCallCFunction(6, eax);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100243 __ mov(eax, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset));
244 __ mov(Operand(esp, 0 * kPointerSize), eax); // Function.
245 __ mov(Operand(esp, 1 * kPointerSize), Immediate(type())); // Bailout type.
246 __ mov(Operand(esp, 2 * kPointerSize), ebx); // Bailout id.
247 __ mov(Operand(esp, 3 * kPointerSize), ecx); // Code address or 0.
248 __ mov(Operand(esp, 4 * kPointerSize), edx); // Fp-to-sp delta.
Ben Murdoch8b112d22011-06-08 16:22:53 +0100249 __ mov(Operand(esp, 5 * kPointerSize),
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000250 Immediate(ExternalReference::isolate_address(isolate())));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100251 {
252 AllowExternalCallThatCantCauseGC scope(masm());
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000253 __ CallCFunction(ExternalReference::new_deoptimizer_function(isolate()), 6);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100254 }
Ben Murdochb0fe1622011-05-05 13:52:32 +0100255
256 // Preserve deoptimizer object in register eax and get the input
257 // frame descriptor pointer.
258 __ mov(ebx, Operand(eax, Deoptimizer::input_offset()));
259
260 // Fill in the input registers.
Steve Block1e0659c2011-05-24 12:43:12 +0100261 for (int i = kNumberOfRegisters - 1; i >= 0; i--) {
262 int offset = (i * kPointerSize) + FrameDescription::registers_offset();
263 __ pop(Operand(ebx, offset));
Ben Murdochb0fe1622011-05-05 13:52:32 +0100264 }
265
Ben Murdochb0fe1622011-05-05 13:52:32 +0100266 int double_regs_offset = FrameDescription::double_registers_offset();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000267 // Fill in the double input registers.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000268 for (int i = 0; i < config->num_allocatable_double_registers(); ++i) {
269 int code = config->GetAllocatableDoubleCode(i);
270 int dst_offset = code * kDoubleSize + double_regs_offset;
271 int src_offset = code * kDoubleSize;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000272 __ movsd(xmm0, Operand(esp, src_offset));
273 __ movsd(Operand(ebx, dst_offset), xmm0);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100274 }
275
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000276 // Clear FPU all exceptions.
277 // TODO(ulan): Find out why the TOP register is not zero here in some cases,
278 // and check that the generated code never deoptimizes with unbalanced stack.
279 __ fnclex();
280
281 // Remove the bailout id, return address and the double registers.
282 __ add(esp, Immediate(kDoubleRegsSize + 2 * kPointerSize));
Ben Murdochb0fe1622011-05-05 13:52:32 +0100283
284 // Compute a pointer to the unwinding limit in register ecx; that is
285 // the first stack slot not part of the input frame.
286 __ mov(ecx, Operand(ebx, FrameDescription::frame_size_offset()));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100287 __ add(ecx, esp);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100288
289 // Unwind the stack down to - but not including - the unwinding
290 // limit and copy the contents of the activation frame to the input
291 // frame description.
292 __ lea(edx, Operand(ebx, FrameDescription::frame_content_offset()));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000293 Label pop_loop_header;
294 __ jmp(&pop_loop_header);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100295 Label pop_loop;
296 __ bind(&pop_loop);
297 __ pop(Operand(edx, 0));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100298 __ add(edx, Immediate(sizeof(uint32_t)));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000299 __ bind(&pop_loop_header);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100300 __ cmp(ecx, esp);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100301 __ j(not_equal, &pop_loop);
302
303 // Compute the output frame in the deoptimizer.
304 __ push(eax);
305 __ PrepareCallCFunction(1, ebx);
306 __ mov(Operand(esp, 0 * kPointerSize), eax);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100307 {
308 AllowExternalCallThatCantCauseGC scope(masm());
309 __ CallCFunction(
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000310 ExternalReference::compute_output_frames_function(isolate()), 1);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100311 }
Ben Murdochb0fe1622011-05-05 13:52:32 +0100312 __ pop(eax);
313
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000314 // If frame was dynamically aligned, pop padding.
315 Label no_padding;
316 __ cmp(Operand(eax, Deoptimizer::has_alignment_padding_offset()),
317 Immediate(0));
318 __ j(equal, &no_padding);
319 __ pop(ecx);
320 if (FLAG_debug_code) {
321 __ cmp(ecx, Immediate(kAlignmentZapValue));
322 __ Assert(equal, kAlignmentMarkerExpected);
323 }
324 __ bind(&no_padding);
325
Ben Murdochb0fe1622011-05-05 13:52:32 +0100326 // Replace the current frame with the output frames.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000327 Label outer_push_loop, inner_push_loop,
328 outer_loop_header, inner_loop_header;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100329 // Outer loop state: eax = current FrameDescription**, edx = one past the
330 // last FrameDescription**.
331 __ mov(edx, Operand(eax, Deoptimizer::output_count_offset()));
332 __ mov(eax, Operand(eax, Deoptimizer::output_offset()));
333 __ lea(edx, Operand(eax, edx, times_4, 0));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000334 __ jmp(&outer_loop_header);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100335 __ bind(&outer_push_loop);
336 // Inner loop state: ebx = current FrameDescription*, ecx = loop index.
337 __ mov(ebx, Operand(eax, 0));
338 __ mov(ecx, Operand(ebx, FrameDescription::frame_size_offset()));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000339 __ jmp(&inner_loop_header);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100340 __ bind(&inner_push_loop);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100341 __ sub(ecx, Immediate(sizeof(uint32_t)));
Ben Murdochb0fe1622011-05-05 13:52:32 +0100342 __ push(Operand(ebx, ecx, times_1, FrameDescription::frame_content_offset()));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000343 __ bind(&inner_loop_header);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100344 __ test(ecx, ecx);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100345 __ j(not_zero, &inner_push_loop);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100346 __ add(eax, Immediate(kPointerSize));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000347 __ bind(&outer_loop_header);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100348 __ cmp(eax, edx);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100349 __ j(below, &outer_push_loop);
350
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000351 // In case of a failed STUB, we have to restore the XMM registers.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000352 for (int i = 0; i < config->num_allocatable_double_registers(); ++i) {
353 int code = config->GetAllocatableDoubleCode(i);
354 XMMRegister xmm_reg = XMMRegister::from_code(code);
355 int src_offset = code * kDoubleSize + double_regs_offset;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000356 __ movsd(xmm_reg, Operand(ebx, src_offset));
Ben Murdochb0fe1622011-05-05 13:52:32 +0100357 }
358
359 // Push state, pc, and continuation from the last output frame.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000360 __ push(Operand(ebx, FrameDescription::state_offset()));
Ben Murdochb0fe1622011-05-05 13:52:32 +0100361 __ push(Operand(ebx, FrameDescription::pc_offset()));
362 __ push(Operand(ebx, FrameDescription::continuation_offset()));
363
364
365 // Push the registers from the last output frame.
366 for (int i = 0; i < kNumberOfRegisters; i++) {
Steve Block1e0659c2011-05-24 12:43:12 +0100367 int offset = (i * kPointerSize) + FrameDescription::registers_offset();
Ben Murdochb0fe1622011-05-05 13:52:32 +0100368 __ push(Operand(ebx, offset));
369 }
370
371 // Restore the registers from the stack.
372 __ popad();
373
374 // Return to the continuation point.
375 __ ret(0);
376}
377
378
379void Deoptimizer::TableEntryGenerator::GeneratePrologue() {
380 // Create a sequence of deoptimization entries.
381 Label done;
382 for (int i = 0; i < count(); i++) {
383 int start = masm()->pc_offset();
384 USE(start);
385 __ push_imm32(i);
386 __ jmp(&done);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000387 DCHECK(masm()->pc_offset() - start == table_entry_size_);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100388 }
389 __ bind(&done);
390}
391
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000392
393void FrameDescription::SetCallerPc(unsigned offset, intptr_t value) {
394 SetFrameSlot(offset, value);
395}
396
397
398void FrameDescription::SetCallerFp(unsigned offset, intptr_t value) {
399 SetFrameSlot(offset, value);
400}
401
402
403void FrameDescription::SetCallerConstantPool(unsigned offset, intptr_t value) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000404 // No embedded constant pool support.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000405 UNREACHABLE();
406}
407
408
Ben Murdochb0fe1622011-05-05 13:52:32 +0100409#undef __
410
411
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000412} // namespace internal
413} // namespace v8
Ben Murdochb8e0da22011-05-16 14:20:40 +0100414
415#endif // V8_TARGET_ARCH_IA32