comparison src/alloc.c @ 53582:b4eef5adebbf

(struct interval_block, struct string_block) (struct symbol_block, struct marker_block, live_string_p) (live_cons_p, live_symbol_p, live_float_p, live_misc_p): Better preserve alignment for objects in blocks. (FLOAT_BLOCK_SIZE): Adjust for possible alignment padding.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Wed, 14 Jan 2004 14:35:23 +0000
parents 72ce38380ab3
children 5558449888ec
comparison
equal deleted inserted replaced
53581:78f37e5ea2f2 53582:b4eef5adebbf
1 /* Storage allocation and gc for GNU Emacs Lisp interpreter. 1 /* Storage allocation and gc for GNU Emacs Lisp interpreter.
2 Copyright (C) 1985, 86, 88, 93, 94, 95, 97, 98, 1999, 2000, 2001, 2002, 2003 2 Copyright (C) 1985,86,88,93,94,95,97,98,1999,2000,01,02,03,2004
3 Free Software Foundation, Inc. 3 Free Software Foundation, Inc.
4 4
5 This file is part of GNU Emacs. 5 This file is part of GNU Emacs.
6 6
7 GNU Emacs is free software; you can redistribute it and/or modify 7 GNU Emacs is free software; you can redistribute it and/or modify
1102 /* Intervals are allocated in chunks in form of an interval_block 1102 /* Intervals are allocated in chunks in form of an interval_block
1103 structure. */ 1103 structure. */
1104 1104
1105 struct interval_block 1105 struct interval_block
1106 { 1106 {
1107 /* Place `intervals' first, to preserve alignment. */
1108 struct interval intervals[INTERVAL_BLOCK_SIZE];
1107 struct interval_block *next; 1109 struct interval_block *next;
1108 struct interval intervals[INTERVAL_BLOCK_SIZE];
1109 }; 1110 };
1110 1111
1111 /* Current interval block. Its `next' pointer points to older 1112 /* Current interval block. Its `next' pointer points to older
1112 blocks. */ 1113 blocks. */
1113 1114
1341 /* Structure describing a block from which Lisp_String structures 1342 /* Structure describing a block from which Lisp_String structures
1342 are allocated. */ 1343 are allocated. */
1343 1344
1344 struct string_block 1345 struct string_block
1345 { 1346 {
1347 /* Place `strings' first, to preserve alignment. */
1348 struct Lisp_String strings[STRING_BLOCK_SIZE];
1346 struct string_block *next; 1349 struct string_block *next;
1347 struct Lisp_String strings[STRING_BLOCK_SIZE];
1348 }; 1350 };
1349 1351
1350 /* Head and tail of the list of sblock structures holding Lisp string 1352 /* Head and tail of the list of sblock structures holding Lisp string
1351 data. We always allocate from current_sblock. The NEXT pointers 1353 data. We always allocate from current_sblock. The NEXT pointers
1352 in the sblock structures go from oldest_sblock to current_sblock. */ 1354 in the sblock structures go from oldest_sblock to current_sblock. */
2123 /* We store float cells inside of float_blocks, allocating a new 2125 /* We store float cells inside of float_blocks, allocating a new
2124 float_block with malloc whenever necessary. Float cells reclaimed 2126 float_block with malloc whenever necessary. Float cells reclaimed
2125 by GC are put on a free list to be reallocated before allocating 2127 by GC are put on a free list to be reallocated before allocating
2126 any new float cells from the latest float_block. */ 2128 any new float cells from the latest float_block. */
2127 2129
2128 #define FLOAT_BLOCK_SIZE \ 2130 #define FLOAT_BLOCK_SIZE \
2129 (((BLOCK_BYTES - sizeof (struct float_block *)) * CHAR_BIT) \ 2131 (((BLOCK_BYTES - sizeof (struct float_block *) \
2132 /* The compiler might add padding at the end. */ \
2133 - (sizeof (struct Lisp_Float) - sizeof (int))) * CHAR_BIT) \
2130 / (sizeof (struct Lisp_Float) * CHAR_BIT + 1)) 2134 / (sizeof (struct Lisp_Float) * CHAR_BIT + 1))
2131 2135
2132 #define GETMARKBIT(block,n) \ 2136 #define GETMARKBIT(block,n) \
2133 (((block)->gcmarkbits[(n) / (sizeof(int) * CHAR_BIT)] \ 2137 (((block)->gcmarkbits[(n) / (sizeof(int) * CHAR_BIT)] \
2134 >> ((n) % (sizeof(int) * CHAR_BIT))) \ 2138 >> ((n) % (sizeof(int) * CHAR_BIT))) \
2751 #define SYMBOL_BLOCK_SIZE \ 2755 #define SYMBOL_BLOCK_SIZE \
2752 ((1020 - sizeof (struct symbol_block *)) / sizeof (struct Lisp_Symbol)) 2756 ((1020 - sizeof (struct symbol_block *)) / sizeof (struct Lisp_Symbol))
2753 2757
2754 struct symbol_block 2758 struct symbol_block
2755 { 2759 {
2760 /* Place `symbols' first, to preserve alignment. */
2761 struct Lisp_Symbol symbols[SYMBOL_BLOCK_SIZE];
2756 struct symbol_block *next; 2762 struct symbol_block *next;
2757 struct Lisp_Symbol symbols[SYMBOL_BLOCK_SIZE];
2758 }; 2763 };
2759 2764
2760 /* Current symbol block and index of first unused Lisp_Symbol 2765 /* Current symbol block and index of first unused Lisp_Symbol
2761 structure in it. */ 2766 structure in it. */
2762 2767
2843 #define MARKER_BLOCK_SIZE \ 2848 #define MARKER_BLOCK_SIZE \
2844 ((1020 - sizeof (struct marker_block *)) / sizeof (union Lisp_Misc)) 2849 ((1020 - sizeof (struct marker_block *)) / sizeof (union Lisp_Misc))
2845 2850
2846 struct marker_block 2851 struct marker_block
2847 { 2852 {
2853 /* Place `markers' first, to preserve alignment. */
2854 union Lisp_Misc markers[MARKER_BLOCK_SIZE];
2848 struct marker_block *next; 2855 struct marker_block *next;
2849 union Lisp_Misc markers[MARKER_BLOCK_SIZE];
2850 }; 2856 };
2851 2857
2852 struct marker_block *marker_block; 2858 struct marker_block *marker_block;
2853 int marker_block_index; 2859 int marker_block_index;
2854 2860
3425 3431
3426 /* P must point to the start of a Lisp_String structure, and it 3432 /* P must point to the start of a Lisp_String structure, and it
3427 must not be on the free-list. */ 3433 must not be on the free-list. */
3428 return (offset >= 0 3434 return (offset >= 0
3429 && offset % sizeof b->strings[0] == 0 3435 && offset % sizeof b->strings[0] == 0
3436 && offset < (STRING_BLOCK_SIZE * sizeof b->strings[0])
3430 && ((struct Lisp_String *) p)->data != NULL); 3437 && ((struct Lisp_String *) p)->data != NULL);
3431 } 3438 }
3432 else 3439 else
3433 return 0; 3440 return 0;
3434 } 3441 }
3449 3456
3450 /* P must point to the start of a Lisp_Cons, not be 3457 /* P must point to the start of a Lisp_Cons, not be
3451 one of the unused cells in the current cons block, 3458 one of the unused cells in the current cons block,
3452 and not be on the free-list. */ 3459 and not be on the free-list. */
3453 return (offset >= 0 3460 return (offset >= 0
3461 && offset % sizeof b->conses[0] == 0
3454 && offset < (CONS_BLOCK_SIZE * sizeof b->conses[0]) 3462 && offset < (CONS_BLOCK_SIZE * sizeof b->conses[0])
3455 && offset % sizeof b->conses[0] == 0
3456 && (b != cons_block 3463 && (b != cons_block
3457 || offset / sizeof b->conses[0] < cons_block_index) 3464 || offset / sizeof b->conses[0] < cons_block_index)
3458 && !EQ (((struct Lisp_Cons *) p)->car, Vdead)); 3465 && !EQ (((struct Lisp_Cons *) p)->car, Vdead));
3459 } 3466 }
3460 else 3467 else
3478 /* P must point to the start of a Lisp_Symbol, not be 3485 /* P must point to the start of a Lisp_Symbol, not be
3479 one of the unused cells in the current symbol block, 3486 one of the unused cells in the current symbol block,
3480 and not be on the free-list. */ 3487 and not be on the free-list. */
3481 return (offset >= 0 3488 return (offset >= 0
3482 && offset % sizeof b->symbols[0] == 0 3489 && offset % sizeof b->symbols[0] == 0
3490 && offset < (SYMBOL_BLOCK_SIZE * sizeof b->symbols[0])
3483 && (b != symbol_block 3491 && (b != symbol_block
3484 || offset / sizeof b->symbols[0] < symbol_block_index) 3492 || offset / sizeof b->symbols[0] < symbol_block_index)
3485 && !EQ (((struct Lisp_Symbol *) p)->function, Vdead)); 3493 && !EQ (((struct Lisp_Symbol *) p)->function, Vdead));
3486 } 3494 }
3487 else 3495 else
3503 int offset = (char *) p - (char *) &b->floats[0]; 3511 int offset = (char *) p - (char *) &b->floats[0];
3504 3512
3505 /* P must point to the start of a Lisp_Float and not be 3513 /* P must point to the start of a Lisp_Float and not be
3506 one of the unused cells in the current float block. */ 3514 one of the unused cells in the current float block. */
3507 return (offset >= 0 3515 return (offset >= 0
3516 && offset % sizeof b->floats[0] == 0
3508 && offset < (FLOAT_BLOCK_SIZE * sizeof b->floats[0]) 3517 && offset < (FLOAT_BLOCK_SIZE * sizeof b->floats[0])
3509 && offset % sizeof b->floats[0] == 0
3510 && (b != float_block 3518 && (b != float_block
3511 || offset / sizeof b->floats[0] < float_block_index)); 3519 || offset / sizeof b->floats[0] < float_block_index));
3512 } 3520 }
3513 else 3521 else
3514 return 0; 3522 return 0;
3531 /* P must point to the start of a Lisp_Misc, not be 3539 /* P must point to the start of a Lisp_Misc, not be
3532 one of the unused cells in the current misc block, 3540 one of the unused cells in the current misc block,
3533 and not be on the free-list. */ 3541 and not be on the free-list. */
3534 return (offset >= 0 3542 return (offset >= 0
3535 && offset % sizeof b->markers[0] == 0 3543 && offset % sizeof b->markers[0] == 0
3544 && offset < (MARKER_BLOCK_SIZE * sizeof b->markers[0])
3536 && (b != marker_block 3545 && (b != marker_block
3537 || offset / sizeof b->markers[0] < marker_block_index) 3546 || offset / sizeof b->markers[0] < marker_block_index)
3538 && ((union Lisp_Misc *) p)->u_marker.type != Lisp_Misc_Free); 3547 && ((union Lisp_Misc *) p)->u_marker.type != Lisp_Misc_Free);
3539 } 3548 }
3540 else 3549 else