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

Side by Side Diff: src/objects.cc

Issue 2547483002: Store SharedFunctionInfos of a Script in a FixedArray indexed by their ID (Closed)
Patch Set: updates Created 4 years 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
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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/objects.h" 5 #include "src/objects.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <iomanip> 8 #include <iomanip>
9 #include <memory> 9 #include <memory>
10 #include <sstream> 10 #include <sstream>
(...skipping 13624 matching lines...) Expand 10 before | Expand all | Expand 10 after
13635 isolate->counters()->script_wrappers()->Increment(); 13635 isolate->counters()->script_wrappers()->Increment();
13636 Handle<JSFunction> constructor = isolate->script_function(); 13636 Handle<JSFunction> constructor = isolate->script_function();
13637 Handle<JSValue> result = 13637 Handle<JSValue> result =
13638 Handle<JSValue>::cast(isolate->factory()->NewJSObject(constructor)); 13638 Handle<JSValue>::cast(isolate->factory()->NewJSObject(constructor));
13639 result->set_value(*script); 13639 result->set_value(*script);
13640 Handle<WeakCell> cell = isolate->factory()->NewWeakCell(result); 13640 Handle<WeakCell> cell = isolate->factory()->NewWeakCell(result);
13641 script->set_wrapper(*cell); 13641 script->set_wrapper(*cell);
13642 return result; 13642 return result;
13643 } 13643 }
13644 13644
13645
13646 MaybeHandle<SharedFunctionInfo> Script::FindSharedFunctionInfo( 13645 MaybeHandle<SharedFunctionInfo> Script::FindSharedFunctionInfo(
13647 FunctionLiteral* fun) { 13646 Isolate* isolate, FunctionLiteral* fun) {
13648 WeakFixedArray::Iterator iterator(shared_function_infos()); 13647 DCHECK_NE(fun->function_literal_id(), FunctionLiteral::kIdTypeInvalid);
13649 SharedFunctionInfo* shared; 13648 DCHECK_LT(fun->function_literal_id(), shared_function_infos()->length());
13650 while ((shared = iterator.Next<SharedFunctionInfo>())) { 13649 Object* shared = shared_function_infos()->get(fun->function_literal_id());
13651 if (fun->function_token_position() == shared->function_token_position() && 13650 if (shared->IsUndefined(isolate) || WeakCell::cast(shared)->cleared()) {
13652 fun->start_position() == shared->start_position() && 13651 return MaybeHandle<SharedFunctionInfo>();
13653 fun->end_position() == shared->end_position()) {
13654 DCHECK_EQ(fun->function_literal_id(), shared->function_literal_id());
13655 return Handle<SharedFunctionInfo>(shared);
13656 }
13657 DCHECK_NE(fun->function_literal_id(), shared->function_literal_id());
13658 } 13652 }
13659 return MaybeHandle<SharedFunctionInfo>(); 13653 return handle(SharedFunctionInfo::cast(WeakCell::cast(shared)->value()));
13660 } 13654 }
13661 13655
13662
13663 Script::Iterator::Iterator(Isolate* isolate) 13656 Script::Iterator::Iterator(Isolate* isolate)
13664 : iterator_(isolate->heap()->script_list()) {} 13657 : iterator_(isolate->heap()->script_list()) {}
13665 13658
13666 13659
13667 Script* Script::Iterator::Next() { return iterator_.Next<Script>(); } 13660 Script* Script::Iterator::Next() { return iterator_.Next<Script>(); }
13668 13661
13662 SharedFunctionInfo::ScriptIterator::ScriptIterator(Handle<Script> script)
13663 : ScriptIterator(script->GetIsolate(),
13664 handle(script->shared_function_infos())) {}
13669 13665
13670 SharedFunctionInfo::Iterator::Iterator(Isolate* isolate) 13666 SharedFunctionInfo::ScriptIterator::ScriptIterator(
13671 : script_iterator_(isolate), 13667 Isolate* isolate, Handle<FixedArray> shared_function_infos)
13672 sfi_iterator_(isolate->heap()->noscript_shared_function_infos()) {} 13668 : isolate_(isolate),
13669 shared_function_infos_(shared_function_infos),
13670 index_(0) {}
13673 13671
13674 13672 SharedFunctionInfo* SharedFunctionInfo::ScriptIterator::Next() {
13675 bool SharedFunctionInfo::Iterator::NextScript() { 13673 while (index_ < shared_function_infos_->length()) {
13676 Script* script = script_iterator_.Next(); 13674 Object* raw = shared_function_infos_->get(index_++);
13677 if (script == NULL) return false; 13675 if (raw->IsUndefined(isolate_) || WeakCell::cast(raw)->cleared()) continue;
13678 sfi_iterator_.Reset(script->shared_function_infos()); 13676 return SharedFunctionInfo::cast(WeakCell::cast(raw)->value());
13679 return true; 13677 }
13678 return nullptr;
13680 } 13679 }
13681 13680
13681 void SharedFunctionInfo::ScriptIterator::Reset(Handle<Script> script) {
13682 shared_function_infos_ = handle(script->shared_function_infos());
13683 index_ = 0;
13684 }
13682 13685
13683 SharedFunctionInfo* SharedFunctionInfo::Iterator::Next() { 13686 SharedFunctionInfo::GlobalIterator::GlobalIterator(Isolate* isolate)
13684 do { 13687 : script_iterator_(isolate),
13685 SharedFunctionInfo* next = sfi_iterator_.Next<SharedFunctionInfo>(); 13688 noscript_sfi_iterator_(isolate->heap()->noscript_shared_function_infos()),
13686 if (next != NULL) return next; 13689 sfi_iterator_(handle(script_iterator_.Next(), isolate)) {}
13687 } while (NextScript()); 13690
13688 return NULL; 13691 SharedFunctionInfo* SharedFunctionInfo::GlobalIterator::Next() {
13692 SharedFunctionInfo* next = noscript_sfi_iterator_.Next<SharedFunctionInfo>();
13693 if (next != nullptr) return next;
13694 for (;;) {
13695 next = sfi_iterator_.Next();
13696 if (next != nullptr) return next;
13697 Script* next_script = script_iterator_.Next();
13698 if (next_script == nullptr) return nullptr;
13699 sfi_iterator_.Reset(handle(next_script));
13700 }
13689 } 13701 }
13690 13702
13691 13703
13692 void SharedFunctionInfo::SetScript(Handle<SharedFunctionInfo> shared, 13704 void SharedFunctionInfo::SetScript(Handle<SharedFunctionInfo> shared,
13693 Handle<Object> script_object) { 13705 Handle<Object> script_object) {
13706 DCHECK_NE(shared->function_literal_id(), FunctionLiteral::kIdTypeInvalid);
13694 if (shared->script() == *script_object) return; 13707 if (shared->script() == *script_object) return;
13695 Isolate* isolate = shared->GetIsolate(); 13708 Isolate* isolate = shared->GetIsolate();
13696 13709
13697 // Add shared function info to new script's list. If a collection occurs, 13710 // Add shared function info to new script's list. If a collection occurs,
13698 // the shared function info may be temporarily in two lists. 13711 // the shared function info may be temporarily in two lists.
13699 // This is okay because the gc-time processing of these lists can tolerate 13712 // This is okay because the gc-time processing of these lists can tolerate
13700 // duplicates. 13713 // duplicates.
13701 Handle<Object> list;
13702 if (script_object->IsScript()) { 13714 if (script_object->IsScript()) {
13703 Handle<Script> script = Handle<Script>::cast(script_object); 13715 Handle<Script> script = Handle<Script>::cast(script_object);
13704 list = handle(script->shared_function_infos(), isolate); 13716 Handle<FixedArray> list = handle(script->shared_function_infos(), isolate);
13717 #ifdef DEBUG
13718 DCHECK_LT(shared->function_literal_id(), list->length());
13719 if (list->get(shared->function_literal_id())->IsWeakCell() &&
13720 !WeakCell::cast(list->get(shared->function_literal_id()))->cleared()) {
13721 DCHECK(
13722 WeakCell::cast(list->get(shared->function_literal_id()))->value() ==
13723 *shared);
13724 }
13725 #endif
13726 Handle<WeakCell> cell = isolate->factory()->NewWeakCell(shared);
13727 list->set(shared->function_literal_id(), *cell);
13705 } else { 13728 } else {
13706 list = isolate->factory()->noscript_shared_function_infos(); 13729 Handle<Object> list = isolate->factory()->noscript_shared_function_infos();
13707 }
13708 13730
13709 #ifdef DEBUG 13731 #ifdef DEBUG
13710 if (FLAG_enable_slow_asserts) { 13732 if (FLAG_enable_slow_asserts) {
13711 WeakFixedArray::Iterator iterator(*list); 13733 WeakFixedArray::Iterator iterator(*list);
13712 SharedFunctionInfo* next; 13734 SharedFunctionInfo* next;
13713 while ((next = iterator.Next<SharedFunctionInfo>())) { 13735 while ((next = iterator.Next<SharedFunctionInfo>())) {
13714 DCHECK_NE(next, *shared); 13736 DCHECK_NE(next, *shared);
13737 }
13715 } 13738 }
13716 }
13717 #endif // DEBUG 13739 #endif // DEBUG
13718 list = WeakFixedArray::Add(list, shared);
13719 13740
13720 if (script_object->IsScript()) { 13741 list = WeakFixedArray::Add(list, shared);
13721 Handle<Script> script = Handle<Script>::cast(script_object); 13742
13722 script->set_shared_function_infos(*list);
13723 } else {
13724 isolate->heap()->SetRootNoScriptSharedFunctionInfos(*list); 13743 isolate->heap()->SetRootNoScriptSharedFunctionInfos(*list);
13725 } 13744 }
13726 13745
13727 // Remove shared function info from old script's list.
13728 if (shared->script()->IsScript()) { 13746 if (shared->script()->IsScript()) {
13747 // Remove shared function info from old script's list.
13729 Script* old_script = Script::cast(shared->script()); 13748 Script* old_script = Script::cast(shared->script());
13730 if (old_script->shared_function_infos()->IsWeakFixedArray()) { 13749
13731 WeakFixedArray* list = 13750 // Due to liveedit, it might happen that the old_script doesn't know
13732 WeakFixedArray::cast(old_script->shared_function_infos()); 13751 // about the SharedFunctionInfo, so we have to guard against that.
13733 list->Remove(shared); 13752 Handle<FixedArray> infos(old_script->shared_function_infos(), isolate);
13753 if (shared->function_literal_id() < infos->length()) {
13754 Object* raw = old_script->shared_function_infos()->get(
13755 shared->function_literal_id());
13756 if (!raw->IsWeakCell() || WeakCell::cast(raw)->value() == *shared) {
13757 old_script->shared_function_infos()->set(
13758 shared->function_literal_id(), isolate->heap()->undefined_value());
13759 }
13734 } 13760 }
13735 } else { 13761 } else {
13736 // Remove shared function info from root array. 13762 // Remove shared function info from root array.
13737 Object* list = isolate->heap()->noscript_shared_function_infos(); 13763 Object* list = isolate->heap()->noscript_shared_function_infos();
13738 CHECK(WeakFixedArray::cast(list)->Remove(shared)); 13764 CHECK(WeakFixedArray::cast(list)->Remove(shared));
13739 } 13765 }
13740 13766
13741 // Finally set new script. 13767 // Finally set new script.
13742 shared->set_script(*script_object); 13768 shared->set_script(*script_object);
13743 } 13769 }
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
13988 shared_info->set_end_position(lit->end_position()); 14014 shared_info->set_end_position(lit->end_position());
13989 shared_info->set_is_declaration(lit->is_declaration()); 14015 shared_info->set_is_declaration(lit->is_declaration());
13990 shared_info->set_is_named_expression(lit->is_named_expression()); 14016 shared_info->set_is_named_expression(lit->is_named_expression());
13991 shared_info->set_is_anonymous_expression(lit->is_anonymous_expression()); 14017 shared_info->set_is_anonymous_expression(lit->is_anonymous_expression());
13992 shared_info->set_inferred_name(*lit->inferred_name()); 14018 shared_info->set_inferred_name(*lit->inferred_name());
13993 shared_info->set_allows_lazy_compilation(lit->AllowsLazyCompilation()); 14019 shared_info->set_allows_lazy_compilation(lit->AllowsLazyCompilation());
13994 shared_info->set_language_mode(lit->language_mode()); 14020 shared_info->set_language_mode(lit->language_mode());
13995 shared_info->set_uses_arguments(lit->scope()->arguments() != NULL); 14021 shared_info->set_uses_arguments(lit->scope()->arguments() != NULL);
13996 shared_info->set_has_duplicate_parameters(lit->has_duplicate_parameters()); 14022 shared_info->set_has_duplicate_parameters(lit->has_duplicate_parameters());
13997 shared_info->set_is_function(lit->is_function()); 14023 shared_info->set_is_function(lit->is_function());
13998 shared_info->set_never_compiled(true);
13999 shared_info->set_kind(lit->kind()); 14024 shared_info->set_kind(lit->kind());
14000 if (!IsConstructable(lit->kind(), lit->language_mode())) { 14025 if (!IsConstructable(lit->kind(), lit->language_mode())) {
14001 shared_info->SetConstructStub( 14026 shared_info->SetConstructStub(
14002 *shared_info->GetIsolate()->builtins()->ConstructedNonConstructable()); 14027 *shared_info->GetIsolate()->builtins()->ConstructedNonConstructable());
14003 } 14028 }
14004 shared_info->set_needs_home_object(lit->scope()->NeedsHomeObject()); 14029 shared_info->set_needs_home_object(lit->scope()->NeedsHomeObject());
14005 shared_info->set_asm_function(lit->scope()->asm_function()); 14030 shared_info->set_asm_function(lit->scope()->asm_function());
14006 shared_info->set_requires_class_field_init(lit->requires_class_field_init()); 14031 shared_info->set_requires_class_field_init(lit->requires_class_field_init());
14007 shared_info->set_is_class_field_initializer( 14032 shared_info->set_is_class_field_initializer(
14008 lit->is_class_field_initializer()); 14033 lit->is_class_field_initializer());
(...skipping 6404 matching lines...) Expand 10 before | Expand all | Expand 10 after
20413 // depend on this. 20438 // depend on this.
20414 return DICTIONARY_ELEMENTS; 20439 return DICTIONARY_ELEMENTS;
20415 } 20440 }
20416 DCHECK_LE(kind, LAST_ELEMENTS_KIND); 20441 DCHECK_LE(kind, LAST_ELEMENTS_KIND);
20417 return kind; 20442 return kind;
20418 } 20443 }
20419 } 20444 }
20420 20445
20421 } // namespace internal 20446 } // namespace internal
20422 } // namespace v8 20447 } // namespace v8
OLDNEW
« src/debug/liveedit.js ('K') | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698