Mercurial > emacs
comparison src/alloc.c @ 49529:fd79b3081e01
(Vgc_elapsed, gcs_done): New variables.
(Fgarbage_collect): Use them.
(init_alloc, syms_of_alloc): Set them up.
| author | Dave Love <fx@gnu.org> |
|---|---|
| date | Thu, 30 Jan 2003 14:15:58 +0000 |
| parents | 668c96afa702 |
| children | 23a1cea22d13 |
comparison
equal
deleted
inserted
replaced
| 49528:bbee23d72342 | 49529:fd79b3081e01 |
|---|---|
| 253 Lisp_Object Qgc_cons_threshold, Qchar_table_extra_slots; | 253 Lisp_Object Qgc_cons_threshold, Qchar_table_extra_slots; |
| 254 | 254 |
| 255 /* Hook run after GC has finished. */ | 255 /* Hook run after GC has finished. */ |
| 256 | 256 |
| 257 Lisp_Object Vpost_gc_hook, Qpost_gc_hook; | 257 Lisp_Object Vpost_gc_hook, Qpost_gc_hook; |
| 258 | |
| 259 Lisp_Object Vgc_elapsed; /* accumulated elapsed time in GC */ | |
| 260 EMACS_INT gcs_done; /* accumulated GCs */ | |
| 258 | 261 |
| 259 static void mark_buffer P_ ((Lisp_Object)); | 262 static void mark_buffer P_ ((Lisp_Object)); |
| 260 static void mark_kboards P_ ((void)); | 263 static void mark_kboards P_ ((void)); |
| 261 static void gc_sweep P_ ((void)); | 264 static void gc_sweep P_ ((void)); |
| 262 static void mark_glyph_matrix P_ ((struct glyph_matrix *)); | 265 static void mark_glyph_matrix P_ ((struct glyph_matrix *)); |
| 643 This only works with GNU malloc. To help out systems which can't | 646 This only works with GNU malloc. To help out systems which can't |
| 644 use GNU malloc, all the calls to malloc, realloc, and free | 647 use GNU malloc, all the calls to malloc, realloc, and free |
| 645 elsewhere in the code should be inside a BLOCK_INPUT/UNBLOCK_INPUT | 648 elsewhere in the code should be inside a BLOCK_INPUT/UNBLOCK_INPUT |
| 646 pairs; unfortunately, we have no idea what C library functions | 649 pairs; unfortunately, we have no idea what C library functions |
| 647 might call malloc, so we can't really protect them unless you're | 650 might call malloc, so we can't really protect them unless you're |
| 648 using GNU malloc. Fortunately, most of the major operating can use | 651 using GNU malloc. Fortunately, most of the major operating systems |
| 649 GNU malloc. */ | 652 can use GNU malloc. */ |
| 650 | 653 |
| 651 #ifndef SYSTEM_MALLOC | 654 #ifndef SYSTEM_MALLOC |
| 652 #ifndef DOUG_LEA_MALLOC | 655 #ifndef DOUG_LEA_MALLOC |
| 653 extern void * (*__malloc_hook) P_ ((size_t)); | 656 extern void * (*__malloc_hook) P_ ((size_t)); |
| 654 extern void * (*__realloc_hook) P_ ((void *, size_t)); | 657 extern void * (*__realloc_hook) P_ ((void *, size_t)); |
| 1234 && nbytes != SDATA_NBYTES (SDATA_OF_STRING (s))) | 1237 && nbytes != SDATA_NBYTES (SDATA_OF_STRING (s))) |
| 1235 abort (); | 1238 abort (); |
| 1236 return nbytes; | 1239 return nbytes; |
| 1237 } | 1240 } |
| 1238 | 1241 |
| 1239 /* Check validity Lisp strings' string_bytes member in B. */ | 1242 /* Check validity of Lisp strings' string_bytes member in B. */ |
| 1240 | 1243 |
| 1241 void | 1244 void |
| 1242 check_sblock (b) | 1245 check_sblock (b) |
| 1243 struct sblock *b; | 1246 struct sblock *b; |
| 1244 { | 1247 { |
| 4083 char stack_top_variable; | 4086 char stack_top_variable; |
| 4084 register int i; | 4087 register int i; |
| 4085 int message_p; | 4088 int message_p; |
| 4086 Lisp_Object total[8]; | 4089 Lisp_Object total[8]; |
| 4087 int count = SPECPDL_INDEX (); | 4090 int count = SPECPDL_INDEX (); |
| 4091 EMACS_TIME t1, t2, t3; | |
| 4092 | |
| 4093 EMACS_GET_TIME (t1); | |
| 4088 | 4094 |
| 4089 /* Can't GC if pure storage overflowed because we can't determine | 4095 /* Can't GC if pure storage overflowed because we can't determine |
| 4090 if something is a pure object or not. */ | 4096 if something is a pure object or not. */ |
| 4091 if (pure_bytes_used_before_overflow) | 4097 if (pure_bytes_used_before_overflow) |
| 4092 return Qnil; | 4098 return Qnil; |
| 4368 { | 4374 { |
| 4369 int count = inhibit_garbage_collection (); | 4375 int count = inhibit_garbage_collection (); |
| 4370 safe_run_hooks (Qpost_gc_hook); | 4376 safe_run_hooks (Qpost_gc_hook); |
| 4371 unbind_to (count, Qnil); | 4377 unbind_to (count, Qnil); |
| 4372 } | 4378 } |
| 4373 | 4379 |
| 4380 /* Accumulate statistics. */ | |
| 4381 EMACS_GET_TIME (t2); | |
| 4382 EMACS_SUB_TIME (t3, t2, t1); | |
| 4383 if (FLOATP (Vgc_elapsed)) | |
| 4384 XSETFLOAT (Vgc_elapsed, make_float (XFLOAT_DATA (Vgc_elapsed) + | |
| 4385 EMACS_SECS (t3) + | |
| 4386 EMACS_USECS (t3) * 1.0e-6)); | |
| 4387 gcs_done++; | |
| 4388 | |
| 4374 return Flist (sizeof total / sizeof *total, total); | 4389 return Flist (sizeof total / sizeof *total, total); |
| 4375 } | 4390 } |
| 4376 | 4391 |
| 4377 | 4392 |
| 4378 /* Mark Lisp objects in glyph matrix MATRIX. Currently the | 4393 /* Mark Lisp objects in glyph matrix MATRIX. Currently the |
| 5523 #if GC_MARK_STACK | 5538 #if GC_MARK_STACK |
| 5524 #if !defined GC_SAVE_REGISTERS_ON_STACK && !defined GC_SETJMP_WORKS | 5539 #if !defined GC_SAVE_REGISTERS_ON_STACK && !defined GC_SETJMP_WORKS |
| 5525 setjmp_tested_p = longjmps_done = 0; | 5540 setjmp_tested_p = longjmps_done = 0; |
| 5526 #endif | 5541 #endif |
| 5527 #endif | 5542 #endif |
| 5543 Vgc_elapsed = make_float (0.0); | |
| 5544 gcs_done = 0; | |
| 5528 } | 5545 } |
| 5529 | 5546 |
| 5530 void | 5547 void |
| 5531 syms_of_alloc () | 5548 syms_of_alloc () |
| 5532 { | 5549 { |
| 5611 staticpro (&Qgc_cons_threshold); | 5628 staticpro (&Qgc_cons_threshold); |
| 5612 Qgc_cons_threshold = intern ("gc-cons-threshold"); | 5629 Qgc_cons_threshold = intern ("gc-cons-threshold"); |
| 5613 | 5630 |
| 5614 staticpro (&Qchar_table_extra_slots); | 5631 staticpro (&Qchar_table_extra_slots); |
| 5615 Qchar_table_extra_slots = intern ("char-table-extra-slots"); | 5632 Qchar_table_extra_slots = intern ("char-table-extra-slots"); |
| 5633 | |
| 5634 DEFVAR_LISP ("gc-elapsed", &Vgc_elapsed, | |
| 5635 doc: /* Accumulated time elapsed in garbage collections. | |
| 5636 The time is in seconds as a floating point value. | |
| 5637 Programs may reset this to get statistics in a specific period. */); | |
| 5638 DEFVAR_INT ("gcs-done", &gcs_done, | |
| 5639 doc: /* Accumulated number of garbage collections done. | |
| 5640 Programs may reset this to get statistics in a specific period. */); | |
| 5616 | 5641 |
| 5617 defsubr (&Scons); | 5642 defsubr (&Scons); |
| 5618 defsubr (&Slist); | 5643 defsubr (&Slist); |
| 5619 defsubr (&Svector); | 5644 defsubr (&Svector); |
| 5620 defsubr (&Smake_byte_code); | 5645 defsubr (&Smake_byte_code); |
