}
GC_gc_no++;
- GC_DBGLOG_PRINTF("GC #%lu reclaimed %ld bytes --> heapsize: %lu"
- " bytes" IF_USE_MUNMAP(" (%lu unmapped)") "\n",
+ GC_DBGLOG_PRINTF("GC #%lu freed %ld bytes, heap %lu KiB"
+ IF_USE_MUNMAP(" (+ %lu KiB unmapped)") "\n",
(unsigned long)GC_gc_no, (long)GC_bytes_found,
- (unsigned long)GC_heapsize /*, */
- COMMA_IF_USE_MUNMAP((unsigned long)GC_unmapped_bytes));
+ TO_KiB_UL(GC_heapsize - GC_unmapped_bytes) /*, */
+ COMMA_IF_USE_MUNMAP(TO_KiB_UL(GC_unmapped_bytes)));
/* Check all debugged objects for consistency */
if (GC_debugging_started) {
GC_on_heap_resize_proc GC_on_heap_resize = 0;
+/* Used for logging only. */
+GC_INLINE int GC_compute_heap_usage_percent(void)
+{
+ word used = GC_composite_in_use + GC_atomic_in_use;
+ word heap_sz = GC_heapsize - GC_unmapped_bytes;
+ return used >= heap_sz ? 0 : used < ((word)-1) / 100 ?
+ (int)((used * 100) / heap_sz) : (int)(used / (heap_sz / 100));
+}
+
/* Finish up a collection. Assumes mark bits are consistent, lock is */
/* held, but the world is otherwise running. */
STATIC void GC_finish_collection(void)
/* Reconstruct free lists to contain everything not marked */
GC_start_reclaim(FALSE);
- 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);
+ GC_DBGLOG_PRINTF("In-use heap: %d%% (%lu KiB pointers + %lu KiB other)\n",
+ GC_compute_heap_usage_percent(),
+ TO_KiB_UL(GC_composite_in_use),
+ TO_KiB_UL(GC_atomic_in_use));
if (GC_is_full_gc) {
GC_used_heap_size_after_full = USED_HEAP_SIZE;
GC_need_full_gc = FALSE;
WARN("Failed to expand heap by %" WARN_PRIdPTR " bytes\n", bytes);
return(FALSE);
}
- GC_INFOLOG_PRINTF(
- "Increasing heap size by %lu after %lu allocated bytes\n",
- (unsigned long)bytes, (unsigned long)GC_bytes_allocd);
+ GC_INFOLOG_PRINTF("Grow heap to %lu KiB after %lu bytes allocated\n",
+ TO_KiB_UL(GC_heapsize + 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. */
/* Write s to stderr, don't buffer, don't add */
/* newlines, don't ... */
+/* Handy macro for logging size values (of word type) in KiB (rounding */
+/* to nearest value). */
+#define TO_KiB_UL(v) ((unsigned long)(((v) + ((1 << 9) - 1)) >> 10))
+
GC_EXTERN unsigned GC_fail_count;
/* How many consecutive GC/expansion failures? */
/* Reset by GC_allochblk(); defined in alloc.c. */