From 765e61e391ee0937ff6b30510b6c4651064fe38e Mon Sep 17 00:00:00 2001 From: Dmitry Antipov Date: Fri, 20 Jul 2012 09:28:00 +0400 Subject: [PATCH] Cleanup calls to Fgarbage_collect. * lisp.h (maybe_gc): New prototype. (consing_since_gc, gc_relative_threshold, memory_full_cons_threshold): Remove declarations. * alloc.c (maybe_gc): New function. (consing_since_gc, gc_relative_threshold, memory_full_cons_threshold): Make them static. * bytecode.c (MAYBE_GC): Use maybe_gc. * eval.c (eval_sub, Ffuncall): Likewise. * keyboard.c (read_char): Likewise. Adjust call to maybe_gc to avoid dependency from auto-save feature. --- src/ChangeLog | 14 ++++++++++++++ src/alloc.c | 18 +++++++++++++++--- src/bytecode.c | 14 +++++--------- src/eval.c | 16 ++-------------- src/keyboard.c | 12 ++++-------- src/lisp.h | 9 +-------- 6 files changed, 41 insertions(+), 42 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index bed8e25ab7..909fb03c48 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,17 @@ +2012-07-20 Dmitry Antipov + + Cleanup calls to Fgarbage_collect. + * lisp.h (maybe_gc): New prototype. + (consing_since_gc, gc_relative_threshold, memory_full_cons_threshold): + Remove declarations. + * alloc.c (maybe_gc): New function. + (consing_since_gc, gc_relative_threshold, memory_full_cons_threshold): + Make them static. + * bytecode.c (MAYBE_GC): Use maybe_gc. + * eval.c (eval_sub, Ffuncall): Likewise. + * keyboard.c (read_char): Likewise. Adjust call to maybe_gc + to avoid dependency from auto-save feature. + 2012-07-19 Paul Eggert * buffer.h (FOR_EACH_BUFFER): Rename from 'for_each_buffer'. diff --git a/src/alloc.c b/src/alloc.c index 7158b45a34..36040f70b2 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -166,16 +166,16 @@ struct emacs_globals globals; /* Number of bytes of consing done since the last gc. */ -EMACS_INT consing_since_gc; +static EMACS_INT consing_since_gc; /* Similar minimum, computed from Vgc_cons_percentage. */ -EMACS_INT gc_relative_threshold; +static EMACS_INT gc_relative_threshold; /* Minimum number of bytes of consing since GC before next GC, when memory is full. */ -EMACS_INT memory_full_cons_threshold; +static EMACS_INT memory_full_cons_threshold; /* Nonzero during GC. */ @@ -5374,6 +5374,18 @@ bounded_number (EMACS_INT number) return make_number (min (MOST_POSITIVE_FIXNUM, number)); } +/* Check whether it's time for GC, and run it if so. */ + +void +maybe_gc (void) +{ + if ((consing_since_gc > gc_cons_threshold + && consing_since_gc > gc_relative_threshold) + || (!NILP (Vmemory_full) + && consing_since_gc > memory_full_cons_threshold)) + Fgarbage_collect (); +} + DEFUN ("garbage-collect", Fgarbage_collect, Sgarbage_collect, 0, 0, "", doc: /* Reclaim storage for Lisp objects no longer needed. Garbage collection happens automatically if you cons more than diff --git a/src/bytecode.c b/src/bytecode.c index acdf809971..dca1e552dd 100644 --- a/src/bytecode.c +++ b/src/bytecode.c @@ -423,15 +423,11 @@ unmark_byte_stack (void) /* Garbage collect if we have consed enough since the last time. We do this at every branch, to avoid loops that never GC. */ -#define MAYBE_GC() \ - do { \ - if (consing_since_gc > gc_cons_threshold \ - && consing_since_gc > gc_relative_threshold) \ - { \ - BEFORE_POTENTIAL_GC (); \ - Fgarbage_collect (); \ - AFTER_POTENTIAL_GC (); \ - } \ +#define MAYBE_GC() \ + do { \ + BEFORE_POTENTIAL_GC (); \ + maybe_gc (); \ + AFTER_POTENTIAL_GC (); \ } while (0) /* Check for jumping out of range. */ diff --git a/src/eval.c b/src/eval.c index da567e1e63..a0143c372d 100644 --- a/src/eval.c +++ b/src/eval.c @@ -2040,15 +2040,7 @@ eval_sub (Lisp_Object form) return form; QUIT; - if ((consing_since_gc > gc_cons_threshold - && consing_since_gc > gc_relative_threshold) - || - (!NILP (Vmemory_full) && consing_since_gc > memory_full_cons_threshold)) - { - GCPRO1 (form); - Fgarbage_collect (); - UNGCPRO; - } + maybe_gc (); if (++lisp_eval_depth > max_lisp_eval_depth) { @@ -2737,11 +2729,7 @@ usage: (funcall FUNCTION &rest ARGUMENTS) */) ptrdiff_t i; QUIT; - if ((consing_since_gc > gc_cons_threshold - && consing_since_gc > gc_relative_threshold) - || - (!NILP (Vmemory_full) && consing_since_gc > memory_full_cons_threshold)) - Fgarbage_collect (); + maybe_gc (); if (++lisp_eval_depth > max_lisp_eval_depth) { diff --git a/src/keyboard.c b/src/keyboard.c index 9f3bc47844..5e6dca64a9 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -2705,17 +2705,13 @@ read_char (int commandflag, ptrdiff_t nmaps, Lisp_Object *maps, && ! CONSP (Vunread_command_events)) { Fdo_auto_save (Qnil, Qnil); - - /* If we have auto-saved and there is still no input - available, garbage collect if there has been enough - consing going on to make it worthwhile. */ - if (!detect_input_pending_run_timers (0) - && consing_since_gc > gc_cons_threshold / 2) - Fgarbage_collect (); - redisplay (); } } + + /* If there is still no input available, ask for GC. */ + if (!detect_input_pending_run_timers (0)) + maybe_gc (); } /* Notify the caller if an autosave hook, or a timer, sentinel or diff --git a/src/lisp.h b/src/lisp.h index bfdc4ea4c0..471b8277b8 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -2091,14 +2091,6 @@ extern void process_quit_flag (void); extern Lisp_Object Vascii_downcase_table; extern Lisp_Object Vascii_canon_table; -/* Number of bytes of structure consed since last GC. */ - -extern EMACS_INT consing_since_gc; - -extern EMACS_INT gc_relative_threshold; - -extern EMACS_INT memory_full_cons_threshold; - /* Structure for recording stack slots that need marking. */ /* This is a chain of structures, each of which points at a Lisp_Object @@ -2601,6 +2593,7 @@ extern void mark_object (Lisp_Object); #if defined REL_ALLOC && !defined SYSTEM_MALLOC extern void refill_memory_reserve (void); #endif +extern void maybe_gc (void); extern const char *pending_malloc_warning; extern Lisp_Object zero_vector; extern Lisp_Object *stack_base; -- 2.20.1