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

Side by Side Diff: src/deoptimizer.cc

Issue 155723005: A64: Synchronize with r19001. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/a64
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/deoptimizer.h ('k') | src/disassembler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 755 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 // descriptions. 766 // descriptions.
767 int count = iterator.Next(); 767 int count = iterator.Next();
768 iterator.Next(); // Drop JS frames count. 768 iterator.Next(); // Drop JS frames count.
769 ASSERT(output_ == NULL); 769 ASSERT(output_ == NULL);
770 output_ = new FrameDescription*[count]; 770 output_ = new FrameDescription*[count];
771 for (int i = 0; i < count; ++i) { 771 for (int i = 0; i < count; ++i) {
772 output_[i] = NULL; 772 output_[i] = NULL;
773 } 773 }
774 output_count_ = count; 774 output_count_ = count;
775 775
776 Register fp_reg = JavaScriptFrame::fp_register();
777 stack_fp_ = reinterpret_cast<Address>(
778 input_->GetRegister(fp_reg.code()) +
779 has_alignment_padding_ * kPointerSize);
780
776 // Translate each output frame. 781 // Translate each output frame.
777 for (int i = 0; i < count; ++i) { 782 for (int i = 0; i < count; ++i) {
778 // Read the ast node id, function, and frame height for this output frame. 783 // Read the ast node id, function, and frame height for this output frame.
779 Translation::Opcode opcode = 784 Translation::Opcode opcode =
780 static_cast<Translation::Opcode>(iterator.Next()); 785 static_cast<Translation::Opcode>(iterator.Next());
781 switch (opcode) { 786 switch (opcode) {
782 case Translation::JS_FRAME: 787 case Translation::JS_FRAME:
783 DoComputeJSFrame(&iterator, i); 788 DoComputeJSFrame(&iterator, i);
784 jsframe_count_++; 789 jsframe_count_++;
785 break; 790 break;
(...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after
1523 // object to the callee and optionally the space to pass the argument 1528 // object to the callee and optionally the space to pass the argument
1524 // object to the stub failure handler. 1529 // object to the stub failure handler.
1525 ASSERT(descriptor->register_param_count_ >= 0); 1530 ASSERT(descriptor->register_param_count_ >= 0);
1526 int height_in_bytes = kPointerSize * descriptor->register_param_count_ + 1531 int height_in_bytes = kPointerSize * descriptor->register_param_count_ +
1527 sizeof(Arguments) + kPointerSize; 1532 sizeof(Arguments) + kPointerSize;
1528 int fixed_frame_size = StandardFrameConstants::kFixedFrameSize; 1533 int fixed_frame_size = StandardFrameConstants::kFixedFrameSize;
1529 int input_frame_size = input_->GetFrameSize(); 1534 int input_frame_size = input_->GetFrameSize();
1530 int output_frame_size = height_in_bytes + fixed_frame_size; 1535 int output_frame_size = height_in_bytes + fixed_frame_size;
1531 if (trace_scope_ != NULL) { 1536 if (trace_scope_ != NULL) {
1532 PrintF(trace_scope_->file(), 1537 PrintF(trace_scope_->file(),
1533 " translating %s => StubFailure%sTrampolineStub, height=%d\n", 1538 " translating %s => StubFailureTrampolineStub, height=%d\n",
1534 CodeStub::MajorName(static_cast<CodeStub::Major>(major_key), false), 1539 CodeStub::MajorName(static_cast<CodeStub::Major>(major_key), false),
1535 descriptor->HasTailCallContinuation() ? "TailCall" : "",
1536 height_in_bytes); 1540 height_in_bytes);
1537 } 1541 }
1538 1542
1539 // The stub failure trampoline is a single frame. 1543 // The stub failure trampoline is a single frame.
1540 FrameDescription* output_frame = 1544 FrameDescription* output_frame =
1541 new(output_frame_size) FrameDescription(output_frame_size, NULL); 1545 new(output_frame_size) FrameDescription(output_frame_size, NULL);
1542 output_frame->SetFrameType(StackFrame::STUB_FAILURE_TRAMPOLINE); 1546 output_frame->SetFrameType(StackFrame::STUB_FAILURE_TRAMPOLINE);
1543 ASSERT(frame_index == 0); 1547 ASSERT(frame_index == 0);
1544 output_[frame_index] = output_frame; 1548 output_[frame_index] = output_frame;
1545 1549
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1614 value = reinterpret_cast<intptr_t>( 1618 value = reinterpret_cast<intptr_t>(
1615 Smi::FromInt(StackFrame::STUB_FAILURE_TRAMPOLINE)); 1619 Smi::FromInt(StackFrame::STUB_FAILURE_TRAMPOLINE));
1616 output_frame->SetFrameSlot(output_frame_offset, value); 1620 output_frame->SetFrameSlot(output_frame_offset, value);
1617 if (trace_scope_ != NULL) { 1621 if (trace_scope_ != NULL) {
1618 PrintF(trace_scope_->file(), 1622 PrintF(trace_scope_->file(),
1619 " 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08" 1623 " 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08"
1620 V8PRIxPTR " ; function (stub failure sentinel)\n", 1624 V8PRIxPTR " ; function (stub failure sentinel)\n",
1621 top_address + output_frame_offset, output_frame_offset, value); 1625 top_address + output_frame_offset, output_frame_offset, value);
1622 } 1626 }
1623 1627
1624 intptr_t caller_arg_count = descriptor->HasTailCallContinuation() 1628 intptr_t caller_arg_count = 0;
1625 ? compiled_code_->arguments_count() + 1 : 0;
1626 bool arg_count_known = !descriptor->stack_parameter_count_.is_valid(); 1629 bool arg_count_known = !descriptor->stack_parameter_count_.is_valid();
1627 1630
1628 // Build the Arguments object for the caller's parameters and a pointer to it. 1631 // Build the Arguments object for the caller's parameters and a pointer to it.
1629 output_frame_offset -= kPointerSize; 1632 output_frame_offset -= kPointerSize;
1630 int args_arguments_offset = output_frame_offset; 1633 int args_arguments_offset = output_frame_offset;
1631 intptr_t the_hole = reinterpret_cast<intptr_t>( 1634 intptr_t the_hole = reinterpret_cast<intptr_t>(
1632 isolate_->heap()->the_hole_value()); 1635 isolate_->heap()->the_hole_value());
1633 if (arg_count_known) { 1636 if (arg_count_known) {
1634 value = frame_ptr + StandardFrameConstants::kCallerSPOffset + 1637 value = frame_ptr + StandardFrameConstants::kCallerSPOffset +
1635 (caller_arg_count - 1) * kPointerSize; 1638 (caller_arg_count - 1) * kPointerSize;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1711 } 1714 }
1712 1715
1713 // Copy the double registers from the input into the output frame. 1716 // Copy the double registers from the input into the output frame.
1714 CopyDoubleRegisters(output_frame); 1717 CopyDoubleRegisters(output_frame);
1715 1718
1716 // Fill registers containing handler and number of parameters. 1719 // Fill registers containing handler and number of parameters.
1717 SetPlatformCompiledStubRegisters(output_frame, descriptor); 1720 SetPlatformCompiledStubRegisters(output_frame, descriptor);
1718 1721
1719 // Compute this frame's PC, state, and continuation. 1722 // Compute this frame's PC, state, and continuation.
1720 Code* trampoline = NULL; 1723 Code* trampoline = NULL;
1721 if (descriptor->HasTailCallContinuation()) { 1724 StubFunctionMode function_mode = descriptor->function_mode_;
1722 StubFailureTailCallTrampolineStub().FindCodeInCache(&trampoline, isolate_); 1725 StubFailureTrampolineStub(function_mode).FindCodeInCache(&trampoline,
1723 } else { 1726 isolate_);
1724 StubFunctionMode function_mode = descriptor->function_mode_;
1725 StubFailureTrampolineStub(function_mode).FindCodeInCache(&trampoline,
1726 isolate_);
1727 }
1728 ASSERT(trampoline != NULL); 1727 ASSERT(trampoline != NULL);
1729 output_frame->SetPc(reinterpret_cast<intptr_t>( 1728 output_frame->SetPc(reinterpret_cast<intptr_t>(
1730 trampoline->instruction_start())); 1729 trampoline->instruction_start()));
1731 output_frame->SetState(Smi::FromInt(FullCodeGenerator::NO_REGISTERS)); 1730 output_frame->SetState(Smi::FromInt(FullCodeGenerator::NO_REGISTERS));
1732 Code* notify_failure = NotifyStubFailureBuiltin(); 1731 Code* notify_failure = NotifyStubFailureBuiltin();
1733 output_frame->SetContinuation( 1732 output_frame->SetContinuation(
1734 reinterpret_cast<intptr_t>(notify_failure->entry())); 1733 reinterpret_cast<intptr_t>(notify_failure->entry()));
1735 } 1734 }
1736 1735
1737 1736
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1770 // Dispatch on the instance type of the object to be materialized. 1769 // Dispatch on the instance type of the object to be materialized.
1771 // We also need to make sure that the representation of all fields 1770 // 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. 1771 // in the given object are general enough to hold a tagged value.
1773 Handle<Map> map = Map::GeneralizeAllFieldRepresentations( 1772 Handle<Map> map = Map::GeneralizeAllFieldRepresentations(
1774 Handle<Map>::cast(MaterializeNextValue()), Representation::Tagged()); 1773 Handle<Map>::cast(MaterializeNextValue()), Representation::Tagged());
1775 switch (map->instance_type()) { 1774 switch (map->instance_type()) {
1776 case HEAP_NUMBER_TYPE: { 1775 case HEAP_NUMBER_TYPE: {
1777 // Reuse the HeapNumber value directly as it is already properly 1776 // Reuse the HeapNumber value directly as it is already properly
1778 // tagged and skip materializing the HeapNumber explicitly. 1777 // tagged and skip materializing the HeapNumber explicitly.
1779 Handle<Object> object = MaterializeNextValue(); 1778 Handle<Object> object = MaterializeNextValue();
1780 materialized_objects_->Add(object); 1779 if (object_index < prev_materialized_count_) {
1780 materialized_objects_->Add(Handle<Object>(
1781 previously_materialized_objects_->get(object_index), isolate_));
1782 } else {
1783 materialized_objects_->Add(object);
1784 }
1781 materialization_value_index_ += kDoubleSize / kPointerSize - 1; 1785 materialization_value_index_ += kDoubleSize / kPointerSize - 1;
1782 break; 1786 break;
1783 } 1787 }
1784 case JS_OBJECT_TYPE: { 1788 case JS_OBJECT_TYPE: {
1785 Handle<JSObject> object = 1789 Handle<JSObject> object =
1786 isolate_->factory()->NewJSObjectFromMap(map, NOT_TENURED, false); 1790 isolate_->factory()->NewJSObjectFromMap(map, NOT_TENURED, false);
1787 materialized_objects_->Add(object); 1791 if (object_index < prev_materialized_count_) {
1792 materialized_objects_->Add(Handle<Object>(
1793 previously_materialized_objects_->get(object_index), isolate_));
1794 } else {
1795 materialized_objects_->Add(object);
1796 }
1788 Handle<Object> properties = MaterializeNextValue(); 1797 Handle<Object> properties = MaterializeNextValue();
1789 Handle<Object> elements = MaterializeNextValue(); 1798 Handle<Object> elements = MaterializeNextValue();
1790 object->set_properties(FixedArray::cast(*properties)); 1799 object->set_properties(FixedArray::cast(*properties));
1791 object->set_elements(FixedArrayBase::cast(*elements)); 1800 object->set_elements(FixedArrayBase::cast(*elements));
1792 for (int i = 0; i < length - 3; ++i) { 1801 for (int i = 0; i < length - 3; ++i) {
1793 Handle<Object> value = MaterializeNextValue(); 1802 Handle<Object> value = MaterializeNextValue();
1794 object->FastPropertyAtPut(i, *value); 1803 object->FastPropertyAtPut(i, *value);
1795 } 1804 }
1796 break; 1805 break;
1797 } 1806 }
1798 case JS_ARRAY_TYPE: { 1807 case JS_ARRAY_TYPE: {
1799 Handle<JSArray> object = 1808 Handle<JSArray> object =
1800 isolate_->factory()->NewJSArray(0, map->elements_kind()); 1809 isolate_->factory()->NewJSArray(0, map->elements_kind());
1801 materialized_objects_->Add(object); 1810 if (object_index < prev_materialized_count_) {
1811 materialized_objects_->Add(Handle<Object>(
1812 previously_materialized_objects_->get(object_index), isolate_));
1813 } else {
1814 materialized_objects_->Add(object);
1815 }
1802 Handle<Object> properties = MaterializeNextValue(); 1816 Handle<Object> properties = MaterializeNextValue();
1803 Handle<Object> elements = MaterializeNextValue(); 1817 Handle<Object> elements = MaterializeNextValue();
1804 Handle<Object> length = MaterializeNextValue(); 1818 Handle<Object> length = MaterializeNextValue();
1805 object->set_properties(FixedArray::cast(*properties)); 1819 object->set_properties(FixedArray::cast(*properties));
1806 object->set_elements(FixedArrayBase::cast(*elements)); 1820 object->set_elements(FixedArrayBase::cast(*elements));
1807 object->set_length(*length); 1821 object->set_length(*length);
1808 break; 1822 break;
1809 } 1823 }
1810 default: 1824 default:
1811 PrintF(stderr, 1825 PrintF(stderr,
(...skipping 12 matching lines...) Expand all
1824 if (*value == isolate_->heap()->arguments_marker()) { 1838 if (*value == isolate_->heap()->arguments_marker()) {
1825 value = MaterializeNextHeapObject(); 1839 value = MaterializeNextHeapObject();
1826 } 1840 }
1827 return value; 1841 return value;
1828 } 1842 }
1829 1843
1830 1844
1831 void Deoptimizer::MaterializeHeapObjects(JavaScriptFrameIterator* it) { 1845 void Deoptimizer::MaterializeHeapObjects(JavaScriptFrameIterator* it) {
1832 ASSERT_NE(DEBUGGER, bailout_type_); 1846 ASSERT_NE(DEBUGGER, bailout_type_);
1833 1847
1848 MaterializedObjectStore* materialized_store =
1849 isolate_->materialized_object_store();
1850 previously_materialized_objects_ = materialized_store->Get(stack_fp_);
1851 prev_materialized_count_ = previously_materialized_objects_.is_null() ?
1852 0 : previously_materialized_objects_->length();
1853
1834 // Walk all JavaScript output frames with the given frame iterator. 1854 // Walk all JavaScript output frames with the given frame iterator.
1835 for (int frame_index = 0; frame_index < jsframe_count(); ++frame_index) { 1855 for (int frame_index = 0; frame_index < jsframe_count(); ++frame_index) {
1836 if (frame_index != 0) it->Advance(); 1856 if (frame_index != 0) it->Advance();
1837 JavaScriptFrame* frame = it->frame(); 1857 JavaScriptFrame* frame = it->frame();
1838 jsframe_functions_.Add(handle(frame->function(), isolate_)); 1858 jsframe_functions_.Add(handle(frame->function(), isolate_));
1839 jsframe_has_adapted_arguments_.Add(frame->has_adapted_arguments()); 1859 jsframe_has_adapted_arguments_.Add(frame->has_adapted_arguments());
1840 } 1860 }
1841 1861
1842 // Handlify all tagged object values before triggering any allocation. 1862 // Handlify all tagged object values before triggering any allocation.
1843 List<Handle<Object> > values(deferred_objects_tagged_values_.length()); 1863 List<Handle<Object> > values(deferred_objects_tagged_values_.length());
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1913 reinterpret_cast<void*>(descriptor.slot_address())); 1933 reinterpret_cast<void*>(descriptor.slot_address()));
1914 } 1934 }
1915 object->ShortPrint(trace_scope_->file()); 1935 object->ShortPrint(trace_scope_->file());
1916 PrintF(trace_scope_->file(), "\n"); 1936 PrintF(trace_scope_->file(), "\n");
1917 } 1937 }
1918 } 1938 }
1919 1939
1920 ASSERT(materialization_object_index_ == materialized_objects_->length()); 1940 ASSERT(materialization_object_index_ == materialized_objects_->length());
1921 ASSERT(materialization_value_index_ == materialized_values_->length()); 1941 ASSERT(materialization_value_index_ == materialized_values_->length());
1922 } 1942 }
1943
1944 if (prev_materialized_count_ > 0) {
1945 materialized_store->Remove(stack_fp_);
1946 }
1923 } 1947 }
1924 1948
1925 1949
1926 #ifdef ENABLE_DEBUGGER_SUPPORT 1950 #ifdef ENABLE_DEBUGGER_SUPPORT
1927 void Deoptimizer::MaterializeHeapNumbersForDebuggerInspectableFrame( 1951 void Deoptimizer::MaterializeHeapNumbersForDebuggerInspectableFrame(
1928 Address parameters_top, 1952 Address parameters_top,
1929 uint32_t parameters_size, 1953 uint32_t parameters_size,
1930 Address expressions_top, 1954 Address expressions_top,
1931 uint32_t expressions_size, 1955 uint32_t expressions_size,
1932 DeoptimizedFrameInfo* info) { 1956 DeoptimizedFrameInfo* info) {
(...skipping 1011 matching lines...) Expand 10 before | Expand all | Expand 10 after
2944 UNREACHABLE(); 2968 UNREACHABLE();
2945 return ""; 2969 return "";
2946 } 2970 }
2947 2971
2948 #endif 2972 #endif
2949 2973
2950 2974
2951 // We can't intermix stack decoding and allocations because 2975 // We can't intermix stack decoding and allocations because
2952 // deoptimization infrastracture is not GC safe. 2976 // deoptimization infrastracture is not GC safe.
2953 // Thus we build a temporary structure in malloced space. 2977 // Thus we build a temporary structure in malloced space.
2954 SlotRef SlotRef::ComputeSlotForNextArgument(TranslationIterator* iterator, 2978 SlotRef SlotRefValueBuilder::ComputeSlotForNextArgument(
2955 DeoptimizationInputData* data, 2979 Translation::Opcode opcode,
2956 JavaScriptFrame* frame) { 2980 TranslationIterator* iterator,
2957 Translation::Opcode opcode = 2981 DeoptimizationInputData* data,
2958 static_cast<Translation::Opcode>(iterator->Next()); 2982 JavaScriptFrame* frame) {
2959
2960 switch (opcode) { 2983 switch (opcode) {
2961 case Translation::BEGIN: 2984 case Translation::BEGIN:
2962 case Translation::JS_FRAME: 2985 case Translation::JS_FRAME:
2963 case Translation::ARGUMENTS_ADAPTOR_FRAME: 2986 case Translation::ARGUMENTS_ADAPTOR_FRAME:
2964 case Translation::CONSTRUCT_STUB_FRAME: 2987 case Translation::CONSTRUCT_STUB_FRAME:
2965 case Translation::GETTER_STUB_FRAME: 2988 case Translation::GETTER_STUB_FRAME:
2966 case Translation::SETTER_STUB_FRAME: 2989 case Translation::SETTER_STUB_FRAME:
2967 // Peeled off before getting here. 2990 // Peeled off before getting here.
2968 break; 2991 break;
2969 2992
2970 case Translation::DUPLICATED_OBJECT: 2993 case Translation::DUPLICATED_OBJECT: {
2994 return SlotRef::NewDuplicateObject(iterator->Next());
2995 }
2996
2971 case Translation::ARGUMENTS_OBJECT: 2997 case Translation::ARGUMENTS_OBJECT:
2972 case Translation::CAPTURED_OBJECT:
2973 // This can be only emitted for local slots not for argument slots. 2998 // This can be only emitted for local slots not for argument slots.
2974 break; 2999 break;
2975 3000
3001 case Translation::CAPTURED_OBJECT: {
3002 return SlotRef::NewDeferredObject(iterator->Next());
3003 }
3004
2976 case Translation::REGISTER: 3005 case Translation::REGISTER:
2977 case Translation::INT32_REGISTER: 3006 case Translation::INT32_REGISTER:
2978 case Translation::UINT32_REGISTER: 3007 case Translation::UINT32_REGISTER:
2979 case Translation::DOUBLE_REGISTER: 3008 case Translation::DOUBLE_REGISTER:
2980 // We are at safepoint which corresponds to call. All registers are 3009 // We are at safepoint which corresponds to call. All registers are
2981 // saved by caller so there would be no live registers at this 3010 // saved by caller so there would be no live registers at this
2982 // point. Thus these translation commands should not be used. 3011 // point. Thus these translation commands should not be used.
2983 break; 3012 break;
2984 3013
2985 case Translation::STACK_SLOT: { 3014 case Translation::STACK_SLOT: {
(...skipping 29 matching lines...) Expand all
3015 case Translation::COMPILED_STUB_FRAME: 3044 case Translation::COMPILED_STUB_FRAME:
3016 UNREACHABLE(); 3045 UNREACHABLE();
3017 break; 3046 break;
3018 } 3047 }
3019 3048
3020 UNREACHABLE(); 3049 UNREACHABLE();
3021 return SlotRef(); 3050 return SlotRef();
3022 } 3051 }
3023 3052
3024 3053
3025 void SlotRef::ComputeSlotsForArguments(Vector<SlotRef>* args_slots, 3054 SlotRefValueBuilder::SlotRefValueBuilder(JavaScriptFrame* frame,
3026 TranslationIterator* it, 3055 int inlined_jsframe_index,
3027 DeoptimizationInputData* data, 3056 int formal_parameter_count)
3028 JavaScriptFrame* frame) { 3057 : current_slot_(0), args_length_(-1), first_slot_index_(-1) {
3029 // Process the translation commands for the arguments. 3058 DisallowHeapAllocation no_gc;
3030 3059
3031 // Skip the translation command for the receiver.
3032 it->Skip(Translation::NumberOfOperandsFor(
3033 static_cast<Translation::Opcode>(it->Next())));
3034
3035 // Compute slots for arguments.
3036 for (int i = 0; i < args_slots->length(); ++i) {
3037 (*args_slots)[i] = ComputeSlotForNextArgument(it, data, frame);
3038 }
3039 }
3040
3041
3042 Vector<SlotRef> SlotRef::ComputeSlotMappingForArguments(
3043 JavaScriptFrame* frame,
3044 int inlined_jsframe_index,
3045 int formal_parameter_count) {
3046 DisallowHeapAllocation no_gc;
3047 int deopt_index = Safepoint::kNoDeoptimizationIndex; 3060 int deopt_index = Safepoint::kNoDeoptimizationIndex;
3048 DeoptimizationInputData* data = 3061 DeoptimizationInputData* data =
3049 static_cast<OptimizedFrame*>(frame)->GetDeoptimizationData(&deopt_index); 3062 static_cast<OptimizedFrame*>(frame)->GetDeoptimizationData(&deopt_index);
3050 TranslationIterator it(data->TranslationByteArray(), 3063 TranslationIterator it(data->TranslationByteArray(),
3051 data->TranslationIndex(deopt_index)->value()); 3064 data->TranslationIndex(deopt_index)->value());
3052 Translation::Opcode opcode = static_cast<Translation::Opcode>(it.Next()); 3065 Translation::Opcode opcode = static_cast<Translation::Opcode>(it.Next());
3053 ASSERT(opcode == Translation::BEGIN); 3066 ASSERT(opcode == Translation::BEGIN);
3054 it.Next(); // Drop frame count. 3067 it.Next(); // Drop frame count.
3068
3069 stack_frame_id_ = frame->fp();
3070
3055 int jsframe_count = it.Next(); 3071 int jsframe_count = it.Next();
3056 USE(jsframe_count); 3072 USE(jsframe_count);
3057 ASSERT(jsframe_count > inlined_jsframe_index); 3073 ASSERT(jsframe_count > inlined_jsframe_index);
3058 int jsframes_to_skip = inlined_jsframe_index; 3074 int jsframes_to_skip = inlined_jsframe_index;
3059 while (true) { 3075 int number_of_slots = -1; // Number of slots inside our frame (yet unknown)
3076 bool should_deopt = false;
3077 while (number_of_slots != 0) {
3060 opcode = static_cast<Translation::Opcode>(it.Next()); 3078 opcode = static_cast<Translation::Opcode>(it.Next());
3079 bool processed = false;
3061 if (opcode == Translation::ARGUMENTS_ADAPTOR_FRAME) { 3080 if (opcode == Translation::ARGUMENTS_ADAPTOR_FRAME) {
3062 if (jsframes_to_skip == 0) { 3081 if (jsframes_to_skip == 0) {
3063 ASSERT(Translation::NumberOfOperandsFor(opcode) == 2); 3082 ASSERT(Translation::NumberOfOperandsFor(opcode) == 2);
3064 3083
3065 it.Skip(1); // literal id 3084 it.Skip(1); // literal id
3066 int height = it.Next(); 3085 int height = it.Next();
3067 3086
3087 // Skip the translation command for the receiver.
3088 it.Skip(Translation::NumberOfOperandsFor(
3089 static_cast<Translation::Opcode>(it.Next())));
3090
3068 // We reached the arguments adaptor frame corresponding to the 3091 // We reached the arguments adaptor frame corresponding to the
3069 // inlined function in question. Number of arguments is height - 1. 3092 // inlined function in question. Number of arguments is height - 1.
3070 Vector<SlotRef> args_slots = 3093 first_slot_index_ = slot_refs_.length();
3071 Vector<SlotRef>::New(height - 1); // Minus receiver. 3094 args_length_ = height - 1;
3072 ComputeSlotsForArguments(&args_slots, &it, data, frame); 3095 number_of_slots = height - 1;
3073 return args_slots; 3096 processed = true;
3074 } 3097 }
3075 } else if (opcode == Translation::JS_FRAME) { 3098 } else if (opcode == Translation::JS_FRAME) {
3076 if (jsframes_to_skip == 0) { 3099 if (jsframes_to_skip == 0) {
3077 // Skip over operands to advance to the next opcode. 3100 // Skip over operands to advance to the next opcode.
3078 it.Skip(Translation::NumberOfOperandsFor(opcode)); 3101 it.Skip(Translation::NumberOfOperandsFor(opcode));
3079 3102
3103 // Skip the translation command for the receiver.
3104 it.Skip(Translation::NumberOfOperandsFor(
3105 static_cast<Translation::Opcode>(it.Next())));
3106
3080 // We reached the frame corresponding to the inlined function 3107 // We reached the frame corresponding to the inlined function
3081 // in question. Process the translation commands for the 3108 // in question. Process the translation commands for the
3082 // arguments. Number of arguments is equal to the number of 3109 // arguments. Number of arguments is equal to the number of
3083 // format parameter count. 3110 // format parameter count.
3084 Vector<SlotRef> args_slots = 3111 first_slot_index_ = slot_refs_.length();
3085 Vector<SlotRef>::New(formal_parameter_count); 3112 args_length_ = formal_parameter_count;
3086 ComputeSlotsForArguments(&args_slots, &it, data, frame); 3113 number_of_slots = formal_parameter_count;
3087 return args_slots; 3114 processed = true;
3088 } 3115 }
3089 jsframes_to_skip--; 3116 jsframes_to_skip--;
3090 } 3117 } else if (opcode != Translation::BEGIN &&
3091 3118 opcode != Translation::CONSTRUCT_STUB_FRAME &&
3092 // Skip over operands to advance to the next opcode. 3119 opcode != Translation::GETTER_STUB_FRAME &&
3093 it.Skip(Translation::NumberOfOperandsFor(opcode)); 3120 opcode != Translation::SETTER_STUB_FRAME &&
3121 opcode != Translation::COMPILED_STUB_FRAME) {
3122 slot_refs_.Add(ComputeSlotForNextArgument(opcode, &it, data, frame));
3123
3124 if (first_slot_index_ >= 0) {
3125 // We have found the beginning of our frame -> make sure we count
3126 // the nested slots of captured objects
3127 number_of_slots--;
3128 SlotRef& slot = slot_refs_.last();
3129 if (slot.Representation() == SlotRef::DEFERRED_OBJECT) {
3130 number_of_slots += slot.DeferredObjectLength();
3131 }
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 UNREACHABLE();
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 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 // For nested deferred objects, we need to read its properties
3222 if (slot.Representation() == SlotRef::DEFERRED_OBJECT) {
3223 length += slot.DeferredObjectLength();
3224 }
3225
3226 // For nested deferred and duplicate objects, we need to put them into
3227 // our materialization array
3228 if (slot.Representation() == SlotRef::DEFERRED_OBJECT ||
3229 slot.Representation() == SlotRef::DUPLICATE_OBJECT) {
3230 int nested_object_index = materialized_objects_.length();
3231 Handle<Object> nested_object = Handle<Object>(
3232 previously_materialized_objects_->get(nested_object_index),
3233 isolate);
3234 materialized_objects_.Add(nested_object);
3235 }
3236 }
3237
3238 return return_value;
3239 }
3240
3241
3242 Handle<Object> SlotRefValueBuilder::GetNext(Isolate* isolate, int lvl) {
3243 SlotRef& slot = slot_refs_[current_slot_];
3244 current_slot_++;
3245 switch (slot.Representation()) {
3246 case SlotRef::TAGGED:
3247 case SlotRef::INT32:
3248 case SlotRef::UINT32:
3249 case SlotRef::DOUBLE:
3250 case SlotRef::LITERAL: {
3251 return slot.GetValue(isolate);
3252 }
3253 case SlotRef::DEFERRED_OBJECT: {
3254 int length = slot.DeferredObjectLength();
3255 ASSERT(slot_refs_[current_slot_].Representation() == SlotRef::LITERAL ||
3256 slot_refs_[current_slot_].Representation() == SlotRef::TAGGED);
3257
3258 int object_index = materialized_objects_.length();
3259 if (object_index < prev_materialized_count_) {
3260 return GetPreviouslyMaterialized(isolate, length);
3261 }
3262
3263 Handle<Object> map_object = slot_refs_[current_slot_].GetValue(isolate);
3264 Handle<Map> map = Map::GeneralizeAllFieldRepresentations(
3265 Handle<Map>::cast(map_object), Representation::Tagged());
3266 current_slot_++;
3267 // TODO(jarin) this should be unified with the code in
3268 // Deoptimizer::MaterializeNextHeapObject()
3269 switch (map->instance_type()) {
3270 case HEAP_NUMBER_TYPE: {
3271 // Reuse the HeapNumber value directly as it is already properly
3272 // tagged and skip materializing the HeapNumber explicitly.
3273 Handle<Object> object = GetNext(isolate, lvl + 1);
3274 materialized_objects_.Add(object);
3275 return object;
3276 }
3277 case JS_OBJECT_TYPE: {
3278 Handle<JSObject> object =
3279 isolate->factory()->NewJSObjectFromMap(map, NOT_TENURED, false);
3280 materialized_objects_.Add(object);
3281 Handle<Object> properties = GetNext(isolate, lvl + 1);
3282 Handle<Object> elements = GetNext(isolate, lvl + 1);
3283 object->set_properties(FixedArray::cast(*properties));
3284 object->set_elements(FixedArrayBase::cast(*elements));
3285 for (int i = 0; i < length - 3; ++i) {
3286 Handle<Object> value = GetNext(isolate, lvl + 1);
3287 object->FastPropertyAtPut(i, *value);
3288 }
3289 return object;
3290 }
3291 case JS_ARRAY_TYPE: {
3292 Handle<JSArray> object =
3293 isolate->factory()->NewJSArray(0, map->elements_kind());
3294 materialized_objects_.Add(object);
3295 Handle<Object> properties = GetNext(isolate, lvl + 1);
3296 Handle<Object> elements = GetNext(isolate, lvl + 1);
3297 Handle<Object> length = GetNext(isolate, lvl + 1);
3298 object->set_properties(FixedArray::cast(*properties));
3299 object->set_elements(FixedArrayBase::cast(*elements));
3300 object->set_length(*length);
3301 return object;
3302 }
3303 default:
3304 PrintF(stderr,
3305 "[couldn't handle instance type %d]\n", map->instance_type());
3306 UNREACHABLE();
3307 break;
3308 }
3309 UNREACHABLE();
3310 }
3311
3312 case SlotRef::DUPLICATE_OBJECT: {
3313 int object_index = slot.DuplicateObjectId();
3314 Handle<Object> object = materialized_objects_[object_index];
3315 materialized_objects_.Add(object);
3316 return object;
3317 }
3318 default:
3319 UNREACHABLE();
3320 break;
3094 } 3321 }
3095 3322
3096 UNREACHABLE(); 3323 UNREACHABLE();
3097 return Vector<SlotRef>(); 3324 return Handle<Object>::null();
3325 }
3326
3327
3328 void SlotRefValueBuilder::Finish(Isolate* isolate) {
3329 // We should have processed all slot
3330 ASSERT(slot_refs_.length() == current_slot_);
3331
3332 if (materialized_objects_.length() > prev_materialized_count_) {
3333 // We have materialized some new objects, so we have to store them
3334 // to prevent duplicate materialization
3335 Handle<FixedArray> array = isolate->factory()->NewFixedArray(
3336 materialized_objects_.length());
3337 for (int i = 0; i < materialized_objects_.length(); i++) {
3338 array->set(i, *(materialized_objects_.at(i)));
3339 }
3340 isolate->materialized_object_store()->Set(stack_frame_id_, array);
3341 }
3342 }
3343
3344
3345 Handle<FixedArray> MaterializedObjectStore::Get(Address fp) {
3346 int index = StackIdToIndex(fp);
3347 if (index == -1) {
3348 return Handle<FixedArray>::null();
3349 }
3350 Handle<FixedArray> array = GetStackEntries();
3351 ASSERT(array->length() > index);
3352 return Handle<FixedArray>::cast(Handle<Object>(array->get(index),
3353 isolate()));
3354 }
3355
3356
3357 void MaterializedObjectStore::Set(Address fp,
3358 Handle<FixedArray> materialized_objects) {
3359 int index = StackIdToIndex(fp);
3360 if (index == -1) {
3361 index = frame_fps_.length();
3362 frame_fps_.Add(fp);
3363 }
3364
3365 Handle<FixedArray> array = EnsureStackEntries(index + 1);
3366 array->set(index, *materialized_objects);
3367 }
3368
3369
3370 void MaterializedObjectStore::Remove(Address fp) {
3371 int index = StackIdToIndex(fp);
3372 ASSERT(index >= 0);
3373
3374 frame_fps_.Remove(index);
3375 Handle<FixedArray> array = GetStackEntries();
3376 ASSERT(array->length() > index);
3377 for (int i = index; i < frame_fps_.length(); i++) {
3378 array->set(i, array->get(i + 1));
3379 }
3380 array->set(frame_fps_.length(), isolate()->heap()->undefined_value());
3381 }
3382
3383
3384 int MaterializedObjectStore::StackIdToIndex(Address fp) {
3385 for (int i = 0; i < frame_fps_.length(); i++) {
3386 if (frame_fps_[i] == fp) {
3387 return i;
3388 }
3389 }
3390 return -1;
3391 }
3392
3393
3394 Handle<FixedArray> MaterializedObjectStore::GetStackEntries() {
3395 return Handle<FixedArray>(isolate()->heap()->materialized_objects());
3396 }
3397
3398
3399 Handle<FixedArray> MaterializedObjectStore::EnsureStackEntries(int length) {
3400 Handle<FixedArray> array = GetStackEntries();
3401 if (array->length() >= length) {
3402 return array;
3403 }
3404
3405 int new_length = length > 10 ? length : 10;
3406 if (new_length < 2 * array->length()) {
3407 new_length = 2 * array->length();
3408 }
3409
3410 Handle<FixedArray> new_array =
3411 isolate()->factory()->NewFixedArray(new_length, TENURED);
3412 for (int i = 0; i < array->length(); i++) {
3413 new_array->set(i, array->get(i));
3414 }
3415 for (int i = array->length(); i < length; i++) {
3416 new_array->set(i, isolate()->heap()->undefined_value());
3417 }
3418 isolate()->heap()->public_set_materialized_objects(*new_array);
3419 return new_array;
3098 } 3420 }
3099 3421
3100 #ifdef ENABLE_DEBUGGER_SUPPORT 3422 #ifdef ENABLE_DEBUGGER_SUPPORT
3101 3423
3102 DeoptimizedFrameInfo::DeoptimizedFrameInfo(Deoptimizer* deoptimizer, 3424 DeoptimizedFrameInfo::DeoptimizedFrameInfo(Deoptimizer* deoptimizer,
3103 int frame_index, 3425 int frame_index,
3104 bool has_arguments_adaptor, 3426 bool has_arguments_adaptor,
3105 bool has_construct_stub) { 3427 bool has_construct_stub) {
3106 FrameDescription* output_frame = deoptimizer->output_[frame_index]; 3428 FrameDescription* output_frame = deoptimizer->output_[frame_index];
3107 function_ = output_frame->GetFunction(); 3429 function_ = output_frame->GetFunction();
(...skipping 30 matching lines...) Expand all
3138 3460
3139 void DeoptimizedFrameInfo::Iterate(ObjectVisitor* v) { 3461 void DeoptimizedFrameInfo::Iterate(ObjectVisitor* v) {
3140 v->VisitPointer(BitCast<Object**>(&function_)); 3462 v->VisitPointer(BitCast<Object**>(&function_));
3141 v->VisitPointers(parameters_, parameters_ + parameters_count_); 3463 v->VisitPointers(parameters_, parameters_ + parameters_count_);
3142 v->VisitPointers(expression_stack_, expression_stack_ + expression_count_); 3464 v->VisitPointers(expression_stack_, expression_stack_ + expression_count_);
3143 } 3465 }
3144 3466
3145 #endif // ENABLE_DEBUGGER_SUPPORT 3467 #endif // ENABLE_DEBUGGER_SUPPORT
3146 3468
3147 } } // namespace v8::internal 3469 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/deoptimizer.h ('k') | src/disassembler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698