diff src/alloc.c @ 2720:6fa9919a9a0b

[xemacs-hg @ 2005-04-08 23:10:01 by crestani] ChangeLog addition: 2005-04-01  Marcus Crestani  <crestani@xemacs.org>         The new allocator.         New configure flag: `MC_ALLOC':         * configure.ac (XE_COMPLEX_ARG_ENABLE): Add `--enable-mc-alloc' as         a new configure flag.         * configure.in (AC_INIT_PARSE_ARGS): Add `--mc-alloc' as a new         configure flag.         * configure.usage: Add description for `mc-alloc'.         DUMP_IN_EXEC:         * Makefile.in.in: Condition the installation of a separate dump         file on !DUMP_ON_EXEC.         * configure.ac (XE_COMPLEX_ARG_ENABLE): Add         `--enable-dump-in-exec' as a new configure flag.         * configure.ac: DUMP_IN_EXEC is define as default for PDUMP but         not default for MC_ALLOC.         * configure.in (AC_INIT_PARSE_ARGS): Add `--dump-in-exec' as a         new configure flag.         * configure.in: DUMP_IN_EXEC is define as default for PDUMP but         not default for MC_ALLOC.         * configure.usage: Add description for `dump-in-exec'. lib-src/ChangeLog addition: 2005-04-01  Marcus Crestani  <crestani@xemacs.org>         The new allocator.         DUMP_IN_EXEC:                  * Makefile.in.in: Only compile insert-data-in-exec if         DUMP_IN_EXEC is defined. lisp/ChangeLog addition: 2005-04-01  Marcus Crestani  <crestani@xemacs.org>         The new allocator.         MEMORY_USAGE_STATS         * diagnose.el: Add new lisp function to pretty print statistics         about the new allocator.         * diagnose.el (show-mc-alloc-memory-usage): New. modules/ChangeLog addition: 2005-04-01  Marcus Crestani  <crestani@xemacs.org>         The new allocator.         Remove Lcrecords:                  * postgresql/postgresql.c (allocate_pgconn): Allocate with new         allocator.         * postgresql/postgresql.c (allocate_pgresult): Allocate PGresult         with new allocator.           * postgresql/postgresql.h (struct Lisp_PGconn): Add         lrecord_header.         * postgresql/postgresql.h (struct Lisp_PGresult): Add         lrecord_header.         * ldap/eldap.c (allocate_ldap): Allocate with new allocator.         * ldap/eldap.h (struct Lisp_LDAP): Add lrecord_header. nt/ChangeLog addition: 2005-04-01  Marcus Crestani  <crestani@xemacs.org>         The new allocator.         New configure flag: `MC_ALLOC':         * config.inc.samp: Add new flag `MC_ALLOC'.         * xemacs.mak: Add flag and configuration output for `MC_ALLOC'.         New files:         * xemacs.dsp: Add source files mc-alloc.c and mc-alloc.h.         * xemacs.mak: Add new object file mc-alloc.obj to dependencies. src/ChangeLog addition: 2005-04-01  Marcus Crestani  <crestani@xemacs.org>         The new allocator.         New configure flag: `MC_ALLOC':         * config.h.in: Add new flag `MC_ALLOC'.         New files:         * Makefile.in.in: Add new object file mc-alloc.o.         * depend: Add new files to dependencies.         * mc-alloc.c: New.         * mc-alloc.h: New.         Running the new allocator from XEmacs:         * alloc.c (deadbeef_memory): Moved to mc-alloc.c.         * emacs.c (main_1): Initialize the new allocator and add         syms_of_mc_alloc.         * symsinit.h: Add syms_of_mc_alloc.         New lrecord allocation and free functions:         * alloc.c (alloc_lrecord): New. Allocates an lrecord, includes         type checking and initializing of the lrecord_header.         * alloc.c (noseeum_alloc_lrecord): Same as above, but increments         the NOSEEUM cons counter.         * alloc.c (free_lrecord): New. Calls the finalizer and frees the         lrecord.         * lrecord.h: Add lrecord allocation prototypes and comments.         Remove old lrecord FROB block allocation:                  * alloc.c (allocate_lisp_storage): Former function to expand         heap. Not needed anymore, remove.         * alloc.c: Completely remove `Fixed-size type macros'         * alloc.c (release_breathing_space): Remove.         * alloc.c (memory_full): Remove release_breathing_space.         * alloc.c (refill_memory_reserve): Remove.         * alloc.c (TYPE_ALLOC_SIZE): Remove.         * alloc.c (DECLARE_FIXED_TYPE_ALLOC): Remove.         * alloc.c (ALLOCATE_FIXED_TYPE_FROM_BLOCK): Remove.         * alloc.c (ALLOCATE_FIXED_TYPE_1): Remove.         * alloc.c (ALLOCATE_FIXED_TYPE): Remove.         * alloc.c (NOSEEUM_ALLOCATE_FIXED_TYPE): Remove.         * alloc.c (struct Lisp_Free): Remove.         * alloc.c (LRECORD_FREE_P): Remove.         * alloc.c (MARK_LRECORD_AS_FREE): Remove.         * alloc.c (MARK_LRECORD_AS_NOT_FREE): Remove.         * alloc.c (PUT_FIXED_TYPE_ON_FREE_LIST): Remove.         * alloc.c (FREE_FIXED_TYPE): Remove.         * alloc.c (FREE_FIXED_TYPE_WHEN_NOT_IN_GC): Remove.         Allocate old lrecords with new allocator:                  * alloc.c: DECLARE_FIXED_TYPE_ALLOC removed for all lrecords         defined in alloc.c.         * alloc.c (Fcons): Allocate with new allocator.         * alloc.c (noseeum_cons): Allocate with new allocator.         * alloc.c (make_float): Allocate with new allocator.         * alloc.c (make_bignum): Allocate with new allocator.         * alloc.c (make_bignum_bg): Allocate with new allocator.         * alloc.c (make_ratio): Allocate with new allocator.         * alloc.c (make_ratio_bg): Allocate with new allocator.         * alloc.c (make_ratio_rt): Allocate with new allocator.         * alloc.c (make_bigfloat): Allocate with new allocator.         * alloc.c (make_bigfloat_bf): Allocate with new allocator.         * alloc.c (make_compiled_function): Allocate with new allocator.         * alloc.c (Fmake_symbol): Allocate with new allocator.         * alloc.c (allocate_extent): Allocate with new allocator.         * alloc.c (allocate_event): Allocate with new allocator.         * alloc.c (make_key_data): Allocate with new allocator.         * alloc.c (make_button_data): Allocate with new allocator.         * alloc.c (make_motion_data): Allocate with new allocator.         * alloc.c (make_process_data): Allocate with new allocator.         * alloc.c (make_timeout_data): Allocate with new allocator.         * alloc.c (make_magic_data): Allocate with new allocator.         * alloc.c (make_magic_eval_data): Allocate with new allocator.         * alloc.c (make_eval_data): Allocate with new allocator.         * alloc.c (make_misc_user_data): Allocate with new allocator.         * alloc.c (Fmake_marker): Allocate with new allocator.         * alloc.c (noseeum_make_marker): Allocate with new allocator.         * alloc.c (make_uninit_string): Allocate with new allocator.         * alloc.c (resize_string): Allocate with new allocator.         * alloc.c (make_string_nocopy): Allocate with new allocator.         Garbage Collection:         * alloc.c (GC_CHECK_NOT_FREE): Remove obsolete assertions.         * alloc.c (SWEEP_FIXED_TYPE_BLOCK): Remove.         * alloc.c (SWEEP_FIXED_TYPE_BLOCK_1): Remove.         * alloc.c (sweep_conses): Remove.         * alloc.c (free_cons): Use new allocator to free.         * alloc.c (sweep_compiled_functions): Remove.         * alloc.c (sweep_floats): Remove.         * alloc.c (sweep_bignums): Remove.         * alloc.c (sweep_ratios): Remove.         * alloc.c (sweep_bigfloats): Remove.         * alloc.c (sweep_symbols): Remove.         * alloc.c (sweep_extents): Remove.         * alloc.c (sweep_events): Remove.         * alloc.c (sweep_key_data): Remove.         * alloc.c (free_key_data): Use new allocator to free.         * alloc.c (sweep_button_data): Remove.         * alloc.c (free_button_data): Use new allocator to free.         * alloc.c (sweep_motion_data): Remove.         * alloc.c (free_motion_data): Use new allocator to free.         * alloc.c (sweep_process_data): Remove.         * alloc.c (free_process_data): Use new allocator to free.         * alloc.c (sweep_timeout_data): Remove.         * alloc.c (free_timeout_data): Use new allocator to free.         * alloc.c (sweep_magic_data): Remove.         * alloc.c (free_magic_data): Use new allocator to free.         * alloc.c (sweep_magic_eval_data): Remove.         * alloc.c (free_magic_eval_data): Use new allocator to free.         * alloc.c (sweep_eval_data): Remove.         * alloc.c (free_eval_data): Use new allocator to free.         * alloc.c (sweep_misc_user_data): Remove.         * alloc.c (free_misc_user_data): Use new allocator to free.         * alloc.c (sweep_markers): Remove.         * alloc.c (free_marker): Use new allocator to free.         * alloc.c (garbage_collect_1): Remove release_breathing_space.         * alloc.c (gc_sweep): Remove all the old lcrecord and lrecord         related stuff. Sweeping now works like this: compact string         chars, finalize, sweep.         * alloc.c (common_init_alloc_early): Remove old lrecord         initializations, remove breathing_space.         * emacs.c (Fdump_emacs): Remove release_breathing_space.         * lisp.h: Remove prototype for release_breathing_space.         * lisp.h: Adjust the special cons mark makros.         Lrecord Finalizer:         * alloc.c: Add finalizer to lrecord definition.         * alloc.c (finalize_string): Add finalizer for string.         * bytecode.c: Add finalizer to lrecord definition.         * bytecode.c (finalize_compiled_function): Add finalizer for         compiled function.         * marker.c: Add finalizer to lrecord definition.         * marker.c (finalize_marker): Add finalizer for marker.         These changes build the interface to mc-alloc:         * lrecord.h (MC_ALLOC_CALL_FINALIZER): Tell mc-alloc how to         finalize lrecords.         * lrecord.h (MC_ALLOC_CALL_FINALIZER_FOR_DISKSAVE): Tell         mc-alloc how to finalize for disksave.         Unify lrecords and lcrecords:         * lisp.h (struct Lisp_String): Adjust string union hack to         new lrecord header.         * lrecord.h: Adjust comments.         * lrecord.h (struct lrecord_header): The new lrecord header         includes type, lisp-readonly, free, and uid.         * lrecord.h (set_lheader_implementation): Adjust to new         lrecord_header.         * lrecord.h (struct lrecord_implementation): The field basic_p         for indication of an old lrecord is not needed anymore, remove.         * lrecord.h (MAKE_LRECORD_IMPLEMENTATION): Remove basic_p.         * lrecord.h (MAKE_EXTERNAL_LRECORD_IMPLEMENTATION): Remove         basic_p.         * lrecord.h (copy_sized_lrecord): Remove distinction between         old lrecords and lcrecords.         * lrecord.h (copy_lrecord): Remove distinction between old         lrecords and lcrecords.         * lrecord.h (zero_sized_lrecord): Remove distinction between         old lrecords and lcrecords.         * lrecord.h (zero_lrecord): Remove distinction between old         lrecords and lcrecords.         Remove lcrecords and lcrecord lists:         * alloc.c (basic_alloc_lcrecord): Not needed anymore, remove.         * alloc.c (very_old_free_lcrecord): Not needed anymore, remove.         * alloc.c (copy_lisp_object): No more distinction between         lrecords and lcrecords.         * alloc.c (all_lcrecords): Not needed anymore, remove.         * alloc.c (make_vector_internal): Allocate as lrecord.         * alloc.c (make_bit_vector_internal): Allocate as lrecord.         * alloc.c: Completely remove `lcrecord lists'.         * alloc.c (free_description): Remove.         * alloc.c (lcrecord_list_description): Remove.         * alloc.c (mark_lcrecord_list): Remove.         * alloc.c (make_lcrecord_list): Remove.         * alloc.c (alloc_managed_lcrecord): Remove.         * alloc.c (free_managed_lcrecord): Remove.         * alloc.c (alloc_automanaged_lcrecord): Remove.         * alloc.c (free_lcrecord): Remove.         * alloc.c (lcrecord_stats): Remove.         * alloc.c (tick_lcrecord_stats): Remove.         * alloc.c (disksave_object_finalization_1): Add call to         mc_finalize_for_disksave. Remove the lcrecord way to visit all         objects.         * alloc.c (kkcc_marking): Remove XD_FLAG_FREE_LISP_OBJECT         * alloc.c (sweep_lcrecords_1): Remove.         * alloc.c (common_init_alloc_early): Remove everything related         to lcrecords, remove old lrecord initializations,         * alloc.c (init_lcrecord_lists): Not needed anymore, remove.         * alloc.c (reinit_alloc_early): Remove everything related to         lcrecords.         * alloc.c (init_alloc_once_early): Remove everything related to         lcrecords.         * buffer.c (allocate_buffer): Allocate as lrecord.         * buffer.c (nuke_all_buffer_slots): Use lrecord functions.         * buffer.c (common_init_complex_vars_of_buffer): Allocate as         lrecord.         * buffer.h (struct buffer): Add lrecord_header.         * casetab.c (allocate_case_table): Allocate as lrecord.         * casetab.h (struct Lisp_Case_Table): Add lrecord_header.         * charset.h (struct Lisp_Charset): Add lrecord_header.         * chartab.c (fill_char_table): Use lrecord functions.         * chartab.c (Fmake_char_table): Allocate as lrecord.         * chartab.c (make_char_table_entry): Allocate as lrecord.         * chartab.c (copy_char_table_entry): Allocate as lrecord.         * chartab.c (Fcopy_char_table): Allocate as lrecord.         * chartab.c (put_char_table): Use lrecord functions.         * chartab.h (struct Lisp_Char_Table_Entry): Add lrecord_header.         * chartab.h (struct Lisp_Char_Table): Add lrecord_header.         * console-impl.h (struct console): Add lrecord_header.         * console-msw-impl.h (struct Lisp_Devmode): Add lrecord_header.         * console-msw-impl.h (struct mswindows_dialog_id): Add         lrecord_header.         * console.c (allocate_console): Allocate as lrecord.         * console.c (nuke_all_console_slots): Use lrecord functions.         * console.c (common_init_complex_vars_of_console): Allocate as         lrecord.         * data.c (make_weak_list): Allocate as lrecord.         * data.c (make_weak_box): Allocate as lrecord.         * data.c (make_ephemeron): Allocate as lrecord.         * database.c (struct Lisp_Database): Add lrecord_header.         * database.c (allocate_database): Allocate as lrecord.         * device-impl.h (struct device): Add lrecord_header.         * device-msw.c (allocate_devmode): Allocate as lrecord.         * device.c (nuke_all_device_slots): Use lrecord functions.         * device.c (allocate_device): Allocate as lrecord.         * dialog-msw.c (handle_question_dialog_box): Allocate as lrecord.         * elhash.c (struct Lisp_Hash_Table): Add lrecord_header.         * elhash.c (make_general_lisp_hash_table): Allocate as lrecord.         * elhash.c (Fcopy_hash_table): Allocate as lrecord.         * event-stream.c: Lcrecord lists Vcommand_builder_free_list and         Vtimeout_free_list are no longer needed. Remove.         * event-stream.c (allocate_command_builder): Allocate as lrecord.         * event-stream.c (free_command_builder): Use lrecord functions.         * event-stream.c (event_stream_generate_wakeup): Allocate as         lrecord.         * event-stream.c (event_stream_resignal_wakeup): Use lrecord         functions.         * event-stream.c (event_stream_disable_wakeup): Use lrecord         functions.         * event-stream.c (reinit_vars_of_event_stream): Lcrecord lists         remove.         * events.h (struct Lisp_Timeout): Add lrecord_header.         * events.h (struct command_builder): Add lrecord_header.         * extents-impl.h (struct extent_auxiliary): Add lrecord_header.         * extents-impl.h (struct extent_info): Add lrecord_header.         * extents.c (allocate_extent_auxiliary): Allocate as lrecord.         * extents.c (allocate_extent_info): Allocate as lrecord.         * extents.c (copy_extent): Allocate as lrecord.         * faces.c (allocate_face): Allocate as lrecord.         * faces.h (struct Lisp_Face): Add lrecord_header.         * file-coding.c (allocate_coding_system): Allocate as lrecord.         * file-coding.c (Fcopy_coding_system): Allocate as lrecord.         * file-coding.h (struct Lisp_Coding_System): Add lrecord_header.         * fns.c (Ffillarray): Allocate as lrecord.         * frame-impl.h (struct frame): Add lrecord_header.         * frame.c (nuke_all_frame_slots): Use lrecord functions.         * frame.c (allocate_frame_core): Allocate as lrecord.         * glyphs.c (allocate_image_instance): Allocate as lrecord.         * glyphs.c (Fcolorize_image_instance): Allocate as lrecord.         * glyphs.c (allocate_glyph): Allocate as lrecord.         * glyphs.h (struct Lisp_Image_Instance): Add lrecord_header.         * glyphs.h (struct Lisp_Glyph): Add lrecord_header.         * gui.c (allocate_gui_item): Allocate as lrecord.         * gui.h (struct Lisp_Gui_Item): Add lrecord_header.         * keymap.c (struct Lisp_Keymap): Add lrecord_header.         * keymap.c (make_keymap): Allocate as lrecord.         * lisp.h (struct Lisp_Vector): Add lrecord_header.         * lisp.h (struct Lisp_Bit_Vector): Add lrecord_header.         * lisp.h (struct weak_box): Add lrecord_header.         * lisp.h (struct ephemeron): Add lrecord_header.         * lisp.h (struct weak_list): Add lrecord_header.         * lrecord.h (struct lcrecord_header): Not used, remove.         * lrecord.h (struct free_lcrecord_header): Not used, remove.         * lrecord.h (struct lcrecord_list): Not needed anymore, remove.         * lrecord.h (lcrecord_list): Not needed anymore, remove.         * lrecord.h: (enum data_description_entry_flags): Remove         XD_FLAG_FREE_LISP_OBJECT.         * lstream.c: Lrecord list Vlstream_free_list remove.         * lstream.c (Lstream_new): Allocate as lrecord.         * lstream.c (Lstream_delete): Use lrecod functions.         * lstream.c (reinit_vars_of_lstream): Vlstream_free_list         initialization remove.           * lstream.h (struct lstream): Add lrecord_header.         * emacs.c (main_1): Remove lstream initialization.         * mule-charset.c (make_charset): Allocate as lrecord.         * objects-impl.h (struct Lisp_Color_Instance): Add         lrecord_header.         * objects-impl.h (struct Lisp_Font_Instance): Add lrecord_header.         * objects.c (Fmake_color_instance): Allocate as lrecord.         * objects.c (Fmake_font_instance): Allocate as lrecord.         * objects.c (reinit_vars_of_objects): Allocate as lrecord.         * opaque.c: Lcreord list Vopaque_ptr_list remove.         * opaque.c (make_opaque): Allocate as lrecord.         * opaque.c (make_opaque_ptr): Allocate as lrecord.         * opaque.c (free_opaque_ptr): Use lrecord functions.         * opaque.c (reinit_opaque_early):         * opaque.c (init_opaque_once_early): Vopaque_ptr_list         initialization remove.         * opaque.h (Lisp_Opaque): Add lrecord_header.         * opaque.h (Lisp_Opaque_Ptr): Add lrecord_header.         * emacs.c (main_1): Remove opaque variable initialization.         * print.c (default_object_printer): Use new lrecord_header.         * print.c (print_internal): Use new lrecord_header.         * print.c (debug_p4): Use new lrecord_header.         * process.c (make_process_internal): Allocate as lrecord.         * procimpl.h (struct Lisp_Process): Add lrecord_header.         * rangetab.c (Fmake_range_table): Allocate as lrecord.         * rangetab.c (Fcopy_range_table): Allocate as lrecord.         * rangetab.h (struct Lisp_Range_Table): Add lrecord_header.         * scrollbar.c (create_scrollbar_instance): Allocate as lrecord.         * scrollbar.h (struct scrollbar_instance): Add lrecord_header.         * specifier.c (make_specifier_internal): Allocate as lrecord.         * specifier.h (struct Lisp_Specifier): Add lrecord_header.         * symbols.c:         * symbols.c (Fmake_variable_buffer_local): Allocate as lrecord.         * symbols.c (Fdontusethis_set_symbol_value_handler): Allocate         as lrecord.         * symbols.c (Fdefvaralias): Allocate as lrecord.         * symeval.h (struct symbol_value_magic): Add lrecord_header.         * toolbar.c (update_toolbar_button): Allocate as lrecord.         * toolbar.h (struct toolbar_button): Add lrecord_header.         * tooltalk.c (struct Lisp_Tooltalk_Message): Add lrecord_header.         * tooltalk.c (make_tooltalk_message): Allocate as lrecord.         * tooltalk.c (struct Lisp_Tooltalk_Pattern): Add lrecord_header.         * tooltalk.c (make_tooltalk_pattern): Allocate as lrecord.         * ui-gtk.c (allocate_ffi_data): Allocate as lrecord.         * ui-gtk.c (allocate_emacs_gtk_object_data): Allocate as lrecord.         * ui-gtk.c (allocate_emacs_gtk_boxed_data): Allocate as lrecord.         * ui-gtk.h (structs): Add lrecord_header.         * window-impl.h (struct window): Add lrecord_header.         * window-impl.h (struct window_mirror): Add lrecord_header.         * window.c (allocate_window): Allocate as lrecord.         * window.c (new_window_mirror): Allocate as lrecord.         * window.c (make_dummy_parent): Allocate as lrecord.         MEMORY_USAGE_STATS         * alloc.c (fixed_type_block_overhead): Not used anymore, remove.         * buffer.c (compute_buffer_usage): Get storage size from new         allocator.         * marker.c (compute_buffer_marker_usage): Get storage size from         new allocator.         * mule-charset.c (compute_charset_usage): Get storage size from         new allocator.         * scrollbar-gtk.c (gtk_compute_scrollbar_instance_usage): Get         storage size from new allocator.         * scrollbar-msw.c (mswindows_compute_scrollbar_instance_usage):         Get storage size from new allocator.         * scrollbar-x.c (x_compute_scrollbar_instance_usage): Get         storage size from new allocator.         * scrollbar.c (compute_scrollbar_instance_usage): Get storage         size from new allocator.         * unicode.c (compute_from_unicode_table_size_1): Get storage         size from new allocator.         * unicode.c (compute_to_unicode_table_size_1): Get storage size         from new allocator.         * window.c (compute_window_mirror_usage): Get storage size from         new allocator.         * window.c (compute_window_usage): Get storage size from new         allocator.         MC_ALLOC_TYPE_STATS:         * alloc.c (alloc_lrecord): Bump lrecord count.         * alloc.c (noseeum_alloc_lrecord): Bump lrecord count.         * alloc.c (struct lrecord_stats): Storage for counts.         * alloc.c (init_lrecord_stats): Zero statistics.         * alloc.c (inc_lrecord_stats): Increase the statistic.         * alloc.c (dec_lrecord_stats): Decrease the statistic.         * alloc.c (gc_plist_hack): Used to print the information.         * alloc.c (Fgarbage_collect): Return the collected information.         * mc-alloc.c (remove_cell): Decrease lrecord count.         * mc-alloc.h: Set flag MC_ALLOC_TYPE_STATS.         * emacs.c (main_1): Init lrecord statistics.         * lrecord.h: Add prototypes for *_lrecord_stats.         Strings:         * alloc.c (Fmake_string): Initialize ascii_begin to zero.         * alloc.c (gc_count_num_short_string_in_use): Remove.         * alloc.c (gc_count_string_total_size): Remove.         * alloc.c (gc_count_short_string_total_size): Remove.         * alloc.c (debug_string_purity): Remove.         * alloc.c (debug_string_purity_print): Remove.         * alloc.c (sweep_strings): Remove.                  Remove static C-readonly Lisp objects:         * alloc.c (c_readonly): Not needed anymore, remove.         * alloc.c (GC_CHECK_LHEADER_INVARIANTS): Remove some obsolete         lheader invariants assertions.         * buffer.c (DEFVAR_BUFFER_LOCAL_1): Allocate dynamically.         * console.c (DEFVAR_CONSOLE_LOCAL_1): Allocate dynamically.         * gpmevent.c: Indirection via MC_ALLOC_Freceive_gpm_event.         * gpmevent.c (Fgpm_enable): Allocate dynamically.         * gpmevent.c (syms_of_gpmevent): Allocate dynamically.         * lisp.h (C_READONLY): Not needed anymore, remove.         * lisp.h (DEFUN): Allocate dynamically.         * lrecord.h (C_READONLY_RECORD_HEADER_P): Not needed anymore,         remove.         * lrecord.h (SET_C_READONLY_RECORD_HEADER): Not needed anymore,         remove.         * symbols.c (guts_of_unbound_marker):         * symeval.h (defsubr): Allocate dynamically.         * symeval.h (DEFSUBR_MACRO): Allocate dynamically.         * symeval.h (DEFVAR_ SYMVAL_FWD): Allocate dynamically.         * tests.c (TESTS_DEFSUBR): Allocate dynamically.         Definition of mcpro:         * lisp.h: Add mcpro prototypes.         * alloc.c (common_init_alloc_early): Add initialization for         mcpros.         * alloc.c (mcpro_description_1): New.         * alloc.c (mcpro_description): New.         * alloc.c (mcpros_description_1): New.         * alloc.c (mcpros_description): New.         * alloc.c (mcpro_one_name_description_1): New.         * alloc.c (mcpro_one_name_description): New.         * alloc.c (mcpro_names_description_1): New.         * alloc.c (mcpro_names_description): New.         * alloc.c (mcpros): New.         * alloc.c (mcpro_names): New.         * alloc.c (mcpro_1): New.         * alloc.c (mc_pro): New.         * alloc.c (garbage_collect_1): Add mcpros to root set.         Usage of mcpro:         * alloc.c (make_string_nocopy): Add string to root set.         * symbols.c (init_symbols_once_early): Add Qunbound to root set.         Changes to the Portable Dumper:                  * alloc.c (FREE_OR_REALLOC_BEGIN): Since dumped objects can be         freed with the new allocator, remove assertion for !DUMPEDP.         * dumper.c: Adjust comments, increase PDUMP_HASHSIZE.         * dumper.c (pdump_make_hash): Shift address only 2 bytes, to         avoid collisions.         * dumper.c (pdump_objects_unmark): No more mark bits within         the object, remove.         * dumper.c (mc_addr_elt): New. Element data structure for mc         hash table.         * dumper.c (pdump_mc_hash): New hash table: `lookup table'.         * dumper.c (pdump_get_mc_addr): New. Lookup for hash table.         * dumper.c (pdump_get_indirect_mc_addr): New. Lookup for         convertibles.         * dumper.c (pdump_put_mc_addr): New. Putter for hash table.         * dumper.c (pdump_dump_mc_data): New. Writes the table for         relocation at load time to the dump file.         * dumper.c (pdump_scan_lisp_objects_by_alignment): New.         Visits all dumped Lisp objects.         * dumper.c (pdump_scan_non_lisp_objects_by_alignment): New.         Visits all other dumped objects.         * dumper.c (pdump_reloc_one_mc): New. Updates all pointers         of an object by using the hash table pdump_mc_hash.         * dumper.c (pdump_reloc_one): Replaced by pdump_reloc_one_mc.         * dumper.c (pdump): Change the structure of the dump file, add         the mc post dump relocation table to dump file.         * dumper.c (pdump_load_finish): Hand all dumped objects to the         new allocator and use the mc post dump relocation table for         relocating the dumped objects at dump file load time, free not         longer used data structures.         * dumper.c (pdump_load): Free the dump file.         * dumper.h: Remove pdump_objects_unmark.         * lrecord.h (DUMPEDP): Dumped objects can be freed, remove.              DUMP_IN_EXEC:         * Makefile.in.in: Linking for and with dump in executable only if         DUMP_IN_EXEC is defined.         * config.h.in: Add new flag `DUMP_IN_EXEC'         * emacs.c: Condition dump-data.h on DUMP_IN_EXEC.         * emacs.c (main_1): Flag `-si' only works if dump image is         written into executable.         Miscellanious         * lrecord.h (enum lrecord_type): Added numbers to all types,         very handy for debugging.         * xemacs.def.in.in: Add mc-alloc functions to make them visible         to the modules.
author crestani
date Fri, 08 Apr 2005 23:11:35 +0000
parents 7bf1f40e6acb
children 05d62157e048
line wrap: on
line diff
--- a/src/alloc.c	Fri Apr 08 21:51:50 2005 +0000
+++ b/src/alloc.c	Fri Apr 08 23:11:35 2005 +0000
@@ -220,11 +220,13 @@
 void *minimum_address_seen;
 void *maximum_address_seen;
 
