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 905 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
916 SharedFunctionInfo::cast(array->GetElementNoExceptionThrown(i))); | 916 SharedFunctionInfo::cast(array->GetElementNoExceptionThrown(i))); |
917 SharedInfoWrapper info_wrapper = SharedInfoWrapper::Create(); | 917 SharedInfoWrapper info_wrapper = SharedInfoWrapper::Create(); |
918 Handle<String> name_handle(String::cast(info->name())); | 918 Handle<String> name_handle(String::cast(info->name())); |
919 info_wrapper.SetProperties(name_handle, info->start_position(), | 919 info_wrapper.SetProperties(name_handle, info->start_position(), |
920 info->end_position(), info); | 920 info->end_position(), info); |
921 SetElementNonStrict(array, i, info_wrapper.GetJSArray()); | 921 SetElementNonStrict(array, i, info_wrapper.GetJSArray()); |
922 } | 922 } |
923 } | 923 } |
924 | 924 |
925 | 925 |
926 // Visitor that collects all references to a particular code object, | 926 // Visitor that finds all references to a particular code object, |
927 // including "CODE_TARGET" references in other code objects. | 927 // including "CODE_TARGET" references in other code objects and replaces |
928 // It works in context of ZoneScope. | 928 // them on the fly. |
929 class ReferenceCollectorVisitor : public ObjectVisitor { | 929 class ReplacingVisitor : public ObjectVisitor { |
930 public: | 930 public: |
931 ReferenceCollectorVisitor(Code* original, Zone* zone) | 931 explicit ReplacingVisitor(Code* original, Code* substitution) |
932 : original_(original), | 932 : original_(original), substitution_(substitution) { |
933 rvalues_(10, zone), | |
934 reloc_infos_(10, zone), | |
935 code_entries_(10, zone), | |
936 zone_(zone) { | |
937 } | 933 } |
938 | 934 |
939 virtual void VisitPointers(Object** start, Object** end) { | 935 virtual void VisitPointers(Object** start, Object** end) { |
940 for (Object** p = start; p < end; p++) { | 936 for (Object** p = start; p < end; p++) { |
941 if (*p == original_) { | 937 if (*p == original_) { |
942 rvalues_.Add(p, zone_); | 938 *p = substitution_; |
943 } | 939 } |
944 } | 940 } |
945 } | 941 } |
946 | 942 |
947 virtual void VisitCodeEntry(Address entry) { | 943 virtual void VisitCodeEntry(Address entry) { |
948 if (Code::GetObjectFromEntryAddress(entry) == original_) { | 944 if (Code::GetObjectFromEntryAddress(entry) == original_) { |
949 code_entries_.Add(entry, zone_); | 945 Address substitution_entry = substitution_->instruction_start(); |
| 946 Memory::Address_at(entry) = substitution_entry; |
950 } | 947 } |
951 } | 948 } |
952 | 949 |
953 virtual void VisitCodeTarget(RelocInfo* rinfo) { | 950 virtual void VisitCodeTarget(RelocInfo* rinfo) { |
954 if (RelocInfo::IsCodeTarget(rinfo->rmode()) && | 951 if (RelocInfo::IsCodeTarget(rinfo->rmode()) && |
955 Code::GetCodeFromTargetAddress(rinfo->target_address()) == original_) { | 952 Code::GetCodeFromTargetAddress(rinfo->target_address()) == original_) { |
956 reloc_infos_.Add(*rinfo, zone_); | 953 Address substitution_entry = substitution_->instruction_start(); |
| 954 rinfo->set_target_address(substitution_entry); |
957 } | 955 } |
958 } | 956 } |
959 | 957 |
960 virtual void VisitDebugTarget(RelocInfo* rinfo) { | 958 virtual void VisitDebugTarget(RelocInfo* rinfo) { |
961 VisitCodeTarget(rinfo); | 959 VisitCodeTarget(rinfo); |
962 } | 960 } |
963 | 961 |
964 // Post-visiting method that iterates over all collected references and | |
965 // modifies them. | |
966 void Replace(Code* substitution) { | |
967 for (int i = 0; i < rvalues_.length(); i++) { | |
968 *(rvalues_[i]) = substitution; | |
969 } | |
970 Address substitution_entry = substitution->instruction_start(); | |
971 for (int i = 0; i < reloc_infos_.length(); i++) { | |
972 reloc_infos_[i].set_target_address(substitution_entry); | |
973 } | |
974 for (int i = 0; i < code_entries_.length(); i++) { | |
975 Address entry = code_entries_[i]; | |
976 Memory::Address_at(entry) = substitution_entry; | |
977 } | |
978 } | |
979 | |
980 private: | 962 private: |
981 Code* original_; | 963 Code* original_; |
982 ZoneList<Object**> rvalues_; | 964 Code* substitution_; |
983 ZoneList<RelocInfo> reloc_infos_; | |
984 ZoneList<Address> code_entries_; | |
985 Zone* zone_; | |
986 }; | 965 }; |
987 | 966 |
988 | 967 |
989 // Finds all references to original and replaces them with substitution. | 968 // Finds all references to original and replaces them with substitution. |
990 static void ReplaceCodeObject(Code* original, Code* substitution) { | 969 static void ReplaceCodeObject(Code* original, Code* substitution) { |
991 ASSERT(!HEAP->InNewSpace(substitution)); | 970 ASSERT(!HEAP->InNewSpace(substitution)); |
992 | 971 |
993 HeapIterator iterator; | |
994 AssertNoAllocation no_allocations_please; | 972 AssertNoAllocation no_allocations_please; |
995 | 973 |
996 // A zone scope for ReferenceCollectorVisitor. | 974 ReplacingVisitor visitor(original, substitution); |
997 ZoneScope scope(Isolate::Current(), DELETE_ON_EXIT); | |
998 | |
999 ReferenceCollectorVisitor visitor(original, Isolate::Current()->zone()); | |
1000 | 975 |
1001 // Iterate over all roots. Stack frames may have pointer into original code, | 976 // Iterate over all roots. Stack frames may have pointer into original code, |
1002 // so temporary replace the pointers with offset numbers | 977 // so temporary replace the pointers with offset numbers |
1003 // in prologue/epilogue. | 978 // in prologue/epilogue. |
1004 { | 979 HEAP->IterateRoots(&visitor, VISIT_ALL); |
1005 HEAP->IterateStrongRoots(&visitor, VISIT_ALL); | |
1006 } | |
1007 | 980 |
1008 // Now iterate over all pointers of all objects, including code_target | 981 // Now iterate over all pointers of all objects, including code_target |
1009 // implicit pointers. | 982 // implicit pointers. |
| 983 HeapIterator iterator; |
1010 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { | 984 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { |
1011 obj->Iterate(&visitor); | 985 obj->Iterate(&visitor); |
1012 } | 986 } |
1013 | |
1014 visitor.Replace(substitution); | |
1015 } | 987 } |
1016 | 988 |
1017 | 989 |
1018 // Check whether the code is natural function code (not a lazy-compile stub | 990 // Check whether the code is natural function code (not a lazy-compile stub |
1019 // code). | 991 // code). |
1020 static bool IsJSFunctionCode(Code* code) { | 992 static bool IsJSFunctionCode(Code* code) { |
1021 return code->kind() == Code::FUNCTION; | 993 return code->kind() == Code::FUNCTION; |
1022 } | 994 } |
1023 | 995 |
1024 | 996 |
(...skipping 872 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1897 | 1869 |
1898 bool LiveEditFunctionTracker::IsActive(Isolate* isolate) { | 1870 bool LiveEditFunctionTracker::IsActive(Isolate* isolate) { |
1899 return false; | 1871 return false; |
1900 } | 1872 } |
1901 | 1873 |
1902 #endif // ENABLE_DEBUGGER_SUPPORT | 1874 #endif // ENABLE_DEBUGGER_SUPPORT |
1903 | 1875 |
1904 | 1876 |
1905 | 1877 |
1906 } } // namespace v8::internal | 1878 } } // namespace v8::internal |
OLD | NEW |