summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--allchblk.c5
-rw-r--r--alloc.c78
-rw-r--r--backgraph.c9
-rw-r--r--blacklst.c6
-rw-r--r--checksums.c16
-rw-r--r--darwin_stop_world.c3
-rw-r--r--dyn_load.c22
-rw-r--r--finalize.c12
-rw-r--r--gcj_mlc.c4
-rw-r--r--headers.c3
-rw-r--r--include/private/gc_priv.h4
-rw-r--r--mark.c50
-rw-r--r--obj_map.c8
-rw-r--r--os_dep.c137
-rw-r--r--pthread_stop_world.c15
-rw-r--r--pthread_support.c20
-rw-r--r--win32_threads.c16
17 files changed, 153 insertions, 255 deletions
diff --git a/allchblk.c b/allchblk.c
index b4879389..5ddafdb3 100644
--- a/allchblk.c
+++ b/allchblk.c
@@ -845,9 +845,8 @@ GC_INNER void GC_freehblk(struct hblk *hbp)
/* Check for duplicate deallocation in the easy case */
if (HBLK_IS_FREE(hhdr)) {
- if (GC_print_stats)
- GC_log_printf("Duplicate large block deallocation of %p\n",
- (void *)hbp);
+ GC_COND_LOG_PRINTF("Duplicate large block deallocation of %p\n",
+ (void *)hbp);
ABORT("Duplicate large block deallocation");
}
diff --git a/alloc.c b/alloc.c
index ef9d118f..c0440e11 100644
--- a/alloc.c
+++ b/alloc.c
@@ -181,11 +181,9 @@ GC_API GC_stop_func GC_CALL GC_get_stop_func(void)
GET_TIME(current_time);
time_diff = MS_TIME_DIFF(current_time,GC_start_time);
if (time_diff >= GC_time_limit) {
- if (GC_print_stats) {
- GC_log_printf(
+ GC_COND_LOG_PRINTF(
"Abandoning stopped marking after %lu msecs (attempt %d)\n",
time_diff, GC_n_attempts);
- }
return(1);
}
return(0);
@@ -368,11 +366,9 @@ STATIC void GC_maybe_gc(void)
GC_wait_for_reclaim();
# endif
if (GC_need_full_gc || n_partial_gcs >= GC_full_freq) {
- if (GC_print_stats) {
- GC_log_printf(
+ GC_COND_LOG_PRINTF(
"***>Full mark for collection %lu after %lu allocd bytes\n",
(unsigned long)GC_gc_no + 1, (unsigned long)GC_bytes_allocd);
- }
GC_promote_black_lists();
(void)GC_reclaim_all((GC_stop_func)0, TRUE);
GC_notify_full_gc();
@@ -421,10 +417,8 @@ GC_INNER GC_bool GC_try_to_collect_inner(GC_stop_func stop_func)
ASSERT_CANCEL_DISABLED();
if (GC_dont_gc || (*stop_func)()) return FALSE;
if (GC_incremental && GC_collection_in_progress()) {
- if (GC_print_stats) {
- GC_log_printf(
+ GC_COND_LOG_PRINTF(
"GC_try_to_collect_inner: finishing collection in progress\n");
- }
/* Just finish collection already in progress. */
while(GC_collection_in_progress()) {
if ((*stop_func)()) return(FALSE);
@@ -613,12 +607,10 @@ STATIC GC_bool GC_stopped_mark(GC_stop_func stop_func)
# ifdef THREAD_LOCAL_ALLOC
GC_world_stopped = TRUE;
# endif
- if (GC_print_stats) {
/* Output blank line for convenience here */
- GC_log_printf(
+ GC_COND_LOG_PRINTF(
"\n--> Marking for collection %lu after %lu allocated bytes\n",
(unsigned long)GC_gc_no + 1, (unsigned long) GC_bytes_allocd);
- }
# ifdef MAKE_BACK_GRAPH
if (GC_print_back_height) {
GC_build_back_graph();
@@ -633,10 +625,8 @@ STATIC GC_bool GC_stopped_mark(GC_stop_func stop_func)
GC_initiate_gc();
for (i = 0;;i++) {
if ((*stop_func)()) {
- if (GC_print_stats) {
- GC_log_printf("Abandoned stopped marking after %u iterations\n",
- i);
- }
+ GC_COND_LOG_PRINTF("Abandoned stopped marking after"
+ " %u iterations\n", i);
GC_deficit = i; /* Give the mutator a chance. */
# ifdef THREAD_LOCAL_ALLOC
GC_world_stopped = FALSE;
@@ -648,13 +638,11 @@ STATIC GC_bool GC_stopped_mark(GC_stop_func stop_func)
}
GC_gc_no++;
- if (GC_print_stats) {
- GC_log_printf("GC %lu reclaimed %ld bytes --> heapsize: %lu"
- " bytes" IF_USE_MUNMAP(" (%lu unmapped)") "\n",
- (unsigned long)GC_gc_no, (long)GC_bytes_found,
- (unsigned long)GC_heapsize /*, */
- COMMA_IF_USE_MUNMAP((unsigned long)GC_unmapped_bytes));
- }
+ GC_COND_LOG_PRINTF("GC %lu reclaimed %ld bytes --> heapsize: %lu"
+ " bytes" IF_USE_MUNMAP(" (%lu unmapped)") "\n",
+ (unsigned long)GC_gc_no, (long)GC_bytes_found,
+ (unsigned long)GC_heapsize /*, */
+ COMMA_IF_USE_MUNMAP((unsigned long)GC_unmapped_bytes));
/* Check all debugged objects for consistency */
if (GC_debugging_started) {
@@ -914,18 +902,15 @@ STATIC void GC_finish_collection(void)
}
}
- if (GC_print_stats == VERBOSE)
- GC_log_printf("Bytes recovered before sweep - f.l. count = %ld\n",
- (long)GC_bytes_found);
+ GC_VERBOSE_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);
- }
+ GC_COND_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;
@@ -934,12 +919,12 @@ STATIC void GC_finish_collection(void)
> min_bytes_allocd();
}
- if (GC_print_stats == VERBOSE) {
- GC_log_printf("Immediately reclaimed %ld bytes, heapsize:"
- " %lu bytes" IF_USE_MUNMAP(" (%lu unmapped)") "\n",
- (long)GC_bytes_found, (unsigned long)GC_heapsize /*, */
- COMMA_IF_USE_MUNMAP((unsigned long)GC_unmapped_bytes));
- }
+ GC_VERBOSE_LOG_PRINTF("Immediately reclaimed %ld bytes, heapsize:"
+ " %lu bytes" IF_USE_MUNMAP(" (%lu unmapped)") "\n",
+ (long)GC_bytes_found,
+ (unsigned long)GC_heapsize /*, */
+ COMMA_IF_USE_MUNMAP((unsigned long)
+ GC_unmapped_bytes));
/* Reset or increment counters for next cycle */
GC_n_attempts = 0;
@@ -1177,16 +1162,13 @@ GC_INNER GC_bool GC_expand_hp_inner(word n)
space = GET_MEM(bytes);
GC_add_to_our_memory((ptr_t)space, bytes);
if (space == 0) {
- if (GC_print_stats) {
- GC_log_printf("Failed to expand heap by %lu bytes\n",
- (unsigned long)bytes);
- }
+ GC_COND_LOG_PRINTF("Failed to expand heap by %lu bytes\n",
+ (unsigned long)bytes);
return(FALSE);
}
- if (GC_print_stats) {
- GC_log_printf("Increasing heap size by %lu after %lu allocated bytes\n",
- (unsigned long)bytes, (unsigned long)GC_bytes_allocd);
- }
+ GC_COND_LOG_PRINTF(
+ "Increasing heap size by %lu after %lu allocated bytes\n",
+ (unsigned long)bytes, (unsigned long)GC_bytes_allocd);
/* Adjust heap limits generously for blacklisting to work better. */
/* GC_add_to_heap performs minimal adjustment needed for */
/* correctness. */
@@ -1320,8 +1302,8 @@ GC_INNER GC_bool GC_collect_or_expand(word needed_blocks,
RESTORE_CANCEL(cancel_state);
return(FALSE);
}
- } else if (GC_fail_count && GC_print_stats) {
- GC_log_printf("Memory available again...\n");
+ } else if (GC_fail_count) {
+ GC_COND_LOG_PRINTF("Memory available again...\n");
}
RESTORE_CANCEL(cancel_state);
return(TRUE);
diff --git a/backgraph.c b/backgraph.c
index 74437ba2..3659f878 100644
--- a/backgraph.c
+++ b/backgraph.c
@@ -376,8 +376,7 @@ static word backwards_height(ptr_t p)
FOR_EACH_PRED(q, p, {
word this_height;
if (GC_is_marked(q) && !(FLAG_MANY & (word)GET_OH_BG_PTR(p))) {
- if (GC_print_stats)
- GC_log_printf("Found bogus pointer from %p to %p\n", q, p);
+ GC_COND_LOG_PRINTF("Found bogus pointer from %p to %p\n", q, p);
/* Reachable object "points to" unreachable one. */
/* Could be caused by our lax treatment of GC descriptors. */
this_height = 1;
@@ -467,10 +466,8 @@ void GC_print_back_graph_stats(void)
"of unreachable objects:\n");
GC_print_heap_obj(GC_deepest_obj);
}
- if (GC_print_stats) {
- GC_log_printf("Needed max total of %d back-edge structs\n",
- GC_n_back_edge_structs);
- }
+ GC_COND_LOG_PRINTF("Needed max total of %d back-edge structs\n",
+ GC_n_back_edge_structs);
GC_apply_to_each_object(reset_back_edge);
GC_deepest_obj = 0;
}
diff --git a/blacklst.c b/blacklst.c
index 11556a4a..77ad6758 100644
--- a/blacklst.c
+++ b/blacklst.c
@@ -147,9 +147,9 @@ GC_INNER void GC_promote_black_lists(void)
GC_incomplete_normal_bl = very_old_normal_bl;
GC_incomplete_stack_bl = very_old_stack_bl;
GC_total_stack_black_listed = total_stack_black_listed();
- if (GC_print_stats == VERBOSE)
- GC_log_printf("%lu bytes in heap blacklisted for interior pointers\n",
- (unsigned long)GC_total_stack_black_listed);
+ GC_VERBOSE_LOG_PRINTF(
+ "%lu bytes in heap blacklisted for interior pointers\n",
+ (unsigned long)GC_total_stack_black_listed);
if (GC_total_stack_black_listed != 0) {
GC_black_list_spacing =
HBLKSIZE*(GC_heapsize/GC_total_stack_black_listed);
diff --git a/checksums.c b/checksums.c
index 8ca587df..f5ad843a 100644
--- a/checksums.c
+++ b/checksums.c
@@ -162,12 +162,11 @@ STATIC void GC_check_blocks(void)
GC_bytes_in_used_blocks = 0;
GC_apply_to_all_blocks(GC_add_block, (word)0);
- if (GC_print_stats)
- GC_log_printf("GC_bytes_in_used_blocks = %lu,"
- " bytes_in_free_blocks = %lu, heapsize = %lu\n",
- (unsigned long)GC_bytes_in_used_blocks,
- (unsigned long)bytes_in_free_blocks,
- (unsigned long)GC_heapsize);
+ GC_COND_LOG_PRINTF("GC_bytes_in_used_blocks = %lu,"
+ " bytes_in_free_blocks = %lu, heapsize = %lu\n",
+ (unsigned long)GC_bytes_in_used_blocks,
+ (unsigned long)bytes_in_free_blocks,
+ (unsigned long)GC_heapsize);
if (GC_bytes_in_used_blocks + bytes_in_free_blocks != GC_heapsize) {
GC_err_printf("LOST SOME BLOCKS!!\n");
}
@@ -200,9 +199,8 @@ void GC_check_dirty(void)
}
}
out:
- if (GC_print_stats)
- GC_log_printf("Checked %lu clean and %lu dirty pages\n",
- (unsigned long)GC_n_clean, (unsigned long)GC_n_dirty);
+ GC_COND_LOG_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_err_printf("Found %d dirty bit errors (%d were faulted)\n",
GC_n_dirty_errors, GC_n_faulted_dirty_errors);
diff --git a/darwin_stop_world.c b/darwin_stop_world.c
index 8fb1d331..a63d64e5 100644
--- a/darwin_stop_world.c
+++ b/darwin_stop_world.c
@@ -322,8 +322,7 @@ GC_INNER void GC_push_all_stacks(void)
}
mach_port_deallocate(my_task, my_thread);
- if (GC_print_stats == VERBOSE)
- GC_log_printf("Pushed %d thread stacks\n", nthreads);
+ GC_VERBOSE_LOG_PRINTF("Pushed %d thread stacks\n", nthreads);
if (!found_me && !GC_in_thread_creation)
ABORT("Collecting from unknown thread");
GC_total_stacksize = total_size;
diff --git a/dyn_load.c b/dyn_load.c
index 708667f8..8e07de32 100644
--- a/dyn_load.c
+++ b/dyn_load.c
@@ -1018,13 +1018,11 @@ GC_INNER void GC_register_dynamic_libraries(void)
/* Check status AFTER checking moduleid because */
/* of a bug in the non-shared ldr_next_module stub */
if (status != 0) {
- if (GC_print_stats) {
- GC_log_printf("dynamic_load: status = %d\n", status);
- if (errno < sys_nerr) {
- GC_log_printf("dynamic_load: %s\n", sys_errlist[errno]);
- } else {
- GC_log_printf("dynamic_load: err_code = %d\n", errno);
- }
+ GC_COND_LOG_PRINTF("dynamic_load: status = %d\n", status);
+ if (errno < sys_nerr) {
+ GC_COND_LOG_PRINTF("dynamic_load: %s\n", sys_errlist[errno]);
+ } else {
+ GC_COND_LOG_PRINTF("dynamic_load: err_code = %d\n", errno);
}
ABORT("ldr_next_module failed");
}
@@ -1111,12 +1109,10 @@ GC_INNER void GC_register_dynamic_libraries(void)
if (errno == EINVAL) {
break; /* Moved past end of shared library list --> finished */
} else {
- if (GC_print_stats) {
- if (errno < sys_nerr) {
- GC_log_printf("dynamic_load: %s\n", sys_errlist[errno]);
- } else {
- GC_log_printf("dynamic_load: err_code = %d\n", errno);
- }
+ if (errno < sys_nerr) {
+ GC_COND_LOG_PRINTF("dynamic_load: %s\n", sys_errlist[errno]);
+ } else {
+ GC_COND_LOG_PRINTF("dynamic_load: err_code = %d\n", errno);
}
ABORT("shl_get failed");
}
diff --git a/finalize.c b/finalize.c
index 0e20f551..1c5ebafb 100644
--- a/finalize.c
+++ b/finalize.c
@@ -150,10 +150,8 @@ GC_API int GC_CALL GC_general_register_disappearing_link(void * * link,
|| GC_dl_entries > ((word)1 << log_dl_table_size)) {
GC_grow_table((struct hash_chain_entry ***)&GC_dl_head,
&log_dl_table_size);
- if (GC_print_stats) {
- GC_log_printf("Grew dl table to %u entries\n",
- (1 << (unsigned)log_dl_table_size));
- }
+ GC_COND_LOG_PRINTF("Grew dl table to %u entries\n",
+ 1 << (unsigned)log_dl_table_size);
}
index = HASH2(link, log_dl_table_size);
for (curr_dl = GC_dl_head[index]; curr_dl != 0;
@@ -370,10 +368,8 @@ STATIC void GC_register_finalizer_inner(void * obj,
|| GC_fo_entries > ((word)1 << log_fo_table_size)) {
GC_grow_table((struct hash_chain_entry ***)&GC_fo_head,
&log_fo_table_size);
- if (GC_print_stats) {
- GC_log_printf("Grew fo table to %u entries\n",
- (1 << (unsigned)log_fo_table_size));
- }
+ GC_COND_LOG_PRINTF("Grew fo table to %u entries\n",
+ 1 << (unsigned)log_fo_table_size);
}
/* in the THREADS case we hold allocation lock. */
base = (ptr_t)obj;
diff --git a/gcj_mlc.c b/gcj_mlc.c
index d2dcbb58..78950e25 100644
--- a/gcj_mlc.c
+++ b/gcj_mlc.c
@@ -88,8 +88,8 @@ GC_API void GC_CALL GC_init_gcj_malloc(int mp_index,
# else
ignore_gcj_info = (0 != GETENV("GC_IGNORE_GCJ_INFO"));
# endif
- if (GC_print_stats && ignore_gcj_info) {
- GC_log_printf("Gcj-style type information is disabled!\n");
+ if (ignore_gcj_info) {
+ GC_COND_LOG_PRINTF("Gcj-style type information is disabled!\n");
}
GC_ASSERT(GC_mark_procs[mp_index] == (GC_mark_proc)0); /* unused */
GC_mark_procs[mp_index] = (GC_mark_proc)(word)mp;
diff --git a/headers.c b/headers.c
index 47cc526e..d650fe78 100644
--- a/headers.c
+++ b/headers.c
@@ -144,8 +144,7 @@ GC_INNER ptr_t GC_scratch_alloc(size_t bytes)
result = (ptr_t)GET_MEM(bytes_to_get);
GC_add_to_our_memory(result, bytes_to_get);
if (result == 0) {
- if (GC_print_stats)
- GC_log_printf("Out of memory - trying to allocate less\n");
+ GC_COND_LOG_PRINTF("Out of memory - trying to allocate less\n");
scratch_free_ptr -= bytes;
bytes_to_get = bytes;
# ifdef USE_MMAP
diff --git a/include/private/gc_priv.h b/include/private/gc_priv.h
index c33e0188..6352267d 100644
--- a/include/private/gc_priv.h
+++ b/include/private/gc_priv.h
@@ -2039,6 +2039,10 @@ GC_API_PRIV void GC_log_printf(const char * format, ...)
}
#endif
+#define GC_COND_LOG_PRINTF if (!GC_print_stats) {} else GC_log_printf
+#define GC_VERBOSE_LOG_PRINTF \
+ if (GC_print_stats != VERBOSE) {} else GC_log_printf
+
void GC_err_puts(const char *s);
/* Write s to stderr, don't buffer, don't add */
/* newlines, don't ... */
diff --git a/mark.c b/mark.c
index 433086f4..e941abf8 100644
--- a/mark.c
+++ b/mark.c
@@ -336,10 +336,8 @@ static void alloc_mark_stack(size_t);
} else {
scan_ptr = GC_push_next_marked_dirty(scan_ptr);
if (scan_ptr == 0) {
- if (GC_print_stats) {
- GC_log_printf("Marked from %lu dirty pages\n",
- (unsigned long)GC_n_rescuing_pages);
- }
+ GC_COND_LOG_PRINTF("Marked from %lu dirty pages\n",
+ (unsigned long)GC_n_rescuing_pages);
GC_push_roots(FALSE, cold_gc_frame);
GC_objects_are_marked = TRUE;
if (GC_mark_state != MS_INVALID) {
@@ -567,10 +565,8 @@ static void alloc_mark_stack(size_t);
handle_ex:
/* Exception handler starts here for all cases. */
- if (GC_print_stats) {
- GC_log_printf(
+ GC_COND_LOG_PRINTF(
"Caught ACCESS_VIOLATION in marker; memory mapping disappeared\n");
- }
/* We have bad roots on the stack. Discard mark stack. */
/* Rescan from marked objects. Redetermine roots. */
@@ -592,10 +588,8 @@ GC_INNER mse * GC_signal_mark_stack_overflow(mse *msp)
{
GC_mark_state = MS_INVALID;
GC_mark_stack_too_small = TRUE;
- if (GC_print_stats) {
- GC_log_printf("Mark stack overflow; current size = %lu entries\n",
- (unsigned long)GC_mark_stack_size);
- }
+ GC_COND_LOG_PRINTF("Mark stack overflow; current size = %lu entries\n",
+ (unsigned long)GC_mark_stack_size);
return(msp - GC_MARK_STACK_DISCARDS);
}
@@ -946,9 +940,7 @@ STATIC void GC_return_mark_stack(mse * low, mse * high)
my_start = my_top + 1;
if ((word)(my_start - GC_mark_stack + stack_size)
> (word)GC_mark_stack_size) {
- if (GC_print_stats) {
- GC_log_printf("No room to copy back mark stack\n");
- }
+ GC_COND_LOG_PRINTF("No room to copy back mark stack\n");
GC_mark_state = MS_INVALID;
GC_mark_stack_too_small = TRUE;
/* We drop the local mark stack. We'll fix things later. */
@@ -1028,8 +1020,7 @@ STATIC void GC_mark_local(mse *local_mark_stack, int id)
GC_ASSERT((word)AO_load(&GC_first_nonempty) >= (word)GC_mark_stack &&
(word)AO_load(&GC_first_nonempty) <=
(word)AO_load((volatile AO_t *)&GC_mark_stack_top) + sizeof(mse));
- if (GC_print_stats == VERBOSE)
- GC_log_printf("Starting mark helper %lu\n", (unsigned long)id);
+ GC_VERBOSE_LOG_PRINTF("Starting mark helper %lu\n", (unsigned long)id);
GC_release_mark_lock();
for (;;) {
size_t n_on_stack;
@@ -1091,9 +1082,8 @@ STATIC void GC_mark_local(mse *local_mark_stack, int id)
/* both conditions actually held simultaneously. */
GC_helper_count--;
if (0 == GC_helper_count) need_to_notify = TRUE;
- if (GC_print_stats == VERBOSE)
- GC_log_printf("Finished mark helper %lu\n",
- (unsigned long)id);
+ GC_VERBOSE_LOG_PRINTF("Finished mark helper %lu\n",
+ (unsigned long)id);
GC_release_mark_lock();
if (need_to_notify) GC_notify_all_marker();
return;
@@ -1136,9 +1126,8 @@ STATIC void GC_do_parallel_mark(void)
/* all the time, especially since it's cheap. */
if (GC_help_wanted || GC_active_count != 0 || GC_helper_count != 0)
ABORT("Tried to start parallel mark in bad state");
- if (GC_print_stats == VERBOSE)
- GC_log_printf("Starting marking for mark phase number %lu\n",
- (unsigned long)GC_mark_no);
+ GC_VERBOSE_LOG_PRINTF("Starting marking for mark phase number %lu\n",
+ (unsigned long)GC_mark_no);
GC_first_nonempty = (AO_t)GC_mark_stack;
GC_active_count = 0;
GC_helper_count = 1;
@@ -1152,9 +1141,8 @@ STATIC void GC_do_parallel_mark(void)
/* Done; clean up. */
while (GC_helper_count > 0) GC_wait_marker();
/* GC_helper_count cannot be incremented while GC_help_wanted == FALSE */
- if (GC_print_stats == VERBOSE)
- GC_log_printf("Finished marking for mark phase number %lu\n",
- (unsigned long)GC_mark_no);
+ GC_VERBOSE_LOG_PRINTF("Finished marking for mark phase number %lu\n",
+ (unsigned long)GC_mark_no);
GC_mark_no++;
GC_release_mark_lock();
GC_notify_all_marker();
@@ -1227,15 +1215,11 @@ static void alloc_mark_stack(size_t n)
GC_mark_stack_size = n;
/* FIXME: Do we need some way to reset GC_mark_stack_size? */
GC_mark_stack_limit = new_stack + n;
- if (GC_print_stats) {
- GC_log_printf("Grew mark stack to %lu frames\n",
- (unsigned long) GC_mark_stack_size);
- }
+ GC_COND_LOG_PRINTF("Grew mark stack to %lu frames\n",
+ (unsigned long)GC_mark_stack_size);
} else {
- if (GC_print_stats) {
- GC_log_printf("Failed to grow mark stack to %lu frames\n",
- (unsigned long) n);
- }
+ GC_COND_LOG_PRINTF("Failed to grow mark stack to %lu frames\n",
+ (unsigned long)n);
}
} else {
if (new_stack == 0) {
diff --git a/obj_map.c b/obj_map.c
index ed75ef12..c935bf3f 100644
--- a/obj_map.c
+++ b/obj_map.c
@@ -59,9 +59,9 @@ GC_INNER void GC_register_displacement_inner(size_t offset)
}
new_map = (short *)GC_scratch_alloc(MAP_LEN * sizeof(short));
if (new_map == 0) return(FALSE);
- if (GC_print_stats)
- GC_log_printf("Adding block map for size of %u granules (%u bytes)\n",
- (unsigned)granules, (unsigned)(GRANULES_TO_BYTES(granules)));
+ GC_COND_LOG_PRINTF(
+ "Adding block map for size of %u granules (%u bytes)\n",
+ (unsigned)granules, (unsigned)GRANULES_TO_BYTES(granules));
if (granules == 0) {
for (displ = 0; displ < BYTES_TO_GRANULES(HBLKSIZE); displ++) {
new_map[displ] = 1; /* Nonzero to get us out of marker fast path. */
@@ -74,7 +74,7 @@ GC_INNER void GC_register_displacement_inner(size_t offset)
GC_obj_map[granules] = new_map;
return(TRUE);
}
-#endif
+#endif /* MARK_BIT_PER_GRANULE */
GC_INNER void GC_initialize_offsets(void)
{
diff --git a/os_dep.c b/os_dep.c
index 69ee1116..45d4a310 100644
--- a/os_dep.c
+++ b/os_dep.c
@@ -265,8 +265,7 @@ GC_INNER char * GC_get_maps(void)
return 0;
# ifdef THREADS
if (maps_size > old_maps_size) {
- if (GC_print_stats)
- GC_log_printf(
+ GC_COND_LOG_PRINTF(
"Unexpected maps size growth from %lu to %lu\n",
(unsigned long)old_maps_size,
(unsigned long)maps_size);
@@ -424,9 +423,7 @@ GC_INNER char * GC_get_maps(void)
{
ptr_t my_start, my_end;
if (!GC_enclosing_mapping(GC_save_regs_in_stack(), &my_start, &my_end)) {
- if (GC_print_stats) {
- GC_log_printf("Failed to find backing store base from /proc\n");
- }
+ GC_COND_LOG_PRINTF("Failed to find backing store base from /proc\n");
return 0;
}
return my_start;
@@ -1481,70 +1478,50 @@ void GC_register_data_segments(void)
}
myexefile = fopen(path, "rb");
if (myexefile == 0) {
- if (GC_print_stats) {
- GC_err_printf("Could not open executable %s\n", path);
- }
+ GC_COND_LOG_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_printf("Could not read MSDOS header from %s\n", path);
- }
+ GC_COND_LOG_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_printf("Executable has wrong DOS magic number: %s\n",
- path);
- }
+ GC_COND_LOG_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_printf("Seek to new header failed in %s\n", path);
- }
+ GC_COND_LOG_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_printf("Could not read MSDOS header from %s\n", path);
- }
+ GC_COND_LOG_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_printf("Executable has wrong OS/2 magic number: %s\n",
- path);
- }
+ GC_COND_LOG_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_printf("Executable has wrong byte order: %s\n", path);
- }
+ GC_COND_LOG_PRINTF("Executable has wrong byte order: %s\n", path);
ABORT("Bad byte order");
}
if (E32_CPU(hdr386) == E32CPU286) {
- if (GC_print_stats) {
- GC_err_printf("GC cannot handle 80286 executables: %s\n", path);
- }
+ GC_COND_LOG_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_printf("Seek to object table failed: %s\n", path);
- }
+ GC_COND_LOG_PRINTF("Seek to object table failed: %s\n", path);
ABORT("Seek to object table failed");
}
for (nsegs = E32_OBJCNT(hdr386); nsegs > 0; nsegs--) {
int flags;
if (fread((char *)(&seg), 1, sizeof(seg), myexefile) < sizeof(seg)) {
- if (GC_print_stats) {
- GC_err_printf("Could not read obj table entry from %s\n", path);
- }
+ GC_COND_LOG_PRINTF("Could not read obj table entry from %s\n", path);
ABORT("Couldn't read obj table entry");
}
flags = O32_FLAGS(seg);
@@ -1641,13 +1618,13 @@ void GC_register_data_segments(void)
GetWriteWatch_func = NULL;
}
}
- if (GC_print_stats) {
+# ifndef SMALL_CONFIG
if (GetWriteWatch_func == NULL) {
- GC_log_printf("Did not find a usable GetWriteWatch()\n");
+ GC_COND_LOG_PRINTF("Did not find a usable GetWriteWatch()\n");
} else {
- GC_log_printf("Using GetWriteWatch()\n");
+ GC_COND_LOG_PRINTF("Using GetWriteWatch()\n");
}
- }
+# endif
done = TRUE;
}
@@ -1781,9 +1758,8 @@ void GC_register_data_segments(void)
return;
}
}
- if (GC_print_stats)
- GC_log_printf("Found new system malloc AllocationBase at %p\n",
- candidate);
+ GC_COND_LOG_PRINTF("Found new system malloc AllocationBase at %p\n",
+ candidate);
new_l -> allocation_base = candidate;
new_l -> next = GC_malloc_heap_l;
GC_malloc_heap_l = new_l;
@@ -2486,10 +2462,9 @@ GC_INNER void GC_remap(ptr_t start, size_t bytes)
# else
if (mprotect(start_addr, len, (PROT_READ | PROT_WRITE)
| (GC_pages_executable ? PROT_EXEC : 0)) != 0) {
- if (GC_print_stats)
- GC_log_printf(
- "mprotect failed at %p (length %lu) with errno %d\n",
- start_addr, (unsigned long)len, errno);
+ GC_COND_LOG_PRINTF("mprotect failed at %p (length %lu)"
+ " with errno %d\n",
+ start_addr, (unsigned long)len, errno);
ABORT("mprotect remapping failed");
}
# endif /* !NACL */
@@ -2825,8 +2800,7 @@ GC_API GC_push_other_roots_proc GC_CALL GC_get_push_other_roots(void)
/* Initialize virtual dirty bit implementation. */
GC_INNER void GC_dirty_init(void)
{
- if (GC_print_stats == VERBOSE)
- GC_log_printf("Initializing DEFAULT_VDB...\n");
+ GC_VERBOSE_LOG_PRINTF("Initializing DEFAULT_VDB...\n");
GC_dirty_maintained = TRUE;
}
@@ -2871,8 +2845,7 @@ GC_API GC_push_other_roots_proc GC_CALL GC_get_push_other_roots(void)
/* Initialize virtual dirty bit implementation. */
GC_INNER void GC_dirty_init(void)
{
- if (GC_print_stats == VERBOSE)
- GC_log_printf("Initializing MANUAL_VDB...\n");
+ GC_VERBOSE_LOG_PRINTF("Initializing MANUAL_VDB...\n");
/* GC_dirty_pages and GC_grungy_pages are already cleared. */
GC_dirty_maintained = TRUE;
}
@@ -2992,8 +2965,8 @@ GC_API GC_push_other_roots_proc GC_CALL GC_get_push_other_roots(void)
GC_pages_executable ? PAGE_EXECUTE_READ : \
PAGE_READONLY, \
&protect_junk)) { \
- if (GC_print_stats) \
- GC_log_printf("Last error code: 0x%lx\n", (long)GetLastError()); \
+ GC_COND_LOG_PRINTF("Last error code: 0x%lx\n", \
+ (long)GetLastError()); \
ABORT("VirtualProtect failed"); \
}
# define UNPROTECT(addr, len) \
@@ -3202,8 +3175,7 @@ GC_API GC_push_other_roots_proc GC_CALL GC_get_push_other_roots(void)
if (old_handler == (SIG_HNDLR_PTR)SIG_DFL) {
# if !defined(MSWIN32) && !defined(MSWINCE)
- if (GC_print_stats)
- GC_log_printf("Unexpected segfault at %p\n", addr);
+ GC_COND_LOG_PRINTF("Unexpected segfault at %p\n", addr);
ABORT("Unexpected bus error or segmentation fault");
# else
return(EXCEPTION_CONTINUE_SEARCH);
@@ -3254,8 +3226,7 @@ GC_API GC_push_other_roots_proc GC_CALL GC_get_push_other_roots(void)
# if defined(MSWIN32) || defined(MSWINCE)
return EXCEPTION_CONTINUE_SEARCH;
# else
- if (GC_print_stats)
- GC_log_printf("Unexpected segfault at %p\n", addr);
+ GC_COND_LOG_PRINTF("Unexpected segfault at %p\n", addr);
ABORT("Unexpected bus error or segmentation fault");
# endif
}
@@ -3319,8 +3290,7 @@ GC_INNER void GC_remove_protection(struct hblk *h, word nblocks,
(void)sigaddset(&act.sa_mask, GC_get_suspend_signal());
# endif
# endif /* !MSWIN32 */
- if (GC_print_stats == VERBOSE)
- GC_log_printf(
+ GC_VERBOSE_LOG_PRINTF(
"Initializing mprotect virtual dirty bit implementation\n");
GC_dirty_maintained = TRUE;
if (GC_page_size % HBLKSIZE != 0) {
@@ -3345,13 +3315,11 @@ GC_INNER void GC_remove_protection(struct hblk *h, word nblocks,
GC_old_segv_handler_used_si = FALSE;
}
if (GC_old_segv_handler == (SIG_HNDLR_PTR)SIG_IGN) {
- if (GC_print_stats)
- GC_err_printf("Previously ignored segmentation violation!?\n");
+ WARN("Previously ignored segmentation violation!?\n", 0);
GC_old_segv_handler = (SIG_HNDLR_PTR)SIG_DFL;
}
if (GC_old_segv_handler != (SIG_HNDLR_PTR)SIG_DFL) {
- if (GC_print_stats == VERBOSE)
- GC_log_printf("Replaced other SIGSEGV handler\n");
+ GC_VERBOSE_LOG_PRINTF("Replaced other SIGSEGV handler\n");
}
# if defined(HPUX) || defined(LINUX) || defined(HURD) \
|| (defined(FREEBSD) && defined(SUNOS5SIGS))
@@ -3368,16 +3336,14 @@ GC_INNER void GC_remove_protection(struct hblk *h, word nblocks,
# endif
}
if (GC_old_bus_handler == (SIG_HNDLR_PTR)SIG_IGN) {
- if (GC_print_stats)
- GC_err_printf("Previously ignored bus error!?\n");
+ WARN("Previously ignored bus error!?\n", 0);
# if !defined(LINUX)
GC_old_bus_handler = (SIG_HNDLR_PTR)SIG_DFL;
# else
/* GC_old_bus_handler is not used by GC_write_fault_handler. */
# endif
- } else if (GC_old_bus_handler != (SIG_HNDLR_PTR)SIG_DFL
- && GC_print_stats == VERBOSE) {
- GC_log_printf("Replaced other SIGBUS handler\n");
+ } else if (GC_old_bus_handler != (SIG_HNDLR_PTR)SIG_DFL) {
+ GC_VERBOSE_LOG_PRINTF("Replaced other SIGBUS handler\n");
}
# endif /* HPUX || LINUX || HURD || (FREEBSD && SUNOS5SIGS) */
# endif /* ! MS windows */
@@ -3388,8 +3354,7 @@ GC_INNER void GC_remove_protection(struct hblk *h, word nblocks,
# if defined(MSWIN32)
GC_old_segv_handler = SetUnhandledExceptionFilter(GC_write_fault_handler);
if (GC_old_segv_handler != NULL) {
- if (GC_print_stats)
- GC_log_printf("Replaced other UnhandledExceptionFilter\n");
+ GC_COND_LOG_PRINTF("Replaced other UnhandledExceptionFilter\n");
} else {
GC_old_segv_handler = SIG_DFL;
}
@@ -3673,10 +3638,9 @@ GC_INNER void GC_dirty_init(void)
if (GC_bytes_allocd != 0 || GC_bytes_allocd_before_gc != 0) {
memset(GC_written_pages, 0xff, sizeof(page_hash_table));
- if (GC_print_stats == VERBOSE)
- GC_log_printf("Allocated %lu bytes: all pages may have been written\n",
- (unsigned long)(GC_bytes_allocd
- + GC_bytes_allocd_before_gc));
+ GC_VERBOSE_LOG_PRINTF(
+ "Allocated %lu bytes: all pages may have been written\n",
+ (unsigned long)(GC_bytes_allocd + GC_bytes_allocd_before_gc));
}
(void)snprintf(buf, sizeof(buf), "/proc/%ld", (long)getpid());
@@ -3717,10 +3681,9 @@ GC_INNER void GC_read_dirty(void)
/* Retry with larger buffer. */
word new_size = 2 * GC_proc_buf_size;
char *new_buf;
- if (GC_print_stats)
- GC_err_printf("/proc read failed: GC_proc_buf_size = %lu\n",
- (unsigned long)GC_proc_buf_size);
+ WARN("/proc read failed: GC_proc_buf_size = %" WARN_PRIdPTR "\n",
+ (signed_word)GC_proc_buf_size);
new_buf = GC_scratch_alloc(new_size);
if (new_buf != 0) {
GC_proc_buf = bufp = new_buf;
@@ -4077,9 +4040,8 @@ STATIC void *GC_mprotect_thread(void *arg)
# endif /* THREADS */
if (r != MACH_MSG_SUCCESS) {
- if (GC_print_stats)
- GC_log_printf("mach_msg failed with code %d: %s\n", (int)r,
- mach_error_string(r));
+ GC_COND_LOG_PRINTF("mach_msg failed with code %d: %s\n", (int)r,
+ mach_error_string(r));
ABORT("mach_msg failed");
}
@@ -4162,16 +4124,14 @@ GC_INNER void GC_dirty_init(void)
/* gracefully (unprotecting all pages and clearing */
/* GC_mach_handler_thread). For now, we just disable incremental */
/* mode if fork() handling is requested by the client. */
- if (GC_print_stats)
- GC_log_printf(
- "GC incremental mode disabled since fork() handling requested\n");
+ GC_COND_LOG_PRINTF("GC incremental mode disabled since fork()"
+ " handling requested\n");
return;
}
# endif
- if (GC_print_stats == VERBOSE)
- GC_log_printf(
- "Initializing mach/darwin mprotect virtual dirty bit implementation\n");
+ GC_VERBOSE_LOG_PRINTF("Initializing mach/darwin mprotect"
+ " virtual dirty bit implementation\n");
# ifdef BROKEN_EXCEPTION_HANDLING
WARN("Enabling workarounds for various darwin "
"exception handling bugs.\n", 0);
@@ -4234,8 +4194,7 @@ GC_INNER void GC_dirty_init(void)
if (sigaction(SIGBUS, &sa, &oldsa) < 0)
ABORT("sigaction failed");
if ((SIG_HNDLR_PTR)oldsa.sa_handler != SIG_DFL) {
- if (GC_print_stats == VERBOSE)
- GC_err_printf("Replaced other SIGBUS handler\n");
+ GC_VERBOSE_LOG_PRINTF("Replaced other SIGBUS handler\n");
}
}
# endif /* BROKEN_EXCEPTION_HANDLING */
diff --git a/pthread_stop_world.c b/pthread_stop_world.c
index 3f288b7c..cbae189c 100644
--- a/pthread_stop_world.c
+++ b/pthread_stop_world.c
@@ -407,9 +407,7 @@ GC_INNER void GC_push_all_stacks(void)
# endif
}
}
- if (GC_print_stats == VERBOSE) {
- GC_log_printf("Pushed %d thread stacks\n", (int)nthreads);
- }
+ GC_VERBOSE_LOG_PRINTF("Pushed %d thread stacks\n", (int)nthreads);
if (!found_me && !GC_in_thread_creation)
ABORT("Collecting from unknown thread");
GC_total_stacksize = total_size;
@@ -601,9 +599,7 @@ GC_INNER void GC_stop_world(void)
if (wait_usecs > RETRY_INTERVAL) {
int newly_sent = GC_suspend_all();
- if (GC_print_stats) {
- GC_log_printf("Resent %d signals after timeout\n", newly_sent);
- }
+ GC_COND_LOG_PRINTF("Resent %d signals after timeout\n", newly_sent);
sem_getvalue(&GC_suspend_ack_sem, &ack_count);
if (newly_sent < n_live_threads - ack_count) {
WARN("Lost some threads during GC_stop_world?!\n",0);
@@ -830,8 +826,7 @@ GC_INNER void GC_start_world(void)
for (i = 0; i < n_live_threads; i++) {
while (0 != (code = sem_wait(&GC_restart_ack_sem))) {
if (errno != EINTR) {
- if (GC_print_stats)
- GC_log_printf("sem_wait() returned %d\n", code);
+ GC_COND_LOG_PRINTF("sem_wait() returned %d\n", code);
ABORT("sem_wait() for restart handler failed");
}
}
@@ -911,8 +906,8 @@ GC_INNER void GC_stop_init(void)
if (0 != GETENV("GC_NO_RETRY_SIGNALS")) {
GC_retry_signals = FALSE;
}
- if (GC_print_stats && GC_retry_signals) {
- GC_log_printf("Will retry suspend signal if necessary\n");
+ if (GC_retry_signals) {
+ GC_COND_LOG_PRINTF("Will retry suspend signal if necessary\n");
}
# endif /* !GC_OPENBSD_THREADS && !NACL */
}
diff --git a/pthread_support.c b/pthread_support.c
index 16dd7b3c..a9baa57e 100644
--- a/pthread_support.c
+++ b/pthread_support.c
@@ -430,9 +430,7 @@ static void start_mark_threads(void)
break;
}
}
- if (GC_print_stats) {
- GC_log_printf("Started %d mark helper threads\n", GC_markers_m1);
- }
+ GC_COND_LOG_PRINTF("Started %d mark helper threads\n", GC_markers_m1);
pthread_attr_destroy(&attr);
}
@@ -1084,17 +1082,14 @@ GC_INNER void GC_thr_init(void)
# endif
}
# ifdef PARALLEL_MARK
- if (GC_print_stats) {
- GC_log_printf(
- "Number of processors = %d, number of marker threads = %d\n",
- GC_nprocs, GC_markers_m1 + 1);
- }
+ GC_COND_LOG_PRINTF("Number of processors = %d,"
+ " number of marker threads = %d\n",
+ GC_nprocs, GC_markers_m1 + 1);
if (GC_markers_m1 <= 0) {
/* Disable parallel marking. */
GC_parallel = FALSE;
- if (GC_print_stats) {
- GC_log_printf("Single marker thread, turning off parallel marking\n");
- }
+ GC_COND_LOG_PRINTF(
+ "Single marker thread, turning off parallel marking\n");
} else {
/* Disable true incremental collection, but generational is OK. */
GC_time_limit = GC_TIME_UNLIMITED;
@@ -1104,8 +1099,7 @@ GC_INNER void GC_thr_init(void)
start_mark_threads();
}
# else
- if (GC_print_stats)
- GC_log_printf("Number of processors = %d\n", GC_nprocs);
+ GC_COND_LOG_PRINTF("Number of processors = %d\n", GC_nprocs);
# endif
}
diff --git a/win32_threads.c b/win32_threads.c
index 44f01b00..66a983ca 100644
--- a/win32_threads.c
+++ b/win32_threads.c
@@ -458,9 +458,8 @@ STATIC GC_thread GC_register_my_thread_inner(const struct GC_stack_base *sb,
(HANDLE*)&(me -> handle),
0 /* dwDesiredAccess */, FALSE /* bInheritHandle */,
DUPLICATE_SAME_ACCESS)) {
- if (GC_print_stats)
- GC_log_printf("DuplicateHandle failed with error code: %d\n",
- (int)GetLastError());
+ GC_COND_LOG_PRINTF("DuplicateHandle failed with error code: %d\n",
+ (int)GetLastError());
ABORT("DuplicateHandle failed");
}
# endif
@@ -1513,10 +1512,9 @@ GC_INNER void GC_push_all_stacks(void)
}
}
# ifndef SMALL_CONFIG
- if (GC_print_stats == VERBOSE) {
- GC_log_printf("Pushed %d thread stacks%s\n", nthreads,
- GC_win32_dll_threads ? " based on DllMain thread tracking" : "");
- }
+ GC_VERBOSE_LOG_PRINTF("Pushed %d thread stacks%s\n", nthreads,
+ GC_win32_dll_threads ?
+ " based on DllMain thread tracking" : "");
# endif
if (!found_me && !GC_in_thread_creation)
ABORT("Collecting from unknown thread");
@@ -2489,9 +2487,7 @@ GC_INNER void GC_thr_init(void)
# ifdef PARALLEL_MARK
/* If we are using a parallel marker, actually start helper threads. */
if (GC_parallel) start_mark_threads();
- if (GC_print_stats) {
- GC_log_printf("Started %d mark helper threads\n", GC_markers_m1);
- }
+ GC_COND_LOG_PRINTF("Started %d mark helper threads\n", GC_markers_m1);
# endif
}