+#ifndef MC_ALLOC
 int
 c_readonly (Lisp_Object obj)
 {
   return POINTER_TYPE_P (XTYPE (obj)) && C_READONLY (obj);
 }
+#endif /* MC_ALLOC */
 
 int
 lisp_readonly (Lisp_Object obj)
@@ -243,6 +245,7 @@
 int ignore_malloc_warnings;
 
 
+#ifndef MC_ALLOC
 static void *breathing_space;
 
 void
@@ -255,6 +258,7 @@
       xfree (tmp, void *);
     }
 }
+#endif /* not MC_ALLOC */
 
 /* malloc calls this if it finds we are near exhausting storage */
 void
@@ -282,7 +286,9 @@
    */
   consing_since_gc = gc_cons_threshold + 1;
   recompute_need_to_garbage_collect ();
+#ifndef MC_ALLOC
   release_breathing_space ();
+#endif /* not MC_ALLOC */
 
   /* Flush some histories which might conceivably contain garbalogical
      inhibitors.  */
@@ -324,6 +330,18 @@
 }						\
 while (0)
 
+#ifdef MC_ALLOC
+#define FREE_OR_REALLOC_BEGIN(block)					\
+do									\
+{									\
+  /* Unbelievably, calling free() on 0xDEADBEEF doesn't cause an	\
+     error until much later on for many system mallocs, such as		\
+     the one that comes with Solaris 2.3.  FMH!! */			\
+  assert (block != (void *) 0xDEADBEEF);				\
+  MALLOC_BEGIN ();							\
+}									\
+while (0)
+#else /* not MC_ALLOC */
 #define FREE_OR_REALLOC_BEGIN(block)					\
 do									\
 {									\
@@ -339,6 +357,7 @@
   MALLOC_BEGIN ();							\
 }									\
 while (0)
