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

Side by Side Diff: src/deoptimizer.cc

Issue 130803009: Revert "Captured arguments object materialization" (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
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/heap.h » ('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
781 // Translate each output frame. 776 // Translate each output frame.
782 for (int i = 0; i < count; ++i) { 777 for (int i = 0; i < count; ++i) {
783 // Read the ast node id, function, and frame height for this output frame. 778 // Read the ast node id, function, and frame height for this output frame.
784 Translation::Opcode opcode = 779 Translation::Opcode opcode =
785 static_cast<Translation::Opcode>(iterator.Next()); 780 static_cast<Translation::Opcode>(iterator.Next());
786 switch (opcode) { 781 switch (opcode) {
787 case Translation::JS_FRAME: 782 case Translation::JS_FRAME:
788 DoComputeJSFrame(&iterator, i); 783 DoComputeJSFrame(&iterator, i);
789 jsframe_count_++; 784 jsframe_count_++;
790 break; 785 break;
(...skipping 984 matching lines...) Expand 10 before | Expand all | Expand 10 after
1775 // Dispatch on the instance type of the object to be materialized. 1770 // Dispatch on the instance type of the object to be materialized.
1776 // We also need to make sure that the representation of all fields 1771 // We also need to make sure that the representation of all fields
1777 // in the given object are general enough to hold a tagged value. 1772 // in the given object are general enough to hold a tagged value.
1778 Handle<Map> map = Map::GeneralizeAllFieldRepresentations( 1773 Handle<Map> map = Map::GeneralizeAllFieldRepresentations(
1779 Handle<Map>::cast(MaterializeNextValue()), Representation::Tagged()); 1774 Handle<Map>::cast(MaterializeNextValue()), Representation::Tagged());
1780 switch (map->instance_type()) { 1775 switch (map->instance_type()) {
1781 case HEAP_NUMBER_TYPE: { 1776 case HEAP_NUMBER_TYPE: {
1782 // Reuse the HeapNumber value directly as it is already properly 1777 // Reuse the HeapNumber value directly as it is already properly
1783 // tagged and skip materializing the HeapNumber explicitly. 1778 // tagged and skip materializing the HeapNumber explicitly.
1784 Handle<Object> object = MaterializeNextValue(); 1779 Handle<Object> object = MaterializeNextValue();
1785 if (object_index < prev_materialized_count_) { 1780 materialized_objects_->Add(object);
1786 materialized_objects_->Add(Handle<Object>(
1787 previously_materialized_objects_->get(object_index), isolate_));
1788 } else {
1789 materialized_objects_->Add(object);
1790 }
1791 materialization_value_index_ += kDoubleSize / kPointerSize - 1; 1781 materialization_value_index_ += kDoubleSize / kPointerSize - 1;
1792 break; 1782 break;
1793 } 1783 }
1794 case JS_OBJECT_TYPE: { 1784 case JS_OBJECT_TYPE: {
1795 Handle<JSObject> object = 1785 Handle<JSObject> object =
1796 isolate_->factory()->NewJSObjectFromMap(map, NOT_TENURED, false); 1786 isolate_->factory()->NewJSObjectFromMap(map, NOT_TENURED, false);
1797 if (object_index < prev_materialized_count_) { 1787 materialized_objects_->Add(object);
1798 materialized_objects_->Add(Handle<Object>(
1799 previously_materialized_objects_->get(object_index), isolate_));
1800 } else {
1801 materialized_objects_->Add(object);
1802 }
1803 Handle<Object> properties = MaterializeNextValue(); 1788 Handle<Object> properties = MaterializeNextValue();
1804 Handle<Object> elements = MaterializeNextValue(); 1789 Handle<Object> elements = MaterializeNextValue();
1805 object->set_properties(FixedArray::cast(*properties)); 1790 object->set_properties(FixedArray::cast(*properties));
1806 object->set_elements(FixedArrayBase::cast(*elements)); 1791 object->set_elements(FixedArrayBase::cast(*elements));
1807 for (int i = 0; i < length - 3; ++i) { 1792 for (int i = 0; i < length - 3; ++i) {
1808 Handle<Object> value = MaterializeNextValue(); 1793 Handle<Object> value = MaterializeNextValue();
1809 object->FastPropertyAtPut(i, *value); 1794 object->FastPropertyAtPut(i, *value);
1810 } 1795 }
1811 break; 1796 break;
1812 } 1797 }
1813 case JS_ARRAY_TYPE: { 1798 case JS_ARRAY_TYPE: {
1814 Handle<JSArray> object = 1799 Handle<JSArray> object =
1815 isolate_->factory()->NewJSArray(0, map->elements_kind()); 1800 isolate_->factory()->NewJSArray(0, map->elements_kind());
1816 if (object_index < prev_materialized_count_) { 1801 materialized_objects_->Add(object);
1817 materialized_objects_->Add(Handle<Object>(
1818 previously_materialized_objects_->get(object_index), isolate_));
1819 } else {
1820 materialized_objects_->Add(object);
1821 }
1822 Handle<Object> properties = MaterializeNextValue(); 1802 Handle<Object> properties = MaterializeNextValue();
1823 Handle<Object> elements = MaterializeNextValue(); 1803 Handle<Object> elements = MaterializeNextValue();
1824 Handle<Object> length = MaterializeNextValue(); 1804 Handle<Object> length = MaterializeNextValue();
1825 object->set_properties(FixedArray::cast(*properties)); 1805 object->set_properties(FixedArray::cast(*properties));
1826 object->set_elements(FixedArrayBase::cast(*elements)); 1806 object->set_elements(FixedArrayBase::cast(*elements));
1827 object->set_length(*length); 1807 object->set_length(*length);
1828 break; 1808 break;
1829 } 1809 }
1830 default: 1810 default:
1831 PrintF(stderr, 1811 PrintF(stderr,
(...skipping 12 matching lines...) Expand all
1844 if (*value == isolate_->heap()->arguments_marker()) { 1824 if (*value == isolate_->heap()->arguments_marker()) {
1845 value = MaterializeNextHeapObject(); 1825 value = MaterializeNextHeapObject();
1846 } 1826 }
1847 return value; 1827 return value;
1848 } 1828 }
1849 1829
1850 1830
1851 void Deoptimizer::MaterializeHeapObjects(JavaScriptFrameIterator* it) { 1831 void Deoptimizer::MaterializeHeapObjects(JavaScriptFrameIterator* it) {
1852 ASSERT_NE(DEBUGGER, bailout_type_); 1832 ASSERT_NE(DEBUGGER, bailout_type_);
1853 1833
1854 MaterializedObjectStore* materialized_store =
1855 isolate_->materialized_object_store();
1856 previously_materialized_objects_ = materialized_store->Get(stack_fp_);
1857 prev_materialized_count_ = previously_materialized_objects_.is_null() ?
1858 0 : previously_materialized_objects_->length();
1859
1860 // Walk all JavaScript output frames with the given frame iterator. 1834 // Walk all JavaScript output frames with the given frame iterator.
1861 for (int frame_index = 0; frame_index < jsframe_count(); ++frame_index) { 1835 for (int frame_index = 0; frame_index < jsframe_count(); ++frame_index) {
1862 if (frame_index != 0) it->Advance(); 1836 if (frame_index != 0) it->Advance();
1863 JavaScriptFrame* frame = it->frame(); 1837 JavaScriptFrame* frame = it->frame();
1864 jsframe_functions_.Add(handle(frame->function(), isolate_)); 1838 jsframe_functions_.Add(handle(frame->function(), isolate_));
1865 jsframe_has_adapted_arguments_.Add(frame->has_adapted_arguments()); 1839 jsframe_has_adapted_arguments_.Add(frame->has_adapted_arguments());
1866 } 1840 }
1867 1841
1868 // Handlify all tagged object values before triggering any allocation. 1842 // Handlify all tagged object values before triggering any allocation.
1869 List<Handle<Object> > values(deferred_objects_tagged_values_.length()); 1843 List<Handle<Object> > values(deferred_objects_tagged_values_.length());
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1939 reinterpret_cast<void*>(descriptor.slot_address())); 1913 reinterpret_cast<void*>(descriptor.slot_address()));
1940 } 1914 }
1941 object->ShortPrint(trace_scope_->file()); 1915 object->ShortPrint(trace_scope_->file());
1942 PrintF(trace_scope_->file(), "\n"); 1916 PrintF(trace_scope_->file(), "\n");
1943 } 1917 }
1944 } 1918 }
1945 1919
1946 ASSERT(materialization_object_index_ == materialized_objects_->length()); 1920 ASSERT(materialization_object_index_ == materialized_objects_->length());
1947 ASSERT(materialization_value_index_ == materialized_values_->length()); 1921 ASSERT(materialization_value_index_ == materialized_values_->length());
1948 } 1922 }
1949
1950 if (prev_materialized_count_ > 0) {
1951 materialized_store->Remove(stack_fp_);
1952 }
1953 } 1923 }
1954 1924
1955 1925
1956 #ifdef ENABLE_DEBUGGER_SUPPORT 1926 #ifdef ENABLE_DEBUGGER_SUPPORT
1957 void Deoptimizer::MaterializeHeapNumbersForDebuggerInspectableFrame( 1927 void Deoptimizer::MaterializeHeapNumbersForDebuggerInspectableFrame(
1958 Address parameters_top, 1928 Address parameters_top,
1959 uint32_t parameters_size, 1929 uint32_t parameters_size,
1960 Address expressions_top, 1930 Address expressions_top,
1961 uint32_t expressions_size, 1931 uint32_t expressions_size,
1962 DeoptimizedFrameInfo* info) { 1932 DeoptimizedFrameInfo* info) {
(...skipping 1008 matching lines...) Expand 10 before | Expand all | Expand 10 after
2971 UNREACHABLE(); 2941 UNREACHABLE();
2972 return ""; 2942 return "";
2973 } 2943 }
2974 2944
2975 #endif 2945 #endif
2976 2946
2977 2947
2978 // We can't intermix stack decoding and allocations because 2948 // We can't intermix stack decoding and allocations because
2979 // deoptimization infrastracture is not GC safe. 2949 // deoptimization infrastracture is not GC safe.
2980 // Thus we build a temporary structure in malloced space. 2950 // Thus we build a temporary structure in malloced space.
2981 SlotRef SlotRefValueBuilder::ComputeSlotForNextArgument( 2951 SlotRef SlotRef::ComputeSlotForNextArgument(TranslationIterator* iterator,
2982 Translation::Opcode opcode, 2952 DeoptimizationInputData* data,
2983 TranslationIterator* iterator, 2953 JavaScriptFrame* frame) {
2984 DeoptimizationInputData* data, 2954 Translation::Opcode opcode =
2985 JavaScriptFrame* frame) { 2955 static_cast<Translation::Opcode>(iterator->Next());
2956
2986 switch (opcode) { 2957 switch (opcode) {
2987 case Translation::BEGIN: 2958 case Translation::BEGIN:
2988 case Translation::JS_FRAME: 2959 case Translation::JS_FRAME:
2989 case Translation::ARGUMENTS_ADAPTOR_FRAME: 2960 case Translation::ARGUMENTS_ADAPTOR_FRAME:
2990 case Translation::CONSTRUCT_STUB_FRAME: 2961 case Translation::CONSTRUCT_STUB_FRAME:
2991 case Translation::GETTER_STUB_FRAME: 2962 case Translation::GETTER_STUB_FRAME:
2992 case Translation::SETTER_STUB_FRAME: 2963 case Translation::SETTER_STUB_FRAME:
2993 // Peeled off before getting here. 2964 // Peeled off before getting here.
2994 break; 2965 break;
2995 2966
2996 case Translation::DUPLICATED_OBJECT: { 2967 case Translation::DUPLICATED_OBJECT:
2997 return SlotRef::NewDuplicateObject(iterator->Next());
2998 }
2999
3000 case Translation::ARGUMENTS_OBJECT: 2968 case Translation::ARGUMENTS_OBJECT:
2969 case Translation::CAPTURED_OBJECT:
3001 // This can be only emitted for local slots not for argument slots. 2970 // This can be only emitted for local slots not for argument slots.
3002 break; 2971 break;
3003 2972
3004 case Translation::CAPTURED_OBJECT: {
3005 return SlotRef::NewDeferredObject(iterator->Next());
3006 }
3007
3008 case Translation::REGISTER: 2973 case Translation::REGISTER:
3009 case Translation::INT32_REGISTER: 2974 case Translation::INT32_REGISTER:
3010 case Translation::UINT32_REGISTER: 2975 case Translation::UINT32_REGISTER:
3011 case Translation::DOUBLE_REGISTER: 2976 case Translation::DOUBLE_REGISTER:
3012 // We are at safepoint which corresponds to call. All registers are 2977 // We are at safepoint which corresponds to call. All registers are
3013 // saved by caller so there would be no live registers at this 2978 // saved by caller so there would be no live registers at this
3014 // point. Thus these translation commands should not be used. 2979 // point. Thus these translation commands should not be used.
3015 break; 2980 break;
3016 2981
3017 case Translation::STACK_SLOT: { 2982 case Translation::STACK_SLOT: {
(...skipping 29 matching lines...) Expand all
3047 case Translation::COMPILED_STUB_FRAME: 3012 case Translation::COMPILED_STUB_FRAME:
3048 UNREACHABLE(); 3013 UNREACHABLE();
3049 break; 3014 break;
3050 } 3015 }
3051 3016
3052 UNREACHABLE(); 3017 UNREACHABLE();
3053 return SlotRef(); 3018 return SlotRef();
3054 } 3019 }
3055 3020
3056 3021
3057 SlotRefValueBuilder::SlotRefValueBuilder(JavaScriptFrame* frame, 3022 void SlotRef::ComputeSlotsForArguments(Vector<SlotRef>* args_slots,
3058 int inlined_jsframe_index, 3023 TranslationIterator* it,
3059 int formal_parameter_count) 3024 DeoptimizationInputData* data,
3060 : current_slot_(0), args_length_(-1), first_slot_index_(-1) { 3025 JavaScriptFrame* frame) {
3026 // Process the translation commands for the arguments.
3027
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) {
3061 DisallowHeapAllocation no_gc; 3043 DisallowHeapAllocation no_gc;
3062
3063 int deopt_index = Safepoint::kNoDeoptimizationIndex; 3044 int deopt_index = Safepoint::kNoDeoptimizationIndex;
3064 DeoptimizationInputData* data = 3045 DeoptimizationInputData* data =
3065 static_cast<OptimizedFrame*>(frame)->GetDeoptimizationData(&deopt_index); 3046 static_cast<OptimizedFrame*>(frame)->GetDeoptimizationData(&deopt_index);
3066 TranslationIterator it(data->TranslationByteArray(), 3047 TranslationIterator it(data->TranslationByteArray(),
3067 data->TranslationIndex(deopt_index)->value()); 3048 data->TranslationIndex(deopt_index)->value());
3068 Translation::Opcode opcode = static_cast<Translation::Opcode>(it.Next()); 3049 Translation::Opcode opcode = static_cast<Translation::Opcode>(it.Next());
3069 ASSERT(opcode == Translation::BEGIN); 3050 ASSERT(opcode == Translation::BEGIN);
3070 it.Next(); // Drop frame count. 3051 it.Next(); // Drop frame count.
3071
3072 stack_frame_id_ = frame->fp();
3073
3074 int jsframe_count = it.Next(); 3052 int jsframe_count = it.Next();
3075 USE(jsframe_count); 3053 USE(jsframe_count);
3076 ASSERT(jsframe_count > inlined_jsframe_index); 3054 ASSERT(jsframe_count > inlined_jsframe_index);
3077 int jsframes_to_skip = inlined_jsframe_index; 3055 int jsframes_to_skip = inlined_jsframe_index;
3078 int number_of_slots = -1; // Number of slots inside our frame (yet unknown) 3056 while (true) {
3079 bool should_deopt = false;
3080 while (number_of_slots != 0) {
3081 opcode = static_cast<Translation::Opcode>(it.Next()); 3057 opcode = static_cast<Translation::Opcode>(it.Next());
3082 bool processed = false;
3083 if (opcode == Translation::ARGUMENTS_ADAPTOR_FRAME) { 3058 if (opcode == Translation::ARGUMENTS_ADAPTOR_FRAME) {
3084 if (jsframes_to_skip == 0) { 3059 if (jsframes_to_skip == 0) {
3085 ASSERT(Translation::NumberOfOperandsFor(opcode) == 2); 3060 ASSERT(Translation::NumberOfOperandsFor(opcode) == 2);
3086 3061
3087 it.Skip(1); // literal id 3062 it.Skip(1); // literal id
3088 int height = it.Next(); 3063 int height = it.Next();
3089 3064
3090 // Skip the translation command for the receiver.
3091 it.Skip(Translation::NumberOfOperandsFor(
3092 static_cast<Translation::Opcode>(it.Next())));
3093
3094 // We reached the arguments adaptor frame corresponding to the 3065 // We reached the arguments adaptor frame corresponding to the
3095 // inlined function in question. Number of arguments is height - 1. 3066 // inlined function in question. Number of arguments is height - 1.
3096 first_slot_index_ = slot_refs_.length(); 3067 Vector<SlotRef> args_slots =
3097 args_length_ = height - 1; 3068 Vector<SlotRef>::New(height - 1); // Minus receiver.
3098 number_of_slots = height - 1; 3069 ComputeSlotsForArguments(&args_slots, &it, data, frame);
3099 processed = true; 3070 return args_slots;
3100 } 3071 }
3101 } else if (opcode == Translation::JS_FRAME) { 3072 } else if (opcode == Translation::JS_FRAME) {
3102 if (jsframes_to_skip == 0) { 3073 if (jsframes_to_skip == 0) {
3103 // Skip over operands to advance to the next opcode. 3074 // Skip over operands to advance to the next opcode.
3104 it.Skip(Translation::NumberOfOperandsFor(opcode)); 3075 it.Skip(Translation::NumberOfOperandsFor(opcode));
3105 3076
3106 // Skip the translation command for the receiver.
3107 it.Skip(Translation::NumberOfOperandsFor(
3108 static_cast<Translation::Opcode>(it.Next())));
3109
3110 // We reached the frame corresponding to the inlined function 3077 // We reached the frame corresponding to the inlined function
3111 // in question. Process the translation commands for the 3078 // in question. Process the translation commands for the
3112 // arguments. Number of arguments is equal to the number of 3079 // arguments. Number of arguments is equal to the number of
3113 // format parameter count. 3080 // format parameter count.
3114 first_slot_index_ = slot_refs_.length(); 3081 Vector<SlotRef> args_slots =
3115 args_length_ = formal_parameter_count; 3082 Vector<SlotRef>::New(formal_parameter_count);
3116 number_of_slots = formal_parameter_count; 3083 ComputeSlotsForArguments(&args_slots, &it, data, frame);
3117 processed = true; 3084 return args_slots;
3118 } 3085 }
3119 jsframes_to_skip--; 3086 jsframes_to_skip--;
3120 } else if (opcode != Translation::BEGIN &&
3121 opcode != Translation::CONSTRUCT_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 } 3087 }
3166 3088
3167 case UINT32: { 3089 // Skip over operands to advance to the next opcode.
3168 uint32_t value = Memory::uint32_at(addr_); 3090 it.Skip(Translation::NumberOfOperandsFor(opcode));
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;
3321 } 3091 }
3322 3092
3323 UNREACHABLE(); 3093 UNREACHABLE();
3324 return Handle<Object>::null(); 3094 return Vector<SlotRef>();
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;
3420 } 3095 }
3421 3096
3422 #ifdef ENABLE_DEBUGGER_SUPPORT 3097 #ifdef ENABLE_DEBUGGER_SUPPORT
3423 3098
3424 DeoptimizedFrameInfo::DeoptimizedFrameInfo(Deoptimizer* deoptimizer, 3099 DeoptimizedFrameInfo::DeoptimizedFrameInfo(Deoptimizer* deoptimizer,
3425 int frame_index, 3100 int frame_index,
3426 bool has_arguments_adaptor, 3101 bool has_arguments_adaptor,
3427 bool has_construct_stub) { 3102 bool has_construct_stub) {
3428 FrameDescription* output_frame = deoptimizer->output_[frame_index]; 3103 FrameDescription* output_frame = deoptimizer->output_[frame_index];
3429 function_ = output_frame->GetFunction(); 3104 function_ = output_frame->GetFunction();
(...skipping 30 matching lines...) Expand all
3460 3135
3461 void DeoptimizedFrameInfo::Iterate(ObjectVisitor* v) { 3136 void DeoptimizedFrameInfo::Iterate(ObjectVisitor* v) {
3462 v->VisitPointer(BitCast<Object**>(&function_)); 3137 v->VisitPointer(BitCast<Object**>(&function_));
3463 v->VisitPointers(parameters_, parameters_ + parameters_count_); 3138 v->VisitPointers(parameters_, parameters_ + parameters_count_);
3464 v->VisitPointers(expression_stack_, expression_stack_ + expression_count_); 3139 v->VisitPointers(expression_stack_, expression_stack_ + expression_count_);
3465 } 3140 }
3466 3141
3467 #endif // ENABLE_DEBUGGER_SUPPORT 3142 #endif // ENABLE_DEBUGGER_SUPPORT
3468 3143
3469 } } // namespace v8::internal 3144 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/deoptimizer.h ('k') | src/heap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698