OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 // information of a code object to perform lazy deoptimization | 183 // information of a code object to perform lazy deoptimization |
184 // patching. If there is not enough room a new relocation | 184 // patching. If there is not enough room a new relocation |
185 // information object is allocated and comments are added until it | 185 // information object is allocated and comments are added until it |
186 // is big enough. | 186 // is big enough. |
187 static void EnsureRelocSpaceForLazyDeoptimization(Handle<Code> code); | 187 static void EnsureRelocSpaceForLazyDeoptimization(Handle<Code> code); |
188 | 188 |
189 // Deoptimize the function now. Its current optimized code will never be run | 189 // Deoptimize the function now. Its current optimized code will never be run |
190 // again and any activations of the optimized code will get deoptimized when | 190 // again and any activations of the optimized code will get deoptimized when |
191 // execution returns. | 191 // execution returns. |
192 static void DeoptimizeFunction(JSFunction* function); | 192 static void DeoptimizeFunction(JSFunction* function); |
| 193 static void DeoptimizeFunctionList(List<JSFunction*>* functions); |
193 | 194 |
194 // Deoptimize all code in the given isolate. | 195 // Deoptimize all code in the given isolate. |
195 static void DeoptimizeAll(Isolate* isolate); | 196 static void DeoptimizeAll(Isolate* isolate); |
196 | 197 |
197 // Deoptimize code associated with the given global object. | 198 // Deoptimize code associated with the given global object. |
198 static void DeoptimizeGlobalObject(JSObject* object); | 199 static void DeoptimizeGlobalObject(JSObject* object); |
199 | 200 |
200 // Deoptimizes all optimized code that has been previously marked | 201 // Deoptimizes all optimized code that has been previously marked |
201 // (via code->set_marked_for_deoptimization) and unlinks all functions that | 202 // (via code->set_marked_for_deoptimization) and unlinks all functions that |
202 // refer to that code. | 203 // refer to that code. |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 // Array of output frame descriptions. | 429 // Array of output frame descriptions. |
429 FrameDescription** output_; | 430 FrameDescription** output_; |
430 | 431 |
431 // Deferred values to be materialized. | 432 // Deferred values to be materialized. |
432 List<Object*> deferred_objects_tagged_values_; | 433 List<Object*> deferred_objects_tagged_values_; |
433 List<HeapNumberMaterializationDescriptor<int> > | 434 List<HeapNumberMaterializationDescriptor<int> > |
434 deferred_objects_double_values_; | 435 deferred_objects_double_values_; |
435 List<ObjectMaterializationDescriptor> deferred_objects_; | 436 List<ObjectMaterializationDescriptor> deferred_objects_; |
436 List<HeapNumberMaterializationDescriptor<Address> > deferred_heap_numbers_; | 437 List<HeapNumberMaterializationDescriptor<Address> > deferred_heap_numbers_; |
437 | 438 |
| 439 // Key for lookup of previously materialized objects |
| 440 Address stack_fp_; |
| 441 Handle<FixedArray> previously_materialized_objects_; |
| 442 int prev_materialized_count_; |
| 443 |
438 // Output frame information. Only used during heap object materialization. | 444 // Output frame information. Only used during heap object materialization. |
439 List<Handle<JSFunction> > jsframe_functions_; | 445 List<Handle<JSFunction> > jsframe_functions_; |
440 List<bool> jsframe_has_adapted_arguments_; | 446 List<bool> jsframe_has_adapted_arguments_; |
441 | 447 |
442 // Materialized objects. Only used during heap object materialization. | 448 // Materialized objects. Only used during heap object materialization. |
443 List<Handle<Object> >* materialized_values_; | 449 List<Handle<Object> >* materialized_values_; |
444 List<Handle<Object> >* materialized_objects_; | 450 List<Handle<Object> >* materialized_objects_; |
445 int materialization_value_index_; | 451 int materialization_value_index_; |
446 int materialization_object_index_; | 452 int materialization_object_index_; |
447 | 453 |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
776 | 782 |
777 | 783 |
778 class SlotRef BASE_EMBEDDED { | 784 class SlotRef BASE_EMBEDDED { |
779 public: | 785 public: |
780 enum SlotRepresentation { | 786 enum SlotRepresentation { |
781 UNKNOWN, | 787 UNKNOWN, |
782 TAGGED, | 788 TAGGED, |
783 INT32, | 789 INT32, |
784 UINT32, | 790 UINT32, |
785 DOUBLE, | 791 DOUBLE, |
786 LITERAL | 792 LITERAL, |
| 793 DEFERRED_OBJECT, |
| 794 DUPLICATE_OBJECT |
787 }; | 795 }; |
788 | 796 |
789 SlotRef() | 797 SlotRef() |
790 : addr_(NULL), representation_(UNKNOWN) { } | 798 : addr_(NULL), representation_(UNKNOWN) { } |
791 | 799 |
792 SlotRef(Address addr, SlotRepresentation representation) | 800 SlotRef(Address addr, SlotRepresentation representation) |
793 : addr_(addr), representation_(representation) { } | 801 : addr_(addr), representation_(representation) { } |
794 | 802 |
795 SlotRef(Isolate* isolate, Object* literal) | 803 SlotRef(Isolate* isolate, Object* literal) |
796 : literal_(literal, isolate), representation_(LITERAL) { } | 804 : literal_(literal, isolate), representation_(LITERAL) { } |
797 | 805 |
798 Handle<Object> GetValue(Isolate* isolate) { | 806 static SlotRef NewDeferredObject(int length) { |
799 switch (representation_) { | 807 SlotRef slot; |
800 case TAGGED: | 808 slot.representation_ = DEFERRED_OBJECT; |
801 return Handle<Object>(Memory::Object_at(addr_), isolate); | 809 slot.deferred_object_length_ = length; |
802 | 810 return slot; |
803 case INT32: { | |
804 int value = Memory::int32_at(addr_); | |
805 if (Smi::IsValid(value)) { | |
806 return Handle<Object>(Smi::FromInt(value), isolate); | |
807 } else { | |
808 return isolate->factory()->NewNumberFromInt(value); | |
809 } | |
810 } | |
811 | |
812 case UINT32: { | |
813 uint32_t value = Memory::uint32_at(addr_); | |
814 if (value <= static_cast<uint32_t>(Smi::kMaxValue)) { | |
815 return Handle<Object>(Smi::FromInt(static_cast<int>(value)), isolate); | |
816 } else { | |
817 return isolate->factory()->NewNumber(static_cast<double>(value)); | |
818 } | |
819 } | |
820 | |
821 case DOUBLE: { | |
822 double value = read_double_value(addr_); | |
823 return isolate->factory()->NewNumber(value); | |
824 } | |
825 | |
826 case LITERAL: | |
827 return literal_; | |
828 | |
829 default: | |
830 UNREACHABLE(); | |
831 return Handle<Object>::null(); | |
832 } | |
833 } | 811 } |
834 | 812 |
835 static Vector<SlotRef> ComputeSlotMappingForArguments( | 813 SlotRepresentation Representation() { return representation_; } |
836 JavaScriptFrame* frame, | 814 |
837 int inlined_frame_index, | 815 static SlotRef NewDuplicateObject(int id) { |
838 int formal_parameter_count); | 816 SlotRef slot; |
| 817 slot.representation_ = DUPLICATE_OBJECT; |
| 818 slot.duplicate_object_id_ = id; |
| 819 return slot; |
| 820 } |
| 821 |
| 822 int DeferredObjectLength() { return deferred_object_length_; } |
| 823 |
| 824 int DuplicateObjectId() { return duplicate_object_id_; } |
| 825 |
| 826 Handle<Object> GetValue(Isolate* isolate); |
839 | 827 |
840 private: | 828 private: |
841 Address addr_; | 829 Address addr_; |
842 Handle<Object> literal_; | 830 Handle<Object> literal_; |
843 SlotRepresentation representation_; | 831 SlotRepresentation representation_; |
| 832 int deferred_object_length_; |
| 833 int duplicate_object_id_; |
| 834 }; |
| 835 |
| 836 class SlotRefValueBuilder BASE_EMBEDDED { |
| 837 public: |
| 838 SlotRefValueBuilder( |
| 839 JavaScriptFrame* frame, |
| 840 int inlined_frame_index, |
| 841 int formal_parameter_count); |
| 842 |
| 843 void Prepare(Isolate* isolate); |
| 844 Handle<Object> GetNext(Isolate* isolate, int level); |
| 845 void Finish(Isolate* isolate); |
| 846 |
| 847 int args_length() { return args_length_; } |
| 848 |
| 849 private: |
| 850 List<Handle<Object> > materialized_objects_; |
| 851 Handle<FixedArray> previously_materialized_objects_; |
| 852 int prev_materialized_count_; |
| 853 Address stack_frame_id_; |
| 854 List<SlotRef> slot_refs_; |
| 855 int current_slot_; |
| 856 int args_length_; |
| 857 int first_slot_index_; |
| 858 |
| 859 static SlotRef ComputeSlotForNextArgument( |
| 860 Translation::Opcode opcode, |
| 861 TranslationIterator* iterator, |
| 862 DeoptimizationInputData* data, |
| 863 JavaScriptFrame* frame); |
| 864 |
| 865 Handle<Object> GetPreviouslyMaterialized(Isolate* isolate, int length); |
844 | 866 |
845 static Address SlotAddress(JavaScriptFrame* frame, int slot_index) { | 867 static Address SlotAddress(JavaScriptFrame* frame, int slot_index) { |
846 if (slot_index >= 0) { | 868 if (slot_index >= 0) { |
847 const int offset = JavaScriptFrameConstants::kLocal0Offset; | 869 const int offset = JavaScriptFrameConstants::kLocal0Offset; |
848 return frame->fp() + offset - (slot_index * kPointerSize); | 870 return frame->fp() + offset - (slot_index * kPointerSize); |
849 } else { | 871 } else { |
850 const int offset = JavaScriptFrameConstants::kLastParameterOffset; | 872 const int offset = JavaScriptFrameConstants::kLastParameterOffset; |
851 return frame->fp() + offset - ((slot_index + 1) * kPointerSize); | 873 return frame->fp() + offset - ((slot_index + 1) * kPointerSize); |
852 } | 874 } |
853 } | 875 } |
854 | 876 |
855 static SlotRef ComputeSlotForNextArgument(TranslationIterator* iterator, | 877 Handle<Object> GetDeferredObject(Isolate* isolate); |
856 DeoptimizationInputData* data, | 878 }; |
857 JavaScriptFrame* frame); | |
858 | 879 |
859 static void ComputeSlotsForArguments( | 880 class MaterializedObjectStore { |
860 Vector<SlotRef>* args_slots, | 881 public: |
861 TranslationIterator* iterator, | 882 explicit MaterializedObjectStore(Isolate* isolate) |
862 DeoptimizationInputData* data, | 883 : isolate_(isolate), |
863 JavaScriptFrame* frame); | 884 materialized_objects_(NULL), |
| 885 initialized_(false) { |
| 886 } |
| 887 |
| 888 void Iterate(ObjectVisitor* v) { |
| 889 v->VisitPointer(reinterpret_cast<Object**>(&materialized_objects_)); |
| 890 } |
| 891 |
| 892 Handle<FixedArray> Get(Address fp); |
| 893 void Set(Address fp, Handle<FixedArray> materialized_objects); |
| 894 void Remove(Address fp); |
| 895 |
| 896 private: |
| 897 Isolate* isolate() { return isolate_; } |
| 898 Handle<JSArray> GetStackEntries(); |
| 899 |
| 900 int StackIdToIndex(Address fp); |
| 901 |
| 902 Isolate* isolate_; |
| 903 Object* materialized_objects_; |
| 904 bool initialized_; |
| 905 List<Address> frame_fps_; |
864 }; | 906 }; |
865 | 907 |
866 | 908 |
867 #ifdef ENABLE_DEBUGGER_SUPPORT | 909 #ifdef ENABLE_DEBUGGER_SUPPORT |
868 // Class used to represent an unoptimized frame when the debugger | 910 // Class used to represent an unoptimized frame when the debugger |
869 // needs to inspect a frame that is part of an optimized frame. The | 911 // needs to inspect a frame that is part of an optimized frame. The |
870 // internally used FrameDescription objects are not GC safe so for use | 912 // internally used FrameDescription objects are not GC safe so for use |
871 // by the debugger frame information is copied to an object of this type. | 913 // by the debugger frame information is copied to an object of this type. |
872 // Represents parameters in unadapted form so their number might mismatch | 914 // Represents parameters in unadapted form so their number might mismatch |
873 // formal parameter count. | 915 // formal parameter count. |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
936 Object** expression_stack_; | 978 Object** expression_stack_; |
937 int source_position_; | 979 int source_position_; |
938 | 980 |
939 friend class Deoptimizer; | 981 friend class Deoptimizer; |
940 }; | 982 }; |
941 #endif | 983 #endif |
942 | 984 |
943 } } // namespace v8::internal | 985 } } // namespace v8::internal |
944 | 986 |
945 #endif // V8_DEOPTIMIZER_H_ | 987 #endif // V8_DEOPTIMIZER_H_ |
OLD | NEW |