+#endif /* not MC_ALLOC */
 
 #define MALLOC_END()				\
 do						\
@@ -424,6 +443,7 @@
 
 #ifdef ERROR_CHECK_GC
 
+#ifndef MC_ALLOC
 static void
 deadbeef_memory (void *ptr, Bytecount size)
 {
@@ -434,6 +454,7 @@
   while (beefs--)
     (*ptr4++) = 0xDEADBEEF; /* -559038737 base 10 */
 }
+#endif /* not MC_ALLOC */
 
 #else /* !ERROR_CHECK_GC */
 
@@ -462,6 +483,7 @@
 #endif /* NEED_STRDUP */
 
 
+#ifndef MC_ALLOC
 static void *
 allocate_lisp_storage (Bytecount size)
 {
@@ -486,12 +508,119 @@
 
   return val;
 }
-
-
+#endif /* not MC_ALLOC */
+
+#ifdef MC_ALLOC_TYPE_STATS
+static struct
+{
+  int instances_in_use;
+  int bytes_in_use;
+  int bytes_in_use_including_overhead;
+} lrecord_stats [countof (lrecord_implementations_table)
+		 + MODULE_DEFINABLE_TYPE_COUNT];
+
+void
+init_lrecord_stats ()
+{
+  xzero (lrecord_stats);
+}
+
+void
+inc_lrecord_stats (Bytecount size, const struct lrecord_header *h)
+{
+  int type_index = h->type;
+  if (!size)
+    size = detagged_lisp_object_size (h);
+
+  lrecord_stats[type_index].instances_in_use++;
+  lrecord_stats[type_index].bytes_in_use += size;
+  lrecord_stats[type_index].bytes_in_use_including_overhead
+#ifdef MEMORY_USAGE_STATS
+    += mc_alloced_storage_size (size, 0);
+#else /* not MEMORY_USAGE_STATS */
+    += size;
+#endif /* not MEMORY_USAGE_STATS */
+}
+
+void
+dec_lrecord_stats (Bytecount size_including_overhead, 
+		   const struct lrecord_header *h)
+{
+  int type_index = h->type;
+
+  lrecord_stats[type_index].instances_in_use--;
+  lrecord_stats[type_index].bytes_in_use -= detagged_lisp_object_size (h);
+  lrecord_stats[type_index].bytes_in_use_including_overhead
+    -= size_including_overhead;
+
+  DECREMENT_CONS_COUNTER (lrecord_stats[type_index].bytes_in_use);
+}
+#endif /* not MC_ALLOC_TYPE_STATS */
+
+#ifndef MC_ALLOC
 /* lcrecords are chained together through their "next" field.
    After doing the mark phase, GC will walk this linked list
    and free any lcrecord which hasn't been marked. */
 static struct lcrecord_header *all_lcrecords;
