]> granicus.if.org Git - gc/commitdiff
2011-03-20 Ivan Maidanski <ivmai@mail.ru>
authorivmai <ivmai>
Sun, 20 Mar 2011 09:08:55 +0000 (09:08 +0000)
committerIvan Maidanski <ivmai@mail.ru>
Tue, 26 Jul 2011 17:06:56 +0000 (21:06 +0400)
* alloc.c (GC_finish_collection): Remove redundant brackets;
adjust code indentation.
* blacklst.c (GC_add_to_black_list_normal): Simplify expression
(to improve code readability).
* blacklst.c (GC_is_black_listed): Join nested "if" (into a single
conditional expression); initialize "nblocks" just before the loop
beginning.
* misc.c (GC_init): Don't compute initial_heap_sz if GC is already
initialized.
* include/private/gc_priv.h (GC_initialize_offsets): Move the
function declaration to misc.c file.
* obj_map.c (GC_initialize_offsets): Remove offsets_initialized
static variable since the function is called only once.
* tests/middle.c: Include "gc.h" instead of <gc.h>; expand all
tabs to spaces; adjust code indentation; replace the K&R-style
function definition with the ANSI C one.
* tests/smash_test.c: Ditto.
* tests/middle.c (main): Use setter for GC_all_interior_pointers;
adjust printf format specifier (and cast the value passed to).

ChangeLog
alloc.c
blacklst.c
include/private/gc_priv.h
misc.c
obj_map.c
tests/middle.c
tests/smash_test.c

index 69f23836e9715af83c8e13778257b90ed20a4110..0024cf704c81970c21a304a42c07b9fab6be7000 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,25 @@
+2011-03-20  Ivan Maidanski  <ivmai@mail.ru>
+
+       * alloc.c (GC_finish_collection): Remove redundant brackets;
+       adjust code indentation.
+       * blacklst.c (GC_add_to_black_list_normal): Simplify expression
+       (to improve code readability).
+       * blacklst.c (GC_is_black_listed): Join nested "if" (into a single
+       conditional expression); initialize "nblocks" just before the loop
+       beginning.
+       * misc.c (GC_init): Don't compute initial_heap_sz if GC is already
+       initialized.
+       * include/private/gc_priv.h (GC_initialize_offsets): Move the
+       function declaration to misc.c file.
+       * obj_map.c (GC_initialize_offsets): Remove offsets_initialized
+       static variable since the function is called only once.
+       * tests/middle.c: Include "gc.h" instead of <gc.h>; expand all
+       tabs to spaces; adjust code indentation; replace the K&R-style
+       function definition with the ANSI C one.
+       * tests/smash_test.c: Ditto.
+       * tests/middle.c (main): Use setter for GC_all_interior_pointers;
+       adjust printf format specifier (and cast the value passed to).
+
 2011-03-15  Ivan Maidanski  <ivmai@mail.ru>
 
        * doc/README.macros (SMALL_CONFIG, LARGE_CONFIG): Refine the
