OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/debug/liveedit.h" | 5 #include "src/debug/liveedit.h" |
6 | 6 |
7 #include "src/ast/scopeinfo.h" | 7 #include "src/ast/scopeinfo.h" |
8 #include "src/ast/scopes.h" | 8 #include "src/ast/scopes.h" |
9 #include "src/code-stubs.h" | 9 #include "src/code-stubs.h" |
10 #include "src/compilation-cache.h" | 10 #include "src/compilation-cache.h" |
(...skipping 1059 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1070 Handle<SharedFunctionInfo> shared_info = | 1070 Handle<SharedFunctionInfo> shared_info = |
1071 UnwrapSharedFunctionInfoFromJSValue(function_wrapper); | 1071 UnwrapSharedFunctionInfoFromJSValue(function_wrapper); |
1072 Isolate* isolate = function_wrapper->GetIsolate(); | 1072 Isolate* isolate = function_wrapper->GetIsolate(); |
1073 CHECK(script_handle->IsScript() || script_handle->IsUndefined(isolate)); | 1073 CHECK(script_handle->IsScript() || script_handle->IsUndefined(isolate)); |
1074 SharedFunctionInfo::SetScript(shared_info, script_handle); | 1074 SharedFunctionInfo::SetScript(shared_info, script_handle); |
1075 shared_info->DisableOptimization(kLiveEdit); | 1075 shared_info->DisableOptimization(kLiveEdit); |
1076 | 1076 |
1077 function_wrapper->GetIsolate()->compilation_cache()->Remove(shared_info); | 1077 function_wrapper->GetIsolate()->compilation_cache()->Remove(shared_info); |
1078 } | 1078 } |
1079 | 1079 |
1080 | 1080 namespace { |
1081 // For a script text change (defined as position_change_array), translates | 1081 // For a script text change (defined as position_change_array), translates |
1082 // position in unchanged text to position in changed text. | 1082 // position in unchanged text to position in changed text. |
1083 // Text change is a set of non-overlapping regions in text, that have changed | 1083 // Text change is a set of non-overlapping regions in text, that have changed |
1084 // their contents and length. It is specified as array of groups of 3 numbers: | 1084 // their contents and length. It is specified as array of groups of 3 numbers: |
1085 // (change_begin, change_end, change_end_new_position). | 1085 // (change_begin, change_end, change_end_new_position). |
1086 // Each group describes a change in text; groups are sorted by change_begin. | 1086 // Each group describes a change in text; groups are sorted by change_begin. |
1087 // Only position in text beyond any changes may be successfully translated. | 1087 // Only position in text beyond any changes may be successfully translated. |
1088 // If a positions is inside some region that changed, result is currently | 1088 // If a positions is inside some region that changed, result is currently |
1089 // undefined. | 1089 // undefined. |
1090 static int TranslatePosition(int original_position, | 1090 static int TranslatePosition(int original_position, |
(...skipping 21 matching lines...) Expand all Loading... |
1112 element = JSReceiver::GetElement(isolate, position_change_array, i + 2) | 1112 element = JSReceiver::GetElement(isolate, position_change_array, i + 2) |
1113 .ToHandleChecked(); | 1113 .ToHandleChecked(); |
1114 CHECK(element->IsSmi()); | 1114 CHECK(element->IsSmi()); |
1115 int chunk_changed_end = Handle<Smi>::cast(element)->value(); | 1115 int chunk_changed_end = Handle<Smi>::cast(element)->value(); |
1116 position_diff = chunk_changed_end - chunk_end; | 1116 position_diff = chunk_changed_end - chunk_end; |
1117 } | 1117 } |
1118 | 1118 |
1119 return original_position + position_diff; | 1119 return original_position + position_diff; |
1120 } | 1120 } |
1121 | 1121 |
1122 | |
1123 // Auto-growing buffer for writing relocation info code section. This buffer | |
1124 // is a simplified version of buffer from Assembler. Unlike Assembler, this | |
1125 // class is platform-independent and it works without dealing with instructions. | |
1126 // As specified by RelocInfo format, the buffer is filled in reversed order: | |
1127 // from upper to lower addresses. | |
1128 // It uses NewArray/DeleteArray for memory management. | |
1129 class RelocInfoBuffer { | |
1130 public: | |
1131 RelocInfoBuffer(int buffer_initial_capicity, byte* pc) { | |
1132 buffer_size_ = buffer_initial_capicity + kBufferGap; | |
1133 buffer_ = NewArray<byte>(buffer_size_); | |
1134 | |
1135 reloc_info_writer_.Reposition(buffer_ + buffer_size_, pc); | |
1136 } | |
1137 ~RelocInfoBuffer() { | |
1138 DeleteArray(buffer_); | |
1139 } | |
1140 | |
1141 // As specified by RelocInfo format, the buffer is filled in reversed order: | |
1142 // from upper to lower addresses. | |
1143 void Write(const RelocInfo* rinfo) { | |
1144 if (buffer_ + kBufferGap >= reloc_info_writer_.pos()) { | |
1145 Grow(); | |
1146 } | |
1147 reloc_info_writer_.Write(rinfo); | |
1148 } | |
1149 | |
1150 Vector<byte> GetResult() { | |
1151 // Return the bytes from pos up to end of buffer. | |
1152 int result_size = | |
1153 static_cast<int>((buffer_ + buffer_size_) - reloc_info_writer_.pos()); | |
1154 return Vector<byte>(reloc_info_writer_.pos(), result_size); | |
1155 } | |
1156 | |
1157 private: | |
1158 void Grow() { | |
1159 // Compute new buffer size. | |
1160 int new_buffer_size; | |
1161 if (buffer_size_ < 2 * KB) { | |
1162 new_buffer_size = 4 * KB; | |
1163 } else { | |
1164 new_buffer_size = 2 * buffer_size_; | |
1165 } | |
1166 // Some internal data structures overflow for very large buffers, | |
1167 // they must ensure that kMaximalBufferSize is not too large. | |
1168 if (new_buffer_size > kMaximalBufferSize) { | |
1169 V8::FatalProcessOutOfMemory("RelocInfoBuffer::GrowBuffer"); | |
1170 } | |
1171 | |
1172 // Set up new buffer. | |
1173 byte* new_buffer = NewArray<byte>(new_buffer_size); | |
1174 | |
1175 // Copy the data. | |
1176 int curently_used_size = | |
1177 static_cast<int>(buffer_ + buffer_size_ - reloc_info_writer_.pos()); | |
1178 MemMove(new_buffer + new_buffer_size - curently_used_size, | |
1179 reloc_info_writer_.pos(), curently_used_size); | |
1180 | |
1181 reloc_info_writer_.Reposition( | |
1182 new_buffer + new_buffer_size - curently_used_size, | |
1183 reloc_info_writer_.last_pc()); | |
1184 | |
1185 DeleteArray(buffer_); | |
1186 buffer_ = new_buffer; | |
1187 buffer_size_ = new_buffer_size; | |
1188 } | |
1189 | |
1190 RelocInfoWriter reloc_info_writer_; | |
1191 byte* buffer_; | |
1192 int buffer_size_; | |
1193 | |
1194 static const int kBufferGap = RelocInfoWriter::kMaxSize; | |
1195 static const int kMaximalBufferSize = 512*MB; | |
1196 }; | |
1197 | |
1198 namespace { | |
1199 Handle<ByteArray> TranslateSourcePositionTable( | 1122 Handle<ByteArray> TranslateSourcePositionTable( |
1200 Handle<ByteArray> source_position_table, | 1123 Handle<ByteArray> source_position_table, |
1201 Handle<JSArray> position_change_array) { | 1124 Handle<JSArray> position_change_array) { |
1202 Isolate* isolate = source_position_table->GetIsolate(); | 1125 Isolate* isolate = source_position_table->GetIsolate(); |
1203 Zone zone(isolate->allocator()); | 1126 Zone zone(isolate->allocator()); |
1204 SourcePositionTableBuilder builder(isolate, &zone); | 1127 SourcePositionTableBuilder builder(isolate, &zone); |
1205 | 1128 |
1206 for (SourcePositionTableIterator iterator(*source_position_table); | 1129 for (SourcePositionTableIterator iterator(*source_position_table); |
1207 !iterator.done(); iterator.Advance()) { | 1130 !iterator.done(); iterator.Advance()) { |
1208 int position = iterator.source_position(); | 1131 int position = iterator.source_position(); |
(...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2022 scope_info_length++; | 1945 scope_info_length++; |
2023 | 1946 |
2024 current_scope = current_scope->outer_scope(); | 1947 current_scope = current_scope->outer_scope(); |
2025 } | 1948 } |
2026 | 1949 |
2027 return scope_info_list; | 1950 return scope_info_list; |
2028 } | 1951 } |
2029 | 1952 |
2030 } // namespace internal | 1953 } // namespace internal |
2031 } // namespace v8 | 1954 } // namespace v8 |
OLD | NEW |