| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 public: | 335 public: |
| 336 virtual void EnterContext(Context* context) { } // Don't care. | 336 virtual void EnterContext(Context* context) { } // Don't care. |
| 337 virtual void LeaveContext(Context* context) { } // Don't care. | 337 virtual void LeaveContext(Context* context) { } // Don't care. |
| 338 virtual void VisitFunction(JSFunction* function) { | 338 virtual void VisitFunction(JSFunction* function) { |
| 339 Code* code = function->code(); | 339 Code* code = function->code(); |
| 340 if (!code->marked_for_deoptimization()) return; | 340 if (!code->marked_for_deoptimization()) return; |
| 341 | 341 |
| 342 // Unlink this function and evict from optimized code map. | 342 // Unlink this function and evict from optimized code map. |
| 343 SharedFunctionInfo* shared = function->shared(); | 343 SharedFunctionInfo* shared = function->shared(); |
| 344 function->set_code(shared->code()); | 344 function->set_code(shared->code()); |
| 345 shared->EvictFromOptimizedCodeMap(code, "deoptimized function"); | |
| 346 | 345 |
| 347 if (FLAG_trace_deopt) { | 346 if (FLAG_trace_deopt) { |
| 348 CodeTracer::Scope scope(code->GetHeap()->isolate()->GetCodeTracer()); | 347 CodeTracer::Scope scope(code->GetHeap()->isolate()->GetCodeTracer()); |
| 349 PrintF(scope.file(), "[deoptimizer unlinked: "); | 348 PrintF(scope.file(), "[deoptimizer unlinked: "); |
| 350 function->PrintName(scope.file()); | 349 function->PrintName(scope.file()); |
| 351 PrintF(scope.file(), | 350 PrintF(scope.file(), |
| 352 " / %" V8PRIxPTR "]\n", reinterpret_cast<intptr_t>(function)); | 351 " / %" V8PRIxPTR "]\n", reinterpret_cast<intptr_t>(function)); |
| 353 } | 352 } |
| 354 } | 353 } |
| 355 }; | 354 }; |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 724 | 723 |
| 725 // We rely on this function not causing a GC. It is called from generated code | 724 // We rely on this function not causing a GC. It is called from generated code |
| 726 // without having a real stack frame in place. | 725 // without having a real stack frame in place. |
| 727 void Deoptimizer::DoComputeOutputFrames() { | 726 void Deoptimizer::DoComputeOutputFrames() { |
| 728 // Print some helpful diagnostic information. | 727 // Print some helpful diagnostic information. |
| 729 if (FLAG_log_timer_events && | 728 if (FLAG_log_timer_events && |
| 730 compiled_code_->kind() == Code::OPTIMIZED_FUNCTION) { | 729 compiled_code_->kind() == Code::OPTIMIZED_FUNCTION) { |
| 731 LOG(isolate(), CodeDeoptEvent(compiled_code_)); | 730 LOG(isolate(), CodeDeoptEvent(compiled_code_)); |
| 732 } | 731 } |
| 733 ElapsedTimer timer; | 732 ElapsedTimer timer; |
| 733 |
| 734 // Determine basic deoptimization information. The optimized frame is |
| 735 // described by the input data. |
| 736 DeoptimizationInputData* input_data = |
| 737 DeoptimizationInputData::cast(compiled_code_->deoptimization_data()); |
| 738 |
| 734 if (trace_scope_ != NULL) { | 739 if (trace_scope_ != NULL) { |
| 735 timer.Start(); | 740 timer.Start(); |
| 736 PrintF(trace_scope_->file(), | 741 PrintF(trace_scope_->file(), |
| 737 "[deoptimizing (DEOPT %s): begin 0x%08" V8PRIxPTR " ", | 742 "[deoptimizing (DEOPT %s): begin 0x%08" V8PRIxPTR " ", |
| 738 MessageFor(bailout_type_), | 743 MessageFor(bailout_type_), |
| 739 reinterpret_cast<intptr_t>(function_)); | 744 reinterpret_cast<intptr_t>(function_)); |
| 740 PrintFunctionName(); | 745 PrintFunctionName(); |
| 741 PrintF(trace_scope_->file(), | 746 PrintF(trace_scope_->file(), |
| 742 " @%d, FP to SP delta: %d]\n", | 747 " (opt #%d) @%d, FP to SP delta: %d]\n", |
| 748 input_data->OptimizationId()->value(), |
| 743 bailout_id_, | 749 bailout_id_, |
| 744 fp_to_sp_delta_); | 750 fp_to_sp_delta_); |
| 745 if (bailout_type_ == EAGER || bailout_type_ == SOFT) { | 751 if (bailout_type_ == EAGER || bailout_type_ == SOFT) { |
| 746 compiled_code_->PrintDeoptLocation(trace_scope_->file(), bailout_id_); | 752 compiled_code_->PrintDeoptLocation(trace_scope_->file(), bailout_id_); |
| 747 } | 753 } |
| 748 } | 754 } |
| 749 | 755 |
| 750 // Determine basic deoptimization information. The optimized frame is | |
| 751 // described by the input data. | |
| 752 DeoptimizationInputData* input_data = | |
| 753 DeoptimizationInputData::cast(compiled_code_->deoptimization_data()); | |
| 754 BailoutId node_id = input_data->AstId(bailout_id_); | 756 BailoutId node_id = input_data->AstId(bailout_id_); |
| 755 ByteArray* translations = input_data->TranslationByteArray(); | 757 ByteArray* translations = input_data->TranslationByteArray(); |
| 756 unsigned translation_index = | 758 unsigned translation_index = |
| 757 input_data->TranslationIndex(bailout_id_)->value(); | 759 input_data->TranslationIndex(bailout_id_)->value(); |
| 758 | 760 |
| 759 // Do the input frame to output frame(s) translation. | 761 // Do the input frame to output frame(s) translation. |
| 760 TranslationIterator iterator(translations, translation_index); | 762 TranslationIterator iterator(translations, translation_index); |
| 761 Translation::Opcode opcode = | 763 Translation::Opcode opcode = |
| 762 static_cast<Translation::Opcode>(iterator.Next()); | 764 static_cast<Translation::Opcode>(iterator.Next()); |
| 763 ASSERT(Translation::BEGIN == opcode); | 765 ASSERT(Translation::BEGIN == opcode); |
| 764 USE(opcode); | 766 USE(opcode); |
| 765 // Read the number of output frames and allocate an array for their | 767 // Read the number of output frames and allocate an array for their |
| 766 // descriptions. | 768 // descriptions. |
| 767 int count = iterator.Next(); | 769 int count = iterator.Next(); |
| 768 iterator.Next(); // Drop JS frames count. | 770 iterator.Next(); // Drop JS frames count. |
| 769 ASSERT(output_ == NULL); | 771 ASSERT(output_ == NULL); |
| 770 output_ = new FrameDescription*[count]; | 772 output_ = new FrameDescription*[count]; |
| 771 for (int i = 0; i < count; ++i) { | 773 for (int i = 0; i < count; ++i) { |
| 772 output_[i] = NULL; | 774 output_[i] = NULL; |
| 773 } | 775 } |
| 774 output_count_ = count; | 776 output_count_ = count; |
| 775 | 777 |
| 778 Register fp_reg = JavaScriptFrame::fp_register(); |
| 779 stack_fp_ = reinterpret_cast<Address>( |
| 780 input_->GetRegister(fp_reg.code()) + |
| 781 has_alignment_padding_ * kPointerSize); |
| 782 |
| 776 // Translate each output frame. | 783 // Translate each output frame. |
| 777 for (int i = 0; i < count; ++i) { | 784 for (int i = 0; i < count; ++i) { |
| 778 // Read the ast node id, function, and frame height for this output frame. | 785 // Read the ast node id, function, and frame height for this output frame. |
| 779 Translation::Opcode opcode = | 786 Translation::Opcode opcode = |
| 780 static_cast<Translation::Opcode>(iterator.Next()); | 787 static_cast<Translation::Opcode>(iterator.Next()); |
| 781 switch (opcode) { | 788 switch (opcode) { |
| 782 case Translation::JS_FRAME: | 789 case Translation::JS_FRAME: |
| 783 DoComputeJSFrame(&iterator, i); | 790 DoComputeJSFrame(&iterator, i); |
| 784 jsframe_count_++; | 791 jsframe_count_++; |
| 785 break; | 792 break; |
| (...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1523 // object to the callee and optionally the space to pass the argument | 1530 // object to the callee and optionally the space to pass the argument |
| 1524 // object to the stub failure handler. | 1531 // object to the stub failure handler. |
| 1525 ASSERT(descriptor->register_param_count_ >= 0); | 1532 ASSERT(descriptor->register_param_count_ >= 0); |
| 1526 int height_in_bytes = kPointerSize * descriptor->register_param_count_ + | 1533 int height_in_bytes = kPointerSize * descriptor->register_param_count_ + |
| 1527 sizeof(Arguments) + kPointerSize; | 1534 sizeof(Arguments) + kPointerSize; |
| 1528 int fixed_frame_size = StandardFrameConstants::kFixedFrameSize; | 1535 int fixed_frame_size = StandardFrameConstants::kFixedFrameSize; |
| 1529 int input_frame_size = input_->GetFrameSize(); | 1536 int input_frame_size = input_->GetFrameSize(); |
| 1530 int output_frame_size = height_in_bytes + fixed_frame_size; | 1537 int output_frame_size = height_in_bytes + fixed_frame_size; |
| 1531 if (trace_scope_ != NULL) { | 1538 if (trace_scope_ != NULL) { |
| 1532 PrintF(trace_scope_->file(), | 1539 PrintF(trace_scope_->file(), |
| 1533 " translating %s => StubFailure%sTrampolineStub, height=%d\n", | 1540 " translating %s => StubFailureTrampolineStub, height=%d\n", |
| 1534 CodeStub::MajorName(static_cast<CodeStub::Major>(major_key), false), | 1541 CodeStub::MajorName(static_cast<CodeStub::Major>(major_key), false), |
| 1535 descriptor->HasTailCallContinuation() ? "TailCall" : "", | |
| 1536 height_in_bytes); | 1542 height_in_bytes); |
| 1537 } | 1543 } |
| 1538 | 1544 |
| 1539 // The stub failure trampoline is a single frame. | 1545 // The stub failure trampoline is a single frame. |
| 1540 FrameDescription* output_frame = | 1546 FrameDescription* output_frame = |
| 1541 new(output_frame_size) FrameDescription(output_frame_size, NULL); | 1547 new(output_frame_size) FrameDescription(output_frame_size, NULL); |
| 1542 output_frame->SetFrameType(StackFrame::STUB_FAILURE_TRAMPOLINE); | 1548 output_frame->SetFrameType(StackFrame::STUB_FAILURE_TRAMPOLINE); |
| 1543 ASSERT(frame_index == 0); | 1549 ASSERT(frame_index == 0); |
| 1544 output_[frame_index] = output_frame; | 1550 output_[frame_index] = output_frame; |
| 1545 | 1551 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1614 value = reinterpret_cast<intptr_t>( | 1620 value = reinterpret_cast<intptr_t>( |
| 1615 Smi::FromInt(StackFrame::STUB_FAILURE_TRAMPOLINE)); | 1621 Smi::FromInt(StackFrame::STUB_FAILURE_TRAMPOLINE)); |
| 1616 output_frame->SetFrameSlot(output_frame_offset, value); | 1622 output_frame->SetFrameSlot(output_frame_offset, value); |
| 1617 if (trace_scope_ != NULL) { | 1623 if (trace_scope_ != NULL) { |
| 1618 PrintF(trace_scope_->file(), | 1624 PrintF(trace_scope_->file(), |
| 1619 " 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08" | 1625 " 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08" |
| 1620 V8PRIxPTR " ; function (stub failure sentinel)\n", | 1626 V8PRIxPTR " ; function (stub failure sentinel)\n", |
| 1621 top_address + output_frame_offset, output_frame_offset, value); | 1627 top_address + output_frame_offset, output_frame_offset, value); |
| 1622 } | 1628 } |
| 1623 | 1629 |
| 1624 intptr_t caller_arg_count = descriptor->HasTailCallContinuation() | 1630 intptr_t caller_arg_count = 0; |
| 1625 ? compiled_code_->arguments_count() + 1 : 0; | |
| 1626 bool arg_count_known = !descriptor->stack_parameter_count_.is_valid(); | 1631 bool arg_count_known = !descriptor->stack_parameter_count_.is_valid(); |
| 1627 | 1632 |
| 1628 // Build the Arguments object for the caller's parameters and a pointer to it. | 1633 // Build the Arguments object for the caller's parameters and a pointer to it. |
| 1629 output_frame_offset -= kPointerSize; | 1634 output_frame_offset -= kPointerSize; |
| 1630 int args_arguments_offset = output_frame_offset; | 1635 int args_arguments_offset = output_frame_offset; |
| 1631 intptr_t the_hole = reinterpret_cast<intptr_t>( | 1636 intptr_t the_hole = reinterpret_cast<intptr_t>( |
| 1632 isolate_->heap()->the_hole_value()); | 1637 isolate_->heap()->the_hole_value()); |
| 1633 if (arg_count_known) { | 1638 if (arg_count_known) { |
| 1634 value = frame_ptr + StandardFrameConstants::kCallerSPOffset + | 1639 value = frame_ptr + StandardFrameConstants::kCallerSPOffset + |
| 1635 (caller_arg_count - 1) * kPointerSize; | 1640 (caller_arg_count - 1) * kPointerSize; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1711 } | 1716 } |
| 1712 | 1717 |
| 1713 // Copy the double registers from the input into the output frame. | 1718 // Copy the double registers from the input into the output frame. |
| 1714 CopyDoubleRegisters(output_frame); | 1719 CopyDoubleRegisters(output_frame); |
| 1715 | 1720 |
| 1716 // Fill registers containing handler and number of parameters. | 1721 // Fill registers containing handler and number of parameters. |
| 1717 SetPlatformCompiledStubRegisters(output_frame, descriptor); | 1722 SetPlatformCompiledStubRegisters(output_frame, descriptor); |
| 1718 | 1723 |
| 1719 // Compute this frame's PC, state, and continuation. | 1724 // Compute this frame's PC, state, and continuation. |
| 1720 Code* trampoline = NULL; | 1725 Code* trampoline = NULL; |
| 1721 if (descriptor->HasTailCallContinuation()) { | 1726 StubFunctionMode function_mode = descriptor->function_mode_; |
| 1722 StubFailureTailCallTrampolineStub().FindCodeInCache(&trampoline, isolate_); | 1727 StubFailureTrampolineStub(function_mode).FindCodeInCache(&trampoline, |
| 1723 } else { | 1728 isolate_); |
| 1724 StubFunctionMode function_mode = descriptor->function_mode_; | |
| 1725 StubFailureTrampolineStub(function_mode).FindCodeInCache(&trampoline, | |
| 1726 isolate_); | |
| 1727 } | |
| 1728 ASSERT(trampoline != NULL); | 1729 ASSERT(trampoline != NULL); |
| 1729 output_frame->SetPc(reinterpret_cast<intptr_t>( | 1730 output_frame->SetPc(reinterpret_cast<intptr_t>( |
| 1730 trampoline->instruction_start())); | 1731 trampoline->instruction_start())); |
| 1731 output_frame->SetState(Smi::FromInt(FullCodeGenerator::NO_REGISTERS)); | 1732 output_frame->SetState(Smi::FromInt(FullCodeGenerator::NO_REGISTERS)); |
| 1732 Code* notify_failure = NotifyStubFailureBuiltin(); | 1733 Code* notify_failure = NotifyStubFailureBuiltin(); |
| 1733 output_frame->SetContinuation( | 1734 output_frame->SetContinuation( |
| 1734 reinterpret_cast<intptr_t>(notify_failure->entry())); | 1735 reinterpret_cast<intptr_t>(notify_failure->entry())); |
| 1735 } | 1736 } |
| 1736 | 1737 |
| 1737 | 1738 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1770 // Dispatch on the instance type of the object to be materialized. | 1771 // Dispatch on the instance type of the object to be materialized. |
| 1771 // We also need to make sure that the representation of all fields | 1772 // We also need to make sure that the representation of all fields |
| 1772 // in the given object are general enough to hold a tagged value. | 1773 // in the given object are general enough to hold a tagged value. |
| 1773 Handle<Map> map = Map::GeneralizeAllFieldRepresentations( | 1774 Handle<Map> map = Map::GeneralizeAllFieldRepresentations( |
| 1774 Handle<Map>::cast(MaterializeNextValue()), Representation::Tagged()); | 1775 Handle<Map>::cast(MaterializeNextValue()), Representation::Tagged()); |
| 1775 switch (map->instance_type()) { | 1776 switch (map->instance_type()) { |
| 1776 case HEAP_NUMBER_TYPE: { | 1777 case HEAP_NUMBER_TYPE: { |
| 1777 // Reuse the HeapNumber value directly as it is already properly | 1778 // Reuse the HeapNumber value directly as it is already properly |
| 1778 // tagged and skip materializing the HeapNumber explicitly. | 1779 // tagged and skip materializing the HeapNumber explicitly. |
| 1779 Handle<Object> object = MaterializeNextValue(); | 1780 Handle<Object> object = MaterializeNextValue(); |
| 1780 materialized_objects_->Add(object); | 1781 if (object_index < prev_materialized_count_) { |
| 1782 materialized_objects_->Add(Handle<Object>( |
| 1783 previously_materialized_objects_->get(object_index), isolate_)); |
| 1784 } else { |
| 1785 materialized_objects_->Add(object); |
| 1786 } |
| 1781 materialization_value_index_ += kDoubleSize / kPointerSize - 1; | 1787 materialization_value_index_ += kDoubleSize / kPointerSize - 1; |
| 1782 break; | 1788 break; |
| 1783 } | 1789 } |
| 1784 case JS_OBJECT_TYPE: { | 1790 case JS_OBJECT_TYPE: { |
| 1785 Handle<JSObject> object = | 1791 Handle<JSObject> object = |
| 1786 isolate_->factory()->NewJSObjectFromMap(map, NOT_TENURED, false); | 1792 isolate_->factory()->NewJSObjectFromMap(map, NOT_TENURED, false); |
| 1787 materialized_objects_->Add(object); | 1793 if (object_index < prev_materialized_count_) { |
| 1794 materialized_objects_->Add(Handle<Object>( |
| 1795 previously_materialized_objects_->get(object_index), isolate_)); |
| 1796 } else { |
| 1797 materialized_objects_->Add(object); |
| 1798 } |
| 1788 Handle<Object> properties = MaterializeNextValue(); | 1799 Handle<Object> properties = MaterializeNextValue(); |
| 1789 Handle<Object> elements = MaterializeNextValue(); | 1800 Handle<Object> elements = MaterializeNextValue(); |
| 1790 object->set_properties(FixedArray::cast(*properties)); | 1801 object->set_properties(FixedArray::cast(*properties)); |
| 1791 object->set_elements(FixedArrayBase::cast(*elements)); | 1802 object->set_elements(FixedArrayBase::cast(*elements)); |
| 1792 for (int i = 0; i < length - 3; ++i) { | 1803 for (int i = 0; i < length - 3; ++i) { |
| 1793 Handle<Object> value = MaterializeNextValue(); | 1804 Handle<Object> value = MaterializeNextValue(); |
| 1794 object->FastPropertyAtPut(i, *value); | 1805 object->FastPropertyAtPut(i, *value); |
| 1795 } | 1806 } |
| 1796 break; | 1807 break; |
| 1797 } | 1808 } |
| 1798 case JS_ARRAY_TYPE: { | 1809 case JS_ARRAY_TYPE: { |
| 1799 Handle<JSArray> object = | 1810 Handle<JSArray> object = |
| 1800 isolate_->factory()->NewJSArray(0, map->elements_kind()); | 1811 isolate_->factory()->NewJSArray(0, map->elements_kind()); |
| 1801 materialized_objects_->Add(object); | 1812 if (object_index < prev_materialized_count_) { |
| 1813 materialized_objects_->Add(Handle<Object>( |
| 1814 previously_materialized_objects_->get(object_index), isolate_)); |
| 1815 } else { |
| 1816 materialized_objects_->Add(object); |
| 1817 } |
| 1802 Handle<Object> properties = MaterializeNextValue(); | 1818 Handle<Object> properties = MaterializeNextValue(); |
| 1803 Handle<Object> elements = MaterializeNextValue(); | 1819 Handle<Object> elements = MaterializeNextValue(); |
| 1804 Handle<Object> length = MaterializeNextValue(); | 1820 Handle<Object> length = MaterializeNextValue(); |
| 1805 object->set_properties(FixedArray::cast(*properties)); | 1821 object->set_properties(FixedArray::cast(*properties)); |
| 1806 object->set_elements(FixedArrayBase::cast(*elements)); | 1822 object->set_elements(FixedArrayBase::cast(*elements)); |
| 1807 object->set_length(*length); | 1823 object->set_length(*length); |
| 1808 break; | 1824 break; |
| 1809 } | 1825 } |
| 1810 default: | 1826 default: |
| 1811 PrintF(stderr, | 1827 PrintF(stderr, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1824 if (*value == isolate_->heap()->arguments_marker()) { | 1840 if (*value == isolate_->heap()->arguments_marker()) { |
| 1825 value = MaterializeNextHeapObject(); | 1841 value = MaterializeNextHeapObject(); |
| 1826 } | 1842 } |
| 1827 return value; | 1843 return value; |
| 1828 } | 1844 } |
| 1829 | 1845 |
| 1830 | 1846 |
| 1831 void Deoptimizer::MaterializeHeapObjects(JavaScriptFrameIterator* it) { | 1847 void Deoptimizer::MaterializeHeapObjects(JavaScriptFrameIterator* it) { |
| 1832 ASSERT_NE(DEBUGGER, bailout_type_); | 1848 ASSERT_NE(DEBUGGER, bailout_type_); |
| 1833 | 1849 |
| 1850 MaterializedObjectStore* materialized_store = |
| 1851 isolate_->materialized_object_store(); |
| 1852 previously_materialized_objects_ = materialized_store->Get(stack_fp_); |
| 1853 prev_materialized_count_ = previously_materialized_objects_.is_null() ? |
| 1854 0 : previously_materialized_objects_->length(); |
| 1855 |
| 1834 // Walk all JavaScript output frames with the given frame iterator. | 1856 // Walk all JavaScript output frames with the given frame iterator. |
| 1835 for (int frame_index = 0; frame_index < jsframe_count(); ++frame_index) { | 1857 for (int frame_index = 0; frame_index < jsframe_count(); ++frame_index) { |
| 1836 if (frame_index != 0) it->Advance(); | 1858 if (frame_index != 0) it->Advance(); |
| 1837 JavaScriptFrame* frame = it->frame(); | 1859 JavaScriptFrame* frame = it->frame(); |
| 1838 jsframe_functions_.Add(handle(frame->function(), isolate_)); | 1860 jsframe_functions_.Add(handle(frame->function(), isolate_)); |
| 1839 jsframe_has_adapted_arguments_.Add(frame->has_adapted_arguments()); | 1861 jsframe_has_adapted_arguments_.Add(frame->has_adapted_arguments()); |
| 1840 } | 1862 } |
| 1841 | 1863 |
| 1842 // Handlify all tagged object values before triggering any allocation. | 1864 // Handlify all tagged object values before triggering any allocation. |
| 1843 List<Handle<Object> > values(deferred_objects_tagged_values_.length()); | 1865 List<Handle<Object> > values(deferred_objects_tagged_values_.length()); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1913 reinterpret_cast<void*>(descriptor.slot_address())); | 1935 reinterpret_cast<void*>(descriptor.slot_address())); |
| 1914 } | 1936 } |
| 1915 object->ShortPrint(trace_scope_->file()); | 1937 object->ShortPrint(trace_scope_->file()); |
| 1916 PrintF(trace_scope_->file(), "\n"); | 1938 PrintF(trace_scope_->file(), "\n"); |
| 1917 } | 1939 } |
| 1918 } | 1940 } |
| 1919 | 1941 |
| 1920 ASSERT(materialization_object_index_ == materialized_objects_->length()); | 1942 ASSERT(materialization_object_index_ == materialized_objects_->length()); |
| 1921 ASSERT(materialization_value_index_ == materialized_values_->length()); | 1943 ASSERT(materialization_value_index_ == materialized_values_->length()); |
| 1922 } | 1944 } |
| 1945 |
| 1946 if (prev_materialized_count_ > 0) { |
| 1947 materialized_store->Remove(stack_fp_); |
| 1948 } |
| 1923 } | 1949 } |
| 1924 | 1950 |
| 1925 | 1951 |
| 1926 #ifdef ENABLE_DEBUGGER_SUPPORT | 1952 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 1927 void Deoptimizer::MaterializeHeapNumbersForDebuggerInspectableFrame( | 1953 void Deoptimizer::MaterializeHeapNumbersForDebuggerInspectableFrame( |
| 1928 Address parameters_top, | 1954 Address parameters_top, |
| 1929 uint32_t parameters_size, | 1955 uint32_t parameters_size, |
| 1930 Address expressions_top, | 1956 Address expressions_top, |
| 1931 uint32_t expressions_size, | 1957 uint32_t expressions_size, |
| 1932 DeoptimizedFrameInfo* info) { | 1958 DeoptimizedFrameInfo* info) { |
| (...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2657 JSFunction* function) | 2683 JSFunction* function) |
| 2658 : frame_size_(frame_size), | 2684 : frame_size_(frame_size), |
| 2659 function_(function), | 2685 function_(function), |
| 2660 top_(kZapUint32), | 2686 top_(kZapUint32), |
| 2661 pc_(kZapUint32), | 2687 pc_(kZapUint32), |
| 2662 fp_(kZapUint32), | 2688 fp_(kZapUint32), |
| 2663 context_(kZapUint32), | 2689 context_(kZapUint32), |
| 2664 constant_pool_(kZapUint32) { | 2690 constant_pool_(kZapUint32) { |
| 2665 // Zap all the registers. | 2691 // Zap all the registers. |
| 2666 for (int r = 0; r < Register::kNumRegisters; r++) { | 2692 for (int r = 0; r < Register::kNumRegisters; r++) { |
| 2693 // TODO(jbramley): It isn't safe to use kZapUint32 here. If the register |
| 2694 // isn't used before the next safepoint, the GC will try to scan it as a |
| 2695 // tagged value. kZapUint32 looks like a valid tagged pointer, but it isn't. |
| 2667 SetRegister(r, kZapUint32); | 2696 SetRegister(r, kZapUint32); |
| 2668 } | 2697 } |
| 2669 | 2698 |
| 2670 // Zap all the slots. | 2699 // Zap all the slots. |
| 2671 for (unsigned o = 0; o < frame_size; o += kPointerSize) { | 2700 for (unsigned o = 0; o < frame_size; o += kPointerSize) { |
| 2672 SetFrameSlot(o, kZapUint32); | 2701 SetFrameSlot(o, kZapUint32); |
| 2673 } | 2702 } |
| 2674 } | 2703 } |
| 2675 | 2704 |
| 2676 | 2705 |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2941 UNREACHABLE(); | 2970 UNREACHABLE(); |
| 2942 return ""; | 2971 return ""; |
| 2943 } | 2972 } |
| 2944 | 2973 |
| 2945 #endif | 2974 #endif |
| 2946 | 2975 |
| 2947 | 2976 |
| 2948 // We can't intermix stack decoding and allocations because | 2977 // We can't intermix stack decoding and allocations because |
| 2949 // deoptimization infrastracture is not GC safe. | 2978 // deoptimization infrastracture is not GC safe. |
| 2950 // Thus we build a temporary structure in malloced space. | 2979 // Thus we build a temporary structure in malloced space. |
| 2951 SlotRef SlotRef::ComputeSlotForNextArgument(TranslationIterator* iterator, | 2980 SlotRef SlotRefValueBuilder::ComputeSlotForNextArgument( |
| 2952 DeoptimizationInputData* data, | 2981 Translation::Opcode opcode, |
| 2953 JavaScriptFrame* frame) { | 2982 TranslationIterator* iterator, |
| 2954 Translation::Opcode opcode = | 2983 DeoptimizationInputData* data, |
| 2955 static_cast<Translation::Opcode>(iterator->Next()); | 2984 JavaScriptFrame* frame) { |
| 2956 | |
| 2957 switch (opcode) { | 2985 switch (opcode) { |
| 2958 case Translation::BEGIN: | 2986 case Translation::BEGIN: |
| 2959 case Translation::JS_FRAME: | 2987 case Translation::JS_FRAME: |
| 2960 case Translation::ARGUMENTS_ADAPTOR_FRAME: | 2988 case Translation::ARGUMENTS_ADAPTOR_FRAME: |
| 2961 case Translation::CONSTRUCT_STUB_FRAME: | 2989 case Translation::CONSTRUCT_STUB_FRAME: |
| 2962 case Translation::GETTER_STUB_FRAME: | 2990 case Translation::GETTER_STUB_FRAME: |
| 2963 case Translation::SETTER_STUB_FRAME: | 2991 case Translation::SETTER_STUB_FRAME: |
| 2964 // Peeled off before getting here. | 2992 // Peeled off before getting here. |
| 2965 break; | 2993 break; |
| 2966 | 2994 |
| 2967 case Translation::DUPLICATED_OBJECT: | 2995 case Translation::DUPLICATED_OBJECT: { |
| 2996 return SlotRef::NewDuplicateObject(iterator->Next()); |
| 2997 } |
| 2998 |
| 2968 case Translation::ARGUMENTS_OBJECT: | 2999 case Translation::ARGUMENTS_OBJECT: |
| 2969 case Translation::CAPTURED_OBJECT: | 3000 return SlotRef::NewArgumentsObject(iterator->Next()); |
| 2970 // This can be only emitted for local slots not for argument slots. | 3001 |
| 2971 break; | 3002 case Translation::CAPTURED_OBJECT: { |
| 3003 return SlotRef::NewDeferredObject(iterator->Next()); |
| 3004 } |
| 2972 | 3005 |
| 2973 case Translation::REGISTER: | 3006 case Translation::REGISTER: |
| 2974 case Translation::INT32_REGISTER: | 3007 case Translation::INT32_REGISTER: |
| 2975 case Translation::UINT32_REGISTER: | 3008 case Translation::UINT32_REGISTER: |
| 2976 case Translation::DOUBLE_REGISTER: | 3009 case Translation::DOUBLE_REGISTER: |
| 2977 // We are at safepoint which corresponds to call. All registers are | 3010 // We are at safepoint which corresponds to call. All registers are |
| 2978 // saved by caller so there would be no live registers at this | 3011 // saved by caller so there would be no live registers at this |
| 2979 // point. Thus these translation commands should not be used. | 3012 // point. Thus these translation commands should not be used. |
| 2980 break; | 3013 break; |
| 2981 | 3014 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 3007 int literal_index = iterator->Next(); | 3040 int literal_index = iterator->Next(); |
| 3008 return SlotRef(data->GetIsolate(), | 3041 return SlotRef(data->GetIsolate(), |
| 3009 data->LiteralArray()->get(literal_index)); | 3042 data->LiteralArray()->get(literal_index)); |
| 3010 } | 3043 } |
| 3011 | 3044 |
| 3012 case Translation::COMPILED_STUB_FRAME: | 3045 case Translation::COMPILED_STUB_FRAME: |
| 3013 UNREACHABLE(); | 3046 UNREACHABLE(); |
| 3014 break; | 3047 break; |
| 3015 } | 3048 } |
| 3016 | 3049 |
| 3017 UNREACHABLE(); | 3050 FATAL("We should never get here - unexpected deopt info."); |
| 3018 return SlotRef(); | 3051 return SlotRef(); |
| 3019 } | 3052 } |
| 3020 | 3053 |
| 3021 | 3054 |
| 3022 void SlotRef::ComputeSlotsForArguments(Vector<SlotRef>* args_slots, | 3055 SlotRefValueBuilder::SlotRefValueBuilder(JavaScriptFrame* frame, |
| 3023 TranslationIterator* it, | 3056 int inlined_jsframe_index, |
| 3024 DeoptimizationInputData* data, | 3057 int formal_parameter_count) |
| 3025 JavaScriptFrame* frame) { | 3058 : current_slot_(0), args_length_(-1), first_slot_index_(-1) { |
| 3026 // Process the translation commands for the arguments. | 3059 DisallowHeapAllocation no_gc; |
| 3027 | 3060 |
| 3028 // Skip the translation command for the receiver. | |
| 3029 it->Skip(Translation::NumberOfOperandsFor( | |
| 3030 static_cast<Translation::Opcode>(it->Next()))); | |
| 3031 | |
| 3032 // Compute slots for arguments. | |
| 3033 for (int i = 0; i < args_slots->length(); ++i) { | |
| 3034 (*args_slots)[i] = ComputeSlotForNextArgument(it, data, frame); | |
| 3035 } | |
| 3036 } | |
| 3037 | |
| 3038 | |
| 3039 Vector<SlotRef> SlotRef::ComputeSlotMappingForArguments( | |
| 3040 JavaScriptFrame* frame, | |
| 3041 int inlined_jsframe_index, | |
| 3042 int formal_parameter_count) { | |
| 3043 DisallowHeapAllocation no_gc; | |
| 3044 int deopt_index = Safepoint::kNoDeoptimizationIndex; | 3061 int deopt_index = Safepoint::kNoDeoptimizationIndex; |
| 3045 DeoptimizationInputData* data = | 3062 DeoptimizationInputData* data = |
| 3046 static_cast<OptimizedFrame*>(frame)->GetDeoptimizationData(&deopt_index); | 3063 static_cast<OptimizedFrame*>(frame)->GetDeoptimizationData(&deopt_index); |
| 3047 TranslationIterator it(data->TranslationByteArray(), | 3064 TranslationIterator it(data->TranslationByteArray(), |
| 3048 data->TranslationIndex(deopt_index)->value()); | 3065 data->TranslationIndex(deopt_index)->value()); |
| 3049 Translation::Opcode opcode = static_cast<Translation::Opcode>(it.Next()); | 3066 Translation::Opcode opcode = static_cast<Translation::Opcode>(it.Next()); |
| 3050 ASSERT(opcode == Translation::BEGIN); | 3067 ASSERT(opcode == Translation::BEGIN); |
| 3051 it.Next(); // Drop frame count. | 3068 it.Next(); // Drop frame count. |
| 3069 |
| 3070 stack_frame_id_ = frame->fp(); |
| 3071 |
| 3052 int jsframe_count = it.Next(); | 3072 int jsframe_count = it.Next(); |
| 3053 USE(jsframe_count); | 3073 USE(jsframe_count); |
| 3054 ASSERT(jsframe_count > inlined_jsframe_index); | 3074 ASSERT(jsframe_count > inlined_jsframe_index); |
| 3055 int jsframes_to_skip = inlined_jsframe_index; | 3075 int jsframes_to_skip = inlined_jsframe_index; |
| 3056 while (true) { | 3076 int number_of_slots = -1; // Number of slots inside our frame (yet unknown) |
| 3077 bool should_deopt = false; |
| 3078 while (number_of_slots != 0) { |
| 3057 opcode = static_cast<Translation::Opcode>(it.Next()); | 3079 opcode = static_cast<Translation::Opcode>(it.Next()); |
| 3080 bool processed = false; |
| 3058 if (opcode == Translation::ARGUMENTS_ADAPTOR_FRAME) { | 3081 if (opcode == Translation::ARGUMENTS_ADAPTOR_FRAME) { |
| 3059 if (jsframes_to_skip == 0) { | 3082 if (jsframes_to_skip == 0) { |
| 3060 ASSERT(Translation::NumberOfOperandsFor(opcode) == 2); | 3083 ASSERT(Translation::NumberOfOperandsFor(opcode) == 2); |
| 3061 | 3084 |
| 3062 it.Skip(1); // literal id | 3085 it.Skip(1); // literal id |
| 3063 int height = it.Next(); | 3086 int height = it.Next(); |
| 3064 | 3087 |
| 3088 // Skip the translation command for the receiver. |
| 3089 it.Skip(Translation::NumberOfOperandsFor( |
| 3090 static_cast<Translation::Opcode>(it.Next()))); |
| 3091 |
| 3065 // We reached the arguments adaptor frame corresponding to the | 3092 // We reached the arguments adaptor frame corresponding to the |
| 3066 // inlined function in question. Number of arguments is height - 1. | 3093 // inlined function in question. Number of arguments is height - 1. |
| 3067 Vector<SlotRef> args_slots = | 3094 first_slot_index_ = slot_refs_.length(); |
| 3068 Vector<SlotRef>::New(height - 1); // Minus receiver. | 3095 args_length_ = height - 1; |
| 3069 ComputeSlotsForArguments(&args_slots, &it, data, frame); | 3096 number_of_slots = height - 1; |
| 3070 return args_slots; | 3097 processed = true; |
| 3071 } | 3098 } |
| 3072 } else if (opcode == Translation::JS_FRAME) { | 3099 } else if (opcode == Translation::JS_FRAME) { |
| 3073 if (jsframes_to_skip == 0) { | 3100 if (jsframes_to_skip == 0) { |
| 3074 // Skip over operands to advance to the next opcode. | 3101 // Skip over operands to advance to the next opcode. |
| 3075 it.Skip(Translation::NumberOfOperandsFor(opcode)); | 3102 it.Skip(Translation::NumberOfOperandsFor(opcode)); |
| 3076 | 3103 |
| 3104 // Skip the translation command for the receiver. |
| 3105 it.Skip(Translation::NumberOfOperandsFor( |
| 3106 static_cast<Translation::Opcode>(it.Next()))); |
| 3107 |
| 3077 // We reached the frame corresponding to the inlined function | 3108 // We reached the frame corresponding to the inlined function |
| 3078 // in question. Process the translation commands for the | 3109 // in question. Process the translation commands for the |
| 3079 // arguments. Number of arguments is equal to the number of | 3110 // arguments. Number of arguments is equal to the number of |
| 3080 // format parameter count. | 3111 // format parameter count. |
| 3081 Vector<SlotRef> args_slots = | 3112 first_slot_index_ = slot_refs_.length(); |
| 3082 Vector<SlotRef>::New(formal_parameter_count); | 3113 args_length_ = formal_parameter_count; |
| 3083 ComputeSlotsForArguments(&args_slots, &it, data, frame); | 3114 number_of_slots = formal_parameter_count; |
| 3084 return args_slots; | 3115 processed = true; |
| 3085 } | 3116 } |
| 3086 jsframes_to_skip--; | 3117 jsframes_to_skip--; |
| 3087 } | 3118 } else if (opcode != Translation::BEGIN && |
| 3088 | 3119 opcode != Translation::CONSTRUCT_STUB_FRAME && |
| 3089 // Skip over operands to advance to the next opcode. | 3120 opcode != Translation::GETTER_STUB_FRAME && |
| 3090 it.Skip(Translation::NumberOfOperandsFor(opcode)); | 3121 opcode != Translation::SETTER_STUB_FRAME && |
| 3091 } | 3122 opcode != Translation::COMPILED_STUB_FRAME) { |
| 3092 | 3123 slot_refs_.Add(ComputeSlotForNextArgument(opcode, &it, data, frame)); |
| 3093 UNREACHABLE(); | 3124 |
| 3094 return Vector<SlotRef>(); | 3125 if (first_slot_index_ >= 0) { |
| 3126 // We have found the beginning of our frame -> make sure we count |
| 3127 // the nested slots of captured objects |
| 3128 number_of_slots--; |
| 3129 SlotRef& slot = slot_refs_.last(); |
| 3130 ASSERT(slot.Representation() != SlotRef::ARGUMENTS_OBJECT); |
| 3131 number_of_slots += slot.GetChildrenCount(); |
| 3132 if (slot.Representation() == SlotRef::DEFERRED_OBJECT || |
| 3133 slot.Representation() == SlotRef::DUPLICATE_OBJECT) { |
| 3134 should_deopt = true; |
| 3135 } |
| 3136 } |
| 3137 |
| 3138 processed = true; |
| 3139 } |
| 3140 if (!processed) { |
| 3141 // Skip over operands to advance to the next opcode. |
| 3142 it.Skip(Translation::NumberOfOperandsFor(opcode)); |
| 3143 } |
| 3144 } |
| 3145 if (should_deopt) { |
| 3146 List<JSFunction*> functions(2); |
| 3147 frame->GetFunctions(&functions); |
| 3148 Deoptimizer::DeoptimizeFunction(functions[0]); |
| 3149 } |
| 3150 } |
| 3151 |
| 3152 |
| 3153 Handle<Object> SlotRef::GetValue(Isolate* isolate) { |
| 3154 switch (representation_) { |
| 3155 case TAGGED: |
| 3156 return Handle<Object>(Memory::Object_at(addr_), isolate); |
| 3157 |
| 3158 case INT32: { |
| 3159 int value = Memory::int32_at(addr_); |
| 3160 if (Smi::IsValid(value)) { |
| 3161 return Handle<Object>(Smi::FromInt(value), isolate); |
| 3162 } else { |
| 3163 return isolate->factory()->NewNumberFromInt(value); |
| 3164 } |
| 3165 } |
| 3166 |
| 3167 case UINT32: { |
| 3168 uint32_t value = Memory::uint32_at(addr_); |
| 3169 if (value <= static_cast<uint32_t>(Smi::kMaxValue)) { |
| 3170 return Handle<Object>(Smi::FromInt(static_cast<int>(value)), isolate); |
| 3171 } else { |
| 3172 return isolate->factory()->NewNumber(static_cast<double>(value)); |
| 3173 } |
| 3174 } |
| 3175 |
| 3176 case DOUBLE: { |
| 3177 double value = read_double_value(addr_); |
| 3178 return isolate->factory()->NewNumber(value); |
| 3179 } |
| 3180 |
| 3181 case LITERAL: |
| 3182 return literal_; |
| 3183 |
| 3184 default: |
| 3185 FATAL("We should never get here - unexpected deopt info."); |
| 3186 return Handle<Object>::null(); |
| 3187 } |
| 3188 } |
| 3189 |
| 3190 |
| 3191 void SlotRefValueBuilder::Prepare(Isolate* isolate) { |
| 3192 MaterializedObjectStore* materialized_store = |
| 3193 isolate->materialized_object_store(); |
| 3194 previously_materialized_objects_ = materialized_store->Get(stack_frame_id_); |
| 3195 prev_materialized_count_ = previously_materialized_objects_.is_null() |
| 3196 ? 0 : previously_materialized_objects_->length(); |
| 3197 |
| 3198 // Skip any materialized objects of the inlined "parent" frames. |
| 3199 // (Note that we still need to materialize them because they might be |
| 3200 // referred to as duplicated objects.) |
| 3201 while (current_slot_ < first_slot_index_) { |
| 3202 GetNext(isolate, 0); |
| 3203 } |
| 3204 ASSERT(current_slot_ == first_slot_index_); |
| 3205 } |
| 3206 |
| 3207 |
| 3208 Handle<Object> SlotRefValueBuilder::GetPreviouslyMaterialized( |
| 3209 Isolate* isolate, int length) { |
| 3210 int object_index = materialized_objects_.length(); |
| 3211 Handle<Object> return_value = Handle<Object>( |
| 3212 previously_materialized_objects_->get(object_index), isolate); |
| 3213 materialized_objects_.Add(return_value); |
| 3214 |
| 3215 // Now need to skip all the nested objects (and possibly read them from |
| 3216 // the materialization store, too). |
| 3217 for (int i = 0; i < length; i++) { |
| 3218 SlotRef& slot = slot_refs_[current_slot_]; |
| 3219 current_slot_++; |
| 3220 |
| 3221 // We need to read all the nested objects - add them to the |
| 3222 // number of objects we need to process. |
| 3223 length += slot.GetChildrenCount(); |
| 3224 |
| 3225 // Put the nested deferred/duplicate objects into our materialization |
| 3226 // array. |
| 3227 if (slot.Representation() == SlotRef::DEFERRED_OBJECT || |
| 3228 slot.Representation() == SlotRef::DUPLICATE_OBJECT) { |
| 3229 int nested_object_index = materialized_objects_.length(); |
| 3230 Handle<Object> nested_object = Handle<Object>( |
| 3231 previously_materialized_objects_->get(nested_object_index), |
| 3232 isolate); |
| 3233 materialized_objects_.Add(nested_object); |
| 3234 } |
| 3235 } |
| 3236 |
| 3237 return return_value; |
| 3238 } |
| 3239 |
| 3240 |
| 3241 Handle<Object> SlotRefValueBuilder::GetNext(Isolate* isolate, int lvl) { |
| 3242 SlotRef& slot = slot_refs_[current_slot_]; |
| 3243 current_slot_++; |
| 3244 switch (slot.Representation()) { |
| 3245 case SlotRef::TAGGED: |
| 3246 case SlotRef::INT32: |
| 3247 case SlotRef::UINT32: |
| 3248 case SlotRef::DOUBLE: |
| 3249 case SlotRef::LITERAL: { |
| 3250 return slot.GetValue(isolate); |
| 3251 } |
| 3252 case SlotRef::ARGUMENTS_OBJECT: { |
| 3253 // We should never need to materialize an arguments object, |
| 3254 // but we still need to put something into the array |
| 3255 // so that the indexing is consistent. |
| 3256 materialized_objects_.Add(isolate->factory()->undefined_value()); |
| 3257 int length = slot.GetChildrenCount(); |
| 3258 for (int i = 0; i < length; ++i) { |
| 3259 // We don't need the argument, just ignore it |
| 3260 GetNext(isolate, lvl + 1); |
| 3261 } |
| 3262 return isolate->factory()->undefined_value(); |
| 3263 } |
| 3264 case SlotRef::DEFERRED_OBJECT: { |
| 3265 int length = slot.GetChildrenCount(); |
| 3266 ASSERT(slot_refs_[current_slot_].Representation() == SlotRef::LITERAL || |
| 3267 slot_refs_[current_slot_].Representation() == SlotRef::TAGGED); |
| 3268 |
| 3269 int object_index = materialized_objects_.length(); |
| 3270 if (object_index < prev_materialized_count_) { |
| 3271 return GetPreviouslyMaterialized(isolate, length); |
| 3272 } |
| 3273 |
| 3274 Handle<Object> map_object = slot_refs_[current_slot_].GetValue(isolate); |
| 3275 Handle<Map> map = Map::GeneralizeAllFieldRepresentations( |
| 3276 Handle<Map>::cast(map_object), Representation::Tagged()); |
| 3277 current_slot_++; |
| 3278 // TODO(jarin) this should be unified with the code in |
| 3279 // Deoptimizer::MaterializeNextHeapObject() |
| 3280 switch (map->instance_type()) { |
| 3281 case HEAP_NUMBER_TYPE: { |
| 3282 // Reuse the HeapNumber value directly as it is already properly |
| 3283 // tagged and skip materializing the HeapNumber explicitly. |
| 3284 Handle<Object> object = GetNext(isolate, lvl + 1); |
| 3285 materialized_objects_.Add(object); |
| 3286 return object; |
| 3287 } |
| 3288 case JS_OBJECT_TYPE: { |
| 3289 Handle<JSObject> object = |
| 3290 isolate->factory()->NewJSObjectFromMap(map, NOT_TENURED, false); |
| 3291 materialized_objects_.Add(object); |
| 3292 Handle<Object> properties = GetNext(isolate, lvl + 1); |
| 3293 Handle<Object> elements = GetNext(isolate, lvl + 1); |
| 3294 object->set_properties(FixedArray::cast(*properties)); |
| 3295 object->set_elements(FixedArrayBase::cast(*elements)); |
| 3296 for (int i = 0; i < length - 3; ++i) { |
| 3297 Handle<Object> value = GetNext(isolate, lvl + 1); |
| 3298 object->FastPropertyAtPut(i, *value); |
| 3299 } |
| 3300 return object; |
| 3301 } |
| 3302 case JS_ARRAY_TYPE: { |
| 3303 Handle<JSArray> object = |
| 3304 isolate->factory()->NewJSArray(0, map->elements_kind()); |
| 3305 materialized_objects_.Add(object); |
| 3306 Handle<Object> properties = GetNext(isolate, lvl + 1); |
| 3307 Handle<Object> elements = GetNext(isolate, lvl + 1); |
| 3308 Handle<Object> length = GetNext(isolate, lvl + 1); |
| 3309 object->set_properties(FixedArray::cast(*properties)); |
| 3310 object->set_elements(FixedArrayBase::cast(*elements)); |
| 3311 object->set_length(*length); |
| 3312 return object; |
| 3313 } |
| 3314 default: |
| 3315 PrintF(stderr, |
| 3316 "[couldn't handle instance type %d]\n", map->instance_type()); |
| 3317 UNREACHABLE(); |
| 3318 break; |
| 3319 } |
| 3320 UNREACHABLE(); |
| 3321 } |
| 3322 |
| 3323 case SlotRef::DUPLICATE_OBJECT: { |
| 3324 int object_index = slot.DuplicateObjectId(); |
| 3325 Handle<Object> object = materialized_objects_[object_index]; |
| 3326 materialized_objects_.Add(object); |
| 3327 return object; |
| 3328 } |
| 3329 default: |
| 3330 UNREACHABLE(); |
| 3331 break; |
| 3332 } |
| 3333 |
| 3334 FATAL("We should never get here - unexpected deopt slot kind."); |
| 3335 return Handle<Object>::null(); |
| 3336 } |
| 3337 |
| 3338 |
| 3339 void SlotRefValueBuilder::Finish(Isolate* isolate) { |
| 3340 // We should have processed all slot |
| 3341 ASSERT(slot_refs_.length() == current_slot_); |
| 3342 |
| 3343 if (materialized_objects_.length() > prev_materialized_count_) { |
| 3344 // We have materialized some new objects, so we have to store them |
| 3345 // to prevent duplicate materialization |
| 3346 Handle<FixedArray> array = isolate->factory()->NewFixedArray( |
| 3347 materialized_objects_.length()); |
| 3348 for (int i = 0; i < materialized_objects_.length(); i++) { |
| 3349 array->set(i, *(materialized_objects_.at(i))); |
| 3350 } |
| 3351 isolate->materialized_object_store()->Set(stack_frame_id_, array); |
| 3352 } |
| 3353 } |
| 3354 |
| 3355 |
| 3356 Handle<FixedArray> MaterializedObjectStore::Get(Address fp) { |
| 3357 int index = StackIdToIndex(fp); |
| 3358 if (index == -1) { |
| 3359 return Handle<FixedArray>::null(); |
| 3360 } |
| 3361 Handle<FixedArray> array = GetStackEntries(); |
| 3362 ASSERT(array->length() > index); |
| 3363 return Handle<FixedArray>::cast(Handle<Object>(array->get(index), |
| 3364 isolate())); |
| 3365 } |
| 3366 |
| 3367 |
| 3368 void MaterializedObjectStore::Set(Address fp, |
| 3369 Handle<FixedArray> materialized_objects) { |
| 3370 int index = StackIdToIndex(fp); |
| 3371 if (index == -1) { |
| 3372 index = frame_fps_.length(); |
| 3373 frame_fps_.Add(fp); |
| 3374 } |
| 3375 |
| 3376 Handle<FixedArray> array = EnsureStackEntries(index + 1); |
| 3377 array->set(index, *materialized_objects); |
| 3378 } |
| 3379 |
| 3380 |
| 3381 void MaterializedObjectStore::Remove(Address fp) { |
| 3382 int index = StackIdToIndex(fp); |
| 3383 ASSERT(index >= 0); |
| 3384 |
| 3385 frame_fps_.Remove(index); |
| 3386 Handle<FixedArray> array = GetStackEntries(); |
| 3387 ASSERT(array->length() > index); |
| 3388 for (int i = index; i < frame_fps_.length(); i++) { |
| 3389 array->set(i, array->get(i + 1)); |
| 3390 } |
| 3391 array->set(frame_fps_.length(), isolate()->heap()->undefined_value()); |
| 3392 } |
| 3393 |
| 3394 |
| 3395 int MaterializedObjectStore::StackIdToIndex(Address fp) { |
| 3396 for (int i = 0; i < frame_fps_.length(); i++) { |
| 3397 if (frame_fps_[i] == fp) { |
| 3398 return i; |
| 3399 } |
| 3400 } |
| 3401 return -1; |
| 3402 } |
| 3403 |
| 3404 |
| 3405 Handle<FixedArray> MaterializedObjectStore::GetStackEntries() { |
| 3406 return Handle<FixedArray>(isolate()->heap()->materialized_objects()); |
| 3407 } |
| 3408 |
| 3409 |
| 3410 Handle<FixedArray> MaterializedObjectStore::EnsureStackEntries(int length) { |
| 3411 Handle<FixedArray> array = GetStackEntries(); |
| 3412 if (array->length() >= length) { |
| 3413 return array; |
| 3414 } |
| 3415 |
| 3416 int new_length = length > 10 ? length : 10; |
| 3417 if (new_length < 2 * array->length()) { |
| 3418 new_length = 2 * array->length(); |
| 3419 } |
| 3420 |
| 3421 Handle<FixedArray> new_array = |
| 3422 isolate()->factory()->NewFixedArray(new_length, TENURED); |
| 3423 for (int i = 0; i < array->length(); i++) { |
| 3424 new_array->set(i, array->get(i)); |
| 3425 } |
| 3426 for (int i = array->length(); i < length; i++) { |
| 3427 new_array->set(i, isolate()->heap()->undefined_value()); |
| 3428 } |
| 3429 isolate()->heap()->public_set_materialized_objects(*new_array); |
| 3430 return new_array; |
| 3095 } | 3431 } |
| 3096 | 3432 |
| 3097 #ifdef ENABLE_DEBUGGER_SUPPORT | 3433 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 3098 | 3434 |
| 3099 DeoptimizedFrameInfo::DeoptimizedFrameInfo(Deoptimizer* deoptimizer, | 3435 DeoptimizedFrameInfo::DeoptimizedFrameInfo(Deoptimizer* deoptimizer, |
| 3100 int frame_index, | 3436 int frame_index, |
| 3101 bool has_arguments_adaptor, | 3437 bool has_arguments_adaptor, |
| 3102 bool has_construct_stub) { | 3438 bool has_construct_stub) { |
| 3103 FrameDescription* output_frame = deoptimizer->output_[frame_index]; | 3439 FrameDescription* output_frame = deoptimizer->output_[frame_index]; |
| 3104 function_ = output_frame->GetFunction(); | 3440 function_ = output_frame->GetFunction(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 3135 | 3471 |
| 3136 void DeoptimizedFrameInfo::Iterate(ObjectVisitor* v) { | 3472 void DeoptimizedFrameInfo::Iterate(ObjectVisitor* v) { |
| 3137 v->VisitPointer(BitCast<Object**>(&function_)); | 3473 v->VisitPointer(BitCast<Object**>(&function_)); |
| 3138 v->VisitPointers(parameters_, parameters_ + parameters_count_); | 3474 v->VisitPointers(parameters_, parameters_ + parameters_count_); |
| 3139 v->VisitPointers(expression_stack_, expression_stack_ + expression_count_); | 3475 v->VisitPointers(expression_stack_, expression_stack_ + expression_count_); |
| 3140 } | 3476 } |
| 3141 | 3477 |
| 3142 #endif // ENABLE_DEBUGGER_SUPPORT | 3478 #endif // ENABLE_DEBUGGER_SUPPORT |
| 3143 | 3479 |
| 3144 } } // namespace v8::internal | 3480 } } // namespace v8::internal |
| OLD | NEW |