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 628 matching lines...) Loading... |
639 | 639 |
640 | 640 |
641 Handle<Code> FunctionInfoWrapper::GetFunctionCode() { | 641 Handle<Code> FunctionInfoWrapper::GetFunctionCode() { |
642 Handle<Object> element = this->GetField(kCodeOffset_); | 642 Handle<Object> element = this->GetField(kCodeOffset_); |
643 Handle<JSValue> value_wrapper = Handle<JSValue>::cast(element); | 643 Handle<JSValue> value_wrapper = Handle<JSValue>::cast(element); |
644 Handle<Object> raw_result = UnwrapJSValue(value_wrapper); | 644 Handle<Object> raw_result = UnwrapJSValue(value_wrapper); |
645 CHECK(raw_result->IsCode()); | 645 CHECK(raw_result->IsCode()); |
646 return Handle<Code>::cast(raw_result); | 646 return Handle<Code>::cast(raw_result); |
647 } | 647 } |
648 | 648 |
649 | 649 MaybeHandle<TypeFeedbackMetadata> FunctionInfoWrapper::GetFeedbackMetadata() { |
650 MaybeHandle<TypeFeedbackVector> FunctionInfoWrapper::GetFeedbackVector() { | |
651 Handle<Object> element = this->GetField(kSharedFunctionInfoOffset_); | 650 Handle<Object> element = this->GetField(kSharedFunctionInfoOffset_); |
652 if (element->IsJSValue()) { | 651 if (element->IsJSValue()) { |
653 Handle<JSValue> value_wrapper = Handle<JSValue>::cast(element); | 652 Handle<JSValue> value_wrapper = Handle<JSValue>::cast(element); |
654 Handle<Object> raw_result = UnwrapJSValue(value_wrapper); | 653 Handle<Object> raw_result = UnwrapJSValue(value_wrapper); |
655 Handle<SharedFunctionInfo> shared = | 654 Handle<SharedFunctionInfo> shared = |
656 Handle<SharedFunctionInfo>::cast(raw_result); | 655 Handle<SharedFunctionInfo>::cast(raw_result); |
657 return Handle<TypeFeedbackVector>(shared->feedback_vector(), isolate()); | 656 return Handle<TypeFeedbackMetadata>(shared->feedback_metadata(), isolate()); |
658 } else { | 657 } else { |
659 // Scripts may never have a SharedFunctionInfo created. | 658 // Scripts may never have a SharedFunctionInfo created. |
660 return MaybeHandle<TypeFeedbackVector>(); | 659 return MaybeHandle<TypeFeedbackMetadata>(); |
661 } | 660 } |
662 } | 661 } |
663 | 662 |
664 | 663 |
665 Handle<Object> FunctionInfoWrapper::GetCodeScopeInfo() { | 664 Handle<Object> FunctionInfoWrapper::GetCodeScopeInfo() { |
666 Handle<Object> element = this->GetField(kCodeScopeInfoOffset_); | 665 Handle<Object> element = this->GetField(kCodeScopeInfoOffset_); |
667 return UnwrapJSValue(Handle<JSValue>::cast(element)); | 666 return UnwrapJSValue(Handle<JSValue>::cast(element)); |
668 } | 667 } |
669 | 668 |
670 | 669 |
(...skipping 283 matching lines...) Loading... |
954 | 953 |
955 // Patch function literals. | 954 // Patch function literals. |
956 // Name 'literals' is a misnomer. Rather it's a cache for complex object | 955 // Name 'literals' is a misnomer. Rather it's a cache for complex object |
957 // boilerplates and for a native context. We must clean cached values. | 956 // boilerplates and for a native context. We must clean cached values. |
958 // Additionally we may need to allocate a new array if number of literals | 957 // Additionally we may need to allocate a new array if number of literals |
959 // changed. | 958 // changed. |
960 class LiteralFixer { | 959 class LiteralFixer { |
961 public: | 960 public: |
962 static void PatchLiterals(FunctionInfoWrapper* compile_info_wrapper, | 961 static void PatchLiterals(FunctionInfoWrapper* compile_info_wrapper, |
963 Handle<SharedFunctionInfo> shared_info, | 962 Handle<SharedFunctionInfo> shared_info, |
964 Isolate* isolate) { | 963 bool feedback_metadata_changed, Isolate* isolate) { |
965 int new_literal_count = compile_info_wrapper->GetLiteralCount(); | 964 int new_literal_count = compile_info_wrapper->GetLiteralCount(); |
966 int old_literal_count = shared_info->num_literals(); | 965 int old_literal_count = shared_info->num_literals(); |
967 | 966 |
968 if (old_literal_count == new_literal_count) { | 967 if (old_literal_count == new_literal_count && !feedback_metadata_changed) { |
969 // If literal count didn't change, simply go over all functions | 968 // If literal count didn't change, simply go over all functions |
970 // and clear literal arrays. | 969 // and clear literal arrays. |
971 ClearValuesVisitor visitor; | 970 ClearValuesVisitor visitor; |
972 IterateJSFunctions(shared_info, &visitor); | 971 IterateJSFunctions(shared_info, &visitor); |
973 } else { | 972 } else { |
974 // When literal count changes, we have to create new array instances. | 973 // When literal count changes, we have to create new array instances. |
975 // Since we cannot create instances when iterating heap, we should first | 974 // Since we cannot create instances when iterating heap, we should first |
976 // collect all functions and fix their literal arrays. | 975 // collect all functions and fix their literal arrays. |
977 Handle<FixedArray> function_instances = | 976 Handle<FixedArray> function_instances = |
978 CollectJSFunctions(shared_info, isolate); | 977 CollectJSFunctions(shared_info, isolate); |
979 Handle<TypeFeedbackVector> vector(shared_info->feedback_vector()); | 978 Handle<TypeFeedbackMetadata> feedback_metadata( |
| 979 shared_info->feedback_metadata()); |
980 | 980 |
981 for (int i = 0; i < function_instances->length(); i++) { | 981 for (int i = 0; i < function_instances->length(); i++) { |
982 Handle<JSFunction> fun(JSFunction::cast(function_instances->get(i))); | 982 Handle<JSFunction> fun(JSFunction::cast(function_instances->get(i))); |
| 983 Handle<TypeFeedbackVector> vector = |
| 984 TypeFeedbackVector::New(isolate, feedback_metadata); |
983 Handle<LiteralsArray> new_literals = | 985 Handle<LiteralsArray> new_literals = |
984 LiteralsArray::New(isolate, vector, new_literal_count, TENURED); | 986 LiteralsArray::New(isolate, vector, new_literal_count, TENURED); |
985 fun->set_literals(*new_literals); | 987 fun->set_literals(*new_literals); |
986 } | 988 } |
987 | 989 |
988 shared_info->set_num_literals(new_literal_count); | 990 shared_info->set_num_literals(new_literal_count); |
989 } | 991 } |
990 } | 992 } |
991 | 993 |
992 private: | 994 private: |
(...skipping 27 matching lines...) Loading... |
1020 if (size > 0) { | 1022 if (size > 0) { |
1021 CollectVisitor collect_visitor(result); | 1023 CollectVisitor collect_visitor(result); |
1022 IterateJSFunctions(shared_info, &collect_visitor); | 1024 IterateJSFunctions(shared_info, &collect_visitor); |
1023 } | 1025 } |
1024 return result; | 1026 return result; |
1025 } | 1027 } |
1026 | 1028 |
1027 class ClearValuesVisitor { | 1029 class ClearValuesVisitor { |
1028 public: | 1030 public: |
1029 void visit(JSFunction* fun) { | 1031 void visit(JSFunction* fun) { |
1030 FixedArray* literals = fun->literals(); | 1032 LiteralsArray* literals = fun->literals(); |
1031 int len = literals->length(); | 1033 int len = literals->literals_count(); |
1032 for (int j = 0; j < len; j++) { | 1034 for (int j = 0; j < len; j++) { |
1033 literals->set_undefined(j); | 1035 literals->set_literal_undefined(j); |
1034 } | 1036 } |
1035 } | 1037 } |
1036 }; | 1038 }; |
1037 | 1039 |
1038 class CountVisitor { | 1040 class CountVisitor { |
1039 public: | 1041 public: |
1040 void visit(JSFunction* fun) { | 1042 void visit(JSFunction* fun) { |
1041 count++; | 1043 count++; |
1042 } | 1044 } |
1043 int count; | 1045 int count; |
(...skipping 54 matching lines...) Loading... |
1098 | 1100 |
1099 void LiveEdit::ReplaceFunctionCode( | 1101 void LiveEdit::ReplaceFunctionCode( |
1100 Handle<JSArray> new_compile_info_array, | 1102 Handle<JSArray> new_compile_info_array, |
1101 Handle<JSArray> shared_info_array) { | 1103 Handle<JSArray> shared_info_array) { |
1102 Isolate* isolate = new_compile_info_array->GetIsolate(); | 1104 Isolate* isolate = new_compile_info_array->GetIsolate(); |
1103 | 1105 |
1104 FunctionInfoWrapper compile_info_wrapper(new_compile_info_array); | 1106 FunctionInfoWrapper compile_info_wrapper(new_compile_info_array); |
1105 SharedInfoWrapper shared_info_wrapper(shared_info_array); | 1107 SharedInfoWrapper shared_info_wrapper(shared_info_array); |
1106 | 1108 |
1107 Handle<SharedFunctionInfo> shared_info = shared_info_wrapper.GetInfo(); | 1109 Handle<SharedFunctionInfo> shared_info = shared_info_wrapper.GetInfo(); |
| 1110 bool feedback_metadata_changed = false; |
1108 | 1111 |
1109 if (shared_info->code()->kind() == Code::FUNCTION) { | 1112 if (shared_info->code()->kind() == Code::FUNCTION) { |
1110 Handle<Code> code = compile_info_wrapper.GetFunctionCode(); | 1113 Handle<Code> code = compile_info_wrapper.GetFunctionCode(); |
1111 ReplaceCodeObject(Handle<Code>(shared_info->code()), code); | 1114 ReplaceCodeObject(Handle<Code>(shared_info->code()), code); |
1112 Handle<Object> code_scope_info = compile_info_wrapper.GetCodeScopeInfo(); | 1115 Handle<Object> code_scope_info = compile_info_wrapper.GetCodeScopeInfo(); |
1113 if (code_scope_info->IsFixedArray()) { | 1116 if (code_scope_info->IsFixedArray()) { |
1114 shared_info->set_scope_info(ScopeInfo::cast(*code_scope_info)); | 1117 shared_info->set_scope_info(ScopeInfo::cast(*code_scope_info)); |
1115 } | 1118 } |
1116 shared_info->DisableOptimization(kLiveEdit); | 1119 shared_info->DisableOptimization(kLiveEdit); |
1117 // Update the type feedback vector, if needed. | 1120 // Update the type feedback vector, if needed. |
1118 MaybeHandle<TypeFeedbackVector> feedback_vector = | 1121 MaybeHandle<TypeFeedbackMetadata> feedback_metadata = |
1119 compile_info_wrapper.GetFeedbackVector(); | 1122 compile_info_wrapper.GetFeedbackMetadata(); |
1120 if (!feedback_vector.is_null()) { | 1123 if (!feedback_metadata.is_null()) { |
1121 shared_info->set_feedback_vector(*feedback_vector.ToHandleChecked()); | 1124 Handle<TypeFeedbackMetadata> checked_feedback_metadata = |
| 1125 feedback_metadata.ToHandleChecked(); |
| 1126 feedback_metadata_changed = checked_feedback_metadata->DiffersFrom( |
| 1127 shared_info->feedback_metadata()); |
| 1128 shared_info->set_feedback_metadata(*checked_feedback_metadata); |
1122 } | 1129 } |
1123 } | 1130 } |
1124 | 1131 |
1125 int start_position = compile_info_wrapper.GetStartPosition(); | 1132 int start_position = compile_info_wrapper.GetStartPosition(); |
1126 int end_position = compile_info_wrapper.GetEndPosition(); | 1133 int end_position = compile_info_wrapper.GetEndPosition(); |
1127 shared_info->set_start_position(start_position); | 1134 shared_info->set_start_position(start_position); |
1128 shared_info->set_end_position(end_position); | 1135 shared_info->set_end_position(end_position); |
1129 | 1136 |
1130 LiteralFixer::PatchLiterals(&compile_info_wrapper, shared_info, isolate); | 1137 LiteralFixer::PatchLiterals(&compile_info_wrapper, shared_info, |
| 1138 feedback_metadata_changed, isolate); |
1131 | 1139 |
1132 DeoptimizeDependentFunctions(*shared_info); | 1140 DeoptimizeDependentFunctions(*shared_info); |
1133 isolate->compilation_cache()->Remove(shared_info); | 1141 isolate->compilation_cache()->Remove(shared_info); |
1134 } | 1142 } |
1135 | 1143 |
1136 | 1144 |
1137 void LiveEdit::FunctionSourceUpdated(Handle<JSArray> shared_info_array) { | 1145 void LiveEdit::FunctionSourceUpdated(Handle<JSArray> shared_info_array) { |
1138 SharedInfoWrapper shared_info_wrapper(shared_info_array); | 1146 SharedInfoWrapper shared_info_wrapper(shared_info_array); |
1139 Handle<SharedFunctionInfo> shared_info = shared_info_wrapper.GetInfo(); | 1147 Handle<SharedFunctionInfo> shared_info = shared_info_wrapper.GetInfo(); |
1140 | 1148 |
(...skipping 878 matching lines...) Loading... |
2019 } | 2027 } |
2020 } | 2028 } |
2021 | 2029 |
2022 | 2030 |
2023 bool LiveEditFunctionTracker::IsActive(Isolate* isolate) { | 2031 bool LiveEditFunctionTracker::IsActive(Isolate* isolate) { |
2024 return isolate->active_function_info_listener() != NULL; | 2032 return isolate->active_function_info_listener() != NULL; |
2025 } | 2033 } |
2026 | 2034 |
2027 } // namespace internal | 2035 } // namespace internal |
2028 } // namespace v8 | 2036 } // namespace v8 |
OLD | NEW |