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...) Expand 10 before | Expand all | Expand 10 after 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 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
967 | 966 |
968 // Patch function literals. | 967 // Patch function literals. |
969 // Name 'literals' is a misnomer. Rather it's a cache for complex object | 968 // Name 'literals' is a misnomer. Rather it's a cache for complex object |
970 // boilerplates and for a native context. We must clean cached values. | 969 // boilerplates and for a native context. We must clean cached values. |
971 // Additionally we may need to allocate a new array if number of literals | 970 // Additionally we may need to allocate a new array if number of literals |
972 // changed. | 971 // changed. |
973 class LiteralFixer { | 972 class LiteralFixer { |
974 public: | 973 public: |
975 static void PatchLiterals(FunctionInfoWrapper* compile_info_wrapper, | 974 static void PatchLiterals(FunctionInfoWrapper* compile_info_wrapper, |
976 Handle<SharedFunctionInfo> shared_info, | 975 Handle<SharedFunctionInfo> shared_info, |
977 Isolate* isolate) { | 976 bool feedback_metadata_changed, Isolate* isolate) { |
978 int new_literal_count = compile_info_wrapper->GetLiteralCount(); | 977 int new_literal_count = compile_info_wrapper->GetLiteralCount(); |
979 int old_literal_count = shared_info->num_literals(); | 978 int old_literal_count = shared_info->num_literals(); |
980 | 979 |
981 if (old_literal_count == new_literal_count) { | 980 if (old_literal_count == new_literal_count && !feedback_metadata_changed) { |
982 // If literal count didn't change, simply go over all functions | 981 // If literal count didn't change, simply go over all functions |
983 // and clear literal arrays. | 982 // and clear literal arrays. |
984 ClearValuesVisitor visitor; | 983 ClearValuesVisitor visitor; |
985 IterateJSFunctions(shared_info, &visitor); | 984 IterateJSFunctions(shared_info, &visitor); |
986 } else { | 985 } else { |
987 // When literal count changes, we have to create new array instances. | 986 // When literal count changes, we have to create new array instances. |
988 // Since we cannot create instances when iterating heap, we should first | 987 // Since we cannot create instances when iterating heap, we should first |
989 // collect all functions and fix their literal arrays. | 988 // collect all functions and fix their literal arrays. |
990 Handle<FixedArray> function_instances = | 989 Handle<FixedArray> function_instances = |
991 CollectJSFunctions(shared_info, isolate); | 990 CollectJSFunctions(shared_info, isolate); |
992 Handle<TypeFeedbackVector> vector(shared_info->feedback_vector()); | 991 Handle<TypeFeedbackMetadata> feedback_metadata( |
| 992 shared_info->feedback_metadata()); |
993 | 993 |
994 for (int i = 0; i < function_instances->length(); i++) { | 994 for (int i = 0; i < function_instances->length(); i++) { |
995 Handle<JSFunction> fun(JSFunction::cast(function_instances->get(i))); | 995 Handle<JSFunction> fun(JSFunction::cast(function_instances->get(i))); |
| 996 Handle<TypeFeedbackVector> vector = |
| 997 TypeFeedbackVector::New(isolate, feedback_metadata); |
996 Handle<LiteralsArray> new_literals = | 998 Handle<LiteralsArray> new_literals = |
997 LiteralsArray::New(isolate, vector, new_literal_count, TENURED); | 999 LiteralsArray::New(isolate, vector, new_literal_count, TENURED); |
998 fun->set_literals(*new_literals); | 1000 fun->set_literals(*new_literals); |
999 } | 1001 } |
1000 | 1002 |
1001 shared_info->set_num_literals(new_literal_count); | 1003 shared_info->set_num_literals(new_literal_count); |
1002 } | 1004 } |
1003 } | 1005 } |
1004 | 1006 |
1005 private: | 1007 private: |
(...skipping 27 matching lines...) Expand all Loading... |
1033 if (size > 0) { | 1035 if (size > 0) { |
1034 CollectVisitor collect_visitor(result); | 1036 CollectVisitor collect_visitor(result); |
1035 IterateJSFunctions(shared_info, &collect_visitor); | 1037 IterateJSFunctions(shared_info, &collect_visitor); |
1036 } | 1038 } |
1037 return result; | 1039 return result; |
1038 } | 1040 } |
1039 | 1041 |
1040 class ClearValuesVisitor { | 1042 class ClearValuesVisitor { |
1041 public: | 1043 public: |
1042 void visit(JSFunction* fun) { | 1044 void visit(JSFunction* fun) { |
1043 FixedArray* literals = fun->literals(); | 1045 LiteralsArray* literals = fun->literals(); |
1044 int len = literals->length(); | 1046 int len = literals->literals_count(); |
1045 for (int j = 0; j < len; j++) { | 1047 for (int j = 0; j < len; j++) { |
1046 literals->set_undefined(j); | 1048 literals->set_literal_undefined(j); |
1047 } | 1049 } |
1048 } | 1050 } |
1049 }; | 1051 }; |
1050 | 1052 |
1051 class CountVisitor { | 1053 class CountVisitor { |
1052 public: | 1054 public: |
1053 void visit(JSFunction* fun) { | 1055 void visit(JSFunction* fun) { |
1054 count++; | 1056 count++; |
1055 } | 1057 } |
1056 int count; | 1058 int count; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1111 | 1113 |
1112 void LiveEdit::ReplaceFunctionCode( | 1114 void LiveEdit::ReplaceFunctionCode( |
1113 Handle<JSArray> new_compile_info_array, | 1115 Handle<JSArray> new_compile_info_array, |
1114 Handle<JSArray> shared_info_array) { | 1116 Handle<JSArray> shared_info_array) { |
1115 Isolate* isolate = new_compile_info_array->GetIsolate(); | 1117 Isolate* isolate = new_compile_info_array->GetIsolate(); |
1116 | 1118 |
1117 FunctionInfoWrapper compile_info_wrapper(new_compile_info_array); | 1119 FunctionInfoWrapper compile_info_wrapper(new_compile_info_array); |
1118 SharedInfoWrapper shared_info_wrapper(shared_info_array); | 1120 SharedInfoWrapper shared_info_wrapper(shared_info_array); |
1119 | 1121 |
1120 Handle<SharedFunctionInfo> shared_info = shared_info_wrapper.GetInfo(); | 1122 Handle<SharedFunctionInfo> shared_info = shared_info_wrapper.GetInfo(); |
| 1123 bool feedback_metadata_changed = false; |
1121 | 1124 |
1122 if (shared_info->code()->kind() == Code::FUNCTION) { | 1125 if (shared_info->code()->kind() == Code::FUNCTION) { |
1123 Handle<Code> code = compile_info_wrapper.GetFunctionCode(); | 1126 Handle<Code> code = compile_info_wrapper.GetFunctionCode(); |
1124 ReplaceCodeObject(Handle<Code>(shared_info->code()), code); | 1127 ReplaceCodeObject(Handle<Code>(shared_info->code()), code); |
1125 Handle<Object> code_scope_info = compile_info_wrapper.GetCodeScopeInfo(); | 1128 Handle<Object> code_scope_info = compile_info_wrapper.GetCodeScopeInfo(); |
1126 if (code_scope_info->IsFixedArray()) { | 1129 if (code_scope_info->IsFixedArray()) { |
1127 shared_info->set_scope_info(ScopeInfo::cast(*code_scope_info)); | 1130 shared_info->set_scope_info(ScopeInfo::cast(*code_scope_info)); |
1128 } | 1131 } |
1129 shared_info->DisableOptimization(kLiveEdit); | 1132 shared_info->DisableOptimization(kLiveEdit); |
1130 // Update the type feedback vector, if needed. | 1133 // Update the type feedback vector, if needed. |
1131 MaybeHandle<TypeFeedbackVector> feedback_vector = | 1134 MaybeHandle<TypeFeedbackMetadata> feedback_metadata = |
1132 compile_info_wrapper.GetFeedbackVector(); | 1135 compile_info_wrapper.GetFeedbackMetadata(); |
1133 if (!feedback_vector.is_null()) { | 1136 if (!feedback_metadata.is_null()) { |
1134 shared_info->set_feedback_vector(*feedback_vector.ToHandleChecked()); | 1137 Handle<TypeFeedbackMetadata> checked_feedback_metadata = |
| 1138 feedback_metadata.ToHandleChecked(); |
| 1139 feedback_metadata_changed = checked_feedback_metadata->DiffersFrom( |
| 1140 shared_info->feedback_metadata()); |
| 1141 shared_info->set_feedback_metadata(*checked_feedback_metadata); |
1135 } | 1142 } |
1136 } | 1143 } |
1137 | 1144 |
1138 int start_position = compile_info_wrapper.GetStartPosition(); | 1145 int start_position = compile_info_wrapper.GetStartPosition(); |
1139 int end_position = compile_info_wrapper.GetEndPosition(); | 1146 int end_position = compile_info_wrapper.GetEndPosition(); |
1140 shared_info->set_start_position(start_position); | 1147 shared_info->set_start_position(start_position); |
1141 shared_info->set_end_position(end_position); | 1148 shared_info->set_end_position(end_position); |
1142 | 1149 |
1143 LiteralFixer::PatchLiterals(&compile_info_wrapper, shared_info, isolate); | 1150 LiteralFixer::PatchLiterals(&compile_info_wrapper, shared_info, |
| 1151 feedback_metadata_changed, isolate); |
1144 | 1152 |
1145 DeoptimizeDependentFunctions(*shared_info); | 1153 DeoptimizeDependentFunctions(*shared_info); |
1146 isolate->compilation_cache()->Remove(shared_info); | 1154 isolate->compilation_cache()->Remove(shared_info); |
1147 } | 1155 } |
1148 | 1156 |
1149 | 1157 |
1150 void LiveEdit::FunctionSourceUpdated(Handle<JSArray> shared_info_array) { | 1158 void LiveEdit::FunctionSourceUpdated(Handle<JSArray> shared_info_array) { |
1151 SharedInfoWrapper shared_info_wrapper(shared_info_array); | 1159 SharedInfoWrapper shared_info_wrapper(shared_info_array); |
1152 Handle<SharedFunctionInfo> shared_info = shared_info_wrapper.GetInfo(); | 1160 Handle<SharedFunctionInfo> shared_info = shared_info_wrapper.GetInfo(); |
1153 | 1161 |
(...skipping 883 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2037 isolate_->active_function_info_listener()->FunctionCode(code); | 2045 isolate_->active_function_info_listener()->FunctionCode(code); |
2038 } | 2046 } |
2039 | 2047 |
2040 | 2048 |
2041 bool LiveEditFunctionTracker::IsActive(Isolate* isolate) { | 2049 bool LiveEditFunctionTracker::IsActive(Isolate* isolate) { |
2042 return isolate->active_function_info_listener() != NULL; | 2050 return isolate->active_function_info_listener() != NULL; |
2043 } | 2051 } |
2044 | 2052 |
2045 } // namespace internal | 2053 } // namespace internal |
2046 } // namespace v8 | 2054 } // namespace v8 |
OLD | NEW |