Ensure BeforeGC and AfterGC events are always sent in pairs
authorChuck Ries <chuckr@microsoft.com>
Fri, 12 Oct 2018 23:28:36 +0000 (16:28 -0700)
committerAndrew Au <cshung@gmail.com>
Wed, 7 Nov 2018 02:34:47 +0000 (18:34 -0800)
This latches the m_isGarbageCollectionEventsEnabled in BeforeGarbageCollection
to ensure that if we send a BeforeGC event we will send the corresponding
AfterGC event. It also ensure we will not send an AfterGC event if we did not
send the corresponding BeforeGC event.

src/debug/ee/debugger.cpp
src/debug/ee/debugger.h

index b608646..44b3764 100644 (file)
@@ -953,7 +953,8 @@ Debugger::Debugger()
     m_pLazyData(NULL),
     m_defines(_defines),
     m_isBlockedOnGarbageCollectionEvent(FALSE),
-    m_isGarbageCollectionEventsEnabled(FALSE)
+    m_isGarbageCollectionEventsEnabled(FALSE),
+    m_isGarbageCollectionEventsEnabledLatch(FALSE)
 {
     CONTRACTL
     {
@@ -6009,7 +6010,9 @@ void Debugger::BeforeGarbageCollection()
     }
     CONTRACTL_END;
 
-    if (!CORDebuggerAttached() || !this->m_isGarbageCollectionEventsEnabled)
+    this->m_isGarbageCollectionEventsEnabledLatch = this->m_isGarbageCollectionEventsEnabled;
+
+    if (!CORDebuggerAttached() || !this->m_isGarbageCollectionEventsEnabledLatch)
     {
         return;
     }
@@ -6047,7 +6050,7 @@ void Debugger::AfterGarbageCollection()
     }
     CONTRACTL_END;
 
-    if (!CORDebuggerAttached() || !this->m_isGarbageCollectionEventsEnabled)
+    if (!CORDebuggerAttached() || !this->m_isGarbageCollectionEventsEnabledLatch)
     {
         return;
     }
index ead8eda..aefc904 100644 (file)
@@ -2959,6 +2959,9 @@ public:
 #endif
     BOOL m_isBlockedOnGarbageCollectionEvent;
     BOOL m_isGarbageCollectionEventsEnabled;
+    // this latches m_isGarbageCollectionEventsEnabled in BeforeGarbageCollection so we can 
+    // guarantee the corresponding AfterGC event is sent even if the events are disabled during GC.
+    BOOL m_isGarbageCollectionEventsEnabledLatch;
 private:
     HANDLE GetGarbageCollectionBlockerEvent() { return  GetLazyData()->m_garbageCollectionBlockerEvent; }