diff --git a/src/api.cc b/src/api.cc index 24aae71209..bd8d08c2ed 100644 --- a/src/api.cc +++ b/src/api.cc @@ -765,7 +765,7 @@ StartupData SnapshotCreator::CreateBlob( i::GarbageCollectionReason::kSnapshotCreator); { i::HandleScope scope(isolate); - isolate->heap()->CompactWeakArrayLists(); + isolate->heap()->CompactFixedArraysOfWeakCells(); } isolate->heap()->read_only_space()->ClearStringPaddingIfNeeded(); diff --git a/src/heap/factory.cc b/src/heap/factory.cc index 870af68b7f..95700bed9d 100644 --- a/src/heap/factory.cc +++ b/src/heap/factory.cc @@ -3541,10 +3541,9 @@ Handle Factory::NewSharedFunctionInfo( share->clear_padding(); } // Link into the list. - Handle noscript_list = noscript_shared_function_infos(); - noscript_list = WeakArrayList::AddToEnd(isolate(), noscript_list, - MaybeObjectHandle::Weak(share)); - isolate()->heap()->set_noscript_shared_function_infos(*noscript_list); + Handle new_noscript_list = FixedArrayOfWeakCells::Add( + isolate(), noscript_shared_function_infos(), share); + isolate()->heap()->set_noscript_shared_function_infos(*new_noscript_list); #ifdef VERIFY_HEAP share->SharedFunctionInfoVerify(isolate()); diff --git a/src/heap/heap.cc b/src/heap/heap.cc index 3a39f61826..9b6d15a471 100644 --- a/src/heap/heap.cc +++ b/src/heap/heap.cc @@ -4978,6 +4978,13 @@ void Heap::RemoveGCEpilogueCallback(v8::Isolate::GCCallbackWithData callback, } namespace { +void CompactFixedArrayOfWeakCells(Isolate* isolate, Object* object) { + if (object->IsFixedArrayOfWeakCells()) { + FixedArrayOfWeakCells* array = FixedArrayOfWeakCells::cast(object); + array->Compact(isolate); + } +} + Handle CompactWeakArrayList(Heap* heap, Handle array) { if (array->length() == 0) { @@ -5007,7 +5014,7 @@ Handle CompactWeakArrayList(Heap* heap, } // anonymous namespace -void Heap::CompactWeakArrayLists() { +void Heap::CompactFixedArraysOfWeakCells() { // Find known PrototypeUsers and compact them. std::vector> prototype_infos; { @@ -5029,15 +5036,13 @@ void Heap::CompactWeakArrayLists() { prototype_info->set_prototype_users(new_array); } + // Find known FixedArrayOfWeakCells and compact them. + CompactFixedArrayOfWeakCells(isolate(), noscript_shared_function_infos()); + // Find known WeakArrayLists and compact them. Handle scripts(script_list(), isolate()); scripts = CompactWeakArrayList(this, scripts); set_script_list(*scripts); - - Handle no_script_list(noscript_shared_function_infos(), - isolate()); - no_script_list = CompactWeakArrayList(this, no_script_list); - set_noscript_shared_function_infos(*no_script_list); } void Heap::AddRetainedMap(Handle map) { diff --git a/src/heap/heap.h b/src/heap/heap.h index 23e2e75c31..2ab561e193 100644 --- a/src/heap/heap.h +++ b/src/heap/heap.h @@ -678,7 +678,7 @@ class Heap { external_memory_concurrently_freed_ = 0; } - void CompactWeakArrayLists(); + void CompactFixedArraysOfWeakCells(); void AddRetainedMap(Handle map); diff --git a/src/heap/object-stats.cc b/src/heap/object-stats.cc index 12264f0bdb..783aad70bd 100644 --- a/src/heap/object-stats.cc +++ b/src/heap/object-stats.cc @@ -706,7 +706,8 @@ void ObjectStatsCollectorImpl::CollectGlobalStatistics() { // FixedArrayOfWeakCells. RecordSimpleVirtualObjectStats( - nullptr, WeakArrayList::cast(heap_->noscript_shared_function_infos()), + nullptr, + FixedArrayOfWeakCells::cast(heap_->noscript_shared_function_infos()), ObjectStats::NOSCRIPT_SHARED_FUNCTION_INFOS_TYPE); RecordSimpleVirtualObjectStats(nullptr, WeakArrayList::cast(heap_->script_list()), diff --git a/src/heap/setup-heap-internal.cc b/src/heap/setup-heap-internal.cc index 9ee4cb8b48..2cd7106e0a 100644 --- a/src/heap/setup-heap-internal.cc +++ b/src/heap/setup-heap-internal.cc @@ -866,7 +866,7 @@ void Heap::CreateInitialObjects() { set_serialized_objects(roots.empty_fixed_array()); set_serialized_global_proxy_sizes(roots.empty_fixed_array()); - set_noscript_shared_function_infos(roots.empty_weak_array_list()); + set_noscript_shared_function_infos(Smi::kZero); STATIC_ASSERT(interpreter::BytecodeOperands::kOperandScaleCount == 3); set_deserialize_lazy_handler(Smi::kZero); diff --git a/src/objects.cc b/src/objects.cc index bbd9c3f08f..ac2698d2bd 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -10581,22 +10581,6 @@ int WeakArrayList::CountLiveWeakReferences() const { return live_weak_references; } -bool WeakArrayList::RemoveOne(MaybeObjectHandle value) { - if (length() == 0) return false; - // Optimize for the most recently added element to be removed again. - for (int i = length() - 1; i >= 0; --i) { - if (Get(i) == *value) { - // Users should make sure that there are no duplicates. - Set(i, HeapObjectReference::ClearedValue()); - if (i == length() - 1) { - set_length(length() - 1); - } - return true; - } - } - return false; -} - // static Handle PrototypeUsers::Add(Isolate* isolate, Handle array, @@ -13911,11 +13895,11 @@ SharedFunctionInfo::GlobalIterator::GlobalIterator(Isolate* isolate) sfi_iterator_(isolate, script_iterator_.Next()) {} SharedFunctionInfo* SharedFunctionInfo::GlobalIterator::Next() { - HeapObject* next = noscript_sfi_iterator_.Next(); - if (next != nullptr) return SharedFunctionInfo::cast(next); + SharedFunctionInfo* next = noscript_sfi_iterator_.Next(); + if (next != nullptr) return next; for (;;) { next = sfi_iterator_.Next(); - if (next != nullptr) return SharedFunctionInfo::cast(next); + if (next != nullptr) return next; Script* next_script = script_iterator_.Next(); if (next_script == nullptr) return nullptr; sfi_iterator_.Reset(next_script); @@ -13952,21 +13936,19 @@ void SharedFunctionInfo::SetScript(Handle shared, #endif list->Set(function_literal_id, HeapObjectReference::Weak(*shared)); } else { - Handle list = - isolate->factory()->noscript_shared_function_infos(); + Handle list = isolate->factory()->noscript_shared_function_infos(); #ifdef DEBUG if (FLAG_enable_slow_asserts) { - WeakArrayList::Iterator iterator(*list); - HeapObject* next; - while ((next = iterator.Next()) != nullptr) { + FixedArrayOfWeakCells::Iterator iterator(*list); + SharedFunctionInfo* next; + while ((next = iterator.Next()) != nullptr) { DCHECK_NE(next, *shared); } } #endif // DEBUG - list = - WeakArrayList::AddToEnd(isolate, list, MaybeObjectHandle::Weak(shared)); + list = FixedArrayOfWeakCells::Add(isolate, list, shared); isolate->heap()->SetRootNoScriptSharedFunctionInfos(*list); } @@ -13990,8 +13972,8 @@ void SharedFunctionInfo::SetScript(Handle shared, } } else { // Remove shared function info from root array. - WeakArrayList* list = isolate->heap()->noscript_shared_function_infos(); - CHECK(list->RemoveOne(MaybeObjectHandle::Weak(shared))); + Object* list = isolate->heap()->noscript_shared_function_infos(); + CHECK(FixedArrayOfWeakCells::cast(list)->Remove(shared)); } // Finally set new script. diff --git a/src/objects/fixed-array.h b/src/objects/fixed-array.h index 00da8c09db..f3d993cbfc 100644 --- a/src/objects/fixed-array.h +++ b/src/objects/fixed-array.h @@ -370,9 +370,6 @@ class WeakArrayList : public HeapObject { // Returns the number of non-cleaned weak references in the array. int CountLiveWeakReferences() const; - // Returns whether an entry was found and removed. - bool RemoveOne(MaybeObjectHandle value); - class Iterator { public: explicit Iterator(WeakArrayList* array) : index_(0), array_(array) {} diff --git a/src/objects/shared-function-info.h b/src/objects/shared-function-info.h index 9d54a57bb8..17654c303c 100644 --- a/src/objects/shared-function-info.h +++ b/src/objects/shared-function-info.h @@ -574,7 +574,7 @@ class SharedFunctionInfo : public HeapObject, public NeverReadOnlySpaceObject { private: Script::Iterator script_iterator_; - WeakArrayList::Iterator noscript_sfi_iterator_; + FixedArrayOfWeakCells::Iterator noscript_sfi_iterator_; SharedFunctionInfo::ScriptIterator sfi_iterator_; DisallowHeapAllocation no_gc_; DISALLOW_COPY_AND_ASSIGN(GlobalIterator); diff --git a/src/roots.h b/src/roots.h index 47c66d29a6..6ab4505879 100644 --- a/src/roots.h +++ b/src/roots.h @@ -244,8 +244,7 @@ namespace internal { /* Feedback vectors that we need for code coverage or type profile */ \ V(Object, feedback_vectors_for_profiling_tools, \ FeedbackVectorsForProfilingTools) \ - V(WeakArrayList, noscript_shared_function_infos, \ - NoScriptSharedFunctionInfos) \ + V(Object, noscript_shared_function_infos, NoScriptSharedFunctionInfos) \ V(FixedArray, serialized_objects, SerializedObjects) \ V(FixedArray, serialized_global_proxy_sizes, SerializedGlobalProxySizes) \ V(TemplateList, message_listeners, MessageListeners) \ diff --git a/test/cctest/test-roots.cc b/test/cctest/test-roots.cc index f99b9df399..7b270076ed 100644 --- a/test/cctest/test-roots.cc +++ b/test/cctest/test-roots.cc @@ -83,7 +83,6 @@ bool IsInitiallyMutable(Factory* factory, Address object_address) { V(feedback_vectors_for_profiling_tools) \ V(materialized_objects) \ V(microtask_queue) \ - V(noscript_shared_function_infos) \ V(retained_maps) \ V(retaining_path_targets) \ V(serialized_global_proxy_sizes) \