diff options
Diffstat (limited to 'src/alloc.c')
| -rw-r--r-- | src/alloc.c | 71 |
1 files changed, 39 insertions, 32 deletions
diff --git a/src/alloc.c b/src/alloc.c index 6e4cfa07fa0..27118c91c9c 100644 --- a/src/alloc.c +++ b/src/alloc.c | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | /* Storage allocation and gc for GNU Emacs Lisp interpreter. | 1 | /* Storage allocation and gc for GNU Emacs Lisp interpreter. |
| 2 | Copyright (C) 1985-1986, 1988, 1993-1995, 1997-2012 | 2 | |
| 3 | Free Software Foundation, Inc. | 3 | Copyright (C) 1985-1986, 1988, 1993-1995, 1997-2012 |
| 4 | Free Software Foundation, Inc. | ||
| 4 | 5 | ||
| 5 | This file is part of GNU Emacs. | 6 | This file is part of GNU Emacs. |
| 6 | 7 | ||
| @@ -4251,23 +4252,38 @@ mark_maybe_pointer (void *p) | |||
| 4251 | } | 4252 | } |
| 4252 | 4253 | ||
| 4253 | 4254 | ||
| 4254 | /* Alignment of Lisp_Object and pointer values. Use offsetof, as it | 4255 | /* Alignment of pointer values. Use offsetof, as it sometimes returns |
| 4255 | sometimes returns a smaller alignment than GCC's __alignof__ and | 4256 | a smaller alignment than GCC's __alignof__ and mark_memory might |
| 4256 | mark_memory might miss objects if __alignof__ were used. For | 4257 | miss objects if __alignof__ were used. */ |
| 4257 | example, on x86 with WIDE_EMACS_INT, __alignof__ (Lisp_Object) is 8 | ||
| 4258 | but GC_LISP_OBJECT_ALIGNMENT should be 4. */ | ||
| 4259 | #ifndef GC_LISP_OBJECT_ALIGNMENT | ||
| 4260 | # define GC_LISP_OBJECT_ALIGNMENT offsetof (struct {char a; Lisp_Object b;}, b) | ||
| 4261 | #endif | ||
| 4262 | #define GC_POINTER_ALIGNMENT offsetof (struct {char a; void *b;}, b) | 4258 | #define GC_POINTER_ALIGNMENT offsetof (struct {char a; void *b;}, b) |
| 4263 | 4259 | ||
| 4260 | /* Define POINTERS_MIGHT_HIDE_IN_OBJECTS to 1 if marking via C pointers does | ||
| 4261 | not suffice, which is the typical case. A host where a Lisp_Object is | ||
| 4262 | wider than a pointer might allocate a Lisp_Object in non-adjacent halves. | ||
| 4263 | If USE_LSB_TAG, the bottom half is not a valid pointer, but it should | ||
| 4264 | suffice to widen it to to a Lisp_Object and check it that way. */ | ||
| 4265 | #if defined USE_LSB_TAG || UINTPTR_MAX >> VALBITS != 0 | ||
| 4266 | # if !defined USE_LSB_TAG && UINTPTR_MAX >> VALBITS >> GCTYPEBITS != 0 | ||
| 4267 | /* If tag bits straddle pointer-word boundaries, neither mark_maybe_pointer | ||
| 4268 | nor mark_maybe_object can follow the pointers. This should not occur on | ||
| 4269 | any practical porting target. */ | ||
| 4270 | # error "MSB type bits straddle pointer-word boundaries" | ||
| 4271 | # endif | ||
| 4272 | /* Marking via C pointers does not suffice, because Lisp_Objects contain | ||
| 4273 | pointer words that hold pointers ORed with type bits. */ | ||
| 4274 | # define POINTERS_MIGHT_HIDE_IN_OBJECTS 1 | ||
| 4275 | #else | ||
| 4276 | /* Marking via C pointers suffices, because Lisp_Objects contain pointer | ||
| 4277 | words that hold unmodified pointers. */ | ||
| 4278 | # define POINTERS_MIGHT_HIDE_IN_OBJECTS 0 | ||
| 4279 | #endif | ||
| 4280 | |||
| 4264 | /* Mark Lisp objects referenced from the address range START+OFFSET..END | 4281 | /* Mark Lisp objects referenced from the address range START+OFFSET..END |
| 4265 | or END+OFFSET..START. */ | 4282 | or END+OFFSET..START. */ |
| 4266 | 4283 | ||
| 4267 | static void | 4284 | static void |
| 4268 | mark_memory (void *start, void *end) | 4285 | mark_memory (void *start, void *end) |
| 4269 | { | 4286 | { |
| 4270 | Lisp_Object *p; | ||
| 4271 | void **pp; | 4287 | void **pp; |
| 4272 | int i; | 4288 | int i; |
| 4273 | 4289 | ||
| @@ -4284,11 +4300,6 @@ mark_memory (void *start, void *end) | |||
| 4284 | end = tem; | 4300 | end = tem; |
| 4285 | } | 4301 | } |
| 4286 | 4302 | ||
| 4287 | /* Mark Lisp_Objects. */ | ||
| 4288 | for (p = start; (void *) p < end; p++) | ||
| 4289 | for (i = 0; i < sizeof *p; i += GC_LISP_OBJECT_ALIGNMENT) | ||
| 4290 | mark_maybe_object (*(Lisp_Object *) ((char *) p + i)); | ||
| 4291 | |||
| 4292 | /* Mark Lisp data pointed to. This is necessary because, in some | 4303 | /* Mark Lisp data pointed to. This is necessary because, in some |
| 4293 | situations, the C compiler optimizes Lisp objects away, so that | 4304 | situations, the C compiler optimizes Lisp objects away, so that |
| 4294 | only a pointer to them remains. Example: | 4305 | only a pointer to them remains. Example: |
| @@ -4310,17 +4321,10 @@ mark_memory (void *start, void *end) | |||
| 4310 | for (pp = start; (void *) pp < end; pp++) | 4321 | for (pp = start; (void *) pp < end; pp++) |
| 4311 | for (i = 0; i < sizeof *pp; i += GC_POINTER_ALIGNMENT) | 4322 | for (i = 0; i < sizeof *pp; i += GC_POINTER_ALIGNMENT) |
| 4312 | { | 4323 | { |
| 4313 | void *w = *(void **) ((char *) pp + i); | 4324 | void *p = *(void **) ((char *) pp + i); |
| 4314 | mark_maybe_pointer (w); | 4325 | mark_maybe_pointer (p); |
| 4315 | 4326 | if (POINTERS_MIGHT_HIDE_IN_OBJECTS) | |
| 4316 | #ifdef USE_LSB_TAG | 4327 | mark_maybe_object (widen_to_Lisp_Object (p)); |
| 4317 | /* A host where a Lisp_Object is wider than a pointer might | ||
| 4318 | allocate a Lisp_Object in non-adjacent halves. If | ||
| 4319 | USE_LSB_TAG, the bottom half is not a valid pointer, so | ||
| 4320 | widen it to to a Lisp_Object and check it that way. */ | ||
| 4321 | if (sizeof w < sizeof (Lisp_Object)) | ||
| 4322 | mark_maybe_object (widen_to_Lisp_Object (w)); | ||
| 4323 | #endif | ||
| 4324 | } | 4328 | } |
| 4325 | } | 4329 | } |
| 4326 | 4330 | ||
| @@ -5011,11 +5015,12 @@ Garbage collection happens automatically if you cons more than | |||
| 5011 | `gc-cons-threshold' bytes of Lisp data since previous garbage collection. | 5015 | `gc-cons-threshold' bytes of Lisp data since previous garbage collection. |
| 5012 | `garbage-collect' normally returns a list with info on amount of space in use: | 5016 | `garbage-collect' normally returns a list with info on amount of space in use: |
| 5013 | ((USED-CONSES . FREE-CONSES) (USED-SYMS . FREE-SYMS) | 5017 | ((USED-CONSES . FREE-CONSES) (USED-SYMS . FREE-SYMS) |
| 5014 | (USED-MARKERS . FREE-MARKERS) USED-STRING-CHARS USED-VECTOR-SLOTS | 5018 | (USED-MISCS . FREE-MISCS) USED-STRING-CHARS USED-VECTOR-SLOTS |
| 5015 | (USED-FLOATS . FREE-FLOATS) (USED-INTERVALS . FREE-INTERVALS) | 5019 | (USED-FLOATS . FREE-FLOATS) (USED-INTERVALS . FREE-INTERVALS) |
| 5016 | (USED-STRINGS . FREE-STRINGS)) | 5020 | (USED-STRINGS . FREE-STRINGS)) |
| 5017 | However, if there was overflow in pure space, `garbage-collect' | 5021 | However, if there was overflow in pure space, `garbage-collect' |
| 5018 | returns nil, because real GC can't be done. */) | 5022 | returns nil, because real GC can't be done. |
| 5023 | See Info node `(elisp)Garbage Collection'. */) | ||
| 5019 | (void) | 5024 | (void) |
| 5020 | { | 5025 | { |
| 5021 | register struct specbinding *bind; | 5026 | register struct specbinding *bind; |
| @@ -6409,7 +6414,7 @@ void | |||
| 6409 | syms_of_alloc (void) | 6414 | syms_of_alloc (void) |
| 6410 | { | 6415 | { |
| 6411 | DEFVAR_INT ("gc-cons-threshold", gc_cons_threshold, | 6416 | DEFVAR_INT ("gc-cons-threshold", gc_cons_threshold, |
| 6412 | doc: /* *Number of bytes of consing between garbage collections. | 6417 | doc: /* Number of bytes of consing between garbage collections. |
| 6413 | Garbage collection can happen automatically once this many bytes have been | 6418 | Garbage collection can happen automatically once this many bytes have been |
| 6414 | allocated since the last garbage collection. All data types count. | 6419 | allocated since the last garbage collection. All data types count. |
| 6415 | 6420 | ||
| @@ -6420,7 +6425,7 @@ prevent garbage collection during a part of the program. | |||
| 6420 | See also `gc-cons-percentage'. */); | 6425 | See also `gc-cons-percentage'. */); |
| 6421 | 6426 | ||
| 6422 | DEFVAR_LISP ("gc-cons-percentage", Vgc_cons_percentage, | 6427 | DEFVAR_LISP ("gc-cons-percentage", Vgc_cons_percentage, |
| 6423 | doc: /* *Portion of the heap used for allocation. | 6428 | doc: /* Portion of the heap used for allocation. |
| 6424 | Garbage collection can happen automatically once this portion of the heap | 6429 | Garbage collection can happen automatically once this portion of the heap |
| 6425 | has been allocated since the last garbage collection. | 6430 | has been allocated since the last garbage collection. |
| 6426 | If this portion is smaller than `gc-cons-threshold', this is ignored. */); | 6431 | If this portion is smaller than `gc-cons-threshold', this is ignored. */); |
| @@ -6445,7 +6450,9 @@ If this portion is smaller than `gc-cons-threshold', this is ignored. */); | |||
| 6445 | doc: /* Number of string characters that have been consed so far. */); | 6450 | doc: /* Number of string characters that have been consed so far. */); |
| 6446 | 6451 | ||
| 6447 | DEFVAR_INT ("misc-objects-consed", misc_objects_consed, | 6452 | DEFVAR_INT ("misc-objects-consed", misc_objects_consed, |
| 6448 | doc: /* Number of miscellaneous objects that have been consed so far. */); | 6453 | doc: /* Number of miscellaneous objects that have been consed so far. |
| 6454 | These include markers and overlays, plus certain objects not visible | ||
| 6455 | to users. */); | ||
| 6449 | 6456 | ||
| 6450 | DEFVAR_INT ("intervals-consed", intervals_consed, | 6457 | DEFVAR_INT ("intervals-consed", intervals_consed, |
| 6451 | doc: /* Number of intervals that have been consed so far. */); | 6458 | doc: /* Number of intervals that have been consed so far. */); |