blob: f40e23c0f3519c05373b17368e59634855f3e26b [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#include "src/v8.h"
Ben Murdochb0fe1622011-05-05 13:52:32 +01006
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007#if V8_TARGET_ARCH_IA32
Ben Murdochb8e0da22011-05-16 14:20:40 +01008
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009#include "src/codegen.h"
10#include "src/deoptimizer.h"
11#include "src/full-codegen.h"
12#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
30 // patching in Deoptimizer::DeoptimizeFunction.
31 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 Murdoch3ef787d2012-04-12 10:51:47 +010078 RelocInfo rinfo(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 }
104 CodePatcher patcher(pointer, 1);
105 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) {
111 CodePatcher osr_patcher(code->instruction_start() + osr_offset, 1);
112 osr_patcher.masm()->int3();
113 }
114 }
115
Steve Block1e0659c2011-05-24 12:43:12 +0100116 // We will overwrite the code's relocation info in-place. Relocation info
117 // is written backward. The relocation info is the payload of a byte
118 // array. Later on we will slide this to the start of the byte array and
119 // create a filler object in the remaining space.
120 ByteArray* reloc_info = code->relocation_info();
121 Address reloc_end_address = reloc_info->address() + reloc_info->Size();
122 RelocInfoWriter reloc_info_writer(reloc_end_address, code_start_address);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100123
Ben Murdoch2b4ba112012-01-20 14:57:15 +0000124 // Since the call is a relative encoding, write new
Steve Block1e0659c2011-05-24 12:43:12 +0100125 // reloc info. We do not need any of the existing reloc info because the
126 // existing code will not be used again (we zap it in debug builds).
Ben Murdoch2b4ba112012-01-20 14:57:15 +0000127 //
128 // Emit call to lazy deoptimization at all lazy deopt points.
129 DeoptimizationInputData* deopt_data =
130 DeoptimizationInputData::cast(code->deoptimization_data());
131#ifdef DEBUG
132 Address prev_call_address = NULL;
133#endif
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000134 // For each LLazyBailout instruction insert a call to the corresponding
135 // deoptimization entry.
Ben Murdoch2b4ba112012-01-20 14:57:15 +0000136 for (int i = 0; i < deopt_data->DeoptCount(); i++) {
137 if (deopt_data->Pc(i)->value() == -1) continue;
138 // Patch lazy deoptimization entry.
139 Address call_address = code_start_address + deopt_data->Pc(i)->value();
140 CodePatcher patcher(call_address, patch_size());
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000141 Address deopt_entry = GetDeoptimizationEntry(isolate, i, LAZY);
142 patcher.masm()->call(deopt_entry, RelocInfo::NONE32);
Ben Murdoch2b4ba112012-01-20 14:57:15 +0000143 // We use RUNTIME_ENTRY for deoptimization bailouts.
144 RelocInfo rinfo(call_address + 1, // 1 after the call opcode.
145 RelocInfo::RUNTIME_ENTRY,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100146 reinterpret_cast<intptr_t>(deopt_entry),
147 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.
160 int new_reloc_size = reloc_end_address - reloc_info_writer.pos();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000161 MemMove(code->relocation_start(), reloc_info_writer.pos(), new_reloc_size);
Steve Block1e0659c2011-05-24 12:43:12 +0100162
163 // The relocation info is in place, update the size.
164 reloc_info->set_length(new_reloc_size);
165
166 // Handle the junk part after the new relocation info. We will create
167 // a non-live object in the extra space at the end of the former reloc info.
168 Address junk_address = reloc_info->address() + reloc_info->Size();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000169 DCHECK(junk_address <= reloc_end_address);
Steve Block44f0eee2011-05-26 01:26:41 +0100170 isolate->heap()->CreateFillerObjectAt(junk_address,
171 reloc_end_address - junk_address);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100172}
173
174
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000175void Deoptimizer::FillInputFrame(Address tos, JavaScriptFrame* frame) {
176 // Set the register values. The values are not important as there are no
177 // callee saved registers in JavaScript frames, so all registers are
178 // spilled. Registers ebp and esp are set to the correct values though.
179
180 for (int i = 0; i < Register::kNumRegisters; i++) {
181 input_->SetRegister(i, i * 4);
182 }
183 input_->SetRegister(esp.code(), reinterpret_cast<intptr_t>(frame->sp()));
184 input_->SetRegister(ebp.code(), reinterpret_cast<intptr_t>(frame->fp()));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000185 for (int i = 0; i < XMMRegister::kMaxNumAllocatableRegisters; i++) {
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000186 input_->SetDoubleRegister(i, 0.0);
187 }
188
189 // Fill the frame content from the actual data on the frame.
190 for (unsigned i = 0; i < input_->GetFrameSize(); i += kPointerSize) {
191 input_->SetFrameSlot(i, Memory::uint32_at(tos + i));
192 }
193}
194
195
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000196void Deoptimizer::SetPlatformCompiledStubRegisters(
197 FrameDescription* output_frame, CodeStubDescriptor* descriptor) {
198 intptr_t handler =
199 reinterpret_cast<intptr_t>(descriptor->deoptimization_handler());
200 int params = descriptor->GetHandlerParameterCount();
201 output_frame->SetRegister(eax.code(), params);
202 output_frame->SetRegister(ebx.code(), handler);
203}
204
205
206void Deoptimizer::CopyDoubleRegisters(FrameDescription* output_frame) {
207 for (int i = 0; i < XMMRegister::kMaxNumAllocatableRegisters; ++i) {
208 double double_value = input_->GetDoubleRegister(i);
209 output_frame->SetDoubleRegister(i, double_value);
210 }
211}
212
213
214bool Deoptimizer::HasAlignmentPadding(JSFunction* function) {
215 int parameter_count = function->shared()->formal_parameter_count() + 1;
216 unsigned input_frame_size = input_->GetFrameSize();
217 unsigned alignment_state_offset =
218 input_frame_size - parameter_count * kPointerSize -
219 StandardFrameConstants::kFixedFrameSize -
220 kPointerSize;
221 DCHECK(JavaScriptFrameConstants::kDynamicAlignmentStateOffset ==
222 JavaScriptFrameConstants::kLocal0Offset);
223 int32_t alignment_state = input_->GetFrameSlot(alignment_state_offset);
224 return (alignment_state == kAlignmentPaddingPushed);
225}
226
227
Ben Murdochb0fe1622011-05-05 13:52:32 +0100228#define __ masm()->
229
230void Deoptimizer::EntryGenerator::Generate() {
231 GeneratePrologue();
Steve Block44f0eee2011-05-26 01:26:41 +0100232
Ben Murdochb0fe1622011-05-05 13:52:32 +0100233 // Save all general purpose registers before messing with them.
234 const int kNumberOfRegisters = Register::kNumRegisters;
235
236 const int kDoubleRegsSize = kDoubleSize *
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000237 XMMRegister::kMaxNumAllocatableRegisters;
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100238 __ sub(esp, Immediate(kDoubleRegsSize));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000239 for (int i = 0; i < XMMRegister::kMaxNumAllocatableRegisters; ++i) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100240 XMMRegister xmm_reg = XMMRegister::FromAllocationIndex(i);
241 int offset = i * kDoubleSize;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000242 __ movsd(Operand(esp, offset), xmm_reg);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100243 }
244
245 __ pushad();
246
247 const int kSavedRegistersAreaSize = kNumberOfRegisters * kPointerSize +
248 kDoubleRegsSize;
249
250 // Get the bailout id from the stack.
251 __ mov(ebx, Operand(esp, kSavedRegistersAreaSize));
252
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000253 // Get the address of the location in the code object
Ben Murdochb0fe1622011-05-05 13:52:32 +0100254 // and compute the fp-to-sp delta in register edx.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000255 __ mov(ecx, Operand(esp, kSavedRegistersAreaSize + 1 * kPointerSize));
256 __ lea(edx, Operand(esp, kSavedRegistersAreaSize + 2 * kPointerSize));
257
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100258 __ sub(edx, ebp);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100259 __ neg(edx);
260
261 // Allocate a new deoptimizer object.
Ben Murdoch8b112d22011-06-08 16:22:53 +0100262 __ PrepareCallCFunction(6, eax);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100263 __ mov(eax, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset));
264 __ mov(Operand(esp, 0 * kPointerSize), eax); // Function.
265 __ mov(Operand(esp, 1 * kPointerSize), Immediate(type())); // Bailout type.
266 __ mov(Operand(esp, 2 * kPointerSize), ebx); // Bailout id.
267 __ mov(Operand(esp, 3 * kPointerSize), ecx); // Code address or 0.
268 __ mov(Operand(esp, 4 * kPointerSize), edx); // Fp-to-sp delta.
Ben Murdoch8b112d22011-06-08 16:22:53 +0100269 __ mov(Operand(esp, 5 * kPointerSize),
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000270 Immediate(ExternalReference::isolate_address(isolate())));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100271 {
272 AllowExternalCallThatCantCauseGC scope(masm());
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000273 __ CallCFunction(ExternalReference::new_deoptimizer_function(isolate()), 6);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100274 }
Ben Murdochb0fe1622011-05-05 13:52:32 +0100275
276 // Preserve deoptimizer object in register eax and get the input
277 // frame descriptor pointer.
278 __ mov(ebx, Operand(eax, Deoptimizer::input_offset()));
279
280 // Fill in the input registers.
Steve Block1e0659c2011-05-24 12:43:12 +0100281 for (int i = kNumberOfRegisters - 1; i >= 0; i--) {
282 int offset = (i * kPointerSize) + FrameDescription::registers_offset();
283 __ pop(Operand(ebx, offset));
Ben Murdochb0fe1622011-05-05 13:52:32 +0100284 }
285
Ben Murdochb0fe1622011-05-05 13:52:32 +0100286 int double_regs_offset = FrameDescription::double_registers_offset();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000287 // Fill in the double input registers.
288 for (int i = 0; i < XMMRegister::kMaxNumAllocatableRegisters; ++i) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100289 int dst_offset = i * kDoubleSize + double_regs_offset;
Steve Block1e0659c2011-05-24 12:43:12 +0100290 int src_offset = i * kDoubleSize;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000291 __ movsd(xmm0, Operand(esp, src_offset));
292 __ movsd(Operand(ebx, dst_offset), xmm0);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100293 }
294
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000295 // Clear FPU all exceptions.
296 // TODO(ulan): Find out why the TOP register is not zero here in some cases,
297 // and check that the generated code never deoptimizes with unbalanced stack.
298 __ fnclex();
299
300 // Remove the bailout id, return address and the double registers.
301 __ add(esp, Immediate(kDoubleRegsSize + 2 * kPointerSize));
Ben Murdochb0fe1622011-05-05 13:52:32 +0100302
303 // Compute a pointer to the unwinding limit in register ecx; that is
304 // the first stack slot not part of the input frame.
305 __ mov(ecx, Operand(ebx, FrameDescription::frame_size_offset()));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100306 __ add(ecx, esp);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100307
308 // Unwind the stack down to - but not including - the unwinding
309 // limit and copy the contents of the activation frame to the input
310 // frame description.
311 __ lea(edx, Operand(ebx, FrameDescription::frame_content_offset()));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000312 Label pop_loop_header;
313 __ jmp(&pop_loop_header);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100314 Label pop_loop;
315 __ bind(&pop_loop);
316 __ pop(Operand(edx, 0));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100317 __ add(edx, Immediate(sizeof(uint32_t)));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000318 __ bind(&pop_loop_header);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100319 __ cmp(ecx, esp);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100320 __ j(not_equal, &pop_loop);
321
322 // Compute the output frame in the deoptimizer.
323 __ push(eax);
324 __ PrepareCallCFunction(1, ebx);
325 __ mov(Operand(esp, 0 * kPointerSize), eax);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100326 {
327 AllowExternalCallThatCantCauseGC scope(masm());
328 __ CallCFunction(
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000329 ExternalReference::compute_output_frames_function(isolate()), 1);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100330 }
Ben Murdochb0fe1622011-05-05 13:52:32 +0100331 __ pop(eax);
332
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000333 // If frame was dynamically aligned, pop padding.
334 Label no_padding;
335 __ cmp(Operand(eax, Deoptimizer::has_alignment_padding_offset()),
336 Immediate(0));
337 __ j(equal, &no_padding);
338 __ pop(ecx);
339 if (FLAG_debug_code) {
340 __ cmp(ecx, Immediate(kAlignmentZapValue));
341 __ Assert(equal, kAlignmentMarkerExpected);
342 }
343 __ bind(&no_padding);
344
Ben Murdochb0fe1622011-05-05 13:52:32 +0100345 // Replace the current frame with the output frames.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000346 Label outer_push_loop, inner_push_loop,
347 outer_loop_header, inner_loop_header;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100348 // Outer loop state: eax = current FrameDescription**, edx = one past the
349 // last FrameDescription**.
350 __ mov(edx, Operand(eax, Deoptimizer::output_count_offset()));
351 __ mov(eax, Operand(eax, Deoptimizer::output_offset()));
352 __ lea(edx, Operand(eax, edx, times_4, 0));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000353 __ jmp(&outer_loop_header);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100354 __ bind(&outer_push_loop);
355 // Inner loop state: ebx = current FrameDescription*, ecx = loop index.
356 __ mov(ebx, Operand(eax, 0));
357 __ mov(ecx, Operand(ebx, FrameDescription::frame_size_offset()));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000358 __ jmp(&inner_loop_header);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100359 __ bind(&inner_push_loop);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100360 __ sub(ecx, Immediate(sizeof(uint32_t)));
Ben Murdochb0fe1622011-05-05 13:52:32 +0100361 __ push(Operand(ebx, ecx, times_1, FrameDescription::frame_content_offset()));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000362 __ bind(&inner_loop_header);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100363 __ test(ecx, ecx);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100364 __ j(not_zero, &inner_push_loop);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100365 __ add(eax, Immediate(kPointerSize));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000366 __ bind(&outer_loop_header);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100367 __ cmp(eax, edx);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100368 __ j(below, &outer_push_loop);
369
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000370 // In case of a failed STUB, we have to restore the XMM registers.
371 for (int i = 0; i < XMMRegister::kMaxNumAllocatableRegisters; ++i) {
372 XMMRegister xmm_reg = XMMRegister::FromAllocationIndex(i);
373 int src_offset = i * kDoubleSize + double_regs_offset;
374 __ movsd(xmm_reg, Operand(ebx, src_offset));
Ben Murdochb0fe1622011-05-05 13:52:32 +0100375 }
376
377 // Push state, pc, and continuation from the last output frame.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000378 __ push(Operand(ebx, FrameDescription::state_offset()));
Ben Murdochb0fe1622011-05-05 13:52:32 +0100379 __ push(Operand(ebx, FrameDescription::pc_offset()));
380 __ push(Operand(ebx, FrameDescription::continuation_offset()));
381
382
383 // Push the registers from the last output frame.
384 for (int i = 0; i < kNumberOfRegisters; i++) {
Steve Block1e0659c2011-05-24 12:43:12 +0100385 int offset = (i * kPointerSize) + FrameDescription::registers_offset();
Ben Murdochb0fe1622011-05-05 13:52:32 +0100386 __ push(Operand(ebx, offset));
387 }
388
389 // Restore the registers from the stack.
390 __ popad();
391
392 // Return to the continuation point.
393 __ ret(0);
394}
395
396
397void Deoptimizer::TableEntryGenerator::GeneratePrologue() {
398 // Create a sequence of deoptimization entries.
399 Label done;
400 for (int i = 0; i < count(); i++) {
401 int start = masm()->pc_offset();
402 USE(start);
403 __ push_imm32(i);
404 __ jmp(&done);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000405 DCHECK(masm()->pc_offset() - start == table_entry_size_);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100406 }
407 __ bind(&done);
408}
409
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000410
411void FrameDescription::SetCallerPc(unsigned offset, intptr_t value) {
412 SetFrameSlot(offset, value);
413}
414
415
416void FrameDescription::SetCallerFp(unsigned offset, intptr_t value) {
417 SetFrameSlot(offset, value);
418}
419
420
421void FrameDescription::SetCallerConstantPool(unsigned offset, intptr_t value) {
422 // No out-of-line constant pool support.
423 UNREACHABLE();
424}
425
426
Ben Murdochb0fe1622011-05-05 13:52:32 +0100427#undef __
428
429
430} } // namespace v8::internal
Ben Murdochb8e0da22011-05-16 14:20:40 +0100431
432#endif // V8_TARGET_ARCH_IA32