diff --git a/alloc.c b/alloc.c
index 2b0c11d289eb1db85b5bf37aa18ad21fb19a4c7d..d18b771061e4243294f6a2fc119dae52c3ada239 100644 (file)
--- a/alloc.c
+++ b/alloc.c
@@ -820,22 +820,20 @@ STATIC void GC_finish_collection(void)
 #   endif
     COND_DUMP;
     if (GC_find_leak) {
-      /* Mark all objects on the free list.  All objects should be */
-      /* marked when we're done.                                   */
-        {
-          word size;            /* current object size          */
-          unsigned kind;
-          ptr_t q;
-
-          for (kind = 0; kind < GC_n_kinds; kind++) {
-            for (size = 1; size <= MAXOBJGRANULES; size++) {
-              q = GC_obj_kinds[kind].ok_freelist[size];
-              if (q != 0) GC_set_fl_marks(q);
-            }
-          }
+      /* Mark all objects on the free list.  All objects should be      */
+      /* marked when we're done.                                        */
+      word size;        /* current object size  */
+      unsigned kind;
+      ptr_t q;
+
+      for (kind = 0; kind < GC_n_kinds; kind++) {
+        for (size = 1; size <= MAXOBJGRANULES; size++) {
+          q = GC_obj_kinds[kind].ok_freelist[size];
+          if (q != 0) GC_set_fl_marks(q);
         }
-        GC_start_reclaim(TRUE);
-          /* The above just checks; it doesn't really reclaim anything. */
+      }
+      GC_start_reclaim(TRUE);
+        /* The above just checks; it doesn't really reclaim anything.   */
     }
 
     GC_finalize();
@@ -863,40 +861,38 @@ STATIC void GC_finish_collection(void)
     /* Note that composite objects on free list are cleared.             */
     /* Thus accidentally marking a free list is not a problem;  only     */
     /* objects on the list itself will be marked, and that's fixed here. */
-      {
-        word size;              /* current object size          */
-        ptr_t q;        /* pointer to current object    */
-        unsigned kind;
-
-        for (kind = 0; kind < GC_n_kinds; kind++) {
-          for (size = 1; size <= MAXOBJGRANULES; size++) {
-            q = GC_obj_kinds[kind].ok_freelist[size];
-            if (q != 0) GC_clear_fl_marks(q);
-          }
+    {
+      word size;        /* current object size          */
+      ptr_t q;          /* pointer to current object    */
+      unsigned kind;
+
+      for (kind = 0; kind < GC_n_kinds; kind++) {
+        for (size = 1; size <= MAXOBJGRANULES; size++) {
+          q = GC_obj_kinds[kind].ok_freelist[size];
+          if (q != 0) GC_clear_fl_marks(q);
         }
       }
-
+    }
 
     if (GC_print_stats == VERBOSE)
         GC_log_printf("Bytes recovered before sweep - f.l. count = %ld\n",
                   (long)GC_bytes_found);
 
     /* Reconstruct free lists to contain everything not marked */
-        GC_start_reclaim(FALSE);
-        if (GC_print_stats) {
-          GC_log_printf("Heap contains %lu pointer-containing "
-                        "+ %lu pointer-free reachable bytes\n",
-                        (unsigned long)GC_composite_in_use,
-                        (unsigned long)GC_atomic_in_use);
-        }
-        if (GC_is_full_gc) {
-            GC_used_heap_size_after_full = USED_HEAP_SIZE;
-            GC_need_full_gc = FALSE;
-        } else {
-            GC_need_full_gc =
-                 USED_HEAP_SIZE - GC_used_heap_size_after_full
-                 > min_bytes_allocd();
-        }
+    GC_start_reclaim(FALSE);
+    if (GC_print_stats) {
+      GC_log_printf("Heap contains %lu pointer-containing "
+                    "+ %lu pointer-free reachable bytes\n",
+                    (unsigned long)GC_composite_in_use,
+                    (unsigned long)GC_atomic_in_use);
+    }
+    if (GC_is_full_gc) {
+        GC_used_heap_size_after_full = USED_HEAP_SIZE;
+        GC_need_full_gc = FALSE;
+    } else {
+        GC_need_full_gc = USED_HEAP_SIZE - GC_used_heap_size_after_full
+                            > min_bytes_allocd();
+    }
 
     if (GC_print_stats == VERBOSE) {
 #       ifdef USE_MUNMAP
@@ -912,14 +908,14 @@ STATIC void GC_finish_collection(void)
     }
 
     /* Reset or increment counters for next cycle */
-      GC_n_attempts = 0;
-      GC_is_full_gc = FALSE;
-      GC_bytes_allocd_before_gc += GC_bytes_allocd;
-      GC_non_gc_bytes_at_gc = GC_non_gc_bytes;
-      GC_bytes_allocd = 0;
-      GC_bytes_dropped = 0;
-      GC_bytes_freed = 0;
-      GC_finalizer_bytes_freed = 0;
+    GC_n_attempts = 0;
+    GC_is_full_gc = FALSE;
+    GC_bytes_allocd_before_gc += GC_bytes_allocd;
+    GC_non_gc_bytes_at_gc = GC_non_gc_bytes;
+    GC_bytes_allocd = 0;
+    GC_bytes_dropped = 0;
+    GC_bytes_freed = 0;
+    GC_finalizer_bytes_freed = 0;
 
 #   ifdef USE_MUNMAP
       GC_unmap_old();
index 25ebea8e177a403031e27e6b524198b92b60bc0b..1fb9d00c93d655d770a2f13d740088b1ddc69a26 100644 (file)
@@ -172,24 +172,22 @@ GC_INNER void GC_unpromote_black_lists(void)
   GC_INNER void GC_add_to_black_list_normal(word p)
 #endif
 {
-    if (!(GC_modws_valid_offsets[p & (sizeof(word)-1)])) return;
-    {
-        word index = PHT_HASH((word)p);
+  if (GC_modws_valid_offsets[p & (sizeof(word)-1)]) {
+    word index = PHT_HASH((word)p);
 
-        if (HDR(p) == 0 || get_pht_entry_from_index(GC_old_normal_bl, index)) {
-#           ifdef PRINT_BLACK_LIST
-                if (!get_pht_entry_from_index(GC_incomplete_normal_bl, index)) {
-                  GC_err_printf(
-                        "Black listing (normal) %p referenced from %p ",
-                        (ptr_t) p, source);
-                  GC_print_source_ptr(source);
-                  GC_err_puts("\n");
-                }
-#           endif
-            set_pht_entry_from_index(GC_incomplete_normal_bl, index);
-        } /* else this is probably just an interior pointer to an allocated */
-          /* object, and isn't worth black listing.                         */
-    }
+    if (HDR(p) == 0 || get_pht_entry_from_index(GC_old_normal_bl, index)) {
+#     ifdef PRINT_BLACK_LIST
+        if (!get_pht_entry_from_index(GC_incomplete_normal_bl, index)) {
+          GC_err_printf("Black listing (normal) %p referenced from %p ",
+                        (ptr_t)p, source);
+          GC_print_source_ptr(source);
+          GC_err_puts("\n");
+        }
+#     endif
+      set_pht_entry_from_index(GC_incomplete_normal_bl, index);
+    } /* else this is probably just an interior pointer to an allocated */
+      /* object, and isn't worth black listing.                         */
+  }
 }
 
 /* And the same for false pointers from the stack. */
@@ -199,20 +197,19 @@ GC_INNER void GC_unpromote_black_lists(void)
   GC_INNER void GC_add_to_black_list_stack(word p)
 #endif
 {
-    word index = PHT_HASH((word)p);
+  word index = PHT_HASH((word)p);
 
-    if (HDR(p) == 0 || get_pht_entry_from_index(GC_old_stack_bl, index)) {
-#       ifdef PRINT_BLACK_LIST
-            if (!get_pht_entry_from_index(GC_incomplete_stack_bl, index)) {
-                  GC_err_printf(
-                        "Black listing (stack) %p referenced from %p ",
-                        (ptr_t)p, source);
-                  GC_print_source_ptr(source);
-                  GC_err_puts("\n");
-            }
-#       endif
-        set_pht_entry_from_index(GC_incomplete_stack_bl, index);
-    }
+  if (HDR(p) == 0 || get_pht_entry_from_index(GC_old_stack_bl, index)) {
+#   ifdef PRINT_BLACK_LIST
+      if (!get_pht_entry_from_index(GC_incomplete_stack_bl, index)) {
+        GC_err_printf("Black listing (stack) %p referenced from %p ",
+                      (ptr_t)p, source);
+        GC_print_source_ptr(source);
+        GC_err_puts("\n");
+      }
+#   endif
+    set_pht_entry_from_index(GC_incomplete_stack_bl, index);
+  }
 }
 
 /*
@@ -227,20 +224,20 @@ GC_INNER struct hblk * GC_is_black_listed(struct hblk *h, word len)
 {
     word index = PHT_HASH((word)h);
     word i;
-    word nblocks = divHBLKSZ(len);
+    word nblocks;
 
-    if (!GC_all_interior_pointers) {
-      if (get_pht_entry_from_index(GC_old_normal_bl, index)
-          || get_pht_entry_from_index(GC_incomplete_normal_bl, index)) {
-        return(h+1);
-      }
+    if (!GC_all_interior_pointers
+        && (get_pht_entry_from_index(GC_old_normal_bl, index)
+            || get_pht_entry_from_index(GC_incomplete_normal_bl, index))) {
+      return (h+1);
     }
 
+    nblocks = divHBLKSZ(len);
     for (i = 0;;) {
         if (GC_old_stack_bl[divWORDSZ(index)] == 0
             && GC_incomplete_stack_bl[divWORDSZ(index)] == 0) {
             /* An easy case */
-            i += WORDSZ - modWORDSZ(index);
+          i += WORDSZ - modWORDSZ(index);
         } else {
           if (get_pht_entry_from_index(GC_old_stack_bl, index)
               || get_pht_entry_from_index(GC_incomplete_stack_bl, index)) {
index 79e9555594f5ec5654844c135ebb79d1dd09b26b..c51a0b0f19dc408b8b77c4f4adce97a13151036e 100644 (file)
@@ -1593,11 +1593,6 @@ GC_INNER void GC_register_displacement_inner(size_t offset);
                                 /* Version of GC_register_displacement  */
                                 /* that assumes lock is already held.   */
 
-GC_INNER void GC_initialize_offsets(void);
-                                /* Initialize GC_valid_offsets,         */
-                                /* depending on current                 */
-                                /* GC_all_interior_pointers settings.   */
-
 /*  hblk allocation: */
 GC_INNER void GC_new_hblk(size_t size_in_granules, int kind);
                                 /* Allocate a new heap block, and build */
diff --git a/misc.c b/misc.c
index b05822859bbc81e6e22b7b13285f0b294e653fde..75b92b066834cb649abc3d4d3fe520a90f319472 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -630,21 +630,24 @@ STATIC void GC_exit_check(void)
   STATIC int GC_log = 2;
 #endif
 
+GC_INNER void GC_initialize_offsets(void);      /* defined in obj_map.c */
+
 GC_API void GC_CALL GC_init(void)
 {
     /* LOCK(); -- no longer does anything this early. */
 #   if !defined(THREADS) && defined(GC_ASSERTIONS)
         word dummy;
 #   endif
-#   ifdef GC_INITIAL_HEAP_SIZE
-        word initial_heap_sz = divHBLKSZ(GC_INITIAL_HEAP_SIZE);
-#   else
-        word initial_heap_sz = (word)MINHINCR;
-#   endif
+    word initial_heap_sz;
     IF_CANCEL(int cancel_state;)
 
     if (GC_is_initialized) return;
 
+#   ifdef GC_INITIAL_HEAP_SIZE
+      initial_heap_sz = divHBLKSZ(GC_INITIAL_HEAP_SIZE);
+#   else
+      initial_heap_sz = (word)MINHINCR;
+#   endif
     DISABLE_CANCEL(cancel_state);
     /* Note that although we are nominally called with the */
     /* allocation lock held, the allocation lock is now    */
index 972ba4916265b97c74cf6bf41a2017343b551e3e..8bd099303a4dc8481086283ff8b41398c9d637a8 100644 (file)
--- a/obj_map.c
+++ b/obj_map.c
@@ -78,14 +78,9 @@ GC_INNER void GC_register_displacement_inner(size_t offset)
 
 GC_INNER void GC_initialize_offsets(void)
 {
-    static GC_bool offsets_initialized = FALSE;
-
-    if (!offsets_initialized) {
-      int i;
-      if (GC_all_interior_pointers) {
-        for (i = 0; i < VALID_OFFSET_SZ; ++i)
-          GC_valid_offsets[i] = TRUE;
-      }
-      offsets_initialized = TRUE;
-    }
+  int i;
+  if (GC_all_interior_pointers) {
+    for (i = 0; i < VALID_OFFSET_SZ; ++i)
+      GC_valid_offsets[i] = TRUE;
+  }
 }
index ebb348c493bd52a01d26700767f12b30b708dfda..ff0a2355d1597fee9fbff6b3b6558821a4053f26 100644 (file)
@@ -2,25 +2,24 @@
  * Test at the boundary between small and large objects.
  * Inspired by a test case from Zoltan Varga.
  */
-#include <gc.h>
+#include "gc.h"
 #include <stdio.h>
 
-int main ()
+int main (void)
 {
-        int i;
+  int i;
 
-        GC_all_interior_pointers = 0;
-       GC_INIT();
+  GC_set_all_interior_pointers(0);
+  GC_INIT();
 
-        for (i = 0; i < 20000; ++i) {
-                GC_malloc_atomic (4096);
-                GC_malloc (4096);
-       }
-        for (i = 0; i < 20000; ++i) {
-                GC_malloc_atomic (2048);
-                GC_malloc (2048);
-       }
-       printf("Final heap size is %ld\n", GC_get_heap_size());
-       return 0;
+  for (i = 0; i < 20000; ++i) {
+    GC_malloc_atomic (4096);
+    GC_malloc (4096);
+  }
+  for (i = 0; i < 20000; ++i) {
+    GC_malloc_atomic (2048);
+    GC_malloc (2048);
+  }
+  printf("Final heap size is %lu\n", (unsigned long)GC_get_heap_size());
+  return 0;
 }
-
index b94af9074d1dd862275e437ffaf45eecd732d4d0..86e081bdef9e491e723b35a8966f36fed9edd72c 100644 (file)
@@ -2,7 +2,8 @@
  * Test that overwrite error detection works reasonably.
  */
 #define GC_DEBUG
-#include <gc.h>
+#include "gc.h"
+
 #include <stdio.h>
 
 #define COUNT 7000
 
 char * A[COUNT];
 
-int main ()
+int main(void)
 {
-        int i;
-       char *p;
+  int i;
+  char *p;
 
-       GC_INIT();
+  GC_INIT();
 
-        for (i = 0; i < COUNT; ++i) {
-               A[i] = p = GC_MALLOC(SIZE);
+  for (i = 0; i < COUNT; ++i) {
+     A[i] = p = GC_MALLOC(SIZE);
 
-               if (i%3000 == 0) GC_gcollect();
-               if (i%5678 == 0) p[SIZE + i/2000] = 42;
-       }
-       return 0;
+     if (i%3000 == 0) GC_gcollect();
+     if (i%5678 == 0) p[SIZE + i/2000] = 42;
+  }
+  return 0;
 }
-