comparison src/alloc.c @ 3024:b7f26b2f78bd

[xemacs-hg @ 2005-10-25 08:32:40 by ben] more mc-alloc-related factoring; make it hard to do the wrong thing postgresql/postgresql.c, postgresql/postgresql.h: MC-Alloc refactoring. ldap/eldap.c, ldap/eldap.h: MC-Alloc refactoring. alloc.c, buffer.c, console.c, emacs.c, file-coding.c, lrecord.h, lstream.c, mule-charset.c, print.c, scrollbar-gtk.c, scrollbar-msw.c, scrollbar-x.c, scrollbar.c, symbols.c, symeval.h, unicode.c, window.c, xemacs.def.in.in: rename `struct lcrecord_header' to `struct old_lcrecord_header'; likewise for `old_basic_alloc_lcrecord', `old_free_lcrecord', `old_zero_lcrecord', `old_zero_sized_lcrecord', `old_copy_lcrecord', `old_copy_sized_lcrecord', `old_alloc_lcrecord_type'. Created new LISPOBJ_STORAGE_SIZE() used only on objects created through allocation of Lisp-Object memory instead of basic xmalloc()/xfree(). This is distinguished from malloced_storage_size(), for non-Lisp-Objects. The definition of LISPOBJ_STORAGE_SIZE() can reduce down to malloced_storage_size() when not MC-ALLOC, but with MC-ALLOC it's a different function. The whole point other than cleaning up the use of LISPOBJ_STORAGE_SIZE is to make it harder to accidentally use the old kind (lowercase) of function in new code, since you get a compile error.
author ben
date Tue, 25 Oct 2005 08:32:50 +0000
parents 1e7cc382eb16
children d30cd499e445
comparison
equal deleted inserted replaced
3023:d305f4207861 3024:b7f26b2f78bd
585 585
586 #ifndef MC_ALLOC 586 #ifndef MC_ALLOC
587 /* lcrecords are chained together through their "next" field. 587 /* lcrecords are chained together through their "next" field.
588 After doing the mark phase, GC will walk this linked list 588 After doing the mark phase, GC will walk this linked list
589 and free any lcrecord which hasn't been marked. */ 589 and free any lcrecord which hasn't been marked. */
590 static struct lcrecord_header *all_lcrecords; 590 static struct old_lcrecord_header *all_lcrecords;
591 #endif /* not MC_ALLOC */ 591 #endif /* not MC_ALLOC */
592 592
593 #ifdef MC_ALLOC 593 #ifdef MC_ALLOC
594 /* The basic lrecord allocation functions. See lrecord.h for details. */ 594 /* The basic lrecord allocation functions. See lrecord.h for details. */
595 void * 595 void *
651 /* The most basic of the lcrecord allocation functions. Not usually called 651 /* The most basic of the lcrecord allocation functions. Not usually called
652 directly. Allocates an lrecord not managed by any lcrecord-list, of a 652 directly. Allocates an lrecord not managed by any lcrecord-list, of a
653 specified size. See lrecord.h. */ 653 specified size. See lrecord.h. */
654 654
655 void * 655 void *
656 basic_alloc_lcrecord (Bytecount size, 656 old_basic_alloc_lcrecord (Bytecount size,
657 const struct lrecord_implementation *implementation) 657 const struct lrecord_implementation *implementation)
658 { 658 {
659 struct lcrecord_header *lcheader; 659 struct old_lcrecord_header *lcheader;
660 660
661 type_checking_assert 661 type_checking_assert
662 ((implementation->static_size == 0 ? 662 ((implementation->static_size == 0 ?
663 implementation->size_in_bytes_method != NULL : 663 implementation->size_in_bytes_method != NULL :
664 implementation->static_size == size) 664 implementation->static_size == size)
665 && 665 &&
666 (! implementation->basic_p) 666 (! implementation->basic_p)
667 && 667 &&
668 (! (implementation->hash == NULL && implementation->equal != NULL))); 668 (! (implementation->hash == NULL && implementation->equal != NULL)));
669 669
670 lcheader = (struct lcrecord_header *) allocate_lisp_storage (size); 670 lcheader = (struct old_lcrecord_header *) allocate_lisp_storage (size);
671 set_lheader_implementation (&lcheader->lheader, implementation); 671 set_lheader_implementation (&lcheader->lheader, implementation);
672 lcheader->next = all_lcrecords; 672 lcheader->next = all_lcrecords;
673 #if 1 /* mly prefers to see small ID numbers */ 673 #if 1 /* mly prefers to see small ID numbers */
674 lcheader->uid = lrecord_uid_counter++; 674 lcheader->uid = lrecord_uid_counter++;
675 #else /* jwz prefers to see real addrs */ 675 #else /* jwz prefers to see real addrs */
687 * Only call it if you really feel you must (and if the 687 * Only call it if you really feel you must (and if the
688 * lrecord was fairly recently allocated). 688 * lrecord was fairly recently allocated).
689 * Otherwise, just let the GC do its job -- that's what it's there for 689 * Otherwise, just let the GC do its job -- that's what it's there for
690 */ 690 */
691 void 691 void
692 very_old_free_lcrecord (struct lcrecord_header *lcrecord) 692 very_old_free_lcrecord (struct old_lcrecord_header *lcrecord)
693 { 693 {
694 if (all_lcrecords == lcrecord) 694 if (all_lcrecords == lcrecord)
695 { 695 {
696 all_lcrecords = lcrecord->next; 696 all_lcrecords = lcrecord->next;
697 } 697 }
698 else 698 else
699 { 699 {
700 struct lrecord_header *header = all_lcrecords; 700 struct old_lcrecord_header *header = all_lcrecords;
701 for (;;) 701 for (;;)
702 { 702 {
703 struct lrecord_header *next = header->next; 703 struct old_lcrecord_header *next = header->next;
704 if (next == lcrecord) 704 if (next == lcrecord)
705 { 705 {
706 header->next = lrecord->next; 706 header->next = lrecord->next;
707 break; 707 break;
708 } 708 }
725 disksave_object_finalization_1 (void) 725 disksave_object_finalization_1 (void)
726 { 726 {
727 #ifdef MC_ALLOC 727 #ifdef MC_ALLOC
728 mc_finalize_for_disksave (); 728 mc_finalize_for_disksave ();
729 #else /* not MC_ALLOC */ 729 #else /* not MC_ALLOC */
730 struct lcrecord_header *header; 730 struct old_lcrecord_header *header;
731 731
732 for (header = all_lcrecords; header; header = header->next) 732 for (header = all_lcrecords; header; header = header->next)
733 { 733 {
734 if (LHEADER_IMPLEMENTATION (&header->lheader)->finalizer && 734 if (LHEADER_IMPLEMENTATION (&header->lheader)->finalizer &&
735 !header->free) 735 !header->free)
758 if (imp->basic_p) 758 if (imp->basic_p)
759 memcpy ((char *) XRECORD_LHEADER (dst) + sizeof (struct lrecord_header), 759 memcpy ((char *) XRECORD_LHEADER (dst) + sizeof (struct lrecord_header),
760 (char *) XRECORD_LHEADER (src) + sizeof (struct lrecord_header), 760 (char *) XRECORD_LHEADER (src) + sizeof (struct lrecord_header),
761 size - sizeof (struct lrecord_header)); 761 size - sizeof (struct lrecord_header));
762 else 762 else
763 memcpy ((char *) XRECORD_LHEADER (dst) + sizeof (struct lcrecord_header), 763 memcpy ((char *) XRECORD_LHEADER (dst) +
764 (char *) XRECORD_LHEADER (src) + sizeof (struct lcrecord_header), 764 sizeof (struct old_lcrecord_header),
765 size - sizeof (struct lcrecord_header)); 765 (char *) XRECORD_LHEADER (src) +
766 sizeof (struct old_lcrecord_header),
767 size - sizeof (struct old_lcrecord_header));
766 #endif /* not MC_ALLOC */ 768 #endif /* not MC_ALLOC */
767 } 769 }
768 770
769 771
770 /************************************************************************/ 772 /************************************************************************/
2885 /************************************************************************/ 2887 /************************************************************************/
2886 /* lcrecord lists */ 2888 /* lcrecord lists */
2887 /************************************************************************/ 2889 /************************************************************************/
2888 2890
2889 /* Lcrecord lists are used to manage the allocation of particular 2891 /* Lcrecord lists are used to manage the allocation of particular
2890 sorts of lcrecords, to avoid calling basic_alloc_lcrecord() (and thus 2892 sorts of lcrecords, to avoid calling BASIC_ALLOC_LCRECORD() (and thus
2891 malloc() and garbage-collection junk) as much as possible. 2893 malloc() and garbage-collection junk) as much as possible.
2892 It is similar to the Blocktype class. 2894 It is similar to the Blocktype class.
2893 2895
2894 See detailed comment in lcrecord.h. 2896 See detailed comment in lcrecord.h.
2895 */ 2897 */
2957 2959
2958 Lisp_Object 2960 Lisp_Object
2959 make_lcrecord_list (Elemcount size, 2961 make_lcrecord_list (Elemcount size,
2960 const struct lrecord_implementation *implementation) 2962 const struct lrecord_implementation *implementation)
2961 { 2963 {
2962 /* Don't use alloc_lcrecord_type() avoid infinite recursion 2964 /* Don't use old_alloc_lcrecord_type() avoid infinite recursion
2963 allocating this, */ 2965 allocating this, */
2964 struct lcrecord_list *p = (struct lcrecord_list *) 2966 struct lcrecord_list *p = (struct lcrecord_list *)
2965 basic_alloc_lcrecord (sizeof (struct lcrecord_list), 2967 old_basic_alloc_lcrecord (sizeof (struct lcrecord_list),
2966 &lrecord_lcrecord_list); 2968 &lrecord_lcrecord_list);
2967 2969
2968 p->implementation = implementation; 2970 p->implementation = implementation;
2969 p->size = size; 2971 p->size = size;
2970 p->free = Qnil; 2972 p->free = Qnil;
2971 return wrap_lcrecord_list (p); 2973 return wrap_lcrecord_list (p);
3003 3005
3004 list->free = free_header->chain; 3006 list->free = free_header->chain;
3005 free_header->lcheader.free = 0; 3007 free_header->lcheader.free = 0;
3006 /* Put back the correct type, as we set it to lrecord_type_free. */ 3008 /* Put back the correct type, as we set it to lrecord_type_free. */
3007 lheader->type = list->implementation->lrecord_type_index; 3009 lheader->type = list->implementation->lrecord_type_index;
3008 zero_sized_lcrecord (free_header, list->size); 3010 old_zero_sized_lcrecord (free_header, list->size);
3009 return val; 3011 return val;
3010 } 3012 }
3011 else 3013 else
3012 return wrap_pointer_1 (basic_alloc_lcrecord (list->size, 3014 return wrap_pointer_1 (old_basic_alloc_lcrecord (list->size,
3013 list->implementation)); 3015 list->implementation));
3014 } 3016 }
3015 3017
3016 /* "Free" a Lisp object LCRECORD by placing it on its associated free list 3018 /* "Free" a Lisp object LCRECORD by placing it on its associated free list
3017 LCRECORD_LIST; next time alloc_managed_lcrecord() is called with the 3019 LCRECORD_LIST; next time alloc_managed_lcrecord() is called with the
3018 same LCRECORD_LIST as its parameter, it will return an object from the 3020 same LCRECORD_LIST as its parameter, it will return an object from the
3079 return XPNTR (alloc_managed_lcrecord 3081 return XPNTR (alloc_managed_lcrecord
3080 (all_lcrecord_lists[imp->lrecord_type_index])); 3082 (all_lcrecord_lists[imp->lrecord_type_index]));
3081 } 3083 }
3082 3084
3083 void 3085 void
3084 free_lcrecord (Lisp_Object rec) 3086 old_free_lcrecord (Lisp_Object rec)
3085 { 3087 {
3086 int type = XRECORD_LHEADER (rec)->type; 3088 int type = XRECORD_LHEADER (rec)->type;
3087 3089
3088 assert (!EQ (all_lcrecord_lists[type], Qzero)); 3090 assert (!EQ (all_lcrecord_lists[type], Qzero));
3089 3091
3615 gc_checking_assert (! LRECORD_FREE_P (lheader)); 3617 gc_checking_assert (! LRECORD_FREE_P (lheader));
3616 #else /* MC_ALLOC */ 3618 #else /* MC_ALLOC */
3617 #define GC_CHECK_NOT_FREE(lheader) \ 3619 #define GC_CHECK_NOT_FREE(lheader) \
3618 gc_checking_assert (! LRECORD_FREE_P (lheader)); \ 3620 gc_checking_assert (! LRECORD_FREE_P (lheader)); \
3619 gc_checking_assert (LHEADER_IMPLEMENTATION (lheader)->basic_p || \ 3621 gc_checking_assert (LHEADER_IMPLEMENTATION (lheader)->basic_p || \
3620 ! ((struct lcrecord_header *) lheader)->free) 3622 ! ((struct old_lcrecord_header *) lheader)->free)
3621 #endif /* MC_ALLOC */ 3623 #endif /* MC_ALLOC */
3622 3624
3623 #ifdef USE_KKCC 3625 #ifdef USE_KKCC
3624 /* The following functions implement the new mark algorithm. 3626 /* The following functions implement the new mark algorithm.
3625 They mark objects according to their descriptions. They 3627 They mark objects according to their descriptions. They
4146 static void 4148 static void
4147 tick_lcrecord_stats (const struct lrecord_header *h, int free_p) 4149 tick_lcrecord_stats (const struct lrecord_header *h, int free_p)
4148 { 4150 {
4149 int type_index = h->type; 4151 int type_index = h->type;
4150 4152
4151 if (((struct lcrecord_header *) h)->free) 4153 if (((struct old_lcrecord_header *) h)->free)
4152 { 4154 {
4153 gc_checking_assert (!free_p); 4155 gc_checking_assert (!free_p);
4154 lcrecord_stats[type_index].instances_on_free_list++; 4156 lcrecord_stats[type_index].instances_on_free_list++;
4155 } 4157 }
4156 else 4158 else
4173 4175
4174 4176
4175 #ifndef MC_ALLOC 4177 #ifndef MC_ALLOC
4176 /* Free all unmarked records */ 4178 /* Free all unmarked records */
4177 static void 4179 static void
4178 sweep_lcrecords_1 (struct lcrecord_header **prev, int *used) 4180 sweep_lcrecords_1 (struct old_lcrecord_header **prev, int *used)
4179 { 4181 {
4180 struct lcrecord_header *header; 4182 struct old_lcrecord_header *header;
4181 int num_used = 0; 4183 int num_used = 0;
4182 /* int total_size = 0; */ 4184 /* int total_size = 0; */
4183 4185
4184 xzero (lcrecord_stats); /* Reset all statistics to 0. */ 4186 xzero (lcrecord_stats); /* Reset all statistics to 0. */
4185 4187
4220 header = *prev; 4222 header = *prev;
4221 tick_lcrecord_stats (h, 0); 4223 tick_lcrecord_stats (h, 0);
4222 } 4224 }
4223 else 4225 else
4224 { 4226 {
4225 struct lcrecord_header *next = header->next; 4227 struct old_lcrecord_header *next = header->next;
4226 *prev = next; 4228 *prev = next;
4227 tick_lcrecord_stats (h, 1); 4229 tick_lcrecord_stats (h, 1);
4228 /* used to call finalizer right here. */ 4230 /* used to call finalizer right here. */
4229 xfree (header, struct lcrecord_header *); 4231 xfree (header, struct old_lcrecord_header *);
4230 header = next; 4232 header = next;
4231 } 4233 }
4232 } 4234 }
4233 *used = num_used; 4235 *used = num_used;
4234 /* *total = total_size; */ 4236 /* *total = total_size; */