Simplified slot buffer logic during weak list visiting.

Tiny reformatting cleanup on the way.

R=mstarzinger@chromium.org

Review URL: https://codereview.chromium.org/282493004

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@21278 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
svenpanne@chromium.org 2014-05-13 06:22:49 +00:00
parent b94d02888a
commit e7d8fb96e2
5 changed files with 62 additions and 89 deletions

View File

@ -1681,36 +1681,24 @@ void Heap::UpdateReferencesInExternalStringTable(
void Heap::ProcessWeakReferences(WeakObjectRetainer* retainer) { void Heap::ProcessWeakReferences(WeakObjectRetainer* retainer) {
// We don't record weak slots during marking or scavenges. ProcessArrayBuffers(retainer);
// Instead we do it once when we complete mark-compact cycle. ProcessNativeContexts(retainer);
// Note that write barrier has no effect if we are already in the middle of
// compacting mark-sweep cycle and we have to record slots manually.
bool record_slots =
gc_state() == MARK_COMPACT &&
mark_compact_collector()->is_compacting();
ProcessArrayBuffers(retainer, record_slots);
ProcessNativeContexts(retainer, record_slots);
// TODO(mvstanton): AllocationSites only need to be processed during // TODO(mvstanton): AllocationSites only need to be processed during
// MARK_COMPACT, as they live in old space. Verify and address. // MARK_COMPACT, as they live in old space. Verify and address.
ProcessAllocationSites(retainer, record_slots); ProcessAllocationSites(retainer);
} }
void Heap::ProcessNativeContexts(WeakObjectRetainer* retainer,
bool record_slots) { void Heap::ProcessNativeContexts(WeakObjectRetainer* retainer) {
Object* head = Object* head = VisitWeakList<Context>(this, native_contexts_list(), retainer);
VisitWeakList<Context>(
this, native_contexts_list(), retainer, record_slots);
// Update the head of the list of contexts. // Update the head of the list of contexts.
set_native_contexts_list(head); set_native_contexts_list(head);
} }
void Heap::ProcessArrayBuffers(WeakObjectRetainer* retainer, void Heap::ProcessArrayBuffers(WeakObjectRetainer* retainer) {
bool record_slots) {
Object* array_buffer_obj = Object* array_buffer_obj =
VisitWeakList<JSArrayBuffer>(this, VisitWeakList<JSArrayBuffer>(this, array_buffers_list(), retainer);
array_buffers_list(),
retainer, record_slots);
set_array_buffers_list(array_buffer_obj); set_array_buffers_list(array_buffer_obj);
} }
@ -1726,12 +1714,9 @@ void Heap::TearDownArrayBuffers() {
} }
void Heap::ProcessAllocationSites(WeakObjectRetainer* retainer, void Heap::ProcessAllocationSites(WeakObjectRetainer* retainer) {
bool record_slots) {
Object* allocation_site_obj = Object* allocation_site_obj =
VisitWeakList<AllocationSite>(this, VisitWeakList<AllocationSite>(this, allocation_sites_list(), retainer);
allocation_sites_list(),
retainer, record_slots);
set_allocation_sites_list(allocation_site_obj); set_allocation_sites_list(allocation_site_obj);
} }

View File

