Chromium Code Reviews| 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 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 613 int parent_index) { | 613 int parent_index) { |
| 614 HandleScope scope(isolate()); | 614 HandleScope scope(isolate()); |
| 615 this->SetField(kFunctionNameOffset_, name); | 615 this->SetField(kFunctionNameOffset_, name); |
| 616 this->SetSmiValueField(kStartPositionOffset_, start_position); | 616 this->SetSmiValueField(kStartPositionOffset_, start_position); |
| 617 this->SetSmiValueField(kEndPositionOffset_, end_position); | 617 this->SetSmiValueField(kEndPositionOffset_, end_position); |
| 618 this->SetSmiValueField(kParamNumOffset_, param_num); | 618 this->SetSmiValueField(kParamNumOffset_, param_num); |
| 619 this->SetSmiValueField(kLiteralNumOffset_, literal_count); | 619 this->SetSmiValueField(kLiteralNumOffset_, literal_count); |
| 620 this->SetSmiValueField(kParentIndexOffset_, parent_index); | 620 this->SetSmiValueField(kParentIndexOffset_, parent_index); |
| 621 } | 621 } |
| 622 | 622 |
| 623 void FunctionInfoWrapper::SetFunctionCode(Handle<AbstractCode> function_code, | |
| 624 Handle<HeapObject> code_scope_info) { | |
| 625 // CompileForLiveEdit must deliver full-codegen code. | |
| 626 Handle<JSValue> code_wrapper = WrapInJSValue(function_code); | |
| 627 this->SetField(kCodeOffset_, code_wrapper); | |
| 628 | |
| 629 Handle<JSValue> scope_wrapper = WrapInJSValue(code_scope_info); | |
| 630 this->SetField(kCodeScopeInfoOffset_, scope_wrapper); | |
| 631 } | |
| 632 | |
| 633 | |
| 634 void FunctionInfoWrapper::SetSharedFunctionInfo( | 623 void FunctionInfoWrapper::SetSharedFunctionInfo( |
| 635 Handle<SharedFunctionInfo> info) { | 624 Handle<SharedFunctionInfo> info) { |
| 636 Handle<JSValue> info_holder = WrapInJSValue(info); | 625 Handle<JSValue> info_holder = WrapInJSValue(info); |
| 637 this->SetField(kSharedFunctionInfoOffset_, info_holder); | 626 this->SetField(kSharedFunctionInfoOffset_, info_holder); |
| 638 } | 627 } |
| 639 | 628 |
| 640 Handle<AbstractCode> FunctionInfoWrapper::GetFunctionCode() { | 629 Handle<SharedFunctionInfo> FunctionInfoWrapper::GetSharedFunctionInfo() { |
| 641 Handle<Object> element = this->GetField(kCodeOffset_); | 630 Handle<Object> element = this->GetField(kSharedFunctionInfoOffset_); |
| 642 Handle<JSValue> value_wrapper = Handle<JSValue>::cast(element); | 631 Handle<JSValue> value_wrapper = Handle<JSValue>::cast(element); |
| 643 Handle<Object> raw_result = UnwrapJSValue(value_wrapper); | 632 Handle<Object> raw_result = UnwrapJSValue(value_wrapper); |
| 644 CHECK(raw_result->IsAbstractCode()); | 633 CHECK(raw_result->IsSharedFunctionInfo()); |
| 645 return Handle<AbstractCode>::cast(raw_result); | 634 return Handle<SharedFunctionInfo>::cast(raw_result); |
| 646 } | 635 } |
| 647 | 636 |
| 648 MaybeHandle<TypeFeedbackMetadata> FunctionInfoWrapper::GetFeedbackMetadata() { | |
| 649 Handle<Object> element = this->GetField(kSharedFunctionInfoOffset_); | |
| 650 if (element->IsJSValue()) { | |
| 651 Handle<JSValue> value_wrapper = Handle<JSValue>::cast(element); | |
| 652 Handle<Object> raw_result = UnwrapJSValue(value_wrapper); | |
| 653 Handle<SharedFunctionInfo> shared = | |
| 654 Handle<SharedFunctionInfo>::cast(raw_result); | |
| 655 return Handle<TypeFeedbackMetadata>(shared->feedback_metadata(), isolate()); | |
| 656 } else { | |
| 657 // Scripts may never have a SharedFunctionInfo created. | |
| 658 return MaybeHandle<TypeFeedbackMetadata>(); | |
| 659 } | |
| 660 } | |
| 661 | |
| 662 | |
| 663 Handle<Object> FunctionInfoWrapper::GetCodeScopeInfo() { | |
| 664 Handle<Object> element = this->GetField(kCodeScopeInfoOffset_); | |
| 665 return UnwrapJSValue(Handle<JSValue>::cast(element)); | |
| 666 } | |
| 667 | |
| 668 | |
| 669 void SharedInfoWrapper::SetProperties(Handle<String> name, | 637 void SharedInfoWrapper::SetProperties(Handle<String> name, |
| 670 int start_position, | 638 int start_position, |
| 671 int end_position, | 639 int end_position, |
| 672 Handle<SharedFunctionInfo> info) { | 640 Handle<SharedFunctionInfo> info) { |
| 673 HandleScope scope(isolate()); | 641 HandleScope scope(isolate()); |
| 674 this->SetField(kFunctionNameOffset_, name); | 642 this->SetField(kFunctionNameOffset_, name); |
| 675 Handle<JSValue> info_holder = WrapInJSValue(info); | 643 Handle<JSValue> info_holder = WrapInJSValue(info); |
| 676 this->SetField(kSharedInfoOffset_, info_holder); | 644 this->SetField(kSharedInfoOffset_, info_holder); |
| 677 this->SetSmiValueField(kStartPositionOffset_, start_position); | 645 this->SetSmiValueField(kStartPositionOffset_, start_position); |
| 678 this->SetSmiValueField(kEndPositionOffset_, end_position); | 646 this->SetSmiValueField(kEndPositionOffset_, end_position); |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 998 | 966 |
| 999 void LiveEdit::ReplaceFunctionCode( | 967 void LiveEdit::ReplaceFunctionCode( |
| 1000 Handle<JSArray> new_compile_info_array, | 968 Handle<JSArray> new_compile_info_array, |
| 1001 Handle<JSArray> shared_info_array) { | 969 Handle<JSArray> shared_info_array) { |
| 1002 Isolate* isolate = new_compile_info_array->GetIsolate(); | 970 Isolate* isolate = new_compile_info_array->GetIsolate(); |
| 1003 | 971 |
| 1004 FunctionInfoWrapper compile_info_wrapper(new_compile_info_array); | 972 FunctionInfoWrapper compile_info_wrapper(new_compile_info_array); |
| 1005 SharedInfoWrapper shared_info_wrapper(shared_info_array); | 973 SharedInfoWrapper shared_info_wrapper(shared_info_array); |
| 1006 | 974 |
| 1007 Handle<SharedFunctionInfo> shared_info = shared_info_wrapper.GetInfo(); | 975 Handle<SharedFunctionInfo> shared_info = shared_info_wrapper.GetInfo(); |
| 976 Handle<SharedFunctionInfo> new_shared_info = | |
| 977 compile_info_wrapper.GetSharedFunctionInfo(); | |
| 1008 bool feedback_metadata_changed = false; | 978 bool feedback_metadata_changed = false; |
| 1009 | 979 |
| 1010 if (shared_info->is_compiled()) { | 980 if (shared_info->is_compiled()) { |
| 1011 Handle<AbstractCode> new_code = compile_info_wrapper.GetFunctionCode(); | 981 // Take whatever code we can get from the new shared function info. We |
| 1012 if (shared_info->HasBytecodeArray()) { | 982 // expect activations of neither the old bytecode nor old FCG code, since |
| 1013 DCHECK(new_code->IsBytecodeArray()); | 983 // the lowest activation is going to be restarted. |
| 1014 // The old code is interpreted, the new code must be interpreted as well. | 984 Handle<Code> old_code(shared_info->code()); |
| 1015 shared_info->ClearBytecodeArray(); | 985 Handle<Code> new_code(new_shared_info->code()); |
| 1016 shared_info->set_bytecode_array(BytecodeArray::cast(*new_code)); | 986 // Clear old bytecode. This will trigger self-healing if we do not install |
| 987 // new bytecode. | |
| 988 shared_info->ClearBytecodeArray(); | |
| 989 if (old_code->is_interpreter_trampoline_builtin()) { | |
| 990 // Every function from this SFI is interpreted. | |
| 991 if (new_code->is_interpreter_trampoline_builtin()) { | |
| 992 // We have newly compiled bytecode. Simply replace the old one. | |
| 993 shared_info->set_bytecode_array(new_shared_info->bytecode_array()); | |
| 994 } else { | |
| 995 // Rely on self-healing for places that used to run bytecode. | |
| 996 shared_info->ReplaceCode(*new_code); | |
|
jgruber
2016/08/05 12:54:50
Why is this different from below (ReplaceCode vs.
Yang
2016/08/05 12:59:47
We use SharedFunctionInfo::ReplaceCode here becaus
| |
| 997 } | |
| 1017 } else { | 998 } else { |
| 1018 Handle<Code> old_code(shared_info->code()); | 999 // Functions from this SFI can be either interpreted or running FCG. |
| 1019 DCHECK(old_code->kind() == Code::FUNCTION); | 1000 DCHECK(old_code->kind() == Code::FUNCTION); |
| 1020 DCHECK(new_code->kind() == AbstractCode::FUNCTION); | 1001 if (new_shared_info->HasBytecodeArray()) { |
|
jgruber
2016/08/05 12:54:50
Does this mean that new_code->is_interpreter_tramp
Yang
2016/08/05 12:59:47
No. This is not equivalent. is_interpreter_trampol
| |
| 1021 ReplaceCodeObject(old_code, Handle<Code>::cast(new_code)); | 1002 // Start using new bytecode everywhere. |
| 1003 shared_info->set_bytecode_array(new_shared_info->bytecode_array()); | |
| 1004 ReplaceCodeObject(old_code, | |
| 1005 isolate->builtins()->InterpreterEntryTrampoline()); | |
| 1006 } else { | |
| 1007 // Start using new FCG code everywhere. | |
| 1008 // Rely on self-healing for places that used to run bytecode. | |
| 1009 DCHECK(new_code->kind() == Code::FUNCTION); | |
| 1010 ReplaceCodeObject(old_code, new_code); | |
| 1011 } | |
| 1022 } | 1012 } |
| 1013 | |
| 1023 if (shared_info->HasDebugInfo()) { | 1014 if (shared_info->HasDebugInfo()) { |
| 1024 // Existing break points will be re-applied. Reset the debug info here. | 1015 // Existing break points will be re-applied. Reset the debug info here. |
| 1025 isolate->debug()->RemoveDebugInfoAndClearFromShared( | 1016 isolate->debug()->RemoveDebugInfoAndClearFromShared( |
| 1026 handle(shared_info->GetDebugInfo())); | 1017 handle(shared_info->GetDebugInfo())); |
| 1027 } | 1018 } |
| 1028 Handle<Object> code_scope_info = compile_info_wrapper.GetCodeScopeInfo(); | 1019 shared_info->set_scope_info(new_shared_info->scope_info()); |
| 1029 if (code_scope_info->IsFixedArray()) { | |
| 1030 shared_info->set_scope_info(ScopeInfo::cast(*code_scope_info)); | |
| 1031 } | |
| 1032 shared_info->DisableOptimization(kLiveEdit); | 1020 shared_info->DisableOptimization(kLiveEdit); |
| 1033 // Update the type feedback vector, if needed. | 1021 // Update the type feedback vector, if needed. |
| 1034 MaybeHandle<TypeFeedbackMetadata> feedback_metadata = | 1022 Handle<TypeFeedbackMetadata> new_feedback_metadata( |
| 1035 compile_info_wrapper.GetFeedbackMetadata(); | 1023 new_shared_info->feedback_metadata()); |
| 1036 if (!feedback_metadata.is_null()) { | 1024 feedback_metadata_changed = |
| 1037 Handle<TypeFeedbackMetadata> checked_feedback_metadata = | 1025 new_feedback_metadata->DiffersFrom(shared_info->feedback_metadata()); |
| 1038 feedback_metadata.ToHandleChecked(); | 1026 shared_info->set_feedback_metadata(*new_feedback_metadata); |
| 1039 feedback_metadata_changed = checked_feedback_metadata->DiffersFrom( | |
| 1040 shared_info->feedback_metadata()); | |
| 1041 shared_info->set_feedback_metadata(*checked_feedback_metadata); | |
| 1042 } | |
| 1043 } | 1027 } |
| 1044 | 1028 |
| 1045 int start_position = compile_info_wrapper.GetStartPosition(); | 1029 int start_position = compile_info_wrapper.GetStartPosition(); |
| 1046 int end_position = compile_info_wrapper.GetEndPosition(); | 1030 int end_position = compile_info_wrapper.GetEndPosition(); |
| 1047 shared_info->set_start_position(start_position); | 1031 shared_info->set_start_position(start_position); |
| 1048 shared_info->set_end_position(end_position); | 1032 shared_info->set_end_position(end_position); |
| 1049 | 1033 |
| 1050 LiteralFixer::PatchLiterals(&compile_info_wrapper, shared_info, | 1034 LiteralFixer::PatchLiterals(&compile_info_wrapper, shared_info, |
| 1051 feedback_metadata_changed, isolate); | 1035 feedback_metadata_changed, isolate); |
| 1052 | 1036 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1147 position_change_array); | 1131 position_change_array); |
| 1148 int new_function_end = TranslatePosition(info->end_position(), | 1132 int new_function_end = TranslatePosition(info->end_position(), |
| 1149 position_change_array); | 1133 position_change_array); |
| 1150 int new_function_token_pos = | 1134 int new_function_token_pos = |
| 1151 TranslatePosition(info->function_token_position(), position_change_array); | 1135 TranslatePosition(info->function_token_position(), position_change_array); |
| 1152 | 1136 |
| 1153 info->set_start_position(new_function_start); | 1137 info->set_start_position(new_function_start); |
| 1154 info->set_end_position(new_function_end); | 1138 info->set_end_position(new_function_end); |
| 1155 info->set_function_token_position(new_function_token_pos); | 1139 info->set_function_token_position(new_function_token_pos); |
| 1156 | 1140 |
| 1157 if (info->code()->kind() == Code::FUNCTION) { | 1141 if (info->HasBytecodeArray()) { |
| 1158 Handle<ByteArray> new_source_position_table = TranslateSourcePositionTable( | |
| 1159 Handle<ByteArray>(info->code()->source_position_table()), | |
| 1160 position_change_array); | |
| 1161 info->code()->set_source_position_table(*new_source_position_table); | |
| 1162 } else if (info->HasBytecodeArray()) { | |
| 1163 Handle<ByteArray> new_source_position_table = TranslateSourcePositionTable( | 1142 Handle<ByteArray> new_source_position_table = TranslateSourcePositionTable( |
| 1164 Handle<ByteArray>(info->bytecode_array()->source_position_table()), | 1143 Handle<ByteArray>(info->bytecode_array()->source_position_table()), |
| 1165 position_change_array); | 1144 position_change_array); |
| 1166 info->bytecode_array()->set_source_position_table( | 1145 info->bytecode_array()->set_source_position_table( |
| 1167 *new_source_position_table); | 1146 *new_source_position_table); |
| 1168 } | 1147 } |
| 1169 | 1148 if (info->code()->kind() == Code::FUNCTION) { |
| 1149 Handle<ByteArray> new_source_position_table = TranslateSourcePositionTable( | |
| 1150 Handle<ByteArray>(info->code()->source_position_table()), | |
| 1151 position_change_array); | |
| 1152 info->code()->set_source_position_table(*new_source_position_table); | |
| 1153 } | |
| 1170 if (info->HasDebugInfo()) { | 1154 if (info->HasDebugInfo()) { |
| 1171 // Existing break points will be re-applied. Reset the debug info here. | 1155 // Existing break points will be re-applied. Reset the debug info here. |
| 1172 info->GetIsolate()->debug()->RemoveDebugInfoAndClearFromShared( | 1156 info->GetIsolate()->debug()->RemoveDebugInfoAndClearFromShared( |
| 1173 handle(info->GetDebugInfo())); | 1157 handle(info->GetDebugInfo())); |
| 1174 } | 1158 } |
| 1175 } | 1159 } |
| 1176 | 1160 |
| 1177 | 1161 |
| 1178 static Handle<Script> CreateScriptCopy(Handle<Script> original) { | 1162 static Handle<Script> CreateScriptCopy(Handle<Script> original) { |
| 1179 Isolate* isolate = original->GetIsolate(); | 1163 Isolate* isolate = original->GetIsolate(); |
| (...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1891 } | 1875 } |
| 1892 | 1876 |
| 1893 // Saves full information about a function: its code, its scope info | 1877 // Saves full information about a function: its code, its scope info |
| 1894 // and a SharedFunctionInfo object. | 1878 // and a SharedFunctionInfo object. |
| 1895 void LiveEditFunctionTracker::FunctionDone(Handle<SharedFunctionInfo> shared, | 1879 void LiveEditFunctionTracker::FunctionDone(Handle<SharedFunctionInfo> shared, |
| 1896 Scope* scope) { | 1880 Scope* scope) { |
| 1897 HandleScope handle_scope(isolate_); | 1881 HandleScope handle_scope(isolate_); |
| 1898 FunctionInfoWrapper info = FunctionInfoWrapper::cast( | 1882 FunctionInfoWrapper info = FunctionInfoWrapper::cast( |
| 1899 *JSReceiver::GetElement(isolate_, result_, current_parent_index_) | 1883 *JSReceiver::GetElement(isolate_, result_, current_parent_index_) |
| 1900 .ToHandleChecked()); | 1884 .ToHandleChecked()); |
| 1901 info.SetFunctionCode(Handle<AbstractCode>(shared->abstract_code()), | |
| 1902 Handle<HeapObject>(shared->scope_info())); | |
| 1903 info.SetSharedFunctionInfo(shared); | 1885 info.SetSharedFunctionInfo(shared); |
| 1904 | 1886 |
| 1905 Handle<Object> scope_info_list = SerializeFunctionScope(scope); | 1887 Handle<Object> scope_info_list = SerializeFunctionScope(scope); |
| 1906 info.SetFunctionScopeInfo(scope_info_list); | 1888 info.SetFunctionScopeInfo(scope_info_list); |
| 1907 | 1889 |
| 1908 current_parent_index_ = info.GetParentIndex(); | 1890 current_parent_index_ = info.GetParentIndex(); |
| 1909 } | 1891 } |
| 1910 | 1892 |
| 1911 Handle<Object> LiveEditFunctionTracker::SerializeFunctionScope(Scope* scope) { | 1893 Handle<Object> LiveEditFunctionTracker::SerializeFunctionScope(Scope* scope) { |
| 1912 Handle<JSArray> scope_info_list = isolate_->factory()->NewJSArray(10); | 1894 Handle<JSArray> scope_info_list = isolate_->factory()->NewJSArray(10); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 1940 scope_info_length++; | 1922 scope_info_length++; |
| 1941 | 1923 |
| 1942 current_scope = current_scope->outer_scope(); | 1924 current_scope = current_scope->outer_scope(); |
| 1943 } | 1925 } |
| 1944 | 1926 |
| 1945 return scope_info_list; | 1927 return scope_info_list; |
| 1946 } | 1928 } |
| 1947 | 1929 |
| 1948 } // namespace internal | 1930 } // namespace internal |
| 1949 } // namespace v8 | 1931 } // namespace v8 |
| OLD | NEW |