Improve frame destructor performance
authorJan Vorlicek <janvorli@microsoft.com>
Tue, 6 Oct 2015 00:25:36 +0000 (02:25 +0200)
committerJan Vorlicek <janvorli@microsoft.com>
Mon, 12 Oct 2015 22:02:55 +0000 (00:02 +0200)
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
src/vm/frames.h

index dca4fe2..1c7f2f4 100644 (file)
@@ -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
 
index 32bd318..4c43314 100644 (file)
@@ -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<PTR_Frame>(nullptr))
     { 
         LIMITED_METHOD_CONTRACT;
     }