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 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 // Array of output frame descriptions. | 428 // Array of output frame descriptions. |
429 FrameDescription** output_; | 429 FrameDescription** output_; |
430 | 430 |
431 // Deferred values to be materialized. | 431 // Deferred values to be materialized. |
432 List<Object*> deferred_objects_tagged_values_; | 432 List<Object*> deferred_objects_tagged_values_; |
433 List<HeapNumberMaterializationDescriptor<int> > | 433 List<HeapNumberMaterializationDescriptor<int> > |
434 deferred_objects_double_values_; | 434 deferred_objects_double_values_; |
435 List<ObjectMaterializationDescriptor> deferred_objects_; | 435 List<ObjectMaterializationDescriptor> deferred_objects_; |
436 List<HeapNumberMaterializationDescriptor<Address> > deferred_heap_numbers_; | 436 List<HeapNumberMaterializationDescriptor<Address> > deferred_heap_numbers_; |
437 | 437 |
| 438 // Key for lookup of previously materialized objects |
| 439 Address stack_fp_; |
| 440 Handle<FixedArray> previously_materialized_objects_; |
| 441 int prev_materialized_count_; |
| 442 |
438 // Output frame information. Only used during heap object materialization. | 443 // Output frame information. Only used during heap object materialization. |
439 List<Handle<JSFunction> > jsframe_functions_; | 444 List<Handle<JSFunction> > jsframe_functions_; |
440 List<bool> jsframe_has_adapted_arguments_; | 445 List<bool> jsframe_has_adapted_arguments_; |
441 | 446 |
442 // Materialized objects. Only used during heap object materialization. | 447 // Materialized objects. Only used during heap object materialization. |
443 List<Handle<Object> >* materialized_values_; | 448 List<Handle<Object> >* materialized_values_; |
444 List<Handle<Object> >* materialized_objects_; | 449 List<Handle<Object> >* materialized_objects_; |
445 int materialization_value_index_; | 450 int materialization_value_index_; |
446 int materialization_object_index_; | 451 int materialization_object_index_; |
447 | 452 |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
776 | 781 |
777 | 782 |
778 class SlotRef BASE_EMBEDDED { | 783 class SlotRef BASE_EMBEDDED { |
779 public: | 784 public: |
780 enum SlotRepresentation { | 785 enum SlotRepresentation { |
781 UNKNOWN, | 786 UNKNOWN, |
782 TAGGED, | 787 TAGGED, |
783 INT32, | 788 INT32, |
784 UINT32, | 789 UINT32, |
785 DOUBLE, | 790 DOUBLE, |
786 LITERAL | 791 LITERAL, |
| 792 DEFERRED_OBJECT, // Object captured by the escape analysis. |
| 793 // The number of nested objects can be obtained |
| 794 // with the DeferredObjectLength() method |
| 795 // (the SlotRefs of the nested objects follow |
| 796 // this SlotRef in the depth-first order.) |
| 797 DUPLICATE_OBJECT // Duplicated object of a deferred object. |
787 }; | 798 }; |
788 | 799 |
789 SlotRef() | 800 SlotRef() |
790 : addr_(NULL), representation_(UNKNOWN) { } | 801 : addr_(NULL), representation_(UNKNOWN) { } |
791 | 802 |
792 SlotRef(Address addr, SlotRepresentation representation) | 803 SlotRef(Address addr, SlotRepresentation representation) |
793 : addr_(addr), representation_(representation) { } | 804 : addr_(addr), representation_(representation) { } |
794 | 805 |
795 SlotRef(Isolate* isolate, Object* literal) | 806 SlotRef(Isolate* isolate, Object* literal) |
796 : literal_(literal, isolate), representation_(LITERAL) { } | 807 : literal_(literal, isolate), representation_(LITERAL) { } |
797 | 808 |
798 Handle<Object> GetValue(Isolate* isolate) { | 809 static SlotRef NewDeferredObject(int length) { |
799 switch (representation_) { | 810 SlotRef slot; |
800 case TAGGED: | 811 slot.representation_ = DEFERRED_OBJECT; |
801 return Handle<Object>(Memory::Object_at(addr_), isolate); | 812 slot.deferred_object_length_ = length; |
802 | 813 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 } | 814 } |
834 | 815 |
835 static Vector<SlotRef> ComputeSlotMappingForArguments( | 816 SlotRepresentation Representation() { return representation_; } |
836 JavaScriptFrame* frame, | 817 |
837 int inlined_frame_index, | 818 static SlotRef NewDuplicateObject(int id) { |
838 int formal_parameter_count); | 819 SlotRef slot; |
| 820 slot.representation_ = DUPLICATE_OBJECT; |
| 821 slot.duplicate_object_id_ = id; |
| 822 return slot; |
| 823 } |
| 824 |
| 825 int DeferredObjectLength() { return deferred_object_length_; } |
| 826 |
| 827 int DuplicateObjectId() { return duplicate_object_id_; } |
| 828 |
| 829 Handle<Object> GetValue(Isolate* isolate); |
839 | 830 |
840 private: | 831 private: |
841 Address addr_; | 832 Address addr_; |
842 Handle<Object> literal_; | 833 Handle<Object> literal_; |
843 SlotRepresentation representation_; | 834 SlotRepresentation representation_; |
| 835 int deferred_object_length_; |
| 836 int duplicate_object_id_; |
| 837 }; |
| 838 |
| 839 class SlotRefValueBuilder BASE_EMBEDDED { |
| 840 public: |
| 841 SlotRefValueBuilder( |
| 842 JavaScriptFrame* frame, |
| 843 int inlined_frame_index, |
| 844 int formal_parameter_count); |
| 845 |
| 846 void Prepare(Isolate* isolate); |
| 847 Handle<Object> GetNext(Isolate* isolate, int level); |
| 848 void Finish(Isolate* isolate); |
| 849 |
| 850 int args_length() { return args_length_; } |
| 851 |
| 852 private: |
| 853 List<Handle<Object> > materialized_objects_; |
| 854 Handle<FixedArray> previously_materialized_objects_; |
| 855 int prev_materialized_count_; |
| 856 Address stack_frame_id_; |
| 857 List<SlotRef> slot_refs_; |
| 858 int current_slot_; |
| 859 int args_length_; |
| 860 int first_slot_index_; |
| 861 |
| 862 static SlotRef ComputeSlotForNextArgument( |
| 863 Translation::Opcode opcode, |
| 864 TranslationIterator* iterator, |
| 865 DeoptimizationInputData* data, |
| 866 JavaScriptFrame* frame); |
| 867 |
| 868 Handle<Object> GetPreviouslyMaterialized(Isolate* isolate, int length); |
844 | 869 |
845 static Address SlotAddress(JavaScriptFrame* frame, int slot_index) { | 870 static Address SlotAddress(JavaScriptFrame* frame, int slot_index) { |
846 if (slot_index >= 0) { | 871 if (slot_index >= 0) { |
847 const int offset = JavaScriptFrameConstants::kLocal0Offset; | 872 const int offset = JavaScriptFrameConstants::kLocal0Offset; |
848 return frame->fp() + offset - (slot_index * kPointerSize); | 873 return frame->fp() + offset - (slot_index * kPointerSize); |
849 } else { | 874 } else { |
850 const int offset = JavaScriptFrameConstants::kLastParameterOffset; | 875 const int offset = JavaScriptFrameConstants::kLastParameterOffset; |
851 return frame->fp() + offset - ((slot_index + 1) * kPointerSize); | 876 return frame->fp() + offset - ((slot_index + 1) * kPointerSize); |
852 } | 877 } |
853 } | 878 } |
854 | 879 |
855 static SlotRef ComputeSlotForNextArgument(TranslationIterator* iterator, | 880 Handle<Object> GetDeferredObject(Isolate* isolate); |
856 DeoptimizationInputData* data, | 881 }; |
857 JavaScriptFrame* frame); | |
858 | 882 |
859 static void ComputeSlotsForArguments( | 883 class MaterializedObjectStore { |
860 Vector<SlotRef>* args_slots, | 884 public: |
861 TranslationIterator* iterator, | 885 explicit MaterializedObjectStore(Isolate* isolate) : isolate_(isolate) { |
862 DeoptimizationInputData* data, | 886 } |
863 JavaScriptFrame* frame); | 887 |
| 888 Handle<FixedArray> Get(Address fp); |
| 889 void Set(Address fp, Handle<FixedArray> materialized_objects); |
| 890 void Remove(Address fp); |
| 891 |
| 892 private: |
| 893 Isolate* isolate() { return isolate_; } |
| 894 Handle<FixedArray> GetStackEntries(); |
| 895 Handle<FixedArray> EnsureStackEntries(int size); |
| 896 |
| 897 int StackIdToIndex(Address fp); |
| 898 |
| 899 Isolate* isolate_; |
| 900 List<Address> frame_fps_; |
864 }; | 901 }; |
865 | 902 |
866 | 903 |
867 #ifdef ENABLE_DEBUGGER_SUPPORT | 904 #ifdef ENABLE_DEBUGGER_SUPPORT |
868 // Class used to represent an unoptimized frame when the debugger | 905 // Class used to represent an unoptimized frame when the debugger |
869 // needs to inspect a frame that is part of an optimized frame. The | 906 // 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 | 907 // 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. | 908 // by the debugger frame information is copied to an object of this type. |
872 // Represents parameters in unadapted form so their number might mismatch | 909 // Represents parameters in unadapted form so their number might mismatch |
873 // formal parameter count. | 910 // formal parameter count. |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
936 Object** expression_stack_; | 973 Object** expression_stack_; |
937 int source_position_; | 974 int source_position_; |
938 | 975 |
939 friend class Deoptimizer; | 976 friend class Deoptimizer; |
940 }; | 977 }; |
941 #endif | 978 #endif |
942 | 979 |
943 } } // namespace v8::internal | 980 } } // namespace v8::internal |
944 | 981 |
945 #endif // V8_DEOPTIMIZER_H_ | 982 #endif // V8_DEOPTIMIZER_H_ |
OLD | NEW |