From 42fc4310783772d7d503e8ab7dde3a7cb3351e00 Mon Sep 17 00:00:00 2001 From: hpayer Date: Wed, 27 May 2015 07:13:04 -0700 Subject: [PATCH] Treat weak references in context weakly in write barrier. BUG= Review URL: https://codereview.chromium.org/1152153004 Cr-Commit-Position: refs/heads/master@{#28658} --- src/bootstrapper.cc | 3 ++- src/contexts.cc | 13 +++++++------ src/heap/objects-visiting.cc | 2 +- src/objects-inl.h | 16 +++++++++------- src/objects.h | 11 +++++++++-- 5 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc index 3e0a686..28c888c 100644 --- a/src/bootstrapper.cc +++ b/src/bootstrapper.cc @@ -790,7 +790,8 @@ static void AddToWeakNativeContextList(Context* context) { } } #endif - context->set(Context::NEXT_CONTEXT_LINK, heap->native_contexts_list()); + context->set(Context::NEXT_CONTEXT_LINK, heap->native_contexts_list(), + UPDATE_WEAK_WRITE_BARRIER); heap->set_native_contexts_list(context); } diff --git a/src/contexts.cc b/src/contexts.cc index 12eb871..b7617f7 100644 --- a/src/contexts.cc +++ b/src/contexts.cc @@ -395,7 +395,7 @@ void Context::AddOptimizedFunction(JSFunction* function) { DCHECK(function->next_function_link()->IsUndefined()); function->set_next_function_link(get(OPTIMIZED_FUNCTIONS_LIST)); - set(OPTIMIZED_FUNCTIONS_LIST, function); + set(OPTIMIZED_FUNCTIONS_LIST, function, UPDATE_WEAK_WRITE_BARRIER); } @@ -409,7 +409,8 @@ void Context::RemoveOptimizedFunction(JSFunction* function) { element_function->next_function_link()->IsJSFunction()); if (element_function == function) { if (prev == NULL) { - set(OPTIMIZED_FUNCTIONS_LIST, element_function->next_function_link()); + set(OPTIMIZED_FUNCTIONS_LIST, element_function->next_function_link(), + UPDATE_WEAK_WRITE_BARRIER); } else { prev->set_next_function_link(element_function->next_function_link()); } @@ -425,7 +426,7 @@ void Context::RemoveOptimizedFunction(JSFunction* function) { void Context::SetOptimizedFunctionsListHead(Object* head) { DCHECK(IsNativeContext()); - set(OPTIMIZED_FUNCTIONS_LIST, head); + set(OPTIMIZED_FUNCTIONS_LIST, head, UPDATE_WEAK_WRITE_BARRIER); } @@ -440,13 +441,13 @@ void Context::AddOptimizedCode(Code* code) { DCHECK(code->kind() == Code::OPTIMIZED_FUNCTION); DCHECK(code->next_code_link()->IsUndefined()); code->set_next_code_link(get(OPTIMIZED_CODE_LIST)); - set(OPTIMIZED_CODE_LIST, code); + set(OPTIMIZED_CODE_LIST, code, UPDATE_WEAK_WRITE_BARRIER); } void Context::SetOptimizedCodeListHead(Object* head) { DCHECK(IsNativeContext()); - set(OPTIMIZED_CODE_LIST, head); + set(OPTIMIZED_CODE_LIST, head, UPDATE_WEAK_WRITE_BARRIER); } @@ -458,7 +459,7 @@ Object* Context::OptimizedCodeListHead() { void Context::SetDeoptimizedCodeListHead(Object* head) { DCHECK(IsNativeContext()); - set(DEOPTIMIZED_CODE_LIST, head); + set(DEOPTIMIZED_CODE_LIST, head, UPDATE_WEAK_WRITE_BARRIER); } diff --git a/src/heap/objects-visiting.cc b/src/heap/objects-visiting.cc index de2cfdd..4adf2a5 100644 --- a/src/heap/objects-visiting.cc +++ b/src/heap/objects-visiting.cc @@ -287,7 +287,7 @@ struct WeakListVisitor { template <> struct WeakListVisitor { static void SetWeakNext(Context* context, Object* next) { - context->set(Context::NEXT_CONTEXT_LINK, next, UPDATE_WRITE_BARRIER); + context->set(Context::NEXT_CONTEXT_LINK, next, UPDATE_WEAK_WRITE_BARRIER); } static Object* WeakNext(Context* context) { diff --git a/src/objects-inl.h b/src/objects-inl.h index f2c21ac..a81ce86 100644 --- a/src/objects-inl.h +++ b/src/objects-inl.h @@ -1275,13 +1275,15 @@ Maybe JSProxy::HasElementWithHandler(Handle proxy, heap->RecordWrite(object->address(), offset); \ } -#define CONDITIONAL_WRITE_BARRIER(heap, object, offset, value, mode) \ - if (mode == UPDATE_WRITE_BARRIER) { \ - heap->incremental_marking()->RecordWrite( \ - object, HeapObject::RawField(object, offset), value); \ - if (heap->InNewSpace(value)) { \ - heap->RecordWrite(object->address(), offset); \ - } \ +#define CONDITIONAL_WRITE_BARRIER(heap, object, offset, value, mode) \ + if (mode != SKIP_WRITE_BARRIER) { \ + if (mode == UPDATE_WRITE_BARRIER) { \ + heap->incremental_marking()->RecordWrite( \ + object, HeapObject::RawField(object, offset), value); \ + } \ + if (heap->InNewSpace(value)) { \ + heap->RecordWrite(object->address(), offset); \ + } \ } #ifndef V8_TARGET_ARCH_MIPS diff --git a/src/objects.h b/src/objects.h index a973f12..c7a9f78 100644 --- a/src/objects.h +++ b/src/objects.h @@ -251,8 +251,15 @@ static inline bool IsGrowStoreMode(KeyedAccessStoreMode store_mode) { enum IcCheckType { ELEMENT, PROPERTY }; -// Setter that skips the write barrier if mode is SKIP_WRITE_BARRIER. -enum WriteBarrierMode { SKIP_WRITE_BARRIER, UPDATE_WRITE_BARRIER }; +// SKIP_WRITE_BARRIER skips the write barrier. +// UPDATE_WEAK_WRITE_BARRIER skips the marking part of the write barrier and +// only performs the generational part. +// UPDATE_WRITE_BARRIER is doing the full barrier, marking and generational. +enum WriteBarrierMode { + SKIP_WRITE_BARRIER, + UPDATE_WEAK_WRITE_BARRIER, + UPDATE_WRITE_BARRIER +}; // Indicates whether a value can be loaded as a constant. -- 2.7.4