+2011-04-03 Ivan Maidanski <ivmai@mail.ru>
+
+ * allchblk.c (GC_freehblk): Use GC_log_printf instead of GC_printf
+ inside "if (GC_print_stats)" branch.
+ * alloc.c (GC_collect_or_expand): Ditto.
+ * dyn_load.c (GC_register_dynamic_libraries): Ditto.
+ * headers.c (GC_scratch_alloc): Ditto.
+ * os_dep.c (GC_get_maps, GC_remap, PROTECT,
+ GC_write_fault_handler, GC_dirty_init, GC_mprotect_thread): Ditto.
+ * alloc.c (min_bytes_allocd): Use GC_log_printf instead of
+ GC_printf for DEBUG_THREADS output.
+ * darwin_stop_world.c (GC_stack_range_for, GC_suspend_thread_list,
+ GC_stop_world, GC_thread_resume, GC_start_world): Ditto.
+ * pthread_start.c (GC_inner_start_routine): Ditto.
+ * pthread_stop_world.c (GC_suspend_handler, GC_restart_handler,
+ GC_push_all_stacks, GC_suspend_all, GC_stop_world,
+ GC_start_world): Ditto.
+ * pthread_support.c (GC_mark_thread, GC_get_nprocs,
+ GC_start_rtn_prepare_thread, pthread_create): Ditto.
+ * alloc.c (GC_adj_bytes_allocd, GC_maybe_gc, GC_stopped_mark,
+ GC_finish_collection): Reformat code.
+ * pthread_stop_world.c (GC_print_sig_mask): Ditto.
+ * pthread_support.c (GC_thr_init): Ditto.
+ * checksums.c (GC_update_check_page): Use GC_printf() instead of
+ GC_err_printf() for error printing.
+ * checksums.c (GC_check_blocks, GC_check_dirty): Use GC_log_printf
+ instead of GC_printf for logging purposes.
+ * dyn_load.c (sys_errlist, sys_nerr, errno): Move declaration of
+ external variable outside from GC_register_dynamic_libraries.
+ * dyn_load.c (GC_register_dynamic_libraries): Don't use
+ sys_errlist value if errno equals to sys_nerr.
+ * dyn_load.c (GC_register_dynamic_libraries): Use GC_log_printf
+ instead of GC_printf for DL_VERBOSE output.
+ * dyn_load.c (GC_dyld_image_add, GC_dyld_image_remove,
+ GC_init_dyld): Use GC_log_printf instead of GC_printf for
+ DARWIN_DEBUG output.
+ * os_dep.c (catch_exception_raise): Use GC_log_printf
+ instead of GC_printf for DEBUG_EXCEPTION_HANDLING output.
+ * reclaim.c (GC_print_free_list): Move "n" increment out of
+ GC_printf() call.
+
2011-04-03 Ivan Maidanski <ivmai@mail.ru>
* win32_threads.c (DEBUG_CYGWIN_THREADS, DEBUG_WIN32_PTHREADS,
/* Check for duplicate deallocation in the easy case */
if (HBLK_IS_FREE(hhdr)) {
if (GC_print_stats)
- GC_printf("Duplicate large block deallocation of %p\n", hbp);
+ GC_log_printf("Duplicate large block deallocation of %p\n", hbp);
ABORT("Duplicate large block deallocation");
}
time_diff = MS_TIME_DIFF(current_time,GC_start_time);
if (time_diff >= GC_time_limit) {
if (GC_print_stats) {
- GC_log_printf(
+ GC_log_printf(
"Abandoning stopped marking after %lu msecs (attempt %d)\n",
time_diff, GC_n_attempts);
}
stack_size = GC_total_stacksize;
/* For now, we just use the value computed during the latest GC. */
# ifdef DEBUG_THREADS
- GC_printf("Total stacks size: %lu\n", (unsigned long)stack_size);
+ GC_log_printf("Total stacks size: %lu\n",
+ (unsigned long)stack_size);
# endif
}
# endif
STATIC word GC_adj_bytes_allocd(void)
{
signed_word result;
- signed_word expl_managed =
- (signed_word)GC_non_gc_bytes
- - (signed_word)GC_non_gc_bytes_at_gc;
+ signed_word expl_managed = (signed_word)GC_non_gc_bytes
+ - (signed_word)GC_non_gc_bytes_at_gc;
/* Don't count what was explicitly freed, or newly allocated for */
/* explicit management. Note that deallocating an explicitly */
# endif
if (GC_need_full_gc || n_partial_gcs >= GC_full_freq) {
if (GC_print_stats) {
- GC_log_printf(
+ GC_log_printf(
"***>Full mark for collection %lu after %ld allocd bytes\n",
- (unsigned long)GC_gc_no+1,
- (long)GC_bytes_allocd);
+ (unsigned long)GC_gc_no + 1, (long)GC_bytes_allocd);
}
GC_promote_black_lists();
(void)GC_reclaim_all((GC_stop_func)0, TRUE);
if (GC_print_stats) {
GET_TIME(current_time);
GC_log_printf("Complete collection took %lu msecs\n",
- MS_TIME_DIFF(current_time,start_time));
+ MS_TIME_DIFF(current_time,start_time));
}
# endif
return(TRUE);
GC_clear_a_few_frames();
GC_noop(0,0,0,0,0,0);
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_deficit = i; /* Give the mutator a chance. */
-# ifdef THREAD_LOCAL_ALLOC
- GC_world_stopped = FALSE;
-# endif
- START_WORLD();
- return(FALSE);
+ for (i = 0;;i++) {
+ if ((*stop_func)()) {
+ if (GC_print_stats) {
+ GC_log_printf("Abandoned stopped marking after %u iterations\n",
+ i);
}
- if (GC_mark_some((ptr_t)(&dummy))) break;
+ GC_deficit = i; /* Give the mutator a chance. */
+# ifdef THREAD_LOCAL_ALLOC
+ GC_world_stopped = FALSE;
+# endif
+ START_WORLD();
+ return(FALSE);
+ }
+ if (GC_mark_some((ptr_t)(&dummy))) break;
}
GC_gc_no++;
if (GC_print_stats == VERBOSE)
GC_log_printf("Bytes recovered before sweep - f.l. count = %ld\n",
- (long)GC_bytes_found);
+ (long)GC_bytes_found);
/* Reconstruct free lists to contain everything not marked */
GC_start_reclaim(FALSE);
}
if (GC_print_stats == VERBOSE) {
-# ifdef USE_MUNMAP
- GC_log_printf("Immediately reclaimed %ld bytes in heap"
- " of size %lu bytes (%lu unmapped)\n",
- (long)GC_bytes_found, (unsigned long)GC_heapsize,
- (unsigned long)GC_unmapped_bytes);
-# else
- GC_log_printf("Immediately reclaimed %ld bytes in heap"
- " of size %lu bytes\n",
- (long)GC_bytes_found, (unsigned long)GC_heapsize);
-# endif
+# ifdef USE_MUNMAP
+ GC_log_printf("Immediately reclaimed %ld bytes in heap"
+ " of size %lu bytes (%lu unmapped)\n",
+ (long)GC_bytes_found, (unsigned long)GC_heapsize,
+ (unsigned long)GC_unmapped_bytes);
+# else
+ GC_log_printf(
+ "Immediately reclaimed %ld bytes in heap of size %lu bytes\n",
+ (long)GC_bytes_found, (unsigned long)GC_heapsize);
+# endif
}
/* Reset or increment counters for next cycle */
/* A convenient place to output finalization statistics. */
GC_print_finalization_stats();
- GC_log_printf("Finalize + initiate sweep took %lu + %lu msecs\n",
+ GC_log_printf("Finalize plus initiate sweep took %lu + %lu msecs\n",
MS_TIME_DIFF(finalize_time,start_time),
MS_TIME_DIFF(done_time,finalize_time));
}
{
unsigned i;
- GC_printf("Total heap size: %lu\n", (unsigned long) GC_heapsize);
+ GC_printf("Total heap size: %lu\n", (unsigned long)GC_heapsize);
for (i = 0; i < GC_n_heap_sects; i++) {
- ptr_t start = GC_heap_sects[i].hs_start;
- size_t len = GC_heap_sects[i].hs_bytes;
- struct hblk *h;
- unsigned nbl = 0;
+ ptr_t start = GC_heap_sects[i].hs_start;
+ size_t len = GC_heap_sects[i].hs_bytes;
+ struct hblk *h;
+ unsigned nbl = 0;
- for (h = (struct hblk *)start; h < (struct hblk *)(start + len); h++) {
- if (GC_is_black_listed(h, HBLKSIZE)) nbl++;
- }
- GC_printf("Section %d from %p to %p %lu/%lu blacklisted\n",
- i, start, start + len,
- (unsigned long)nbl, (unsigned long)(len/HBLKSIZE));
+ for (h = (struct hblk *)start; h < (struct hblk *)(start + len); h++) {
+ if (GC_is_black_listed(h, HBLKSIZE)) nbl++;
+ }
+ GC_printf("Section %d from %p to %p %lu/%lu blacklisted\n",
+ i, start, start + len,
+ (unsigned long)nbl, (unsigned long)(len/HBLKSIZE));
}
}
#endif
}
space = GET_MEM(bytes);
GC_add_to_our_memory((ptr_t)space, bytes);
- if( space == 0 ) {
+ if (space == 0) {
if (GC_print_stats) {
GC_log_printf("Failed to expand heap by %ld bytes\n",
(unsigned long)bytes);
return(FALSE);
}
} else if (GC_fail_count && GC_print_stats) {
- GC_printf("Memory available again...\n");
+ GC_log_printf("Memory available again...\n");
}
RESTORE_CANCEL(cancel_state);
return(TRUE);
pe -> new_sum = GC_checksum(h);
# if !defined(MSWIN32) && !defined(MSWINCE)
if (pe -> new_sum != 0x80000000 && !GC_page_was_ever_dirty(h)) {
- GC_printf("GC_page_was_ever_dirty(%p) is wrong\n", h);
+ GC_err_printf("GC_page_was_ever_dirty(%p) is wrong\n", h);
}
# endif
if (GC_page_was_dirty(h)) {
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 ",
- (unsigned long)GC_bytes_in_used_blocks,
- (unsigned long)bytes_in_free_blocks);
- GC_printf("GC_heapsize = %lu\n", (unsigned long)GC_heapsize);
+ GC_log_printf(
+ "GC_bytes_in_used_blocks = %lu, bytes_in_free_blocks = %lu ",
+ (unsigned long)GC_bytes_in_used_blocks,
+ (unsigned long)bytes_in_free_blocks);
+ GC_log_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");
+ GC_log_printf("LOST SOME BLOCKS!!\n");
}
}
}
}
out:
- GC_printf("Checked %lu clean and %lu dirty pages\n",
- (unsigned long) GC_n_clean, (unsigned long) GC_n_dirty);
+ GC_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_printf("Found %d dirty bit errors (%d were faulted)\n",
- GC_n_dirty_errors, GC_n_faulted_dirty_errors);
+ GC_log_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",
- (unsigned long)GC_n_changed_errors);
- GC_printf("These may be benign (provoked by nonpointer changes)\n");
+ GC_log_printf("Found %lu changed bit errors\n",
+ (unsigned long)GC_n_changed_errors);
+ GC_log_printf(
+ "These may be benign (provoked by nonpointer changes)\n");
# ifdef THREADS
- GC_printf(
+ GC_log_printf(
"Also expect 1 per thread currently allocating a stubborn obj\n");
# endif
}
(natural_t *)&state,
&thread_state_count);
# ifdef DEBUG_THREADS
- GC_printf("thread_get_state return value = %d\n", kern_result);
+ GC_log_printf("thread_get_state returns value = %d\n", kern_result);
# endif
if (kern_result != KERN_SUCCESS)
ABORT("thread_get_state failed");
*phi = (p->flags & MAIN_THREAD) != 0 ? GC_stackbottom : p->stack_end;
# endif
# ifdef DEBUG_THREADS
- GC_printf("Darwin: Stack for thread 0x%lx = [%p,%p)\n",
- (unsigned long) thread, lo, *phi);
+ GC_log_printf("Darwin: Stack for thread 0x%lx = [%p,%p)\n",
+ (unsigned long)thread, lo, *phi);
# endif
return lo;
}
# endif
# ifdef DEBUG_THREADS
- GC_printf("Attempting to suspend thread 0x%lx\n",
- (unsigned long)thread);
+ GC_log_printf("Attempting to suspend thread 0x%lx\n",
+ (unsigned long)thread);
# endif
/* find the current thread in the old list */
found = FALSE;
continue;
}
# ifdef DEBUG_THREADS
- GC_printf("Thread state for 0x%lx = %d\n", (unsigned long)thread,
- info.run_state);
+ GC_log_printf("Thread state for 0x%lx = %d\n", (unsigned long)thread,
+ info.run_state);
# endif
if (info.suspend_count != 0) {
/* thread is already suspended. */
}
# ifdef DEBUG_THREADS
- GC_printf("Suspending 0x%lx\n", (unsigned long)thread);
+ GC_log_printf("Suspending 0x%lx\n", (unsigned long)thread);
# endif
kern_result = thread_suspend(thread);
if (kern_result != KERN_SUCCESS) {
kern_return_t kern_result;
# ifdef DEBUG_THREADS
- GC_printf("Stopping the world from thread 0x%lx\n",
- (unsigned long)my_thread);
+ GC_log_printf("Stopping the world from thread 0x%lx\n",
+ (unsigned long)my_thread);
# endif
# ifdef PARALLEL_MARK
if (GC_parallel) {
# endif
# ifdef DEBUG_THREADS
- GC_printf("World stopped from 0x%lx\n", (unsigned long)my_thread);
+ GC_log_printf("World stopped from 0x%lx\n", (unsigned long)my_thread);
# endif
mach_port_deallocate(my_task, my_thread);
}
ABORT("thread_info failed");
# endif
# ifdef DEBUG_THREADS
- GC_printf("Resuming thread 0x%lx with state %d\n",
- (unsigned long)thread, info.run_state);
+ GC_log_printf("Resuming thread 0x%lx with state %d\n",
+ (unsigned long)thread, info.run_state);
# endif
/* Resume the thread */
kern_result = thread_resume(thread);
task_t my_task = current_task();
int i;
# ifdef DEBUG_THREADS
- GC_printf("World starting\n");
+ GC_log_printf("World starting\n");
# endif
# ifdef MPROTECT_VDB
if(GC_incremental) {
/* The thread is found in GC_mach_threads. */
if (GC_mach_threads[j].already_suspended) {
# ifdef DEBUG_THREADS
- GC_printf("Not resuming already suspended thread 0x%lx\n",
- (unsigned long)thread);
+ GC_log_printf("Not resuming already suspended thread 0x%lx\n",
+ (unsigned long)thread);
# endif
} else {
GC_thread_resume(thread);
}
# ifdef DEBUG_THREADS
- GC_printf("World started\n");
+ GC_log_printf("World started\n");
# endif
}
#include <loader.h>
+extern char *sys_errlist[];
+extern int sys_nerr;
+extern int errno;
+
GC_INNER void GC_register_dynamic_libraries(void)
{
int status;
/* Check status AFTER checking moduleid because */
/* of a bug in the non-shared ldr_next_module stub */
if (status != 0) {
- if (GC_print_stats) {
- extern char *sys_errlist[];
- extern int sys_nerr;
- extern int errno;
- GC_printf("dynamic_load: status = %d\n", status);
- if (errno <= sys_nerr) {
- GC_printf("dynamic_load: %s\n", sys_errlist[errno]);
- } else {
- GC_printf("dynamic_load: err_code = %d\n", errno);
- }
+ 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);
}
- ABORT("ldr_next_module failed");
+ }
+ ABORT("ldr_next_module failed");
}
/* Get the module information */
continue; /* skip the main module */
# ifdef DL_VERBOSE
- GC_printf("---Module---\n");
- GC_printf("Module ID = %16ld\n", moduleinfo.lmi_modid);
- GC_printf("Count of regions = %16d\n", moduleinfo.lmi_nregion);
- GC_printf("flags for module = %16lx\n", moduleinfo.lmi_flags);
- GC_printf("pathname of module = \"%s\"\n", moduleinfo.lmi_name);
+ GC_log_printf("---Module---\n");
+ GC_log_printf("Module ID\t = %16ld\n", moduleinfo.lmi_modid);
+ GC_log_printf("Count of regions = %16d\n", moduleinfo.lmi_nregion);
+ GC_log_printf("flags for module = %16lx\n", moduleinfo.lmi_flags);
+ GC_log_printf("module pathname\t = \"%s\"\n", moduleinfo.lmi_name);
# endif
/* For each region in this module */
continue;
# ifdef DL_VERBOSE
- GC_printf("--- Region ---\n");
- GC_printf("Region number = %16ld\n",
- regioninfo.lri_region_no);
- GC_printf("Protection flags = %016x\n", regioninfo.lri_prot);
- GC_printf("Virtual address = %16p\n", regioninfo.lri_vaddr);
- GC_printf("Mapped address = %16p\n", regioninfo.lri_mapaddr);
- GC_printf("Region size = %16ld\n", regioninfo.lri_size);
- GC_printf("Region name = \"%s\"\n", regioninfo.lri_name);
+ GC_log_printf("--- Region ---\n");
+ GC_log_printf("Region number\t = %16ld\n",
+ regioninfo.lri_region_no);
+ GC_log_printf("Protection flags = %016x\n", regioninfo.lri_prot);
+ GC_log_printf("Virtual address\t = %16p\n", regioninfo.lri_vaddr);
+ GC_log_printf("Mapped address\t = %16p\n",
+ regioninfo.lri_mapaddr);
+ GC_log_printf("Region size\t = %16ld\n", regioninfo.lri_size);
+ GC_log_printf("Region name\t = \"%s\"\n", regioninfo.lri_name);
# endif
/* register region as a garbage collection root */
- GC_add_roots_inner (
- (char *)regioninfo.lri_mapaddr,
- (char *)regioninfo.lri_mapaddr + regioninfo.lri_size,
- TRUE);
+ GC_add_roots_inner((char *)regioninfo.lri_mapaddr,
+ (char *)regioninfo.lri_mapaddr + regioninfo.lri_size,
+ TRUE);
}
}
break; /* Moved past end of shared library list --> finished */
} else {
if (GC_print_stats) {
- if (errno <= sys_nerr) {
- GC_printf("dynamic_load: %s\n", sys_errlist[errno]);
+ if (errno < sys_nerr) {
+ GC_log_printf("dynamic_load: %s\n", sys_errlist[errno]);
} else {
- GC_printf("dynamic_load: err_code = %d\n", errno);
+ GC_log_printf("dynamic_load: err_code = %d\n", errno);
}
}
ABORT("shl_get failed");
}
# ifdef DL_VERBOSE
- GC_printf("---Shared library---\n");
- GC_printf("\tfilename = \"%s\"\n", shl_desc->filename);
- GC_printf("\tindex = %d\n", index);
- GC_printf("\thandle = %08x\n",
- (unsigned long) shl_desc->handle);
- GC_printf("\ttext seg. start = %08x\n", shl_desc->tstart);
- GC_printf("\ttext seg. end = %08x\n", shl_desc->tend);
- GC_printf("\tdata seg. start = %08x\n", shl_desc->dstart);
- GC_printf("\tdata seg. end = %08x\n", shl_desc->dend);
- GC_printf("\tref. count = %lu\n", shl_desc->ref_count);
+ GC_log_printf("---Shared library---\n");
+ GC_log_printf("\tfilename\t= \"%s\"\n", shl_desc->filename);
+ GC_log_printf("\tindex\t\t= %d\n", index);
+ GC_log_printf("\thandle\t\t= %08x\n",
+ (unsigned long) shl_desc->handle);
+ GC_log_printf("\ttext seg.start\t= %08x\n", shl_desc->tstart);
+ GC_log_printf("\ttext seg.end\t= %08x\n", shl_desc->tend);
+ GC_log_printf("\tdata seg.start\t= %08x\n", shl_desc->dstart);
+ GC_log_printf("\tdata seg.end\t= %08x\n", shl_desc->dend);
+ GC_log_printf("\tref.count\t= %lu\n", shl_desc->ref_count);
# endif
/* register shared library's data segment as a garbage collection root */
/* The user callback is called holding the lock */
if (callback == 0 || callback(name, (void*)start, (size_t)sec->size)) {
# ifdef DARWIN_DEBUG
- GC_printf("Adding section at %p-%p (%lu bytes) from image %s\n",
- start,end,sec->size,name);
+ GC_log_printf("Adding section at %p-%p (%lu bytes) from image %s\n",
+ start, end, sec->size, name);
# endif
GC_add_roots_inner((ptr_t)start, (ptr_t)end, FALSE);
}
start = slide + sec->addr;
end = start + sec->size;
# ifdef DARWIN_DEBUG
- GC_printf("Removing section at %p-%p (%lu bytes) from image %s\n",
- start,end,sec->size,GC_dyld_name_for_hdr(hdr));
+ GC_log_printf("Removing section at %p-%p (%lu bytes) from image %s\n",
+ start, end, sec->size, GC_dyld_name_for_hdr(hdr));
# endif
GC_remove_roots((char*)start,(char*)end);
}
if (initialized) return;
# ifdef DARWIN_DEBUG
- GC_printf("Registering dyld callbacks...\n");
+ GC_log_printf("Registering dyld callbacks...\n");
# endif
/* Apple's Documentation:
if (GETENV("DYLD_BIND_AT_LAUNCH") == 0) {
/* The environment variable is unset, so we should bind manually. */
# ifdef DARWIN_DEBUG
- GC_printf("Forcing full bind of GC code...\n");
+ GC_log_printf("Forcing full bind of GC code...\n");
# endif
/* FIXME: '_dyld_bind_fully_image_containing_address' is deprecated. */
if (!_dyld_bind_fully_image_containing_address(
GC_add_to_our_memory(result, bytes_to_get);
if (result == 0) {
if (GC_print_stats)
- GC_printf("Out of memory - trying to allocate less\n");
+ GC_log_printf("Out of memory - trying to allocate less\n");
scratch_free_ptr -= bytes;
bytes_to_get = bytes;
# ifdef USE_MMAP
# ifdef THREADS
if (maps_size > old_maps_size) {
if (GC_print_stats)
- GC_printf("Unexpected maps size growth from %lu to %lu\n",
- (unsigned long)old_maps_size,
- (unsigned long)maps_size);
+ GC_log_printf(
+ "Unexpected maps size growth from %lu to %lu\n",
+ (unsigned long)old_maps_size,
+ (unsigned long)maps_size);
ABORT("Unexpected asynchronous /proc/self/maps growth: "
"unregistered thread?");
}
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_log_printf("Failed to find backing store base from /proc\n");
}
return 0;
}
}
}
if (GC_print_stats)
- GC_log_printf("Found new system malloc AllocationBase at %p\n",
- candidate);
+ GC_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;
if (result != 0) {
if (GC_print_stats)
- GC_printf("Mprotect failed at %p (length %lu) with errno %d\n",
- start_addr, (unsigned long)len, errno);
+ GC_log_printf("Mprotect failed at %p (length %lu) with errno %d\n",
+ start_addr, (unsigned long)len, errno);
ABORT("mprotect remapping failed");
}
GC_unmapped_bytes -= len;
# include <sys/syscall.h>
# define PROTECT(addr, len) \
- if (mprotect((caddr_t)(addr), (size_t)(len), \
- PROT_READ \
- | (pages_executable ? PROT_EXEC : 0)) < 0) { \
- ABORT("mprotect failed"); \
- }
+ if (mprotect((caddr_t)(addr), (size_t)(len), \
+ PROT_READ \
+ | (pages_executable ? PROT_EXEC : 0)) < 0) { \
+ ABORT("mprotect failed"); \
+ }
# define UNPROTECT(addr, len) \
- if (mprotect((caddr_t)(addr), (size_t)(len), \
- (PROT_READ | PROT_WRITE) \
- | (pages_executable ? PROT_EXEC : 0)) < 0) { \
- ABORT(pages_executable ? "un-mprotect executable page" \
- " failed (probably disabled by OS)" : \
- "un-mprotect failed"); \
- }
+ if (mprotect((caddr_t)(addr), (size_t)(len), \
+ (PROT_READ | PROT_WRITE) \
+ | (pages_executable ? PROT_EXEC : 0)) < 0) { \
+ ABORT(pages_executable ? "un-mprotect executable page" \
+ " failed (probably disabled by OS)" : \
+ "un-mprotect failed"); \
+ }
# undef IGNORE_PAGES_EXECUTABLE
# else /* MSWIN32 */
static DWORD protect_junk;
# define PROTECT(addr, len) \
- if (!VirtualProtect((addr), (len), \
- pages_executable ? PAGE_EXECUTE_READ : \
- PAGE_READONLY, \
- &protect_junk)) { \
- if (GC_print_stats) \
- GC_printf("Last error code: 0x%lx\n", (long)GetLastError()); \
- ABORT("VirtualProtect failed"); \
- }
+ if (!VirtualProtect((addr), (len), \
+ pages_executable ? PAGE_EXECUTE_READ : \
+ PAGE_READONLY, \
+ &protect_junk)) { \
+ if (GC_print_stats) \
+ GC_log_printf("Last error code: 0x%lx\n", (long)GetLastError()); \
+ ABORT("VirtualProtect failed"); \
+ }
# define UNPROTECT(addr, len) \
- if (!VirtualProtect((addr), (len), \
- pages_executable ? PAGE_EXECUTE_READWRITE : \
- PAGE_READWRITE, \
- &protect_junk)) { \
- ABORT("un-VirtualProtect failed"); \
- }
+ if (!VirtualProtect((addr), (len), \
+ pages_executable ? PAGE_EXECUTE_READWRITE : \
+ PAGE_READWRITE, \
+ &protect_junk)) { \
+ ABORT("un-VirtualProtect failed"); \
+ }
# endif /* MSWIN32 || MSWINCE || DARWIN */
# if defined(MSWIN32)
if (old_handler == (SIG_HNDLR_PTR)SIG_DFL) {
# if !defined(MSWIN32) && !defined(MSWINCE)
if (GC_print_stats)
- GC_printf("Unexpected segfault at %p\n", addr);
+ GC_log_printf("Unexpected segfault at %p\n", addr);
ABORT("Unexpected bus error or segmentation fault");
# else
return(EXCEPTION_CONTINUE_SEARCH);
return EXCEPTION_CONTINUE_SEARCH;
# else
if (GC_print_stats)
- GC_printf("Unexpected segfault at %p\n", addr);
+ GC_log_printf("Unexpected segfault at %p\n", addr);
ABORT("Unexpected bus error or segmentation fault");
# endif
}
# endif /* SIG_SUSPEND */
# endif
if (GC_print_stats == VERBOSE)
- GC_log_printf(
+ GC_log_printf(
"Initializing mprotect virtual dirty bit implementation\n");
GC_dirty_maintained = TRUE;
if (GC_page_size % HBLKSIZE != 0) {
GC_dirty_maintained = TRUE;
if (GC_bytes_allocd != 0 || GC_bytes_allocd_before_gc != 0) {
- register int i;
-
- for (i = 0; i < PHT_SIZE; i++)
- GC_written_pages[i] = (word)(-1);
- if (GC_print_stats == VERBOSE)
- GC_log_printf(
- "Allocated bytes:%lu:all pages may have been written\n",
- (unsigned long)
- (GC_bytes_allocd + GC_bytes_allocd_before_gc));
+ register int i;
+ for (i = 0; i < PHT_SIZE; i++)
+ GC_written_pages[i] = (word)(-1);
+ if (GC_print_stats == VERBOSE)
+ GC_log_printf("Allocated bytes:%lu:all pages may have been written\n",
+ (unsigned long)(GC_bytes_allocd
+ + GC_bytes_allocd_before_gc));
}
sprintf(buf, "/proc/%ld", (long)getpid());
fd = open(buf, O_RDONLY);
char *new_buf;
if (GC_print_stats)
- GC_log_printf("/proc read failed: GC_proc_buf_size = %lu\n",
- (unsigned long)GC_proc_buf_size);
+ GC_log_printf("/proc read failed: GC_proc_buf_size = %lu\n",
+ (unsigned long)GC_proc_buf_size);
new_buf = GC_scratch_alloc(new_size);
if (new_buf != 0) {
if (r != MACH_MSG_SUCCESS) {
if (GC_print_stats)
- GC_printf("mach_msg failed with code %d: %s\n", (int)r,
- mach_error_string(r));
+ GC_log_printf("mach_msg failed with code %d: %s\n", (int)r,
+ mach_error_string(r));
ABORT("mach_msg failed");
}
if (exception != EXC_BAD_ACCESS || code[0] != KERN_PROTECTION_FAILURE) {
# ifdef DEBUG_EXCEPTION_HANDLING
/* We aren't interested, pass it on to the old handler */
- GC_printf("Exception: 0x%x Code: 0x%x 0x%x in catch...\n", exception,
- code_count > 0 ? code[0] : -1, code_count > 1 ? code[1] : -1);
+ GC_log_printf("Exception: 0x%x Code: 0x%x 0x%x in catch...\n",
+ exception, code_count > 0 ? code[0] : -1,
+ code_count > 1 ? code[1] : -1);
# endif
return FWD();
}
# endif
result = (*start)(start_arg);
# ifdef DEBUG_THREADS
- GC_printf("Finishing thread 0x%x\n", (unsigned)pthread_self());
+ GC_log_printf("Finishing thread 0x%x\n", (unsigned)pthread_self());
# endif
me -> status = result;
# ifndef NACL
int i;
if (pthread_sigmask(SIG_BLOCK, NULL, &blocked) != 0)
- ABORT("pthread_sigmask failed");
+ ABORT("pthread_sigmask failed");
GC_printf("Blocked: ");
for (i = 1; i < NSIG; i++) {
- if (sigismember(&blocked, i)) { GC_printf("%d ", i); }
+ if (sigismember(&blocked, i))
+ GC_printf("%d ", i);
}
GC_printf("\n");
}
/* cancellation point is inherently a problem, unless there is */
/* some way to disable cancellation in the handler. */
# ifdef DEBUG_THREADS
- GC_printf("Suspending 0x%x\n", (unsigned)my_thread);
+ GC_log_printf("Suspending 0x%x\n", (unsigned)my_thread);
# endif
me = GC_lookup_thread(my_thread);
/* unlikely to be efficient. */
# ifdef DEBUG_THREADS
- GC_printf("Continuing 0x%x\n", (unsigned)my_thread);
+ GC_log_printf("Continuing 0x%x\n", (unsigned)my_thread);
# endif
RESTORE_CANCEL(cancel_state);
}
*/
# ifdef DEBUG_THREADS
- GC_printf("In GC_restart_handler for 0x%x\n", (unsigned)pthread_self());
+ GC_log_printf("In GC_restart_handler for 0x%x\n",
+ (unsigned)pthread_self());
# endif
}
if (!GC_thr_initialized) GC_thr_init();
# ifdef DEBUG_THREADS
- GC_printf("Pushing stacks from thread 0x%x\n", (unsigned) me);
+ GC_log_printf("Pushing stacks from thread 0x%x\n", (unsigned)me);
# endif
for (i = 0; i < THREAD_TABLE_SZ; i++) {
for (p = GC_threads[i]; p != 0; p = p -> next) {
IF_IA64(bs_lo = BACKING_STORE_BASE;)
}
# ifdef DEBUG_THREADS
- GC_printf("Stack for thread 0x%x = [%p,%p)\n",
- (unsigned)(p -> id), lo, hi);
+ GC_log_printf("Stack for thread 0x%x = [%p,%p)\n",
+ (unsigned)(p -> id), lo, hi);
# endif
if (0 == lo) ABORT("GC_push_all_stacks: sp not set!");
GC_push_all_stack_sections(lo, hi, p -> traced_stack_sect);
# endif
# ifdef IA64
# ifdef DEBUG_THREADS
- GC_printf("Reg stack for thread 0x%x = [%p,%p)\n",
- (unsigned)p -> id, bs_lo, bs_hi);
+ GC_log_printf("Reg stack for thread 0x%x = [%p,%p)\n",
+ (unsigned)p -> id, bs_lo, bs_hi);
# endif
/* FIXME: This (if p->id==me) may add an unbounded number of */
/* entries, and hence overflow the mark stack, which is bad. */
}
}
if (GC_print_stats == VERBOSE) {
- GC_log_printf("Pushed %d thread stacks\n", (int)nthreads);
+ GC_log_printf("Pushed %d thread stacks\n", (int)nthreads);
}
if (!found_me && !GC_in_thread_creation)
ABORT("Collecting from unknown thread");
n_live_threads++;
# endif
# ifdef DEBUG_THREADS
- GC_printf("Sending suspend signal to 0x%x\n",
- (unsigned)(p -> id));
+ GC_log_printf("Sending suspend signal to 0x%x\n",
+ (unsigned)(p -> id));
# endif
# ifdef GC_OPENBSD_THREADS
# define NACL_PARK_WAIT_NANOSECONDS (100 * 1000)
# endif
# ifdef DEBUG_THREADS
- GC_printf("pthread_stop_world: num_threads %d\n",
- GC_nacl_num_gc_threads - 1);
+ GC_log_printf("pthread_stop_world: num_threads %d\n",
+ GC_nacl_num_gc_threads - 1);
# endif
GC_nacl_thread_parker = pthread_self();
GC_nacl_park_threads_now = 1;
ts.tv_sec = 0;
ts.tv_nsec = NACL_PARK_WAIT_NANOSECONDS;
# ifdef DEBUG_THREADS
- GC_printf("Sleep waiting for %d threads to park...\n",
- GC_nacl_num_gc_threads - num_threads_parked - 1);
+ GC_log_printf("Sleep waiting for %d threads to park...\n",
+ GC_nacl_num_gc_threads - num_threads_parked - 1);
# endif
/* This requires _POSIX_TIMERS feature. */
nanosleep(&ts, 0);
# endif
GC_ASSERT(I_HOLD_LOCK());
# ifdef DEBUG_THREADS
- GC_printf("Stopping the world from 0x%x\n", (unsigned)pthread_self());
+ GC_log_printf("Stopping the world from 0x%x\n", (unsigned)pthread_self());
# endif
/* Make sure all free list construction has stopped before we start. */
GC_release_mark_lock();
# endif
# ifdef DEBUG_THREADS
- GC_printf("World stopped from 0x%x\n", (unsigned)pthread_self());
+ GC_log_printf("World stopped from 0x%x\n", (unsigned)pthread_self());
GC_stopping_thread = 0;
# endif
}
# endif
# ifdef DEBUG_THREADS
- GC_printf("World starting\n");
+ GC_log_printf("World starting\n");
# endif
# ifndef GC_OPENBSD_THREADS
n_live_threads++;
# endif
# ifdef DEBUG_THREADS
- GC_printf("Sending restart signal to 0x%x\n",
- (unsigned)(p -> id));
+ GC_log_printf("Sending restart signal to 0x%x\n",
+ (unsigned)(p -> id));
# endif
# ifdef GC_OPENBSD_THREADS
while (0 != (code = sem_wait(&GC_restart_ack_sem)))
if (errno != EINTR) {
if (GC_print_stats)
- GC_printf("sem_wait() returned %d\n", code);
+ GC_log_printf("sem_wait() returned %d\n", code);
ABORT("sem_wait() for restart handler failed");
}
# endif
# ifdef DEBUG_THREADS
- GC_printf("World started\n");
+ GC_log_printf("World started\n");
# endif
# else /* NACL */
# ifdef DEBUG_THREADS
- GC_printf("World starting...\n");
+ GC_log_printf("World starting...\n");
# endif
GC_nacl_park_threads_now = 0;
# endif
GC_retry_signals = FALSE;
}
if (GC_print_stats && GC_retry_signals) {
- GC_log_printf("Will retry suspend signal if necessary\n");
+ GC_log_printf("Will retry suspend signal if necessary\n");
}
# endif /* !GC_OPENBSD_THREADS && !NACL */
}
my_mark_no = GC_mark_no;
}
# ifdef DEBUG_THREADS
- GC_printf("Starting mark helper for mark number %lu\n",
- (unsigned long)my_mark_no);
+ GC_log_printf("Starting mark helper for mark number %lu\n",
+ (unsigned long)my_mark_no);
# endif
GC_help_marker(my_mark_no);
}
}
}
if (GC_print_stats) {
- GC_log_printf("Started %ld mark helper threads\n", GC_markers - 1);
+ GC_log_printf("Started %ld mark helper threads\n", GC_markers - 1);
}
pthread_attr_destroy(&attr);
}
numCpus = pm_sysinfo.idle_vp_count;
# ifdef DEBUG_THREADS
- GC_printf("Number of active CPUs in this system: %d\n", numCpus);
+ GC_log_printf("Number of active CPUs in this system: %d\n", numCpus);
# endif
return(numCpus);
}
}
# ifdef PARALLEL_MARK
if (GC_print_stats) {
- GC_log_printf("Number of processors = %ld, "
- "number of marker threads = %ld\n", GC_nprocs, GC_markers);
+ GC_log_printf(
+ "Number of processors = %ld, number of marker threads = %ld\n",
+ GC_nprocs, GC_markers);
}
if (GC_markers <= 1) {
GC_parallel = FALSE;
my_pthread = pthread_self();
# ifdef DEBUG_THREADS
- GC_printf("Starting thread 0x%x, pid = %ld, sp = %p\n",
- (unsigned)my_pthread, (long) getpid(), &arg);
+ GC_log_printf("Starting thread 0x%x, pid = %ld, sp = %p\n",
+ (unsigned)my_pthread, (long)getpid(), &arg);
# endif
LOCK();
me = GC_register_my_thread_inner(sb, my_pthread);
UNLOCK();
*pstart = si -> start_routine;
# ifdef DEBUG_THREADS
- GC_printf("start_routine = %p\n", (void *)(signed_word)(*pstart));
+ GC_log_printf("start_routine = %p\n", (void *)(signed_word)(*pstart));
# endif
*pstart_arg = si -> arg;
sem_post(&(si -> registered)); /* Last action on si. */
si -> flags = my_flags;
UNLOCK();
# ifdef DEBUG_THREADS
- GC_printf("About to start new thread from thread 0x%x\n",
- (unsigned)pthread_self());
+ GC_log_printf("About to start new thread from thread 0x%x\n",
+ (unsigned)pthread_self());
# endif
GC_need_to_lock = TRUE;
result = REAL_FUNC(pthread_create)(new_thread, attr, GC_start_routine, si);
# ifdef DEBUG_THREADS
- GC_printf("Started thread 0x%x\n", (unsigned)(*new_thread));
+ GC_log_printf("Started thread 0x%x\n", (unsigned)(*new_thread));
# endif
/* Wait until child has been added to the thread table. */
/* This also ensures that we hold onto si until the child is done */
if (hhdr -> hb_n_marks != n_marks) {
GC_printf("(%u:%u,%u!=%u)", hhdr -> hb_obj_kind, (unsigned)bytes,
- (unsigned)hhdr -> hb_n_marks, n_marks);
+ (unsigned)hhdr -> hb_n_marks, n_marks);
} else {
GC_printf("(%u:%u,%u)", hhdr -> hb_obj_kind,
- (unsigned)bytes, n_marks);
+ (unsigned)bytes, n_marks);
}
bytes += HBLKSIZE-1;
bytes &= ~(HBLKSIZE-1);
struct obj_kind * ok = &GC_obj_kinds[kind];
ptr_t flh = ok -> ok_freelist[sz_in_granules];
struct hblk *lastBlock = 0;
- int n = 0;
+ int n;
- while (flh) {
+ for (n = 1; flh; n++) {
struct hblk *block = HBLKPTR(flh);
if (block != lastBlock) {
- GC_printf("\nIn heap block at %p:\n\t", block);
- lastBlock = block;
+ GC_printf("\nIn heap block at %p:\n\t", block);
+ lastBlock = block;
}
- GC_printf("%d: %p;", ++n, flh);
+ GC_printf("%d: %p;", n, flh);
flh = obj_link(flh);
}
}
if (GC_print_stats == VERBOSE) {
GET_TIME(done_time);
GC_log_printf("Disposing of reclaim lists took %lu msecs\n",
- MS_TIME_DIFF(done_time,start_time));
+ MS_TIME_DIFF(done_time,start_time));
}
# endif
return(TRUE);