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/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 Loading... |
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 Loading... |
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( |
| 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 } |
1050 | 1069 |
1051 void LiveEdit::SetFunctionScript(Handle<JSValue> function_wrapper, | 1070 void LiveEdit::SetFunctionScript(Handle<JSValue> function_wrapper, |
1052 Handle<Object> script_handle) { | 1071 Handle<Object> script_handle) { |
1053 Handle<SharedFunctionInfo> shared_info = | 1072 Handle<SharedFunctionInfo> shared_info = |
1054 UnwrapSharedFunctionInfoFromJSValue(function_wrapper); | 1073 UnwrapSharedFunctionInfoFromJSValue(function_wrapper); |
1055 Isolate* isolate = function_wrapper->GetIsolate(); | 1074 Isolate* isolate = function_wrapper->GetIsolate(); |
1056 CHECK(script_handle->IsScript() || script_handle->IsUndefined(isolate)); | 1075 CHECK(script_handle->IsScript() || script_handle->IsUndefined(isolate)); |
1057 SharedFunctionInfo::SetScript(shared_info, script_handle); | 1076 SharedFunctionInfo::SetScript(shared_info, script_handle); |
1058 shared_info->DisableOptimization(kLiveEdit); | 1077 shared_info->DisableOptimization(kLiveEdit); |
1059 | 1078 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1166 Handle<Script> copy = isolate->factory()->NewScript(original_source); | 1185 Handle<Script> copy = isolate->factory()->NewScript(original_source); |
1167 | 1186 |
1168 copy->set_name(original->name()); | 1187 copy->set_name(original->name()); |
1169 copy->set_line_offset(original->line_offset()); | 1188 copy->set_line_offset(original->line_offset()); |
1170 copy->set_column_offset(original->column_offset()); | 1189 copy->set_column_offset(original->column_offset()); |
1171 copy->set_type(original->type()); | 1190 copy->set_type(original->type()); |
1172 copy->set_context_data(original->context_data()); | 1191 copy->set_context_data(original->context_data()); |
1173 copy->set_eval_from_shared(original->eval_from_shared()); | 1192 copy->set_eval_from_shared(original->eval_from_shared()); |
1174 copy->set_eval_from_position(original->eval_from_position()); | 1193 copy->set_eval_from_position(original->eval_from_position()); |
1175 | 1194 |
| 1195 Handle<FixedArray> infos(isolate->factory()->NewFixedArray( |
| 1196 original->shared_function_infos()->length())); |
| 1197 copy->set_shared_function_infos(*infos); |
| 1198 |
1176 // Copy all the flags, but clear compilation state. | 1199 // Copy all the flags, but clear compilation state. |
1177 copy->set_flags(original->flags()); | 1200 copy->set_flags(original->flags()); |
1178 copy->set_compilation_state(Script::COMPILATION_STATE_INITIAL); | 1201 copy->set_compilation_state(Script::COMPILATION_STATE_INITIAL); |
1179 | 1202 |
1180 return copy; | 1203 return copy; |
1181 } | 1204 } |
1182 | 1205 |
1183 | |
1184 Handle<Object> LiveEdit::ChangeScriptSource(Handle<Script> original_script, | 1206 Handle<Object> LiveEdit::ChangeScriptSource(Handle<Script> original_script, |
1185 Handle<String> new_source, | 1207 Handle<String> new_source, |
1186 Handle<Object> old_script_name) { | 1208 Handle<Object> old_script_name) { |
1187 Isolate* isolate = original_script->GetIsolate(); | 1209 Isolate* isolate = original_script->GetIsolate(); |
1188 Handle<Object> old_script_object; | 1210 Handle<Object> old_script_object; |
1189 if (old_script_name->IsString()) { | 1211 if (old_script_name->IsString()) { |
1190 Handle<Script> old_script = CreateScriptCopy(original_script); | 1212 Handle<Script> old_script = CreateScriptCopy(original_script); |
1191 old_script->set_name(String::cast(*old_script_name)); | 1213 old_script->set_name(String::cast(*old_script_name)); |
1192 old_script_object = old_script; | 1214 old_script_object = old_script; |
1193 isolate->debug()->OnAfterCompile(old_script); | 1215 isolate->debug()->OnAfterCompile(old_script); |
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1849 script_ = script; | 1871 script_ = script; |
1850 zone_ = zone; | 1872 zone_ = zone; |
1851 } | 1873 } |
1852 | 1874 |
1853 void LiveEditFunctionTracker::VisitFunctionLiteral(FunctionLiteral* node) { | 1875 void LiveEditFunctionTracker::VisitFunctionLiteral(FunctionLiteral* node) { |
1854 // FunctionStarted is called in pre-order. | 1876 // FunctionStarted is called in pre-order. |
1855 FunctionStarted(node); | 1877 FunctionStarted(node); |
1856 // Recurse using the regular traversal. | 1878 // Recurse using the regular traversal. |
1857 AstTraversalVisitor::VisitFunctionLiteral(node); | 1879 AstTraversalVisitor::VisitFunctionLiteral(node); |
1858 // FunctionDone are called in post-order. | 1880 // 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 = | 1881 Handle<SharedFunctionInfo> info = |
1862 script_->FindSharedFunctionInfo(node).ToHandleChecked(); | 1882 script_->FindSharedFunctionInfo(isolate_, node).ToHandleChecked(); |
1863 FunctionDone(info, node->scope()); | 1883 FunctionDone(info, node->scope()); |
1864 } | 1884 } |
1865 | 1885 |
1866 void LiveEditFunctionTracker::FunctionStarted(FunctionLiteral* fun) { | 1886 void LiveEditFunctionTracker::FunctionStarted(FunctionLiteral* fun) { |
1867 HandleScope handle_scope(isolate_); | 1887 HandleScope handle_scope(isolate_); |
1868 FunctionInfoWrapper info = FunctionInfoWrapper::Create(isolate_); | 1888 FunctionInfoWrapper info = FunctionInfoWrapper::Create(isolate_); |
1869 info.SetInitialProperties(fun->name(), fun->start_position(), | 1889 info.SetInitialProperties(fun->name(), fun->start_position(), |
1870 fun->end_position(), fun->parameter_count(), | 1890 fun->end_position(), fun->parameter_count(), |
1871 fun->materialized_literal_count(), | 1891 fun->materialized_literal_count(), |
1872 current_parent_index_); | 1892 current_parent_index_, fun->function_literal_id()); |
1873 current_parent_index_ = len_; | 1893 current_parent_index_ = len_; |
1874 SetElementSloppy(result_, len_, info.GetJSArray()); | 1894 SetElementSloppy(result_, len_, info.GetJSArray()); |
1875 len_++; | 1895 len_++; |
1876 } | 1896 } |
1877 | 1897 |
1878 // Saves full information about a function: its code, its scope info | 1898 // Saves full information about a function: its code, its scope info |
1879 // and a SharedFunctionInfo object. | 1899 // and a SharedFunctionInfo object. |
1880 void LiveEditFunctionTracker::FunctionDone(Handle<SharedFunctionInfo> shared, | 1900 void LiveEditFunctionTracker::FunctionDone(Handle<SharedFunctionInfo> shared, |
1881 Scope* scope) { | 1901 Scope* scope) { |
1882 HandleScope handle_scope(isolate_); | 1902 HandleScope handle_scope(isolate_); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1915 scope_info_length++; | 1935 scope_info_length++; |
1916 | 1936 |
1917 current_scope = current_scope->outer_scope(); | 1937 current_scope = current_scope->outer_scope(); |
1918 } | 1938 } |
1919 | 1939 |
1920 return scope_info_list; | 1940 return scope_info_list; |
1921 } | 1941 } |
1922 | 1942 |
1923 } // namespace internal | 1943 } // namespace internal |
1924 } // namespace v8 | 1944 } // namespace v8 |
OLD | NEW |