Mercurial > hg > xemacs-beta
annotate src/profile.h @ 5169:6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
-------------------- ChangeLog entries follow: --------------------
src/ChangeLog addition:
2010-03-24 Ben Wing <ben@xemacs.org>
* array.h:
* array.h (XD_LISP_DYNARR_DESC):
* dumper.c (pdump_register_sub):
* dumper.c (pdump_store_new_pointer_offsets):
* dumper.c (pdump_reloc_one_mc):
* elhash.c:
* gc.c (lispdesc_one_description_line_size):
* gc.c (kkcc_marking):
* lrecord.h:
* lrecord.h (IF_NEW_GC):
* lrecord.h (enum memory_description_type):
* lrecord.h (enum data_description_entry_flags):
* lrecord.h (struct opaque_convert_functions):
Rename XD_LISP_OBJECT_BLOCK_PTR to XD_INLINE_LISP_OBJECT_BLOCK_PTR
and document it in lrecord.h.
* data.c:
* data.c (finish_marking_weak_lists):
* data.c (continue_marking_ephemerons):
* data.c (finish_marking_ephemerons):
* elhash.c (MARK_OBJ):
* gc.c:
* gc.c (lispdesc_indirect_count_1):
* gc.c (struct):
* gc.c (kkcc_bt_push):
* gc.c (kkcc_gc_stack_push):
* gc.c (kkcc_gc_stack_push_lisp_object):
* gc.c (kkcc_gc_stack_repush_dirty_object):
* gc.c (KKCC_DO_CHECK_FREE):
* gc.c (mark_object_maybe_checking_free):
* gc.c (mark_struct_contents):
* gc.c (mark_lisp_object_block_contents):
* gc.c (register_for_finalization):
* gc.c (mark_object):
* gc.h:
* lisp.h:
* profile.c:
* profile.c (mark_profiling_info_maphash):
Clean up KKCC code related to DEBUG_XEMACS. Rename
kkcc_backtrace() to kkcc_backtrace_1() and add two params: a
`size' arg to control how many stack elements to print and a
`detailed' arg to control whether Lisp objects are printed using
`debug_print()'. Create front-ends to kkcc_backtrace_1() --
kkcc_detailed_backtrace(), kkcc_short_backtrace(),
kkcc_detailed_backtrace_full(), kkcc_short_backtrace_full(), as
well as shortened versions kbt(), kbts(), kbtf(), kbtsf() -- to
call it with various parameter values. Add an `is_lisp' field to
the stack and backtrace structures and use it to keep track of
whether an object pushed onto the stack is a Lisp object or a
non-Lisp structure; in kkcc_backtrace_1(), don't try to print a
non-Lisp structure as a Lisp object.
* elhash.c:
* extents.c:
* file-coding.c:
* lrecord.h:
* lrecord.h (IF_NEW_GC):
* marker.c:
* marker.c (Fmarker_buffer):
* mule-coding.c:
* number.c:
* rangetab.c:
* specifier.c:
New macros IF_OLD_GC(), IF_NEW_GC() to simplify declaration of
Lisp objects when a finalizer may exist in one but not the other.
Use them appropriately.
* extents.c (finalize_extent_info):
Don't zero out data->soe and data->extents before trying to free,
else we get memory leaks.
* lrecord.h (enum lrecord_type):
Make the first lrecord type have value 1 not 0 so that 0 remains
without implementation and attempts to interpret zeroed memory
as a Lisp object will be more obvious.
* array.c (Dynarr_free):
* device-msw.c (msprinter_delete_device):
* device-tty.c (free_tty_device_struct):
* device-tty.c (tty_delete_device):
* dialog-msw.c (handle_directory_dialog_box):
* dialog-x.c:
* emacs.c (free_argc_argv):
* emodules.c (attempt_module_delete):
* file-coding.c (chain_finalize_coding_stream_1):
* file-coding.c (chain_finalize_coding_stream):
* glyphs-eimage.c:
* glyphs-eimage.c (jpeg_instantiate_unwind):
* glyphs-eimage.c (gif_instantiate_unwind):
* glyphs-eimage.c (png_instantiate_unwind):
* glyphs-eimage.c (tiff_instantiate_unwind):
* imgproc.c:
* imgproc.c (build_EImage_quantable):
* insdel.c (uninit_buffer_text):
* mule-coding.c (iso2022_finalize_detection_state):
* objects-tty.c (tty_finalize_color_instance):
* objects-tty.c (tty_finalize_font_instance):
* objects-tty.c (tty_font_list):
* process.c:
* process.c (finalize_process):
* redisplay.c (add_propagation_runes):
* scrollbar-gtk.c:
* scrollbar-gtk.c (gtk_free_scrollbar_instance):
* scrollbar-gtk.c (gtk_release_scrollbar_instance):
* scrollbar-msw.c:
* scrollbar-msw.c (mswindows_free_scrollbar_instance):
* scrollbar-msw.c (unshow_that_mofo):
* scrollbar-x.c (x_free_scrollbar_instance):
* scrollbar-x.c (x_release_scrollbar_instance):
* select-x.c:
* select-x.c (x_handle_selection_request):
* syntax.c:
* syntax.c (uninit_buffer_syntax_cache):
* text.h (eifree):
If possible, whenever we call xfree() on a field in a structure,
set the field to 0 afterwards. A lot of code is written so that
it checks the value being freed to see if it is non-zero before
freeing it -- doing this and setting the value to 0 afterwards
ensures (a) we won't try to free twice if the cleanup code is
called twice; (b) if the object itself stays around, KKCC won't
crash when attempting to mark the freed field.
* rangetab.c:
Add a finalization method when not NEW_GC to avoid memory leaks.
(#### We still get memory leaks when NEW_GC; need to convert gap
array to Lisp object).
author | Ben Wing <ben@xemacs.org> |
---|---|
date | Wed, 24 Mar 2010 01:22:51 -0500 |
parents | 8f6a825eb3d3 |
children | 308d34e9f07d |
rev | line source |
---|---|
1292 | 1 /* Profiling. |
3025 | 2 Copyright (C) 2003, 2005 Ben Wing. |
1292 | 3 |
4 This file is part of XEmacs. | |
5 | |
6 XEmacs is free software; you can redistribute it and/or modify it | |
7 under the terms of the GNU General Public License as published by the | |
8 Free Software Foundation; either version 2, or (at your option) any | |
9 later version. | |
10 | |
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
14 for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
17 along with XEmacs; see the file COPYING. If not, write to | |
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
19 Boston, MA 02111-1307, USA. */ | |
20 | |
21 /* Synched up with: Not in FSF. */ | |
22 | |
23 /* Authorship: | |
24 | |
25 Ben Wing: Feb 2003. | |
26 */ | |
27 | |
28 #include "backtrace.h" | |
29 | |
30 void mark_profiling_info (void); | |
31 void profile_record_unwind (struct backtrace *); | |
32 void profile_record_about_to_call (struct backtrace *); | |
33 void profile_record_just_called (struct backtrace *); | |
34 void profile_record_consing (EMACS_INT size); | |
35 void profile_record_unconsing (EMACS_INT size); | |
36 extern int profiling_active; | |
37 | |
38 /* We call about_to_call() and just_called() depending on the current | |
39 *dynamic* value of profiling_active (which could change as a result of | |
40 calling the function) but if we push a backtrace, we must pop it later, | |
41 so we need to remember the status of this. */ | |
42 #define PROFILE_DECLARE() \ | |
43 int do_backtrace = profiling_active || backtrace_with_internal_sections; \ | |
44 struct backtrace backtrace | |
45 | |
46 /* As just mentioned, we rely on the dynamic value of profiling_active. | |
47 This ensures correct behavior (e.g. we never modify the profiling info | |
48 when profiling is not active) because we seed and reap all functions | |
49 currently on the stack when starting and stopping. See | |
4162 | 50 `start-profiling'. |
51 | |
52 We check do_backtrace to make sure that the backtrace structure is | |
53 initialised. If it isn't, we can enter a function with profiling turned | |
54 off, and exit it with it turned on, with the consequence that an | |
55 unitialised backtrace structure is passed to | |
56 profile_record_just_called. Since do_backtrace is function-local (apart | |
57 from in the garbage collector) this avoids that. */ | |
1292 | 58 #define PROFILE_ENTER_FUNCTION() \ |
59 do \ | |
60 { \ | |
4162 | 61 if (profiling_active && do_backtrace) \ |
1292 | 62 profile_record_about_to_call (&backtrace); \ |
63 } \ | |
64 while (0) | |
65 | |
66 #define PROFILE_EXIT_FUNCTION() \ | |
67 do \ | |
68 { \ | |
4162 | 69 if (profiling_active && do_backtrace) \ |
1292 | 70 profile_record_just_called (&backtrace); \ |
71 } \ | |
72 while (0) | |
73 | |
74 /* We are entering a section that we would like to record profile information | |
75 about. We put this information into the backtrace list, just like | |
76 normal functions do. That is one easy way to make sure that we always | |
77 record info on the innermost section or function, whether section or | |
78 function. (To do this, we always need some sort of collusion between | |
79 profile and eval; this is one way.) */ | |
80 | |
3025 | 81 /* Or, we could call xzero() to zero the whole thing, and avoid four |
82 of the statements below; or we could create a global backtrace object, | |
83 uninitialized (i.e. it will be initialized to all 0), and do structure | |
84 copy to initialize. It's not clear it will make much difference here, | |
85 but someone who really cared about counting cycles could implement it. */ | |
1292 | 86 #define PROFILE_RECORD_ENTERING_SECTION(var) \ |
87 do \ | |
88 { \ | |
89 if (do_backtrace) \ | |
90 { \ | |
91 backtrace.function = &var; \ | |
92 backtrace.args = NULL; \ | |
93 backtrace.nargs = UNEVALLED; \ | |
94 backtrace.evalargs = 0; \ | |
95 backtrace.pdlcount = specpdl_depth (); \ | |
96 backtrace.debug_on_exit = 0; \ | |
97 backtrace.function_being_called = 0; \ | |
98 PUSH_BACKTRACE (backtrace); \ | |
99 } \ | |
100 PROFILE_ENTER_FUNCTION (); \ | |
101 } while (0) | |
102 | |
103 #define PROFILE_RECORD_EXITING_SECTION(var) \ | |
104 do \ | |
105 { \ | |
106 PROFILE_EXIT_FUNCTION (); \ | |
107 if (do_backtrace) \ | |
108 POP_BACKTRACE (backtrace); \ | |
109 } while (0) | |
2514 | 110 |
111 #define RETURN_EXIT_PROFILING(tag, type, expr) \ | |
112 do \ | |
113 { \ | |
114 type _ret_exitpr_ = (expr); \ | |
115 PROFILE_RECORD_EXITING_SECTION (tag); \ | |
116 RETURN_SANS_WARNINGS _ret_exitpr_; \ | |
117 } while (0) | |
118 | |
119 #define RETURN_LISP_EXIT_PROFILING(tag, expr) \ | |
120 RETURN_EXIT_PROFILING (tag, Lisp_Object, expr) | |
121 | |
122 #define RETURN_UNGCPRO_EXIT_PROFILING(tag, expr) \ | |
3282 | 123 do \ |
2514 | 124 { \ |
125 Lisp_Object ret_ungc_val = (expr); \ | |
126 UNGCPRO; \ | |
127 PROFILE_RECORD_EXITING_SECTION (tag); \ | |
128 RETURN_SANS_WARNINGS ret_ungc_val; \ | |
129 } while (0) | |
130 | |
131 #ifdef DEBUG_XEMACS | |
132 extern Lisp_Object QSin_temp_spot_1; | |
133 extern Lisp_Object QSin_temp_spot_2; | |
134 extern Lisp_Object QSin_temp_spot_3; | |
135 extern Lisp_Object QSin_temp_spot_4; | |
136 extern Lisp_Object QSin_temp_spot_5; | |
137 #endif /* DEBUG_XEMACS */ |