| 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 void FunctionInfoWrapper::SetInitialProperties( | 607 void FunctionInfoWrapper::SetInitialProperties(Handle<String> name, |
| 608 Handle<String> name, int start_position, int end_position, int param_num, | 608 int start_position, |
| 609 int literal_count, int parent_index, int function_literal_id) { | 609 int end_position, int param_num, |
| 610 int parent_index, |
| 611 int function_literal_id) { |
| 610 HandleScope scope(isolate()); | 612 HandleScope scope(isolate()); |
| 611 this->SetField(kFunctionNameOffset_, name); | 613 this->SetField(kFunctionNameOffset_, name); |
| 612 this->SetSmiValueField(kStartPositionOffset_, start_position); | 614 this->SetSmiValueField(kStartPositionOffset_, start_position); |
| 613 this->SetSmiValueField(kEndPositionOffset_, end_position); | 615 this->SetSmiValueField(kEndPositionOffset_, end_position); |
| 614 this->SetSmiValueField(kParamNumOffset_, param_num); | 616 this->SetSmiValueField(kParamNumOffset_, param_num); |
| 615 this->SetSmiValueField(kLiteralNumOffset_, literal_count); | 617 this->SetSmiValueField(kLiteralNumOffset, 0); |
| 616 this->SetSmiValueField(kParentIndexOffset_, parent_index); | 618 this->SetSmiValueField(kParentIndexOffset_, parent_index); |
| 617 this->SetSmiValueField(kFunctionLiteralIdOffset_, function_literal_id); | 619 this->SetSmiValueField(kFunctionLiteralIdOffset_, function_literal_id); |
| 618 } | 620 } |
| 619 | 621 |
| 620 void FunctionInfoWrapper::SetSharedFunctionInfo( | 622 void FunctionInfoWrapper::SetSharedFunctionInfo( |
| 621 Handle<SharedFunctionInfo> info) { | 623 Handle<SharedFunctionInfo> info) { |
| 622 Handle<JSValue> info_holder = WrapInJSValue(info); | 624 Handle<JSValue> info_holder = WrapInJSValue(info); |
| 623 this->SetField(kSharedFunctionInfoOffset_, info_holder); | 625 this->SetField(kSharedFunctionInfoOffset_, info_holder); |
| 624 } | 626 } |
| 625 | 627 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 744 | 746 |
| 745 // Patch function feedback vector. | 747 // Patch function feedback vector. |
| 746 // The feedback vector is a cache for complex object boilerplates and for a | 748 // The feedback vector is a cache for complex object boilerplates and for a |
| 747 // native context. We must clean cached values, or if the structure of the | 749 // native context. We must clean cached values, or if the structure of the |
| 748 // vector itself changes we need to allocate a new one. | 750 // vector itself changes we need to allocate a new one. |
| 749 class FeedbackVectorFixer { | 751 class FeedbackVectorFixer { |
| 750 public: | 752 public: |
| 751 static void PatchFeedbackVector(FunctionInfoWrapper* compile_info_wrapper, | 753 static void PatchFeedbackVector(FunctionInfoWrapper* compile_info_wrapper, |
| 752 Handle<SharedFunctionInfo> shared_info, | 754 Handle<SharedFunctionInfo> shared_info, |
| 753 Isolate* isolate) { | 755 Isolate* isolate) { |
| 754 int new_literal_count = compile_info_wrapper->GetLiteralCount(); | |
| 755 | |
| 756 // When feedback metadata changes, we have to create new array instances. | 756 // When feedback metadata changes, we have to create new array instances. |
| 757 // Since we cannot create instances when iterating heap, we should first | 757 // Since we cannot create instances when iterating heap, we should first |
| 758 // collect all functions and fix their literal arrays. | 758 // collect all functions and fix their literal arrays. |
| 759 Handle<FixedArray> function_instances = | 759 Handle<FixedArray> function_instances = |
| 760 CollectJSFunctions(shared_info, isolate); | 760 CollectJSFunctions(shared_info, isolate); |
| 761 | 761 |
| 762 for (int i = 0; i < function_instances->length(); i++) { | 762 for (int i = 0; i < function_instances->length(); i++) { |
| 763 Handle<JSFunction> fun(JSFunction::cast(function_instances->get(i))); | 763 Handle<JSFunction> fun(JSFunction::cast(function_instances->get(i))); |
| 764 Handle<Cell> new_cell = isolate->factory()->NewManyClosuresCell( | 764 Handle<Cell> new_cell = isolate->factory()->NewManyClosuresCell( |
| 765 isolate->factory()->undefined_value()); | 765 isolate->factory()->undefined_value()); |
| 766 fun->set_feedback_vector_cell(*new_cell); | 766 fun->set_feedback_vector_cell(*new_cell); |
| 767 // Only create feedback vectors if we already have the metadata. | 767 // Only create feedback vectors if we already have the metadata. |
| 768 if (shared_info->is_compiled()) JSFunction::EnsureLiterals(fun); | 768 if (shared_info->is_compiled()) JSFunction::EnsureLiterals(fun); |
| 769 } | 769 } |
| 770 | |
| 771 shared_info->set_num_literals(new_literal_count); | |
| 772 } | 770 } |
| 773 | 771 |
| 774 private: | 772 private: |
| 775 // Iterates all function instances in the HEAP that refers to the | 773 // Iterates all function instances in the HEAP that refers to the |
| 776 // provided shared_info. | 774 // provided shared_info. |
| 777 template<typename Visitor> | 775 template<typename Visitor> |
| 778 static void IterateJSFunctions(Handle<SharedFunctionInfo> shared_info, | 776 static void IterateJSFunctions(Handle<SharedFunctionInfo> shared_info, |
| 779 Visitor* visitor) { | 777 Visitor* visitor) { |
| 780 HeapIterator iterator(shared_info->GetHeap()); | 778 HeapIterator iterator(shared_info->GetHeap()); |
| 781 for (HeapObject* obj = iterator.next(); obj != NULL; | 779 for (HeapObject* obj = iterator.next(); obj != NULL; |
| (...skipping 812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1594 Handle<SharedFunctionInfo> info = | 1592 Handle<SharedFunctionInfo> info = |
| 1595 script_->FindSharedFunctionInfo(isolate_, node).ToHandleChecked(); | 1593 script_->FindSharedFunctionInfo(isolate_, node).ToHandleChecked(); |
| 1596 FunctionDone(info, node->scope()); | 1594 FunctionDone(info, node->scope()); |
| 1597 } | 1595 } |
| 1598 | 1596 |
| 1599 void LiveEditFunctionTracker::FunctionStarted(FunctionLiteral* fun) { | 1597 void LiveEditFunctionTracker::FunctionStarted(FunctionLiteral* fun) { |
| 1600 HandleScope handle_scope(isolate_); | 1598 HandleScope handle_scope(isolate_); |
| 1601 FunctionInfoWrapper info = FunctionInfoWrapper::Create(isolate_); | 1599 FunctionInfoWrapper info = FunctionInfoWrapper::Create(isolate_); |
| 1602 info.SetInitialProperties(fun->name(), fun->start_position(), | 1600 info.SetInitialProperties(fun->name(), fun->start_position(), |
| 1603 fun->end_position(), fun->parameter_count(), | 1601 fun->end_position(), fun->parameter_count(), |
| 1604 fun->materialized_literal_count(), | |
| 1605 current_parent_index_, fun->function_literal_id()); | 1602 current_parent_index_, fun->function_literal_id()); |
| 1606 current_parent_index_ = len_; | 1603 current_parent_index_ = len_; |
| 1607 SetElementSloppy(result_, len_, info.GetJSArray()); | 1604 SetElementSloppy(result_, len_, info.GetJSArray()); |
| 1608 len_++; | 1605 len_++; |
| 1609 } | 1606 } |
| 1610 | 1607 |
| 1611 // Saves full information about a function: its code, its scope info | 1608 // Saves full information about a function: its code, its scope info |
| 1612 // and a SharedFunctionInfo object. | 1609 // and a SharedFunctionInfo object. |
| 1613 void LiveEditFunctionTracker::FunctionDone(Handle<SharedFunctionInfo> shared, | 1610 void LiveEditFunctionTracker::FunctionDone(Handle<SharedFunctionInfo> shared, |
| 1614 Scope* scope) { | 1611 Scope* scope) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1648 scope_info_length++; | 1645 scope_info_length++; |
| 1649 | 1646 |
| 1650 current_scope = current_scope->outer_scope(); | 1647 current_scope = current_scope->outer_scope(); |
| 1651 } | 1648 } |
| 1652 | 1649 |
| 1653 return scope_info_list; | 1650 return scope_info_list; |
| 1654 } | 1651 } |
| 1655 | 1652 |
| 1656 } // namespace internal | 1653 } // namespace internal |
| 1657 } // namespace v8 | 1654 } // namespace v8 |
| OLD | NEW |