aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Antipov2012-11-15 09:25:05 +0400
committerDmitry Antipov2012-11-15 09:25:05 +0400
commit74934dccc4d793557c1880034fd5433d9b97ae52 (patch)
tree60dc7e532ee29f38dd1432fbb8f89c438954fabe
parent1232d6c2e4c41cc5c3296058a3750a662aaab2a1 (diff)
downloademacs-74934dccc4d793557c1880034fd5433d9b97ae52.tar.gz
emacs-74934dccc4d793557c1880034fd5433d9b97ae52.zip
* internals.texi (Garbage Collection): Update descriptions
of vectorlike_header, garbage-collect and gc-cons-threshold. (Object Internals): Explain Lisp_Object layout and the basics of an internal type system. (Buffer Internals): Update description of struct buffer.
-rw-r--r--doc/lispref/ChangeLog8
-rw-r--r--doc/lispref/internals.texi295
2 files changed, 212 insertions, 91 deletions
diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog
index 6d6ddf4da9a..d157fec9a6c 100644
--- a/doc/lispref/ChangeLog
+++ b/doc/lispref/ChangeLog
@@ -1,3 +1,11 @@
12012-11-15 Dmitry Antipov <dmantipov@yandex.ru>
2
3 * internals.texi (Garbage Collection): Update descriptions
4 of vectorlike_header, garbage-collect and gc-cons-threshold.
5 (Object Internals): Explain Lisp_Object layout and the basics
6 of an internal type system.
7 (Buffer Internals): Update description of struct buffer.
8
12012-11-13 Glenn Morris <rgm@gnu.org> 92012-11-13 Glenn Morris <rgm@gnu.org>
2 10
3 * variables.texi (Adding Generalized Variables): 11 * variables.texi (Adding Generalized Variables):
diff --git a/doc/lispref/internals.texi b/doc/lispref/internals.texi
index 1459f52d979..2a2846921c5 100644
--- a/doc/lispref/internals.texi
+++ b/doc/lispref/internals.texi
@@ -226,12 +226,11 @@ of 8k bytes, and small vectors are packed into blocks of 4k bytes).
226 Beyond the basic vector, a lot of objects like window, buffer, and 226 Beyond the basic vector, a lot of objects like window, buffer, and
227frame are managed as if they were vectors. The corresponding C data 227frame are managed as if they were vectors. The corresponding C data
228structures include the @code{struct vectorlike_header} field whose 228structures include the @code{struct vectorlike_header} field whose
229@code{next} field points to the next object in the chain: 229@code{size} member contains the subtype enumerated by @code{enum pvec_type}
230@code{header.next.buffer} points to the next buffer (which could be 230and an information about how many @code{Lisp_Object} fields this structure
231a killed buffer), and @code{header.next.vector} points to the next 231contains and what the size of the rest data is. This information is
232vector in a free list. If a vector is small (smaller than or equal to 232needed to calculate the memory footprint of an object, and used
233@code{VBLOCK_BYTES_MAX} bytes, see @file{alloc.c}), then 233by the vector allocation code while iterating over the vector blocks.
234@code{header.next.nbytes} contains the vector size in bytes.
235 234
236@cindex garbage collection 235@cindex garbage collection
237 It is quite common to use some storage for a while, then release it 236 It is quite common to use some storage for a while, then release it
@@ -284,88 +283,147 @@ the amount of space in use. (Garbage collection can also occur
284spontaneously if you use more than @code{gc-cons-threshold} bytes of 283spontaneously if you use more than @code{gc-cons-threshold} bytes of
285Lisp data since the previous garbage collection.) 284Lisp data since the previous garbage collection.)
286 285
287@code{garbage-collect} returns a list containing the following 286@code{garbage-collect} returns a list with information on amount of space in
288information: 287use, where each entry has the form @samp{(@var{name} @var{size} @var{used})}
288or @samp{(@var{name} @var{size} @var{used} @var{free})}. In the entry,
289@var{name} is a symbol describing the kind of objects this entry represents,
290@var{size} is the number of bytes used by each one, @var{used} is the number
291of those objects that were found live in the heap, and optional @var{free} is
292the number of those objects that are not live but that Emacs keeps around for
293future allocations. So an overall result is:
289 294
290@example 295@example
291@group 296((@code{conses} @var{cons-size} @var{used-conse} @var{free-conses})
292((@var{used-conses} . @var{free-conses}) 297 (@code{symbols} @var{symbol-size} @var{used-symbols} @var{free-symbols})
293 (@var{used-syms} . @var{free-syms}) 298 (@code{miscs} @var{misc-size} @var{used-miscs} @var{free-miscs})
294@end group 299 (@code{strings} @var{string-size} @var{used-strings} @var{free-strings})
295 (@var{used-miscs} . @var{free-miscs}) 300 (@code{string-bytes} @var{byte-size} @var{used-bytes})
296 @var{used-string-chars} 301 (@code{vectors} @var{vector-size} @var{used-vectors})
297 @var{used-vector-slots} 302 (@code{vector-slots} @var{slot-size} @var{used-slots} @var{free-slots})
298 (@var{used-floats} . @var{free-floats}) 303 (@code{floats} @var{float-size} @var{used-floats} @var{free-floats})
299 (@var{used-intervals} . @var{free-intervals}) 304 (@code{intervals} @var{interval-size} @var{used-intervals} @var{free-intervals})
300 (@var{used-strings} . @var{free-strings})) 305 (@code{buffers} @var{buffer-size} @var{used-buffers})
306 (@code{heap} @var{unit-size} @var{total-size} @var{free-size}))
301@end example 307@end example
302 308
303Here is an example: 309Here is an example:
304 310
305@example 311@example
306@group
307(garbage-collect) 312(garbage-collect)
308 @result{} ((106886 . 13184) (9769 . 0) 313 @result{} ((conses 16 49126 8058) (symbols 48 14607 0)
309 (7731 . 4651) 347543 121628 314 (miscs 40 34 56) (strings 32 2942 2607)
310 (31 . 94) (1273 . 168) 315 (string-bytes 1 78607) (vectors 16 7247)
311 (25474 . 3569)) 316 (vector-slots 8 341609 29474) (floats 8 71 102)
312@end group 317 (intervals 56 27 26) (buffers 944 8)
318 (heap 1024 11715 2678))
313@end example 319@end example
314 320
315Here is a table explaining each element: 321Below is a table explaining each element. Note that last @code{heap} entry
322is optional and present only if an underlying @code{malloc} implementation
323provides @code{mallinfo} function.
316 324
317@table @var 325@table @var
326@item cons-size
327Internal size of a cons cell, i.e.@: @code{sizeof (struct Lisp_Cons)}.
328
318@item used-conses 329@item used-conses
319The number of cons cells in use. 330The number of cons cells in use.
320 331
321@item free-conses 332@item free-conses
322The number of cons cells for which space has been obtained from the 333The number of cons cells for which space has been obtained from
323operating system, but that are not currently being used. 334the operating system, but that are not currently being used.
324 335
325@item used-syms 336@item symbol-size
337Internal size of a symbol, i.e.@: @code{sizeof (struct Lisp_Symbol)}.
338
339@item used-symbols
326The number of symbols in use. 340The number of symbols in use.
327 341
328@item free-syms 342@item free-symbols
329The number of symbols for which space has been obtained from the 343The number of symbols for which space has been obtained from
330operating system, but that are not currently being used. 344the operating system, but that are not currently being used.
345
346@item misc-size
347Internal size of a miscellaneous entity, i.e.@:
348@code{sizeof (union Lisp_Misc)}, which is a size of the
349largest type enumerated in @code{enum Lisp_Misc_Type}.
331 350
332@item used-miscs 351@item used-miscs
333The number of miscellaneous objects in use. These include markers and 352The number of miscellaneous objects in use. These include markers
334overlays, plus certain objects not visible to users. 353and overlays, plus certain objects not visible to users.
335 354
336@item free-miscs 355@item free-miscs
337The number of miscellaneous objects for which space has been obtained 356The number of miscellaneous objects for which space has been obtained
338from the operating system, but that are not currently being used. 357from the operating system, but that are not currently being used.
339 358
340@item used-string-chars 359@item string-size
341The total size of all strings, in characters. 360Internal size of a string header, i.e.@: @code{sizeof (struct Lisp_String)}.
361
362@item used-strings
363The number of string headers in use.
364
365@item free-strings
366The number of string headers for which space has been obtained
367from the operating system, but that are not currently being used.
368
369@item byte-size
370This is used for convenience and equals to @code{sizeof (char)}.
371
372@item used-bytes
373The total size of all string data in bytes.
374
375@item vector-size
376Internal size of a vector header, i.e.@: @code{sizeof (struct Lisp_Vector)}.
342 377
343@item used-vector-slots 378@item used-vectors
344The total number of elements of existing vectors. 379The number of vector headers allocated from the vector blocks.
380
381@item slot-size
382Internal size of a vector slot, always equal to @code{sizeof (Lisp_Object)}.
383
384@item used-slots
385The number of slots in all used vectors.
386
387@item free-slots
388The number of free slots in all vector blocks.
389
390@item float-size
391Internal size of a float object, i.e.@: @code{sizeof (struct Lisp_Float)}.
392(Do not confuse it with the native platform @code{float} or @code{double}.)
345 393
346@item used-floats 394@item used-floats
347The number of floats in use. 395The number of floats in use.
348 396
349@item free-floats 397@item free-floats
350The number of floats for which space has been obtained from the 398The number of floats for which space has been obtained from
351operating system, but that are not currently being used. 399the operating system, but that are not currently being used.
400
401@item interval-size
402Internal size of an interval object, i.e.@: @code{sizeof (struct interval)}.
352 403
353@item used-intervals 404@item used-intervals
354The number of intervals in use. Intervals are an internal 405The number of intervals in use.
355data structure used for representing text properties.
356 406
357@item free-intervals 407@item free-intervals
358The number of intervals for which space has been obtained 408The number of intervals for which space has been obtained from
359from the operating system, but that are not currently being used. 409the operating system, but that are not currently being used.
360 410
361@item used-strings 411@item buffer-size
362The number of strings in use. 412Internal size of a buffer, i.e.@: @code{sizeof (struct buffer)}.
413(Do not confuse with the value returned by @code{buffer-size} function.)
363 414
364@item free-strings 415@item used-buffers
365The number of string headers for which the space was obtained from the 416The number of buffer objects in use. This includes killed buffers
366operating system, but which are currently not in use. (A string 417invisible to users, i.e.@: all buffers in @code{all_buffers} list.
367object consists of a header and the storage for the string text 418
368itself; the latter is only allocated when the string is created.) 419@item unit-size
420The unit of heap space measurement, always equal to 1024 bytes.
421
422@item total-size
423Total heap size, in @var{unit-size} units.
424
425@item free-size
426Heap space which is not currently used, in @var{unit-size} units.
369@end table 427@end table
370 428
371If there was overflow in pure space (@pxref{Pure Storage}), 429If there was overflow in pure space (@pxref{Pure Storage}),
@@ -388,23 +446,25 @@ careful writing them.
388@defopt gc-cons-threshold 446@defopt gc-cons-threshold
389The value of this variable is the number of bytes of storage that must 447The value of this variable is the number of bytes of storage that must
390be allocated for Lisp objects after one garbage collection in order to 448be allocated for Lisp objects after one garbage collection in order to
391trigger another garbage collection. A cons cell counts as eight bytes, 449trigger another garbage collection. You can use the result returned by
392a string as one byte per character plus a few bytes of overhead, and so 450@code{garbage-collect} to get an information about size of the particular
393on; space allocated to the contents of buffers does not count. Note 451object type; space allocated to the contents of buffers does not count.
394that the subsequent garbage collection does not happen immediately when 452Note that the subsequent garbage collection does not happen immediately
395the threshold is exhausted, but only the next time the Lisp evaluator is 453when the threshold is exhausted, but only the next time the Lisp interpreter
396called. 454is called.
397 455
398The initial threshold value is 800,000. If you specify a larger 456The initial threshold value is @code{GC_DEFAULT_THRESHOLD}, defined in
399value, garbage collection will happen less often. This reduces the 457@file{alloc.c}. Since it's defined in @code{word_size} units, the value
400amount of time spent garbage collecting, but increases total memory use. 458is 400,000 for the default 32-bit configuration and 800,000 for the 64-bit
401You may want to do this when running a program that creates lots of 459one. If you specify a larger value, garbage collection will happen less
402Lisp data. 460often. This reduces the amount of time spent garbage collecting, but
403 461increases total memory use. You may want to do this when running a program
404You can make collections more frequent by specifying a smaller value, 462that creates lots of Lisp data.
405down to 10,000. A value less than 10,000 will remain in effect only 463
406until the subsequent garbage collection, at which time 464You can make collections more frequent by specifying a smaller value, down
407@code{garbage-collect} will set the threshold back to 10,000. 465to 1/10th of @code{GC_DEFAULT_THRESHOLD}. A value less than this minimum
466will remain in effect only until the subsequent garbage collection, at which
467time @code{garbage-collect} will set the threshold back to the minimum.
408@end defopt 468@end defopt
409 469
410@defopt gc-cons-percentage 470@defopt gc-cons-percentage
@@ -639,7 +699,12 @@ in the file @file{lisp.h}.) If the primitive has no upper limit on
639the number of Lisp arguments, it must have exactly two C arguments: 699the number of Lisp arguments, it must have exactly two C arguments:
640the first is the number of Lisp arguments, and the second is the 700the first is the number of Lisp arguments, and the second is the
641address of a block containing their values. These have types 701address of a block containing their values. These have types
642@code{int} and @w{@code{Lisp_Object *}} respectively. 702@code{int} and @w{@code{Lisp_Object *}} respectively. Since
703@code{Lisp_Object} can hold any Lisp object of any data type, you
704can determine the actual data type only at run time; so if you want
705a primitive to accept only a certain type of argument, you must check
706the type explicitly using a suitable predicate (@pxref{Type Predicates}).
707@cindex type checking internals
643 708
644@cindex @code{GCPRO} and @code{UNGCPRO} 709@cindex @code{GCPRO} and @code{UNGCPRO}
645@cindex protect C variables from garbage collection 710@cindex protect C variables from garbage collection
@@ -820,23 +885,70 @@ knows about it.
820@section Object Internals 885@section Object Internals
821@cindex object internals 886@cindex object internals
822 887
823@c FIXME Is this still true? Does --with-wide-int affect anything? 888 Emacs Lisp provides a rich set of the data types. Some of them, like cons
824 GNU Emacs Lisp manipulates many different types of data. The actual 889cells, integers and stirngs, are common to nearly all Lisp dialects. Some
825data are stored in a heap and the only access that programs have to it 890others, like markers and buffers, are quite special and needed to provide
826is through pointers. Each pointer is 32 bits wide on 32-bit machines, 891the basic support to write editor commands in Lisp. To implement such
827and 64 bits wide on 64-bit machines; three of these bits are used for 892a variety of object types and provide an efficient way to pass objects between
828the tag that identifies the object's type, and the remainder are used 893the subsystems of an interpreter, there is a set of C data structures and
829to address the object. 894a special type to represent the pointers to all of them, which is known as
830 895@dfn{tagged pointer}.
831 Because Lisp objects are represented as tagged pointers, it is always 896
832possible to determine the Lisp data type of any object. The C data type 897 In C, the tagged pointer is an object of type @code{Lisp_Object}. Any
833@code{Lisp_Object} can hold any Lisp object of any data type. Ordinary 898initialized variable of such a type always holds the value of one of the
834variables have type @code{Lisp_Object}, which means they can hold any 899following basic data types: integer, symbol, string, cons cell, float,
835type of Lisp value; you can determine the actual data type only at run 900vectorlike or miscellaneous object. Each of these data types has the
836time. The same is true for function arguments; if you want a function 901corresponding tag value. All tags are enumerated by @code{enum Lisp_Type}
837to accept only a certain type of argument, you must check the type 902and placed into a 3-bit bitfield of the @code{Lisp_Object}. The rest of the
838explicitly using a suitable predicate (@pxref{Type Predicates}). 903bits is the value itself. Integer values are immediate, i.e.@: directly
839@cindex type checking internals 904represented by those @dfn{value bits}, and all other objects are represented
905by the C pointers to a corresponding object allocated from the heap. Width
906of the @code{Lisp_Object} is platform- and configuration-dependent: usually
907it's equal to the width of an underlying platform pointer (i.e.@: 32-bit on
908a 32-bit machine and 64-bit on a 64-bit one), but also there is a special
909configuration where @code{Lisp_Object} is 64-bit but all pointers are 32-bit.
910The latter trick was designed to overcome the limited range of values for
911Lisp integers on a 32-bit system by using 64-bit @code{long long} type for
912@code{Lisp_Object}.
913
914 The following C data structures are defined in @file{lisp.h} to represent
915the basic data types beyond integers:
916
917@table @code
918@item struct Lisp_Cons
919Cons cell, an object used to construct lists.
920
921@item struct Lisp_String
922String, the basic object to represent a sequence of characters.
923
924@item struct Lisp_Vector
925Array, a fixed-size set of Lisp objects which may be accessed by an index.
926
927@item struct Lisp_Symbol
928Symbol, the unique-named entity commonly used as an identifier.
929
930@item struct Lisp_Float
931Floating point value.
932
933@item union Lisp_Misc
934Miscellaneous kinds of objects which don't fit into any of the above.
935@end table
936
937 These types are the first-class citizens of an internal type system.
938Since the tag space is limited, all other types are the subtypes of either
939@code{Lisp_Vectorlike} or @code{Lisp_Misc}. Vector subtypes are enumerated
940by @code{enum pvec_type}, and nearly all complex objects like windows, buffers,
941frames, and processes fall into this category. The rest of special types,
942including markers and overlays, are enumerated by @code{enum Lisp_Misc_Type}
943and form the set of subtypes of @code{Lisp_Misc}.
944
945 Below there is a description of a few subtypes of @code{Lisp_Vectorlike}.
946Buffer object represents the text to display and edit. Window is the part
947of display structure which shows the buffer or used as a container to
948recursively place other windows on the same frame. (Do not confuse Emacs Lisp
949window object with the window as an entity managed by the user interface
950system like X; in Emacs terminology, the latter is called frame.) Finally,
951process object is used to manage the subprocesses.
840 952
841@menu 953@menu
842* Buffer Internals:: Components of a buffer structure. 954* Buffer Internals:: Components of a buffer structure.
@@ -912,12 +1024,8 @@ Some of the fields of @code{struct buffer} are:
912 1024
913@table @code 1025@table @code
914@item header 1026@item header
915A @code{struct vectorlike_header} structure where @code{header.next} 1027A header of type @code{struct vectorlike_header} is common to all
916points to the next buffer, in the chain of all buffers (including 1028vectorlike objects.
917killed buffers). This chain is used only for garbage collection, in
918order to collect killed buffers properly. Note that vectors, and most
919kinds of objects allocated as vectors, are all on one chain, but
920buffers are on a separate chain of their own.
921 1029
922@item own_text 1030@item own_text
923A @code{struct buffer_text} structure that ordinarily holds the buffer 1031A @code{struct buffer_text} structure that ordinarily holds the buffer
@@ -928,6 +1036,11 @@ A pointer to the @code{buffer_text} structure for this buffer. In an
928ordinary buffer, this is the @code{own_text} field above. In an 1036ordinary buffer, this is the @code{own_text} field above. In an
929indirect buffer, this is the @code{own_text} field of the base buffer. 1037indirect buffer, this is the @code{own_text} field of the base buffer.
930 1038
1039@item next
1040A pointer to the next buffer, in the chain of all buffers, including
1041killed buffers. This chain is used only for allocation and garbage
1042collection, in order to collect killed buffers properly.
1043
931@item pt 1044@item pt
932@itemx pt_byte 1045@itemx pt_byte
933The character and byte positions of point in a buffer. 1046The character and byte positions of point in a buffer.