summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2012-11-08 21:51:10 +0400
committerIvan Maidanski <ivmai@mail.ru>2012-11-08 22:15:03 +0400
commit60615a56f5a82e8d214d2c8267363cd1bc2a70d7 (patch)
treefe9f0070a366fc787e0ade6c6c209aac6c72868c
parent3ae3bfe965926c3fd940bcef4bfe8dcdf1613ddc (diff)
downloadbdwgc-60615a56f5a82e8d214d2c8267363cd1bc2a70d7.tar.gz
Improve GC error printing atomicity in GC_debug_X and GC_print_obj
* dbg_mlc.c (GC_generate_random_backtrace_no_gc): Refine comment. * dbg_mlc.c (GC_print_type): Replace multiple code fragments calling GC_err_puts with a single invocation of GC_err_puts (or GC_err_printf) at the routine end (code refactoring). * dbg_mlc.c (IF_NOT_SHORTDBG_HDRS, COMMA_IFNOT_SHORTDBG_HDRS): New macro (used by GC_print_obj). * dbg_mlc.c (GC_print_obj, GC_debug_malloc, GC_debug_malloc_ignore_off_page, GC_debug_malloc_atomic_ignore_off_page, GC_debug_malloc_stubborn, GC_debug_malloc_atomic, GC_debug_malloc_uncollectable, GC_debug_malloc_atomic_uncollectable): Replace adjacent GC_err_printf and GC_err_puts calls with a single GC_err_printf invocation (for output atomicity). * gcj_mlc.c (GC_debug_gcj_malloc): Likewise. * os_dep.c (GC_register_data_segments): Likewise. * dbg_mlc.c (GC_malloc_stubborn): Fix printed function name.
-rw-r--r--dbg_mlc.c109
-rw-r--r--gcj_mlc.c6
-rw-r--r--os_dep.c42
3 files changed, 63 insertions, 94 deletions
diff --git a/dbg_mlc.c b/dbg_mlc.c
index 8ce3387c..7e7a347e 100644
--- a/dbg_mlc.c
+++ b/dbg_mlc.c
@@ -226,8 +226,8 @@
out:;
}
- /* Force a garbage collection and generate a backtrace from a */
- /* random heap address. */
+ /* Force a garbage collection and generate/print a backtrace */
+ /* from a random heap address. */
GC_INNER void GC_generate_random_backtrace_no_gc(void)
{
void * current;
@@ -329,6 +329,7 @@ STATIC void GC_print_type(ptr_t p)
hdr * hhdr = GC_find_header(p);
char buffer[GC_TYPE_DESCR_LEN + 1];
int kind = hhdr -> hb_obj_kind;
+ char *kind_str;
if (0 != GC_describe_type_fns[kind] && GC_is_marked(GC_base(p))) {
/* This should preclude free list objects except with */
@@ -336,35 +337,48 @@ STATIC void GC_print_type(ptr_t p)
buffer[GC_TYPE_DESCR_LEN] = 0;
(GC_describe_type_fns[kind])(p, buffer);
GC_ASSERT(buffer[GC_TYPE_DESCR_LEN] == 0);
- GC_err_puts(buffer);
+ kind_str = buffer;
} else {
switch(kind) {
case PTRFREE:
- GC_err_puts("PTRFREE");
+ kind_str = "PTRFREE";
break;
case NORMAL:
- GC_err_puts("NORMAL");
+ kind_str = "NORMAL";
break;
case UNCOLLECTABLE:
- GC_err_puts("UNCOLLECTABLE");
+ kind_str = "UNCOLLECTABLE";
break;
# ifdef ATOMIC_UNCOLLECTABLE
case AUNCOLLECTABLE:
- GC_err_puts("ATOMIC UNCOLLECTABLE");
+ kind_str = "ATOMIC UNCOLLECTABLE";
break;
# endif
case STUBBORN:
- GC_err_puts("STUBBORN");
+ kind_str = "STUBBORN";
break;
default:
- GC_err_printf("kind=%d descr=0x%lx", kind,
- (unsigned long)(hhdr -> hb_descr));
+ kind_str = NULL;
}
}
+ if (NULL != kind_str) {
+ GC_err_puts(kind_str);
+ } else {
+ GC_err_printf("kind=%d descr=0x%lx",
+ kind, (unsigned long)hhdr->hb_descr);
+ }
}
#define GET_OH_LINENUM(ohdr) ((int)(ohdr)->oh_int)
+#ifndef SHORT_DBG_HDRS
+# define IF_NOT_SHORTDBG_HDRS(x) x
+# define COMMA_IFNOT_SHORTDBG_HDRS(x) /* comma */, x
+#else
+# define IF_NOT_SHORTDBG_HDRS(x) /* empty */
+# define COMMA_IFNOT_SHORTDBG_HDRS(x) /* empty */
+#endif
+
/* Print a human-readable description of the object to stderr. p points */
/* to somewhere inside an object with the debugging info. */
STATIC void GC_print_obj(ptr_t p)
@@ -375,14 +389,10 @@ STATIC void GC_print_obj(ptr_t p)
# ifdef LINT2
if (!ohdr) ABORT("Invalid GC_print_obj argument");
# endif
- GC_err_printf("%p (", ((ptr_t)ohdr + sizeof(oh)));
- GC_err_puts(ohdr -> oh_string);
-# ifdef SHORT_DBG_HDRS
- GC_err_printf(":%d, ", GET_OH_LINENUM(ohdr));
-# else
- GC_err_printf(":%d, sz=%lu, ",
- GET_OH_LINENUM(ohdr), (unsigned long)(ohdr -> oh_sz));
-# endif
+ GC_err_printf("%p (%s:%d," IF_NOT_SHORTDBG_HDRS(" sz=%lu,") " ",
+ (ptr_t)ohdr + sizeof(oh), ohdr->oh_string,
+ GET_OH_LINENUM(ohdr) /*, */
+ COMMA_IFNOT_SHORTDBG_HDRS((unsigned long)ohdr->oh_sz));
GC_print_type((ptr_t)(ohdr + 1));
GC_err_puts(")\n");
PRINT_CALL_CHAIN(ohdr);
@@ -481,10 +491,8 @@ GC_API void * GC_CALL GC_debug_malloc(size_t lb, GC_EXTRA_PARAMS)
result = GC_malloc(lb + DEBUG_BYTES);
if (result == 0) {
- GC_err_printf("GC_debug_malloc(%lu) returning NULL (",
- (unsigned long) lb);
- GC_err_puts(s);
- GC_err_printf(":%d)\n", i);
+ GC_err_printf("GC_debug_malloc(%lu) returning NULL (%s:%d)\n",
+ (unsigned long)lb, s, i);
return(0);
}
if (!GC_debugging_started) {
@@ -500,10 +508,8 @@ GC_API void * GC_CALL GC_debug_malloc_ignore_off_page(size_t lb,
void * result = GC_malloc_ignore_off_page(lb + DEBUG_BYTES);
if (result == 0) {
- GC_err_printf("GC_debug_malloc_ignore_off_page(%lu) returning NULL (",
- (unsigned long) lb);
- GC_err_puts(s);
- GC_err_printf(":%d)\n", i);
+ GC_err_printf("GC_debug_malloc_ignore_off_page(%lu)"
+ " returning NULL (%s:%d)\n", (unsigned long)lb, s, i);
return(0);
}
if (!GC_debugging_started) {
@@ -520,9 +526,7 @@ GC_API void * GC_CALL GC_debug_malloc_atomic_ignore_off_page(size_t lb,
if (result == 0) {
GC_err_printf("GC_debug_malloc_atomic_ignore_off_page(%lu)"
- " returning NULL (", (unsigned long)lb);
- GC_err_puts(s);
- GC_err_printf(":%d)\n", i);
+ " returning NULL (%s:%d)\n", (unsigned long)lb, s, i);
return(0);
}
if (!GC_debugging_started) {
@@ -579,10 +583,8 @@ GC_API void * GC_CALL GC_debug_malloc_atomic_ignore_off_page(size_t lb,
void * result = GC_malloc_stubborn(lb + DEBUG_BYTES);
if (result == 0) {
- GC_err_printf("GC_debug_malloc(%lu) returning NULL (",
- (unsigned long) lb);
- GC_err_puts(s);
- GC_err_printf(":%d)\n", i);
+ GC_err_printf("GC_debug_malloc_stubborn(%lu)"
+ " returning NULL (%s:%d)\n", (unsigned long)lb, s, i);
return(0);
}
if (!GC_debugging_started) {
@@ -645,10 +647,8 @@ GC_API void * GC_CALL GC_debug_malloc_atomic(size_t lb, GC_EXTRA_PARAMS)
void * result = GC_malloc_atomic(lb + DEBUG_BYTES);
if (result == 0) {
- GC_err_printf("GC_debug_malloc_atomic(%lu) returning NULL (",
- (unsigned long) lb);
- GC_err_puts(s);
- GC_err_printf(":%d)\n", i);
+ GC_err_printf("GC_debug_malloc_atomic(%lu) returning NULL (%s:%d)\n",
+ (unsigned long)lb, s, i);
return(0);
}
if (!GC_debugging_started) {
@@ -723,10 +723,8 @@ GC_API void * GC_CALL GC_debug_malloc_uncollectable(size_t lb,
void * result = GC_malloc_uncollectable(lb + UNCOLLECTABLE_DEBUG_BYTES);
if (result == 0) {
- GC_err_printf("GC_debug_malloc_uncollectable(%lu) returning NULL (",
- (unsigned long) lb);
- GC_err_puts(s);
- GC_err_printf(":%d)\n", i);
+ GC_err_printf("GC_debug_malloc_uncollectable(%lu)"
+ " returning NULL (%s:%d)\n", (unsigned long)lb, s, i);
return(0);
}
if (!GC_debugging_started) {
@@ -744,11 +742,8 @@ GC_API void * GC_CALL GC_debug_malloc_uncollectable(size_t lb,
GC_malloc_atomic_uncollectable(lb + UNCOLLECTABLE_DEBUG_BYTES);
if (result == 0) {
- GC_err_printf(
- "GC_debug_malloc_atomic_uncollectable(%lu) returning NULL (",
- (unsigned long) lb);
- GC_err_puts(s);
- GC_err_printf(":%d)\n", i);
+ GC_err_printf("GC_debug_malloc_atomic_uncollectable(%lu)"
+ " returning NULL (%s:%d)\n", (unsigned long)lb, s, i);
return(0);
}
if (!GC_debugging_started) {
@@ -1080,9 +1075,8 @@ GC_API void GC_CALL GC_debug_register_finalizer(void * obj,
return;
}
if ((ptr_t)obj - base != sizeof(oh)) {
- GC_err_printf(
- "GC_debug_register_finalizer called with non-base-pointer %p\n",
- obj);
+ GC_err_printf("GC_debug_register_finalizer called with"
+ " non-base-pointer %p\n", obj);
}
if (0 == fn) {
GC_register_finalizer(base, 0, 0, &my_old_fn, &my_old_cd);
@@ -1110,10 +1104,8 @@ GC_API void GC_CALL GC_debug_register_finalizer_no_order
return;
}
if ((ptr_t)obj - base != sizeof(oh)) {
- GC_err_printf(
- "GC_debug_register_finalizer_no_order called with "
- "non-base-pointer %p\n",
- obj);
+ GC_err_printf("GC_debug_register_finalizer_no_order called with"
+ " non-base-pointer %p\n", obj);
}
if (0 == fn) {
GC_register_finalizer_no_order(base, 0, 0, &my_old_fn, &my_old_cd);
@@ -1141,10 +1133,8 @@ GC_API void GC_CALL GC_debug_register_finalizer_unreachable
return;
}
if ((ptr_t)obj - base != sizeof(oh)) {
- GC_err_printf(
- "GC_debug_register_finalizer_unreachable called with "
- "non-base-pointer %p\n",
- obj);
+ GC_err_printf("GC_debug_register_finalizer_unreachable called with"
+ " non-base-pointer %p\n", obj);
}
if (0 == fn) {
GC_register_finalizer_unreachable(base, 0, 0, &my_old_fn, &my_old_cd);
@@ -1172,9 +1162,8 @@ GC_API void GC_CALL GC_debug_register_finalizer_ignore_self
return;
}
if ((ptr_t)obj - base != sizeof(oh)) {
- GC_err_printf(
- "GC_debug_register_finalizer_ignore_self called with "
- "non-base-pointer %p\n", obj);
+ GC_err_printf("GC_debug_register_finalizer_ignore_self called with"
+ " non-base-pointer %p\n", obj);
}
if (0 == fn) {
GC_register_finalizer_ignore_self(base, 0, 0, &my_old_fn, &my_old_cd);
diff --git a/gcj_mlc.c b/gcj_mlc.c
index ea5c8816..d2dcbb58 100644
--- a/gcj_mlc.c
+++ b/gcj_mlc.c
@@ -220,10 +220,8 @@ GC_API void * GC_CALL GC_debug_gcj_malloc(size_t lb,
if (result == 0) {
GC_oom_func oom_fn = GC_oom_fn;
UNLOCK();
- GC_err_printf("GC_debug_gcj_malloc(%lu, %p) returning NULL (",
- (unsigned long)lb, ptr_to_struct_containing_descr);
- GC_err_puts(s);
- GC_err_printf(":%d)\n", i);
+ GC_err_printf("GC_debug_gcj_malloc(%lu, %p) returning NULL (%s:%d)\n",
+ (unsigned long)lb, ptr_to_struct_containing_descr, s, i);
return((*oom_fn)(lb));
}
*((void **)((ptr_t)result + sizeof(oh))) = ptr_to_struct_containing_descr;
diff --git a/os_dep.c b/os_dep.c
index eb6b846c..69ee1116 100644
--- a/os_dep.c
+++ b/os_dep.c
@@ -1482,76 +1482,60 @@ void GC_register_data_segments(void)
myexefile = fopen(path, "rb");
if (myexefile == 0) {
if (GC_print_stats) {
- GC_err_puts("Couldn't open executable ");
- GC_err_puts(path);
- GC_err_puts("\n");
+ GC_err_printf("Could not open executable %s\n", path);
}
ABORT("Failed to open executable");
}
if (fread((char *)(&hdrdos), 1, sizeof(hdrdos), myexefile)
< sizeof(hdrdos)) {
if (GC_print_stats) {
- GC_err_puts("Couldn't read MSDOS header from ");
- GC_err_puts(path);
- GC_err_puts("\n");
+ GC_err_printf("Could not read MSDOS header from %s\n", path);
}
ABORT("Couldn't read MSDOS header");
}
if (E_MAGIC(hdrdos) != EMAGIC) {
if (GC_print_stats) {
- GC_err_puts("Executable has wrong DOS magic number: ");
- GC_err_puts(path);
- GC_err_puts("\n");
+ GC_err_printf("Executable has wrong DOS magic number: %s\n",
+ path);
}
ABORT("Bad DOS magic number");
}
if (fseek(myexefile, E_LFANEW(hdrdos), SEEK_SET) != 0) {
if (GC_print_stats) {
- GC_err_puts("Seek to new header failed in ");
- GC_err_puts(path);
- GC_err_puts("\n");
+ GC_err_printf("Seek to new header failed in %s\n", path);
}
ABORT("Bad DOS magic number");
}
if (fread((char *)(&hdr386), 1, sizeof(hdr386), myexefile)
< sizeof(hdr386)) {
if (GC_print_stats) {
- GC_err_puts("Couldn't read MSDOS header from ");
- GC_err_puts(path);
- GC_err_puts("\n");
+ GC_err_printf("Could not read MSDOS header from %s\n", path);
}
ABORT("Couldn't read OS/2 header");
}
if (E32_MAGIC1(hdr386) != E32MAGIC1 || E32_MAGIC2(hdr386) != E32MAGIC2) {
if (GC_print_stats) {
- GC_err_puts("Executable has wrong OS/2 magic number: ");
- GC_err_puts(path);
- GC_err_puts("\n");
+ GC_err_printf("Executable has wrong OS/2 magic number: %s\n",
+ path);
}
ABORT("Bad OS/2 magic number");
}
if (E32_BORDER(hdr386) != E32LEBO || E32_WORDER(hdr386) != E32LEWO) {
if (GC_print_stats) {
- GC_err_puts("Executable has wrong byte order: ");
- GC_err_puts(path);
- GC_err_puts("\n");
+ GC_err_printf("Executable has wrong byte order: %s\n", path);
}
ABORT("Bad byte order");
}
if (E32_CPU(hdr386) == E32CPU286) {
if (GC_print_stats) {
- GC_err_puts("GC can't handle 80286 executables: ");
- GC_err_puts(path);
- GC_err_puts("\n");
+ GC_err_printf("GC cannot handle 80286 executables: %s\n", path);
}
ABORT("Intel 80286 executables are unsupported");
}
if (fseek(myexefile, E_LFANEW(hdrdos) + E32_OBJTAB(hdr386),
SEEK_SET) != 0) {
if (GC_print_stats) {
- GC_err_puts("Seek to object table failed: ");
- GC_err_puts(path);
- GC_err_puts("\n");
+ GC_err_printf("Seek to object table failed: %s\n", path);
}
ABORT("Seek to object table failed");
}
@@ -1559,9 +1543,7 @@ void GC_register_data_segments(void)
int flags;
if (fread((char *)(&seg), 1, sizeof(seg), myexefile) < sizeof(seg)) {
if (GC_print_stats) {
- GC_err_puts("Couldn't read obj table entry from ");
- GC_err_puts(path);
- GC_err_puts("\n");
+ GC_err_printf("Could not read obj table entry from %s\n", path);
}
ABORT("Couldn't read obj table entry");
}