Move sync block scan (#41600)
authorPeter Sollich <petersol@microsoft.com>
Thu, 26 Nov 2020 13:38:10 +0000 (14:38 +0100)
committerGitHub <noreply@github.com>
Thu, 26 Nov 2020 13:38:10 +0000 (14:38 +0100)
This change implements some primitive work stealing by executing GCScan::GcWeakPtrScanBySingleThread on the first thread that finishes GCScan::GcWeakPtrScan and sort_mark_list.

src/coreclr/src/gc/gc.cpp

index 0efd127..18cbbd2 100644 (file)
@@ -21819,11 +21819,13 @@ void gc_heap::mark_phase (int condemned_gen_number, BOOL mark_only_p)
     scan_dependent_handles(condemned_gen_number, &sc, false);
 
 #ifdef MULTIPLE_HEAPS
+    static VOLATILE(int32_t) syncblock_scan_p;
     dprintf(3, ("Joining for weak pointer deletion"));
     gc_t_join.join(this, gc_join_null_dead_long_weak);
     if (gc_t_join.joined())
     {
         dprintf(3, ("Starting all gc thread for weak pointer deletion"));
+        syncblock_scan_p = 0;
         gc_t_join.restart();
     }
 #endif //MULTIPLE_HEAPS
@@ -21838,17 +21840,21 @@ void gc_heap::mark_phase (int condemned_gen_number, BOOL mark_only_p)
 //    unsigned long start = GetCycleCount32();
     sort_mark_list();
 //    printf("sort_mark_list took %u cycles\n", GetCycleCount32() - start);
+    // first thread to finish sorting will scan the sync syncblk cache
+    if ((syncblock_scan_p == 0) && (Interlocked::Increment(&syncblock_scan_p) == 1))
 #endif //PARALLEL_MARK_LIST_SORT
 #endif //MARK_LIST
-
+#endif //MULTIPLE_HEAPS
+    {
+        // scan for deleted entries in the syncblk cache
+        GCScan::GcWeakPtrScanBySingleThread(condemned_gen_number, max_generation, &sc);
+    }
+#ifdef MULTIPLE_HEAPS
     dprintf (3, ("Joining for sync block cache entry scanning"));
     gc_t_join.join(this, gc_join_null_dead_syncblk);
     if (gc_t_join.joined())
 #endif //MULTIPLE_HEAPS
     {
-        // scan for deleted entries in the syncblk cache
-        GCScan::GcWeakPtrScanBySingleThread (condemned_gen_number, max_generation, &sc);
-
 #ifdef MULTIPLE_HEAPS
 #if defined(MARK_LIST) && !defined(PARALLEL_MARK_LIST_SORT)
         //compact g_mark_list and sort it.