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

Side by Side Diff: src/deoptimizer.cc

Issue 103243005: Captured arguments object materialization (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Formatting fix Created 6 years, 11 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/isolate.h » ('j') | src/isolate.h » ('J')
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 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 Object* element = context->OptimizedCodeListHead(); 467 Object* element = context->OptimizedCodeListHead();
468 while (!element->IsUndefined()) { 468 while (!element->IsUndefined()) {
469 Code* code = Code::cast(element); 469 Code* code = Code::cast(element);
470 ASSERT(code->kind() == Code::OPTIMIZED_FUNCTION); 470 ASSERT(code->kind() == Code::OPTIMIZED_FUNCTION);
471 code->set_marked_for_deoptimization(true); 471 code->set_marked_for_deoptimization(true);
472 element = code->next_code_link(); 472 element = code->next_code_link();
473 } 473 }
474 } 474 }
475 475
476 476
477 void Deoptimizer::DeoptimizeFunctionList(List<JSFunction*>* functions) {
478 bool do_deopt = false;
479 for (int i = 0; i < functions->length(); i++) {
480 Code* code = (*functions)[i]->code();
481 if (code->kind() == Code::OPTIMIZED_FUNCTION) {
482 // Mark the code for deoptimization and unlink any functions that also
483 // refer to that code. The code cannot be shared across native contexts,
484 // so we only need to search one.
485 code->set_marked_for_deoptimization(true);
486 do_deopt = true;
487 }
488 }
489 if (do_deopt) {
490 DeoptimizeMarkedCodeForContext(
491 (*functions)[0]->context()->native_context());
Michael Starzinger 2014/01/14 09:50:18 This seems to assume that all functions in the lis
Jarin 2014/01/27 15:40:58 Done.
492 }
493 }
494
495
477 void Deoptimizer::DeoptimizeFunction(JSFunction* function) { 496 void Deoptimizer::DeoptimizeFunction(JSFunction* function) {
478 Code* code = function->code(); 497 Code* code = function->code();
479 if (code->kind() == Code::OPTIMIZED_FUNCTION) { 498 if (code->kind() == Code::OPTIMIZED_FUNCTION) {
480 // Mark the code for deoptimization and unlink any functions that also 499 // Mark the code for deoptimization and unlink any functions that also
481 // refer to that code. The code cannot be shared across native contexts, 500 // refer to that code. The code cannot be shared across native contexts,
482 // so we only need to search one. 501 // so we only need to search one.
483 code->set_marked_for_deoptimization(true); 502 code->set_marked_for_deoptimization(true);
484 DeoptimizeMarkedCodeForContext(function->context()->native_context()); 503 DeoptimizeMarkedCodeForContext(function->context()->native_context());
485 } 504 }
486 } 505 }
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 // descriptions. 785 // descriptions.
767 int count = iterator.Next(); 786 int count = iterator.Next();
768 iterator.Next(); // Drop JS frames count. 787 iterator.Next(); // Drop JS frames count.
769 ASSERT(output_ == NULL); 788 ASSERT(output_ == NULL);
770 output_ = new FrameDescription*[count]; 789 output_ = new FrameDescription*[count];
771 for (int i = 0; i < count; ++i) { 790 for (int i = 0; i < count; ++i) {
772 output_[i] = NULL; 791 output_[i] = NULL;
773 } 792 }
774 output_count_ = count; 793 output_count_ = count;
775 794
795 Register fp_reg = JavaScriptFrame::fp_register();
796 stack_fp_ = reinterpret_cast<Address>(
797 input_->GetRegister(fp_reg.code()) +
798 has_alignment_padding_ * kPointerSize);
799
776 // Translate each output frame. 800 // Translate each output frame.
777 for (int i = 0; i < count; ++i) { 801 for (int i = 0; i < count; ++i) {
778 // Read the ast node id, function, and frame height for this output frame. 802 // Read the ast node id, function, and frame height for this output frame.
779 Translation::Opcode opcode = 803 Translation::Opcode opcode =
780 static_cast<Translation::Opcode>(iterator.Next()); 804 static_cast<Translation::Opcode>(iterator.Next());
781 switch (opcode) { 805 switch (opcode) {
782 case Translation::JS_FRAME: 806 case Translation::JS_FRAME:
783 DoComputeJSFrame(&iterator, i); 807 DoComputeJSFrame(&iterator, i);
784 jsframe_count_++; 808 jsframe_count_++;
785 break; 809 break;
(...skipping 984 matching lines...) Expand 10 before | Expand all | Expand 10 after
1770 // Dispatch on the instance type of the object to be materialized. 1794 // Dispatch on the instance type of the object to be materialized.
1771 // We also need to make sure that the representation of all fields 1795 // 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. 1796 // in the given object are general enough to hold a tagged value.
1773 Handle<Map> map = Map::GeneralizeAllFieldRepresentations( 1797 Handle<Map> map = Map::GeneralizeAllFieldRepresentations(
1774 Handle<Map>::cast(MaterializeNextValue()), Representation::Tagged()); 1798 Handle<Map>::cast(MaterializeNextValue()), Representation::Tagged());
1775 switch (map->instance_type()) { 1799 switch (map->instance_type()) {
1776 case HEAP_NUMBER_TYPE: { 1800 case HEAP_NUMBER_TYPE: {
1777 // Reuse the HeapNumber value directly as it is already properly 1801 // Reuse the HeapNumber value directly as it is already properly
1778 // tagged and skip materializing the HeapNumber explicitly. 1802 // tagged and skip materializing the HeapNumber explicitly.
1779 Handle<Object> object = MaterializeNextValue(); 1803 Handle<Object> object = MaterializeNextValue();
1780 materialized_objects_->Add(object); 1804 if (object_index < prev_materialized_count_) {
1805 materialized_objects_->Add(Handle<Object>(
1806 previously_materialized_objects_->get(object_index), isolate_));
1807 } else {
1808 materialized_objects_->Add(object);
1809 }
1781 materialization_value_index_ += kDoubleSize / kPointerSize - 1; 1810 materialization_value_index_ += kDoubleSize / kPointerSize - 1;
1782 break; 1811 break;
1783 } 1812 }
1784 case JS_OBJECT_TYPE: { 1813 case JS_OBJECT_TYPE: {
1785 Handle<JSObject> object = 1814 Handle<JSObject> object =
1786 isolate_->factory()->NewJSObjectFromMap(map, NOT_TENURED, false); 1815 isolate_->factory()->NewJSObjectFromMap(map, NOT_TENURED, false);
1787 materialized_objects_->Add(object); 1816 if (object_index < prev_materialized_count_) {
1817 materialized_objects_->Add(Handle<Object>(
1818 previously_materialized_objects_->get(object_index), isolate_));
1819 } else {
1820 materialized_objects_->Add(object);
1821 }
1788 Handle<Object> properties = MaterializeNextValue(); 1822 Handle<Object> properties = MaterializeNextValue();
1789 Handle<Object> elements = MaterializeNextValue(); 1823 Handle<Object> elements = MaterializeNextValue();
1790 object->set_properties(FixedArray::cast(*properties)); 1824 object->set_properties(FixedArray::cast(*properties));
1791 object->set_elements(FixedArrayBase::cast(*elements)); 1825 object->set_elements(FixedArrayBase::cast(*elements));
1792 for (int i = 0; i < length - 3; ++i) { 1826 for (int i = 0; i < length - 3; ++i) {
1793 Handle<Object> value = MaterializeNextValue(); 1827 Handle<Object> value = MaterializeNextValue();
1794 object->FastPropertyAtPut(i, *value); 1828 object->FastPropertyAtPut(i, *value);
1795 } 1829 }
1796 break; 1830 break;
1797 } 1831 }
1798 case JS_ARRAY_TYPE: { 1832 case JS_ARRAY_TYPE: {
1799 Handle<JSArray> object = 1833 Handle<JSArray> object =
1800 isolate_->factory()->NewJSArray(0, map->elements_kind()); 1834 isolate_->factory()->NewJSArray(0, map->elements_kind());
1801 materialized_objects_->Add(object); 1835 if (object_index < prev_materialized_count_) {
1836 materialized_objects_->Add(Handle<Object>(
1837 previously_materialized_objects_->get(object_index), isolate_));
1838 } else {
1839 materialized_objects_->Add(object);
1840 }
1802 Handle<Object> properties = MaterializeNextValue(); 1841 Handle<Object> properties = MaterializeNextValue();
1803 Handle<Object> elements = MaterializeNextValue(); 1842 Handle<Object> elements = MaterializeNextValue();
1804 Handle<Object> length = MaterializeNextValue(); 1843 Handle<Object> length = MaterializeNextValue();
1805 object->set_properties(FixedArray::cast(*properties)); 1844 object->set_properties(FixedArray::cast(*properties));
1806 object->set_elements(FixedArrayBase::cast(*elements)); 1845 object->set_elements(FixedArrayBase::cast(*elements));
1807 object->set_length(*length); 1846 object->set_length(*length);
1808 break; 1847 break;
1809 } 1848 }
1810 default: 1849 default:
1811 PrintF(stderr, 1850 PrintF(stderr,
(...skipping 12 matching lines...) Expand all
1824 if (*value == isolate_->heap()->arguments_marker()) { 1863 if (*value == isolate_->heap()->arguments_marker()) {
1825 value = MaterializeNextHeapObject(); 1864 value = MaterializeNextHeapObject();
1826 } 1865 }
1827 return value; 1866 return value;
1828 } 1867 }
1829 1868
1830 1869
1831 void Deoptimizer::MaterializeHeapObjects(JavaScriptFrameIterator* it) { 1870 void Deoptimizer::MaterializeHeapObjects(JavaScriptFrameIterator* it) {
1832 ASSERT_NE(DEBUGGER, bailout_type_); 1871 ASSERT_NE(DEBUGGER, bailout_type_);
1833 1872
1873 MaterializedObjectStore* materialized_store =
1874 isolate_->materialized_object_store();
1875 previously_materialized_objects_ = materialized_store->Get(stack_fp_);
1876 prev_materialized_count_ = previously_materialized_objects_.is_null() ?
1877 0 : previously_materialized_objects_->length();
1878
1834 // Walk all JavaScript output frames with the given frame iterator. 1879 // Walk all JavaScript output frames with the given frame iterator.
1835 for (int frame_index = 0; frame_index < jsframe_count(); ++frame_index) { 1880 for (int frame_index = 0; frame_index < jsframe_count(); ++frame_index) {
1836 if (frame_index != 0) it->Advance(); 1881 if (frame_index != 0) it->Advance();
1837 JavaScriptFrame* frame = it->frame(); 1882 JavaScriptFrame* frame = it->frame();
1838 jsframe_functions_.Add(handle(frame->function(), isolate_)); 1883 jsframe_functions_.Add(handle(frame->function(), isolate_));
1839 jsframe_has_adapted_arguments_.Add(frame->has_adapted_arguments()); 1884 jsframe_has_adapted_arguments_.Add(frame->has_adapted_arguments());
1840 } 1885 }
1841 1886
1842 // Handlify all tagged object values before triggering any allocation. 1887 // Handlify all tagged object values before triggering any allocation.
1843 List<Handle<Object> > values(deferred_objects_tagged_values_.length()); 1888 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())); 1958 reinterpret_cast<void*>(descriptor.slot_address()));
1914 } 1959 }
1915 object->ShortPrint(trace_scope_->file()); 1960 object->ShortPrint(trace_scope_->file());
1916 PrintF(trace_scope_->file(), "\n"); 1961 PrintF(trace_scope_->file(), "\n");
1917 } 1962 }
1918 } 1963 }
1919 1964
1920 ASSERT(materialization_object_index_ == materialized_objects_->length()); 1965 ASSERT(materialization_object_index_ == materialized_objects_->length());
1921 ASSERT(materialization_value_index_ == materialized_values_->length()); 1966 ASSERT(materialization_value_index_ == materialized_values_->length());
1922 } 1967 }
1968
1969 if (prev_materialized_count_ > 0) {
1970 materialized_store->Remove(stack_fp_);
1971 }
1923 } 1972 }
1924 1973
1925 1974
1926 #ifdef ENABLE_DEBUGGER_SUPPORT 1975 #ifdef ENABLE_DEBUGGER_SUPPORT
1927 void Deoptimizer::MaterializeHeapNumbersForDebuggerInspectableFrame( 1976 void Deoptimizer::MaterializeHeapNumbersForDebuggerInspectableFrame(
1928 Address parameters_top, 1977 Address parameters_top,
1929 uint32_t parameters_size, 1978 uint32_t parameters_size,
1930 Address expressions_top, 1979 Address expressions_top,
1931 uint32_t expressions_size, 1980 uint32_t expressions_size,
1932 DeoptimizedFrameInfo* info) { 1981 DeoptimizedFrameInfo* info) {
(...skipping 1008 matching lines...) Expand 10 before | Expand all | Expand 10 after
2941 UNREACHABLE(); 2990 UNREACHABLE();
2942 return ""; 2991 return "";
2943 } 2992 }
2944 2993
2945 #endif 2994 #endif
2946 2995
2947 2996
2948 // We can't intermix stack decoding and allocations because 2997 // We can't intermix stack decoding and allocations because
2949 // deoptimization infrastracture is not GC safe. 2998 // deoptimization infrastracture is not GC safe.
2950 // Thus we build a temporary structure in malloced space. 2999 // Thus we build a temporary structure in malloced space.
2951 SlotRef SlotRef::ComputeSlotForNextArgument(TranslationIterator* iterator, 3000 SlotRef SlotRefValueBuilder::ComputeSlotForNextArgument(
2952 DeoptimizationInputData* data, 3001 Translation::Opcode opcode,
2953 JavaScriptFrame* frame) { 3002 TranslationIterator* iterator,
2954 Translation::Opcode opcode = 3003 DeoptimizationInputData* data,
2955 static_cast<Translation::Opcode>(iterator->Next()); 3004 JavaScriptFrame* frame) {
2956
2957 switch (opcode) { 3005 switch (opcode) {
2958 case Translation::BEGIN: 3006 case Translation::BEGIN:
2959 case Translation::JS_FRAME: 3007 case Translation::JS_FRAME:
2960 case Translation::ARGUMENTS_ADAPTOR_FRAME: 3008 case Translation::ARGUMENTS_ADAPTOR_FRAME:
2961 case Translation::CONSTRUCT_STUB_FRAME: 3009 case Translation::CONSTRUCT_STUB_FRAME:
2962 case Translation::GETTER_STUB_FRAME: 3010 case Translation::GETTER_STUB_FRAME:
2963 case Translation::SETTER_STUB_FRAME: 3011 case Translation::SETTER_STUB_FRAME:
2964 // Peeled off before getting here. 3012 // Peeled off before getting here.
2965 break; 3013 break;
2966 3014
2967 case Translation::DUPLICATED_OBJECT: 3015 case Translation::DUPLICATED_OBJECT: {
3016 return SlotRef::NewDuplicateObject(iterator->Next());
3017 }
3018
2968 case Translation::ARGUMENTS_OBJECT: 3019 case Translation::ARGUMENTS_OBJECT:
2969 case Translation::CAPTURED_OBJECT:
2970 // This can be only emitted for local slots not for argument slots. 3020 // This can be only emitted for local slots not for argument slots.
2971 break; 3021 break;
2972 3022
3023 case Translation::CAPTURED_OBJECT: {
3024 return SlotRef::NewDeferredObject(iterator->Next());
3025 }
3026
2973 case Translation::REGISTER: 3027 case Translation::REGISTER:
2974 case Translation::INT32_REGISTER: 3028 case Translation::INT32_REGISTER:
2975 case Translation::UINT32_REGISTER: 3029 case Translation::UINT32_REGISTER:
2976 case Translation::DOUBLE_REGISTER: 3030 case Translation::DOUBLE_REGISTER:
2977 // We are at safepoint which corresponds to call. All registers are 3031 // We are at safepoint which corresponds to call. All registers are
2978 // saved by caller so there would be no live registers at this 3032 // saved by caller so there would be no live registers at this
2979 // point. Thus these translation commands should not be used. 3033 // point. Thus these translation commands should not be used.
2980 break; 3034 break;
2981 3035
2982 case Translation::STACK_SLOT: { 3036 case Translation::STACK_SLOT: {
(...skipping 29 matching lines...) Expand all
3012 case Translation::COMPILED_STUB_FRAME: 3066 case Translation::COMPILED_STUB_FRAME:
3013 UNREACHABLE(); 3067 UNREACHABLE();
3014 break; 3068 break;
3015 } 3069 }
3016 3070
3017 UNREACHABLE(); 3071 UNREACHABLE();
3018 return SlotRef(); 3072 return SlotRef();
3019 } 3073 }
3020 3074
3021 3075
3022 void SlotRef::ComputeSlotsForArguments(Vector<SlotRef>* args_slots, 3076 SlotRefValueBuilder::SlotRefValueBuilder(JavaScriptFrame* frame,
3023 TranslationIterator* it, 3077 int inlined_jsframe_index,
3024 DeoptimizationInputData* data, 3078 int formal_parameter_count)
3025 JavaScriptFrame* frame) { 3079 : current_slot_(0), args_length_(-1), first_slot_index_(-1) {
3026 // Process the translation commands for the arguments. 3080 DisallowHeapAllocation no_gc;
3027 3081
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; 3082 int deopt_index = Safepoint::kNoDeoptimizationIndex;
3045 DeoptimizationInputData* data = 3083 DeoptimizationInputData* data =
3046 static_cast<OptimizedFrame*>(frame)->GetDeoptimizationData(&deopt_index); 3084 static_cast<OptimizedFrame*>(frame)->GetDeoptimizationData(&deopt_index);
3047 TranslationIterator it(data->TranslationByteArray(), 3085 TranslationIterator it(data->TranslationByteArray(),
3048 data->TranslationIndex(deopt_index)->value()); 3086 data->TranslationIndex(deopt_index)->value());
3049 Translation::Opcode opcode = static_cast<Translation::Opcode>(it.Next()); 3087 Translation::Opcode opcode = static_cast<Translation::Opcode>(it.Next());
3050 ASSERT(opcode == Translation::BEGIN); 3088 ASSERT(opcode == Translation::BEGIN);
3051 it.Next(); // Drop frame count. 3089 it.Next(); // Drop frame count.
3090
3091 stack_frame_id_ = frame->fp();
3092
3052 int jsframe_count = it.Next(); 3093 int jsframe_count = it.Next();
3053 USE(jsframe_count); 3094 USE(jsframe_count);
3054 ASSERT(jsframe_count > inlined_jsframe_index); 3095 ASSERT(jsframe_count > inlined_jsframe_index);
3055 int jsframes_to_skip = inlined_jsframe_index; 3096 int jsframes_to_skip = inlined_jsframe_index;
3056 while (true) { 3097 int number_of_slots = -1; // Number of slots inside our frame (yet unknown)
3098 bool should_deopt = false;
3099 while (number_of_slots != 0) {
3057 opcode = static_cast<Translation::Opcode>(it.Next()); 3100 opcode = static_cast<Translation::Opcode>(it.Next());
3101 bool processed = false;
3058 if (opcode == Translation::ARGUMENTS_ADAPTOR_FRAME) { 3102 if (opcode == Translation::ARGUMENTS_ADAPTOR_FRAME) {
3059 if (jsframes_to_skip == 0) { 3103 if (jsframes_to_skip == 0) {
3060 ASSERT(Translation::NumberOfOperandsFor(opcode) == 2); 3104 ASSERT(Translation::NumberOfOperandsFor(opcode) == 2);
3061 3105
3062 it.Skip(1); // literal id 3106 it.Skip(1); // literal id
3063 int height = it.Next(); 3107 int height = it.Next();
3064 3108
3109 // Skip the translation command for the receiver.
3110 it.Skip(Translation::NumberOfOperandsFor(
3111 static_cast<Translation::Opcode>(it.Next())));
3112
3065 // We reached the arguments adaptor frame corresponding to the 3113 // We reached the arguments adaptor frame corresponding to the
3066 // inlined function in question. Number of arguments is height - 1. 3114 // inlined function in question. Number of arguments is height - 1.
3067 Vector<SlotRef> args_slots = 3115 first_slot_index_ = slot_refs_.length();
3068 Vector<SlotRef>::New(height - 1); // Minus receiver. 3116 args_length_ = height - 1;
3069 ComputeSlotsForArguments(&args_slots, &it, data, frame); 3117 number_of_slots = height - 1;
3070 return args_slots; 3118 processed = true;
3071 } 3119 }
3072 } else if (opcode == Translation::JS_FRAME) { 3120 } else if (opcode == Translation::JS_FRAME) {
3073 if (jsframes_to_skip == 0) { 3121 if (jsframes_to_skip == 0) {
3074 // Skip over operands to advance to the next opcode. 3122 // Skip over operands to advance to the next opcode.
3075 it.Skip(Translation::NumberOfOperandsFor(opcode)); 3123 it.Skip(Translation::NumberOfOperandsFor(opcode));
3076 3124
3125 // Skip the translation command for the receiver.
3126 it.Skip(Translation::NumberOfOperandsFor(
3127 static_cast<Translation::Opcode>(it.Next())));
3128
3077 // We reached the frame corresponding to the inlined function 3129 // We reached the frame corresponding to the inlined function
3078 // in question. Process the translation commands for the 3130 // in question. Process the translation commands for the
3079 // arguments. Number of arguments is equal to the number of 3131 // arguments. Number of arguments is equal to the number of
3080 // format parameter count. 3132 // format parameter count.
3081 Vector<SlotRef> args_slots = 3133 first_slot_index_ = slot_refs_.length();
3082 Vector<SlotRef>::New(formal_parameter_count); 3134 args_length_ = formal_parameter_count;
3083 ComputeSlotsForArguments(&args_slots, &it, data, frame); 3135 number_of_slots = formal_parameter_count;
3084 return args_slots; 3136 processed = true;
3085 } 3137 }
3086 jsframes_to_skip--; 3138 jsframes_to_skip--;
3087 } 3139 } else if (opcode != Translation::BEGIN &&
3088 3140 opcode != Translation::CONSTRUCT_STUB_FRAME) {
3089 // Skip over operands to advance to the next opcode. 3141 slot_refs_.Add(ComputeSlotForNextArgument(opcode, &it, data, frame));
3090 it.Skip(Translation::NumberOfOperandsFor(opcode)); 3142
3143 if (first_slot_index_ >= 0) {
3144 // We have found the beginning of our frame -> make sure we count
3145 // the nested slots of captured objects
3146 number_of_slots--;
3147 SlotRef& slot = slot_refs_.last();
3148 if (slot.Representation() == SlotRef::DEFERRED_OBJECT) {
3149 number_of_slots += slot.DeferredObjectLength();
3150 }
3151 if (slot.Representation() == SlotRef::DEFERRED_OBJECT ||
3152 slot.Representation() == SlotRef::DUPLICATE_OBJECT) {
3153 should_deopt = true;
3154 }
3155 }
3156
3157 processed = true;
3158 }
3159 if (!processed) {
3160 // Skip over operands to advance to the next opcode.
3161 it.Skip(Translation::NumberOfOperandsFor(opcode));
3162 }
3163 }
3164 if (should_deopt) {
3165 List<JSFunction*> functions(2);
3166 frame->GetFunctions(&functions);
3167 Deoptimizer::DeoptimizeFunctionList(&functions);
3168 }
3169 }
3170
3171
3172 Handle<Object> SlotRef::GetValue(Isolate* isolate) {
3173 switch (representation_) {
3174 case TAGGED:
3175 return Handle<Object>(Memory::Object_at(addr_), isolate);
3176
3177 case INT32: {
3178 int value = Memory::int32_at(addr_);
3179 if (Smi::IsValid(value)) {
3180 return Handle<Object>(Smi::FromInt(value), isolate);
3181 } else {
3182 return isolate->factory()->NewNumberFromInt(value);
3183 }
3184 }
3185
3186 case UINT32: {
3187 uint32_t value = Memory::uint32_at(addr_);
3188 if (value <= static_cast<uint32_t>(Smi::kMaxValue)) {
3189 return Handle<Object>(Smi::FromInt(static_cast<int>(value)), isolate);
3190 } else {
3191 return isolate->factory()->NewNumber(static_cast<double>(value));
3192 }
3193 }
3194
3195 case DOUBLE: {
3196 double value = read_double_value(addr_);
3197 return isolate->factory()->NewNumber(value);
3198 }
3199
3200 case LITERAL:
3201 return literal_;
3202
3203 default:
3204 UNREACHABLE();
3205 return Handle<Object>::null();
3206 }
3207 }
3208
3209
3210 void SlotRefValueBuilder::Prepare(Isolate* isolate) {
3211 MaterializedObjectStore* materialized_store =
3212 isolate->materialized_object_store();
3213 previously_materialized_objects_ = materialized_store->Get(stack_frame_id_);
3214 prev_materialized_count_ = previously_materialized_objects_.is_null() ?
3215 0 : previously_materialized_objects_->length();
3216
3217 // Now skip the initial segment (we need to get over the segment
3218 // to recover the captured objects in case we have duplicate
3219 // objects)
3220 while (current_slot_ < first_slot_index_) {
3221 GetNext(isolate, 0);
3222 }
3223 ASSERT(current_slot_ == first_slot_index_);
3224 }
3225
3226
3227 Handle<Object> SlotRefValueBuilder::GetPreviouslyMaterialized(
3228 Isolate* isolate, int length) {
3229 int object_index = materialized_objects_.length();
3230 Handle<Object> return_value = Handle<Object>(
3231 previously_materialized_objects_->get(object_index), isolate);
3232 materialized_objects_.Add(return_value);
3233
3234 // Now need to skip all nested objects (and possibly read them from
3235 // the materialization store, too)
3236 for (int i = 0; i < length; i++) {
3237 SlotRef& slot = slot_refs_[current_slot_];
3238 current_slot_++;
3239
3240 // For nested deferred objects, we need to read its properties
3241 if (slot.Representation() == SlotRef::DEFERRED_OBJECT) {
3242 length += slot.DeferredObjectLength();
3243 }
3244
3245 // For nested deferred and duplicate objects, we need to put them into
3246 // our materialization array
3247 if (slot.Representation() == SlotRef::DEFERRED_OBJECT ||
3248 slot.Representation() == SlotRef::DUPLICATE_OBJECT) {
3249 int nested_object_index = materialized_objects_.length();
3250 Handle<Object> nested_object = Handle<Object>(
3251 previously_materialized_objects_->get(nested_object_index),
3252 isolate);
3253 materialized_objects_.Add(nested_object);
3254 }
3255 }
3256
3257 return return_value;
3258 }
3259
3260
3261 Handle<Object> SlotRefValueBuilder::GetNext(Isolate* isolate, int lvl) {
3262 SlotRef& slot = slot_refs_[current_slot_];
3263 current_slot_++;
3264 switch (slot.Representation()) {
3265 case SlotRef::TAGGED:
3266 case SlotRef::INT32:
3267 case SlotRef::UINT32:
3268 case SlotRef::DOUBLE:
3269 case SlotRef::LITERAL: {
3270 return slot.GetValue(isolate);
3271 }
3272 case SlotRef::DEFERRED_OBJECT: {
3273 int length = slot.DeferredObjectLength();
3274 ASSERT(slot_refs_[current_slot_].Representation() == SlotRef::LITERAL ||
3275 slot_refs_[current_slot_].Representation() == SlotRef::TAGGED);
3276
3277 int object_index = materialized_objects_.length();
3278 if (object_index < prev_materialized_count_) {
3279 return GetPreviouslyMaterialized(isolate, length);
3280 }
3281
3282 Handle<Object> map_object = slot_refs_[current_slot_].GetValue(isolate);
3283 Handle<Map> map = Map::GeneralizeAllFieldRepresentations(
3284 Handle<Map>::cast(map_object), Representation::Tagged());
3285 current_slot_++;
3286 switch (map->instance_type()) {
Michael Starzinger 2014/01/14 09:50:18 It would really be nice if we this duplication (th
Jarin 2014/01/27 15:40:58 Added a TODO for now.
3287 case HEAP_NUMBER_TYPE: {
3288 // Reuse the HeapNumber value directly as it is already properly
3289 // tagged and skip materializing the HeapNumber explicitly.
3290 Handle<Object> object = GetNext(isolate, lvl + 1);
3291 materialized_objects_.Add(object);
3292 return object;
3293 }
3294 case JS_OBJECT_TYPE: {
3295 Handle<JSObject> object =
3296 isolate->factory()->NewJSObjectFromMap(map, NOT_TENURED, false);
3297 materialized_objects_.Add(object);
3298 Handle<Object> properties = GetNext(isolate, lvl + 1);
3299 Handle<Object> elements = GetNext(isolate, lvl + 1);
3300 object->set_properties(FixedArray::cast(*properties));
3301 object->set_elements(FixedArrayBase::cast(*elements));
3302 for (int i = 0; i < length - 3; ++i) {
3303 Handle<Object> value = GetNext(isolate, lvl + 1);
3304 object->FastPropertyAtPut(i, *value);
3305 }
3306 return object;
3307 }
3308 case JS_ARRAY_TYPE: {
3309 Handle<JSArray> object =
3310 isolate->factory()->NewJSArray(0, map->elements_kind());
3311 materialized_objects_.Add(object);
3312 Handle<Object> properties = GetNext(isolate, lvl + 1);
3313 Handle<Object> elements = GetNext(isolate, lvl + 1);
3314 Handle<Object> length = GetNext(isolate, lvl + 1);
3315 object->set_properties(FixedArray::cast(*properties));
3316 object->set_elements(FixedArrayBase::cast(*elements));
3317 object->set_length(*length);
3318 return object;
3319 }
3320 default:
3321 PrintF(stderr,
3322 "[couldn't handle instance type %d]\n", map->instance_type());
3323 UNREACHABLE();
3324 break;
3325 }
3326 UNREACHABLE();
3327 }
3328
3329 case SlotRef::DUPLICATE_OBJECT: {
3330 int object_index = slot.DuplicateObjectId();
3331 Handle<Object> object = materialized_objects_[object_index];
3332 materialized_objects_.Add(object);
3333 return object;
3334 }
3335 default:
3336 UNREACHABLE();
3337 break;
3091 } 3338 }
3092 3339
3093 UNREACHABLE(); 3340 UNREACHABLE();
3094 return Vector<SlotRef>(); 3341 return Handle<Object>::null();
3342 }
3343
3344
3345 void SlotRefValueBuilder::Finish(Isolate* isolate) {
3346 // We should have processed all slot
3347 ASSERT(slot_refs_.length() == current_slot_);
3348
3349 if (materialized_objects_.length() > prev_materialized_count_) {
3350 // We have materialized some new objects, so we have to store them
3351 // to prevent duplicate materialization
3352 Handle<FixedArray> array = isolate->factory()->NewFixedArray(
3353 materialized_objects_.length());
3354 for (int i = 0; i < materialized_objects_.length(); i++) {
3355 array->set(i, *(materialized_objects_.at(i)));
3356 }
3357 isolate->materialized_object_store()->Set(stack_frame_id_, array);
3358 }
3359 }
3360
3361
3362 Handle<FixedArray> MaterializedObjectStore::Get(Address fp) {
3363 int index = StackIdToIndex(fp);
3364 if (index == -1) {
3365 return Handle<FixedArray>::null();
3366 }
3367 Handle<JSArray> array = GetStackEntries();
3368 return Handle<FixedArray>::cast(
3369 JSObject::GetElement(isolate(), array, index));
3370 }
3371
3372
3373 void MaterializedObjectStore::Set(Address fp,
3374 Handle<FixedArray> materialized_objects) {
3375 int index = StackIdToIndex(fp);
3376 if (index == -1) {
3377 index = frame_fps_.length();
3378 frame_fps_.Add(fp);
3379 }
3380 Handle<JSArray> array = GetStackEntries();
3381 JSObject::SetElement(array, index, materialized_objects, NONE, kStrictMode);
Michael Starzinger 2014/01/14 09:50:18 While using a JSArray here to get a "growable arra
Jarin 2014/01/27 15:40:58 Replaced with FixedArrays.
3382 }
3383
3384
3385 void MaterializedObjectStore::Remove(Address fp) {
3386 int index = StackIdToIndex(fp);
3387 ASSERT(index >= 0);
3388
3389 frame_fps_.Remove(index);
3390 Handle<JSArray> array = GetStackEntries();
3391 for (int i = index; i < frame_fps_.length(); i++) {
3392 Handle<Object> element = JSObject::GetElement(isolate(), array, i + 1);
3393 JSObject::SetElement(array, i, element, NONE, kStrictMode);
3394 }
3395 JSObject::SetElement(array, frame_fps_.length(),
3396 Handle<Object>(isolate()->heap()->undefined_value(), isolate()),
3397 NONE, kStrictMode);
3398 }
3399
3400
3401 int MaterializedObjectStore::StackIdToIndex(Address fp) {
3402 for (int i = 0; i < frame_fps_.length(); i++) {
3403 if (frame_fps_[i] == fp) {
3404 return i;
3405 }
3406 }
3407 return -1;
3408 }
3409
3410
3411 Handle<JSArray> MaterializedObjectStore::GetStackEntries() {
3412 if (!initialized_) {
3413 initialized_ = true;
3414 materialized_objects_ =
3415 *(isolate()->factory()->NewJSArray(10,
3416 TERMINAL_FAST_ELEMENTS_KIND,
3417 TENURED));
3418 }
3419 return Handle<JSArray>::cast(
3420 Handle<Object>(materialized_objects_, isolate()));
3095 } 3421 }
3096 3422
3097 #ifdef ENABLE_DEBUGGER_SUPPORT 3423 #ifdef ENABLE_DEBUGGER_SUPPORT
3098 3424
3099 DeoptimizedFrameInfo::DeoptimizedFrameInfo(Deoptimizer* deoptimizer, 3425 DeoptimizedFrameInfo::DeoptimizedFrameInfo(Deoptimizer* deoptimizer,
3100 int frame_index, 3426 int frame_index,
3101 bool has_arguments_adaptor, 3427 bool has_arguments_adaptor,
3102 bool has_construct_stub) { 3428 bool has_construct_stub) {
3103 FrameDescription* output_frame = deoptimizer->output_[frame_index]; 3429 FrameDescription* output_frame = deoptimizer->output_[frame_index];
3104 function_ = output_frame->GetFunction(); 3430 function_ = output_frame->GetFunction();
(...skipping 30 matching lines...) Expand all
3135 3461
3136 void DeoptimizedFrameInfo::Iterate(ObjectVisitor* v) { 3462 void DeoptimizedFrameInfo::Iterate(ObjectVisitor* v) {
3137 v->VisitPointer(BitCast<Object**>(&function_)); 3463 v->VisitPointer(BitCast<Object**>(&function_));
3138 v->VisitPointers(parameters_, parameters_ + parameters_count_); 3464 v->VisitPointers(parameters_, parameters_ + parameters_count_);
3139 v->VisitPointers(expression_stack_, expression_stack_ + expression_count_); 3465 v->VisitPointers(expression_stack_, expression_stack_ + expression_count_);
3140 } 3466 }
3141 3467
3142 #endif // ENABLE_DEBUGGER_SUPPORT 3468 #endif // ENABLE_DEBUGGER_SUPPORT
3143 3469
3144 } } // namespace v8::internal 3470 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/deoptimizer.h ('k') | src/isolate.h » ('j') | src/isolate.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698