tidy up
authorSimon Marlow <marlowsd@gmail.com>
Tue, 21 Aug 2012 11:26:16 +0000 (12:26 +0100)
committerSimon Marlow <marlowsd@gmail.com>
Tue, 21 Aug 2012 11:26:16 +0000 (12:26 +0100)
rts/Schedule.c
rts/sm/GC.c

index 310e68e..a8de843 100644 (file)
@@ -1451,6 +1451,7 @@ scheduleDoGC (Capability **pcap, Task *task USED_IF_THREADS,
 {
     Capability *cap = *pcap;
     rtsBool heap_census;
+    nat collect_gen;
 #ifdef THREADED_RTS
     rtsBool idle_cap[n_capabilities];
     rtsBool gc_type;
@@ -1465,10 +1466,16 @@ scheduleDoGC (Capability **pcap, Task *task USED_IF_THREADS,
         return;
     }
 
+    heap_census = scheduleNeedHeapProfile(rtsTrue);
+
+    // Figure out which generation we are collecting, so that we can
+    // decide whether this is a parallel GC or not.
+    collect_gen = calcNeeded(force_major || heap_census, NULL);
+
 #ifdef THREADED_RTS
     if (sched_state < SCHED_INTERRUPTING
         && RtsFlags.ParFlags.parGcEnabled
-        && N >= RtsFlags.ParFlags.parGcGen
+        && collect_gen >= RtsFlags.ParFlags.parGcGen
         && ! oldest_gen->mark)
     {
         gc_type = SYNC_GC_PAR;
@@ -1540,7 +1547,7 @@ scheduleDoGC (Capability **pcap, Task *task USED_IF_THREADS,
 
         if (RtsFlags.ParFlags.parGcNoSyncWithIdle == 0
             || (RtsFlags.ParFlags.parGcLoadBalancingEnabled &&
-                N >= RtsFlags.ParFlags.parGcLoadBalancingGen)) {
+                collect_gen >= RtsFlags.ParFlags.parGcLoadBalancingGen)) {
             for (i=0; i < n_capabilities; i++) {
                 if (capabilities[i].disabled) {
                     idle_cap[i] = tryGrabCapability(&capabilities[i], task);
@@ -1645,15 +1652,13 @@ delete_threads_and_gc:
     }
 #endif
 
-    heap_census = scheduleNeedHeapProfile(rtsTrue);
-
 #if defined(THREADED_RTS)
     // reset pending_sync *before* GC, so that when the GC threads
     // emerge they don't immediately re-enter the GC.
     pending_sync = 0;
-    GarbageCollect(force_major || heap_census, heap_census, gc_type, cap);
+    GarbageCollect(collect_gen, heap_census, gc_type, cap);
 #else
-    GarbageCollect(force_major || heap_census, heap_census, 0, cap);
+    GarbageCollect(collect_gen, heap_census, 0, cap);
 #endif
 
     traceSparkCounters(cap);
index e9baa81..1b81b26 100644 (file)
@@ -166,11 +166,13 @@ StgPtr mark_sp;            // pointer to the next unallocated mark stack entry
 /* -----------------------------------------------------------------------------
    GarbageCollect: the main entry point to the garbage collector.
 
+   The collect_gen parameter is gotten by calling calcNeeded().
+
    Locks held: all capabilities are held throughout GarbageCollect().
    -------------------------------------------------------------------------- */
 
 void
-GarbageCollect (rtsBool force_major_gc, 
+GarbageCollect (nat collect_gen,
                 rtsBool do_heap_census,
                 nat gc_type USED_IF_THREADS,
                 Capability *cap)
@@ -234,7 +236,7 @@ GarbageCollect (rtsBool force_major_gc,
 
   /* Figure out which generation to collect
    */
-  N = calcNeeded(force_major_gc, NULL);
+  N = collect_gen;
   major_gc = (N == RtsFlags.GcFlags.generations-1);
 
 #if defined(THREADED_RTS)
@@ -751,9 +753,6 @@ GarbageCollect (rtsBool force_major_gc,
              live_blocks * BLOCK_SIZE_W - live_words /* slop */,
              N, n_gc_threads, par_max_copied, par_tot_copied);
 
-  // Guess which generation we'll collect *next* time
-  N = calcNeeded(force_major_gc, NULL);
-
 #if defined(RTS_USER_SIGNALS)
   if (RtsFlags.MiscFlags.install_signal_handlers) {
     // unblock signals again