+#endif /* not MC_ALLOC */
+
+#ifdef MC_ALLOC
+/* The basic lrecord allocation functions. See lrecord.h for details. */
+void *
+alloc_lrecord (Bytecount size,
+	       const struct lrecord_implementation *implementation)
+{
+  struct lrecord_header *lheader;
+
+  type_checking_assert
+    ((implementation->static_size == 0 ?
+      implementation->size_in_bytes_method != NULL :
+      implementation->static_size == size));
+
+  lheader = (struct lrecord_header *) mc_alloc (size);
+  gc_checking_assert (LRECORD_FREE_P (lheader));
+  set_lheader_implementation (lheader, implementation);
+  lheader->uid = lrecord_uid_counter++;
+#ifdef MC_ALLOC_TYPE_STATS
+  inc_lrecord_stats (size, lheader);
+#endif /* not MC_ALLOC_TYPE_STATS */
+  INCREMENT_CONS_COUNTER (size, implementation->name);
+  return lheader;
+}
+
+void *
+noseeum_alloc_lrecord (Bytecount size,
+		       const struct lrecord_implementation *implementation)
+{
+  struct lrecord_header *lheader;
+
+  type_checking_assert
+    ((implementation->static_size == 0 ?
+      implementation->size_in_bytes_method != NULL :
+      implementation->static_size == size));
+
+  lheader = (struct lrecord_header *) mc_alloc (size);
+  gc_checking_assert (LRECORD_FREE_P (lheader));
+  set_lheader_implementation (lheader, implementation);
+  lheader->uid = lrecord_uid_counter++;
+#ifdef MC_ALLOC_TYPE_STATS
+  inc_lrecord_stats (size, lheader);
+#endif /* not MC_ALLOC_TYPE_STATS */
+  NOSEEUM_INCREMENT_CONS_COUNTER (size, implementation->name);
+  return lheader;
+}
+
+void
+free_lrecord (Lisp_Object lrecord)
+{
+  gc_checking_assert (!gc_in_progress);
+  gc_checking_assert (!LRECORD_FREE_P (XRECORD_LHEADER (lrecord)));
+  gc_checking_assert (!XRECORD_LHEADER (lrecord)->free);
+
+  MC_ALLOC_CALL_FINALIZER (XPNTR (lrecord));
+  mc_free (XPNTR (lrecord));
+}
+#else /* not MC_ALLOC */
 
 /* The most basic of the lcrecord allocation functions.  Not usually called
    directly.  Allocates an lrecord not managed by any lcrecord-list, of a
@@ -563,11 +692,15 @@
   return;
 }
 #endif /* Unused */
+#endif /* not MC_ALLOC */
 
 
 static void
 disksave_object_finalization_1 (void)
 {
+#ifdef MC_ALLOC
+  mc_finalize_for_disksave ();
+#else /* not MC_ALLOC */
   struct lcrecord_header *header;
 
   for (header = all_lcrecords; header; header = header->next)
@@ -576,6 +709,7 @@
 	  !header->free)
 	LHEADER_IMPLEMENTATION (&header->lheader)->finalizer (header, 1);
     }
+#endif /* not MC_ALLOC */
 }
 
 /* Bitwise copy all parts of a Lisp object other than the header */
@@ -590,6 +724,11 @@
   assert (imp == XRECORD_LHEADER_IMPLEMENTATION (dst));
   assert (size == lisp_object_size (dst));
 
+#ifdef MC_ALLOC
+  memcpy ((char *) XRECORD_LHEADER (dst) + sizeof (struct lrecord_header),
+	  (char *) XRECORD_LHEADER (src) + sizeof (struct lrecord_header),
+	  size - sizeof (struct lrecord_header));
+#else /* not MC_ALLOC */
   if (imp->basic_p)
     memcpy ((char *) XRECORD_LHEADER (dst) + sizeof (struct lrecord_header),
 	    (char *) XRECORD_LHEADER (src) + sizeof (struct lrecord_header),
@@ -598,6 +737,7 @@
     memcpy ((char *) XRECORD_LHEADER (dst) + sizeof (struct lcrecord_header),
 	    (char *) XRECORD_LHEADER (src) + sizeof (struct lcrecord_header),
 	    size - sizeof (struct lcrecord_header));
+#endif /* not MC_ALLOC */
 }
 
 
@@ -645,6 +785,7 @@
 }
 
 
+#ifndef MC_ALLOC
 /************************************************************************/
 /*			  Fixed-size type macros			*/
 /************************************************************************/
@@ -1003,6 +1144,7 @@
 #else
 #define FREE_FIXED_TYPE_WHEN_NOT_IN_GC(type, structtype, ptr)
 #endif
+#endif /* not MC_ALLOC */
 
 
 
@@ -1010,10 +1152,12 @@
 /*			   Cons allocation				*/
 /************************************************************************/
 
+#ifndef MC_ALLOC
 DECLARE_FIXED_TYPE_ALLOC (cons, Lisp_Cons);
 /* conses are used and freed so often that we set this really high */
 /* #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_cons 20000 */
 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_cons 2000
+#endif /* not MC_ALLOC */
 
 static Lisp_Object
 mark_cons (Lisp_Object obj)
@@ -1067,8 +1211,12 @@
   Lisp_Object val;
   Lisp_Cons *c;
 
+#ifdef MC_ALLOC
+  c = alloc_lrecord_type (Lisp_Cons, &lrecord_cons);
+#else /* not MC_ALLOC */
   ALLOCATE_FIXED_TYPE (cons, Lisp_Cons, c);
   set_lheader_implementation (&c->lheader, &lrecord_cons);
+#endif /* not MC_ALLOC */
   val = wrap_cons (c);
   XSETCAR (val, car);
   XSETCDR (val, cdr);
@@ -1084,8 +1232,12 @@
   Lisp_Object val;
   Lisp_Cons *c;
 
+#ifdef MC_ALLOC
+  c = noseeum_alloc_lrecord_type (Lisp_Cons, &lrecord_cons);
+#else /* not MC_ALLOC */
   NOSEEUM_ALLOCATE_FIXED_TYPE (cons, Lisp_Cons, c);
   set_lheader_implementation (&c->lheader, &lrecord_cons);
+#endif /* not MC_ALLOC */
   val = wrap_cons (c);
   XCAR (val) = car;
   XCDR (val) = cdr;
@@ -1187,19 +1339,25 @@
 
 /*** With enhanced number support, these are short floats */
 
+#ifndef MC_ALLOC
 DECLARE_FIXED_TYPE_ALLOC (float, Lisp_Float);
 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_float 1000
