Skip to content

Commit

Permalink
clear expirableObjectDisposeList on DisposeObjects
Browse files Browse the repository at this point in the history
to avoid linear searching the list to do the removal which can cause busy hang
this is a more completed fix for chakra-core#2739
  • Loading branch information
leirocks committed Apr 6, 2017
1 parent 25942bc commit 925076a
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 16 deletions.
1 change: 1 addition & 0 deletions lib/Common/Memory/Recycler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3275,6 +3275,7 @@ Recycler::DisposeObjects()
#ifdef FAULT_INJECTION
this->collectionWrapper->DisposeScriptContextByFaultInjectionCallBack();
#endif
this->collectionWrapper->PreDisposeObjectsCallBack();

// Scope timestamp to just dispose
{
Expand Down
2 changes: 2 additions & 0 deletions lib/Common/Memory/Recycler.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ class RecyclerCollectionWrapper
virtual void DisposeScriptContextByFaultInjectionCallBack() = 0;
#endif
virtual void DisposeObjects(Recycler * recycler) = 0;
virtual void PreDisposeObjectsCallBack() = 0;
#ifdef ENABLE_PROJECTION
virtual void MarkExternalWeakReferencedObjects(bool inPartialCollect) = 0;
virtual void ResolveExternalWeakReferencedObjects() = 0;
Expand Down Expand Up @@ -402,6 +403,7 @@ class DefaultRecyclerCollectionWrapper : public RecyclerCollectionWrapper
virtual void DisposeScriptContextByFaultInjectionCallBack() override {};
#endif
virtual void DisposeObjects(Recycler * recycler) override;
virtual void PreDisposeObjectsCallBack() override {};

#ifdef ENABLE_PROJECTION
virtual void MarkExternalWeakReferencedObjects(bool inPartialCollect) override {};
Expand Down
5 changes: 0 additions & 5 deletions lib/Runtime/Base/ExpirableObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ void ExpirableObject::Finalize(bool isShutdown)

void ExpirableObject::Dispose(bool isShutdown)
{
if (!isShutdown && this->registrationHandle == nullptr)
{
ThreadContext* threadContext = ThreadContext::GetContextForCurrentThread();
threadContext->DisposeExpirableObject(this);
}
}

void ExpirableObject::EnterExpirableCollectMode()
Expand Down
16 changes: 6 additions & 10 deletions lib/Runtime/Base/ThreadContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1838,7 +1838,6 @@ void ThreadContext::DisposeOnLeaveScript()
if (this->callDispose && this->recycler->NeedDispose())
{
this->recycler->FinishDisposeObjectsNow<FinishDispose>();
this->expirableObjectDisposeList->Clear();
}
}

Expand Down Expand Up @@ -2843,6 +2842,12 @@ ThreadContext::UpdateRedeferralState()
}
}

void
ThreadContext::PreDisposeObjectsCallBack()
{
this->expirableObjectDisposeList->Clear();
}

#ifdef FAULT_INJECTION
void
ThreadContext::DisposeScriptContextByFaultInjectionCallBack()
Expand Down Expand Up @@ -3017,15 +3022,6 @@ ThreadContext::UnregisterExpirableObject(ExpirableObject* object)
numExpirableObjects--;
}

void
ThreadContext::DisposeExpirableObject(ExpirableObject* object)
{
Assert(object->registrationHandle == nullptr);

//expirableObjectDisposeList will be cleared after finished disposing all objects

OUTPUT_VERBOSE_TRACE(Js::ExpirableCollectPhase, _u("Disposed 0x%p\n"), object);
}
#pragma endregion

void
Expand Down
2 changes: 1 addition & 1 deletion lib/Runtime/Base/ThreadContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -1575,6 +1575,7 @@ class ThreadContext sealed :
virtual void DisposeScriptContextByFaultInjectionCallBack() override;
#endif
virtual void DisposeObjects(Recycler * recycler) override;
virtual void PreDisposeObjectsCallBack() override;

typedef DList<ExpirableObject*, ArenaAllocator> ExpirableObjectList;
ExpirableObjectList* expirableObjectList;
Expand All @@ -1588,7 +1589,6 @@ class ThreadContext sealed :
void TryExitExpirableCollectMode();
void RegisterExpirableObject(ExpirableObject* object);
void UnregisterExpirableObject(ExpirableObject* object);
void DisposeExpirableObject(ExpirableObject* object);

void * GetDynamicObjectEnumeratorCache(Js::DynamicType const * dynamicType);
void AddDynamicObjectEnumeratorCache(Js::DynamicType const * dynamicType, void * cache);
Expand Down

0 comments on commit 925076a

Please sign in to comment.