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

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

Issue 1906823002: Move of the type feedback vector to the closure. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: REBASE. Created 4 years, 6 months 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/factory.cc » ('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/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 631 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 642
643 643
644 Handle<Code> FunctionInfoWrapper::GetFunctionCode() { 644 Handle<Code> FunctionInfoWrapper::GetFunctionCode() {
645 Handle<Object> element = this->GetField(kCodeOffset_); 645 Handle<Object> element = this->GetField(kCodeOffset_);
646 Handle<JSValue> value_wrapper = Handle<JSValue>::cast(element); 646 Handle<JSValue> value_wrapper = Handle<JSValue>::cast(element);
647 Handle<Object> raw_result = UnwrapJSValue(value_wrapper); 647 Handle<Object> raw_result = UnwrapJSValue(value_wrapper);
648 CHECK(raw_result->IsCode()); 648 CHECK(raw_result->IsCode());
649 return Handle<Code>::cast(raw_result); 649 return Handle<Code>::cast(raw_result);
650 } 650 }
651 651
652 652 MaybeHandle<TypeFeedbackMetadata> FunctionInfoWrapper::GetFeedbackMetadata() {
653 MaybeHandle<TypeFeedbackVector> FunctionInfoWrapper::GetFeedbackVector() {
654 Handle<Object> element = this->GetField(kSharedFunctionInfoOffset_); 653 Handle<Object> element = this->GetField(kSharedFunctionInfoOffset_);
655 if (element->IsJSValue()) { 654 if (element->IsJSValue()) {
656 Handle<JSValue> value_wrapper = Handle<JSValue>::cast(element); 655 Handle<JSValue> value_wrapper = Handle<JSValue>::cast(element);
657 Handle<Object> raw_result = UnwrapJSValue(value_wrapper); 656 Handle<Object> raw_result = UnwrapJSValue(value_wrapper);
658 Handle<SharedFunctionInfo> shared = 657 Handle<SharedFunctionInfo> shared =
659 Handle<SharedFunctionInfo>::cast(raw_result); 658 Handle<SharedFunctionInfo>::cast(raw_result);
660 return Handle<TypeFeedbackVector>(shared->feedback_vector(), isolate()); 659 return Handle<TypeFeedbackMetadata>(shared->feedback_metadata(), isolate());
661 } else { 660 } else {
662 // Scripts may never have a SharedFunctionInfo created. 661 // Scripts may never have a SharedFunctionInfo created.
663 return MaybeHandle<TypeFeedbackVector>(); 662 return MaybeHandle<TypeFeedbackMetadata>();
664 } 663 }
665 } 664 }
666 665
667 666
668 Handle<Object> FunctionInfoWrapper::GetCodeScopeInfo() { 667 Handle<Object> FunctionInfoWrapper::GetCodeScopeInfo() {
669 Handle<Object> element = this->GetField(kCodeScopeInfoOffset_); 668 Handle<Object> element = this->GetField(kCodeScopeInfoOffset_);
670 return UnwrapJSValue(Handle<JSValue>::cast(element)); 669 return UnwrapJSValue(Handle<JSValue>::cast(element));
671 } 670 }
672 671
673 672
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 855
857 // Patch function literals. 856 // Patch function literals.
858 // Name 'literals' is a misnomer. Rather it's a cache for complex object 857 // Name 'literals' is a misnomer. Rather it's a cache for complex object
859 // boilerplates and for a native context. We must clean cached values. 858 // boilerplates and for a native context. We must clean cached values.
860 // Additionally we may need to allocate a new array if number of literals 859 // Additionally we may need to allocate a new array if number of literals
861 // changed. 860 // changed.
862 class LiteralFixer { 861 class LiteralFixer {
863 public: 862 public:
864 static void PatchLiterals(FunctionInfoWrapper* compile_info_wrapper, 863 static void PatchLiterals(FunctionInfoWrapper* compile_info_wrapper,
865 Handle<SharedFunctionInfo> shared_info, 864 Handle<SharedFunctionInfo> shared_info,
866 Isolate* isolate) { 865 bool feedback_metadata_changed, Isolate* isolate) {
867 int new_literal_count = compile_info_wrapper->GetLiteralCount(); 866 int new_literal_count = compile_info_wrapper->GetLiteralCount();
868 int old_literal_count = shared_info->num_literals(); 867 int old_literal_count = shared_info->num_literals();
869 868
870 if (old_literal_count == new_literal_count) { 869 if (old_literal_count == new_literal_count && !feedback_metadata_changed) {
871 // If literal count didn't change, simply go over all functions 870 // If literal count didn't change, simply go over all functions
872 // and clear literal arrays. 871 // and clear literal arrays.
873 ClearValuesVisitor visitor; 872 ClearValuesVisitor visitor;
874 IterateJSFunctions(shared_info, &visitor); 873 IterateJSFunctions(shared_info, &visitor);
875 } else { 874 } else {
876 // When literal count changes, we have to create new array instances. 875 // When literal count changes, we have to create new array instances.
877 // Since we cannot create instances when iterating heap, we should first 876 // Since we cannot create instances when iterating heap, we should first
878 // collect all functions and fix their literal arrays. 877 // collect all functions and fix their literal arrays.
879 Handle<FixedArray> function_instances = 878 Handle<FixedArray> function_instances =
880 CollectJSFunctions(shared_info, isolate); 879 CollectJSFunctions(shared_info, isolate);
881 Handle<TypeFeedbackVector> vector(shared_info->feedback_vector()); 880 Handle<TypeFeedbackMetadata> feedback_metadata(
881 shared_info->feedback_metadata());
882 882
883 for (int i = 0; i < function_instances->length(); i++) { 883 for (int i = 0; i < function_instances->length(); i++) {
884 Handle<JSFunction> fun(JSFunction::cast(function_instances->get(i))); 884 Handle<JSFunction> fun(JSFunction::cast(function_instances->get(i)));
885 Handle<TypeFeedbackVector> vector =
886 TypeFeedbackVector::New(isolate, feedback_metadata);
885 Handle<LiteralsArray> new_literals = 887 Handle<LiteralsArray> new_literals =
886 LiteralsArray::New(isolate, vector, new_literal_count, TENURED); 888 LiteralsArray::New(isolate, vector, new_literal_count, TENURED);
887 fun->set_literals(*new_literals); 889 fun->set_literals(*new_literals);
888 } 890 }
889 891
890 shared_info->set_num_literals(new_literal_count); 892 shared_info->set_num_literals(new_literal_count);
891 } 893 }
892 } 894 }
893 895
894 private: 896 private:
(...skipping 27 matching lines...) Expand all
922 if (size > 0) { 924 if (size > 0) {
923 CollectVisitor collect_visitor(result); 925 CollectVisitor collect_visitor(result);
924 IterateJSFunctions(shared_info, &collect_visitor); 926 IterateJSFunctions(shared_info, &collect_visitor);
925 } 927 }
926 return result; 928 return result;
927 } 929 }
928 930
929 class ClearValuesVisitor { 931 class ClearValuesVisitor {
930 public: 932 public:
931 void visit(JSFunction* fun) { 933 void visit(JSFunction* fun) {
932 FixedArray* literals = fun->literals(); 934 LiteralsArray* literals = fun->literals();
933 int len = literals->length(); 935 int len = literals->literals_count();
934 for (int j = 0; j < len; j++) { 936 for (int j = 0; j < len; j++) {
935 literals->set_undefined(j); 937 literals->set_literal_undefined(j);
936 } 938 }
937 } 939 }
938 }; 940 };
939 941
940 class CountVisitor { 942 class CountVisitor {
941 public: 943 public:
942 void visit(JSFunction* fun) { 944 void visit(JSFunction* fun) {
943 count++; 945 count++;
944 } 946 }
945 int count; 947 int count;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1000 1002
1001 void LiveEdit::ReplaceFunctionCode( 1003 void LiveEdit::ReplaceFunctionCode(
1002 Handle<JSArray> new_compile_info_array, 1004 Handle<JSArray> new_compile_info_array,
1003 Handle<JSArray> shared_info_array) { 1005 Handle<JSArray> shared_info_array) {
1004 Isolate* isolate = new_compile_info_array->GetIsolate(); 1006 Isolate* isolate = new_compile_info_array->GetIsolate();
1005 1007
1006 FunctionInfoWrapper compile_info_wrapper(new_compile_info_array); 1008 FunctionInfoWrapper compile_info_wrapper(new_compile_info_array);
1007 SharedInfoWrapper shared_info_wrapper(shared_info_array); 1009 SharedInfoWrapper shared_info_wrapper(shared_info_array);
1008 1010
1009 Handle<SharedFunctionInfo> shared_info = shared_info_wrapper.GetInfo(); 1011 Handle<SharedFunctionInfo> shared_info = shared_info_wrapper.GetInfo();
1012 bool feedback_metadata_changed = false;
1010 1013
1011 if (shared_info->is_compiled()) { 1014 if (shared_info->is_compiled()) {
1012 Handle<Code> new_code = compile_info_wrapper.GetFunctionCode(); 1015 Handle<Code> new_code = compile_info_wrapper.GetFunctionCode();
1013 Handle<Code> old_code(shared_info->code()); 1016 Handle<Code> old_code(shared_info->code());
1014 if (shared_info->HasBytecodeArray()) { 1017 if (shared_info->HasBytecodeArray()) {
1015 // The old code is interpreted. If we clear the bytecode array, the 1018 // The old code is interpreted. If we clear the bytecode array, the
1016 // interpreter entry trampoline will self-heal and go to compiled code. 1019 // interpreter entry trampoline will self-heal and go to compiled code.
1017 shared_info->ClearBytecodeArray(); 1020 shared_info->ClearBytecodeArray();
1018 shared_info->ReplaceCode(*new_code); 1021 shared_info->ReplaceCode(*new_code);
1019 } else { 1022 } else {
1020 DCHECK(old_code->kind() == Code::FUNCTION); 1023 DCHECK(old_code->kind() == Code::FUNCTION);
1021 ReplaceCodeObject(old_code, new_code); 1024 ReplaceCodeObject(old_code, new_code);
1022 } 1025 }
1023 if (shared_info->HasDebugInfo()) { 1026 if (shared_info->HasDebugInfo()) {
1024 // Existing break points will be re-applied. Reset the debug info here. 1027 // Existing break points will be re-applied. Reset the debug info here.
1025 isolate->debug()->RemoveDebugInfoAndClearFromShared( 1028 isolate->debug()->RemoveDebugInfoAndClearFromShared(
1026 handle(shared_info->GetDebugInfo())); 1029 handle(shared_info->GetDebugInfo()));
1027 } 1030 }
1028 Handle<Object> code_scope_info = compile_info_wrapper.GetCodeScopeInfo(); 1031 Handle<Object> code_scope_info = compile_info_wrapper.GetCodeScopeInfo();
1029 if (code_scope_info->IsFixedArray()) { 1032 if (code_scope_info->IsFixedArray()) {
1030 shared_info->set_scope_info(ScopeInfo::cast(*code_scope_info)); 1033 shared_info->set_scope_info(ScopeInfo::cast(*code_scope_info));
1031 } 1034 }
1032 shared_info->DisableOptimization(kLiveEdit); 1035 shared_info->DisableOptimization(kLiveEdit);
1033 // Update the type feedback vector, if needed. 1036 // Update the type feedback vector, if needed.
1034 MaybeHandle<TypeFeedbackVector> feedback_vector = 1037 MaybeHandle<TypeFeedbackMetadata> feedback_metadata =
1035 compile_info_wrapper.GetFeedbackVector(); 1038 compile_info_wrapper.GetFeedbackMetadata();
1036 if (!feedback_vector.is_null()) { 1039 if (!feedback_metadata.is_null()) {
1037 shared_info->set_feedback_vector(*feedback_vector.ToHandleChecked()); 1040 Handle<TypeFeedbackMetadata> checked_feedback_metadata =
1041 feedback_metadata.ToHandleChecked();
1042 feedback_metadata_changed = checked_feedback_metadata->DiffersFrom(
1043 shared_info->feedback_metadata());
1044 shared_info->set_feedback_metadata(*checked_feedback_metadata);
1038 } 1045 }
1039 } 1046 }
1040 1047
1041 int start_position = compile_info_wrapper.GetStartPosition(); 1048 int start_position = compile_info_wrapper.GetStartPosition();
1042 int end_position = compile_info_wrapper.GetEndPosition(); 1049 int end_position = compile_info_wrapper.GetEndPosition();
1043 shared_info->set_start_position(start_position); 1050 shared_info->set_start_position(start_position);
1044 shared_info->set_end_position(end_position); 1051 shared_info->set_end_position(end_position);
1045 1052
1046 LiteralFixer::PatchLiterals(&compile_info_wrapper, shared_info, isolate); 1053 LiteralFixer::PatchLiterals(&compile_info_wrapper, shared_info,
1054 feedback_metadata_changed, isolate);
1047 1055
1048 DeoptimizeDependentFunctions(*shared_info); 1056 DeoptimizeDependentFunctions(*shared_info);
1049 isolate->compilation_cache()->Remove(shared_info); 1057 isolate->compilation_cache()->Remove(shared_info);
1050 } 1058 }
1051 1059
1052 1060
1053 void LiveEdit::FunctionSourceUpdated(Handle<JSArray> shared_info_array) { 1061 void LiveEdit::FunctionSourceUpdated(Handle<JSArray> shared_info_array) {
1054 SharedInfoWrapper shared_info_wrapper(shared_info_array); 1062 SharedInfoWrapper shared_info_wrapper(shared_info_array);
1055 Handle<SharedFunctionInfo> shared_info = shared_info_wrapper.GetInfo(); 1063 Handle<SharedFunctionInfo> shared_info = shared_info_wrapper.GetInfo();
1056 1064
(...skipping 978 matching lines...) Expand 10 before | Expand all | Expand 10 after
2035 scope_info_length++; 2043 scope_info_length++;
2036 2044
2037 current_scope = current_scope->outer_scope(); 2045 current_scope = current_scope->outer_scope();
2038 } 2046 }
2039 2047
2040 return scope_info_list; 2048 return scope_info_list;
2041 } 2049 }
2042 2050
2043 } // namespace internal 2051 } // namespace internal
2044 } // namespace v8 2052 } // namespace v8
OLDNEW
« no previous file with comments | « src/debug/liveedit.h ('k') | src/factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698