@ -1974,9 +1974,9 @@ class Heap {
// Code to be run before and after mark-compact. // Code to be run before and after mark-compact.
void MarkCompactPrologue(); void MarkCompactPrologue();
void ProcessNativeContexts(WeakObjectRetainer* retainer, bool record_slots); void ProcessNativeContexts(WeakObjectRetainer* retainer);
void ProcessArrayBuffers(WeakObjectRetainer* retainer, bool record_slots); void ProcessArrayBuffers(WeakObjectRetainer* retainer);
void ProcessAllocationSites(WeakObjectRetainer* retainer, bool record_slots); void ProcessAllocationSites(WeakObjectRetainer* retainer);
// Deopts all code that contains allocation instruction which are tenured or // Deopts all code that contains allocation instruction which are tenured or
// not tenured. Moreover it clears the pretenuring allocation site statistics. // not tenured. Moreover it clears the pretenuring allocation site statistics.

View File

@ -2757,7 +2757,7 @@ int MarkCompactCollector::ClearNonLiveDependentCodeInGroup(
ASSERT(start + 1 == end); ASSERT(start + 1 == end);
Object* old_head = entries->object_at(start); Object* old_head = entries->object_at(start);
MarkCompactWeakObjectRetainer retainer; MarkCompactWeakObjectRetainer retainer;
Object* head = VisitWeakList<Code>(heap(), old_head, &retainer, true); Object* head = VisitWeakList<Code>(heap(), old_head, &retainer);
entries->set_object_at(new_start, head); entries->set_object_at(new_start, head);
Object** slot = entries->slot_at(new_start); Object** slot = entries->slot_at(new_start);
RecordSlot(slot, slot, head); RecordSlot(slot, slot, head);

View File

@ -191,6 +191,16 @@ StaticVisitorBase::VisitorId StaticVisitorBase::GetVisitorId(
} }
// We don't record weak slots during marking or scavenges. Instead we do it
// once when we complete mark-compact cycle. Note that write barrier has no
// effect if we are already in the middle of compacting mark-sweep cycle and we
// have to record slots manually.
static bool MustRecordSlots(Heap* heap) {
return heap->gc_state() == Heap::MARK_COMPACT &&
heap->mark_compact_collector()->is_compacting();
}
template <class T> template <class T>
struct WeakListVisitor; struct WeakListVisitor;
@ -198,12 +208,12 @@ struct WeakListVisitor;
template <class T> template <class T>
Object* VisitWeakList(Heap* heap, Object* VisitWeakList(Heap* heap,
Object* list, Object* list,
WeakObjectRetainer* retainer, WeakObjectRetainer* retainer) {
bool record_slots) {
Object* undefined = heap->undefined_value(); Object* undefined = heap->undefined_value();
Object* head = undefined; Object* head = undefined;
T* tail = NULL; T* tail = NULL;
MarkCompactCollector* collector = heap->mark_compact_collector(); MarkCompactCollector* collector = heap->mark_compact_collector();
bool record_slots = MustRecordSlots(heap);
while (list != undefined) { while (list != undefined) {
// Check whether to keep the candidate in the list. // Check whether to keep the candidate in the list.
T* candidate = reinterpret_cast<T*>(list); T* candidate = reinterpret_cast<T*>(list);
@ -229,8 +239,7 @@ Object* VisitWeakList(Heap* heap,
// tail is a live object, visit it. // tail is a live object, visit it.
WeakListVisitor<T>::VisitLiveObject( WeakListVisitor<T>::VisitLiveObject(heap, tail, retainer);
heap, tail, retainer, record_slots);
} else { } else {
WeakListVisitor<T>::VisitPhantomObject(heap, candidate); WeakListVisitor<T>::VisitPhantomObject(heap, candidate);
} }
@ -273,12 +282,9 @@ struct WeakListVisitor<JSFunction> {
return JSFunction::kNextFunctionLinkOffset; return JSFunction::kNextFunctionLinkOffset;
} }
static void VisitLiveObject(Heap*, JSFunction*, static void VisitLiveObject(Heap*, JSFunction*, WeakObjectRetainer*) {}
WeakObjectRetainer*, bool) {
}
static void VisitPhantomObject(Heap*, JSFunction*) { static void VisitPhantomObject(Heap*, JSFunction*) {}
}
}; };
@ -296,12 +302,9 @@ struct WeakListVisitor<Code> {
return Code::kNextCodeLinkOffset; return Code::kNextCodeLinkOffset;
} }
static void VisitLiveObject(Heap*, Code*, static void VisitLiveObject(Heap*, Code*, WeakObjectRetainer*) {}
WeakObjectRetainer*, bool) {
}
static void VisitPhantomObject(Heap*, Code*) { static void VisitPhantomObject(Heap*, Code*) {}
}
}; };
@ -317,33 +320,32 @@ struct WeakListVisitor<Context> {
return context->get(Context::NEXT_CONTEXT_LINK); return context->get(Context::NEXT_CONTEXT_LINK);
} }
static int WeakNextOffset() {
return FixedArray::SizeFor(Context::NEXT_CONTEXT_LINK);
}
static void VisitLiveObject(Heap* heap, static void VisitLiveObject(Heap* heap,
Context* context, Context* context,
WeakObjectRetainer* retainer, WeakObjectRetainer* retainer) {
bool record_slots) {
// Process the three weak lists linked off the context. // Process the three weak lists linked off the context.
DoWeakList<JSFunction>(heap, context, retainer, record_slots, DoWeakList<JSFunction>(heap, context, retainer,
Context::OPTIMIZED_FUNCTIONS_LIST); Context::OPTIMIZED_FUNCTIONS_LIST);
DoWeakList<Code>(heap, context, retainer, record_slots, DoWeakList<Code>(heap, context, retainer, Context::OPTIMIZED_CODE_LIST);
Context::OPTIMIZED_CODE_LIST); DoWeakList<Code>(heap, context, retainer, Context::DEOPTIMIZED_CODE_LIST);
DoWeakList<Code>(heap, context, retainer, record_slots,
Context::DEOPTIMIZED_CODE_LIST);
} }
template<class T> template<class T>
static void DoWeakList(Heap* heap, static void DoWeakList(Heap* heap,
Context* context, Context* context,
WeakObjectRetainer* retainer, WeakObjectRetainer* retainer,
bool record_slots,
int index) { int index) {
// Visit the weak list, removing dead intermediate elements. // Visit the weak list, removing dead intermediate elements.
Object* list_head = VisitWeakList<T>(heap, context->get(index), retainer, Object* list_head = VisitWeakList<T>(heap, context->get(index), retainer);
record_slots);
// Update the list head. // Update the list head.
context->set(index, list_head, UPDATE_WRITE_BARRIER); context->set(index, list_head, UPDATE_WRITE_BARRIER);
if (record_slots) { if (MustRecordSlots(heap)) {
// Record the updated slot if necessary. // Record the updated slot if necessary.
Object** head_slot = HeapObject::RawField( Object** head_slot = HeapObject::RawField(
context, FixedArray::SizeFor(index)); context, FixedArray::SizeFor(index));
@ -358,10 +360,6 @@ struct WeakListVisitor<Context> {
ClearWeakList<Code>(heap, context->get(Context::OPTIMIZED_CODE_LIST)); ClearWeakList<Code>(heap, context->get(Context::OPTIMIZED_CODE_LIST));
ClearWeakList<Code>(heap, context->get(Context::DEOPTIMIZED_CODE_LIST)); ClearWeakList<Code>(heap, context->get(Context::DEOPTIMIZED_CODE_LIST));
} }
static int WeakNextOffset() {
return FixedArray::SizeFor(Context::NEXT_CONTEXT_LINK);
}
}; };
@ -375,16 +373,13 @@ struct WeakListVisitor<JSArrayBufferView> {
return obj->weak_next(); return obj->weak_next();
} }
static void VisitLiveObject(Heap*,
JSArrayBufferView* obj,
WeakObjectRetainer* retainer,
bool record_slots) {}
static void VisitPhantomObject(Heap*, JSArrayBufferView*) {}
static int WeakNextOffset() { static int WeakNextOffset() {
return JSArrayBufferView::kWeakNextOffset; return JSArrayBufferView::kWeakNextOffset;
} }
static void VisitLiveObject(Heap*, JSArrayBufferView*, WeakObjectRetainer*) {}
static void VisitPhantomObject(Heap*, JSArrayBufferView*) {}
}; };
@ -398,17 +393,20 @@ struct WeakListVisitor<JSArrayBuffer> {
return obj->weak_next(); return obj->weak_next();
} }
static int WeakNextOffset() {
return JSArrayBuffer::kWeakNextOffset;
}
static void VisitLiveObject(Heap* heap, static void VisitLiveObject(Heap* heap,
JSArrayBuffer* array_buffer, JSArrayBuffer* array_buffer,
WeakObjectRetainer* retainer, WeakObjectRetainer* retainer) {
bool record_slots) {
Object* typed_array_obj = Object* typed_array_obj =
VisitWeakList<JSArrayBufferView>( VisitWeakList<JSArrayBufferView>(
heap, heap,
array_buffer->weak_first_view(), array_buffer->weak_first_view(),
retainer, record_slots); retainer);
array_buffer->set_weak_first_view(typed_array_obj); array_buffer->set_weak_first_view(typed_array_obj);
if (typed_array_obj != heap->undefined_value() && record_slots) { if (typed_array_obj != heap->undefined_value() && MustRecordSlots(heap)) {
Object** slot = HeapObject::RawField( Object** slot = HeapObject::RawField(
array_buffer, JSArrayBuffer::kWeakFirstViewOffset); array_buffer, JSArrayBuffer::kWeakFirstViewOffset);
heap->mark_compact_collector()->RecordSlot(slot, slot, typed_array_obj); heap->mark_compact_collector()->RecordSlot(slot, slot, typed_array_obj);
@ -418,10 +416,6 @@ struct WeakListVisitor<JSArrayBuffer> {
static void VisitPhantomObject(Heap* heap, JSArrayBuffer* phantom) { static void VisitPhantomObject(Heap* heap, JSArrayBuffer* phantom) {
Runtime::FreeArrayBuffer(heap->isolate(), phantom); Runtime::FreeArrayBuffer(heap->isolate(), phantom);
} }
static int WeakNextOffset() {
return JSArrayBuffer::kWeakNextOffset;
}
}; };
@ -435,36 +429,33 @@ struct WeakListVisitor<AllocationSite> {
return obj->weak_next(); return obj->weak_next();
} }
static void VisitLiveObject(Heap* heap,
AllocationSite* site,
WeakObjectRetainer* retainer,
bool record_slots) {}
static void VisitPhantomObject(Heap* heap, AllocationSite* phantom) {}
static int WeakNextOffset() { static int WeakNextOffset() {
return AllocationSite::kWeakNextOffset; return AllocationSite::kWeakNextOffset;
} }
static void VisitLiveObject(Heap*, AllocationSite*, WeakObjectRetainer*) {}
static void VisitPhantomObject(Heap*, AllocationSite*) {}
}; };
template Object* VisitWeakList<Code>( template Object* VisitWeakList<Code>(
Heap* heap, Object* list, WeakObjectRetainer* retainer, bool record_slots); Heap* heap, Object* list, WeakObjectRetainer* retainer);
template Object* VisitWeakList<JSFunction>( template Object* VisitWeakList<JSFunction>(
Heap* heap, Object* list, WeakObjectRetainer* retainer, bool record_slots); Heap* heap, Object* list, WeakObjectRetainer* retainer);
template Object* VisitWeakList<Context>( template Object* VisitWeakList<Context>(
Heap* heap, Object* list, WeakObjectRetainer* retainer, bool record_slots); Heap* heap, Object* list, WeakObjectRetainer* retainer);
template Object* VisitWeakList<JSArrayBuffer>( template Object* VisitWeakList<JSArrayBuffer>(
Heap* heap, Object* list, WeakObjectRetainer* retainer, bool record_slots); Heap* heap, Object* list, WeakObjectRetainer* retainer);
template Object* VisitWeakList<AllocationSite>( template Object* VisitWeakList<AllocationSite>(
Heap* heap, Object* list, WeakObjectRetainer* retainer, bool record_slots); Heap* heap, Object* list, WeakObjectRetainer* retainer);
} } // namespace v8::internal } } // namespace v8::internal

View File

@ -469,10 +469,7 @@ class WeakObjectRetainer;
// pointers. The template parameter T is a WeakListVisitor that defines how to // pointers. The template parameter T is a WeakListVisitor that defines how to
// access the next-element pointers. // access the next-element pointers.
template <class T> template <class T>
Object* VisitWeakList(Heap* heap, Object* VisitWeakList(Heap* heap, Object* list, WeakObjectRetainer* retainer);
Object* list,
WeakObjectRetainer* retainer,
bool record_slots);
} } // namespace v8::internal } } // namespace v8::internal