Commit 5aab1d9c authored by Ömer Sinan Ağacan's avatar Ömer Sinan Ağacan Committed by Marge Bot

rts: Unglobalize dead_weak_ptr_list and resurrected_threads

In the concurrent nonmoving collector we will need the ability to call
`traverseWeakPtrList` concurrently with minor generation collections.
This global state stands in the way of this. However, refactoring it
away is straightforward since this list only persists the length of a
single GC.
parent 2ff77b98
...@@ -940,7 +940,7 @@ update_bkwd_compact( generation *gen ) ...@@ -940,7 +940,7 @@ update_bkwd_compact( generation *gen )
} }
void void
compact(StgClosure *static_objects) compact(StgClosure *static_objects, StgWeak *dead_weak_ptr_list, StgTSO *resurrected_threads)
{ {
W_ n, g, blocks; W_ n, g, blocks;
generation *gen; generation *gen;
......
...@@ -45,6 +45,8 @@ is_marked(StgPtr p, bdescr *bd) ...@@ -45,6 +45,8 @@ is_marked(StgPtr p, bdescr *bd)
return (*bitmap_word & bit_mask); return (*bitmap_word & bit_mask);
} }
void compact (StgClosure *static_objects); void compact (StgClosure *static_objects,
StgWeak *dead_weak_ptr_list,
StgTSO *resurrected_threads);
#include "EndPrivate.h" #include "EndPrivate.h"
...@@ -416,15 +416,20 @@ GarbageCollect (uint32_t collect_gen, ...@@ -416,15 +416,20 @@ GarbageCollect (uint32_t collect_gen,
* Repeatedly scavenge all the areas we know about until there's no * Repeatedly scavenge all the areas we know about until there's no
* more scavenging to be done. * more scavenging to be done.
*/ */
StgWeak *dead_weak_ptr_list = NULL;
StgTSO *resurrected_threads = END_TSO_QUEUE;
for (;;) for (;;)
{ {
scavenge_until_all_done(); scavenge_until_all_done();
// The other threads are now stopped. We might recurse back to // The other threads are now stopped. We might recurse back to
// here, but from now on this is the only thread. // here, but from now on this is the only thread.
// must be last... invariant is that everything is fully // must be last... invariant is that everything is fully
// scavenged at this point. // scavenged at this point.
if (traverseWeakPtrList()) { // returns true if evaced something if (traverseWeakPtrList(&dead_weak_ptr_list, &resurrected_threads)) { // returns true if evaced something
inc_running(); inc_running();
continue; continue;
} }
...@@ -468,7 +473,7 @@ GarbageCollect (uint32_t collect_gen, ...@@ -468,7 +473,7 @@ GarbageCollect (uint32_t collect_gen,
// Finally: compact or sweep the oldest generation. // Finally: compact or sweep the oldest generation.
if (major_gc && oldest_gen->mark) { if (major_gc && oldest_gen->mark) {
if (oldest_gen->compact) if (oldest_gen->compact)
compact(gct->scavenged_static_objects); compact(gct->scavenged_static_objects, dead_weak_ptr_list, resurrected_threads);
else else
sweep(oldest_gen); sweep(oldest_gen);
} }
......
...@@ -77,15 +77,9 @@ ...@@ -77,15 +77,9 @@
typedef enum { WeakPtrs, WeakThreads, WeakDone } WeakStage; typedef enum { WeakPtrs, WeakThreads, WeakDone } WeakStage;
static WeakStage weak_stage; static WeakStage weak_stage;
// List of weak pointers whose key is dead static void collectDeadWeakPtrs (generation *gen, StgWeak **dead_weak_ptr_list);
StgWeak *dead_weak_ptr_list;
// List of threads found to be unreachable
StgTSO *resurrected_threads;
static void collectDeadWeakPtrs (generation *gen);
static bool tidyWeakList (generation *gen); static bool tidyWeakList (generation *gen);
static bool resurrectUnreachableThreads (generation *gen); static bool resurrectUnreachableThreads (generation *gen, StgTSO **resurrected_threads);
static void tidyThreadList (generation *gen); static void tidyThreadList (generation *gen);
void void
...@@ -100,12 +94,10 @@ initWeakForGC(void) ...@@ -100,12 +94,10 @@ initWeakForGC(void)
} }
weak_stage = WeakThreads; weak_stage = WeakThreads;
dead_weak_ptr_list = NULL;
resurrected_threads = END_TSO_QUEUE;
} }
bool bool
traverseWeakPtrList(void) traverseWeakPtrList(StgWeak **dead_weak_ptr_list, StgTSO **resurrected_threads)
{ {
bool flag = false; bool flag = false;
...@@ -140,7 +132,7 @@ traverseWeakPtrList(void) ...@@ -140,7 +132,7 @@ traverseWeakPtrList(void)
// Resurrect any threads which were unreachable // Resurrect any threads which were unreachable
for (g = 0; g <= N; g++) { for (g = 0; g <= N; g++) {
if (resurrectUnreachableThreads(&generations[g])) { if (resurrectUnreachableThreads(&generations[g], resurrected_threads)) {
flag = true; flag = true;
} }
} }
...@@ -175,7 +167,7 @@ traverseWeakPtrList(void) ...@@ -175,7 +167,7 @@ traverseWeakPtrList(void)
*/ */
if (flag == false) { if (flag == false) {
for (g = 0; g <= N; g++) { for (g = 0; g <= N; g++) {
collectDeadWeakPtrs(&generations[g]); collectDeadWeakPtrs(&generations[g], dead_weak_ptr_list);
} }
weak_stage = WeakDone; // *now* we're done, weak_stage = WeakDone; // *now* we're done,
...@@ -190,7 +182,7 @@ traverseWeakPtrList(void) ...@@ -190,7 +182,7 @@ traverseWeakPtrList(void)
} }
} }
static void collectDeadWeakPtrs (generation *gen) static void collectDeadWeakPtrs (generation *gen, StgWeak **dead_weak_ptr_list)
{ {
StgWeak *w, *next_w; StgWeak *w, *next_w;
for (w = gen->old_weak_ptr_list; w != NULL; w = next_w) { for (w = gen->old_weak_ptr_list; w != NULL; w = next_w) {
...@@ -201,12 +193,12 @@ static void collectDeadWeakPtrs (generation *gen) ...@@ -201,12 +193,12 @@ static void collectDeadWeakPtrs (generation *gen)
} }
evacuate(&w->finalizer); evacuate(&w->finalizer);
next_w = w->link; next_w = w->link;
w->link = dead_weak_ptr_list; w->link = *dead_weak_ptr_list;
dead_weak_ptr_list = w; *dead_weak_ptr_list = w;
} }
} }
static bool resurrectUnreachableThreads (generation *gen) static bool resurrectUnreachableThreads (generation *gen, StgTSO **resurrected_threads)
{ {
StgTSO *t, *tmp, *next; StgTSO *t, *tmp, *next;
bool flag = false; bool flag = false;
...@@ -225,8 +217,8 @@ static bool resurrectUnreachableThreads (generation *gen) ...@@ -225,8 +217,8 @@ static bool resurrectUnreachableThreads (generation *gen)
default: default:
tmp = t; tmp = t;
evacuate((StgClosure **)&tmp); evacuate((StgClosure **)&tmp);
tmp->global_link = resurrected_threads; tmp->global_link = *resurrected_threads;
resurrected_threads = tmp; *resurrected_threads = tmp;
flag = true; flag = true;
} }
} }
......
...@@ -19,7 +19,7 @@ extern StgTSO *resurrected_threads; ...@@ -19,7 +19,7 @@ extern StgTSO *resurrected_threads;
void collectFreshWeakPtrs ( void ); void collectFreshWeakPtrs ( void );
void initWeakForGC ( void ); void initWeakForGC ( void );
bool traverseWeakPtrList ( void ); bool traverseWeakPtrList ( StgWeak **dead_weak_ptr_list, StgTSO **resurrected_threads );
void markWeakPtrList ( void ); void markWeakPtrList ( void );
void scavengeLiveWeak ( StgWeak * ); void scavengeLiveWeak ( StgWeak * );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment