[in-place weak refs] Use WeakArrayList in Heap::noscript_list.

BUG=v8:7308

Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng
Change-Id: Ia53233a3a0ba13b8019f2fda4bc4876ebf4feb76
Reviewed-on: https://chromium-review.googlesource.com/1149367
Commit-Queue: Marja Hölttä <marja@chromium.org>
Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54700}
This commit is contained in:
Marja Hölttä 2018-07-25 16:58:54 +02:00 committed by Commit Bot
parent cd5fbf635c
commit 6755b95631
11 changed files with 49 additions and 31 deletions

View File

@ -765,7 +765,7 @@ StartupData SnapshotCreator::CreateBlob(
i::GarbageCollectionReason::kSnapshotCreator);
{
i::HandleScope scope(isolate);
isolate->heap()->CompactFixedArraysOfWeakCells();
isolate->heap()->CompactWeakArrayLists();
}
isolate->heap()->read_only_space()->ClearStringPaddingIfNeeded();

View File

@ -3541,9 +3541,10 @@ Handle<SharedFunctionInfo> Factory::NewSharedFunctionInfo(
share->clear_padding();
}
// Link into the list.
Handle<Object> new_noscript_list = FixedArrayOfWeakCells::Add(
isolate(), noscript_shared_function_infos(), share);
isolate()->heap()->set_noscript_shared_function_infos(*new_noscript_list);
Handle<WeakArrayList> 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);
#ifdef VERIFY_HEAP
share->SharedFunctionInfoVerify(isolate());

View File

