OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 ASSERT_EQ(interrupt_builtin->entry(), | 251 ASSERT_EQ(interrupt_builtin->entry(), |
252 Assembler::target_address_at(call_target_address)); | 252 Assembler::target_address_at(call_target_address)); |
253 ASSERT_EQ(kJnsInstruction, *(call_target_address - 3)); | 253 ASSERT_EQ(kJnsInstruction, *(call_target_address - 3)); |
254 ASSERT_EQ(kJnsOffset, *(call_target_address - 2)); | 254 ASSERT_EQ(kJnsOffset, *(call_target_address - 2)); |
255 return NOT_PATCHED; | 255 return NOT_PATCHED; |
256 } | 256 } |
257 } | 257 } |
258 #endif // DEBUG | 258 #endif // DEBUG |
259 | 259 |
260 | 260 |
261 static int LookupBailoutId(DeoptimizationInputData* data, BailoutId ast_id) { | |
262 ByteArray* translations = data->TranslationByteArray(); | |
263 int length = data->DeoptCount(); | |
264 for (int i = 0; i < length; i++) { | |
265 if (data->AstId(i) == ast_id) { | |
266 TranslationIterator it(translations, data->TranslationIndex(i)->value()); | |
267 int value = it.Next(); | |
268 ASSERT(Translation::BEGIN == static_cast<Translation::Opcode>(value)); | |
269 // Read the number of frames. | |
270 value = it.Next(); | |
271 if (value == 1) return i; | |
272 } | |
273 } | |
274 UNREACHABLE(); | |
275 return -1; | |
276 } | |
277 | |
278 | |
279 void Deoptimizer::DoComputeOsrOutputFrame() { | |
280 DeoptimizationInputData* data = DeoptimizationInputData::cast( | |
281 compiled_code_->deoptimization_data()); | |
282 unsigned ast_id = data->OsrAstId()->value(); | |
283 // TODO(kasperl): This should not be the bailout_id_. It should be | |
284 // the ast id. Confusing. | |
285 ASSERT(bailout_id_ == ast_id); | |
286 | |
287 int bailout_id = LookupBailoutId(data, BailoutId(ast_id)); | |
288 unsigned translation_index = data->TranslationIndex(bailout_id)->value(); | |
289 ByteArray* translations = data->TranslationByteArray(); | |
290 | |
291 TranslationIterator iterator(translations, translation_index); | |
292 Translation::Opcode opcode = | |
293 static_cast<Translation::Opcode>(iterator.Next()); | |
294 ASSERT(Translation::BEGIN == opcode); | |
295 USE(opcode); | |
296 int count = iterator.Next(); | |
297 iterator.Next(); // Drop JS frames count. | |
298 ASSERT(count == 1); | |
299 USE(count); | |
300 | |
301 opcode = static_cast<Translation::Opcode>(iterator.Next()); | |
302 USE(opcode); | |
303 ASSERT(Translation::JS_FRAME == opcode); | |
304 unsigned node_id = iterator.Next(); | |
305 USE(node_id); | |
306 ASSERT(node_id == ast_id); | |
307 int closure_id = iterator.Next(); | |
308 USE(closure_id); | |
309 ASSERT_EQ(Translation::kSelfLiteralId, closure_id); | |
310 unsigned height = iterator.Next(); | |
311 unsigned height_in_bytes = height * kPointerSize; | |
312 USE(height_in_bytes); | |
313 | |
314 unsigned fixed_size = ComputeFixedSize(function_); | |
315 unsigned input_frame_size = input_->GetFrameSize(); | |
316 ASSERT(fixed_size + height_in_bytes == input_frame_size); | |
317 | |
318 unsigned stack_slot_size = compiled_code_->stack_slots() * kPointerSize; | |
319 unsigned outgoing_height = data->ArgumentsStackHeight(bailout_id)->value(); | |
320 unsigned outgoing_size = outgoing_height * kPointerSize; | |
321 unsigned output_frame_size = fixed_size + stack_slot_size + outgoing_size; | |
322 ASSERT(outgoing_size == 0); // OSR does not happen in the middle of a call. | |
323 | |
324 if (FLAG_trace_osr) { | |
325 PrintF("[on-stack replacement: begin 0x%08" V8PRIxPTR " ", | |
326 reinterpret_cast<intptr_t>(function_)); | |
327 PrintFunctionName(); | |
328 PrintF(" => node=%u, frame=%d->%d, ebp:esp=0x%08x:0x%08x]\n", | |
329 ast_id, | |
330 input_frame_size, | |
331 output_frame_size, | |
332 input_->GetRegister(ebp.code()), | |
333 input_->GetRegister(esp.code())); | |
334 } | |
335 | |
336 // There's only one output frame in the OSR case. | |
337 output_count_ = 1; | |
338 output_ = new FrameDescription*[1]; | |
339 output_[0] = new(output_frame_size) FrameDescription( | |
340 output_frame_size, function_); | |
341 output_[0]->SetFrameType(StackFrame::JAVA_SCRIPT); | |
342 | |
343 // Clear the incoming parameters in the optimized frame to avoid | |
344 // confusing the garbage collector. | |
345 unsigned output_offset = output_frame_size - kPointerSize; | |
346 int parameter_count = function_->shared()->formal_parameter_count() + 1; | |
347 for (int i = 0; i < parameter_count; ++i) { | |
348 output_[0]->SetFrameSlot(output_offset, 0); | |
349 output_offset -= kPointerSize; | |
350 } | |
351 | |
352 // Translate the incoming parameters. This may overwrite some of the | |
353 // incoming argument slots we've just cleared. | |
354 int input_offset = input_frame_size - kPointerSize; | |
355 bool ok = true; | |
356 int limit = input_offset - (parameter_count * kPointerSize); | |
357 while (ok && input_offset > limit) { | |
358 ok = DoOsrTranslateCommand(&iterator, &input_offset); | |
359 } | |
360 | |
361 // There are no translation commands for the caller's pc and fp, the | |
362 // context, and the function. Set them up explicitly. | |
363 for (int i = StandardFrameConstants::kCallerPCOffset; | |
364 ok && i >= StandardFrameConstants::kMarkerOffset; | |
365 i -= kPointerSize) { | |
366 uint32_t input_value = input_->GetFrameSlot(input_offset); | |
367 if (FLAG_trace_osr) { | |
368 const char* name = "UNKNOWN"; | |
369 switch (i) { | |
370 case StandardFrameConstants::kCallerPCOffset: | |
371 name = "caller's pc"; | |
372 break; | |
373 case StandardFrameConstants::kCallerFPOffset: | |
374 name = "fp"; | |
375 break; | |
376 case StandardFrameConstants::kContextOffset: | |
377 name = "context"; | |
378 break; | |
379 case StandardFrameConstants::kMarkerOffset: | |
380 name = "function"; | |
381 break; | |
382 } | |
383 PrintF(" [sp + %d] <- 0x%08x ; [sp + %d] (fixed part - %s)\n", | |
384 output_offset, | |
385 input_value, | |
386 input_offset, | |
387 name); | |
388 } | |
389 output_[0]->SetFrameSlot(output_offset, input_->GetFrameSlot(input_offset)); | |
390 input_offset -= kPointerSize; | |
391 output_offset -= kPointerSize; | |
392 } | |
393 | |
394 // All OSR stack frames are dynamically aligned to an 8-byte boundary. | |
395 int frame_pointer = input_->GetRegister(ebp.code()); | |
396 if ((frame_pointer & kPointerSize) != 0) { | |
397 frame_pointer -= kPointerSize; | |
398 has_alignment_padding_ = 1; | |
399 } | |
400 | |
401 int32_t alignment_state = (has_alignment_padding_ == 1) ? | |
402 kAlignmentPaddingPushed : | |
403 kNoAlignmentPadding; | |
404 if (FLAG_trace_osr) { | |
405 PrintF(" [sp + %d] <- 0x%08x ; (alignment state)\n", | |
406 output_offset, | |
407 alignment_state); | |
408 } | |
409 output_[0]->SetFrameSlot(output_offset, alignment_state); | |
410 output_offset -= kPointerSize; | |
411 | |
412 // Translate the rest of the frame. | |
413 while (ok && input_offset >= 0) { | |
414 ok = DoOsrTranslateCommand(&iterator, &input_offset); | |
415 } | |
416 | |
417 // If translation of any command failed, continue using the input frame. | |
418 if (!ok) { | |
419 delete output_[0]; | |
420 output_[0] = input_; | |
421 output_[0]->SetPc(reinterpret_cast<uint32_t>(from_)); | |
422 } else { | |
423 // Set up the frame pointer and the context pointer. | |
424 output_[0]->SetRegister(ebp.code(), frame_pointer); | |
425 output_[0]->SetRegister(esi.code(), input_->GetRegister(esi.code())); | |
426 | |
427 unsigned pc_offset = data->OsrPcOffset()->value(); | |
428 uint32_t pc = reinterpret_cast<uint32_t>( | |
429 compiled_code_->entry() + pc_offset); | |
430 output_[0]->SetPc(pc); | |
431 } | |
432 Code* continuation = | |
433 function_->GetIsolate()->builtins()->builtin(Builtins::kNotifyOSR); | |
434 output_[0]->SetContinuation( | |
435 reinterpret_cast<uint32_t>(continuation->entry())); | |
436 | |
437 if (FLAG_trace_osr) { | |
438 PrintF("[on-stack replacement translation %s: 0x%08" V8PRIxPTR " ", | |
439 ok ? "finished" : "aborted", | |
440 reinterpret_cast<intptr_t>(function_)); | |
441 PrintFunctionName(); | |
442 PrintF(" => pc=0x%0x]\n", output_[0]->GetPc()); | |
443 } | |
444 } | |
445 | |
446 | |
447 void Deoptimizer::FillInputFrame(Address tos, JavaScriptFrame* frame) { | 261 void Deoptimizer::FillInputFrame(Address tos, JavaScriptFrame* frame) { |
448 // Set the register values. The values are not important as there are no | 262 // Set the register values. The values are not important as there are no |
449 // callee saved registers in JavaScript frames, so all registers are | 263 // callee saved registers in JavaScript frames, so all registers are |
450 // spilled. Registers ebp and esp are set to the correct values though. | 264 // spilled. Registers ebp and esp are set to the correct values though. |
451 | 265 |
452 for (int i = 0; i < Register::kNumRegisters; i++) { | 266 for (int i = 0; i < Register::kNumRegisters; i++) { |
453 input_->SetRegister(i, i * 4); | 267 input_->SetRegister(i, i * 4); |
454 } | 268 } |
455 input_->SetRegister(esp.code(), reinterpret_cast<intptr_t>(frame->sp())); | 269 input_->SetRegister(esp.code(), reinterpret_cast<intptr_t>(frame->sp())); |
456 input_->SetRegister(ebp.code(), reinterpret_cast<intptr_t>(frame->fp())); | 270 input_->SetRegister(ebp.code(), reinterpret_cast<intptr_t>(frame->fp())); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 __ push(eax); | 418 __ push(eax); |
605 __ PrepareCallCFunction(1, ebx); | 419 __ PrepareCallCFunction(1, ebx); |
606 __ mov(Operand(esp, 0 * kPointerSize), eax); | 420 __ mov(Operand(esp, 0 * kPointerSize), eax); |
607 { | 421 { |
608 AllowExternalCallThatCantCauseGC scope(masm()); | 422 AllowExternalCallThatCantCauseGC scope(masm()); |
609 __ CallCFunction( | 423 __ CallCFunction( |
610 ExternalReference::compute_output_frames_function(isolate()), 1); | 424 ExternalReference::compute_output_frames_function(isolate()), 1); |
611 } | 425 } |
612 __ pop(eax); | 426 __ pop(eax); |
613 | 427 |
614 if (type() != OSR) { | 428 // If frame was dynamically aligned, pop padding. |
615 // If frame was dynamically aligned, pop padding. | 429 Label no_padding; |
616 Label no_padding; | 430 __ cmp(Operand(eax, Deoptimizer::has_alignment_padding_offset()), |
617 __ cmp(Operand(eax, Deoptimizer::has_alignment_padding_offset()), | 431 Immediate(0)); |
618 Immediate(0)); | 432 __ j(equal, &no_padding); |
619 __ j(equal, &no_padding); | 433 __ pop(ecx); |
620 __ pop(ecx); | 434 if (FLAG_debug_code) { |
621 if (FLAG_debug_code) { | 435 __ cmp(ecx, Immediate(kAlignmentZapValue)); |
622 __ cmp(ecx, Immediate(kAlignmentZapValue)); | 436 __ Assert(equal, kAlignmentMarkerExpected); |
623 __ Assert(equal, kAlignmentMarkerExpected); | |
624 } | |
625 __ bind(&no_padding); | |
626 } else { | |
627 // If frame needs dynamic alignment push padding. | |
628 Label no_padding; | |
629 __ cmp(Operand(eax, Deoptimizer::has_alignment_padding_offset()), | |
630 Immediate(0)); | |
631 __ j(equal, &no_padding); | |
632 __ push(Immediate(kAlignmentZapValue)); | |
633 __ bind(&no_padding); | |
634 } | 437 } |
| 438 __ bind(&no_padding); |
635 | 439 |
636 // Replace the current frame with the output frames. | 440 // Replace the current frame with the output frames. |
637 Label outer_push_loop, inner_push_loop, | 441 Label outer_push_loop, inner_push_loop, |
638 outer_loop_header, inner_loop_header; | 442 outer_loop_header, inner_loop_header; |
639 // Outer loop state: eax = current FrameDescription**, edx = one past the | 443 // Outer loop state: eax = current FrameDescription**, edx = one past the |
640 // last FrameDescription**. | 444 // last FrameDescription**. |
641 __ mov(edx, Operand(eax, Deoptimizer::output_count_offset())); | 445 __ mov(edx, Operand(eax, Deoptimizer::output_count_offset())); |
642 __ mov(eax, Operand(eax, Deoptimizer::output_offset())); | 446 __ mov(eax, Operand(eax, Deoptimizer::output_offset())); |
643 __ lea(edx, Operand(eax, edx, times_4, 0)); | 447 __ lea(edx, Operand(eax, edx, times_4, 0)); |
644 __ jmp(&outer_loop_header); | 448 __ jmp(&outer_loop_header); |
645 __ bind(&outer_push_loop); | 449 __ bind(&outer_push_loop); |
646 // Inner loop state: ebx = current FrameDescription*, ecx = loop index. | 450 // Inner loop state: ebx = current FrameDescription*, ecx = loop index. |
647 __ mov(ebx, Operand(eax, 0)); | 451 __ mov(ebx, Operand(eax, 0)); |
648 __ mov(ecx, Operand(ebx, FrameDescription::frame_size_offset())); | 452 __ mov(ecx, Operand(ebx, FrameDescription::frame_size_offset())); |
649 __ jmp(&inner_loop_header); | 453 __ jmp(&inner_loop_header); |
650 __ bind(&inner_push_loop); | 454 __ bind(&inner_push_loop); |
651 __ sub(ecx, Immediate(sizeof(uint32_t))); | 455 __ sub(ecx, Immediate(sizeof(uint32_t))); |
652 __ push(Operand(ebx, ecx, times_1, FrameDescription::frame_content_offset())); | 456 __ push(Operand(ebx, ecx, times_1, FrameDescription::frame_content_offset())); |
653 __ bind(&inner_loop_header); | 457 __ bind(&inner_loop_header); |
654 __ test(ecx, ecx); | 458 __ test(ecx, ecx); |
655 __ j(not_zero, &inner_push_loop); | 459 __ j(not_zero, &inner_push_loop); |
656 __ add(eax, Immediate(kPointerSize)); | 460 __ add(eax, Immediate(kPointerSize)); |
657 __ bind(&outer_loop_header); | 461 __ bind(&outer_loop_header); |
658 __ cmp(eax, edx); | 462 __ cmp(eax, edx); |
659 __ j(below, &outer_push_loop); | 463 __ j(below, &outer_push_loop); |
660 | 464 |
661 // In case of OSR or a failed STUB, we have to restore the XMM registers. | 465 // In case of a failed STUB, we have to restore the XMM registers. |
662 if (CpuFeatures::IsSupported(SSE2)) { | 466 if (CpuFeatures::IsSupported(SSE2)) { |
663 CpuFeatureScope scope(masm(), SSE2); | 467 CpuFeatureScope scope(masm(), SSE2); |
664 for (int i = 0; i < XMMRegister::kNumAllocatableRegisters; ++i) { | 468 for (int i = 0; i < XMMRegister::kNumAllocatableRegisters; ++i) { |
665 XMMRegister xmm_reg = XMMRegister::FromAllocationIndex(i); | 469 XMMRegister xmm_reg = XMMRegister::FromAllocationIndex(i); |
666 int src_offset = i * kDoubleSize + double_regs_offset; | 470 int src_offset = i * kDoubleSize + double_regs_offset; |
667 __ movdbl(xmm_reg, Operand(ebx, src_offset)); | 471 __ movdbl(xmm_reg, Operand(ebx, src_offset)); |
668 } | 472 } |
669 } | 473 } |
670 | 474 |
671 // Push state, pc, and continuation from the last output frame. | 475 // Push state, pc, and continuation from the last output frame. |
672 if (type() != OSR) { | 476 __ push(Operand(ebx, FrameDescription::state_offset())); |
673 __ push(Operand(ebx, FrameDescription::state_offset())); | |
674 } | |
675 __ push(Operand(ebx, FrameDescription::pc_offset())); | 477 __ push(Operand(ebx, FrameDescription::pc_offset())); |
676 __ push(Operand(ebx, FrameDescription::continuation_offset())); | 478 __ push(Operand(ebx, FrameDescription::continuation_offset())); |
677 | 479 |
678 | 480 |
679 // Push the registers from the last output frame. | 481 // Push the registers from the last output frame. |
680 for (int i = 0; i < kNumberOfRegisters; i++) { | 482 for (int i = 0; i < kNumberOfRegisters; i++) { |
681 int offset = (i * kPointerSize) + FrameDescription::registers_offset(); | 483 int offset = (i * kPointerSize) + FrameDescription::registers_offset(); |
682 __ push(Operand(ebx, offset)); | 484 __ push(Operand(ebx, offset)); |
683 } | 485 } |
684 | 486 |
(...skipping 28 matching lines...) Expand all Loading... |
713 SetFrameSlot(offset, value); | 515 SetFrameSlot(offset, value); |
714 } | 516 } |
715 | 517 |
716 | 518 |
717 #undef __ | 519 #undef __ |
718 | 520 |
719 | 521 |
720 } } // namespace v8::internal | 522 } } // namespace v8::internal |
721 | 523 |
722 #endif // V8_TARGET_ARCH_IA32 | 524 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |