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

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 13625 matching lines...) Expand 10 before | Expand all | Expand 10 after
13636 Handle<JSValue>::cast(isolate->factory()->NewJSObject(constructor)); 13636 Handle<JSValue>::cast(isolate->factory()->NewJSObject(constructor));
13637 result->set_value(*script); 13637 result->set_value(*script);
13638 Handle<WeakCell> cell = isolate->factory()->NewWeakCell(result); 13638 Handle<WeakCell> cell = isolate->factory()->NewWeakCell(result);
13639 script->set_wrapper(*cell); 13639 script->set_wrapper(*cell);
13640 return result; 13640 return result;
13641 } 13641 }
13642 13642
13643 13643
13644 MaybeHandle<SharedFunctionInfo> Script::FindSharedFunctionInfo( 13644 MaybeHandle<SharedFunctionInfo> Script::FindSharedFunctionInfo(
13645 FunctionLiteral* fun) { 13645 FunctionLiteral* fun) {
13646 WeakFixedArray::Iterator iterator(shared_function_infos()); 13646 if (fun->function_literal_id() == FunctionLiteral::kIdTypeInvalid ||
Toon Verwaest 2016/12/06 21:10:14 Mmh. DCHECK_NE(id, Invalid); DCHECK_LT(id, length)
jochen (gone - plz use gerrit) 2016/12/07 15:57:00 done
13647 SharedFunctionInfo* shared; 13647 fun->function_literal_id() >= shared_function_infos()->length()) {
13648 while ((shared = iterator.Next<SharedFunctionInfo>())) { 13648 UNREACHABLE();
13649 if (fun->function_token_position() == shared->function_token_position() && 13649 return MaybeHandle<SharedFunctionInfo>();
13650 fun->start_position() == shared->start_position() &&
13651 fun->end_position() == shared->end_position()) {
13652 DCHECK_EQ(fun->function_literal_id(), shared->function_literal_id());
13653 return Handle<SharedFunctionInfo>(shared);
13654 }
13655 DCHECK_NE(fun->function_literal_id(), shared->function_literal_id());
13656 } 13650 }
13657 return MaybeHandle<SharedFunctionInfo>(); 13651 Object* shared = shared_function_infos()->get(fun->function_literal_id());
13652 if (shared->IsSmi() || WeakCell::cast(shared)->cleared()) {
13653 return MaybeHandle<SharedFunctionInfo>();
13654 }
13655 return handle(SharedFunctionInfo::cast(WeakCell::cast(shared)->value()));
13658 } 13656 }
13659 13657
13660
13661 Script::Iterator::Iterator(Isolate* isolate) 13658 Script::Iterator::Iterator(Isolate* isolate)
13662 : iterator_(isolate->heap()->script_list()) {} 13659 : iterator_(isolate->heap()->script_list()) {}
13663 13660
13664 13661
13665 Script* Script::Iterator::Next() { return iterator_.Next<Script>(); } 13662 Script* Script::Iterator::Next() { return iterator_.Next<Script>(); }
13666 13663
13667
13668 SharedFunctionInfo::Iterator::Iterator(Isolate* isolate) 13664 SharedFunctionInfo::Iterator::Iterator(Isolate* isolate)
13669 : script_iterator_(isolate), 13665 : script_iterator_(isolate),
13670 sfi_iterator_(isolate->heap()->noscript_shared_function_infos()) {} 13666 sfi_iterator_(isolate->heap()->noscript_shared_function_infos()),
13671 13667 current_script_(nullptr),
13672 13668 index_(-1) {
13673 bool SharedFunctionInfo::Iterator::NextScript() { 13669 NextScript();
13674 Script* script = script_iterator_.Next();
13675 if (script == NULL) return false;
13676 sfi_iterator_.Reset(script->shared_function_infos());
13677 return true;
13678 } 13670 }
13679 13671
13672 void SharedFunctionInfo::Iterator::NextScript() {
13673 current_script_ = script_iterator_.Next();
13674 if (current_script_ == nullptr) return;
13675 index_ = 0;
13676 }
13680 13677
13681 SharedFunctionInfo* SharedFunctionInfo::Iterator::Next() { 13678 SharedFunctionInfo* SharedFunctionInfo::Iterator::Next() {
13682 do { 13679 SharedFunctionInfo* next = sfi_iterator_.Next<SharedFunctionInfo>();
13683 SharedFunctionInfo* next = sfi_iterator_.Next<SharedFunctionInfo>(); 13680 if (next != nullptr) return next;
13684 if (next != NULL) return next; 13681 while (current_script_ != nullptr) {
13685 } while (NextScript()); 13682 FixedArray* infos = current_script_->shared_function_infos();
13686 return NULL; 13683 while (index_ < infos->length()) {
13684 Object* info = infos->get(index_++);
13685 if (!(info->IsSmi() || WeakCell::cast(info)->cleared())) {
13686 return SharedFunctionInfo::cast(WeakCell::cast(info)->value());
13687 }
13688 }
13689 NextScript();
13690 }
13691 return nullptr;
13687 } 13692 }
13688 13693
13689 13694
13690 void SharedFunctionInfo::SetScript(Handle<SharedFunctionInfo> shared, 13695 void SharedFunctionInfo::SetScript(Handle<SharedFunctionInfo> shared,
13691 Handle<Object> script_object) { 13696 Handle<Object> script_object) {
13697 DCHECK(shared->function_literal_id() != FunctionLiteral::kIdTypeInvalid);
Toon Verwaest 2016/12/06 21:10:14 DCHECK_NE
jochen (gone - plz use gerrit) 2016/12/07 15:57:00 done
13692 if (shared->script() == *script_object) return; 13698 if (shared->script() == *script_object) return;
13693 Isolate* isolate = shared->GetIsolate(); 13699 Isolate* isolate = shared->GetIsolate();
13694 13700
13695 // Add shared function info to new script's list. If a collection occurs, 13701 // Add shared function info to new script's list. If a collection occurs,
13696 // the shared function info may be temporarily in two lists. 13702 // the shared function info may be temporarily in two lists.
13697 // This is okay because the gc-time processing of these lists can tolerate 13703 // This is okay because the gc-time processing of these lists can tolerate
13698 // duplicates. 13704 // duplicates.
13699 Handle<Object> list;
13700 if (script_object->IsScript()) { 13705 if (script_object->IsScript()) {
13701 Handle<Script> script = Handle<Script>::cast(script_object); 13706 Handle<Script> script = Handle<Script>::cast(script_object);
13702 list = handle(script->shared_function_infos(), isolate); 13707 Handle<FixedArray> list = handle(script->shared_function_infos(), isolate);
13708 #ifdef DEBUG
13709 DCHECK_LT(shared->function_literal_id(), list->length());
13710 if (list->get(shared->function_literal_id())->IsWeakCell() &&
13711 !WeakCell::cast(list->get(shared->function_literal_id()))->cleared()) {
13712 DCHECK(
13713 WeakCell::cast(list->get(shared->function_literal_id()))->value() ==
13714 *shared);
13715 }
13716 #endif
13717 Handle<WeakCell> cell = isolate->factory()->NewWeakCell(shared);
13718 list->set(shared->function_literal_id(), *cell);
13703 } else { 13719 } else {
13704 list = isolate->factory()->noscript_shared_function_infos(); 13720 Handle<Object> list = isolate->factory()->noscript_shared_function_infos();
13705 }
13706 13721
13707 #ifdef DEBUG 13722 #ifdef DEBUG
13708 if (FLAG_enable_slow_asserts) { 13723 if (FLAG_enable_slow_asserts) {
13709 WeakFixedArray::Iterator iterator(*list); 13724 WeakFixedArray::Iterator iterator(*list);
13710 SharedFunctionInfo* next; 13725 SharedFunctionInfo* next;
13711 while ((next = iterator.Next<SharedFunctionInfo>())) { 13726 while ((next = iterator.Next<SharedFunctionInfo>())) {
13712 DCHECK_NE(next, *shared); 13727 DCHECK_NE(next, *shared);
13728 }
13713 } 13729 }
13714 }
13715 #endif // DEBUG 13730 #endif // DEBUG
13716 list = WeakFixedArray::Add(list, shared);
13717 13731
13718 if (script_object->IsScript()) { 13732 list = WeakFixedArray::Add(list, shared);
13719 Handle<Script> script = Handle<Script>::cast(script_object); 13733
13720 script->set_shared_function_infos(*list);
13721 } else {
13722 isolate->heap()->SetRootNoScriptSharedFunctionInfos(*list); 13734 isolate->heap()->SetRootNoScriptSharedFunctionInfos(*list);
13723 } 13735 }
13724 13736
13725 // Remove shared function info from old script's list.
13726 if (shared->script()->IsScript()) { 13737 if (shared->script()->IsScript()) {
13738 // Remove shared function info from old script's list.
13727 Script* old_script = Script::cast(shared->script()); 13739 Script* old_script = Script::cast(shared->script());
13728 if (old_script->shared_function_infos()->IsWeakFixedArray()) { 13740
13729 WeakFixedArray* list = 13741 // Due to liveedit, it might happen that the old_script doesn't know
13730 WeakFixedArray::cast(old_script->shared_function_infos()); 13742 // about the SharedFunctionInfo, so we have to guard against that.
13731 list->Remove(shared); 13743 Handle<FixedArray> infos(old_script->shared_function_infos(), isolate);
13744 if (shared->function_literal_id() < infos->length()) {
13745 Object* raw = old_script->shared_function_infos()->get(
13746 shared->function_literal_id());
13747 if (!raw->IsWeakCell() || WeakCell::cast(raw)->value() == *shared) {
13748 old_script->shared_function_infos()->set(shared->function_literal_id(),
13749 Smi::kZero);
13750 }
13732 } 13751 }
13733 } else { 13752 } else {
13734 // Remove shared function info from root array. 13753 // Remove shared function info from root array.
13735 Object* list = isolate->heap()->noscript_shared_function_infos(); 13754 Object* list = isolate->heap()->noscript_shared_function_infos();
13736 CHECK(WeakFixedArray::cast(list)->Remove(shared)); 13755 CHECK(WeakFixedArray::cast(list)->Remove(shared));
13737 } 13756 }
13738 13757
13739 // Finally set new script. 13758 // Finally set new script.
13740 shared->set_script(*script_object); 13759 shared->set_script(*script_object);
13741 } 13760 }
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
13986 shared_info->set_end_position(lit->end_position()); 14005 shared_info->set_end_position(lit->end_position());
13987 shared_info->set_is_declaration(lit->is_declaration()); 14006 shared_info->set_is_declaration(lit->is_declaration());
13988 shared_info->set_is_named_expression(lit->is_named_expression()); 14007 shared_info->set_is_named_expression(lit->is_named_expression());
13989 shared_info->set_is_anonymous_expression(lit->is_anonymous_expression()); 14008 shared_info->set_is_anonymous_expression(lit->is_anonymous_expression());
13990 shared_info->set_inferred_name(*lit->inferred_name()); 14009 shared_info->set_inferred_name(*lit->inferred_name());
13991 shared_info->set_allows_lazy_compilation(lit->AllowsLazyCompilation()); 14010 shared_info->set_allows_lazy_compilation(lit->AllowsLazyCompilation());
13992 shared_info->set_language_mode(lit->language_mode()); 14011 shared_info->set_language_mode(lit->language_mode());
13993 shared_info->set_uses_arguments(lit->scope()->arguments() != NULL); 14012 shared_info->set_uses_arguments(lit->scope()->arguments() != NULL);
13994 shared_info->set_has_duplicate_parameters(lit->has_duplicate_parameters()); 14013 shared_info->set_has_duplicate_parameters(lit->has_duplicate_parameters());
13995 shared_info->set_is_function(lit->is_function()); 14014 shared_info->set_is_function(lit->is_function());
13996 shared_info->set_never_compiled(true);
13997 shared_info->set_kind(lit->kind()); 14015 shared_info->set_kind(lit->kind());
13998 if (!IsConstructable(lit->kind(), lit->language_mode())) { 14016 if (!IsConstructable(lit->kind(), lit->language_mode())) {
13999 shared_info->SetConstructStub( 14017 shared_info->SetConstructStub(
14000 *shared_info->GetIsolate()->builtins()->ConstructedNonConstructable()); 14018 *shared_info->GetIsolate()->builtins()->ConstructedNonConstructable());
14001 } 14019 }
14002 shared_info->set_needs_home_object(lit->scope()->NeedsHomeObject()); 14020 shared_info->set_needs_home_object(lit->scope()->NeedsHomeObject());
14003 shared_info->set_asm_function(lit->scope()->asm_function()); 14021 shared_info->set_asm_function(lit->scope()->asm_function());
14004 shared_info->set_requires_class_field_init(lit->requires_class_field_init()); 14022 shared_info->set_requires_class_field_init(lit->requires_class_field_init());
14005 shared_info->set_is_class_field_initializer( 14023 shared_info->set_is_class_field_initializer(
14006 lit->is_class_field_initializer()); 14024 lit->is_class_field_initializer());
(...skipping 6495 matching lines...) Expand 10 before | Expand all | Expand 10 after
20502 // depend on this. 20520 // depend on this.
20503 return DICTIONARY_ELEMENTS; 20521 return DICTIONARY_ELEMENTS;
20504 } 20522 }
20505 DCHECK_LE(kind, LAST_ELEMENTS_KIND); 20523 DCHECK_LE(kind, LAST_ELEMENTS_KIND);
20506 return kind; 20524 return kind;
20507 } 20525 }
20508 } 20526 }
20509 20527
20510 } // namespace internal 20528 } // namespace internal
20511 } // namespace v8 20529 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698