From d0566445e2546a2e159a24e4e28c82bab648b786 Mon Sep 17 00:00:00 2001 From: Nikodemus Siivola Date: Thu, 2 Jun 2011 16:37:29 +0300 Subject: [PATCH] write heap exhaustion information to the GC logfile as well --- src/runtime/gencgc.c | 58 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 42 insertions(+), 16 deletions(-) diff --git a/src/runtime/gencgc.c b/src/runtime/gencgc.c index 972697c..1ea30b4 100644 --- a/src/runtime/gencgc.c +++ b/src/runtime/gencgc.c @@ -513,7 +513,29 @@ write_generation_stats(FILE *file) } extern void -print_generation_stats() +write_heap_exhaustion_report(FILE *file, long available, long requested, + struct thread *thread) +{ + fprintf(file, + "Heap exhausted during %s: %ld bytes available, %ld requested.\n", + gc_active_p ? "garbage collection" : "allocation", + available, + requested); + write_generation_stats(file); + fprintf(file, "GC control variables:\n"); + fprintf(file, " *GC-INHIBIT* = %s\n *GC-PENDING* = %s\n", + SymbolValue(GC_INHIBIT,thread)==NIL ? "false" : "true", + (SymbolValue(GC_PENDING, thread) == T) ? + "true" : ((SymbolValue(GC_PENDING, thread) == NIL) ? + "false" : "in progress")); +#ifdef LISP_FEATURE_SB_THREAD + fprintf(file, " *STOP-FOR-GC-PENDING* = %s\n", + SymbolValue(STOP_FOR_GC_PENDING,thread)==NIL ? "false" : "true"); +#endif +} + +extern void +print_generation_stats(void) { write_generation_stats(stderr); } @@ -531,11 +553,28 @@ log_generation_stats(char *logfile, char *header) write_generation_stats(log); fclose(log); } else { - fprintf(stderr, "Could not open gc logile: %s\n", gc_logfile); + fprintf(stderr, "Could not open gc logfile: %s\n", logfile); fflush(stderr); } } } + +extern void +report_heap_exhaustion(long available, long requested, struct thread *th) +{ + if (gc_logfile) { + FILE * log = fopen(gc_logfile, "a"); + if (log) { + write_heap_exhaustion_report(log, available, requested, th); + fclose(log); + } else { + fprintf(stderr, "Could not open gc logfile: %s\n", gc_logfile); + fflush(stderr); + } + } + /* Always to stderr as well. */ + write_heap_exhaustion_report(stderr, available, requested, th); +} #if defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64) @@ -1184,20 +1223,7 @@ gc_heap_exhausted_error_or_lose (long available, long requested) * the danger that we bounce back here before the error has been * handled, or indeed even printed. */ - fprintf(stderr, "Heap exhausted during %s: %ld bytes available, %ld requested.\n", - gc_active_p ? "garbage collection" : "allocation", - available, requested); - print_generation_stats(); - fprintf(stderr, "GC control variables:\n"); - fprintf(stderr, " *GC-INHIBIT* = %s\n *GC-PENDING* = %s\n", - SymbolValue(GC_INHIBIT,thread)==NIL ? "false" : "true", - (SymbolValue(GC_PENDING, thread) == T) ? - "true" : ((SymbolValue(GC_PENDING, thread) == NIL) ? - "false" : "in progress")); -#ifdef LISP_FEATURE_SB_THREAD - fprintf(stderr, " *STOP-FOR-GC-PENDING* = %s\n", - SymbolValue(STOP_FOR_GC_PENDING,thread)==NIL ? "false" : "true"); -#endif + report_heap_exhaustion(available, requested, thread); if (gc_active_p || (available == 0)) { /* If we are in GC, or totally out of memory there is no way * to sanely transfer control to the lisp-side of things. -- 1.7.10.4