boehm-gc: revert all CACAO-specific modifications; this is now an exact copy of the...
[cacao.git] / src / mm / boehm-gc / checksums.c
index 6673f4184831b7c84031a3c380e4bcf482515772..275026d5538fe097f3a517667cc451122db78c91 100644 (file)
@@ -11,9 +11,6 @@
  * modified is included with the above copyright notice.
  */
 /* Boehm, March 29, 1995 12:51 pm PST */
-
-#include "config.h"
-
 # ifdef CHECKSUMS
 
 # include "private/gc_priv.h"
@@ -37,8 +34,34 @@ typedef struct {
 
 page_entry GC_sums [NSUMS];
 
-word GC_checksum(h)
-struct hblk *h;
+STATIC word GC_faulted[NSUMS]; /* Record of pages on which we saw a write */
+                               /* fault.                                  */
+STATIC size_t GC_n_faulted = 0;
+
+void GC_record_fault(struct hblk * h)
+{
+    word page = (word)h;
+
+    page += GC_page_size - 1;
+    page &= ~(GC_page_size - 1);
+    if (GC_n_faulted >= NSUMS) ABORT("write fault log overflowed");
+    GC_faulted[GC_n_faulted++] = page;
+}
+
+STATIC GC_bool GC_was_faulted(struct hblk *h)
+{
+    size_t i;
+    word page = (word)h;
+
+    page += GC_page_size - 1;
+    page &= ~(GC_page_size - 1);
+    for (i = 0; i < GC_n_faulted; ++i) {
+       if (GC_faulted[i] == page) return TRUE;
+    }
+    return FALSE;
+}
+
+STATIC word GC_checksum(struct hblk *h)
 {
     register word *p = (word *)h;
     register word *lim = (word *)(h+1);
@@ -53,11 +76,10 @@ struct hblk *h;
 # ifdef STUBBORN_ALLOC
 /* Check whether a stubborn object from the given block appears on     */
 /* the appropriate free list.                                          */
-GC_bool GC_on_free_list(struct hblk *h)
-struct hblk *h;
+STATIC GC_bool GC_on_free_list(struct hblk *h)
 {
     hdr * hhdr = HDR(h);
-    int sz = BYTES_TO_WORDS(hhdr -> hb_sz);
+    size_t sz = BYTES_TO_WORDS(hhdr -> hb_sz);
     ptr_t p;
     
     if (sz > MAXOBJWORDS) return(FALSE);
@@ -69,11 +91,12 @@ struct hblk *h;
 # endif
  
 int GC_n_dirty_errors;
+int GC_n_faulted_dirty_errors;
 int GC_n_changed_errors;
 int GC_n_clean;
 int GC_n_dirty;
 
-void GC_update_check_page(struct hblk *h, int index)
+STATIC void GC_update_check_page(struct hblk *h, int index)
 {
     page_entry *pe = GC_sums + index;
     register hdr * hhdr = HDR(h);
@@ -101,7 +124,9 @@ void GC_update_check_page(struct hblk *h, int index)
        && hhdr != 0 && hhdr -> hb_descr != 0 /* may contain pointers */
        && pe -> old_sum != pe -> new_sum) {
        if (!GC_page_was_dirty(h) || !GC_page_was_ever_dirty(h)) {
+           GC_bool was_faulted = GC_was_faulted(h);
            /* Set breakpoint here */GC_n_dirty_errors++;
+           if (was_faulted) GC_n_faulted_dirty_errors++;
        }
 #      ifdef STUBBORN_ALLOC
          if (!HBLK_IS_FREE(hhdr)
@@ -118,28 +143,28 @@ void GC_update_check_page(struct hblk *h, int index)
     pe -> block = h + OFFSET;
 }
 
-unsigned long GC_bytes_in_used_blocks;
+word GC_bytes_in_used_blocks;
 
-void GC_add_block(h, dummy)
-struct hblk *h;
-word dummy;
+/*ARGSUSED*/
+STATIC void GC_add_block(struct hblk *h, word dummy)
 {
    hdr * hhdr = HDR(h);
-   bytes = hhdr -> hb_sz;
+   size_t bytes = hhdr -> hb_sz;
    
    bytes += HBLKSIZE-1;
    bytes &= ~(HBLKSIZE-1);
    GC_bytes_in_used_blocks += bytes;
 }
 
-void GC_check_blocks()
+STATIC void GC_check_blocks(void)
 {
-    unsigned long bytes_in_free_blocks = GC_large_free_bytes;
+    word bytes_in_free_blocks = GC_large_free_bytes;
     
     GC_bytes_in_used_blocks = 0;
     GC_apply_to_all_blocks(GC_add_block, (word)0);
     GC_printf("GC_bytes_in_used_blocks = %lu, bytes_in_free_blocks = %lu ",
-             GC_bytes_in_used_blocks, bytes_in_free_blocks);
+             (unsigned long)GC_bytes_in_used_blocks,
+             (unsigned long)bytes_in_free_blocks);
     GC_printf("GC_heapsize = %lu\n", (unsigned long)GC_heapsize);
     if (GC_bytes_in_used_blocks + bytes_in_free_blocks != GC_heapsize) {
        GC_printf("LOST SOME BLOCKS!!\n");
@@ -147,16 +172,17 @@ void GC_check_blocks()
 }
 
 /* Should be called immediately after GC_read_dirty and GC_read_changed. */
-void GC_check_dirty()
+void GC_check_dirty(void)
 {
-    register int index;
-    register unsigned i;
-    register struct hblk *h;
-    register ptr_t start;
+    int index;
+    unsigned i;
+    struct hblk *h;
+    ptr_t start;
     
     GC_check_blocks();
     
     GC_n_dirty_errors = 0;
+    GC_n_faulted_dirty_errors = 0;
     GC_n_changed_errors = 0;
     GC_n_clean = 0;
     GC_n_dirty = 0;
@@ -176,8 +202,8 @@ out:
     GC_printf("Checked %lu clean and %lu dirty pages\n",
              (unsigned long) GC_n_clean, (unsigned long) GC_n_dirty);
     if (GC_n_dirty_errors > 0) {
-        GC_printf("Found %lu dirty bit errors\n",
-                 (unsigned long)GC_n_dirty_errors);
+        GC_printf("Found %d dirty bit errors (%d were faulted)\n",
+                 GC_n_dirty_errors, GC_n_faulted_dirty_errors);
     }
     if (GC_n_changed_errors > 0) {
        GC_printf("Found %lu changed bit errors\n",
@@ -188,6 +214,10 @@ out:
            "Also expect 1 per thread currently allocating a stubborn obj.\n");
 #      endif
     }
+    for (i = 0; i < GC_n_faulted; ++i) {
+        GC_faulted[i] = 0; /* Don't expose block pointers to GC */
+    }
+    GC_n_faulted = 0;
 }
 
 # else