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

Side by Side Diff: src/debug/liveedit.cc

Issue 2547483002: Store SharedFunctionInfos of a Script in a FixedArray indexed by their ID (Closed)
Patch Set: updates Created 4 years 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
OLDNEW
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/scopes.h" 7 #include "src/ast/scopes.h"
8 #include "src/code-stubs.h" 8 #include "src/code-stubs.h"
9 #include "src/compilation-cache.h" 9 #include "src/compilation-cache.h"
10 #include "src/compiler.h" 10 #include "src/compiler.h"
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 return Handle<SharedFunctionInfo>(SharedFunctionInfo::cast(shared)); 597 return Handle<SharedFunctionInfo>(SharedFunctionInfo::cast(shared));
598 } 598 }
599 599
600 600
601 static int GetArrayLength(Handle<JSArray> array) { 601 static int GetArrayLength(Handle<JSArray> array) {
602 Object* length = array->length(); 602 Object* length = array->length();
603 CHECK(length->IsSmi()); 603 CHECK(length->IsSmi());
604 return Smi::cast(length)->value(); 604 return Smi::cast(length)->value();
605 } 605 }
606 606
607 607 void FunctionInfoWrapper::SetInitialProperties(
608 void FunctionInfoWrapper::SetInitialProperties(Handle<String> name, 608 Handle<String> name, int start_position, int end_position, int param_num,
609 int start_position, 609 int literal_count, int parent_index, int function_literal_id) {
610 int end_position, int param_num,
611 int literal_count,
612 int parent_index) {
613 HandleScope scope(isolate()); 610 HandleScope scope(isolate());
614 this->SetField(kFunctionNameOffset_, name); 611 this->SetField(kFunctionNameOffset_, name);
615 this->SetSmiValueField(kStartPositionOffset_, start_position); 612 this->SetSmiValueField(kStartPositionOffset_, start_position);
616 this->SetSmiValueField(kEndPositionOffset_, end_position); 613 this->SetSmiValueField(kEndPositionOffset_, end_position);
617 this->SetSmiValueField(kParamNumOffset_, param_num); 614 this->SetSmiValueField(kParamNumOffset_, param_num);
618 this->SetSmiValueField(kLiteralNumOffset_, literal_count); 615 this->SetSmiValueField(kLiteralNumOffset_, literal_count);
619 this->SetSmiValueField(kParentIndexOffset_, parent_index); 616 this->SetSmiValueField(kParentIndexOffset_, parent_index);
617 this->SetSmiValueField(kFunctionLiteralIdOffset_, function_literal_id);
620 } 618 }
621 619
622 void FunctionInfoWrapper::SetSharedFunctionInfo( 620 void FunctionInfoWrapper::SetSharedFunctionInfo(
623 Handle<SharedFunctionInfo> info) { 621 Handle<SharedFunctionInfo> info) {
624 Handle<JSValue> info_holder = WrapInJSValue(info); 622 Handle<JSValue> info_holder = WrapInJSValue(info);
625 this->SetField(kSharedFunctionInfoOffset_, info_holder); 623 this->SetField(kSharedFunctionInfoOffset_, info_holder);
626 } 624 }
627 625
628 Handle<SharedFunctionInfo> FunctionInfoWrapper::GetSharedFunctionInfo() { 626 Handle<SharedFunctionInfo> FunctionInfoWrapper::GetSharedFunctionInfo() {
629 Handle<Object> element = this->GetField(kSharedFunctionInfoOffset_); 627 Handle<Object> element = this->GetField(kSharedFunctionInfoOffset_);
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
1031 shared_info->set_start_position(start_position); 1029 shared_info->set_start_position(start_position);
1032 shared_info->set_end_position(end_position); 1030 shared_info->set_end_position(end_position);
1033 1031
1034 LiteralFixer::PatchLiterals(&compile_info_wrapper, shared_info, 1032 LiteralFixer::PatchLiterals(&compile_info_wrapper, shared_info,
1035 feedback_metadata_changed, isolate); 1033 feedback_metadata_changed, isolate);
1036 1034
1037 DeoptimizeDependentFunctions(*shared_info); 1035 DeoptimizeDependentFunctions(*shared_info);
1038 isolate->compilation_cache()->Remove(shared_info); 1036 isolate->compilation_cache()->Remove(shared_info);
1039 } 1037 }
1040 1038
1041 1039 void LiveEdit::FunctionSourceUpdated(Handle<JSArray> shared_info_array,
1042 void LiveEdit::FunctionSourceUpdated(Handle<JSArray> shared_info_array) { 1040 int new_function_literal_id) {
1043 SharedInfoWrapper shared_info_wrapper(shared_info_array); 1041 SharedInfoWrapper shared_info_wrapper(shared_info_array);
1044 Handle<SharedFunctionInfo> shared_info = shared_info_wrapper.GetInfo(); 1042 Handle<SharedFunctionInfo> shared_info = shared_info_wrapper.GetInfo();
1045 1043
1044 shared_info->set_function_literal_id(new_function_literal_id);
1046 DeoptimizeDependentFunctions(*shared_info); 1045 DeoptimizeDependentFunctions(*shared_info);
1047 shared_info_array->GetIsolate()->compilation_cache()->Remove(shared_info); 1046 shared_info_array->GetIsolate()->compilation_cache()->Remove(shared_info);
1048 } 1047 }
1049 1048
1049 void LiveEdit::FixupScript(Handle<Script> script, int max_function_literal_id) {
1050 Isolate* isolate = script->GetIsolate();
1051 Handle<FixedArray> old_infos(script->shared_function_infos(), isolate);
1052 Handle<FixedArray> new_infos(isolate->factory()->NewFixedArrayWithSmis(
1053 max_function_literal_id + 1, 0));
1054 script->set_shared_function_infos(*new_infos);
1055 for (int index = 0; index < old_infos->length(); ++index) {
1056 Object* raw = old_infos->get(index);
1057 if (raw->IsSmi() || WeakCell::cast(raw)->cleared()) continue;
1058 // We can't use SharedFunctionInfo::SetScript(info, undefined_value()) here,
1059 // as we severed the link from the Script to the SharedFunctionInfo above.
1060 Handle<SharedFunctionInfo> info(
1061 SharedFunctionInfo::cast(WeakCell::cast(raw)->value()), isolate);
1062 info->set_script(isolate->heap()->undefined_value());
1063 Handle<Object> new_noscript_list = WeakFixedArray::Add(
1064 isolate->factory()->noscript_shared_function_infos(), info);
1065 isolate->heap()->SetRootNoScriptSharedFunctionInfos(*new_noscript_list);
1066
1067 // Put the SharedFunctionInfo at its new, correct location.
1068 SharedFunctionInfo::SetScript(info, script);
1069 }
1070 }
1050 1071
1051 void LiveEdit::SetFunctionScript(Handle<JSValue> function_wrapper, 1072 void LiveEdit::SetFunctionScript(Handle<JSValue> function_wrapper,
1052 Handle<Object> script_handle) { 1073 Handle<Object> script_handle) {
1053 Handle<SharedFunctionInfo> shared_info = 1074 Handle<SharedFunctionInfo> shared_info =
1054 UnwrapSharedFunctionInfoFromJSValue(function_wrapper); 1075 UnwrapSharedFunctionInfoFromJSValue(function_wrapper);
1055 Isolate* isolate = function_wrapper->GetIsolate(); 1076 Isolate* isolate = function_wrapper->GetIsolate();
1056 CHECK(script_handle->IsScript() || script_handle->IsUndefined(isolate)); 1077 CHECK(script_handle->IsScript() || script_handle->IsUndefined(isolate));
1078 #if 0
Toon Verwaest 2016/12/06 21:10:14 left-over code?
jochen (gone - plz use gerrit) 2016/12/07 15:57:00 yes, removed
1079 if (shared_info->script()->IsScript()) {
1080 Handle<Script> old_script(Script::cast(shared_info->script()), isolate);
1081 Handle<Object> raw(old_script->shared_function_infos()->get(
1082 shared_info->function_literal_id()),
1083 isolate);
1084 if (raw->IsWeakCell() && !Handle<WeakCell>::cast(raw)->cleared()) {
1085 Handle<SharedFunctionInfo> old_info(
1086 SharedFunctionInfo::cast(Handle<WeakCell>::cast(raw)->value()),
1087 isolate);
1088 SharedFunctionInfo::SetScript(old_info,
1089 isolate->factory()->undefined_value());
1090 }
1091 }
1092 #endif
1057 SharedFunctionInfo::SetScript(shared_info, script_handle); 1093 SharedFunctionInfo::SetScript(shared_info, script_handle);
1058 shared_info->DisableOptimization(kLiveEdit); 1094 shared_info->DisableOptimization(kLiveEdit);
1059 1095
1060 function_wrapper->GetIsolate()->compilation_cache()->Remove(shared_info); 1096 function_wrapper->GetIsolate()->compilation_cache()->Remove(shared_info);
1061 } 1097 }
1062 1098
1063 namespace { 1099 namespace {
1064 // For a script text change (defined as position_change_array), translates 1100 // For a script text change (defined as position_change_array), translates
1065 // position in unchanged text to position in changed text. 1101 // position in unchanged text to position in changed text.
1066 // Text change is a set of non-overlapping regions in text, that have changed 1102 // Text change is a set of non-overlapping regions in text, that have changed
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1166 Handle<Script> copy = isolate->factory()->NewScript(original_source); 1202 Handle<Script> copy = isolate->factory()->NewScript(original_source);
1167 1203
1168 copy->set_name(original->name()); 1204 copy->set_name(original->name());
1169 copy->set_line_offset(original->line_offset()); 1205 copy->set_line_offset(original->line_offset());
1170 copy->set_column_offset(original->column_offset()); 1206 copy->set_column_offset(original->column_offset());
1171 copy->set_type(original->type()); 1207 copy->set_type(original->type());
1172 copy->set_context_data(original->context_data()); 1208 copy->set_context_data(original->context_data());
1173 copy->set_eval_from_shared(original->eval_from_shared()); 1209 copy->set_eval_from_shared(original->eval_from_shared());
1174 copy->set_eval_from_position(original->eval_from_position()); 1210 copy->set_eval_from_position(original->eval_from_position());
1175 1211
1212 Handle<FixedArray> infos(isolate->factory()->NewFixedArrayWithSmis(
1213 original->shared_function_infos()->length(), 0));
1214 copy->set_shared_function_infos(*infos);
1215
1176 // Copy all the flags, but clear compilation state. 1216 // Copy all the flags, but clear compilation state.
1177 copy->set_flags(original->flags()); 1217 copy->set_flags(original->flags());
1178 copy->set_compilation_state(Script::COMPILATION_STATE_INITIAL); 1218 copy->set_compilation_state(Script::COMPILATION_STATE_INITIAL);
1179 1219
1180 return copy; 1220 return copy;
1181 } 1221 }
1182 1222
1183
1184 Handle<Object> LiveEdit::ChangeScriptSource(Handle<Script> original_script, 1223 Handle<Object> LiveEdit::ChangeScriptSource(Handle<Script> original_script,
1185 Handle<String> new_source, 1224 Handle<String> new_source,
1186 Handle<Object> old_script_name) { 1225 Handle<Object> old_script_name) {
1187 Isolate* isolate = original_script->GetIsolate(); 1226 Isolate* isolate = original_script->GetIsolate();
1188 Handle<Object> old_script_object; 1227 Handle<Object> old_script_object;
1189 if (old_script_name->IsString()) { 1228 if (old_script_name->IsString()) {
1190 Handle<Script> old_script = CreateScriptCopy(original_script); 1229 Handle<Script> old_script = CreateScriptCopy(original_script);
1191 old_script->set_name(String::cast(*old_script_name)); 1230 old_script->set_name(String::cast(*old_script_name));
1192 old_script_object = old_script; 1231 old_script_object = old_script;
1193 isolate->debug()->OnAfterCompile(old_script); 1232 isolate->debug()->OnAfterCompile(old_script);
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after
1849 script_ = script; 1888 script_ = script;
1850 zone_ = zone; 1889 zone_ = zone;
1851 } 1890 }
1852 1891
1853 void LiveEditFunctionTracker::VisitFunctionLiteral(FunctionLiteral* node) { 1892 void LiveEditFunctionTracker::VisitFunctionLiteral(FunctionLiteral* node) {
1854 // FunctionStarted is called in pre-order. 1893 // FunctionStarted is called in pre-order.
1855 FunctionStarted(node); 1894 FunctionStarted(node);
1856 // Recurse using the regular traversal. 1895 // Recurse using the regular traversal.
1857 AstTraversalVisitor::VisitFunctionLiteral(node); 1896 AstTraversalVisitor::VisitFunctionLiteral(node);
1858 // FunctionDone are called in post-order. 1897 // FunctionDone are called in post-order.
1859 // TODO(jgruber): If required, replace the (linear cost)
1860 // FindSharedFunctionInfo call with a more efficient implementation.
1861 Handle<SharedFunctionInfo> info = 1898 Handle<SharedFunctionInfo> info =
1862 script_->FindSharedFunctionInfo(node).ToHandleChecked(); 1899 script_->FindSharedFunctionInfo(node).ToHandleChecked();
1863 FunctionDone(info, node->scope()); 1900 FunctionDone(info, node->scope());
1864 } 1901 }
1865 1902
1866 void LiveEditFunctionTracker::FunctionStarted(FunctionLiteral* fun) { 1903 void LiveEditFunctionTracker::FunctionStarted(FunctionLiteral* fun) {
1867 HandleScope handle_scope(isolate_); 1904 HandleScope handle_scope(isolate_);
1868 FunctionInfoWrapper info = FunctionInfoWrapper::Create(isolate_); 1905 FunctionInfoWrapper info = FunctionInfoWrapper::Create(isolate_);
1869 info.SetInitialProperties(fun->name(), fun->start_position(), 1906 info.SetInitialProperties(fun->name(), fun->start_position(),
1870 fun->end_position(), fun->parameter_count(), 1907 fun->end_position(), fun->parameter_count(),
1871 fun->materialized_literal_count(), 1908 fun->materialized_literal_count(),
1872 current_parent_index_); 1909 current_parent_index_, fun->function_literal_id());
1873 current_parent_index_ = len_; 1910 current_parent_index_ = len_;
1874 SetElementSloppy(result_, len_, info.GetJSArray()); 1911 SetElementSloppy(result_, len_, info.GetJSArray());
1875 len_++; 1912 len_++;
1876 } 1913 }
1877 1914
1878 // Saves full information about a function: its code, its scope info 1915 // Saves full information about a function: its code, its scope info
1879 // and a SharedFunctionInfo object. 1916 // and a SharedFunctionInfo object.
1880 void LiveEditFunctionTracker::FunctionDone(Handle<SharedFunctionInfo> shared, 1917 void LiveEditFunctionTracker::FunctionDone(Handle<SharedFunctionInfo> shared,
1881 Scope* scope) { 1918 Scope* scope) {
1882 HandleScope handle_scope(isolate_); 1919 HandleScope handle_scope(isolate_);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1915 scope_info_length++; 1952 scope_info_length++;
1916 1953
1917 current_scope = current_scope->outer_scope(); 1954 current_scope = current_scope->outer_scope();
1918 } 1955 }
1919 1956
1920 return scope_info_list; 1957 return scope_info_list;
1921 } 1958 }
1922 1959
1923 } // namespace internal 1960 } // namespace internal
1924 } // namespace v8 1961 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698