Commit a1e2dcaf authored by Marja Hölttä's avatar Marja Hölttä Committed by Commit Bot

[in-place weak refs] Force compacted WeakFixedArrays into old space.

This way the snapshot will contain only old space objects.

BUG=v8:7308

Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng
Change-Id: Ib19642795b1e8c7cbeda5162be86909c1a777767
Reviewed-on: https://chromium-review.googlesource.com/1177384Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Reviewed-by: 's avatarDan Elphick <delphick@chromium.org>
Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Commit-Queue: Marja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55186}
parent 9554b5fc
......@@ -766,7 +766,7 @@ StartupData SnapshotCreator::CreateBlob(
i::GarbageCollectionReason::kSnapshotCreator);
{
i::HandleScope scope(isolate);
isolate->heap()->CompactWeakArrayLists();
isolate->heap()->CompactWeakArrayLists(internal::TENURED);
}
isolate->heap()->read_only_space()->ClearStringPaddingIfNeeded();
......
......@@ -5081,7 +5081,8 @@ void Heap::RemoveGCEpilogueCallback(v8::Isolate::GCCallbackWithData callback,
namespace {
Handle<WeakArrayList> CompactWeakArrayList(Heap* heap,
Handle<WeakArrayList> array) {
Handle<WeakArrayList> array,
PretenureFlag pretenure) {
if (array->length() == 0) {
return array;
}
......@@ -5093,7 +5094,7 @@ Handle<WeakArrayList> CompactWeakArrayList(Heap* heap,
Handle<WeakArrayList> new_array = WeakArrayList::EnsureSpace(
heap->isolate(),
handle(ReadOnlyRoots(heap).empty_weak_array_list(), heap->isolate()),
new_length);
new_length, pretenure);
// Allocation might have caused GC and turned some of the elements into
// cleared weak heap objects. Count the number of live references again and
// fill in the new array.
......@@ -5109,7 +5110,7 @@ Handle<WeakArrayList> CompactWeakArrayList(Heap* heap,
} // anonymous namespace
void Heap::CompactWeakArrayLists() {
void Heap::CompactWeakArrayLists(PretenureFlag pretenure) {
// Find known PrototypeUsers and compact them.
std::vector<Handle<PrototypeInfo>> prototype_infos;
{
......@@ -5126,19 +5127,24 @@ void Heap::CompactWeakArrayLists() {
for (auto& prototype_info : prototype_infos) {
Handle<WeakArrayList> array(
WeakArrayList::cast(prototype_info->prototype_users()), isolate());
DCHECK_IMPLIES(pretenure == TENURED,
InOldSpace(*array) ||
*array == ReadOnlyRoots(this).empty_weak_array_list());
WeakArrayList* new_array = PrototypeUsers::Compact(
array, this, JSObject::PrototypeRegistryCompactionCallback);
array, this, JSObject::PrototypeRegistryCompactionCallback, pretenure);
prototype_info->set_prototype_users(new_array);
}
// Find known WeakArrayLists and compact them.
Handle<WeakArrayList> scripts(script_list(), isolate());
scripts = CompactWeakArrayList(this, scripts);
DCHECK_IMPLIES(pretenure == TENURED, InOldSpace(*scripts));
scripts = CompactWeakArrayList(this, scripts, pretenure);
set_script_list(*scripts);
Handle<WeakArrayList> no_script_list(noscript_shared_function_infos(),
isolate());
no_script_list = CompactWeakArrayList(this, no_script_list);
DCHECK_IMPLIES(pretenure == TENURED, InOldSpace(*no_script_list));
no_script_list = CompactWeakArrayList(this, no_script_list, pretenure);
set_noscript_shared_function_infos(*no_script_list);
}
......
......@@ -691,7 +691,7 @@ class Heap {
void ProcessMovedExternalString(Page* old_page, Page* new_page,
ExternalString* string);
void CompactWeakArrayLists();
void CompactWeakArrayLists(PretenureFlag pretenure);
void AddRetainedMap(Handle<Map> map);
......
......@@ -10463,13 +10463,15 @@ bool WeakArrayList::IsFull() { return length() == capacity(); }
// static
Handle<WeakArrayList> WeakArrayList::EnsureSpace(Isolate* isolate,
Handle<WeakArrayList> array,
int length) {
int length,
PretenureFlag pretenure) {
int capacity = array->capacity();
if (capacity < length) {
int new_capacity = length;
new_capacity = new_capacity + Max(new_capacity / 2, 2);
int grow_by = new_capacity - capacity;
array = isolate->factory()->CopyWeakArrayListAndGrow(array, grow_by);
array =
isolate->factory()->CopyWeakArrayListAndGrow(array, grow_by, pretenure);
}
return array;
}
......@@ -10550,7 +10552,8 @@ Handle<WeakArrayList> PrototypeUsers::Add(Isolate* isolate,
}
WeakArrayList* PrototypeUsers::Compact(Handle<WeakArrayList> array, Heap* heap,
CompactionCallback callback) {
CompactionCallback callback,
PretenureFlag pretenure) {
if (array->length() == 0) {
return *array;
}
......@@ -10562,7 +10565,7 @@ WeakArrayList* PrototypeUsers::Compact(Handle<WeakArrayList> array, Heap* heap,
Handle<WeakArrayList> new_array = WeakArrayList::EnsureSpace(
heap->isolate(),
handle(ReadOnlyRoots(heap).empty_weak_array_list(), heap->isolate()),
new_length);
new_length, pretenure);
// Allocation might have caused GC and turned some of the elements into
// cleared weak heap objects. Count the number of live objects again.
int copy_to = kFirstIndex;
......
......@@ -370,9 +370,9 @@ class WeakArrayList : public HeapObject {
static const int kMaxCapacity =
(FixedArray::kMaxSize - kHeaderSize) / kPointerSize;
static Handle<WeakArrayList> EnsureSpace(Isolate* isolate,
Handle<WeakArrayList> array,
int length);
static Handle<WeakArrayList> EnsureSpace(
Isolate* isolate, Handle<WeakArrayList> array, int length,
PretenureFlag pretenure = NOT_TENURED);
// Returns the number of non-cleaned weak references in the array.
int CountLiveWeakReferences() const;
......
......@@ -88,7 +88,8 @@ class PrototypeUsers : public WeakArrayList {
typedef void (*CompactionCallback)(HeapObject* object, int from_index,
int to_index);
static WeakArrayList* Compact(Handle<WeakArrayList> array, Heap* heap,
CompactionCallback callback);
CompactionCallback callback,
PretenureFlag pretenure = NOT_TENURED);
#ifdef VERIFY_HEAP
static void Verify(WeakArrayList* array);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment