From 766e02e43ef8fcb055f3a4370f69d926778bbfad Mon Sep 17 00:00:00 2001 From: vsadov Date: Mon, 7 Sep 2020 01:53:50 -0700 Subject: [PATCH] Dependent Handles --- src/coreclr/src/gc/satori/SatoriRecycler.cpp | 69 +++++++++++++++++--- src/coreclr/src/gc/satori/SatoriRecycler.h | 3 + 2 files changed, 63 insertions(+), 9 deletions(-) diff --git a/src/coreclr/src/gc/satori/SatoriRecycler.cpp b/src/coreclr/src/gc/satori/SatoriRecycler.cpp index d83083f0601..9586c483337 100644 --- a/src/coreclr/src/gc/satori/SatoriRecycler.cpp +++ b/src/coreclr/src/gc/satori/SatoriRecycler.cpp @@ -96,26 +96,38 @@ void SatoriRecycler::Collect() // drain queues DrainMarkQueues(); - // mark handles to queues + // mark handles MarkHandles(); while (m_workList->Count() > 0) { DrainMarkQueues(); - //mark through cards (could be due to overflow) + //TODO: VS clean cards (could be due to overflow) } - // all marked here + // all strongly reachable objects are marked here + + DependentHandlesInitialScan(); + while (m_workList->Count() > 0) + { + DrainMarkQueues(); + //TODO: VS clean cards (could be due to overflow) + DependentHandlesRescan(); + } - // TODO: VS - // DH initial scan (could be a part of loop above?) // sync WeakPtrScan(/*isShort*/ true); // sync ScanFinalizables(); - DrainMarkQueues(); - // scan DH again (why no sync before?) + // TODO: VS why no sync before? + while (m_workList->Count() > 0) + { + DrainMarkQueues(); + //TODO: VS clean cards (could be due to overflow) + DependentHandlesRescan(); + } + // sync WeakPtrScan(/*isShort*/ false); WeakPtrScanBySingleThread(); @@ -424,7 +436,6 @@ void SatoriRecycler::DrainMarkQueues() void SatoriRecycler::MarkHandles() { - // mark roots for the current stack ScanContext sc; sc.promotion = TRUE; sc.thread_number = 0; @@ -444,7 +455,6 @@ void SatoriRecycler::MarkHandles() void SatoriRecycler::WeakPtrScan(bool isShort) { - // mark roots for the current stack ScanContext sc; sc.promotion = TRUE; sc.thread_number = 0; @@ -602,3 +612,44 @@ void SatoriRecycler::ScanFinalizables() m_workList->Push(c.m_markChunk); } } + +void SatoriRecycler::DependentHandlesInitialScan() +{ + ScanContext sc; + sc.promotion = TRUE; + sc.thread_number = 0; + + MarkContext c = MarkContext(this); + sc._unused1 = &c; + + // concurrent, per thread/heap + // relies on thread_number to select handle buckets and specialcases #0 + GCScan::GcDhInitialScan(MarkFn, 2, 2, &sc); + + if (c.m_markChunk != nullptr) + { + m_workList->Push(c.m_markChunk); + } +} + +void SatoriRecycler::DependentHandlesRescan() +{ + ScanContext sc; + sc.promotion = TRUE; + sc.thread_number = 0; + + MarkContext c = MarkContext(this); + sc._unused1 = &c; + + // concurrent, per thread/heap + // relies on thread_number to select handle buckets and specialcases #0 + if (GCScan::GcDhUnpromotedHandlesExist(&sc)) + { + GCScan::GcDhReScan(&sc); + } + + if (c.m_markChunk != nullptr) + { + m_workList->Push(c.m_markChunk); + } +} diff --git a/src/coreclr/src/gc/satori/SatoriRecycler.h b/src/coreclr/src/gc/satori/SatoriRecycler.h index edc84ceeae1..11765509953 100644 --- a/src/coreclr/src/gc/satori/SatoriRecycler.h +++ b/src/coreclr/src/gc/satori/SatoriRecycler.h @@ -67,6 +67,9 @@ private: void WeakPtrScan(bool isShort); void WeakPtrScanBySingleThread(); void ScanFinalizables(); + + void DependentHandlesInitialScan(); + void DependentHandlesRescan(); }; #endif