]> granicus.if.org Git - gc/commitdiff
2011-04-07 Ivan Maidanski <ivmai@mail.ru>
authorivmai <ivmai>
Thu, 7 Apr 2011 20:35:46 +0000 (20:35 +0000)
committerIvan Maidanski <ivmai@mail.ru>
Tue, 26 Jul 2011 17:06:57 +0000 (21:06 +0400)
* alloc.c (GC_check_heap, GC_print_all_smashed): Move the
definition from misc.c.
* dbg_mlc.c (GC_debug_malloc_atomic_uncollectable): Define as
public.
* include/gc.h (GC_debug_malloc_atomic_uncollectable): Declare.
* include/gc.h (GC_MALLOC_ATOMIC_UNCOLLECTABLE): Define new public
macro.
* dbg_mlc.c (MAX_SMASHED): Don't define if already set.
* reclaim.c (MAX_LEAKED): Ditto.
* dbg_mlc.c (GC_add_smashed): Add FIXME about the concurrent
access to the global array.
* reclaim.c (GC_add_leaked): Ditto.
* misc.c (GC_print_back_height): Set on if GC_PRINT_BACK_HEIGHT
(new macro) is defined.
* doc/README.macros (GC_PRINT_BACK_HEIGHT): Document.
* misc.c (GC_dump_regularly, GC_init): Replace 0/1 for
GC_dump_regularly and GC_print_back_height variables with
FALSE/TRUE.
* reclaim.c (GC_print_all_errors): Refine the comment.

ChangeLog
alloc.c
dbg_mlc.c
doc/README.macros
include/gc.h
include/private/gc_priv.h
misc.c
reclaim.c

index 26522ba005387658164a9095efbf026cdba28350..db572e1225fc411013d1836ee48814cee0c05083 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,25 @@
+2011-04-07  Ivan Maidanski  <ivmai@mail.ru>
+
+       * alloc.c (GC_check_heap, GC_print_all_smashed): Move the
+       definition from misc.c.
+       * dbg_mlc.c (GC_debug_malloc_atomic_uncollectable): Define as
+       public.
+       * include/gc.h (GC_debug_malloc_atomic_uncollectable): Declare.
+       * include/gc.h (GC_MALLOC_ATOMIC_UNCOLLECTABLE): Define new public
+       macro.
+       * dbg_mlc.c (MAX_SMASHED): Don't define if already set.
+       * reclaim.c (MAX_LEAKED): Ditto.
+       * dbg_mlc.c (GC_add_smashed): Add FIXME about the concurrent
+       access to the global array.
+       * reclaim.c (GC_add_leaked): Ditto.
+       * misc.c (GC_print_back_height): Set on if GC_PRINT_BACK_HEIGHT
+       (new macro) is defined.
+       * doc/README.macros (GC_PRINT_BACK_HEIGHT): Document.
+       * misc.c (GC_dump_regularly, GC_init): Replace 0/1 for
+       GC_dump_regularly and GC_print_back_height variables with
+       FALSE/TRUE.
+       * reclaim.c (GC_print_all_errors): Refine the comment.
+
 2011-04-04  Ivan Maidanski  <ivmai@mail.ru>
 
        * tests/test.c (reverse_test_inner): Undo one of the previous
diff --git a/alloc.c b/alloc.c
index dffbc014623cb0220aa881be2b501dd7865d3700..79fce2a25b55b61fe4729afc6fed1a902d6ee089 100644 (file)
--- a/alloc.c
+++ b/alloc.c
@@ -541,6 +541,9 @@ GC_INNER void GC_collect_a_little_inner(int n)
     RESTORE_CANCEL(cancel_state);
 }
 
