[Local GC] Add TrapReturningThreads to the GC/EE interface (#12067)
authorSean Gillespie <segilles@microsoft.com>
Tue, 6 Jun 2017 05:23:46 +0000 (22:23 -0700)
committerGitHub <noreply@github.com>
Tue, 6 Jun 2017 05:23:46 +0000 (22:23 -0700)
src/gc/env/gcenv.ee.h
src/gc/gc.cpp
src/gc/gcenv.ee.standalone.inl
src/gc/gcimpl.h
src/gc/gcinterface.ee.h
src/gc/sample/gcenv.ee.cpp
src/vm/gcenv.ee.cpp
src/vm/gcenv.ee.h

index bb335c6..ed5173f 100644 (file)
@@ -49,6 +49,7 @@ public:
     static bool IsPreemptiveGCDisabled(Thread * pThread);
     static void EnablePreemptiveGC(Thread * pThread);
     static void DisablePreemptiveGC(Thread * pThread);
+    static bool TrapReturningThreads();
 
     static gc_alloc_context * GetAllocContext(Thread * pThread);
     static bool CatchAtSafePoint(Thread * pThread);
index 962e09b..47de5a4 100644 (file)
@@ -1496,7 +1496,7 @@ void WaitLongerNoInstru (int i)
     }
 
     // if we're waiting for gc to finish, we should block immediately
-    if (!g_TrapReturningThreads)
+    if (!GCToEEInterface::TrapReturningThreads())
     {
         if  (g_num_processors > 1)
         {
@@ -1516,7 +1516,7 @@ void WaitLongerNoInstru (int i)
     // is in a tight loop.  If the thread has high priority, the perf is going to be very BAD.
     if (pCurThread)
     {
-        if (bToggleGC || g_TrapReturningThreads)
+        if (bToggleGC || GCToEEInterface::TrapReturningThreads())
         {
 #ifdef _DEBUG
             // In debug builds, all enter_spin_lock operations go through this code.  If a GC has
@@ -1537,7 +1537,7 @@ void WaitLongerNoInstru (int i)
             }
         }
     }
-    else if (g_TrapReturningThreads)
+    else if (GCToEEInterface::TrapReturningThreads())
     {
         g_theGCHeap->WaitUntilGCComplete();
     }
index 642d150..a673e73 100644 (file)
@@ -134,6 +134,12 @@ ALWAYS_INLINE void GCToEEInterface::DisablePreemptiveGC(Thread * pThread)
     g_theGCToCLR->DisablePreemptiveGC(pThread);
 }
 
+ALWAYS_INLINE bool GCToEEInterface::TrapReturningThreads()
+{
+    assert(g_theGCToCLR != nullptr);
+    return g_theGCToCLR->TrapReturningThreads();
+}
+
 ALWAYS_INLINE gc_alloc_context * GCToEEInterface::GetAllocContext(Thread * pThread)
 {
     assert(g_theGCToCLR != nullptr);
index 8ac16c5..c0efa69 100644 (file)
@@ -254,7 +254,7 @@ private:
         // to threads returning to cooperative mode is down after gc.
         // In other words, if the sequence in GCHeap::RestartEE changes,
         // the condition here may have to change as well.
-        return g_TrapReturningThreads == 0;
+        return !GCToEEInterface::TrapReturningThreads();
     }
 public:
     //return TRUE if GC actually happens, otherwise FALSE
index 32dcc03..b6a1d82 100644 (file)
@@ -77,6 +77,10 @@ public:
     virtual
     void DisablePreemptiveGC(Thread * pThread) = 0;
 
+    // Returns whether or not a thread suspension is pending.
+    virtual
+    bool TrapReturningThreads() = 0;
+
     // Retrieves the alloc context associated with a given thread.
     virtual
     gc_alloc_context * GetAllocContext(Thread * pThread) = 0;
index 03d9608..1867f1c 100644 (file)
@@ -190,6 +190,11 @@ void GCToEEInterface::DisablePreemptiveGC(Thread * pThread)
     pThread->DisablePreemptiveGC();
 }
 
+bool GCToEEInterface::TrapReturningThreads()
+{
+    return !!g_TrapReturningThreads;
+}
+
 gc_alloc_context * GCToEEInterface::GetAllocContext(Thread * pThread)
 {
     return pThread->GetAllocContext();
index 38c8ef0..f520c1a 100644 (file)
@@ -356,6 +356,12 @@ void GCToEEInterface::DisablePreemptiveGC(Thread * pThread)
     pThread->DisablePreemptiveGC();
 }
 
+bool GCToEEInterface::TrapReturningThreads()
+{
+    WRAPPER_NO_CONTRACT;
+    return !!g_TrapReturningThreads;
+}
+
 struct BackgroundThreadStubArgs
 {
     Thread* thread;
index 6b02f5c..4871e51 100644 (file)
@@ -31,6 +31,7 @@ public:
     bool IsPreemptiveGCDisabled(Thread * pThread);
     void EnablePreemptiveGC(Thread * pThread);
     void DisablePreemptiveGC(Thread * pThread);
+    bool TrapReturningThreads();
     gc_alloc_context * GetAllocContext(Thread * pThread);
     bool CatchAtSafePoint(Thread * pThread);
     void GcEnumAllocContexts(enum_alloc_context_func* fn, void* param);