[project @ 2002-11-28 10:04:15 by simonpj]
[ghc-hetmet.git] / ghc / rts / GCCompact.c
index 1bd21f3..ea2e474 100644 (file)
@@ -1,5 +1,5 @@
 /* -----------------------------------------------------------------------------
- * $Id: GCCompact.c,v 1.7 2001/08/08 13:44:13 simonmar Exp $
+ * $Id: GCCompact.c,v 1.12 2002/03/12 11:51:06 simonmar Exp $
  *
  * (c) The GHC Team 2001
  *
@@ -7,6 +7,7 @@
  *
  * ---------------------------------------------------------------------------*/
 
+#include "PosixSource.h"
 #include "Rts.h"
 #include "RtsUtils.h"
 #include "RtsFlags.h"
@@ -446,18 +447,11 @@ update_fwd( bdescr *blocks )
                break;
            }
 
-           // specialise this case, because we want to update the
-           // mut_link field too.
            case IND_OLDGEN:
            case IND_OLDGEN_PERM:
-           {
-               StgIndOldGen *ind = (StgIndOldGen *)p;
-               thread((StgPtr)&ind->indirectee);
-               if (ind->mut_link != NULL) {
-                   thread((StgPtr)&ind->mut_link);
-               }
+               thread((StgPtr)&((StgIndOldGen *)p)->indirectee);
+               p += sizeofW(StgIndOldGen);
                break;
-           }
 
            case THUNK_SELECTOR:
            { 
@@ -516,7 +510,9 @@ static void
 update_fwd_compact( bdescr *blocks )
 {
     StgPtr p, q, free;
+#if 0
     StgWord m;
+#endif
     bdescr *bd, *free_bd;
     StgInfoTable *info;
     nat size;
@@ -661,17 +657,9 @@ update_fwd_compact( bdescr *blocks )
 
            case IND_OLDGEN:
            case IND_OLDGEN_PERM:
-               // specialise this case, because we want to update the
-               // mut_link field too.
-           {
-               StgIndOldGen *ind = (StgIndOldGen *)p;
-               thread((StgPtr)&ind->indirectee);
-               if (ind->mut_link != NULL) {
-                   thread((StgPtr)&ind->mut_link);
-               }
+               thread((StgPtr)&((StgIndOldGen *)p)->indirectee);
                p += sizeofW(StgIndOldGen);
                break;
-           }
 
            case THUNK_SELECTOR:
            { 
@@ -749,7 +737,9 @@ static nat
 update_bkwd_compact( step *stp )
 {
     StgPtr p, free;
+#if 0
     StgWord m;
+#endif
     bdescr *bd, *free_bd;
     StgInfoTable *info;
     nat size, free_blocks;
@@ -813,8 +803,6 @@ update_bkwd_compact( step *stp )
            }
 
            // Rebuild the mutable list for the old generation.
-           // (the mut_once list is updated using threading, with
-           // special cases for IND_OLDGEN and MUT_CONS above).
            if (ip_MUTABLE(info)) {
                recordMutable((StgMutClosure *)free);
            }
@@ -841,14 +829,26 @@ update_bkwd_compact( step *stp )
     stp->n_blocks = free_blocks;
 
     return free_blocks;
-} 
+}
+
+static void
+thread_mut_once_list( generation *g )
+{
+    StgMutClosure *p, *next;
+
+    for (p = g->mut_once_list; p != END_MUT_LIST; p = next) {
+       next = p->mut_link;
+       thread((StgPtr)&p->mut_link);
+    }
+    
+    thread((StgPtr)&g->mut_once_list);
+}
 
 void
 compact( void (*get_roots)(evac_fn) )
 {
     nat g, s, blocks;
     step *stp;
-    extern StgWeak *old_weak_ptr_list; // tmp
 
     // 1. thread the roots
     get_roots((evac_fn)thread);
@@ -864,18 +864,32 @@ compact( void (*get_roots)(evac_fn) )
     // mutable lists
     for (g = 1; g < RtsFlags.GcFlags.generations; g++) {
        thread((StgPtr)&generations[g].mut_list);
-       thread((StgPtr)&generations[g].mut_once_list);
+       thread_mut_once_list(&generations[g]);
     }
 
     // the global thread list
     thread((StgPtr)&all_threads);
 
+    // any threads resurrected during this GC
+    thread((StgPtr)&resurrected_threads);
+
+    // the main threads list
+    {
+       StgMainThread *m;
+       for (m = main_threads; m != NULL; m = m->link) {
+           thread((StgPtr)&m->tso);
+       }
+    }
+
     // the static objects
     thread_static(scavenged_static_objects);
 
     // the stable pointer table
     threadStablePtrTable((evac_fn)thread);
 
+    // the CAF list (used by GHCi)
+    markCAFs((evac_fn)thread);
+
     // 2. update forward ptrs
     for (g = 0; g < RtsFlags.GcFlags.generations; g++) {
        for (s = 0; s < generations[g].n_steps; s++) {