+#endif /* not MC_ALLOC */
 
 Lisp_Object
 make_float (double float_value)
 {
   Lisp_Float *f;
 
+#ifdef MC_ALLOC
+  f = alloc_lrecord_type (Lisp_Float, &lrecord_float);
+#else /* not MC_ALLOC */
   ALLOCATE_FIXED_TYPE (float, Lisp_Float, f);
 
   /* Avoid dump-time `uninitialized memory read' purify warnings. */
   if (sizeof (struct lrecord_header) + sizeof (double) != sizeof (*f))
     xzero (*f);
+#endif /* not MC_ALLOC */
 
   set_lheader_implementation (&f->lheader, &lrecord_float);
   float_data (f) = float_value;
@@ -1213,8 +1371,10 @@
 
 /*** Bignum ***/
 #ifdef HAVE_BIGNUM
+#ifndef MC_ALLOC
 DECLARE_FIXED_TYPE_ALLOC (bignum, Lisp_Bignum);
 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_bignum 250
+#endif /* not MC_ALLOC */
 
 /* WARNING: This function returns a bignum even if its argument fits into a
    fixnum.  See Fcanonicalize_number(). */
@@ -1223,8 +1383,12 @@
 {
   Lisp_Bignum *b;
 
+#ifdef MC_ALLOC
+  b = alloc_lrecord_type (Lisp_Bignum, &lrecord_bignum);
+#else /* not MC_ALLOC */
   ALLOCATE_FIXED_TYPE (bignum, Lisp_Bignum, b);
   set_lheader_implementation (&b->lheader, &lrecord_bignum);
+#endif /* not MC_ALLOC */
   bignum_init (bignum_data (b));
   bignum_set_long (bignum_data (b), bignum_value);
   return wrap_bignum (b);
@@ -1237,8 +1401,12 @@
 {
   Lisp_Bignum *b;
 
+#ifdef MC_ALLOC
+  b = alloc_lrecord_type (Lisp_Bignum, &lrecord_bignum);
+#else /* not MC_ALLOC */
   ALLOCATE_FIXED_TYPE (bignum, Lisp_Bignum, b);
   set_lheader_implementation (&b->lheader, &lrecord_bignum);
+#endif /* not MC_ALLOC */
   bignum_init (bignum_data (b));
   bignum_set (bignum_data (b), bg);
   return wrap_bignum (b);
@@ -1247,16 +1415,22 @@
 
 /*** Ratio ***/
 #ifdef HAVE_RATIO
+#ifndef MC_ALLOC
 DECLARE_FIXED_TYPE_ALLOC (ratio, Lisp_Ratio);
 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_ratio 250
+#endif /* not MC_ALLOC */
 
 Lisp_Object
 make_ratio (long numerator, unsigned long denominator)
 {
   Lisp_Ratio *r;
 
+#ifdef MC_ALLOC
+  r = alloc_lrecord_type (Lisp_Ratio, &lrecord_ratio);
+#else /* not MC_ALLOC */
   ALLOCATE_FIXED_TYPE (ratio, Lisp_Ratio, r);
   set_lheader_implementation (&r->lheader, &lrecord_ratio);
+#endif /* not MC_ALLOC */
   ratio_init (ratio_data (r));
   ratio_set_long_ulong (ratio_data (r), numerator, denominator);
   ratio_canonicalize (ratio_data (r));
@@ -1268,8 +1442,12 @@
 {
   Lisp_Ratio *r;
 
+#ifdef MC_ALLOC
+  r = alloc_lrecord_type (Lisp_Ratio, &lrecord_ratio);
+#else /* not MC_ALLOC */
   ALLOCATE_FIXED_TYPE (ratio, Lisp_Ratio, r);
   set_lheader_implementation (&r->lheader, &lrecord_ratio);
+#endif /* not MC_ALLOC */
   ratio_init (ratio_data (r));
   ratio_set_bignum_bignum (ratio_data (r), numerator, denominator);
   ratio_canonicalize (ratio_data (r));
@@ -1281,8 +1459,12 @@
 {
   Lisp_Ratio *r;
 
+#ifdef MC_ALLOC
+  r = alloc_lrecord_type (Lisp_Ratio, &lrecord_ratio);
+#else /* not MC_ALLOC */
   ALLOCATE_FIXED_TYPE (ratio, Lisp_Ratio, r);
   set_lheader_implementation (&r->lheader, &lrecord_ratio);
+#endif /* not MC_ALLOC */
   ratio_init (ratio_data (r));
   ratio_set (ratio_data (r), rat);
   return wrap_ratio (r);
@@ -1291,8 +1473,10 @@
 
 /*** Bigfloat ***/
 #ifdef HAVE_BIGFLOAT
+#ifndef MC_ALLOC
 DECLARE_FIXED_TYPE_ALLOC (bigfloat, Lisp_Bigfloat);
 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_bigfloat 250
+#endif /* not MC_ALLOC */
 
 /* This function creates a bigfloat with the default precision if the
    PRECISION argument is zero. */
@@ -1301,8 +1485,12 @@
 {
   Lisp_Bigfloat *f;
 
+#ifdef MC_ALLOC
+  f = alloc_lrecord_type (Lisp_Bigfloat, &lrecord_bigfloat);
+#else /* not MC_ALLOC */
   ALLOCATE_FIXED_TYPE (bigfloat, Lisp_Bigfloat, f);
   set_lheader_implementation (&f->lheader, &lrecord_bigfloat);
+#endif /* not MC_ALLOC */
   if (precision == 0UL)
     bigfloat_init (bigfloat_data (f));
   else
@@ -1317,8 +1505,12 @@
 {
   Lisp_Bigfloat *f;
 
+#ifdef MC_ALLOC
+  f = alloc_lrecord_type (Lisp_Bigfloat, &lrecord_bigfloat);
+#else /* not MC_ALLOC */
   ALLOCATE_FIXED_TYPE (bigfloat, Lisp_Bigfloat, f);
   set_lheader_implementation (&f->lheader, &lrecord_bigfloat);
+#endif /* not MC_ALLOC */
   bigfloat_init_prec (bigfloat_data (f), bigfloat_get_prec (float_value));
   bigfloat_set (bigfloat_data (f), float_value);
   return wrap_bigfloat (f);
@@ -1395,7 +1587,11 @@
   Bytecount sizem = FLEXIBLE_ARRAY_STRUCT_SIZEOF (Lisp_Vector, Lisp_Object,
 						  contents, sizei);
   Lisp_Vector *p =
+#ifdef MC_ALLOC
+    (Lisp_Vector *) alloc_lrecord (sizem, &lrecord_vector);
+#else /* not MC_ALLOC */
     (Lisp_Vector *) basic_alloc_lcrecord (sizem, &lrecord_vector);
+#endif /* not MC_ALLOC */
 
   p->size = sizei;
   return p;
@@ -1552,7 +1748,11 @@
 						  unsigned long,
 						  bits, num_longs);
   Lisp_Bit_Vector *p = (Lisp_Bit_Vector *)
+#ifdef MC_ALLOC
+    alloc_lrecord (sizem, &lrecord_bit_vector);
+#else /* not MC_ALLOC */
     basic_alloc_lcrecord (sizem, &lrecord_bit_vector);
+#endif /* not MC_ALLOC */
 
   bit_vector_length (p) = sizei;
   return p;
@@ -1628,16 +1828,22 @@
 /*		     Compiled-function allocation			*/
 /************************************************************************/
 
+#ifndef MC_ALLOC
 DECLARE_FIXED_TYPE_ALLOC (compiled_function, Lisp_Compiled_Function);
 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_compiled_function 1000
+#endif /* not MC_ALLOC */
 
 static Lisp_Object
 make_compiled_function (void)
 {
   Lisp_Compiled_Function *f;
 
+#ifdef MC_ALLOC
+  f = alloc_lrecord_type (Lisp_Compiled_Function, &lrecord_compiled_function);
+#else /* not MC_ALLOC */
   ALLOCATE_FIXED_TYPE (compiled_function, Lisp_Compiled_Function, f);
   set_lheader_implementation (&f->lheader, &lrecord_compiled_function);
+#endif /* not MC_ALLOC */
 
   f->stack_depth = 0;
   f->specpdl_depth = 0;
@@ -1769,8 +1975,10 @@
 /*			    Symbol allocation				*/
 /************************************************************************/
 
+#ifndef MC_ALLOC
 DECLARE_FIXED_TYPE_ALLOC (symbol, Lisp_Symbol);
 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_symbol 1000
+#endif /* not MC_ALLOC */
 
 DEFUN ("make-symbol", Fmake_symbol, 1, 1, 0, /*
 Return a newly allocated uninterned symbol whose name is NAME.
@@ -1782,8 +1990,12 @@
 
   CHECK_STRING (name);
 
+#ifdef MC_ALLOC
+  p = alloc_lrecord_type (Lisp_Symbol, &lrecord_symbol);
+#else /* not MC_ALLOC */
   ALLOCATE_FIXED_TYPE (symbol, Lisp_Symbol, p);
   set_lheader_implementation (&p->lheader, &lrecord_symbol);
+#endif /* not MC_ALLOC */
   p->name     = name;
   p->plist    = Qnil;
   p->value    = Qunbound;
@@ -1797,16 +2009,22 @@
 /*			   Extent allocation				*/
 /************************************************************************/
 
+#ifndef MC_ALLOC
 DECLARE_FIXED_TYPE_ALLOC (extent, struct extent);
 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_extent 1000
+#endif /* not MC_ALLOC */
 
 struct extent *
 allocate_extent (void)
 {
   struct extent *e;
 
+#ifdef MC_ALLOC
+  e = alloc_lrecord_type (struct extent, &lrecord_extent);
+#else /* not MC_ALLOC */
   ALLOCATE_FIXED_TYPE (extent, struct extent, e);
   set_lheader_implementation (&e->lheader, &lrecord_extent);
+#endif /* not MC_ALLOC */
   extent_object (e) = Qnil;
   set_extent_start (e, -1);
   set_extent_end (e, -1);
@@ -1826,161 +2044,221 @@
 /*			   Event allocation				*/
 /************************************************************************/
 
+#ifndef MC_ALLOC
 DECLARE_FIXED_TYPE_ALLOC (event, Lisp_Event);
 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_event 1000
+#endif /* not MC_ALLOC */
 
 Lisp_Object
 allocate_event (void)
 {
   Lisp_Event *e;
 
+#ifdef MC_ALLOC
+  e = alloc_lrecord_type (Lisp_Event, &lrecord_event);
+#else /* not MC_ALLOC */
   ALLOCATE_FIXED_TYPE (event, Lisp_Event, e);
   set_lheader_implementation (&e->lheader, &lrecord_event);
+#endif /* not MC_ALLOC */
 
   return wrap_event (e);
 }
 
 #ifdef EVENT_DATA_AS_OBJECTS
+#ifndef MC_ALLOC
 DECLARE_FIXED_TYPE_ALLOC (key_data, Lisp_Key_Data);
 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_key_data 1000
+#endif /* not MC_ALLOC */
 
 Lisp_Object
 make_key_data (void)
 {
   Lisp_Key_Data *d;
 
+#ifdef MC_ALLOC
+  d = alloc_lrecord_type (Lisp_Key_Data, &lrecord_key_data);
+#else /* not MC_ALLOC */
   ALLOCATE_FIXED_TYPE (key_data, Lisp_Key_Data, d);
   xzero (*d);
   set_lheader_implementation (&d->lheader, &lrecord_key_data);
+#endif /* not MC_ALLOC */
   d->keysym = Qnil;
 
   return wrap_key_data (d);
 }
 
+#ifndef MC_ALLOC
 DECLARE_FIXED_TYPE_ALLOC (button_data, Lisp_Button_Data);
 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_button_data 1000
+#endif /* not MC_ALLOC */
 
 Lisp_Object
 make_button_data (void)
 {
   Lisp_Button_Data *d;
 
+#ifdef MC_ALLOC
+  d = alloc_lrecord_type (Lisp_Button_Data, &lrecord_button_data);
+#else /* not MC_ALLOC */
   ALLOCATE_FIXED_TYPE (button_data, Lisp_Button_Data, d);
   xzero (*d);
   set_lheader_implementation (&d->lheader, &lrecord_button_data);
 
+#endif /* not MC_ALLOC */
   return wrap_button_data (d);
 }
 
+#ifndef MC_ALLOC
 DECLARE_FIXED_TYPE_ALLOC (motion_data, Lisp_Motion_Data);
 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_motion_data 1000
+#endif /* not MC_ALLOC */
 
 Lisp_Object
 make_motion_data (void)
 {
   Lisp_Motion_Data *d;
 
+#ifdef MC_ALLOC
+  d = alloc_lrecord_type (Lisp_Motion_Data, &lrecord_motion_data);
+#else /* not MC_ALLOC */
   ALLOCATE_FIXED_TYPE (motion_data, Lisp_Motion_Data, d);
   xzero (*d);
   set_lheader_implementation (&d->lheader, &lrecord_motion_data);
+#endif /* not MC_ALLOC */
 
   return wrap_motion_data (d);
 }
 
+#ifndef MC_ALLOC
 DECLARE_FIXED_TYPE_ALLOC (process_data, Lisp_Process_Data);
 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_process_data 1000
+#endif /* not MC_ALLOC */
 
 Lisp_Object
 make_process_data (void)
 {
   Lisp_Process_Data *d;
 
+#ifdef MC_ALLOC
+  d = alloc_lrecord_type (Lisp_Process_Data, &lrecord_process_data);
+#else /* not MC_ALLOC */
   ALLOCATE_FIXED_TYPE (process_data, Lisp_Process_Data, d);
   xzero (*d);
   set_lheader_implementation (&d->lheader, &lrecord_process_data);
   d->process = Qnil;
+#endif /* not MC_ALLOC */
 
   return wrap_process_data (d);
 }
 
+#ifndef MC_ALLOC
 DECLARE_FIXED_TYPE_ALLOC (timeout_data, Lisp_Timeout_Data);
 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_timeout_data 1000
+#endif /* not MC_ALLOC */
 
 Lisp_Object
 make_timeout_data (void)
 {
   Lisp_Timeout_Data *d;
 
+#ifdef MC_ALLOC
+  d = alloc_lrecord_type (Lisp_Timeout_Data, &lrecord_timeout_data);
+#else /* not MC_ALLOC */
   ALLOCATE_FIXED_TYPE (timeout_data, Lisp_Timeout_Data, d);
   xzero (*d);
   set_lheader_implementation (&d->lheader, &lrecord_timeout_data);
   d->function = Qnil;
   d->object = Qnil;
+#endif /* not MC_ALLOC */
 
   return wrap_timeout_data (d);
 }
 
+#ifndef MC_ALLOC
 DECLARE_FIXED_TYPE_ALLOC (magic_data, Lisp_Magic_Data);
 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_magic_data 1000
+#endif /* not MC_ALLOC */
 
 Lisp_Object
 make_magic_data (void)
 {
   Lisp_Magic_Data *d;
 
+#ifdef MC_ALLOC
+  d = alloc_lrecord_type (Lisp_Magic_Data, &lrecord_magic_data);
+#else /* not MC_ALLOC */
   ALLOCATE_FIXED_TYPE (magic_data, Lisp_Magic_Data, d);
   xzero (*d);
   set_lheader_implementation (&d->lheader, &lrecord_magic_data);
+#endif /* not MC_ALLOC */
 
   return wrap_magic_data (d);
 }
 
+#ifndef MC_ALLOC
 DECLARE_FIXED_TYPE_ALLOC (magic_eval_data, Lisp_Magic_Eval_Data);
 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_magic_eval_data 1000
+#endif /* not MC_ALLOC */
 
 Lisp_Object
 make_magic_eval_data (void)
 {
   Lisp_Magic_Eval_Data *d;
 
+#ifdef MC_ALLOC
+  d = alloc_lrecord_type (Lisp_Magic_Eval_Data, &lrecord_magic_eval_data);
+#else /* not MC_ALLOC */
   ALLOCATE_FIXED_TYPE (magic_eval_data, Lisp_Magic_Eval_Data, d);
   xzero (*d);
   set_lheader_implementation (&d->lheader, &lrecord_magic_eval_data);
   d->object = Qnil;
+#endif /* not MC_ALLOC */
 
   return wrap_magic_eval_data (d);
 }
 
+#ifndef MC_ALLOC
 DECLARE_FIXED_TYPE_ALLOC (eval_data, Lisp_Eval_Data);
 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_eval_data 1000
+#endif /* not MC_ALLOC */
 
 Lisp_Object
 make_eval_data (void)
 {
   Lisp_Eval_Data *d;
 
+#ifdef MC_ALLOC
+  d = alloc_lrecord_type (Lisp_Eval_Data, &lrecord_eval_data);
+#else /* not MC_ALLOC */
   ALLOCATE_FIXED_TYPE (eval_data, Lisp_Eval_Data, d);
   xzero (*d);
   set_lheader_implementation (&d->lheader, &lrecord_eval_data);
   d->function = Qnil;
   d->object = Qnil;
+#endif /* not MC_ALLOC */
 
   return wrap_eval_data (d);
 }
 
+#ifndef MC_ALLOC
 DECLARE_FIXED_TYPE_ALLOC (misc_user_data, Lisp_Misc_User_Data);
 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_misc_user_data 1000
+#endif /* not MC_ALLOC */
 
 Lisp_Object
 make_misc_user_data (void)
 {
   Lisp_Misc_User_Data *d;
 
+#ifdef MC_ALLOC
+  d = alloc_lrecord_type (Lisp_Misc_User_Data, &lrecord_misc_user_data);
+#else /* not MC_ALLOC */
   ALLOCATE_FIXED_TYPE (misc_user_data, Lisp_Misc_User_Data, d);
   xzero (*d);
   set_lheader_implementation (&d->lheader, &lrecord_misc_user_data);
   d->function = Qnil;
   d->object = Qnil;
+#endif /* not MC_ALLOC */
 
   return wrap_misc_user_data (d);
 }
@@ -1991,8 +2269,10 @@
 /*			 Marker allocation				*/
 /************************************************************************/
 
+#ifndef MC_ALLOC
 DECLARE_FIXED_TYPE_ALLOC (marker, Lisp_Marker);
 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_marker 1000
+#endif /* not MC_ALLOC */
 
 DEFUN ("make-marker", Fmake_marker, 0, 0, 0, /*
 Return a new marker which does not point at any place.
@@ -2001,8 +2281,12 @@
 {
   Lisp_Marker *p;
 
+#ifdef MC_ALLOC
+  p = alloc_lrecord_type (Lisp_Marker, &lrecord_marker);
+#else /* not MC_ALLOC */
   ALLOCATE_FIXED_TYPE (marker, Lisp_Marker, p);
   set_lheader_implementation (&p->lheader, &lrecord_marker);
+#endif /* not MC_ALLOC */
   p->buffer = 0;
   p->membpos = 0;
   marker_next (p) = 0;
@@ -2016,8 +2300,12 @@
 {
   Lisp_Marker *p;
 
+#ifdef MC_ALLOC
+  p = noseeum_alloc_lrecord_type (Lisp_Marker, &lrecord_marker);
+#else /* not MC_ALLOC */
   NOSEEUM_ALLOCATE_FIXED_TYPE (marker, Lisp_Marker, p);
   set_lheader_implementation (&p->lheader, &lrecord_marker);
+#endif /* not MC_ALLOC */
   p->buffer = 0;
   p->membpos = 0;
   marker_next (p) = 0;
@@ -2044,10 +2332,12 @@
 
    This new method makes things somewhat bigger, but it is MUCH safer.  */
 
+#ifndef MC_ALLOC
 DECLARE_FIXED_TYPE_ALLOC (string, Lisp_String);
 /* strings are used and freed quite often */
 /* #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_string 10000 */
 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_string 1000
+#endif /* not MC_ALLOC */
 
 static Lisp_Object
 mark_string (Lisp_Object obj)
@@ -2119,11 +2409,13 @@
   return *string_plist_ptr (string);
 }
 
+#ifndef MC_ALLOC
 /* No `finalize', or `hash' methods.
    internal_hash() already knows how to hash strings and finalization
    is done with the ADDITIONAL_FREE_string macro, which is the
    standard way to do finalization when using
    SWEEP_FIXED_TYPE_BLOCK(). */
+
 DEFINE_BASIC_LRECORD_IMPLEMENTATION_WITH_PROPS ("string", string,
 						1, /*dumpable-flag*/
 						mark_string, print_string,
@@ -2134,6 +2426,8 @@
 						string_remprop,
 						string_plist,
 						Lisp_String);
+#endif /* not MC_ALLOC */
+
 /* String blocks contain this many useful bytes. */
 #define STRING_CHARS_BLOCK_SIZE					\
   ((Bytecount) (8192 - MALLOC_OVERHEAD -			\
@@ -2166,6 +2460,33 @@
 #define STRING_CHARS_FREE_P(ptr) ((ptr)->string == NULL)
 #define MARK_STRING_CHARS_AS_FREE(ptr) ((void) ((ptr)->string = NULL))
 
+#ifdef MC_ALLOC
+static void
+finalize_string (void *header, int for_disksave)
+{
+  if (!for_disksave)
+    {
+      Lisp_String *s = (Lisp_String *) header;
+      Bytecount size = s->size_;
+      if (BIG_STRING_SIZE_P (size))
+	xfree (s->data_, Ibyte *);
+    }
+}
+
+DEFINE_LRECORD_IMPLEMENTATION_WITH_PROPS ("string", string,
+					  1, /*dumpable-flag*/
+					  mark_string, print_string,
+					  finalize_string,
+					  string_equal, 0,
+					  string_description,
+					  string_getprop,
+					  string_putprop,
+					  string_remprop,
+					  string_plist,
+					  Lisp_String);
+
+#endif /* MC_ALLOC */
+
 struct string_chars
 {
   Lisp_String *string;
@@ -2264,15 +2585,19 @@
 
   assert (length >= 0 && fullsize > 0);
 
+#ifdef MC_ALLOC
+  s = alloc_lrecord_type (Lisp_String, &lrecord_string);
+#else /* not MC_ALLOC */
   /* Allocate the string header */
   ALLOCATE_FIXED_TYPE (string, Lisp_String, s);
   xzero (*s);
   set_lheader_implementation (&s->u.lheader, &lrecord_string);
-  
+#endif /* not MC_ALLOC */
+
   set_lispstringp_data (s, BIG_STRING_FULLSIZE_P (fullsize)
-		   ? allocate_big_string_chars (length + 1)
-		   : allocate_string_chars_struct (wrap_string (s),
-						   fullsize)->chars);
+			? allocate_big_string_chars (length + 1)
+			: allocate_string_chars_struct (wrap_string (s),
+							fullsize)->chars);
 
   set_lispstringp_length (s, length);
   s->plist = Qnil;
@@ -2298,7 +2623,6 @@
 #ifdef VERIFY_STRING_CHARS_INTEGRITY
   verify_string_chars_integrity ();
 #endif
-
 #ifdef ERROR_CHECK_TEXT
   if (pos >= 0)
     {
@@ -2498,6 +2822,16 @@
 	EMACS_INT i;
 	Ibyte *ptr = XSTRING_DATA (val);
 
+#ifdef MC_ALLOC
+	/* Need this for the new allocator: strings are using the uid
+	   field for ascii_begin. The uid field is set for debugging,
+	   but the string code assumes here that ascii_begin is always
+	   zero, when not touched. This assumption is not true with
+	   the new allocator, so ascii_begin has to be set to zero
+	   here. */
+	XSET_STRING_ASCII_BEGIN (val, 0);
+#endif /* not MC_ALLOC */
+
 	for (i = XINT (length); i; i--)
 	  {
 	    Ibyte *init_ptr = init_str;
@@ -2634,10 +2968,17 @@
   bytecount_to_charcount (contents, length); /* Just for the assertions */
 #endif
 
+#ifdef MC_ALLOC
+  s = alloc_lrecord_type (Lisp_String, &lrecord_string);
+  mcpro (wrap_pointer_1 (s)); /* otherwise nocopy_strings get
+				 collected and static data is tried to
+				 be freed. */
+#else /* not MC_ALLOC */
   /* Allocate the string header */
   ALLOCATE_FIXED_TYPE (string, Lisp_String, s);
   set_lheader_implementation (&s->u.lheader, &lrecord_string);
   SET_C_READONLY_RECORD_HEADER (&s->u.lheader);
+#endif /* not MC_ALLOC */
   s->plist = Qnil;
   set_lispstringp_data (s, (Ibyte *) contents);
   set_lispstringp_length (s, length);
@@ -2649,6 +2990,7 @@
 }
 
 
+#ifndef MC_ALLOC
 /************************************************************************/
 /*                           lcrecord lists                             */
 /************************************************************************/
@@ -2856,6 +3198,7 @@
 
   free_managed_lcrecord (all_lcrecord_lists[type], rec);
 }
+#endif /* not MC_ALLOC */
 
 
 DEFUN ("purecopy", Fpurecopy, 1, 1, 0, /*
@@ -3030,7 +3373,91 @@
 
 #endif /* not DEBUG_XEMACS */
 
+
+
+
+
+#ifdef MC_ALLOC
+static const struct memory_description mcpro_description_1[] = {
+  { XD_END }
+};
+
+static const struct sized_memory_description mcpro_description = {
+  sizeof (Lisp_Object *),
+  mcpro_description_1
+};
+
+static const struct memory_description mcpros_description_1[] = {
+  XD_DYNARR_DESC (Lisp_Object_dynarr, &mcpro_description),
+  { XD_END }
+};
+
+static const struct sized_memory_description mcpros_description = {
+  sizeof (Lisp_Object_dynarr),
+  mcpros_description_1
+};
+
+#ifdef DEBUG_XEMACS
+
+static const struct memory_description mcpro_one_name_description_1[] = {
+  { XD_ASCII_STRING, 0 },
+  { XD_END }
+};
+
+static const struct sized_memory_description mcpro_one_name_description = {
+  sizeof (char *),
+  mcpro_one_name_description_1
+};
+
+static const struct memory_description mcpro_names_description_1[] = {
+  XD_DYNARR_DESC (char_ptr_dynarr, &mcpro_one_name_description),
+  { XD_END }
+};
+
+extern const struct sized_memory_description mcpro_names_description;
+
+const struct sized_memory_description mcpro_names_description = {
+  sizeof (char_ptr_dynarr),
+  mcpro_names_description_1
+};
+
+/* Help debug crashes gc-marking a mcpro'ed object. */
+
+Lisp_Object_dynarr *mcpros;
+char_ptr_dynarr *mcpro_names;
+
+/* Mark the Lisp_Object at non-heap VARADDRESS as a root object for
+   garbage collection, and for dumping. */
+void
+mcpro_1 (Lisp_Object varaddress, char *varname)
+{
+  Dynarr_add (mcpros, varaddress);
+  Dynarr_add (mcpro_names, varname);
+}
+
+#else /* not DEBUG_XEMACS */
+
+Lisp_Object_dynarr *mcpros;
+
+/* Mark the Lisp_Object at non-heap VARADDRESS as a root object for
+   garbage collection, and for dumping. */
+void
+mcpro (Lisp_Object varaddress)
+{
+  Dynarr_add (mcpros, varaddress);
+}
+
+#endif /* not DEBUG_XEMACS */
+#endif /* MC_ALLOC */
+
 #ifdef ERROR_CHECK_GC
+#ifdef MC_ALLOC
+#define GC_CHECK_LHEADER_INVARIANTS(lheader) do {		\
+  struct lrecord_header * GCLI_lh = (lheader);			\
+  assert (GCLI_lh != 0);					\
+  assert (GCLI_lh->type < (unsigned int) lrecord_type_count);	\
+} while (0)
+#else /* not MC_ALLOC */
 #define GC_CHECK_LHEADER_INVARIANTS(lheader) do {		\
   struct lrecord_header * GCLI_lh = (lheader);			\
   assert (GCLI_lh != 0);					\
@@ -3039,6 +3466,7 @@
 	  (MARKED_RECORD_HEADER_P (GCLI_lh) &&			\
 	   LISP_READONLY_RECORD_HEADER_P (GCLI_lh)));		\
 } while (0)
+#endif /* not MC_ALLOC */
 #else
 #define GC_CHECK_LHEADER_INVARIANTS(lheader)
 #endif
@@ -3291,9 +3719,15 @@
 
 #endif /* defined (USE_KKCC) || defined (PDUMP) */
 
+#ifdef MC_ALLOC
+#define GC_CHECK_NOT_FREE(lheader)			\
+      gc_checking_assert (! LRECORD_FREE_P (lheader));
+#else /* MC_ALLOC */
 #define GC_CHECK_NOT_FREE(lheader)					\
+      gc_checking_assert (! LRECORD_FREE_P (lheader));			\
       gc_checking_assert (LHEADER_IMPLEMENTATION (lheader)->basic_p ||	\
 			  ! ((struct lcrecord_header *) lheader)->free)
+#endif /* MC_ALLOC */
 
 #ifdef USE_KKCC
 /* The following functions implement the new mark algorithm. 
@@ -3339,7 +3773,11 @@
     {
       Lisp_Object obj = wrap_pointer_1 (kkcc_bt[i].obj);
       stderr_out (" [%d]", i);
+#ifdef MC_ALLOC
+      if ((XRECORD_LHEADER (obj)->type >= lrecord_type_last_built_in_type)
+#else /* not MC_ALLOC */
       if ((XRECORD_LHEADER (obj)->type >= lrecord_type_free)
+#endif /* not MC_ALLOC */
 	  || (!LRECORDP (obj))
 	  || (!XRECORD_LHEADER_IMPLEMENTATION (obj)))
 	{
@@ -3630,6 +4068,9 @@
 
       kkcc_bt_push (data, desc, stack_entry->level, stack_entry->pos);
 
+      gc_checking_assert (data);
+      gc_checking_assert (desc);
+
       for (pos = 0; desc[pos].type != XD_END; pos++)
 	{
 	  const struct memory_description *desc1 = &desc[pos];
@@ -3666,10 +4107,14 @@
 		   though. */
 		if (EQ (*stored_obj, Qnull_pointer))
 		  break;
+#ifdef MC_ALLOC
+		mark_object_maybe_checking_free (*stored_obj, 0, level, pos);
+#else /* not MC_ALLOC */
 		mark_object_maybe_checking_free
 		  (*stored_obj, (desc1->flags) & XD_FLAG_FREE_LISP_OBJECT,
 		   level, pos);
 		break;
+#endif /* not MC_ALLOC */
 	      }
 	    case XD_LISP_OBJECT_ARRAY:
 	      {
@@ -3684,9 +4129,13 @@
 
 		    if (EQ (*stored_obj, Qnull_pointer))
 		      break;
+#ifdef MC_ALLOC
+		    mark_object_maybe_checking_free (*stored_obj, 0, level, pos);
+#else /* not MC_ALLOC */
 		    mark_object_maybe_checking_free
 		      (*stored_obj, (desc1->flags) & XD_FLAG_FREE_LISP_OBJECT,
 		       level, pos);
+#endif /* not MC_ALLOC */
 		  }
 		break;
 	      }
@@ -3783,6 +4232,7 @@
 }
 
 
+#ifndef MC_ALLOC
 static int gc_count_num_short_string_in_use;
 static Bytecount gc_count_string_total_size;
 static Bytecount gc_count_short_string_total_size;
@@ -3828,8 +4278,10 @@
 	}
     }
 }
+#endif /* not MC_ALLOC */
 
 
+#ifndef MC_ALLOC
 /* Free all unmarked records */
 static void
 sweep_lcrecords_1 (struct lcrecord_header **prev, int *used)
@@ -4025,9 +4477,10 @@
 #define SWEEP_FIXED_TYPE_BLOCK(typename, obj_type) \
   SWEEP_FIXED_TYPE_BLOCK_1 (typename, obj_type, lheader)
 
+#endif /* not MC_ALLOC */
+
 
-
-
+#ifndef MC_ALLOC
 static void
 sweep_conses (void)
 {
@@ -4036,14 +4489,20 @@
 
   SWEEP_FIXED_TYPE_BLOCK (cons, Lisp_Cons);
 }
+#endif /* not MC_ALLOC */
 
 /* Explicitly free a cons cell.  */
 void
 free_cons (Lisp_Object cons)
 {
+#ifndef MC_ALLOC /* to avoid compiler warning */
   Lisp_Cons *ptr = XCONS (cons);
+#endif /* MC_ALLOC */
 
 #ifdef ERROR_CHECK_GC
+#ifdef MC_ALLOC
+  Lisp_Cons *ptr = XCONS (cons);
+#endif /* MC_ALLOC */
   /* If the CAR is not an int, then it will be a pointer, which will
      always be four-byte aligned.  If this cons cell has already been
      placed on the free list, however, its car will probably contain
@@ -4058,7 +4517,11 @@
     ASSERT_VALID_POINTER (XPNTR (cons_car (ptr)));
 #endif /* ERROR_CHECK_GC */
 
+#ifdef MC_ALLOC
+  free_lrecord (cons);
+#else /* not MC_ALLOC */
   FREE_FIXED_TYPE_WHEN_NOT_IN_GC (cons, Lisp_Cons, ptr);
+#endif /* not MC_ALLOC */
 }
 
 /* explicitly free a list.  You **must make sure** that you have
@@ -4096,6 +4559,7 @@
     }
 }
 
+#ifndef MC_ALLOC
 static void
 sweep_compiled_functions (void)
 {
@@ -4174,9 +4638,11 @@
 
   SWEEP_FIXED_TYPE_BLOCK (event, Lisp_Event);
 }
+#endif /* not MC_ALLOC */
 
 #ifdef EVENT_DATA_AS_OBJECTS
 
+#ifndef MC_ALLOC
 static void
 sweep_key_data (void)
 {
@@ -4185,13 +4651,19 @@
 
   SWEEP_FIXED_TYPE_BLOCK (key_data, Lisp_Key_Data);
 }
+#endif /* not MC_ALLOC */
 
 void
 free_key_data (Lisp_Object ptr)
 {
+#ifdef MC_ALLOC
+  free_lrecord (ptr);
+#else /* not MC_ALLOC */
   FREE_FIXED_TYPE_WHEN_NOT_IN_GC (key_data, Lisp_Key_Data, XKEY_DATA (ptr));
-}
-
+#endif /* not MC_ALLOC */
+}
+
+#ifndef MC_ALLOC
 static void
 sweep_button_data (void)
 {
@@ -4200,13 +4672,19 @@
 
   SWEEP_FIXED_TYPE_BLOCK (button_data, Lisp_Button_Data);
 }
+#endif /* not MC_ALLOC */
 
 void
 free_button_data (Lisp_Object ptr)
 {
+#ifdef MC_ALLOC
+  free_lrecord (ptr);
+#else /* not MC_ALLOC */
   FREE_FIXED_TYPE_WHEN_NOT_IN_GC (button_data, Lisp_Button_Data, XBUTTON_DATA (ptr));
-}
-
+#endif /* not MC_ALLOC */
+}
+
+#ifndef MC_ALLOC
 static void
 sweep_motion_data (void)
 {
@@ -4215,13 +4693,19 @@
 
   SWEEP_FIXED_TYPE_BLOCK (motion_data, Lisp_Motion_Data);
 }
+#endif /* not MC_ALLOC */
 
 void
 free_motion_data (Lisp_Object ptr)
 {
+#ifdef MC_ALLOC
+  free_lrecord (ptr);
+#else /* not MC_ALLOC */
   FREE_FIXED_TYPE_WHEN_NOT_IN_GC (motion_data, Lisp_Motion_Data, XMOTION_DATA (ptr));
-}
-
+#endif /* not MC_ALLOC */
+}
+
+#ifndef MC_ALLOC
 static void
 sweep_process_data (void)
 {
@@ -4230,13 +4714,19 @@
 
   SWEEP_FIXED_TYPE_BLOCK (process_data, Lisp_Process_Data);
 }
+#endif /* not MC_ALLOC */
 
 void
 free_process_data (Lisp_Object ptr)
 {
+#ifdef MC_ALLOC
+  free_lrecord (ptr);
+#else /* not MC_ALLOC */
   FREE_FIXED_TYPE_WHEN_NOT_IN_GC (process_data, Lisp_Process_Data, XPROCESS_DATA (ptr));
-}
-
+#endif /* not MC_ALLOC */
+}
+
+#ifndef MC_ALLOC
 static void
 sweep_timeout_data (void)
 {
@@ -4245,13 +4735,19 @@
 
   SWEEP_FIXED_TYPE_BLOCK (timeout_data, Lisp_Timeout_Data);
 }
+#endif /* not MC_ALLOC */
 
 void
 free_timeout_data (Lisp_Object ptr)
 {
+#ifdef MC_ALLOC
+  free_lrecord (ptr);
+#else /* not MC_ALLOC */
   FREE_FIXED_TYPE_WHEN_NOT_IN_GC (timeout_data, Lisp_Timeout_Data, XTIMEOUT_DATA (ptr));
-}
-
+#endif /* not MC_ALLOC */
+}
+
+#ifndef MC_ALLOC
 static void
 sweep_magic_data (void)
 {
@@ -4260,13 +4756,19 @@
 
   SWEEP_FIXED_TYPE_BLOCK (magic_data, Lisp_Magic_Data);
 }
+#endif /* not MC_ALLOC */
 
 void
 free_magic_data (Lisp_Object ptr)
 {
+#ifdef MC_ALLOC
+  free_lrecord (ptr);
+#else /* not MC_ALLOC */
   FREE_FIXED_TYPE_WHEN_NOT_IN_GC (magic_data, Lisp_Magic_Data, XMAGIC_DATA (ptr));
-}
-
+#endif /* not MC_ALLOC */
+}
+
+#ifndef MC_ALLOC
 static void
 sweep_magic_eval_data (void)
 {
@@ -4275,13 +4777,19 @@
 
   SWEEP_FIXED_TYPE_BLOCK (magic_eval_data, Lisp_Magic_Eval_Data);
 }
+#endif /* not MC_ALLOC */
 
 void
 free_magic_eval_data (Lisp_Object ptr)
 {
+#ifdef MC_ALLOC
+  free_lrecord (ptr);
+#else /* not MC_ALLOC */
   FREE_FIXED_TYPE_WHEN_NOT_IN_GC (magic_eval_data, Lisp_Magic_Eval_Data, XMAGIC_EVAL_DATA (ptr));
-}
-
+#endif /* not MC_ALLOC */
+}
+
+#ifndef MC_ALLOC
 static void
 sweep_eval_data (void)
 {
@@ -4290,13 +4798,19 @@
 
   SWEEP_FIXED_TYPE_BLOCK (eval_data, Lisp_Eval_Data);
 }