@ -4978,13 +4978,6 @@ void Heap::RemoveGCEpilogueCallback(v8::Isolate::GCCallbackWithData callback,
}
namespace {
void CompactFixedArrayOfWeakCells(Isolate* isolate, Object* object) {
if (object->IsFixedArrayOfWeakCells()) {
FixedArrayOfWeakCells* array = FixedArrayOfWeakCells::cast(object);
array->Compact<FixedArrayOfWeakCells::NullCallback>(isolate);
}
}
Handle<WeakArrayList> CompactWeakArrayList(Heap* heap,
Handle<WeakArrayList> array) {
if (array->length() == 0) {
@ -5014,7 +5007,7 @@ Handle<WeakArrayList> CompactWeakArrayList(Heap* heap,
} // anonymous namespace
void Heap::CompactFixedArraysOfWeakCells() {
void Heap::CompactWeakArrayLists() {
// Find known PrototypeUsers and compact them.
std::vector<Handle<PrototypeInfo>> prototype_infos;
{
@ -5036,13 +5029,15 @@ void Heap::CompactFixedArraysOfWeakCells() {
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<WeakArrayList> scripts(script_list(), isolate());
scripts = CompactWeakArrayList(this, scripts);
set_script_list(*scripts);
Handle<WeakArrayList> 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> map) {

View File

@ -678,7 +678,7 @@ class Heap {
external_memory_concurrently_freed_ = 0;
}
void CompactFixedArraysOfWeakCells();
void CompactWeakArrayLists();
void AddRetainedMap(Handle<Map> map);

View File

@ -706,8 +706,7 @@ void ObjectStatsCollectorImpl::CollectGlobalStatistics() {
// FixedArrayOfWeakCells.
RecordSimpleVirtualObjectStats(
nullptr,
FixedArrayOfWeakCells::cast(heap_->noscript_shared_function_infos()),
nullptr, WeakArrayList::cast(heap_->noscript_shared_function_infos()),
ObjectStats::NOSCRIPT_SHARED_FUNCTION_INFOS_TYPE);
RecordSimpleVirtualObjectStats(nullptr,
WeakArrayList::cast(heap_->script_list()),

View File

@ -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(Smi::kZero);
set_noscript_shared_function_infos(roots.empty_weak_array_list());
STATIC_ASSERT(interpreter::BytecodeOperands::kOperandScaleCount == 3);
set_deserialize_lazy_handler(Smi::kZero);

View File

@ -10581,6 +10581,22 @@ 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<WeakArrayList> PrototypeUsers::Add(Isolate* isolate,
Handle<WeakArrayList> array,
@ -13895,11 +13911,11 @@ SharedFunctionInfo::GlobalIterator::GlobalIterator(Isolate* isolate)
sfi_iterator_(isolate, script_iterator_.Next()) {}
SharedFunctionInfo* SharedFunctionInfo::GlobalIterator::Next() {
SharedFunctionInfo* next = noscript_sfi_iterator_.Next<SharedFunctionInfo>();
if (next != nullptr) return next;
HeapObject* next = noscript_sfi_iterator_.Next();
if (next != nullptr) return SharedFunctionInfo::cast(next);
for (;;) {
next = sfi_iterator_.Next();
if (next != nullptr) return next;
if (next != nullptr) return SharedFunctionInfo::cast(next);
Script* next_script = script_iterator_.Next();
if (next_script == nullptr) return nullptr;
sfi_iterator_.Reset(next_script);
@ -13936,19 +13952,21 @@ void SharedFunctionInfo::SetScript(Handle<SharedFunctionInfo> shared,
#endif
list->Set(function_literal_id, HeapObjectReference::Weak(*shared));
} else {
Handle<Object> list = isolate->factory()->noscript_shared_function_infos();
Handle<WeakArrayList> list =
isolate->factory()->noscript_shared_function_infos();
#ifdef DEBUG
if (FLAG_enable_slow_asserts) {
FixedArrayOfWeakCells::Iterator iterator(*list);
SharedFunctionInfo* next;
while ((next = iterator.Next<SharedFunctionInfo>()) != nullptr) {
WeakArrayList::Iterator iterator(*list);
HeapObject* next;
while ((next = iterator.Next()) != nullptr) {
DCHECK_NE(next, *shared);
}
}
#endif // DEBUG
list = FixedArrayOfWeakCells::Add(isolate, list, shared);
list =
WeakArrayList::AddToEnd(isolate, list, MaybeObjectHandle::Weak(shared));
isolate->heap()->SetRootNoScriptSharedFunctionInfos(*list);
}
@ -13972,8 +13990,8 @@ void SharedFunctionInfo::SetScript(Handle<SharedFunctionInfo> shared,
}
} else {
// Remove shared function info from root array.
Object* list = isolate->heap()->noscript_shared_function_infos();
CHECK(FixedArrayOfWeakCells::cast(list)->Remove(shared));
WeakArrayList* list = isolate->heap()->noscript_shared_function_infos();
CHECK(list->RemoveOne(MaybeObjectHandle::Weak(shared)));
}
// Finally set new script.

View File

@ -370,6 +370,9 @@ 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) {}

View File

@ -574,7 +574,7 @@ class SharedFunctionInfo : public HeapObject, public NeverReadOnlySpaceObject {
private:
Script::Iterator script_iterator_;
FixedArrayOfWeakCells::Iterator noscript_sfi_iterator_;
WeakArrayList::Iterator noscript_sfi_iterator_;
SharedFunctionInfo::ScriptIterator sfi_iterator_;
DisallowHeapAllocation no_gc_;
DISALLOW_COPY_AND_ASSIGN(GlobalIterator);

View File

@ -244,7 +244,8 @@ namespace internal {
/* Feedback vectors that we need for code coverage or type profile */ \
V(Object, feedback_vectors_for_profiling_tools, \
FeedbackVectorsForProfilingTools) \
V(Object, noscript_shared_function_infos, NoScriptSharedFunctionInfos) \
V(WeakArrayList, noscript_shared_function_infos, \
NoScriptSharedFunctionInfos) \
V(FixedArray, serialized_objects, SerializedObjects) \
V(FixedArray, serialized_global_proxy_sizes, SerializedGlobalProxySizes) \
V(TemplateList, message_listeners, MessageListeners) \

View File

@ -83,6 +83,7 @@ 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) \