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

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

Issue 2578433002: Revert of Store SharedFunctionInfos of a Script in a FixedArray indexed by their ID (Closed)
Patch Set: 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
« no previous file with comments | « src/debug/liveedit.h ('k') | src/debug/liveedit.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 void FunctionInfoWrapper::SetInitialProperties( 607
608 Handle<String> name, int start_position, int end_position, int param_num, 608 void FunctionInfoWrapper::SetInitialProperties(Handle<String> name,
609 int literal_count, int parent_index, int function_literal_id) { 609 int start_position,
610 int end_position, int param_num,
611 int literal_count,
612 int parent_index) {
610 HandleScope scope(isolate()); 613 HandleScope scope(isolate());
611 this->SetField(kFunctionNameOffset_, name); 614 this->SetField(kFunctionNameOffset_, name);
612 this->SetSmiValueField(kStartPositionOffset_, start_position); 615 this->SetSmiValueField(kStartPositionOffset_, start_position);
613 this->SetSmiValueField(kEndPositionOffset_, end_position); 616 this->SetSmiValueField(kEndPositionOffset_, end_position);
614 this->SetSmiValueField(kParamNumOffset_, param_num); 617 this->SetSmiValueField(kParamNumOffset_, param_num);
615 this->SetSmiValueField(kLiteralNumOffset_, literal_count); 618 this->SetSmiValueField(kLiteralNumOffset_, literal_count);
616 this->SetSmiValueField(kParentIndexOffset_, parent_index); 619 this->SetSmiValueField(kParentIndexOffset_, parent_index);
617 this->SetSmiValueField(kFunctionLiteralIdOffset_, function_literal_id);
618 } 620 }
619 621
620 void FunctionInfoWrapper::SetSharedFunctionInfo( 622 void FunctionInfoWrapper::SetSharedFunctionInfo(
621 Handle<SharedFunctionInfo> info) { 623 Handle<SharedFunctionInfo> info) {
622 Handle<JSValue> info_holder = WrapInJSValue(info); 624 Handle<JSValue> info_holder = WrapInJSValue(info);
623 this->SetField(kSharedFunctionInfoOffset_, info_holder); 625 this->SetField(kSharedFunctionInfoOffset_, info_holder);
624 } 626 }
625 627
626 Handle<SharedFunctionInfo> FunctionInfoWrapper::GetSharedFunctionInfo() { 628 Handle<SharedFunctionInfo> FunctionInfoWrapper::GetSharedFunctionInfo() {
627 Handle<Object> element = this->GetField(kSharedFunctionInfoOffset_); 629 Handle<Object> element = this->GetField(kSharedFunctionInfoOffset_);
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 shared_info->set_start_position(start_position); 1031 shared_info->set_start_position(start_position);
1030 shared_info->set_end_position(end_position); 1032 shared_info->set_end_position(end_position);
1031 1033
1032 LiteralFixer::PatchLiterals(&compile_info_wrapper, shared_info, 1034 LiteralFixer::PatchLiterals(&compile_info_wrapper, shared_info,
1033 feedback_metadata_changed, isolate); 1035 feedback_metadata_changed, isolate);
1034 1036
1035 DeoptimizeDependentFunctions(*shared_info); 1037 DeoptimizeDependentFunctions(*shared_info);
1036 isolate->compilation_cache()->Remove(shared_info); 1038 isolate->compilation_cache()->Remove(shared_info);
1037 } 1039 }
1038 1040
1039 void LiveEdit::FunctionSourceUpdated(Handle<JSArray> shared_info_array, 1041
1040 int new_function_literal_id) { 1042 void LiveEdit::FunctionSourceUpdated(Handle<JSArray> shared_info_array) {
1041 SharedInfoWrapper shared_info_wrapper(shared_info_array); 1043 SharedInfoWrapper shared_info_wrapper(shared_info_array);
1042 Handle<SharedFunctionInfo> shared_info = shared_info_wrapper.GetInfo(); 1044 Handle<SharedFunctionInfo> shared_info = shared_info_wrapper.GetInfo();
1043 1045
1044 shared_info->set_function_literal_id(new_function_literal_id);
1045 DeoptimizeDependentFunctions(*shared_info); 1046 DeoptimizeDependentFunctions(*shared_info);
1046 shared_info_array->GetIsolate()->compilation_cache()->Remove(shared_info); 1047 shared_info_array->GetIsolate()->compilation_cache()->Remove(shared_info);
1047 } 1048 }
1048 1049
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(
1053 isolate->factory()->NewFixedArray(max_function_literal_id + 1));
1054 script->set_shared_function_infos(*new_infos);
1055 SharedFunctionInfo::ScriptIterator iterator(isolate, old_infos);
1056 while (SharedFunctionInfo* shared = iterator.Next()) {
1057 // We can't use SharedFunctionInfo::SetScript(info, undefined_value()) here,
1058 // as we severed the link from the Script to the SharedFunctionInfo above.
1059 Handle<SharedFunctionInfo> info(shared, isolate);
1060 info->set_script(isolate->heap()->undefined_value());
1061 Handle<Object> new_noscript_list = WeakFixedArray::Add(
1062 isolate->factory()->noscript_shared_function_infos(), info);
1063 isolate->heap()->SetRootNoScriptSharedFunctionInfos(*new_noscript_list);
1064
1065 // Put the SharedFunctionInfo at its new, correct location.
1066 SharedFunctionInfo::SetScript(info, script);
1067 }
1068 }
1069 1050
1070 void LiveEdit::SetFunctionScript(Handle<JSValue> function_wrapper, 1051 void LiveEdit::SetFunctionScript(Handle<JSValue> function_wrapper,
1071 Handle<Object> script_handle) { 1052 Handle<Object> script_handle) {
1072 Handle<SharedFunctionInfo> shared_info = 1053 Handle<SharedFunctionInfo> shared_info =
1073 UnwrapSharedFunctionInfoFromJSValue(function_wrapper); 1054 UnwrapSharedFunctionInfoFromJSValue(function_wrapper);
1074 Isolate* isolate = function_wrapper->GetIsolate(); 1055 Isolate* isolate = function_wrapper->GetIsolate();
1075 CHECK(script_handle->IsScript() || script_handle->IsUndefined(isolate)); 1056 CHECK(script_handle->IsScript() || script_handle->IsUndefined(isolate));
1076 SharedFunctionInfo::SetScript(shared_info, script_handle); 1057 SharedFunctionInfo::SetScript(shared_info, script_handle);
1077 shared_info->DisableOptimization(kLiveEdit); 1058 shared_info->DisableOptimization(kLiveEdit);
1078 1059
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1185 Handle<Script> copy = isolate->factory()->NewScript(original_source); 1166 Handle<Script> copy = isolate->factory()->NewScript(original_source);
1186 1167
1187 copy->set_name(original->name()); 1168 copy->set_name(original->name());
1188 copy->set_line_offset(original->line_offset()); 1169 copy->set_line_offset(original->line_offset());
1189 copy->set_column_offset(original->column_offset()); 1170 copy->set_column_offset(original->column_offset());
1190 copy->set_type(original->type()); 1171 copy->set_type(original->type());
1191 copy->set_context_data(original->context_data()); 1172 copy->set_context_data(original->context_data());
1192 copy->set_eval_from_shared(original->eval_from_shared()); 1173 copy->set_eval_from_shared(original->eval_from_shared());
1193 copy->set_eval_from_position(original->eval_from_position()); 1174 copy->set_eval_from_position(original->eval_from_position());
1194 1175
1195 Handle<FixedArray> infos(isolate->factory()->NewFixedArray(
1196 original->shared_function_infos()->length()));
1197 copy->set_shared_function_infos(*infos);
1198
1199 // Copy all the flags, but clear compilation state. 1176 // Copy all the flags, but clear compilation state.
1200 copy->set_flags(original->flags()); 1177 copy->set_flags(original->flags());
1201 copy->set_compilation_state(Script::COMPILATION_STATE_INITIAL); 1178 copy->set_compilation_state(Script::COMPILATION_STATE_INITIAL);
1202 1179
1203 return copy; 1180 return copy;
1204 } 1181 }
1205 1182
1183
1206 Handle<Object> LiveEdit::ChangeScriptSource(Handle<Script> original_script, 1184 Handle<Object> LiveEdit::ChangeScriptSource(Handle<Script> original_script,
1207 Handle<String> new_source, 1185 Handle<String> new_source,
1208 Handle<Object> old_script_name) { 1186 Handle<Object> old_script_name) {
1209 Isolate* isolate = original_script->GetIsolate(); 1187 Isolate* isolate = original_script->GetIsolate();
1210 Handle<Object> old_script_object; 1188 Handle<Object> old_script_object;
1211 if (old_script_name->IsString()) { 1189 if (old_script_name->IsString()) {
1212 Handle<Script> old_script = CreateScriptCopy(original_script); 1190 Handle<Script> old_script = CreateScriptCopy(original_script);
1213 old_script->set_name(String::cast(*old_script_name)); 1191 old_script->set_name(String::cast(*old_script_name));
1214 old_script_object = old_script; 1192 old_script_object = old_script;
1215 isolate->debug()->OnAfterCompile(old_script); 1193 isolate->debug()->OnAfterCompile(old_script);
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after
1871 script_ = script; 1849 script_ = script;
1872 zone_ = zone; 1850 zone_ = zone;
1873 } 1851 }
1874 1852
1875 void LiveEditFunctionTracker::VisitFunctionLiteral(FunctionLiteral* node) { 1853 void LiveEditFunctionTracker::VisitFunctionLiteral(FunctionLiteral* node) {
1876 // FunctionStarted is called in pre-order. 1854 // FunctionStarted is called in pre-order.
1877 FunctionStarted(node); 1855 FunctionStarted(node);
1878 // Recurse using the regular traversal. 1856 // Recurse using the regular traversal.
1879 AstTraversalVisitor::VisitFunctionLiteral(node); 1857 AstTraversalVisitor::VisitFunctionLiteral(node);
1880 // FunctionDone are called in post-order. 1858 // FunctionDone are called in post-order.
1859 // TODO(jgruber): If required, replace the (linear cost)
1860 // FindSharedFunctionInfo call with a more efficient implementation.
1881 Handle<SharedFunctionInfo> info = 1861 Handle<SharedFunctionInfo> info =
1882 script_->FindSharedFunctionInfo(isolate_, node).ToHandleChecked(); 1862 script_->FindSharedFunctionInfo(node).ToHandleChecked();
1883 FunctionDone(info, node->scope()); 1863 FunctionDone(info, node->scope());
1884 } 1864 }
1885 1865
1886 void LiveEditFunctionTracker::FunctionStarted(FunctionLiteral* fun) { 1866 void LiveEditFunctionTracker::FunctionStarted(FunctionLiteral* fun) {
1887 HandleScope handle_scope(isolate_); 1867 HandleScope handle_scope(isolate_);
1888 FunctionInfoWrapper info = FunctionInfoWrapper::Create(isolate_); 1868 FunctionInfoWrapper info = FunctionInfoWrapper::Create(isolate_);
1889 info.SetInitialProperties(fun->name(), fun->start_position(), 1869 info.SetInitialProperties(fun->name(), fun->start_position(),
1890 fun->end_position(), fun->parameter_count(), 1870 fun->end_position(), fun->parameter_count(),
1891 fun->materialized_literal_count(), 1871 fun->materialized_literal_count(),
1892 current_parent_index_, fun->function_literal_id()); 1872 current_parent_index_);
1893 current_parent_index_ = len_; 1873 current_parent_index_ = len_;
1894 SetElementSloppy(result_, len_, info.GetJSArray()); 1874 SetElementSloppy(result_, len_, info.GetJSArray());
1895 len_++; 1875 len_++;
1896 } 1876 }
1897 1877
1898 // Saves full information about a function: its code, its scope info 1878 // Saves full information about a function: its code, its scope info
1899 // and a SharedFunctionInfo object. 1879 // and a SharedFunctionInfo object.
1900 void LiveEditFunctionTracker::FunctionDone(Handle<SharedFunctionInfo> shared, 1880 void LiveEditFunctionTracker::FunctionDone(Handle<SharedFunctionInfo> shared,
1901 Scope* scope) { 1881 Scope* scope) {
1902 HandleScope handle_scope(isolate_); 1882 HandleScope handle_scope(isolate_);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1935 scope_info_length++; 1915 scope_info_length++;
1936 1916
1937 current_scope = current_scope->outer_scope(); 1917 current_scope = current_scope->outer_scope();
1938 } 1918 }
1939 1919
1940 return scope_info_list; 1920 return scope_info_list;
1941 } 1921 }
1942 1922
1943 } // namespace internal 1923 } // namespace internal
1944 } // namespace v8 1924 } // namespace v8
OLDNEW
« no previous file with comments | « src/debug/liveedit.h ('k') | src/debug/liveedit.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698