+#endif /* not MC_ALLOC */
 
 void
 free_eval_data (Lisp_Object ptr)
 {
+#ifdef MC_ALLOC
+  free_lrecord (ptr);
+#else /* not MC_ALLOC */
   FREE_FIXED_TYPE_WHEN_NOT_IN_GC (eval_data, Lisp_Eval_Data, XEVAL_DATA (ptr));
-}
-
+#endif /* not MC_ALLOC */
+}
+
+#ifndef MC_ALLOC
 static void
 sweep_misc_user_data (void)
 {
@@ -4305,15 +4819,21 @@
 
   SWEEP_FIXED_TYPE_BLOCK (misc_user_data, Lisp_Misc_User_Data);
 }
+#endif /* not MC_ALLOC */
 
 void
 free_misc_user_data (Lisp_Object ptr)
 {
+#ifdef MC_ALLOC
+  free_lrecord (ptr);
+#else /* not MC_ALLOC */
   FREE_FIXED_TYPE_WHEN_NOT_IN_GC (misc_user_data, Lisp_Misc_User_Data, XMISC_USER_DATA (ptr));
+#endif /* not MC_ALLOC */
 }
 
 #endif /* EVENT_DATA_AS_OBJECTS */
 
+#ifndef MC_ALLOC
 static void
 sweep_markers (void)
 {
@@ -4326,12 +4846,17 @@
 
   SWEEP_FIXED_TYPE_BLOCK (marker, Lisp_Marker);
 }