+GC_INNER void (*GC_check_heap)(void) = 0;
+GC_INNER void (*GC_print_all_smashed)(void) = 0;
+
 GC_API int GC_CALL GC_collect_a_little(void)
 {
     int result;
index f8727f6b5ee86feaf5c99efdbf64ef5524e94481..bc14d08c94e3ed081aefabcfb9d61693e67c9fd2 100644 (file)
--- a/dbg_mlc.c
+++ b/dbg_mlc.c
@@ -571,11 +571,11 @@ GC_API void * GC_CALL GC_debug_malloc_atomic_ignore_off_page(size_t lb,
     ADD_CALL_CHAIN(result, GC_RETURN_ADDR);
     return (GC_store_debug_info_inner(result, (word)lb, "INTERNAL", (word)0));
   }
-#endif
+#endif /* DBG_HDRS_ALL */
 
 #ifdef STUBBORN_ALLOC
-GC_API void * GC_CALL GC_debug_malloc_stubborn(size_t lb, GC_EXTRA_PARAMS)
-{
+  GC_API void * GC_CALL GC_debug_malloc_stubborn(size_t lb, GC_EXTRA_PARAMS)
+  {
     void * result = GC_malloc_stubborn(lb + DEBUG_BYTES);
 
     if (result == 0) {
@@ -590,10 +590,10 @@ GC_API void * GC_CALL GC_debug_malloc_stubborn(size_t lb, GC_EXTRA_PARAMS)
     }
     ADD_CALL_CHAIN(result, ra);
     return (GC_store_debug_info(result, (word)lb, s, (word)i));
-}
+  }
 
-GC_API void GC_CALL GC_debug_change_stubborn(void *p)
-{
+  GC_API void GC_CALL GC_debug_change_stubborn(void *p)
+  {
     void * q = GC_base(p);
     hdr * hhdr;
 
@@ -607,10 +607,10 @@ GC_API void GC_CALL GC_debug_change_stubborn(void *p)
         ABORT("GC_debug_change_stubborn: arg not stubborn");
     }
     GC_change_stubborn(q);
-}
+  }
 
-GC_API void GC_CALL GC_debug_end_stubborn_change(void *p)
-{
+  GC_API void GC_CALL GC_debug_end_stubborn_change(void *p)
+  {
     void * q = GC_base(p);
     hdr * hhdr;
 
@@ -624,21 +624,20 @@ GC_API void GC_CALL GC_debug_end_stubborn_change(void *p)
         ABORT("GC_debug_end_stubborn_change: arg not stubborn");
     }
     GC_end_stubborn_change(q);
-}
+  }
 
 #else /* !STUBBORN_ALLOC */
 
-GC_API void * GC_CALL GC_debug_malloc_stubborn(size_t lb, GC_EXTRA_PARAMS)
-{
+  GC_API void * GC_CALL GC_debug_malloc_stubborn(size_t lb, GC_EXTRA_PARAMS)
+  {
     return GC_debug_malloc(lb, OPT_RA s, i);
-}
-
-/*ARGSUSED*/
-GC_API void GC_CALL GC_debug_change_stubborn(void *p) {}
+  }
 
-/*ARGSUSED*/
-GC_API void GC_CALL GC_debug_end_stubborn_change(void *p) {}
+  /*ARGSUSED*/
+  GC_API void GC_CALL GC_debug_change_stubborn(void *p) {}
 
+  /*ARGSUSED*/
+  GC_API void GC_CALL GC_debug_end_stubborn_change(void *p) {}
 #endif /* !STUBBORN_ALLOC */
 
 GC_API void * GC_CALL GC_debug_malloc_atomic(size_t lb, GC_EXTRA_PARAMS)
@@ -742,7 +741,8 @@ GC_API void * GC_CALL GC_debug_malloc_uncollectable(size_t lb,
 }
 
 #ifdef ATOMIC_UNCOLLECTABLE
