# HG changeset patch # User stephent # Date 1128444430 0 # Node ID fb22a4eb2694fe1dd60f9184a661282716bc0f4a # Parent adda8fccb13d0185dfbe0b3a039ac9ef8aac9349 [xemacs-hg @ 2005-10-04 16:47:10 by stephent] undo accidental commit diff -r adda8fccb13d -r fb22a4eb2694 src/alloc.c --- a/src/alloc.c Tue Oct 04 16:43:38 2005 +0000 +++ b/src/alloc.c Tue Oct 04 16:47:10 2005 +0000 @@ -1,7 +1,7 @@ /* Storage allocation and gc for XEmacs Lisp interpreter. Copyright (C) 1985-1998 Free Software Foundation, Inc. Copyright (C) 1995 Sun Microsystems, Inc. - Copyright (C) 1995, 1996, 2001, 2002, 2003, 2004, 2005 Ben Wing. + Copyright (C) 1995, 1996, 2001, 2002, 2003, 2004 Ben Wing. This file is part of XEmacs. @@ -94,8 +94,6 @@ /* Number of bytes of consing done since the last gc */ static EMACS_INT consing_since_gc; EMACS_UINT total_consing; -EMACS_INT total_gc_usage; -int total_gc_usage_set; int need_to_garbage_collect; int need_to_check_c_alloca; @@ -5527,13 +5525,13 @@ } { - struct catchtag *c; - for (c = catchlist; c; c = c->next) + struct catchtag *catch; + for (catch = catchlist; catch; catch = catch->next) { - mark_object (c->tag); - mark_object (c->val); - mark_object (c->actual_tag); - mark_object (c->backtrace); + mark_object (catch->tag); + mark_object (catch->val); + mark_object (catch->actual_tag); + mark_object (catch->backtrace); } } @@ -5771,7 +5769,7 @@ /* Debugging aids. */ static Lisp_Object -gc_plist_hack (const Ascbyte *name, EMACS_INT value, Lisp_Object tail) +gc_plist_hack (const Ascbyte *name, int value, Lisp_Object tail) { /* C doesn't have local functions (or closures, or GC, or readable syntax, or portable numeric datatypes, or bit-vectors, or characters, or @@ -5780,10 +5778,9 @@ } #define HACK_O_MATIC(type, name, pl) do { \ - EMACS_INT s = 0; \ + int s = 0; \ struct type##_block *x = current_##type##_block; \ while (x) { s += sizeof (*x) + MALLOC_OVERHEAD; x = x->prev; } \ - object_usage += s; \ (pl) = gc_plist_hack ((name), s, (pl)); \ } while (0) @@ -5803,11 +5800,8 @@ Lisp_Object pl = Qnil; int i; int gc_count_vector_total_size = 0; - EMACS_INT object_usage = 0; - garbage_collect_1 (); - for (i = 0; i < lrecord_type_count; i++) { if (lcrecord_stats[i].bytes_in_use != 0 @@ -5824,7 +5818,6 @@ sprintf (buf, "%s-storage", name); pl = gc_plist_hack (buf, lcrecord_stats[i].bytes_in_use, pl); - object_usage += lcrecord_stats[i].bytes_in_use; /* Okay, simple pluralization check for `symbol-value-varalias' */ if (name[len-1] == 's') sprintf (buf, "%ses-freed", name); @@ -5902,10 +5895,6 @@ pl = gc_plist_hack ("conses-free", gc_count_num_cons_freelist, pl); pl = gc_plist_hack ("conses-used", gc_count_num_cons_in_use, pl); - /* Record total usage for purposes of determining next GC */ - total_gc_usage = object_usage; - total_gc_usage_set = 1; - /* The things we do for backwards-compatibility */ return list6 (Fcons (make_int (gc_count_num_cons_in_use), @@ -5945,29 +5934,15 @@ } #endif -DEFUN ("total-memory-usage", Ftotal_memory_usage, 0, 0, 0, /* +DEFUN ("memory-usage", Fmemory_usage, 0, 0, 0, /* Return the total number of bytes used by the data segment in XEmacs. This may be helpful in debugging XEmacs's memory usage. -NOTE: This may or may not be accurate! It is hard to determine this -value in a system-independent fashion. */ ()) { return make_int (total_data_usage ()); } -DEFUN ("lisp-object-memory-usage", Flisp_object_memory_usage, 0, 0, 0, /* -Return the total number of bytes used for object storage in XEmacs. -This may be helpful in debugging XEmacs's memory usage. -This value is only recomputed when garbage collection happens; thus, a -better value of the real number of bytes used is - (+ (lisp-object-memory-usage) (consing-since-gc)) -*/ - ()) -{ - return make_int (total_gc_usage); -} - void recompute_funcall_allocation_flag (void) { @@ -5986,15 +5961,11 @@ else need_to_garbage_collect = (consing_since_gc > gc_cons_threshold +#if 0 /* #### implement this better */ && -#if 0 /* #### implement this better */ (100 * consing_since_gc) / total_data_usage () >= gc_cons_percentage -#else - (!total_gc_usage_set || - (100 * consing_since_gc) / total_gc_usage >= - gc_cons_percentage) -#endif +#endif /* 0 */ ); recompute_funcall_allocation_flag (); } @@ -6249,8 +6220,9 @@ #else gc_cons_threshold = 15000; /* debugging */ #endif - gc_cons_percentage = 40; /* #### what is optimal? */ - total_gc_usage_set = 0; + gc_cons_percentage = 0; /* #### 20; Don't have an accurate measure of + memory usage on Windows; not verified on other + systems */ lrecord_uid_counter = 259; #ifndef MC_ALLOC debug_string_purity = 0; @@ -6382,8 +6354,7 @@ #if 0 DEFSUBR (Fmemory_limit); #endif - DEFSUBR (Ftotal_memory_usage); - DEFSUBR (Flisp_object_memory_usage); + DEFSUBR (Fmemory_usage); DEFSUBR (Fconsing_since_gc); } @@ -6415,22 +6386,26 @@ will be unusable! You almost certainly won't have the patience to wait long enough to be able to set it back. -See also `consing-since-gc' and `gc-cons-percentage'. +See also `consing-since-gc'. */ ); DEFVAR_INT ("gc-cons-percentage", &gc_cons_percentage /* *Percentage of memory allocated between garbage collections. Garbage collection will happen if this percentage of the total amount of -memory used for data (see `lisp-object-memory-usage') has been allocated -since the last garbage collection. However, it will not happen if less -than `gc-cons-threshold' bytes have been allocated -- this sets an absolute -minimum in case very little data has been allocated or the percentage is -set very low. Set this to 0 to have garbage collection always happen after -`gc-cons-threshold' bytes have been allocated, regardless of current memory -usage. - -See also `consing-since-gc' and `gc-cons-threshold'. +memory used for data has been allocated since the last garbage collection. +However, it will not happen if less than `gc-cons-threshold' bytes have +been allocated -- this sets an absolute minimum in case very little data +has been allocated or the percentage is set very low. Set this to 0 to +have garbage collection always happen after `gc-cons-threshold' bytes have +been allocated, regardless of current memory usage. + +Garbage collection happens automatically when `eval' or `funcall' are +called. (Note that `funcall' is called implicitly as part of evaluation.) +By binding this temporarily to a large number, you can effectively +prevent garbage collection during a part of the program. + +See also `consing-since-gc'. */ ); #ifdef DEBUG_XEMACS