+#endif /* not MC_ALLOC */
 
 /* Explicitly free a marker.  */
 void
 free_marker (Lisp_Object ptr)
 {
+#ifdef MC_ALLOC
+  free_lrecord (ptr);
+#else /* not MC_ALLOC */
   FREE_FIXED_TYPE_WHEN_NOT_IN_GC (marker, Lisp_Marker, XMARKER (ptr));
+#endif /* not MC_ALLOC */
 }
 
 
@@ -4374,7 +4899,7 @@
           fullsize = STRING_FULLSIZE (size);
 
           assert (!BIG_STRING_FULLSIZE_P (fullsize));
-	  assert (string->data_ == s_chars->chars);
+	  assert (XSTRING_DATA (string) == s_chars->chars);
 	  pos += fullsize;
         }
       assert (pos == sb->pos);
@@ -4482,6 +5007,7 @@
   }
 }
 
+#ifndef MC_ALLOC
 #if 1 /* Hack to debug missing purecopy's */
 static int debug_string_purity;
 
@@ -4504,8 +5030,9 @@
   stderr_out ("\"\n");
 }
 #endif /* 1 */
-
-
+#endif /* not MC_ALLOC */
+
+#ifndef MC_ALLOC
 static void
 sweep_strings (void)
 {
@@ -4538,7 +5065,7 @@
   gc_count_string_total_size = num_bytes;
   gc_count_short_string_total_size = num_small_bytes;
 }
