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

[in-place weak refs] Replace Heap::detached_contexts with WeakArrayList.

BUG=v8:7308

Change-Id: I8cc8b3a426b9b24dd5c5e32fb665f29544f3daf6
Reviewed-on: https://chromium-review.googlesource.com/1143190Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Marja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54553}
parent a6a72735
...@@ -760,7 +760,7 @@ void Heap::CreateInitialObjects() { ...@@ -760,7 +760,7 @@ void Heap::CreateInitialObjects() {
cell->clear(); cell->clear();
} }
set_detached_contexts(roots.empty_fixed_array()); set_detached_contexts(roots.empty_weak_array_list());
set_retained_maps(roots.empty_weak_array_list()); set_retained_maps(roots.empty_weak_array_list());
set_retaining_path_targets(roots.undefined_value()); set_retaining_path_targets(roots.undefined_value());
......
...@@ -4011,51 +4011,51 @@ std::string Isolate::GetTurboCfgFileName() { ...@@ -4011,51 +4011,51 @@ std::string Isolate::GetTurboCfgFileName() {
// (number of GC since the context was detached, the context). // (number of GC since the context was detached, the context).
void Isolate::AddDetachedContext(Handle<Context> context) { void Isolate::AddDetachedContext(Handle<Context> context) {
HandleScope scope(this); HandleScope scope(this);
Handle<WeakCell> cell = factory()->NewWeakCell(context); Handle<WeakArrayList> detached_contexts = factory()->detached_contexts();
Handle<FixedArray> detached_contexts = detached_contexts = WeakArrayList::AddToEnd(
factory()->CopyFixedArrayAndGrow(factory()->detached_contexts(), 2); this, detached_contexts, MaybeObjectHandle(Smi::kZero, this));
int new_length = detached_contexts->length(); detached_contexts = WeakArrayList::AddToEnd(this, detached_contexts,
detached_contexts->set(new_length - 2, Smi::kZero); MaybeObjectHandle::Weak(context));
detached_contexts->set(new_length - 1, *cell);
heap()->set_detached_contexts(*detached_contexts); heap()->set_detached_contexts(*detached_contexts);
} }
void Isolate::CheckDetachedContextsAfterGC() { void Isolate::CheckDetachedContextsAfterGC() {
HandleScope scope(this); HandleScope scope(this);
Handle<FixedArray> detached_contexts = factory()->detached_contexts(); Handle<WeakArrayList> detached_contexts = factory()->detached_contexts();
int length = detached_contexts->length(); int length = detached_contexts->length();
if (length == 0) return; if (length == 0) return;
int new_length = 0; int new_length = 0;
for (int i = 0; i < length; i += 2) { for (int i = 0; i < length; i += 2) {
int mark_sweeps = Smi::ToInt(detached_contexts->get(i)); int mark_sweeps = Smi::ToInt(detached_contexts->Get(i)->ToSmi());
DCHECK(detached_contexts->get(i + 1)->IsWeakCell()); MaybeObject* context = detached_contexts->Get(i + 1);
WeakCell* cell = WeakCell::cast(detached_contexts->get(i + 1)); DCHECK(context->IsWeakHeapObject() || context->IsClearedWeakHeapObject());
if (!cell->cleared()) { if (!context->IsClearedWeakHeapObject()) {
detached_contexts->set(new_length, Smi::FromInt(mark_sweeps + 1)); detached_contexts->Set(
detached_contexts->set(new_length + 1, cell); new_length, MaybeObject::FromSmi(Smi::FromInt(mark_sweeps + 1)));
detached_contexts->Set(new_length + 1, context);
new_length += 2; new_length += 2;
} }
counters()->detached_context_age_in_gc()->AddSample(mark_sweeps + 1);
} }
detached_contexts->set_length(new_length);
while (new_length < length) {
detached_contexts->Set(new_length, MaybeObject::FromSmi(Smi::kZero));
++new_length;
}
if (FLAG_trace_detached_contexts) { if (FLAG_trace_detached_contexts) {
PrintF("%d detached contexts are collected out of %d\n", PrintF("%d detached contexts are collected out of %d\n",
length - new_length, length); length - new_length, length);
for (int i = 0; i < new_length; i += 2) { for (int i = 0; i < new_length; i += 2) {
int mark_sweeps = Smi::ToInt(detached_contexts->get(i)); int mark_sweeps = Smi::ToInt(detached_contexts->Get(i)->ToSmi());
DCHECK(detached_contexts->get(i + 1)->IsWeakCell()); MaybeObject* context = detached_contexts->Get(i + 1);
WeakCell* cell = WeakCell::cast(detached_contexts->get(i + 1)); DCHECK(context->IsWeakHeapObject() || context->IsClearedWeakHeapObject());
if (mark_sweeps > 3) { if (mark_sweeps > 3) {
PrintF("detached context %p\n survived %d GCs (leak?)\n", PrintF("detached context %p\n survived %d GCs (leak?)\n",
static_cast<void*>(cell->value()), mark_sweeps); static_cast<void*>(context), mark_sweeps);
} }
} }
} }
if (new_length == 0) {
heap()->set_detached_contexts(ReadOnlyRoots(heap()).empty_fixed_array());
} else if (new_length < length) {
heap()->RightTrimFixedArray(*detached_contexts, length - new_length);
}
} }
double Isolate::LoadStartTimeMs() { double Isolate::LoadStartTimeMs() {
......
...@@ -236,7 +236,7 @@ namespace internal { ...@@ -236,7 +236,7 @@ namespace internal {
V(SimpleNumberDictionary, code_stubs, CodeStubs) \ V(SimpleNumberDictionary, code_stubs, CodeStubs) \
V(FixedArray, materialized_objects, MaterializedObjects) \ V(FixedArray, materialized_objects, MaterializedObjects) \
V(FixedArray, microtask_queue, MicrotaskQueue) \ V(FixedArray, microtask_queue, MicrotaskQueue) \
V(FixedArray, detached_contexts, DetachedContexts) \ V(WeakArrayList, detached_contexts, DetachedContexts) \
V(HeapObject, retaining_path_targets, RetainingPathTargets) \ V(HeapObject, retaining_path_targets, RetainingPathTargets) \
V(WeakArrayList, retained_maps, RetainedMaps) \ V(WeakArrayList, retained_maps, RetainedMaps) \
/* Indirection lists for isolate-independent builtins */ \ /* Indirection lists for isolate-independent builtins */ \
......
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