]> git.llucax.com Git - software/dgc/cdgc.git/blobdiff - rt/gc/cdgc/gc.d
Avoid output duplication because of FILE* buffers
[software/dgc/cdgc.git] / rt / gc / cdgc / gc.d
index e53d5d13b20e35ccc2c6eb1fb7c989d03a1a44c0..96c6a86360d24277f0456ea9038f17580f90864d 100644 (file)
@@ -50,6 +50,7 @@ import opts = rt.gc.cdgc.opts;
 
 import cstdlib = tango.stdc.stdlib;
 import cstring = tango.stdc.string;
+import cstdio = tango.stdc.stdio;
 
 /*
  * This is a small optimization that proved it's usefulness. For small chunks
@@ -307,6 +308,8 @@ BlkInfo getInfo(void* p)
         return BlkInfo.init;
     BlkInfo info;
     info.base = pool.findBase(p);
+    if (info.base is null)
+        return BlkInfo.init;
     info.size = pool.findSize(info.base);
     info.attr = getAttr(pool, cast(size_t)(info.base - pool.baseAddr) / 16u);
     if (has_pointermap(info.attr)) {
@@ -784,6 +787,7 @@ size_t fullcollect(void *stackTop)
     gc.stats.world_stopped();
 
     if (opts.options.fork) {
+        cstdio.fflush(null); // avoid duplicated FILE* output
         os.pid_t child_pid = os.fork();
         assert (child_pid != -1); // don't accept errors in non-release mode
         switch (child_pid) {
@@ -822,9 +826,6 @@ void mark(void *stackTop)
 {
     debug(COLLECT_PRINTF) printf("\tmark()\n");
 
-    gc.p_cache = null;
-    gc.size_cache = 0;
-
     gc.any_changes = false;
     for (size_t n = 0; n < gc.pools.length; n++)
     {
@@ -970,6 +971,8 @@ size_t sweep()
 {
     // Free up everything not marked
     debug(COLLECT_PRINTF) printf("\tsweep\n");
+    gc.p_cache = null;
+    gc.size_cache = 0;
     size_t freedpages = 0;
     size_t freed = 0;
     for (size_t n = 0; n < gc.pools.length; n++)
@@ -999,7 +1002,7 @@ version(none) // BUG: doesn't work because freebits() must also be cleared
                 {
                     for (; p < ptop; p += size, bit_i += bit_stride)
                     {
-                        if (pool.finals.nbits && pool.finals.testClear(bit_i)) {
+                        if (pool.finals.testClear(bit_i)) {
                             if (opts.options.sentinel)
                                 rt_finalize(sentinel_add(p), false/*gc.no_stack > 0*/);
                             else
@@ -1023,7 +1026,7 @@ version(none) // BUG: doesn't work because freebits() must also be cleared
                             sentinel_Invariant(sentinel_add(p));
 
                         pool.freebits.set(bit_i);
-                        if (pool.finals.nbits && pool.finals.testClear(bit_i)) {
+                        if (pool.finals.testClear(bit_i)) {
                             if (opts.options.sentinel)
                                 rt_finalize(sentinel_add(p), false/*gc.no_stack > 0*/);
                             else
@@ -1046,7 +1049,7 @@ version(none) // BUG: doesn't work because freebits() must also be cleared
                     byte *p = pool.baseAddr + pn * PAGESIZE;
                     if (opts.options.sentinel)
                         sentinel_Invariant(sentinel_add(p));
-                    if (pool.finals.nbits && pool.finals.testClear(bit_i)) {
+                    if (pool.finals.testClear(bit_i)) {
                         if (opts.options.sentinel)
                             rt_finalize(sentinel_add(p), false/*gc.no_stack > 0*/);
                         else
@@ -1149,14 +1152,11 @@ in
 body
 {
     uint attrs;
-
-    if (pool.finals.nbits &&
-        pool.finals.test(bit_i))
+    if (pool.finals.test(bit_i))
         attrs |= BlkAttr.FINALIZE;
     if (pool.noscan.test(bit_i))
         attrs |= BlkAttr.NO_SCAN;
-//        if (pool.nomove.nbits &&
-//            pool.nomove.test(bit_i))
+//        if (pool.nomove.test(bit_i))
 //            attrs |= BlkAttr.NO_MOVE;
     return attrs;
 }
@@ -1174,8 +1174,6 @@ body
 {
     if (mask & BlkAttr.FINALIZE)
     {
-        if (!pool.finals.nbits)
-            pool.finals.alloc(pool.mark.nbits);
         pool.finals.set(bit_i);
     }
     if (mask & BlkAttr.NO_SCAN)
@@ -1201,7 +1199,7 @@ in
 }
 body
 {
-    if (mask & BlkAttr.FINALIZE && pool.finals.nbits)
+    if (mask & BlkAttr.FINALIZE)
         pool.finals.clear(bit_i);
     if (mask & BlkAttr.NO_SCAN)
         pool.noscan.clear(bit_i);