Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: src/ia32/deoptimizer-ia32.cc

Issue 6529055: [Isolates] Merge crankshaft (r5922 from bleeding_edge). (Closed)
Patch Set: Win32 port Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/ia32/cpu-ia32.cc ('k') | src/ia32/disasm-ia32.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2010 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 #include "v8.h"
29
30 #include "codegen.h"
31 #include "deoptimizer.h"
32 #include "full-codegen.h"
33 #include "safepoint-table.h"
34
35 namespace v8 {
36 namespace internal {
37
38
39 int Deoptimizer::table_entry_size_ = 10;
40
41 void Deoptimizer::DeoptimizeFunction(JSFunction* function) {
42 AssertNoAllocation no_allocation;
43
44 if (!function->IsOptimized()) return;
45
46 // Get the optimized code.
47 Code* code = function->code();
48
49 // Invalidate the relocation information, as it will become invalid by the
50 // code patching below, and is not needed any more.
51 code->InvalidateRelocation();
52
53 // For each return after a safepoint insert a absolute call to the
54 // corresponding deoptimization entry.
55 unsigned last_pc_offset = 0;
56 SafepointTable table(function->code());
57 for (unsigned i = 0; i < table.length(); i++) {
58 unsigned pc_offset = table.GetPcOffset(i);
59 int deoptimization_index = table.GetDeoptimizationIndex(i);
60 int gap_code_size = table.GetGapCodeSize(i);
61 #ifdef DEBUG
62 // Destroy the code which is not supposed to run again.
63 unsigned instructions = pc_offset - last_pc_offset;
64 CodePatcher destroyer(code->instruction_start() + last_pc_offset,
65 instructions);
66 for (unsigned i = 0; i < instructions; i++) {
67 destroyer.masm()->int3();
68 }
69 #endif
70 last_pc_offset = pc_offset;
71 if (deoptimization_index != Safepoint::kNoDeoptimizationIndex) {
72 CodePatcher patcher(
73 code->instruction_start() + pc_offset + gap_code_size,
74 Assembler::kCallInstructionLength);
75 patcher.masm()->call(GetDeoptimizationEntry(deoptimization_index, LAZY),
76 RelocInfo::NONE);
77 last_pc_offset += gap_code_size + Assembler::kCallInstructionLength;
78 }
79 }
80 #ifdef DEBUG
81 // Destroy the code which is not supposed to run again.
82 unsigned instructions = code->safepoint_table_start() - last_pc_offset;
83 CodePatcher destroyer(code->instruction_start() + last_pc_offset,
84 instructions);
85 for (unsigned i = 0; i < instructions; i++) {
86 destroyer.masm()->int3();
87 }
88 #endif
89
90 // Add the deoptimizing code to the list.
91 DeoptimizingCodeListNode* node = new DeoptimizingCodeListNode(code);
92 DeoptimizerData* data = Isolate::Current()->deoptimizer_data();
93 node->set_next(data->deoptimizing_code_list_);
94 data->deoptimizing_code_list_ = node;
95
96 // Set the code for the function to non-optimized version.
97 function->ReplaceCode(function->shared()->code());
98
99 if (FLAG_trace_deopt) {
100 PrintF("[forced deoptimization: ");
101 function->PrintName();
102 PrintF(" / %x]\n", reinterpret_cast<uint32_t>(function));
103 }
104 }
105
106
107 void Deoptimizer::PatchStackCheckCode(RelocInfo* rinfo,
108 Code* replacement_code) {
109 // The stack check code matches the pattern (on ia32, for example):
110 //
111 // cmp esp, <limit>
112 // jae ok
113 // call <stack guard>
114 // ok: ...
115 //
116 // We will patch the code to:
117 //
118 // cmp esp, <limit> ;; Not changed
119 // nop
120 // nop
121 // call <on-stack replacment>
122 // ok:
123 Address call_target_address = rinfo->pc();
124 ASSERT(*(call_target_address - 3) == 0x73 && // jae
125 *(call_target_address - 2) == 0x05 && // offset
126 *(call_target_address - 1) == 0xe8); // call
127 *(call_target_address - 3) = 0x90; // nop
128 *(call_target_address - 2) = 0x90; // nop
129 rinfo->set_target_address(replacement_code->entry());
130 }
131
132
133 void Deoptimizer::RevertStackCheckCode(RelocInfo* rinfo, Code* check_code) {
134 Address call_target_address = rinfo->pc();
135 ASSERT(*(call_target_address - 3) == 0x90 && // nop
136 *(call_target_address - 2) == 0x90 && // nop
137 *(call_target_address - 1) == 0xe8); // call
138 *(call_target_address - 3) = 0x73; // jae
139 *(call_target_address - 2) = 0x05; // offset
140 rinfo->set_target_address(check_code->entry());
141 }
142
143
144 static int LookupBailoutId(DeoptimizationInputData* data, unsigned ast_id) {
145 ByteArray* translations = data->TranslationByteArray();
146 int length = data->DeoptCount();
147 for (int i = 0; i < length; i++) {
148 if (static_cast<unsigned>(data->AstId(i)->value()) == ast_id) {
149 TranslationIterator it(translations, data->TranslationIndex(i)->value());
150 int value = it.Next();
151 ASSERT(Translation::BEGIN == static_cast<Translation::Opcode>(value));
152 // Read the number of frames.
153 value = it.Next();
154 if (value == 1) return i;
155 }
156 }
157 UNREACHABLE();
158 return -1;
159 }
160
161
162 void Deoptimizer::DoComputeOsrOutputFrame() {
163 DeoptimizationInputData* data = DeoptimizationInputData::cast(
164 optimized_code_->deoptimization_data());
165 unsigned ast_id = data->OsrAstId()->value();
166 // TODO(kasperl): This should not be the bailout_id_. It should be
167 // the ast id. Confusing.
168 ASSERT(bailout_id_ == ast_id);
169
170 int bailout_id = LookupBailoutId(data, ast_id);
171 unsigned translation_index = data->TranslationIndex(bailout_id)->value();
172 ByteArray* translations = data->TranslationByteArray();
173
174 TranslationIterator iterator(translations, translation_index);
175 Translation::Opcode opcode =
176 static_cast<Translation::Opcode>(iterator.Next());
177 ASSERT(Translation::BEGIN == opcode);
178 USE(opcode);
179 int count = iterator.Next();
180 ASSERT(count == 1);
181 USE(count);
182
183 opcode = static_cast<Translation::Opcode>(iterator.Next());
184 USE(opcode);
185 ASSERT(Translation::FRAME == opcode);
186 unsigned node_id = iterator.Next();
187 USE(node_id);
188 ASSERT(node_id == ast_id);
189 JSFunction* function = JSFunction::cast(ComputeLiteral(iterator.Next()));
190 USE(function);
191 ASSERT(function == function_);
192 unsigned height = iterator.Next();
193 unsigned height_in_bytes = height * kPointerSize;
194 USE(height_in_bytes);
195
196 unsigned fixed_size = ComputeFixedSize(function_);
197 unsigned input_frame_size = input_->GetFrameSize();
198 ASSERT(fixed_size + height_in_bytes == input_frame_size);
199
200 unsigned stack_slot_size = optimized_code_->stack_slots() * kPointerSize;
201 unsigned outgoing_height = data->ArgumentsStackHeight(bailout_id)->value();
202 unsigned outgoing_size = outgoing_height * kPointerSize;
203 unsigned output_frame_size = fixed_size + stack_slot_size + outgoing_size;
204 ASSERT(outgoing_size == 0); // OSR does not happen in the middle of a call.
205
206 if (FLAG_trace_osr) {
207 PrintF("[on-stack replacement: begin 0x%08" V8PRIxPTR " ",
208 reinterpret_cast<intptr_t>(function_));
209 function_->PrintName();
210 PrintF(" => node=%u, frame=%d->%d]\n",
211 ast_id,
212 input_frame_size,
213 output_frame_size);
214 }
215
216 // There's only one output frame in the OSR case.
217 output_count_ = 1;
218 output_ = new FrameDescription*[1];
219 output_[0] = new(output_frame_size) FrameDescription(
220 output_frame_size, function_);
221
222 // Clear the incoming parameters in the optimized frame to avoid
223 // confusing the garbage collector.
224 unsigned output_offset = output_frame_size - kPointerSize;
225 int parameter_count = function_->shared()->formal_parameter_count() + 1;
226 for (int i = 0; i < parameter_count; ++i) {
227 output_[0]->SetFrameSlot(output_offset, 0);
228 output_offset -= kPointerSize;
229 }
230
231 // Translate the incoming parameters. This may overwrite some of the
232 // incoming argument slots we've just cleared.
233 int input_offset = input_frame_size - kPointerSize;
234 bool ok = true;
235 int limit = input_offset - (parameter_count * kPointerSize);
236 while (ok && input_offset > limit) {
237 ok = DoOsrTranslateCommand(&iterator, &input_offset);
238 }
239
240 // There are no translation commands for the caller's pc and fp, the
241 // context, and the function. Set them up explicitly.
242 for (int i = 0; ok && i < 4; i++) {
243 uint32_t input_value = input_->GetFrameSlot(input_offset);
244 if (FLAG_trace_osr) {
245 PrintF(" [esp + %d] <- 0x%08x ; [esp + %d] (fixed part)\n",
246 output_offset,
247 input_value,
248 input_offset);
249 }
250 output_[0]->SetFrameSlot(output_offset, input_->GetFrameSlot(input_offset));
251 input_offset -= kPointerSize;
252 output_offset -= kPointerSize;
253 }
254
255 // Translate the rest of the frame.
256 while (ok && input_offset >= 0) {
257 ok = DoOsrTranslateCommand(&iterator, &input_offset);
258 }
259
260 // If translation of any command failed, continue using the input frame.
261 if (!ok) {
262 delete output_[0];
263 output_[0] = input_;
264 output_[0]->SetPc(reinterpret_cast<uint32_t>(from_));
265 } else {
266 // Setup the frame pointer and the context pointer.
267 output_[0]->SetRegister(ebp.code(), input_->GetRegister(ebp.code()));
268 output_[0]->SetRegister(esi.code(), input_->GetRegister(esi.code()));
269
270 unsigned pc_offset = data->OsrPcOffset()->value();
271 uint32_t pc = reinterpret_cast<uint32_t>(
272 optimized_code_->entry() + pc_offset);
273 output_[0]->SetPc(pc);
274 }
275 Code* continuation =
276 Isolate::Current()->builtins()->builtin(Builtins::NotifyOSR);
277 output_[0]->SetContinuation(
278 reinterpret_cast<uint32_t>(continuation->entry()));
279
280 if (FLAG_trace_osr) {
281 PrintF("[on-stack replacement translation %s: 0x%08" V8PRIxPTR " ",
282 ok ? "finished" : "aborted",
283 reinterpret_cast<intptr_t>(function));
284 function->PrintName();
285 PrintF(" => pc=0x%0x]\n", output_[0]->GetPc());
286 }
287 }
288
289
290 void Deoptimizer::DoComputeFrame(TranslationIterator* iterator,
291 int frame_index) {
292 // Read the ast node id, function, and frame height for this output frame.
293 Translation::Opcode opcode =
294 static_cast<Translation::Opcode>(iterator->Next());
295 USE(opcode);
296 ASSERT(Translation::FRAME == opcode);
297 int node_id = iterator->Next();
298 JSFunction* function = JSFunction::cast(ComputeLiteral(iterator->Next()));
299 unsigned height = iterator->Next();
300 unsigned height_in_bytes = height * kPointerSize;
301 if (FLAG_trace_deopt) {
302 PrintF(" translating ");
303 function->PrintName();
304 PrintF(" => node=%d, height=%d\n", node_id, height_in_bytes);
305 }
306
307 // The 'fixed' part of the frame consists of the incoming parameters and
308 // the part described by JavaScriptFrameConstants.
309 unsigned fixed_frame_size = ComputeFixedSize(function);
310 unsigned input_frame_size = input_->GetFrameSize();
311 unsigned output_frame_size = height_in_bytes + fixed_frame_size;
312
313 // Allocate and store the output frame description.
314 FrameDescription* output_frame =
315 new(output_frame_size) FrameDescription(output_frame_size, function);
316
317 bool is_bottommost = (0 == frame_index);
318 bool is_topmost = (output_count_ - 1 == frame_index);
319 ASSERT(frame_index >= 0 && frame_index < output_count_);
320 ASSERT(output_[frame_index] == NULL);
321 output_[frame_index] = output_frame;
322
323 // The top address for the bottommost output frame can be computed from
324 // the input frame pointer and the output frame's height. For all
325 // subsequent output frames, it can be computed from the previous one's
326 // top address and the current frame's size.
327 uint32_t top_address;
328 if (is_bottommost) {
329 // 2 = context and function in the frame.
330 top_address =
331 input_->GetRegister(ebp.code()) - (2 * kPointerSize) - height_in_bytes;
332 } else {
333 top_address = output_[frame_index - 1]->GetTop() - output_frame_size;
334 }
335 output_frame->SetTop(top_address);
336
337 // Compute the incoming parameter translation.
338 int parameter_count = function->shared()->formal_parameter_count() + 1;
339 unsigned output_offset = output_frame_size;
340 unsigned input_offset = input_frame_size;
341 for (int i = 0; i < parameter_count; ++i) {
342 output_offset -= kPointerSize;
343 DoTranslateCommand(iterator, frame_index, output_offset);
344 }
345 input_offset -= (parameter_count * kPointerSize);
346
347 // There are no translation commands for the caller's pc and fp, the
348 // context, and the function. Synthesize their values and set them up
349 // explicitly.
350 //
351 // The caller's pc for the bottommost output frame is the same as in the
352 // input frame. For all subsequent output frames, it can be read from the
353 // previous one. This frame's pc can be computed from the non-optimized
354 // function code and AST id of the bailout.
355 output_offset -= kPointerSize;
356 input_offset -= kPointerSize;
357 uint32_t value;
358 if (is_bottommost) {
359 value = input_->GetFrameSlot(input_offset);
360 } else {
361 value = output_[frame_index - 1]->GetPc();
362 }
363 output_frame->SetFrameSlot(output_offset, value);
364 if (FLAG_trace_deopt) {
365 PrintF(" 0x%08x: [top + %d] <- 0x%08x ; caller's pc\n",
366 top_address + output_offset, output_offset, value);
367 }
368
369 // The caller's frame pointer for the bottommost output frame is the same
370 // as in the input frame. For all subsequent output frames, it can be
371 // read from the previous one. Also compute and set this frame's frame
372 // pointer.
373 output_offset -= kPointerSize;
374 input_offset -= kPointerSize;
375 if (is_bottommost) {
376 value = input_->GetFrameSlot(input_offset);
377 } else {
378 value = output_[frame_index - 1]->GetFp();
379 }
380 output_frame->SetFrameSlot(output_offset, value);
381 unsigned fp_value = top_address + output_offset;
382 ASSERT(!is_bottommost || input_->GetRegister(ebp.code()) == fp_value);
383 output_frame->SetFp(fp_value);
384 if (is_topmost) output_frame->SetRegister(ebp.code(), fp_value);
385 if (FLAG_trace_deopt) {
386 PrintF(" 0x%08x: [top + %d] <- 0x%08x ; caller's fp\n",
387 fp_value, output_offset, value);
388 }
389
390 // The context can be gotten from the function so long as we don't
391 // optimize functions that need local contexts.
392 output_offset -= kPointerSize;
393 input_offset -= kPointerSize;
394 value = reinterpret_cast<uint32_t>(function->context());
395 // The context for the bottommost output frame should also agree with the
396 // input frame.
397 ASSERT(!is_bottommost || input_->GetFrameSlot(input_offset) == value);
398 output_frame->SetFrameSlot(output_offset, value);
399 if (is_topmost) output_frame->SetRegister(esi.code(), value);
400 if (FLAG_trace_deopt) {
401 PrintF(" 0x%08x: [top + %d] <- 0x%08x ; context\n",
402 top_address + output_offset, output_offset, value);
403 }
404
405 // The function was mentioned explicitly in the BEGIN_FRAME.
406 output_offset -= kPointerSize;
407 input_offset -= kPointerSize;
408 value = reinterpret_cast<uint32_t>(function);
409 // The function for the bottommost output frame should also agree with the
410 // input frame.
411 ASSERT(!is_bottommost || input_->GetFrameSlot(input_offset) == value);
412 output_frame->SetFrameSlot(output_offset, value);
413 if (FLAG_trace_deopt) {
414 PrintF(" 0x%08x: [top + %d] <- 0x%08x ; function\n",
415 top_address + output_offset, output_offset, value);
416 }
417
418 // Translate the rest of the frame.
419 for (unsigned i = 0; i < height; ++i) {
420 output_offset -= kPointerSize;
421 DoTranslateCommand(iterator, frame_index, output_offset);
422 }
423 ASSERT(0 == output_offset);
424
425 // Compute this frame's PC, state, and continuation.
426 Code* non_optimized_code = function->shared()->code();
427 FixedArray* raw_data = non_optimized_code->deoptimization_data();
428 DeoptimizationOutputData* data = DeoptimizationOutputData::cast(raw_data);
429 Address start = non_optimized_code->instruction_start();
430 unsigned pc_and_state = GetOutputInfo(data, node_id, function->shared());
431 unsigned pc_offset = FullCodeGenerator::PcField::decode(pc_and_state);
432 uint32_t pc_value = reinterpret_cast<uint32_t>(start + pc_offset);
433 output_frame->SetPc(pc_value);
434
435 FullCodeGenerator::State state =
436 FullCodeGenerator::StateField::decode(pc_and_state);
437 output_frame->SetState(Smi::FromInt(state));
438
439 // Set the continuation for the topmost frame.
440 if (is_topmost) {
441 Builtins* builtins = isolate_->builtins();
442 Code* continuation = (bailout_type_ == EAGER)
443 ? builtins->builtin(Builtins::NotifyDeoptimized)
444 : builtins->builtin(Builtins::NotifyLazyDeoptimized);
445 output_frame->SetContinuation(
446 reinterpret_cast<uint32_t>(continuation->entry()));
447 }
448
449 if (output_count_ - 1 == frame_index) iterator->Done();
450 }
451
452
453 #define __ masm()->
454
455 void Deoptimizer::EntryGenerator::Generate() {
456 GeneratePrologue();
457 CpuFeatures::Scope scope(SSE2);
458
459 // Save all general purpose registers before messing with them.
460 const int kNumberOfRegisters = Register::kNumRegisters;
461
462 const int kDoubleRegsSize = kDoubleSize *
463 XMMRegister::kNumAllocatableRegisters;
464 __ sub(Operand(esp), Immediate(kDoubleRegsSize));
465 for (int i = 0; i < XMMRegister::kNumAllocatableRegisters; ++i) {
466 XMMRegister xmm_reg = XMMRegister::FromAllocationIndex(i);
467 int offset = i * kDoubleSize;
468 __ movdbl(Operand(esp, offset), xmm_reg);
469 }
470
471 __ pushad();
472
473 const int kSavedRegistersAreaSize = kNumberOfRegisters * kPointerSize +
474 kDoubleRegsSize;
475
476 // Get the bailout id from the stack.
477 __ mov(ebx, Operand(esp, kSavedRegistersAreaSize));
478
479 // Get the address of the location in the code object if possible
480 // and compute the fp-to-sp delta in register edx.
481 if (type() == EAGER) {
482 __ Set(ecx, Immediate(0));
483 __ lea(edx, Operand(esp, kSavedRegistersAreaSize + 1 * kPointerSize));
484 } else {
485 __ mov(ecx, Operand(esp, kSavedRegistersAreaSize + 1 * kPointerSize));
486 __ lea(edx, Operand(esp, kSavedRegistersAreaSize + 2 * kPointerSize));
487 }
488 __ sub(edx, Operand(ebp));
489 __ neg(edx);
490
491 // Allocate a new deoptimizer object.
492 __ PrepareCallCFunction(5, eax);
493 __ mov(eax, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset));
494 __ mov(Operand(esp, 0 * kPointerSize), eax); // Function.
495 __ mov(Operand(esp, 1 * kPointerSize), Immediate(type())); // Bailout type.
496 __ mov(Operand(esp, 2 * kPointerSize), ebx); // Bailout id.
497 __ mov(Operand(esp, 3 * kPointerSize), ecx); // Code address or 0.
498 __ mov(Operand(esp, 4 * kPointerSize), edx); // Fp-to-sp delta.
499 __ CallCFunction(ExternalReference::new_deoptimizer_function(), 5);
500
501 // Preserve deoptimizer object in register eax and get the input
502 // frame descriptor pointer.
503 __ mov(ebx, Operand(eax, Deoptimizer::input_offset()));
504
505 // Fill in the input registers.
506 for (int i = 0; i < kNumberOfRegisters; i++) {
507 int offset = (i * kIntSize) + FrameDescription::registers_offset();
508 __ mov(ecx, Operand(esp, (kNumberOfRegisters - 1 - i) * kPointerSize));
509 __ mov(Operand(ebx, offset), ecx);
510 }
511
512 // Fill in the double input registers.
513 int double_regs_offset = FrameDescription::double_registers_offset();
514 for (int i = 0; i < XMMRegister::kNumAllocatableRegisters; ++i) {
515 int dst_offset = i * kDoubleSize + double_regs_offset;
516 int src_offset = i * kDoubleSize + kNumberOfRegisters * kPointerSize;
517 __ movdbl(xmm0, Operand(esp, src_offset));
518 __ movdbl(Operand(ebx, dst_offset), xmm0);
519 }
520
521 // Remove the bailout id and the general purpose registers from the stack.
522 if (type() == EAGER) {
523 __ add(Operand(esp), Immediate(kSavedRegistersAreaSize + kPointerSize));
524 } else {
525 __ add(Operand(esp), Immediate(kSavedRegistersAreaSize + 2 * kPointerSize));
526 }
527
528 // Compute a pointer to the unwinding limit in register ecx; that is
529 // the first stack slot not part of the input frame.
530 __ mov(ecx, Operand(ebx, FrameDescription::frame_size_offset()));
531 __ add(ecx, Operand(esp));
532
533 // Unwind the stack down to - but not including - the unwinding
534 // limit and copy the contents of the activation frame to the input
535 // frame description.
536 __ lea(edx, Operand(ebx, FrameDescription::frame_content_offset()));
537 Label pop_loop;
538 __ bind(&pop_loop);
539 __ pop(Operand(edx, 0));
540 __ add(Operand(edx), Immediate(sizeof(uint32_t)));
541 __ cmp(ecx, Operand(esp));
542 __ j(not_equal, &pop_loop);
543
544 // Compute the output frame in the deoptimizer.
545 __ push(eax);
546 __ PrepareCallCFunction(1, ebx);
547 __ mov(Operand(esp, 0 * kPointerSize), eax);
548 __ CallCFunction(ExternalReference::compute_output_frames_function(), 1);
549 __ pop(eax);
550
551 // Replace the current frame with the output frames.
552 Label outer_push_loop, inner_push_loop;
553 // Outer loop state: eax = current FrameDescription**, edx = one past the
554 // last FrameDescription**.
555 __ mov(edx, Operand(eax, Deoptimizer::output_count_offset()));
556 __ mov(eax, Operand(eax, Deoptimizer::output_offset()));
557 __ lea(edx, Operand(eax, edx, times_4, 0));
558 __ bind(&outer_push_loop);
559 // Inner loop state: ebx = current FrameDescription*, ecx = loop index.
560 __ mov(ebx, Operand(eax, 0));
561 __ mov(ecx, Operand(ebx, FrameDescription::frame_size_offset()));
562 __ bind(&inner_push_loop);
563 __ sub(Operand(ecx), Immediate(sizeof(uint32_t)));
564 __ push(Operand(ebx, ecx, times_1, FrameDescription::frame_content_offset()));
565 __ test(ecx, Operand(ecx));
566 __ j(not_zero, &inner_push_loop);
567 __ add(Operand(eax), Immediate(kPointerSize));
568 __ cmp(eax, Operand(edx));
569 __ j(below, &outer_push_loop);
570
571 // In case of OSR, we have to restore the XMM registers.
572 if (type() == OSR) {
573 for (int i = 0; i < XMMRegister::kNumAllocatableRegisters; ++i) {
574 XMMRegister xmm_reg = XMMRegister::FromAllocationIndex(i);
575 int src_offset = i * kDoubleSize + double_regs_offset;
576 __ movdbl(xmm_reg, Operand(ebx, src_offset));
577 }
578 }
579
580 // Push state, pc, and continuation from the last output frame.
581 if (type() != OSR) {
582 __ push(Operand(ebx, FrameDescription::state_offset()));
583 }
584 __ push(Operand(ebx, FrameDescription::pc_offset()));
585 __ push(Operand(ebx, FrameDescription::continuation_offset()));
586
587
588 // Push the registers from the last output frame.
589 for (int i = 0; i < kNumberOfRegisters; i++) {
590 int offset = (i * kIntSize) + FrameDescription::registers_offset();
591 __ push(Operand(ebx, offset));
592 }
593
594 // Restore the registers from the stack.
595 __ popad();
596
597 // Return to the continuation point.
598 __ ret(0);
599 }
600
601
602 void Deoptimizer::TableEntryGenerator::GeneratePrologue() {
603 // Create a sequence of deoptimization entries.
604 Label done;
605 for (int i = 0; i < count(); i++) {
606 int start = masm()->pc_offset();
607 USE(start);
608 __ push_imm32(i);
609 __ jmp(&done);
610 ASSERT(masm()->pc_offset() - start == table_entry_size_);
611 }
612 __ bind(&done);
613 }
614
615 #undef __
616
617
618 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/ia32/cpu-ia32.cc ('k') | src/ia32/disasm-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698