From d6a18e3e12074fad765ed1ba055ef3861f85efaf Mon Sep 17 00:00:00 2001 From: Jan Vorlicek Date: Tue, 6 Oct 2015 02:25:36 +0200 Subject: [PATCH] Improve frame destructor performance This change makes the Frame destructor access thread local storage much less often, only in rare case when the Frame was not popped before the destructor is called. --- src/vm/frames.cpp | 18 +++++++++++------- src/vm/frames.h | 1 + 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/vm/frames.cpp b/src/vm/frames.cpp index dca4fe2..1c7f2f4 100644 --- a/src/vm/frames.cpp +++ b/src/vm/frames.cpp @@ -477,18 +477,22 @@ VOID Frame::Pop(Thread *pThread) (*m_Next->GetGSCookiePtr() == GetProcessGSCookie())); pThread->SetFrame(m_Next); + m_Next = NULL; } #ifdef FEATURE_PAL Frame::~Frame() { - // When the frame is destroyed, make sure it is no longer in the - // frame chain managed by the Thread. - Thread* pThread = GetThread(); - if (pThread != NULL && pThread->GetFrame() == this) - { - Pop(pThread); - } + if (m_Next != NULL) + { + // When the frame is destroyed, make sure it is no longer in the + // frame chain managed by the Thread. + Thread* pThread = GetThread(); + if (pThread != NULL && pThread->GetFrame() == this) + { + Pop(pThread); + } + } } #endif // FEATURE_PAL diff --git a/src/vm/frames.h b/src/vm/frames.h index 32bd318..4c43314 100644 --- a/src/vm/frames.h +++ b/src/vm/frames.h @@ -845,6 +845,7 @@ protected: // Frame is considered an abstract class: this protected constructor // causes any attempt to instantiate one to fail at compile-time. Frame() + : m_Next(dac_cast(nullptr)) { LIMITED_METHOD_CONTRACT; } -- 2.7.4