OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 node->set_next(data->deoptimizing_code_list_); | 95 node->set_next(data->deoptimizing_code_list_); |
96 data->deoptimizing_code_list_ = node; | 96 data->deoptimizing_code_list_ = node; |
97 | 97 |
98 // We might be in the middle of incremental marking with compaction. | 98 // We might be in the middle of incremental marking with compaction. |
99 // Tell collector to treat this code object in a special way and | 99 // Tell collector to treat this code object in a special way and |
100 // ignore all slots that might have been recorded on it. | 100 // ignore all slots that might have been recorded on it. |
101 isolate->heap()->mark_compact_collector()->InvalidateCode(code); | 101 isolate->heap()->mark_compact_collector()->InvalidateCode(code); |
102 | 102 |
103 // Iterate over all the functions which share the same code object | 103 // Iterate over all the functions which share the same code object |
104 // and make them use unoptimized version. | 104 // and make them use unoptimized version. |
105 Context* context = function->context()->native_context(); | 105 Context* context = function->context()->global_context(); |
106 Object* element = context->get(Context::OPTIMIZED_FUNCTIONS_LIST); | 106 Object* element = context->get(Context::OPTIMIZED_FUNCTIONS_LIST); |
107 SharedFunctionInfo* shared = function->shared(); | 107 SharedFunctionInfo* shared = function->shared(); |
108 while (!element->IsUndefined()) { | 108 while (!element->IsUndefined()) { |
109 JSFunction* func = JSFunction::cast(element); | 109 JSFunction* func = JSFunction::cast(element); |
110 // Grab element before code replacement as ReplaceCode alters the list. | 110 // Grab element before code replacement as ReplaceCode alters the list. |
111 element = func->next_function_link(); | 111 element = func->next_function_link(); |
112 if (func->code() == code) { | 112 if (func->code() == code) { |
113 func->ReplaceCode(shared->code()); | 113 func->ReplaceCode(shared->code()); |
114 } | 114 } |
115 } | 115 } |
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 | 575 |
576 ASSERT(0 == output_offset); | 576 ASSERT(0 == output_offset); |
577 | 577 |
578 uint32_t pc = reinterpret_cast<uint32_t>( | 578 uint32_t pc = reinterpret_cast<uint32_t>( |
579 construct_stub->instruction_start() + | 579 construct_stub->instruction_start() + |
580 isolate_->heap()->construct_stub_deopt_pc_offset()->value()); | 580 isolate_->heap()->construct_stub_deopt_pc_offset()->value()); |
581 output_frame->SetPc(pc); | 581 output_frame->SetPc(pc); |
582 } | 582 } |
583 | 583 |
584 | 584 |
585 void Deoptimizer::DoComputeSetterStubFrame(TranslationIterator* iterator, | |
586 int frame_index) { | |
587 JSFunction* setter = JSFunction::cast(ComputeLiteral(iterator->Next())); | |
588 // The receiver and the implicit return value are expected in registers by the | |
589 // StoreIC, so they don't belong to the output stack frame. This means that we | |
590 // have to use a height of 0. | |
591 unsigned height = 0; | |
592 unsigned height_in_bytes = height * kPointerSize; | |
593 if (FLAG_trace_deopt) { | |
594 PrintF(" translating setter stub => height=%u\n", height_in_bytes); | |
595 } | |
596 | |
597 // We need 5 stack entries from StackFrame::INTERNAL (ra, fp, cp, frame type, | |
598 // code object, see MacroAssembler::EnterFrame) + 1 stack entry from setter | |
599 // stub (implicit return value, see StoreStubCompiler::CompileStoreViaSetter). | |
600 unsigned fixed_frame_size = (5 + 1) * kPointerSize; | |
601 unsigned output_frame_size = height_in_bytes + fixed_frame_size; | |
602 | |
603 // Allocate and store the output frame description. | |
604 FrameDescription* output_frame = | |
605 new(output_frame_size) FrameDescription(output_frame_size, setter); | |
606 output_frame->SetFrameType(StackFrame::INTERNAL); | |
607 | |
608 // A frame for a setter stub can not be the topmost or bottommost one. | |
609 ASSERT(frame_index > 0 && frame_index < output_count_ - 1); | |
610 ASSERT(output_[frame_index] == NULL); | |
611 output_[frame_index] = output_frame; | |
612 | |
613 // The top address of the frame is computed from the previous frame's top and | |
614 // this frame's size. | |
615 uint32_t top_address = output_[frame_index - 1]->GetTop() - output_frame_size; | |
616 output_frame->SetTop(top_address); | |
617 | |
618 unsigned output_offset = output_frame_size; | |
619 | |
620 // Read caller's PC from the previous frame. | |
621 output_offset -= kPointerSize; | |
622 intptr_t value = output_[frame_index - 1]->GetPc(); | |
623 output_frame->SetFrameSlot(output_offset, value); | |
624 if (FLAG_trace_deopt) { | |
625 PrintF(" 0x%08" V8PRIxPTR ": [top + %u] <- 0x%08" V8PRIxPTR | |
626 " ; caller's pc\n", | |
627 top_address + output_offset, output_offset, value); | |
628 } | |
629 | |
630 // Read caller's FP from the previous frame, and set this frame's FP. | |
631 output_offset -= kPointerSize; | |
632 value = output_[frame_index - 1]->GetFp(); | |
633 output_frame->SetFrameSlot(output_offset, value); | |
634 intptr_t fp_value = top_address + output_offset; | |
635 output_frame->SetFp(fp_value); | |
636 if (FLAG_trace_deopt) { | |
637 PrintF(" 0x%08" V8PRIxPTR ": [top + %u] <- 0x%08" V8PRIxPTR | |
638 " ; caller's fp\n", | |
639 fp_value, output_offset, value); | |
640 } | |
641 | |
642 // The context can be gotten from the previous frame. | |
643 output_offset -= kPointerSize; | |
644 value = output_[frame_index - 1]->GetContext(); | |
645 output_frame->SetFrameSlot(output_offset, value); | |
646 if (FLAG_trace_deopt) { | |
647 PrintF(" 0x%08" V8PRIxPTR ": [top + %u] <- 0x%08" V8PRIxPTR | |
648 " ; context\n", | |
649 top_address + output_offset, output_offset, value); | |
650 } | |
651 | |
652 // A marker value is used in place of the function. | |
653 output_offset -= kPointerSize; | |
654 value = reinterpret_cast<intptr_t>(Smi::FromInt(StackFrame::INTERNAL)); | |
655 output_frame->SetFrameSlot(output_offset, value); | |
656 if (FLAG_trace_deopt) { | |
657 PrintF(" 0x%08" V8PRIxPTR ": [top + %u] <- 0x%08" V8PRIxPTR | |
658 " ; function (setter sentinel)\n", | |
659 top_address + output_offset, output_offset, value); | |
660 } | |
661 | |
662 // Get Code object from setter stub. | |
663 output_offset -= kPointerSize; | |
664 Code* setter_stub = | |
665 isolate_->builtins()->builtin(Builtins::kStoreIC_Setter_ForDeopt); | |
666 value = reinterpret_cast<intptr_t>(setter_stub); | |
667 output_frame->SetFrameSlot(output_offset, value); | |
668 if (FLAG_trace_deopt) { | |
669 PrintF(" 0x%08" V8PRIxPTR ": [top + %u] <- 0x%08" V8PRIxPTR | |
670 " ; code object\n", | |
671 top_address + output_offset, output_offset, value); | |
672 } | |
673 | |
674 // Skip receiver. | |
675 Translation::Opcode opcode = | |
676 static_cast<Translation::Opcode>(iterator->Next()); | |
677 iterator->Skip(Translation::NumberOfOperandsFor(opcode)); | |
678 | |
679 // The implicit return value was part of the artificial setter stub | |
680 // environment. | |
681 output_offset -= kPointerSize; | |
682 DoTranslateCommand(iterator, frame_index, output_offset); | |
683 | |
684 ASSERT(0 == output_offset); | |
685 | |
686 intptr_t pc = reinterpret_cast<intptr_t>( | |
687 setter_stub->instruction_start() + | |
688 isolate_->heap()->setter_stub_deopt_pc_offset()->value()); | |
689 output_frame->SetPc(pc); | |
690 } | |
691 | |
692 | |
693 // This code is very similar to ia32/arm code, but relies on register names | 585 // This code is very similar to ia32/arm code, but relies on register names |
694 // (fp, sp) and how the frame is laid out. | 586 // (fp, sp) and how the frame is laid out. |
695 void Deoptimizer::DoComputeJSFrame(TranslationIterator* iterator, | 587 void Deoptimizer::DoComputeJSFrame(TranslationIterator* iterator, |
696 int frame_index) { | 588 int frame_index) { |
697 // Read the ast node id, function, and frame height for this output frame. | 589 // Read the ast node id, function, and frame height for this output frame. |
698 BailoutId node_id = BailoutId(iterator->Next()); | 590 BailoutId node_id = BailoutId(iterator->Next()); |
699 JSFunction* function; | 591 JSFunction* function; |
700 if (frame_index != 0) { | 592 if (frame_index != 0) { |
701 function = JSFunction::cast(ComputeLiteral(iterator->Next())); | 593 function = JSFunction::cast(ComputeLiteral(iterator->Next())); |
702 } else { | 594 } else { |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1123 } | 1015 } |
1124 | 1016 |
1125 ASSERT_EQ(masm()->SizeOfCodeGeneratedSince(&table_start), | 1017 ASSERT_EQ(masm()->SizeOfCodeGeneratedSince(&table_start), |
1126 count() * table_entry_size_); | 1018 count() * table_entry_size_); |
1127 } | 1019 } |
1128 | 1020 |
1129 #undef __ | 1021 #undef __ |
1130 | 1022 |
1131 | 1023 |
1132 } } // namespace v8::internal | 1024 } } // namespace v8::internal |
OLD | NEW |