Mercurial > hg > xemacs-beta
comparison src/alloc.c @ 887:ccc3177ef10b
[xemacs-hg @ 2002-06-28 14:21:41 by michaels]
2002-06-27 Mike Sperber <mike@xemacs.org>
* eval.c (Ffuncall): Run `post-gc-hook' if GC just happened.
* alloc.c (garbage_collect_1): Delay running `post-gc-hook' until later.
author | michaels |
---|---|
date | Fri, 28 Jun 2002 14:21:41 +0000 |
parents | 79c6ff3eef26 |
children | c925bacdda60 |
comparison
equal
deleted
inserted
replaced
886:011e1bce6ece | 887:ccc3177ef10b |
---|---|
94 | 94 |
95 /* Number of bytes of consing done since the last gc */ | 95 /* Number of bytes of consing done since the last gc */ |
96 static EMACS_INT consing_since_gc; | 96 static EMACS_INT consing_since_gc; |
97 int need_to_garbage_collect; | 97 int need_to_garbage_collect; |
98 int need_to_check_c_alloca; | 98 int need_to_check_c_alloca; |
99 int need_to_signal_post_gc; | |
99 int funcall_allocation_flag; | 100 int funcall_allocation_flag; |
100 Bytecount __temp_alloca_size__; | 101 Bytecount __temp_alloca_size__; |
101 Bytecount funcall_alloca_count; | 102 Bytecount funcall_alloca_count; |
102 | 103 |
103 /* Determine now whether we need to garbage collect or not, to make | 104 /* Determine now whether we need to garbage collect or not, to make |
3624 /* Very important to prevent GC during any of the following | 3625 /* Very important to prevent GC during any of the following |
3625 stuff that might run Lisp code; otherwise, we'll likely | 3626 stuff that might run Lisp code; otherwise, we'll likely |
3626 have infinite GC recursion. */ | 3627 have infinite GC recursion. */ |
3627 speccount = begin_gc_forbidden (); | 3628 speccount = begin_gc_forbidden (); |
3628 | 3629 |
3630 need_to_signal_post_gc = 0; | |
3631 recompute_funcall_allocation_flag(); | |
3632 | |
3629 if (!gc_hooks_inhibited) | 3633 if (!gc_hooks_inhibited) |
3630 run_hook_trapping_problems | 3634 run_hook_trapping_problems |
3631 ("Error in pre-gc-hook", Qpre_gc_hook, | 3635 ("Error in pre-gc-hook", Qpre_gc_hook, |
3632 INHIBIT_EXISTING_PERMANENT_DISPLAY_OBJECT_DELETION); | 3636 INHIBIT_EXISTING_PERMANENT_DISPLAY_OBJECT_DELETION); |
3633 | 3637 |
3768 a weak hash table might be unmarked, but after processing a later | 3772 a weak hash table might be unmarked, but after processing a later |
3769 weak hash table, the former one might get marked. So we have to | 3773 weak hash table, the former one might get marked. So we have to |
3770 iterate until nothing more gets marked. */ | 3774 iterate until nothing more gets marked. */ |
3771 | 3775 |
3772 while (finish_marking_weak_hash_tables () > 0 || | 3776 while (finish_marking_weak_hash_tables () > 0 || |
3773 finish_marking_weak_lists () > 0) | 3777 finish_marking_weak_lists () > 0 || |
3778 finish_marking_ephemerons () > 0) | |
3774 ; | 3779 ; |
3775 | 3780 |
3776 /* And prune (this needs to be called after everything else has been | 3781 /* And prune (this needs to be called after everything else has been |
3777 marked and before we do any sweeping). */ | 3782 marked and before we do any sweeping). */ |
3778 /* #### this is somewhat ad-hoc and should probably be an object | 3783 /* #### this is somewhat ad-hoc and should probably be an object |
3780 prune_weak_hash_tables (); | 3785 prune_weak_hash_tables (); |
3781 prune_weak_lists (); | 3786 prune_weak_lists (); |
3782 prune_specifiers (); | 3787 prune_specifiers (); |
3783 prune_syntax_tables (); | 3788 prune_syntax_tables (); |
3784 | 3789 |
3790 prune_ephemerons (); | |
3785 prune_weak_boxes (); | 3791 prune_weak_boxes (); |
3786 | 3792 |
3787 gc_sweep (); | 3793 gc_sweep (); |
3788 | 3794 |
3789 consing_since_gc = 0; | 3795 consing_since_gc = 0; |
3798 gc_in_progress = 0; | 3804 gc_in_progress = 0; |
3799 | 3805 |
3800 run_post_gc_actions (); | 3806 run_post_gc_actions (); |
3801 | 3807 |
3802 /******* End of garbage collection ********/ | 3808 /******* End of garbage collection ********/ |
3803 | |
3804 run_hook_trapping_problems | |
3805 ("Error in post-gc-hook", Qpost_gc_hook, | |
3806 INHIBIT_EXISTING_PERMANENT_DISPLAY_OBJECT_DELETION); | |
3807 | 3809 |
3808 /* Now remove the GC cursor/message */ | 3810 /* Now remove the GC cursor/message */ |
3809 if (!noninteractive) | 3811 if (!noninteractive) |
3810 { | 3812 { |
3811 if (cursor_changed) | 3813 if (cursor_changed) |
3835 { | 3837 { |
3836 breathing_space = malloc (4096 - MALLOC_OVERHEAD); | 3838 breathing_space = malloc (4096 - MALLOC_OVERHEAD); |
3837 } | 3839 } |
3838 | 3840 |
3839 UNGCPRO; | 3841 UNGCPRO; |
3842 | |
3843 need_to_signal_post_gc = 1; | |
3844 funcall_allocation_flag = 1; | |
3845 | |
3840 return; | 3846 return; |
3841 } | 3847 } |
3842 | 3848 |
3843 /* Debugging aids. */ | 3849 /* Debugging aids. */ |
3844 | 3850 |
4010 } | 4016 } |
4011 | 4017 |
4012 void | 4018 void |
4013 recompute_funcall_allocation_flag (void) | 4019 recompute_funcall_allocation_flag (void) |
4014 { | 4020 { |
4015 funcall_allocation_flag = need_to_garbage_collect || need_to_check_c_alloca; | 4021 funcall_allocation_flag = |
4022 need_to_garbage_collect || | |
4023 need_to_check_c_alloca || | |
4024 need_to_signal_post_gc; | |
4016 } | 4025 } |
4017 | 4026 |
4018 /* True if it's time to garbage collect now. */ | 4027 /* True if it's time to garbage collect now. */ |
4019 static void | 4028 static void |
4020 recompute_need_to_garbage_collect (void) | 4029 recompute_need_to_garbage_collect (void) |
4425 Vpre_gc_hook = Qnil; | 4434 Vpre_gc_hook = Qnil; |
4426 | 4435 |
4427 DEFVAR_LISP ("post-gc-hook", &Vpost_gc_hook /* | 4436 DEFVAR_LISP ("post-gc-hook", &Vpost_gc_hook /* |
4428 Function or functions to be run just after each garbage collection. | 4437 Function or functions to be run just after each garbage collection. |
4429 Interrupts, garbage collection, and errors are inhibited while this hook | 4438 Interrupts, garbage collection, and errors are inhibited while this hook |
4430 runs, so be extremely careful in what you add here. In particular, avoid | 4439 runs. Each hook is called with one argument which is an alist with |
4431 consing, and do not interact with the user. | 4440 finalization data. |
4432 */ ); | 4441 */ ); |
4433 Vpost_gc_hook = Qnil; | 4442 Vpost_gc_hook = Qnil; |
4434 | 4443 |
4435 DEFVAR_LISP ("gc-message", &Vgc_message /* | 4444 DEFVAR_LISP ("gc-message", &Vgc_message /* |
4436 String to print to indicate that a garbage collection is in progress. | 4445 String to print to indicate that a garbage collection is in progress. |