2 @c This is part of the SXEmacs Lisp Reference Manual.
3 @c Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
4 @c Copyright (C) 2005 Sebastian Freundt <hroptatyr@sxemacs.org>
5 @c See the file lispref.texi for copying conditions.
6 @setfilename ../../info/building.info
8 @node Building SXEmacs and Object Allocation, Standard Errors, Tips, Top
9 @appendix Building SXEmacs; Allocation of Objects
11 This chapter describes how the runnable SXEmacs executable is dumped
12 with the preloaded Lisp libraries in it and how storage is allocated.
14 There is an entire separate document, the @cite{SXEmacs Internals
15 Manual}, devoted to the internals of SXEmacs from the perspective of the
16 C programmer. It contains much more detailed information about the
17 build process, the allocation and garbage-collection process, and other
18 aspects related to the internals of SXEmacs.
21 * Building SXEmacs:: How to preload Lisp libraries into SXEmacs.
22 * Garbage Collection:: Reclaiming space for Lisp objects no longer used.
26 @node Building SXEmacs
27 @appendixsec Building SXEmacs
28 @cindex building SXEmacs
31 This section explains the steps involved in building the SXEmacs
32 executable. You do not have to know this material to build and install
33 SXEmacs, since the makefiles do all these things automatically. This
34 information is pertinent to SXEmacs maintenance.
36 The @cite{SXEmacs Internals Manual} contains more information about this.
38 Compilation of the C source files in the @file{src} directory
39 produces an executable file called @file{temacs}, also called a
40 @dfn{bare impure SXEmacs}. It contains the SXEmacs Lisp interpreter and
41 I/O routines, but not the editing commands.
43 @cindex @file{loadup.el}
44 Before SXEmacs is actually usable, a number of Lisp files need to be
45 loaded. These define all the editing commands, plus most of the startup
46 code and many very basic Lisp primitives. This is accomplished by
47 loading the file @file{loadup.el}, which in turn loads all of the other
48 standardly-loaded Lisp files.
50 It takes a substantial time to load the standard Lisp files. Luckily,
51 you don't have to do this each time you run SXEmacs; @file{temacs} can
52 dynamically dump out an executable program called @file{sxemacs} that
53 has these files preloaded. In fact, this is actually all what
54 @file{temacs} can do and does.
56 The resulting file @file{sxemacs} starts more quickly because it does
57 not need to load the files. This is the SXEmacs executable that is
60 To create @file{sxemacs}, use the command @samp{temacs -batch -l loadup
61 dump}. The purpose of @samp{-batch} here is to tell @file{temacs} to run
62 in non-interactive, command-line mode. @file{temacs} can @emph{only}
63 run in this fashion. Part of the code required to initialize frames and
64 faces is in Lisp, and must be loaded before SXEmacs is able to create
65 any frames. The argument @samp{dump} tells @file{loadup.el} to dump a
66 new executable named @file{sxemacs}.
68 Note: The dumping process is highly system-specific, and some operating
69 systems do not support dumping. On those systems, you must start
70 SXEmacs with the @samp{temacs -batch -l loadup run-temacs} command each
71 time you use it. This takes a substantial time, but since you need to
72 start SXEmacs once a day at most---or once a week if you never log
73 out---the extra time is not too severe a problem.
75 @cindex runnable @file{temacs}
76 @cindex bootstrapping SXEmacs from @file{temacs}
77 You are free to start SXEmacs directly from @file{temacs} if you want,
78 even if there is already a dumped @file{sxemacs}. Normally you wouldn't
79 want to do that; but the Makefiles do this when you rebuild SXEmacs using
80 @samp{make all-elc}, which builds SXEmacs and simultaneously compiles any
81 out-of-date Lisp files.
83 You need @file{temacs} in order to compile Lisp files. However, you
84 also need the compiled Lisp files in order to dump out
85 @file{sxemacs}. If both of these are missing or corrupted, you are
86 out of luck unless you're able to bootstrap @file{sxemacs} from
87 @file{temacs}. Note that @samp{make all-elc} actually loads the
88 alternative loadup file @file{loadup-el.el}, which works like
89 @file{loadup.el} but disables the pure-copying process and forces
90 SXEmacs to ignore any compiled Lisp files even if they exist.
92 @cindex @file{site-load.el}
93 You can specify additional files to preload by writing a library named
94 @file{site-load.el} that loads them. You may need to increase the value
95 of @code{PURESIZE}, in @file{src/puresize.h}, to make room for the
96 additional files. You should @emph{not} modify this file directly,
97 however; instead, use the @samp{--puresize} configuration option. If
98 you run out of pure space while dumping @file{sxemacs}, you will be told
99 how much pure space you actually will need. However, the advantage of
100 preloading additional files decreases as machines get faster. On modern
101 machines, it is often not advisable, especially if the Lisp code is
102 on a file system local to the machine running SXEmacs.
104 @cindex @file{site-init.el}
105 You can specify other Lisp expressions to execute just before dumping
106 by putting them in a library named @file{site-init.el}. However, if
107 they might alter the behavior that users expect from an ordinary
108 unmodified SXEmacs, it is better to put them in @file{default.el}, so
109 that users can override them if they wish. @xref{Start-up Summary}.
111 Before @file{loadup.el} dumps the new executable, it finds the
112 documentation strings for primitive and preloaded functions (and
113 variables) in the file where they are stored, by calling
114 @code{Snarf-documentation} (@pxref{Accessing Documentation}). These
115 strings were moved out of the @file{sxemacs} executable to make it
116 smaller. @xref{Documentation Basics}.
118 @defun dump-emacs to-file from-file
120 This function dumps the current state of SXEmacs into an executable file
121 @var{to-file}. It takes symbols from @var{from-file} (this is normally
122 the executable file @file{temacs}).
124 If you use this function in an SXEmacs that was already dumped, you must
125 set @code{command-line-processed} to @code{nil} first for good results.
126 @xref{Command Line Arguments}.
129 @defun run-emacs-from-temacs &rest args
130 This is the function that implements the @file{run-temacs} command-line
131 argument. It is called from @file{loadup.el} as appropriate. You should
132 most emphatically @emph{not} call this yourself; it will reinitialize
133 your SXEmacs process and you'll be sorry.
136 @deffn Command emacs-version &optional arg
137 This function returns a string describing the version of SXEmacs that is
138 running. It is useful to include this string in bug reports.
140 When called interactively with a prefix argument, insert string at point.
141 Don't use this function in programs to choose actions according
142 to the system configuration; look at @code{system-configuration} instead.
147 @result{} "SXEmacs: hroptatyr@@sxemacs.org--sxemacs/sxemacs--hrop--22.1.2--patch-15,
148 built Fri Apr 29 18:44:05 2005 on marlin.math.tu-berlin.de"
152 Called interactively, the function prints the same information in the
156 @defvar emacs-build-time
157 The value of this variable is the time at which SXEmacs was built at the
163 @result{} "Fri Apr 29 18:44:05 2005"
168 @defvar emacs-version
169 The value of this variable is the version of Emacs being run. It is a string,
170 e.g. @code{"hroptatyr@@sxemacs.org--sxemacs/sxemacs--hrop--22.1.2--patch-15"}.
173 The following two variables should be used in favour of snarfing and parsing
174 the output of @code{emacs-version}.
176 @defvar emacs-major-version
177 The major version number of Emacs, as an integer. For SXEmacs version
178 22.1.2, the value is 22.
181 @defvar emacs-minor-version
182 The minor version number of Emacs, as an integer. For SXEmacs version
183 22.1.2, the value is 1.
186 Note: These variables did not exist in early Emacs versions. If you
187 intend to preserve backward compatibility to this great extent you
188 should definitely consider to use a @code{boundp} condition.
190 Code to make certain features dependent on the version you are running
191 can be derived from the following example:
195 (when (boundp 'emacs-major-version)
196 (case emacs-major-version
197 (21 (message "You are probably not using SXEmacs"))
198 (22 (case emacs-minor-version
199 (1 (message "SXEmacs 22.1.x"))
200 (2 (message "SXEmacs 22.2.x"))
201 (3 (message "SXEmacs 22.3.x"))
202 (otherwise (message "Weird version."))))
203 (otherwise (error "Your version of SXEmacs is too old."))))
208 @node Garbage Collection
209 @appendixsec Garbage Collection
210 @cindex garbage collector
212 @cindex memory allocation
213 When a program creates a list or the user defines a new function (such
214 as by loading a library), that data is placed in normal storage. If
215 normal storage runs low, then SXEmacs asks the operating system to
216 allocate more memory in blocks of 2k bytes. Each block is used for one
217 type of Lisp object, so symbols, cons cells, markers, etc., are
218 segregated in distinct blocks in memory. Vectors, long strings,
219 buffers and certain other editing types, which are fairly large, are
220 allocated in individual blocks, one per object, while small strings are
221 packed into blocks of 8k bytes.
223 More correctly, a string is allocated in two sections: a fixed size
224 chunk containing the length, list of extents, etc.; and a chunk
225 containing the actual characters in the string. It is this latter chunk
226 that is either allocated individually or packed into 8k blocks. The
227 fixed size chunk is packed into 2k blocks, as for conses, markers,
230 It is quite common to use some storage for a while, then release it by
231 (for example) killing a buffer or deleting the last pointer to an
232 object. SXEmacs provides a @dfn{garbage collector} to reclaim this
233 abandoned storage. This name is traditional, but ``garbage recycler''
234 might be a more intuitive metaphor for this facility.
236 The garbage collector operates by finding and marking all Lisp objects
237 that are still accessible to Lisp programs. To begin with, it assumes
238 all the symbols, their values and associated function definitions, and
239 any data presently on the stack, are accessible. Any objects that can
240 be reached indirectly through other accessible objects are also
243 When marking is finished, all objects still unmarked are garbage. No
244 matter what the Lisp program or the user does, it is impossible to refer
245 to them, since there is no longer a way to reach them. Their space
246 might as well be reused, since no one will miss them. The second
247 (``sweep'') phase of the garbage collector arranges to reuse them.
250 The sweep phase puts unused cons cells onto a @dfn{free list} for
251 future allocation; likewise for symbols, markers, extents, events,
252 floats, compiled-function objects, and the fixed-size portion of
253 strings. It compacts the accessible small string-chars chunks so they
254 occupy fewer 8k blocks; then it frees the other 8k blocks. Vectors,
255 buffers, windows, and other large objects are individually allocated and
256 freed using @code{malloc} and @code{free}.
258 @cindex CL note---allocate more storage
260 @b{Common Lisp note:} unlike other Lisps, SXEmacs Lisp does not
261 call the garbage collector when the free list is empty. Instead, it
262 simply requests the operating system to allocate more storage, and
263 processing continues until @code{gc-cons-threshold} bytes have been
266 This means that you can make sure that the garbage collector will not
267 run during a certain portion of a Lisp program by calling the garbage
268 collector explicitly just before it provided that portion of the
269 program does not use so much space as to force a second garbage
273 @deffn Command garbage-collect
274 This command runs a garbage collection, and returns information on
275 the amount of space in use.
277 Garbage collection can also occur spontaneously if you use more than
278 @code{gc-cons-threshold} bytes of Lisp data since the previous garbage
281 @code{garbage-collect} returns a list containing the following
286 ((@var{used-conses} . @var{free-conses})
287 (@var{used-syms} . @var{free-syms})
289 (@var{used-markers} . @var{free-markers})
290 @var{used-string-chars}
291 @var{used-vector-slots}
295 @result{} ((73362 . 8325) (13718 . 164)
296 (5089 . 5098) 949121 118677
297 (conses-used 73362 conses-free 8329 cons-storage 658168
298 symbols-used 13718 symbols-free 164 symbol-storage 335216
299 bit-vectors-used 0 bit-vectors-total-length 0
300 bit-vector-storage 0 vectors-used 7882
301 vectors-total-length 118677 vector-storage 537764
302 compiled-functions-used 1336 compiled-functions-free 37
303 compiled-function-storage 44440 short-strings-used 28829
304 long-strings-used 2 strings-free 7722
305 short-strings-total-length 916657 short-string-storage 1179648
306 long-strings-total-length 32464 string-header-storage 441504
307 floats-used 3 floats-free 43 float-storage 2044 markers-used 5089
308 markers-free 5098 marker-storage 245280 events-used 103
309 events-free 835 event-storage 110656 extents-used 10519
310 extents-free 2718 extent-storage 372736
311 extent-auxiliarys-used 111 extent-auxiliarys-freed 3
312 extent-auxiliary-storage 4440 window-configurations-used 39
313 window-configurations-on-free-list 5
314 window-configurations-freed 10 window-configuration-storage 9492
315 popup-datas-used 3 popup-data-storage 72 toolbar-buttons-used 62
316 toolbar-button-storage 4960 toolbar-datas-used 12
317 toolbar-data-storage 240 symbol-value-buffer-locals-used 182
318 symbol-value-buffer-local-storage 5824
319 symbol-value-lisp-magics-used 22
320 symbol-value-lisp-magic-storage 1496
321 symbol-value-varaliases-used 43
322 symbol-value-varalias-storage 1032 opaque-lists-used 2
323 opaque-list-storage 48 color-instances-used 12
324 color-instance-storage 288 font-instances-used 5
325 font-instance-storage 180 opaques-used 11 opaque-storage 312
326 range-tables-used 1 range-table-storage 16 faces-used 34
327 face-storage 2584 glyphs-used 124 glyph-storage 4464
328 specifiers-used 775 specifier-storage 43869 weak-lists-used 786
329 weak-list-storage 18864 char-tables-used 40
330 char-table-storage 41920 buffers-used 25 buffer-storage 7000
331 extent-infos-used 457 extent-infos-freed 73
332 extent-info-storage 9140 keymaps-used 275 keymap-storage 12100
333 consoles-used 4 console-storage 384 command-builders-used 2
334 command-builder-storage 120 devices-used 2 device-storage 344
335 frames-used 3 frame-storage 624 image-instances-used 47
336 image-instance-storage 3008 windows-used 27 windows-freed 2
337 window-storage 9180 lcrecord-lists-used 15
338 lcrecord-list-storage 360 hash-tables-used 631
339 hash-table-storage 25240 streams-used 1 streams-on-free-list 3
340 streams-freed 12 stream-storage 91))
344 Here is a table explaining each element:
348 The number of cons cells in use.
351 The number of cons cells for which space has been obtained from the
352 operating system, but that are not currently being used.
355 The number of symbols in use.
358 The number of symbols for which space has been obtained from the
359 operating system, but that are not currently being used.
362 The number of markers in use.
365 The number of markers for which space has been obtained from the
366 operating system, but that are not currently being used.
368 @item used-string-chars
369 The total size of all strings, in characters.
371 @item used-vector-slots
372 The total number of elements of existing vectors.
375 A list of alternating keyword/value pairs providing more detailed
376 information. (As you can see above, quite a lot of information is
378 @ignore @c Different in SXEmacs
382 The number of floats in use.
386 The number of floats for which space has been obtained from the
387 operating system, but that are not currently being used.
392 @defopt gc-cons-threshold
393 The value of this variable is the number of bytes of storage that must
394 be allocated for Lisp objects after one garbage collection in order to
395 trigger another garbage collection.
397 A cons cell counts as eight bytes, a string as one byte per character
398 plus a few bytes of overhead, and so on; space allocated to the contents
399 of buffers does not count. Note that the subsequent garbage collection
400 does not happen immediately when the threshold is exhausted, but only
401 the next time the Lisp evaluator is called.
403 The initial threshold value is 500,000. If you specify a larger
404 value, garbage collection will happen less often. This reduces the
405 amount of time spent garbage collecting, but increases total memory use.
406 You may want to do this when running a program that creates lots of
409 You can make collections more frequent by specifying a smaller value,
410 down to 10,000. A value less than 10,000 will remain in effect only
411 until the subsequent garbage collection, at which time
412 @code{garbage-collect} will set the threshold back to 10,000.
414 Note: This does not apply if SXEmacs was configured with @samp{--debug}.
415 Therefore, be careful when setting @code{gc-cons-threshold} in that
422 This function returns the address of the last byte SXEmacs has allocated,
423 divided by 1024. We divide the value by 1024 to make sure it fits in a
426 You can use this to get a general idea of how your actions affect the
432 This is a normal hook to be run just before each garbage collection.
433 Interrupts, garbage collection, and errors are inhibited while this hook
434 runs, so be extremely careful in what you add here.
436 In particular, avoid consing, and do not interact with the user!
440 This is a normal hook to be run just after each garbage collection.
441 Interrupts, garbage collection, and errors are inhibited while this hook
442 runs, so be extremely careful in what you add here.
444 In particular, avoid consing, and do not interact with the user!
448 This is a string to print to indicate that a garbage collection is in
449 progress. This is printed in the echo area. If the selected frame is
450 on a window system and @code{gc-pointer-glyph} specifies a value (i.e. a
451 pointer image instance) in the domain of the selected frame, the mouse
452 cursor will change instead of this message being printed.
455 @defvr Glyph gc-pointer-glyph
456 This holds the pointer glyph used to indicate that a garbage collection
457 is in progress. If the selected window is on a window system and this
458 glyph specifies a value (i.e. a pointer image instance) in the domain of
459 the selected window, the cursor will be changed as specified during
460 garbage collection. Otherwise, a message will be printed in the echo
461 area, as controlled by @code{gc-message}. @xref{Glyphs}.
464 If SXEmacs was configured with @samp{--debug}, you can set the following
465 two variables to get direct information about all the allocation that
466 is happening in a segment of Lisp code.
468 @defvar debug-allocation
469 If non-zero, print out information to stderr about all objects
473 @defvar debug-allocation-backtrace
474 Length (in stack frames) of short backtrace printed out by
475 @code{debug-allocation}.