-  void * GC_debug_malloc_atomic_uncollectable(size_t lb, GC_EXTRA_PARAMS)
+  GC_API void * GC_CALL GC_debug_malloc_atomic_uncollectable(size_t lb,
+                                                             GC_EXTRA_PARAMS)
   {
     void * result =
         GC_malloc_atomic_uncollectable(lb + UNCOLLECTABLE_DEBUG_BYTES);
@@ -913,13 +913,16 @@ GC_API void * GC_CALL GC_debug_realloc(void * p, size_t lb, GC_EXTRA_PARAMS)
 /* always print them nicely with the allocation lock held.              */
 /* We put them here instead of in GC_arrays, since it may be useful to  */
 /* be able to look at them with the debugger.                           */
-#define MAX_SMASHED 20
+#ifndef MAX_SMASHED
+# define MAX_SMASHED 20
+#endif
 STATIC ptr_t GC_smashed[MAX_SMASHED] = {0};
 STATIC unsigned GC_n_smashed = 0;
 
 STATIC void GC_add_smashed(ptr_t smashed)
 {
     GC_ASSERT(GC_is_marked(GC_base(smashed)));
+    /* FIXME: Prevent adding an object while printing smashed list.     */
     GC_smashed[GC_n_smashed] = smashed;
     if (GC_n_smashed < MAX_SMASHED - 1) ++GC_n_smashed;
       /* In case of overflow, we keep the first MAX_SMASHED-1   */
index 50eab283535b9d59a5195d0af4ed623d9633c9f1..1b49200061ade0e8c1a84f7e890e8bbaf4a0f78c 100644 (file)
@@ -416,6 +416,10 @@ MAKE_BACK_GRAPH         Enable GC_PRINT_BACK_HEIGHT environment variable.
   support.  Implies DBG_HDRS_ALL.  All allocation should be done using
   the debug interface.
 
+GC_PRINT_BACK_HEIGHT    Permanently turn on back-height printing mode
+  (useful when NO_GETENV).  See the similar environment variable description
+  in README.environment.  Requires MAKE_BACK_GRAPH defined.
+
 STUBBORN_ALLOC  Allows allocation of "hard to change" objects, and thus
   makes incremental collection easier.  Was enabled by default until 6.0.
   Rarely used, to my knowledge.
index 2354acdcf26accc6f70690dfb9ac9f9145a2155a..e702fd25bba5b62065b5bdee22b4e25a923f0aeb 100644 (file)
@@ -364,12 +364,6 @@ GC_API void * GC_CALL GC_memalign(size_t /* align */, size_t /* lb */)
 GC_API int GC_CALL GC_posix_memalign(void ** /* memptr */, size_t /* align */,
                         size_t /* lb */);
 
-/* The following is only defined if the library has been suitably       */
-/* compiled:                                                            */
-GC_API void * GC_CALL GC_malloc_atomic_uncollectable(
-                                                size_t /* size_in_bytes */)
-                        GC_ATTR_MALLOC GC_ATTR_ALLOC_SIZE(1);
-
 /* Explicitly deallocate an object.  Dangerous if used incorrectly.     */
 /* Requires a pointer to the base of an object.                         */
 /* If the argument is stubborn, it should not be changeable when freed. */
@@ -597,6 +591,15 @@ GC_API void * GC_CALL GC_malloc_atomic_ignore_off_page(size_t /* lb */)
 # define GC_EXTRA_PARAMS const char * s, int i
 #endif
 
+/* The following is only defined if the library has been suitably       */
+/* compiled:                                                            */
+GC_API void * GC_CALL GC_malloc_atomic_uncollectable(
+                                                size_t /* size_in_bytes */)
+                        GC_ATTR_MALLOC GC_ATTR_ALLOC_SIZE(1);
+GC_API void * GC_CALL GC_debug_malloc_atomic_uncollectable(size_t,
+                                                           GC_EXTRA_PARAMS)
+                        GC_ATTR_MALLOC GC_ATTR_ALLOC_SIZE(1);
+
 /* Debugging (annotated) allocation.  GC_gcollect will check            */
 /* objects allocated in this way for overwrites, etc.                   */
 GC_API void * GC_CALL GC_debug_malloc(size_t /* size_in_bytes */,
@@ -661,6 +664,8 @@ GC_API void * GC_CALL GC_debug_realloc_replacement(void * /* object_addr */,
 # define GC_MALLOC_ATOMIC(sz) GC_debug_malloc_atomic(sz, GC_EXTRAS)
 # define GC_STRDUP(s) GC_debug_strdup(s, GC_EXTRAS)
 # define GC_STRNDUP(s, sz) GC_debug_strndup(s, sz, GC_EXTRAS)
+# define GC_MALLOC_ATOMIC_UNCOLLECTABLE(sz) \
+                        GC_debug_malloc_atomic_uncollectable(sz, GC_EXTRAS)
 # define GC_MALLOC_UNCOLLECTABLE(sz) \
                         GC_debug_malloc_uncollectable(sz, GC_EXTRAS)
 # define GC_MALLOC_IGNORE_OFF_PAGE(sz) \
@@ -686,6 +691,7 @@ GC_API void * GC_CALL GC_debug_realloc_replacement(void * /* object_addr */,
 # define GC_MALLOC_ATOMIC(sz) GC_malloc_atomic(sz)
 # define GC_STRDUP(s) GC_strdup(s)
 # define GC_STRNDUP(s, sz) GC_strndup(s, sz)
+# define GC_MALLOC_ATOMIC_UNCOLLECTABLE(sz) GC_malloc_atomic_uncollectable(sz)
 # define GC_MALLOC_UNCOLLECTABLE(sz) GC_malloc_uncollectable(sz)
 # define GC_MALLOC_IGNORE_OFF_PAGE(sz) \
                         GC_malloc_ignore_off_page(sz)
index b8f48792c2ba39b7f118d6bb27300bca8d9e605a..8919532770abf597e9e4211057e24a1a12018507 100644 (file)
@@ -1788,7 +1788,8 @@ GC_EXTERN void (*GC_print_heap_obj)(ptr_t p);
 
 GC_EXTERN GC_bool GC_have_errors; /* We saw a smashed or leaked object. */
                                   /* Call error printing routine        */
-                                  /* occasionally.                      */
+                                  /* occasionally.  It is ok to read it */
+                                  /* without acquiring the lock.        */
 
 #ifndef SMALL_CONFIG
   /* GC_print_stats should be visible outside the GC in some cases.     */
diff --git a/misc.c b/misc.c
index a27d9aa4f2581f696157b1493a8874db0c2c9d1d..51a9248301f3ed3fcc7cb6bbb0e53431d87c77a5 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -76,9 +76,6 @@ GC_FAR struct _GC_arrays GC_arrays /* = { 0 } */;
 GC_INNER GC_bool GC_debugging_started = FALSE;
         /* defined here so we don't have to load debug_malloc.o */
 
-GC_INNER void (*GC_check_heap)(void) = 0;
-GC_INNER void (*GC_print_all_smashed)(void) = 0;
-
 ptr_t GC_stackbottom = 0;
 
 #ifdef IA64
@@ -95,10 +92,14 @@ GC_bool GC_quiet = 0; /* used also in pcr_interface.c */
   GC_bool GC_print_stats = 0;
 #endif
 
-GC_INNER GC_bool GC_print_back_height = 0;
+#ifdef GC_PRINT_BACK_HEIGHT
+  GC_INNER GC_bool GC_print_back_height = TRUE;
+#else
+  GC_INNER GC_bool GC_print_back_height = FALSE;
+#endif
 
 #ifndef NO_DEBUGGING
-  GC_INNER GC_bool GC_dump_regularly = 0;
+  GC_INNER GC_bool GC_dump_regularly = FALSE;
                                 /* Generate regular debugging dumps. */
 #endif
 
@@ -739,7 +740,7 @@ GC_API void GC_CALL GC_init(void)
 #   endif /* !SMALL_CONFIG */
 #   ifndef NO_DEBUGGING
       if (0 != GETENV("GC_DUMP_REGULARLY")) {
-        GC_dump_regularly = 1;
+        GC_dump_regularly = TRUE;
       }
 #   endif
 #   ifdef KEEP_BACK_PTRS
@@ -761,7 +762,7 @@ GC_API void GC_CALL GC_init(void)
       GC_dont_gc = 1;
     }
     if (0 != GETENV("GC_PRINT_BACK_HEIGHT")) {
-      GC_print_back_height = 1;
+      GC_print_back_height = TRUE;
     }
     if (0 != GETENV("GC_NO_BLACKLIST_WARNING")) {
       GC_large_alloc_warn_interval = LONG_MAX;
index a0f6dd32d6fadb587e0e49ab0fb087b18bc76a5e..e17d374a670de083fc6a85ad56329a4a9257de30 100644 (file)
--- a/reclaim.c
+++ b/reclaim.c
@@ -33,7 +33,9 @@ GC_INNER signed_word GC_bytes_found = 0;
 /* We defer printing of leaked objects until we're done with the GC     */
 /* cycle, since the routine for printing objects needs to run outside   */
 /* the collector, e.g. without the allocation lock.                     */
-#define MAX_LEAKED 40
+#ifndef MAX_LEAKED
+# define MAX_LEAKED 40
+#endif
 STATIC ptr_t GC_leaked[MAX_LEAKED] = { NULL };
 STATIC unsigned GC_n_leaked = 0;
 
@@ -41,16 +43,17 @@ GC_INNER GC_bool GC_have_errors = FALSE;
 
 STATIC void GC_add_leaked(ptr_t leaked)
 {
+    GC_have_errors = TRUE;
+    /* FIXME: Prevent adding an object while printing leaked ones.      */
     if (GC_n_leaked < MAX_LEAKED) {
-      GC_have_errors = TRUE;
       GC_leaked[GC_n_leaked++] = leaked;
       /* Make sure it's not reclaimed this cycle */
-        GC_set_mark_bit(leaked);
+      GC_set_mark_bit(leaked);
     }
 }
 
 /* Print all objects on the list after printing any smashed objects.    */
-/* Clear both lists.                                                    */
+/* Clear both lists.  Called without the allocation lock held.          */
 GC_INNER void GC_print_all_errors(void)
 {
     static GC_bool printing_errors = FALSE;