[local gc] Enable eventing (#16120)
authorDavid Mason <davmason@microsoft.com>
Thu, 1 Feb 2018 00:56:27 +0000 (16:56 -0800)
committerGitHub <noreply@github.com>
Thu, 1 Feb 2018 00:56:27 +0000 (16:56 -0800)
* move GC etw enums to gcinterface.ee.h

* add GetActiveSyncBlockCount

* refactor reference to ETW::GCLog::ShouldTrackMovementForEtw()

* mov g_dwHandles to gc side

* enable FEATURE_EVENT_TRACE for gc

16 files changed:
src/gc/CMakeLists.txt
src/gc/env/gcenv.ee.h
src/gc/gc.cpp
src/gc/gc.h
src/gc/gcee.cpp
src/gc/gcenv.ee.standalone.inl
src/gc/gcinterface.ee.h
src/gc/gcinterface.h
src/gc/handletable.cpp
src/inc/eventtracebase.h
src/vm/eetoprofinterfaceimpl.h
src/vm/gcenv.ee.cpp
src/vm/gcenv.ee.h
src/vm/gchandleutilities.cpp
src/vm/vars.cpp
src/vm/vars.hpp

index e7aacdb..caecdba 100644 (file)
@@ -2,9 +2,6 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
 
 # Local GC meta-issue: https://github.com/dotnet/coreclr/issues/11518
 
-# https://github.com/dotnet/coreclr/issues/11514
-remove_definitions(-DFEATURE_EVENT_TRACE=1)
-
 # https://github.com/dotnet/coreclr/issues/11517
 remove_definitions(-DFEATURE_APPDOMAIN_RESOURCE_MONITORING)
 
index 5f2b890..4ef1b93 100644 (file)
@@ -44,6 +44,7 @@ public:
     static void SyncBlockCacheWeakPtrScan(HANDLESCANPROC scanProc, uintptr_t lp1, uintptr_t lp2);
     static void SyncBlockCacheDemote(int max_gen);
     static void SyncBlockCachePromotionsGranted(int max_gen);
+    static uint32_t GetActiveSyncBlockCount();
 
     // Thread functions
     static bool IsPreemptiveGCDisabled(Thread * pThread);
index d6ab65a..dd26a54 100644 (file)
@@ -13231,7 +13231,7 @@ int gc_heap::try_allocate_more_space (alloc_context* acontext, size_t size,
             // Unfortunately some of the ETW macros do not check whether the ETW feature is enabled.
             // The ones that do are much less efficient.
 #if defined(FEATURE_EVENT_TRACE)
-            if (EventEnabledGCAllocationTick_V3())
+            if (EVENT_ENABLED(GCAllocationTick_V3))
             {
                 fire_etw_allocation_event (etw_allocation_running_amount[etw_allocation_index], gen_number, acontext->alloc_ptr);
             }
@@ -19972,7 +19972,7 @@ void gc_heap::pin_object (uint8_t* o, uint8_t** ppObject, uint8_t* low, uint8_t*
         set_pinned (o);
 
 #ifdef FEATURE_EVENT_TRACE        
-        if(EventEnabledPinObjectAtGCTime())
+        if(EVENT_ENABLED(PinObjectAtGCTime))
         {
             fire_etw_pin_object_event(o, ppObject);
         }
@@ -31352,7 +31352,9 @@ void gc_heap::background_sweep()
 #endif //MULTIPLE_HEAPS
     {
 #ifdef FEATURE_EVENT_TRACE
-        bgc_heap_walk_for_etw_p = ETW::GCLog::ShouldTrackMovementForEtw();
+        bgc_heap_walk_for_etw_p = GCEventStatus::IsEnabled(GCEventProvider_Default, 
+                                                           GCEventKeyword_GCHeapSurvivalAndMovement, 
+                                                           GCEventLevel_Information);
 #endif //FEATURE_EVENT_TRACE
 
         leave_spin_lock (&gc_lock);
index 6641f0b..a0e09cd 100644 (file)
@@ -122,6 +122,12 @@ class DacHeapWalker;
 extern "C" uint32_t* g_gc_card_bundle_table;
 #endif
 
+#if defined(ENABLE_PERF_COUNTERS) || defined(FEATURE_EVENT_TRACE)
+// Note this is not updated in a thread safe way so the value may not be accurate. We get
+// it accurately in full GCs if the handle count is requested.
+extern DWORD g_dwHandles;
+#endif // ENABLE_PERF_COUNTERS || FEATURE_EVENT_TRACE
+
 extern "C" uint32_t* g_gc_card_table;
 extern "C" uint8_t* g_gc_lowest_address;
 extern "C" uint8_t* g_gc_highest_address;
index 358b40c..b399cde 100644 (file)
@@ -132,7 +132,7 @@ void GCHeap::UpdatePostGCCounters()
     memset (g_GenerationPromotedSizes, 0, sizeof (g_GenerationPromotedSizes));
     
     size_t total_num_gc_handles = g_dwHandles;
-    uint32_t total_num_sync_blocks = SyncBlockCache::GetSyncBlockCache()->GetActiveCount();
+    uint32_t total_num_sync_blocks = GCToEEInterface::GetActiveSyncBlockCount();
 
     // Note this is however for perf counter only, for legacy reasons. What we showed 
     // in perf counters for "gen0 size" was really the gen0 budget which made
index 675e7fa..665bd32 100644 (file)
@@ -83,6 +83,13 @@ inline void GCToEEInterface::SyncBlockCachePromotionsGranted(int max_gen)
     g_theGCToCLR->SyncBlockCachePromotionsGranted(max_gen);
 }
 
+
+inline uint32_t GCToEEInterface::GetActiveSyncBlockCount()
+{
+    assert(g_theGCToCLR != nullptr);
+    return g_theGCToCLR->GetActiveSyncBlockCount();
+}
+
 inline bool GCToEEInterface::IsPreemptiveGCDisabled(Thread * pThread)
 {
     assert(g_theGCToCLR != nullptr);
index a79043e..e6e3bca 100644 (file)
@@ -5,6 +5,21 @@
 #ifndef _GCINTERFACE_EE_H_
 #define _GCINTERFACE_EE_H_
 
+enum EtwGCRootFlags
+{
+    kEtwGCRootFlagsPinning =            0x1,
+    kEtwGCRootFlagsWeakRef =            0x2,
+    kEtwGCRootFlagsInterior =           0x4,
+    kEtwGCRootFlagsRefCounted =         0x8,
+};
+
+enum EtwGCRootKind
+{
+    kEtwGCRootKindStack =               0,
+    kEtwGCRootKindFinalizer =           1,
+    kEtwGCRootKindHandle =              2,
+    kEtwGCRootKindOther =               3,
+};
 
 // This interface provides functions that the GC can use to fire events.
 // Events fired on this interface are split into two categories: "known"
@@ -203,6 +218,9 @@ public:
     virtual
     void SyncBlockCachePromotionsGranted(int max_gen) = 0;
 
+    virtual
+    uint32_t GetActiveSyncBlockCount() = 0;
+
     // Queries whether or not the given thread has preemptive GC disabled.
     virtual
     bool IsPreemptiveGCDisabled(Thread * pThread) = 0;
index 2b98385..4c03811 100644 (file)
@@ -914,7 +914,7 @@ struct ScanContext
 #if defined(GC_PROFILING) || defined(FEATURE_EVENT_TRACE)
     EtwGCRootKind dwEtwRootKind;
 #else
-    int _unused3;
+    EtwGCRootKind _unused3;
 #endif // GC_PROFILING || FEATURE_EVENT_TRACE
     
     ScanContext()
@@ -929,9 +929,9 @@ struct ScanContext
 #ifdef GC_PROFILING
         pMD = NULL;
 #endif //GC_PROFILING
-#ifdef FEATURE_EVENT_TRACE
+#if defined(GC_PROFILING) || defined(FEATURE_EVENT_TRACE)
         dwEtwRootKind = kEtwGCRootKindOther;
-#endif // FEATURE_EVENT_TRACE
+#endif
     }
 };
 
index 4d42dda..0ae2b03 100644 (file)
 #include "objecthandle.h"
 #include "handletablepriv.h"
 
+#if defined(ENABLE_PERF_COUNTERS) || defined(FEATURE_EVENT_TRACE)
+DWORD g_dwHandles = 0;
+#endif // ENABLE_PERF_COUNTERS || FEATURE_EVENT_TRACE
+
 /****************************************************************************
  *
  * FORWARD DECLARATIONS
@@ -342,6 +346,10 @@ OBJECTHANDLE HndCreateHandle(HHANDLETABLE hTable, uint32_t uType, OBJECTREF obje
         HandleQuickSetUserData(handle, lExtraInfo);
     }
 
+#if defined(ENABLE_PERF_COUNTERS) || defined(FEATURE_EVENT_TRACE)
+    g_dwHandles++;
+#endif // defined(ENABLE_PERF_COUNTERS) || defined(FEATURE_EVENT_TRACE)
+
     // store the reference
     HndAssignHandle(handle, object);
     STRESS_LOG2(LF_GC, LL_INFO1000, "CreateHandle: %p, type=%d\n", handle, uType);
@@ -464,6 +472,10 @@ void HndDestroyHandle(HHANDLETABLE hTable, uint32_t uType, OBJECTHANDLE handle)
 
     // return the handle to the table's cache
     TableFreeSingleHandleToCache(pTable, uType, handle);
+
+#if defined(ENABLE_PERF_COUNTERS) || defined(FEATURE_EVENT_TRACE)
+    g_dwHandles--;
+#endif // defined(ENABLE_PERF_COUNTERS) || defined(FEATURE_EVENT_TRACE)
 }
 
 
index d73d72a..c29308d 100644 (file)
@@ -38,22 +38,6 @@ void InitializeEventTracing();
 // These flags need to be defined either when FEATURE_EVENT_TRACE is enabled or the 
 // PROFILING_SUPPORTED is set, since they are used both by event tracing and profiling.
 
-enum EtwGCRootFlags
-{
-    kEtwGCRootFlagsPinning =            0x1,
-    kEtwGCRootFlagsWeakRef =            0x2,
-    kEtwGCRootFlagsInterior =           0x4,
-    kEtwGCRootFlagsRefCounted =         0x8,
-};
-
-enum EtwGCRootKind
-{
-    kEtwGCRootKindStack =               0,
-    kEtwGCRootKindFinalizer =           1,
-    kEtwGCRootKindHandle =              2,
-    kEtwGCRootKindOther =               3,
-};
-
 enum EtwTypeFlags
 {
     kEtwTypeFlagsDelegate =                         0x1,
index 63d1cad..6b67674 100644 (file)
@@ -21,6 +21,7 @@
 #include "eeprofinterfaces.h"
 #include "shash.h"
 #include "eventtracebase.h"
+#include "gcinterface.h"
 
 class SimpleRWLock;
 
index 7c6f940..8e2594b 100644 (file)
@@ -303,6 +303,18 @@ void GCToEEInterface::SyncBlockCachePromotionsGranted(int max_gen)
     SyncBlockCache::GetSyncBlockCache()->GCDone(FALSE, max_gen);
 }
 
+uint32_t GCToEEInterface::GetActiveSyncBlockCount()
+{
+    CONTRACTL
+    {
+        NOTHROW;
+        GC_NOTRIGGER;
+    }
+    CONTRACTL_END;
+
+    return SyncBlockCache::GetSyncBlockCache()->GetActiveCount();   
+}
+
 gc_alloc_context * GCToEEInterface::GetAllocContext(Thread * pThread)
 {
     WRAPPER_NO_CONTRACT;
index dc09618..4529669 100644 (file)
@@ -28,6 +28,7 @@ public:
     void SyncBlockCacheWeakPtrScan(HANDLESCANPROC scanProc, uintptr_t lp1, uintptr_t lp2);
     void SyncBlockCacheDemote(int max_gen);
     void SyncBlockCachePromotionsGranted(int max_gen);
+    uint32_t GetActiveSyncBlockCount();
     bool IsPreemptiveGCDisabled(Thread * pThread);
     void EnablePreemptiveGC(Thread * pThread);
     void DisablePreemptiveGC(Thread * pThread);
index 9345a18..4361778 100644 (file)
@@ -48,10 +48,6 @@ void ValidateHandleAssignment(OBJECTHANDLE handle, OBJECTREF objRef)
 
 void DiagHandleCreated(OBJECTHANDLE handle, OBJECTREF objRef)
 {
-#if defined(ENABLE_PERF_COUNTERS) || defined(FEATURE_EVENT_TRACE)
-    g_dwHandles++;
-#endif // defined(ENABLE_PERF_COUNTERS) || defined(FEATURE_EVENT_TRACE)
-
 #ifdef GC_PROFILING
     BEGIN_PIN_PROFILER(CORProfilerTrackGC());
     g_profControlBlock.pProfInterface->HandleCreated((uintptr_t)handle, (ObjectID)OBJECTREF_TO_UNCHECKED_OBJECTREF(objRef));
@@ -71,8 +67,4 @@ void DiagHandleDestroyed(OBJECTHANDLE handle)
 #else
     UNREFERENCED_PARAMETER(handle);
 #endif // GC_PROFILING
-
-#if defined(ENABLE_PERF_COUNTERS) || defined(FEATURE_EVENT_TRACE)
-    g_dwHandles--;
-#endif // defined(ENABLE_PERF_COUNTERS) || defined(FEATURE_EVENT_TRACE)
 }
index 3c54029..fac4cc5 100644 (file)
@@ -107,10 +107,6 @@ GPTR_IMPL(Thread,g_pSuspensionThread);
 // Global SyncBlock cache
 GPTR_IMPL(SyncTableEntry,g_pSyncTable);
 
-#if defined(ENABLE_PERF_COUNTERS) || defined(FEATURE_EVENT_TRACE)
-DWORD g_dwHandles = 0;
-#endif // ENABLE_PERF_COUNTERS || FEATURE_EVENT_TRACE
-
 #ifdef STRESS_LOG
 GPTR_IMPL_INIT(StressLog, g_pStressLog, &StressLog::theLog);
 #endif
index 820260a..b102b28 100644 (file)
@@ -435,12 +435,6 @@ GPTR_DECL(Thread,g_pSuspensionThread);
 typedef DPTR(SyncTableEntry) PTR_SyncTableEntry;
 GPTR_DECL(SyncTableEntry, g_pSyncTable);
 
-#if defined(ENABLE_PERF_COUNTERS) || defined(FEATURE_EVENT_TRACE)
-// Note this is not updated in a thread safe way so the value may not be accurate. We get
-// it accurately in full GCs if the handle count is requested.
-extern DWORD g_dwHandles;
-#endif // ENABLE_PERF_COUNTERS || FEATURE_EVENT_TRACE
-
 #ifdef FEATURE_COMINTEROP
 // Global RCW cleanup list
 typedef DPTR(RCWCleanupList) PTR_RCWCleanupList;