-
+#endif /* not MC_ALLOC */
 
 /* I hate duplicating all this crap! */
 int
@@ -4563,6 +5090,11 @@
 static void
 gc_sweep (void)
 {
+#ifdef MC_ALLOC
+  compact_string_chars ();
+  mc_finalize ();
+  mc_sweep ();
+#else /* not MC_ALLOC */
   /* Free all unmarked records.  Do this at the very beginning,
      before anything else, so that the finalize methods can safely
      examine items in the objects.  sweep_lcrecords_1() makes
@@ -4637,10 +5169,13 @@
   sweep_eval_data ();
   sweep_misc_user_data ();
 #endif /* EVENT_DATA_AS_OBJECTS */
-
+#endif /* not MC_ALLOC */
+
+#ifndef MC_ALLOC
 #ifdef PDUMP
   pdump_objects_unmark ();
 #endif
+#endif /* not MC_ALLOC */
 }
 
 /* Clearing for disksave. */
@@ -4930,6 +5465,15 @@
       mark_object (**p++);
   }
 
+#ifdef MC_ALLOC
+  { /* mcpro () */
+    Lisp_Object *p = Dynarr_begin (mcpros);
+    Elemcount count;
+    for (count = Dynarr_length (mcpros); count; count--)
+      mark_object (*p++);
+  }
+#endif /* MC_ALLOC */
+
   { /* GCPRO() */
     struct gcpro *tail;
     int i;
@@ -5073,10 +5617,12 @@
   /* now stop inhibiting GC */
   unbind_to (speccount);
 
+#ifndef MC_ALLOC
   if (!breathing_space)
     {
       breathing_space = malloc (4096 - MALLOC_OVERHEAD);
     }
+#endif /* not MC_ALLOC */
 
   UNGCPRO;
 
@@ -5088,6 +5634,93 @@
   return;
 }
 
+#ifdef MC_ALLOC
+#ifdef MC_ALLOC_TYPE_STATS
+static Lisp_Object
+gc_plist_hack (const Ascbyte *name, int value, Lisp_Object tail)
+{
+  /* C doesn't have local functions (or closures, or GC, or readable syntax,
+     or portable numeric datatypes, or bit-vectors, or characters, or
+     arrays, or exceptions, or ...) */
+  return cons3 (intern (name), make_int (value), tail);
+}
+#endif /* MC_ALLOC_TYPE_STATS */
+
+DEFUN ("garbage-collect", Fgarbage_collect, 0, 0, "", /*
+Reclaim storage for Lisp objects no longer needed.
+Return info on amount of space in use:
+ ((USED-CONSES . STORAGE-CONSES) (USED-SYMS . STORAGE-SYMS)
+  (USED-MARKERS . STORAGE-MARKERS) USED-STRING-CHARS USED-VECTOR-SLOTS
+  PLIST)
+  where `PLIST' is a list of alternating keyword/value pairs providing
+  more detailed information.
+Garbage collection happens automatically if you cons more than
+`gc-cons-threshold' bytes of Lisp data since previous garbage collection.
+*/
+       ())
+{
+#ifdef MC_ALLOC_TYPE_STATS
+  Lisp_Object pl = Qnil;
+  int i;
+#endif /* not MC_ALLOC_TYPE_STATS */
+
+  garbage_collect_1 ();
+
+#ifdef MC_ALLOC_TYPE_STATS
+  for (i = 0; i < (countof (lrecord_implementations_table)
+		   + MODULE_DEFINABLE_TYPE_COUNT); i++)
+    {
+      if (lrecord_stats[i].instances_in_use != 0)
+        {
+          char buf [255];
+          const char *name = lrecord_implementations_table[i]->name;
+	  int len = strlen (name);
+
+	  if (lrecord_stats[i].bytes_in_use_including_overhead != 
+	      lrecord_stats[i].bytes_in_use)
+	    {
+	      sprintf (buf, "%s-storage-including-overhead", name);
+	      pl = gc_plist_hack (buf, 
+				  lrecord_stats[i]
+				  .bytes_in_use_including_overhead,
+				  pl);
+	    }
+	  
+	  sprintf (buf, "%s-storage", name);
+	  pl = gc_plist_hack (buf, 
+			      lrecord_stats[i].bytes_in_use,
+			      pl);
+	  
+	  if (name[len-1] == 's')
+	    sprintf (buf, "%ses-used", name);
+	  else
+	    sprintf (buf, "%ss-used", name);
+	  pl = gc_plist_hack (buf, lrecord_stats[i].instances_in_use, pl);
+        }
+    }
+
+  /* The things we do for backwards-compatibility */
+  return
+    list6 
+    (Fcons (make_int (lrecord_stats[lrecord_type_cons].instances_in_use),
+	    make_int (lrecord_stats[lrecord_type_cons]
+		      .bytes_in_use_including_overhead)),
+    Fcons (make_int (lrecord_stats[lrecord_type_symbol].instances_in_use),
+	    make_int (lrecord_stats[lrecord_type_symbol]
+		      .bytes_in_use_including_overhead)),
+     Fcons (make_int (lrecord_stats[lrecord_type_marker].instances_in_use),
+	    make_int (lrecord_stats[lrecord_type_marker]
+		      .bytes_in_use_including_overhead)),
+     make_int (lrecord_stats[lrecord_type_string]
+	       .bytes_in_use_including_overhead),
+     make_int (lrecord_stats[lrecord_type_vector]
+	       .bytes_in_use_including_overhead),
+     pl);
+#else /* not MC_ALLOC_TYPE_STATS */
+  return Qnil;
+#endif /* not MC_ALLOC_TYPE_STATS */
+}
+#else /* not MC_ALLOC */
 /* Debugging aids.  */
 
 static Lisp_Object
@@ -5230,6 +5863,7 @@
 	   pl);
 }
 #undef HACK_O_MATIC
+#endif /* not MC_ALLOC */
 
 DEFUN ("consing-since-gc", Fconsing_since_gc, 0, 0, "", /*
 Return the number of bytes consed since the last garbage collection.
@@ -5423,6 +6057,7 @@
   return claimed_size;
 }
 
+#ifndef MC_ALLOC
 Bytecount
 fixed_type_block_overhead (Bytecount size)
 {
@@ -5438,7 +6073,7 @@
     overhead += sizeof (void *) + per_block - storage_size;
   return overhead;
 }
-
+#endif /* not MC_ALLOC */
 #endif /* MEMORY_USAGE_STATS */
 
 
@@ -5457,9 +6092,13 @@
 #endif
 
   gc_generation_number[0] = 0;
+#ifndef MC_ALLOC
   breathing_space = 0;
+#endif /* not MC_ALLOC */
   Vgc_message = Qzero;
+#ifndef MC_ALLOC
   all_lcrecords = 0;
+#endif /* not MC_ALLOC */
   ignore_malloc_warnings = 1;
 #ifdef DOUG_LEA_MALLOC
   mallopt (M_TRIM_THRESHOLD, 128*1024); /* trim threshold */
@@ -5468,6 +6107,8 @@
   mallopt (M_MMAP_MAX, 64); /* max. number of mmap'ed areas */
 #endif
 #endif
+  init_string_chars_alloc ();
+#ifndef MC_ALLOC
   init_string_alloc ();
   init_string_chars_alloc ();
   init_cons_alloc ();
@@ -5497,6 +6138,7 @@
   init_eval_data_alloc ();
   init_misc_user_data_alloc ();
 #endif /* EVENT_DATA_AS_OBJECTS */
+#endif /* not MC_ALLOC */
 
   ignore_malloc_warnings = 0;
 
@@ -5511,6 +6153,17 @@
   Dynarr_resize (staticpro_nodump_names, 100); /* ditto */
 #endif
 
+#ifdef MC_ALLOC
+  mcpros = Dynarr_new2 (Lisp_Object_dynarr, Lisp_Object);
+  Dynarr_resize (mcpros, 1410); /* merely a small optimization */
+  dump_add_root_block_ptr (&mcpros, &mcpros_description);
+#ifdef DEBUG_XEMACS
+  mcpro_names = Dynarr_new2 (char_ptr_dynarr, char *);
+  Dynarr_resize (mcpro_names, 1410); /* merely a small optimization */
+  dump_add_root_block_ptr (&mcpro_names, &mcpro_names_description);
+#endif
+#endif /* MC_ALLOC */
+
   consing_since_gc = 0;
   need_to_garbage_collect = always_gc;
   need_to_check_c_alloca = 0;
@@ -5526,7 +6179,9 @@
 			     memory usage on Windows; not verified on other
 			     systems */
   lrecord_uid_counter = 259;
+#ifndef MC_ALLOC
   debug_string_purity = 0;
+#endif /* not MC_ALLOC */
 
   gc_currently_forbidden = 0;
   gc_hooks_inhibited = 0;
@@ -5545,6 +6200,7 @@
 #endif /* ERROR_CHECK_TYPES */
 }
 
+#ifndef MC_ALLOC
 static void
 init_lcrecord_lists (void)
 {
@@ -5556,6 +6212,7 @@
       staticpro_nodump (&all_lcrecord_lists[i]);
     }
 }
+#endif /* not MC_ALLOC */
 
 void
 init_alloc_early (void)
@@ -5576,7 +6233,9 @@
 reinit_alloc_early (void)
 {
   common_init_alloc_early ();
+#ifndef MC_ALLOC
   init_lcrecord_lists ();
+#endif /* not MC_ALLOC */
 }
 
 void
@@ -5593,8 +6252,10 @@
   INIT_LRECORD_IMPLEMENTATION (cons);
   INIT_LRECORD_IMPLEMENTATION (vector);
   INIT_LRECORD_IMPLEMENTATION (string);
+#ifndef MC_ALLOC
   INIT_LRECORD_IMPLEMENTATION (lcrecord_list);
   INIT_LRECORD_IMPLEMENTATION (free);
+#endif /* not MC_ALLOC */
 
   staticpros = Dynarr_new2 (Lisp_Object_ptr_dynarr, Lisp_Object *);
   Dynarr_resize (staticpros, 1410); /* merely a small optimization */
@@ -5605,7 +6266,20 @@
   dump_add_root_block_ptr (&staticpro_names, &staticpro_names_description);
 #endif
 
+#ifdef MC_ALLOC
+  mcpros = Dynarr_new2 (Lisp_Object_dynarr, Lisp_Object);
+  Dynarr_resize (mcpros, 1410); /* merely a small optimization */
+  dump_add_root_block_ptr (&mcpros, &mcpros_description);
+#ifdef DEBUG_XEMACS
+  mcpro_names = Dynarr_new2 (char_ptr_dynarr, char *);
+  Dynarr_resize (mcpro_names, 1410); /* merely a small optimization */
+  dump_add_root_block_ptr (&mcpro_names, &mcpro_names_description);
+#endif
+#endif /* MC_ALLOC */
+
+#ifndef MC_ALLOC
   init_lcrecord_lists ();
+#endif /* not MC_ALLOC */
 }
 
 void