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 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 if (FLAG_trace_osr) { | 456 if (FLAG_trace_osr) { |
457 PrintF("[on-stack replacement translation %s: 0x%08" V8PRIxPTR " ", | 457 PrintF("[on-stack replacement translation %s: 0x%08" V8PRIxPTR " ", |
458 ok ? "finished" : "aborted", | 458 ok ? "finished" : "aborted", |
459 reinterpret_cast<intptr_t>(function_)); | 459 reinterpret_cast<intptr_t>(function_)); |
460 function_->PrintName(); | 460 function_->PrintName(); |
461 PrintF(" => pc=0x%0x]\n", output_[0]->GetPc()); | 461 PrintF(" => pc=0x%0x]\n", output_[0]->GetPc()); |
462 } | 462 } |
463 } | 463 } |
464 | 464 |
465 | 465 |
466 void Deoptimizer::DoComputeCompiledStubFrame(TranslationIterator* iterator, | |
467 int frame_index) { | |
468 // | |
469 // FROM TO | |
470 // | .... | | .... | | |
471 // +-------------------------+ +-------------------------+ | |
472 // | JSFunction continuation | | JSFunction continuation | | |
473 // +-------------------------+ +-------------------------+ | |
474 // | | saved frame (ebp) | | saved frame (ebp) | | |
475 // | +=========================+<-ebp +=========================+<-ebp | |
476 // | | JSFunction context | | JSFunction context | | |
477 // v +-------------------------+ +-------------------------| | |
478 // | COMPILED_STUB marker | | STUB_FAILURE marker | | |
479 // +-------------------------+ +-------------------------+ | |
480 // | | | caller args.arguments_ | | |
481 // | ... | +-------------------------+ | |
482 // | | | caller args.length_ | | |
483 // |-------------------------|<-esp +-------------------------+ | |
484 // | caller args pointer | | |
485 // +-------------------------+ | |
486 // | caller stack param 1 | | |
487 // parameters in registers +-------------------------+ | |
488 // and spilled to stack | .... | | |
489 // +-------------------------+ | |
490 // | caller stack param n | | |
491 // +-------------------------+<-esp | |
492 // eax = number of parameters | |
493 // ebx = failure handler address | |
494 // ebp = saved frame | |
495 // esi = JSFunction context | |
496 // | |
497 | |
498 ASSERT(compiled_code_->kind() == Code::COMPILED_STUB); | |
499 int major_key = compiled_code_->major_key(); | |
500 CodeStubInterfaceDescriptor* descriptor = | |
501 isolate_->code_stub_interface_descriptor(major_key); | |
502 | |
503 // The output frame must have room for all pushed register parameters | |
504 // and the standard stack frame slots. Include space for an argument | |
505 // object to the callee and optionally the space to pass the argument | |
506 // object to the stub failure handler. | |
507 int height_in_bytes = kPointerSize * descriptor->register_param_count_ + | |
508 sizeof(Arguments) + kPointerSize; | |
509 int fixed_frame_size = StandardFrameConstants::kFixedFrameSize; | |
510 int input_frame_size = input_->GetFrameSize(); | |
511 int output_frame_size = height_in_bytes + fixed_frame_size; | |
512 if (trace_) { | |
513 PrintF(" translating %s => StubFailureTrampolineStub, height=%d\n", | |
514 CodeStub::MajorName(static_cast<CodeStub::Major>(major_key), false), | |
515 height_in_bytes); | |
516 } | |
517 | |
518 // The stub failure trampoline is a single frame. | |
519 FrameDescription* output_frame = | |
520 new(output_frame_size) FrameDescription(output_frame_size, NULL); | |
521 output_frame->SetFrameType(StackFrame::STUB_FAILURE_TRAMPOLINE); | |
522 ASSERT(frame_index == 0); | |
523 output_[frame_index] = output_frame; | |
524 | |
525 // The top address for the output frame can be computed from the input | |
526 // frame pointer and the output frame's height. Subtract space for the | |
527 // context and function slots. | |
528 intptr_t top_address = input_->GetRegister(ebp.code()) - (2 * kPointerSize) - | |
529 height_in_bytes; | |
530 output_frame->SetTop(top_address); | |
531 | |
532 // Read caller's PC (JSFunction continuation) from the input frame. | |
533 intptr_t input_frame_offset = input_frame_size - kPointerSize; | |
534 intptr_t output_frame_offset = output_frame_size - kPointerSize; | |
535 intptr_t value = input_->GetFrameSlot(input_frame_offset); | |
536 output_frame->SetFrameSlot(output_frame_offset, value); | |
537 if (trace_) { | |
538 PrintF(" 0x%08x: [top + %d] <- 0x%08x ; caller's pc\n", | |
539 top_address + output_frame_offset, output_frame_offset, value); | |
540 } | |
541 | |
542 // Read caller's FP from the input frame, and set this frame's FP. | |
543 input_frame_offset -= kPointerSize; | |
544 value = input_->GetFrameSlot(input_frame_offset); | |
545 output_frame_offset -= kPointerSize; | |
546 output_frame->SetFrameSlot(output_frame_offset, value); | |
547 intptr_t frame_ptr = input_->GetRegister(ebp.code()); | |
548 output_frame->SetRegister(ebp.code(), frame_ptr); | |
549 output_frame->SetFp(frame_ptr); | |
550 if (trace_) { | |
551 PrintF(" 0x%08x: [top + %d] <- 0x%08x ; caller's fp\n", | |
552 top_address + output_frame_offset, output_frame_offset, value); | |
553 } | |
554 | |
555 // The context can be gotten from the input frame. | |
556 input_frame_offset -= kPointerSize; | |
557 value = input_->GetFrameSlot(input_frame_offset); | |
558 output_frame->SetRegister(esi.code(), value); | |
559 output_frame_offset -= kPointerSize; | |
560 output_frame->SetFrameSlot(output_frame_offset, value); | |
561 if (trace_) { | |
562 PrintF(" 0x%08x: [top + %d] <- 0x%08x ; context\n", | |
563 top_address + output_frame_offset, output_frame_offset, value); | |
564 } | |
565 | |
566 // A marker value is used in place of the function. | |
567 output_frame_offset -= kPointerSize; | |
568 value = reinterpret_cast<intptr_t>( | |
569 Smi::FromInt(StackFrame::STUB_FAILURE_TRAMPOLINE)); | |
570 output_frame->SetFrameSlot(output_frame_offset, value); | |
571 if (trace_) { | |
572 PrintF(" 0x%08x: [top + %d] <- 0x%08x ; function (stub fail sentinel)\n", | |
573 top_address + output_frame_offset, output_frame_offset, value); | |
574 } | |
575 | |
576 int caller_arg_count = 0; | |
577 if (descriptor->stack_parameter_count_ != NULL) { | |
578 caller_arg_count = | |
579 input_->GetRegister(descriptor->stack_parameter_count_->code()); | |
580 } | |
581 | |
582 // Build the Arguments object for the caller's parameters and a pointer to it. | |
583 output_frame_offset -= kPointerSize; | |
584 value = frame_ptr + StandardFrameConstants::kCallerSPOffset + | |
585 (caller_arg_count - 1) * kPointerSize; | |
586 output_frame->SetFrameSlot(output_frame_offset, value); | |
587 if (trace_) { | |
588 PrintF(" 0x%08x: [top + %d] <- 0x%08x ; args.arguments\n", | |
589 top_address + output_frame_offset, output_frame_offset, value); | |
590 } | |
591 | |
592 output_frame_offset -= kPointerSize; | |
593 value = caller_arg_count; | |
594 output_frame->SetFrameSlot(output_frame_offset, value); | |
595 if (trace_) { | |
596 PrintF(" 0x%08x: [top + %d] <- 0x%08x ; args.length\n", | |
597 top_address + output_frame_offset, output_frame_offset, value); | |
598 } | |
599 | |
600 output_frame_offset -= kPointerSize; | |
601 value = frame_ptr - (output_frame_size - output_frame_offset) - | |
602 StandardFrameConstants::kMarkerOffset + kPointerSize; | |
603 output_frame->SetFrameSlot(output_frame_offset, value); | |
604 if (trace_) { | |
605 PrintF(" 0x%08x: [top + %d] <- 0x%08x ; args*\n", | |
606 top_address + output_frame_offset, output_frame_offset, value); | |
607 } | |
608 | |
609 // Copy the register parameters to the failure frame. | |
610 for (int i = 0; i < descriptor->register_param_count_; ++i) { | |
611 output_frame_offset -= kPointerSize; | |
612 DoTranslateCommand(iterator, 0, output_frame_offset); | |
613 } | |
614 | |
615 ASSERT(0 == output_frame_offset); | |
616 | |
617 for (int i = 0; i < XMMRegister::kNumAllocatableRegisters; ++i) { | |
618 double double_value = input_->GetDoubleRegister(i); | |
619 output_frame->SetDoubleRegister(i, double_value); | |
620 } | |
621 | |
622 intptr_t handler = | |
623 reinterpret_cast<intptr_t>(descriptor->deoptimization_handler_); | |
624 int params = descriptor->register_param_count_; | |
625 if (descriptor->stack_parameter_count_ != NULL) { | |
626 params++; | |
627 } | |
628 output_frame->SetRegister(eax.code(), params); | |
629 output_frame->SetRegister(ebx.code(), handler); | |
630 | |
631 // Compute this frame's PC, state, and continuation. | |
632 Code* trampoline = NULL; | |
633 int extra = descriptor->extra_expression_stack_count_; | |
634 StubFailureTrampolineStub(extra).FindCodeInCache(&trampoline, isolate_); | |
635 ASSERT(trampoline != NULL); | |
636 output_frame->SetPc(reinterpret_cast<intptr_t>( | |
637 trampoline->instruction_start())); | |
638 output_frame->SetState(Smi::FromInt(FullCodeGenerator::NO_REGISTERS)); | |
639 Code* notify_failure = | |
640 isolate_->builtins()->builtin(Builtins::kNotifyStubFailure); | |
641 output_frame->SetContinuation( | |
642 reinterpret_cast<intptr_t>(notify_failure->entry())); | |
643 } | |
644 | |
645 | |
646 void Deoptimizer::DoComputeConstructStubFrame(TranslationIterator* iterator, | |
647 int frame_index) { | |
648 Builtins* builtins = isolate_->builtins(); | |
649 Code* construct_stub = builtins->builtin(Builtins::kJSConstructStubGeneric); | |
650 JSFunction* function = JSFunction::cast(ComputeLiteral(iterator->Next())); | |
651 unsigned height = iterator->Next(); | |
652 unsigned height_in_bytes = height * kPointerSize; | |
653 if (trace_) { | |
654 PrintF(" translating construct stub => height=%d\n", height_in_bytes); | |
655 } | |
656 | |
657 unsigned fixed_frame_size = 7 * kPointerSize; | |
658 unsigned output_frame_size = height_in_bytes + fixed_frame_size; | |
659 | |
660 // Allocate and store the output frame description. | |
661 FrameDescription* output_frame = | |
662 new(output_frame_size) FrameDescription(output_frame_size, function); | |
663 output_frame->SetFrameType(StackFrame::CONSTRUCT); | |
664 | |
665 // Construct stub can not be topmost or bottommost. | |
666 ASSERT(frame_index > 0 && frame_index < output_count_ - 1); | |
667 ASSERT(output_[frame_index] == NULL); | |
668 output_[frame_index] = output_frame; | |
669 | |
670 // The top address of the frame is computed from the previous | |
671 // frame's top and this frame's size. | |
672 uint32_t top_address; | |
673 top_address = output_[frame_index - 1]->GetTop() - output_frame_size; | |
674 output_frame->SetTop(top_address); | |
675 | |
676 // Compute the incoming parameter translation. | |
677 int parameter_count = height; | |
678 unsigned output_offset = output_frame_size; | |
679 for (int i = 0; i < parameter_count; ++i) { | |
680 output_offset -= kPointerSize; | |
681 DoTranslateCommand(iterator, frame_index, output_offset); | |
682 } | |
683 | |
684 // Read caller's PC from the previous frame. | |
685 output_offset -= kPointerSize; | |
686 intptr_t callers_pc = output_[frame_index - 1]->GetPc(); | |
687 output_frame->SetFrameSlot(output_offset, callers_pc); | |
688 if (trace_) { | |
689 PrintF(" 0x%08x: [top + %d] <- 0x%08x ; caller's pc\n", | |
690 top_address + output_offset, output_offset, callers_pc); | |
691 } | |
692 | |
693 // Read caller's FP from the previous frame, and set this frame's FP. | |
694 output_offset -= kPointerSize; | |
695 intptr_t value = output_[frame_index - 1]->GetFp(); | |
696 output_frame->SetFrameSlot(output_offset, value); | |
697 intptr_t fp_value = top_address + output_offset; | |
698 output_frame->SetFp(fp_value); | |
699 if (trace_) { | |
700 PrintF(" 0x%08x: [top + %d] <- 0x%08x ; caller's fp\n", | |
701 fp_value, output_offset, value); | |
702 } | |
703 | |
704 // The context can be gotten from the previous frame. | |
705 output_offset -= kPointerSize; | |
706 value = output_[frame_index - 1]->GetContext(); | |
707 output_frame->SetFrameSlot(output_offset, value); | |
708 if (trace_) { | |
709 PrintF(" 0x%08x: [top + %d] <- 0x%08x ; context\n", | |
710 top_address + output_offset, output_offset, value); | |
711 } | |
712 | |
713 // A marker value is used in place of the function. | |
714 output_offset -= kPointerSize; | |
715 value = reinterpret_cast<intptr_t>(Smi::FromInt(StackFrame::CONSTRUCT)); | |
716 output_frame->SetFrameSlot(output_offset, value); | |
717 if (trace_) { | |
718 PrintF(" 0x%08x: [top + %d] <- 0x%08x ; function (construct sentinel)\n", | |
719 top_address + output_offset, output_offset, value); | |
720 } | |
721 | |
722 // The output frame reflects a JSConstructStubGeneric frame. | |
723 output_offset -= kPointerSize; | |
724 value = reinterpret_cast<intptr_t>(construct_stub); | |
725 output_frame->SetFrameSlot(output_offset, value); | |
726 if (trace_) { | |
727 PrintF(" 0x%08x: [top + %d] <- 0x%08x ; code object\n", | |
728 top_address + output_offset, output_offset, value); | |
729 } | |
730 | |
731 // Number of incoming arguments. | |
732 output_offset -= kPointerSize; | |
733 value = reinterpret_cast<uint32_t>(Smi::FromInt(height - 1)); | |
734 output_frame->SetFrameSlot(output_offset, value); | |
735 if (trace_) { | |
736 PrintF(" 0x%08x: [top + %d] <- 0x%08x ; argc (%d)\n", | |
737 top_address + output_offset, output_offset, value, height - 1); | |
738 } | |
739 | |
740 // The newly allocated object was passed as receiver in the artificial | |
741 // constructor stub environment created by HEnvironment::CopyForInlining(). | |
742 output_offset -= kPointerSize; | |
743 value = output_frame->GetFrameSlot(output_frame_size - kPointerSize); | |
744 output_frame->SetFrameSlot(output_offset, value); | |
745 if (trace_) { | |
746 PrintF(" 0x%08x: [top + %d] <- 0x%08x ; allocated receiver\n", | |
747 top_address + output_offset, output_offset, value); | |
748 } | |
749 | |
750 ASSERT(0 == output_offset); | |
751 | |
752 uint32_t pc = reinterpret_cast<uint32_t>( | |
753 construct_stub->instruction_start() + | |
754 isolate_->heap()->construct_stub_deopt_pc_offset()->value()); | |
755 output_frame->SetPc(pc); | |
756 } | |
757 | |
758 | |
759 void Deoptimizer::DoComputeJSFrame(TranslationIterator* iterator, | 466 void Deoptimizer::DoComputeJSFrame(TranslationIterator* iterator, |
760 int frame_index) { | 467 int frame_index) { |
761 BailoutId node_id = BailoutId(iterator->Next()); | 468 BailoutId node_id = BailoutId(iterator->Next()); |
762 JSFunction* function; | 469 JSFunction* function; |
763 if (frame_index != 0) { | 470 if (frame_index != 0) { |
764 function = JSFunction::cast(ComputeLiteral(iterator->Next())); | 471 function = JSFunction::cast(ComputeLiteral(iterator->Next())); |
765 } else { | 472 } else { |
766 int closure_id = iterator->Next(); | 473 int closure_id = iterator->Next(); |
767 USE(closure_id); | 474 USE(closure_id); |
768 ASSERT_EQ(Translation::kSelfLiteralId, closure_id); | 475 ASSERT_EQ(Translation::kSelfLiteralId, closure_id); |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
956 input_->SetDoubleRegister(i, 0.0); | 663 input_->SetDoubleRegister(i, 0.0); |
957 } | 664 } |
958 | 665 |
959 // Fill the frame content from the actual data on the frame. | 666 // Fill the frame content from the actual data on the frame. |
960 for (unsigned i = 0; i < input_->GetFrameSize(); i += kPointerSize) { | 667 for (unsigned i = 0; i < input_->GetFrameSize(); i += kPointerSize) { |
961 input_->SetFrameSlot(i, Memory::uint32_at(tos + i)); | 668 input_->SetFrameSlot(i, Memory::uint32_at(tos + i)); |
962 } | 669 } |
963 } | 670 } |
964 | 671 |
965 | 672 |
| 673 void Deoptimizer::SetPlatformCompiledStubRegisters( |
| 674 FrameDescription* output_frame, CodeStubInterfaceDescriptor* descriptor) { |
| 675 intptr_t handler = |
| 676 reinterpret_cast<intptr_t>(descriptor->deoptimization_handler_); |
| 677 int params = descriptor->register_param_count_; |
| 678 if (descriptor->stack_parameter_count_ != NULL) { |
| 679 params++; |
| 680 } |
| 681 output_frame->SetRegister(eax.code(), params); |
| 682 output_frame->SetRegister(ebx.code(), handler); |
| 683 } |
| 684 |
| 685 |
| 686 void Deoptimizer::CopyDoubleRegisters(FrameDescription* output_frame) { |
| 687 for (int i = 0; i < XMMRegister::kNumAllocatableRegisters; ++i) { |
| 688 double double_value = input_->GetDoubleRegister(i); |
| 689 output_frame->SetDoubleRegister(i, double_value); |
| 690 } |
| 691 } |
| 692 |
| 693 |
966 #define __ masm()-> | 694 #define __ masm()-> |
967 | 695 |
968 void Deoptimizer::EntryGenerator::Generate() { | 696 void Deoptimizer::EntryGenerator::Generate() { |
969 GeneratePrologue(); | 697 GeneratePrologue(); |
970 | 698 |
971 Isolate* isolate = masm()->isolate(); | 699 Isolate* isolate = masm()->isolate(); |
972 | 700 |
973 // Save all general purpose registers before messing with them. | 701 // Save all general purpose registers before messing with them. |
974 const int kNumberOfRegisters = Register::kNumRegisters; | 702 const int kNumberOfRegisters = Register::kNumRegisters; |
975 | 703 |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1175 } | 903 } |
1176 __ bind(&done); | 904 __ bind(&done); |
1177 } | 905 } |
1178 | 906 |
1179 #undef __ | 907 #undef __ |
1180 | 908 |
1181 | 909 |
1182 } } // namespace v8::internal | 910 } } // namespace v8::internal |
1183 | 911 |
1184 #endif // V8_TARGET_ARCH_IA32 | 912 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |