1 /* Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2, or (at your option)
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this software; see the file COPYING. If not, write to
15 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
16 * Boston, MA 02111-1307 USA
18 * As a special exception, the Free Software Foundation gives permission
19 * for additional uses of the text contained in its release of GUILE.
21 * The exception is that, if you link the GUILE library with other files
22 * to produce an executable, this does not by itself cause the
23 * resulting executable to be covered by the GNU General Public License.
24 * Your use of that executable is in no way restricted on account of
25 * linking the GUILE library code into it.
27 * This exception does not however invalidate any other reasons why
28 * the executable file might be covered by the GNU General Public License.
30 * This exception applies only to the code released by the
31 * Free Software Foundation under the name GUILE. If you copy
32 * code from other Free Software Foundation releases into a copy of
33 * GUILE, as the General Public License permits, the exception does
34 * not apply to the code that you add in this way. To avoid misleading
35 * anyone as to the status of such modified files, you must delete
36 * this exception notice from them.
38 * If you write modifications of your own for GUILE, it is your choice
39 * whether to permit this exception to apply to your modifications.
40 * If you do not wish that, delete this exception notice. */
49 #include "guardians.h"
66 #define var_start(x, y) va_start(x, y)
69 #define var_start(x, y) va_start(x)
73 /* {heap tuning parameters}
75 * These are parameters for controlling memory allocation. The heap
76 * is the area out of which scm_cons, and object headers are allocated.
78 * Each heap cell is 8 bytes on a 32 bit machine and 16 bytes on a
79 * 64 bit machine. The units of the _SIZE parameters are bytes.
80 * Cons pairs and object headers occupy one heap cell.
82 * SCM_INIT_HEAP_SIZE is the initial size of heap. If this much heap is
83 * allocated initially the heap will grow by half its current size
84 * each subsequent time more heap is needed.
86 * If SCM_INIT_HEAP_SIZE heap cannot be allocated initially, SCM_HEAP_SEG_SIZE
87 * will be used, and the heap will grow by SCM_HEAP_SEG_SIZE when more
88 * heap is needed. SCM_HEAP_SEG_SIZE must fit into type scm_sizet. This code
89 * is in scm_init_storage() and alloc_some_heap() in sys.c
91 * If SCM_INIT_HEAP_SIZE can be allocated initially, the heap will grow by
92 * SCM_EXPHEAP(scm_heap_size) when more heap is needed.
94 * SCM_MIN_HEAP_SEG_SIZE is minimum size of heap to accept when more heap
97 * INIT_MALLOC_LIMIT is the initial amount of malloc usage which will
100 * SCM_MTRIGGER_HYSTERESIS is the amount of malloc storage that must be
101 * reclaimed by a GC triggered by must_malloc. If less than this is
102 * reclaimed, the trigger threshold is raised. [I don't know what a
103 * good value is. I arbitrarily chose 1/10 of the INIT_MALLOC_LIMIT to
104 * work around a oscillation that caused almost constant GC.]
107 #define SCM_INIT_HEAP_SIZE (32768L*sizeof(scm_cell))
108 #define SCM_MIN_HEAP_SEG_SIZE (2048L*sizeof(scm_cell))
110 # define SCM_HEAP_SEG_SIZE 32768L
113 # define SCM_HEAP_SEG_SIZE (7000L*sizeof(scm_cell))
115 # define SCM_HEAP_SEG_SIZE (16384L*sizeof(scm_cell))
118 #define SCM_EXPHEAP(scm_heap_size) (scm_heap_size*2)
119 #define SCM_INIT_MALLOC_LIMIT 100000
120 #define SCM_MTRIGGER_HYSTERESIS (SCM_INIT_MALLOC_LIMIT/10)
122 /* CELL_UP and CELL_DN are used by scm_init_heap_seg to find scm_cell aligned inner
123 bounds for allocated storage */
126 /*in 386 protected mode we must only adjust the offset */
127 # define CELL_UP(p) MK_FP(FP_SEG(p), ~7&(FP_OFF(p)+7))
128 # define CELL_DN(p) MK_FP(FP_SEG(p), ~7&FP_OFF(p))
131 # define CELL_UP(p) (SCM_CELLPTR)(~1L & ((long)(p)+1L))
132 # define CELL_DN(p) (SCM_CELLPTR)(~1L & (long)(p))
134 # define CELL_UP(p) (SCM_CELLPTR)(~(sizeof(scm_cell)-1L) & ((long)(p)+sizeof(scm_cell)-1L))
135 # define CELL_DN(p) (SCM_CELLPTR)(~(sizeof(scm_cell)-1L) & (long)(p))
142 * is the head of freelist of cons pairs.
144 SCM scm_freelist
= SCM_EOL
;
147 * is the number of bytes of must_malloc allocation needed to trigger gc.
149 unsigned long scm_mtrigger
;
153 * If set, don't expand the heap. Set only during gc, during which no allocation
154 * is supposed to take place anyway.
156 int scm_gc_heap_lock
= 0;
159 * Don't pause for collection if this is set -- just
163 int scm_block_gc
= 1;
165 /* If fewer than MIN_GC_YIELD cells are recovered during a garbage
166 * collection (GC) more space is allocated for the heap.
168 #define MIN_GC_YIELD (scm_heap_size/4)
170 /* During collection, this accumulates objects holding
173 SCM
*scm_weak_vectors
;
177 /* GC Statistics Keeping
179 unsigned long scm_cells_allocated
= 0;
180 unsigned long scm_mallocated
= 0;
181 unsigned long scm_gc_cells_collected
;
182 unsigned long scm_gc_malloc_collected
;
183 unsigned long scm_gc_ports_collected
;
184 unsigned long scm_gc_rt
;
185 unsigned long scm_gc_time_taken
= 0;
187 SCM_SYMBOL (sym_cells_allocated
, "cells-allocated");
188 SCM_SYMBOL (sym_heap_size
, "cell-heap-size");
189 SCM_SYMBOL (sym_mallocated
, "bytes-malloced");
190 SCM_SYMBOL (sym_mtrigger
, "gc-malloc-threshold");
191 SCM_SYMBOL (sym_heap_segments
, "cell-heap-segments");
192 SCM_SYMBOL (sym_gc_time_taken
, "gc-time-taken");
195 struct scm_heap_seg_data
197 /* lower and upper bounds of the segment */
198 SCM_CELLPTR bounds
[2];
200 /* address of the head-of-freelist pointer for this segment's cells.
201 All segments usually point to the same one, scm_freelist. */
204 /* number of SCM words per object in this segment */
207 /* If SEG_DATA->valid is non-zero, the conservative marking
208 functions will apply SEG_DATA->valid to the purported pointer and
209 SEG_DATA, and mark the object iff the function returns non-zero.
210 At the moment, I don't think anyone uses this. */
217 static void scm_mark_weak_vector_spines
SCM_P ((void));
218 static scm_sizet init_heap_seg
SCM_P ((SCM_CELLPTR
, scm_sizet
, int, SCM
*));
219 static void alloc_some_heap
SCM_P ((int, SCM
*));
223 /* Debugging functions. */
225 #ifdef DEBUG_FREELIST
227 /* Return the number of the heap segment containing CELL. */
233 for (i
= 0; i
< scm_n_heap_segs
; i
++)
234 if (SCM_PTR_LE (scm_heap_table
[i
].bounds
[0], (SCM_CELLPTR
) cell
)
235 && SCM_PTR_GT (scm_heap_table
[i
].bounds
[1], (SCM_CELLPTR
) cell
))
237 fprintf (stderr
, "which_seg: can't find segment containing cell %lx\n",
243 SCM_PROC (s_map_free_list
, "map-free-list", 0, 0, 0, scm_map_free_list
);
247 int last_seg
= -1, count
= 0;
250 fprintf (stderr
, "%d segments total\n", scm_n_heap_segs
);
251 for (f
= scm_freelist
; SCM_NIMP (f
); f
= SCM_CDR (f
))
253 int this_seg
= which_seg (f
);
255 if (this_seg
!= last_seg
)
258 fprintf (stderr
, " %5d cells in segment %d\n", count
, last_seg
);
265 fprintf (stderr
, " %5d cells in segment %d\n", count
, last_seg
);
269 return SCM_UNSPECIFIED
;
273 /* Number of calls to SCM_NEWCELL since startup. */
274 static unsigned long scm_newcell_count
;
276 /* Search freelist for anything that isn't marked as a free cell.
277 Abort if we find something. */
279 scm_check_freelist ()
284 for (f
= scm_freelist
; SCM_NIMP (f
); f
= SCM_CDR (f
), i
++)
285 if (SCM_CAR (f
) != (SCM
) scm_tc_free_cell
)
287 fprintf (stderr
, "Bad cell in freelist on newcell %lu: %d'th elt\n",
288 scm_newcell_count
, i
);
294 static int scm_debug_check_freelist
= 0;
296 scm_debug_newcell (void)
301 if (scm_debug_check_freelist
)
302 scm_check_freelist ();
304 /* The rest of this is supposed to be identical to the SCM_NEWCELL
306 if (SCM_IMP (scm_freelist
))
307 new = scm_gc_for_newcell ();
311 scm_freelist
= SCM_CDR (scm_freelist
);
312 ++scm_cells_allocated
;
318 #endif /* DEBUG_FREELIST */
322 /* {Scheme Interface to GC}
325 SCM_PROC (s_gc_stats
, "gc-stats", 0, 0, 0, scm_gc_stats
);
332 SCM local_scm_mtrigger
;
333 SCM local_scm_mallocated
;
334 SCM local_scm_heap_size
;
335 SCM local_scm_cells_allocated
;
336 SCM local_scm_gc_time_taken
;
344 for (i
= scm_n_heap_segs
; i
--; )
345 heap_segs
= scm_cons (scm_cons (scm_ulong2num ((unsigned long)scm_heap_table
[i
].bounds
[1]),
346 scm_ulong2num ((unsigned long)scm_heap_table
[i
].bounds
[0])),
348 if (scm_n_heap_segs
!= n
)
352 local_scm_mtrigger
= scm_mtrigger
;
353 local_scm_mallocated
= scm_mallocated
;
354 local_scm_heap_size
= scm_heap_size
;
355 local_scm_cells_allocated
= scm_cells_allocated
;
356 local_scm_gc_time_taken
= scm_gc_time_taken
;
358 answer
= scm_listify (scm_cons (sym_gc_time_taken
, scm_ulong2num (local_scm_gc_time_taken
)),
359 scm_cons (sym_cells_allocated
, scm_ulong2num (local_scm_cells_allocated
)),
360 scm_cons (sym_heap_size
, scm_ulong2num (local_scm_heap_size
)),
361 scm_cons (sym_mallocated
, scm_ulong2num (local_scm_mallocated
)),
362 scm_cons (sym_mtrigger
, scm_ulong2num (local_scm_mtrigger
)),
363 scm_cons (sym_heap_segments
, heap_segs
),
374 scm_gc_rt
= SCM_INUM (scm_get_internal_run_time ());
375 scm_gc_cells_collected
= 0;
376 scm_gc_malloc_collected
= 0;
377 scm_gc_ports_collected
= 0;
383 scm_gc_rt
= SCM_INUM (scm_get_internal_run_time ()) - scm_gc_rt
;
384 scm_gc_time_taken
= scm_gc_time_taken
+ scm_gc_rt
;
385 scm_system_async_mark (scm_gc_async
);
389 SCM_PROC(s_object_address
, "object-address", 1, 0, 0, scm_object_addr
);
391 scm_object_addr (obj
)
394 return scm_ulong2num ((unsigned long)obj
);
398 SCM_PROC(s_gc
, "gc", 0, 0, 0, scm_gc
);
405 return SCM_UNSPECIFIED
;
410 /* {C Interface For When GC is Triggered}
414 scm_gc_for_alloc (ncells
, freelistp
)
420 if ((scm_gc_cells_collected
< MIN_GC_YIELD
) || SCM_IMP (*freelistp
))
422 alloc_some_heap (ncells
, freelistp
);
429 scm_gc_for_newcell ()
432 scm_gc_for_alloc (1, &scm_freelist
);
434 scm_freelist
= SCM_CDR (fl
);
445 /* During the critical section, only the current thread may run. */
446 SCM_THREAD_CRITICAL_SECTION_START
;
449 /* fprintf (stderr, "gc: %s\n", what); */
452 if (!scm_stack_base
|| scm_block_gc
)
461 scm_guardian_gc_init ();
463 /* unprotect any struct types with no instances */
469 pos
= &scm_type_obj_list
;
470 type_list
= scm_type_obj_list
;
471 while (type_list
!= SCM_EOL
)
472 if (SCM_VELTS (SCM_CAR (type_list
))[scm_struct_i_refcnt
])
474 pos
= SCM_CDRLOC (type_list
);
475 type_list
= SCM_CDR (type_list
);
479 *pos
= SCM_CDR (type_list
);
480 type_list
= SCM_CDR (type_list
);
485 /* flush dead entries from the continuation stack */
490 elts
= SCM_VELTS (scm_continuation_stack
);
491 bound
= SCM_LENGTH (scm_continuation_stack
);
492 x
= SCM_INUM (scm_continuation_stack_ptr
);
495 elts
[x
] = SCM_BOOL_F
;
502 /* Protect from the C stack. This must be the first marking
503 * done because it provides information about what objects
504 * are "in-use" by the C code. "in-use" objects are those
505 * for which the values from SCM_LENGTH and SCM_CHARS must remain
506 * usable. This requirement is stricter than a liveness
507 * requirement -- in particular, it constrains the implementation
508 * of scm_vector_set_length_x.
510 SCM_FLUSH_REGISTER_WINDOWS
;
511 /* This assumes that all registers are saved into the jmp_buf */
512 setjmp (scm_save_regs_gc_mark
);
513 scm_mark_locations ((SCM_STACKITEM
*) scm_save_regs_gc_mark
,
514 ( (scm_sizet
) (sizeof (SCM_STACKITEM
) - 1 +
515 sizeof scm_save_regs_gc_mark
)
516 / sizeof (SCM_STACKITEM
)));
519 /* stack_len is long rather than scm_sizet in order to guarantee that
520 &stack_len is long aligned */
521 #ifdef SCM_STACK_GROWS_UP
523 long stack_len
= (SCM_STACKITEM
*) (&stack_len
) - scm_stack_base
;
525 long stack_len
= scm_stack_size (scm_stack_base
);
527 scm_mark_locations (scm_stack_base
, (scm_sizet
) stack_len
);
530 long stack_len
= scm_stack_base
- (SCM_STACKITEM
*) (&stack_len
);
532 long stack_len
= scm_stack_size (scm_stack_base
);
534 scm_mark_locations ((scm_stack_base
- stack_len
), (scm_sizet
) stack_len
);
538 #else /* USE_THREADS */
540 /* Mark every thread's stack and registers */
541 scm_threads_mark_stacks();
543 #endif /* USE_THREADS */
545 /* FIXME: insert a phase to un-protect string-data preserved
546 * in scm_vector_set_length_x.
549 j
= SCM_NUM_PROTECTS
;
551 scm_gc_mark (scm_sys_protects
[j
]);
554 scm_gc_mark (scm_root
->handle
);
557 scm_mark_weak_vector_spines ();
559 scm_guardian_zombify ();
567 SCM_THREAD_CRITICAL_SECTION_END
;
577 /* Mark an object precisely.
593 if (SCM_NCELLP (ptr
))
594 scm_wta (ptr
, "rogue pointer in heap", NULL
);
596 switch (SCM_TYP7 (ptr
))
598 case scm_tcs_cons_nimcar
:
599 if (SCM_GCMARKP (ptr
))
602 if (SCM_IMP (SCM_CDR (ptr
))) /* SCM_IMP works even with a GC mark */
607 scm_gc_mark (SCM_CAR (ptr
));
608 ptr
= SCM_GCCDR (ptr
);
610 case scm_tcs_cons_imcar
:
611 if (SCM_GCMARKP (ptr
))
614 ptr
= SCM_GCCDR (ptr
);
616 case scm_tcs_cons_gloc
:
617 if (SCM_GCMARKP (ptr
))
622 vcell
= SCM_CAR (ptr
) - 1L;
623 switch (SCM_CDR (vcell
))
627 ptr
= SCM_GCCDR (ptr
);
639 vtable_data
= (SCM
*)vcell
;
640 layout
= vtable_data
[scm_vtable_index_layout
];
641 len
= SCM_LENGTH (layout
);
642 fields_desc
= SCM_CHARS (layout
);
643 /* We're using SCM_GCCDR here like STRUCT_DATA, except
644 that it removes the mark */
645 mem
= (SCM
*)SCM_GCCDR (ptr
);
647 if (vtable_data
[scm_struct_i_flags
] & SCM_STRUCTF_ENTITY
)
649 scm_gc_mark (mem
[scm_struct_i_proc
+ 0]);
650 scm_gc_mark (mem
[scm_struct_i_proc
+ 1]);
651 scm_gc_mark (mem
[scm_struct_i_proc
+ 2]);
652 scm_gc_mark (mem
[scm_struct_i_proc
+ 3]);
656 for (x
= 0; x
< len
- 2; x
+= 2, ++mem
)
657 if (fields_desc
[x
] == 'p')
659 if (fields_desc
[x
] == 'p')
661 if (SCM_LAYOUT_TAILP (fields_desc
[x
+ 1]))
662 for (x
= *mem
; x
; --x
)
663 scm_gc_mark (*++mem
);
668 if (!SCM_CDR (vcell
))
670 SCM_SETGCMARK (vcell
);
671 ptr
= vtable_data
[scm_vtable_index_vtable
];
678 case scm_tcs_closures
:
679 if (SCM_GCMARKP (ptr
))
682 if (SCM_IMP (SCM_CDR (ptr
)))
684 ptr
= SCM_CLOSCAR (ptr
);
687 scm_gc_mark (SCM_CLOSCAR (ptr
));
688 ptr
= SCM_GCCDR (ptr
);
691 case scm_tc7_lvector
:
695 if (SCM_GC8MARKP (ptr
))
697 SCM_SETGC8MARK (ptr
);
698 i
= SCM_LENGTH (ptr
);
702 if (SCM_NIMP (SCM_VELTS (ptr
)[i
]))
703 scm_gc_mark (SCM_VELTS (ptr
)[i
]);
704 ptr
= SCM_VELTS (ptr
)[0];
709 SCM_SETGC8MARK (ptr
);
711 scm_mark_locations (SCM_VELTS (ptr
),
714 (sizeof (SCM_STACKITEM
) + -1 +
715 sizeof (scm_contregs
)) /
716 sizeof (SCM_STACKITEM
)));
731 SCM_SETGC8MARK (ptr
);
734 case scm_tc7_substring
:
735 if (SCM_GC8MARKP(ptr
))
737 SCM_SETGC8MARK (ptr
);
742 if (SCM_GC8MARKP(ptr
))
744 scm_weak_vectors
[scm_n_weak
++] = ptr
;
745 if (scm_n_weak
>= scm_weak_size
)
747 SCM_SYSCALL (scm_weak_vectors
=
748 (SCM
*) realloc ((char *) scm_weak_vectors
,
749 sizeof (SCM
) * (scm_weak_size
*= 2)));
750 if (scm_weak_vectors
== NULL
)
752 scm_puts ("weak vector table", scm_cur_errp
);
753 scm_puts ("\nFATAL ERROR DURING CRITICAL SCM_CODE SECTION\n",
755 exit(SCM_EXIT_FAILURE
);
758 SCM_SETGC8MARK (ptr
);
759 if (SCM_IS_WHVEC_ANY (ptr
))
766 len
= SCM_LENGTH (ptr
);
767 weak_keys
= SCM_IS_WHVEC (ptr
) || SCM_IS_WHVEC_B (ptr
);
768 weak_values
= SCM_IS_WHVEC_V (ptr
) || SCM_IS_WHVEC_B (ptr
);
770 for (x
= 0; x
< len
; ++x
)
773 alist
= SCM_VELTS (ptr
)[x
];
774 /* mark everything on the alist
775 * except the keys or values, according to weak_values and weak_keys.
777 while ( SCM_NIMP (alist
)
779 && !SCM_GCMARKP (alist
)
780 && SCM_NIMP (SCM_CAR (alist
))
781 && SCM_CONSP (SCM_CAR (alist
)))
786 kvpair
= SCM_CAR (alist
);
787 next_alist
= SCM_CDR (alist
);
790 * SCM_SETGCMARK (alist);
791 * SCM_SETGCMARK (kvpair);
793 * It may be that either the key or value is protected by
794 * an escaped reference to part of the spine of this alist.
795 * If we mark the spine here, and only mark one or neither of the
796 * key and value, they may never be properly marked.
797 * This leads to a horrible situation in which an alist containing
798 * freelist cells is exported.
800 * So only mark the spines of these arrays last of all marking.
801 * If somebody confuses us by constructing a weak vector
802 * with a circular alist then we are hosed, but at least we
803 * won't prematurely drop table entries.
806 scm_gc_mark (SCM_CAR (kvpair
));
808 scm_gc_mark (SCM_GCCDR (kvpair
));
811 if (SCM_NIMP (alist
))
817 case scm_tc7_msymbol
:
818 if (SCM_GC8MARKP(ptr
))
820 SCM_SETGC8MARK (ptr
);
821 scm_gc_mark (SCM_SYMBOL_FUNC (ptr
));
822 ptr
= SCM_SYMBOL_PROPS (ptr
);
824 case scm_tc7_ssymbol
:
825 if (SCM_GC8MARKP(ptr
))
827 SCM_SETGC8MARK (ptr
);
830 ptr
= (SCM
)(scm_heap_org
+ (((unsigned long)SCM_CAR (ptr
)) >> 8));
833 i
= SCM_PTOBNUM (ptr
);
834 if (!(i
< scm_numptob
))
836 if (SCM_GC8MARKP (ptr
))
838 SCM_SETGC8MARK (ptr
);
839 if (SCM_PTAB_ENTRY(ptr
))
840 scm_gc_mark (SCM_PTAB_ENTRY(ptr
)->file_name
);
841 if (scm_ptobs
[i
].mark
)
843 ptr
= (scm_ptobs
[i
].mark
) (ptr
);
850 if (SCM_GC8MARKP (ptr
))
852 SCM_SETGC8MARK (ptr
);
853 switch SCM_GCTYP16 (ptr
)
854 { /* should be faster than going through scm_smobs */
855 case scm_tc_free_cell
:
856 /* printf("found free_cell %X ", ptr); fflush(stdout); */
857 SCM_SETCDR (ptr
, SCM_EOL
);
859 case scm_tcs_bignums
:
863 i
= SCM_SMOBNUM (ptr
);
864 if (!(i
< scm_numsmob
))
866 if (scm_smobs
[i
].mark
)
868 ptr
= (scm_smobs
[i
].mark
) (ptr
);
876 def
:scm_wta (ptr
, "unknown type in ", "gc_mark");
881 /* Mark a Region Conservatively
885 scm_mark_locations (x
, n
)
891 register SCM_CELLPTR ptr
;
894 if SCM_CELLP (*(SCM
**) & x
[m
])
896 ptr
= (SCM_CELLPTR
) SCM2PTR ((*(SCM
**) & x
[m
]));
898 j
= scm_n_heap_segs
- 1;
899 if ( SCM_PTR_LE (scm_heap_table
[i
].bounds
[0], ptr
)
900 && SCM_PTR_GT (scm_heap_table
[j
].bounds
[1], ptr
))
907 || SCM_PTR_GT (scm_heap_table
[i
].bounds
[1], ptr
))
909 else if (SCM_PTR_LE (scm_heap_table
[j
].bounds
[0], ptr
))
917 if (SCM_PTR_GT (scm_heap_table
[k
].bounds
[1], ptr
))
921 if (SCM_PTR_LE (scm_heap_table
[i
].bounds
[0], ptr
))
926 else if (SCM_PTR_LE (scm_heap_table
[k
].bounds
[0], ptr
))
930 if (SCM_PTR_GT (scm_heap_table
[j
].bounds
[1], ptr
))
936 if ( !scm_heap_table
[seg_id
].valid
937 || scm_heap_table
[seg_id
].valid (ptr
,
938 &scm_heap_table
[seg_id
]))
939 scm_gc_mark (*(SCM
*) & x
[m
]);
948 /* The following is a C predicate which determines if an SCM value can be
949 regarded as a pointer to a cell on the heap. The code is duplicated
950 from scm_mark_locations. */
958 register SCM_CELLPTR ptr
;
960 if SCM_CELLP (*(SCM
**) & value
)
962 ptr
= (SCM_CELLPTR
) SCM2PTR ((*(SCM
**) & value
));
964 j
= scm_n_heap_segs
- 1;
965 if ( SCM_PTR_LE (scm_heap_table
[i
].bounds
[0], ptr
)
966 && SCM_PTR_GT (scm_heap_table
[j
].bounds
[1], ptr
))
973 || SCM_PTR_GT (scm_heap_table
[i
].bounds
[1], ptr
))
975 else if (SCM_PTR_LE (scm_heap_table
[j
].bounds
[0], ptr
))
983 if (SCM_PTR_GT (scm_heap_table
[k
].bounds
[1], ptr
))
987 if (SCM_PTR_LE (scm_heap_table
[i
].bounds
[0], ptr
))
992 else if (SCM_PTR_LE (scm_heap_table
[k
].bounds
[0], ptr
))
996 if (SCM_PTR_GT (scm_heap_table
[j
].bounds
[1], ptr
))
1002 if ( !scm_heap_table
[seg_id
].valid
1003 || scm_heap_table
[seg_id
].valid (ptr
,
1004 &scm_heap_table
[seg_id
]))
1016 scm_mark_weak_vector_spines ()
1020 for (i
= 0; i
< scm_n_weak
; ++i
)
1022 if (SCM_IS_WHVEC_ANY (scm_weak_vectors
[i
]))
1029 obj
= scm_weak_vectors
[i
];
1030 ptr
= SCM_VELTS (scm_weak_vectors
[i
]);
1031 n
= SCM_LENGTH (scm_weak_vectors
[i
]);
1032 for (j
= 0; j
< n
; ++j
)
1037 while ( SCM_NIMP (alist
)
1038 && SCM_CONSP (alist
)
1039 && !SCM_GCMARKP (alist
)
1040 && SCM_NIMP (SCM_CAR (alist
))
1041 && SCM_CONSP (SCM_CAR (alist
)))
1043 SCM_SETGCMARK (alist
);
1044 SCM_SETGCMARK (SCM_CAR (alist
));
1045 alist
= SCM_GCCDR (alist
);
1057 register SCM_CELLPTR ptr
;
1058 #ifdef SCM_POINTERS_MUNGED
1059 register SCM scmptr
;
1062 #define scmptr (SCM)ptr
1064 register SCM nfreelist
;
1065 register SCM
*hp_freelist
;
1073 /* Reset all free list pointers. We'll reconstruct them completely
1075 for (i
= 0; i
< scm_n_heap_segs
; i
++)
1076 *scm_heap_table
[i
].freelistp
= SCM_EOL
;
1078 for (i
= 0; i
< scm_n_heap_segs
; i
++)
1080 register scm_sizet n
= 0;
1081 register scm_sizet j
;
1083 /* Unmarked cells go onto the front of the freelist this heap
1084 segment points to. Rather than updating the real freelist
1085 pointer as we go along, we accumulate the new head in
1086 nfreelist. Then, if it turns out that the entire segment is
1087 free, we free (i.e., malloc's free) the whole segment, and
1088 simply don't assign nfreelist back into the real freelist. */
1089 hp_freelist
= scm_heap_table
[i
].freelistp
;
1090 nfreelist
= *hp_freelist
;
1092 span
= scm_heap_table
[i
].ncells
;
1093 ptr
= CELL_UP (scm_heap_table
[i
].bounds
[0]);
1094 seg_size
= CELL_DN (scm_heap_table
[i
].bounds
[1]) - ptr
;
1095 for (j
= seg_size
+ span
; j
-= span
; ptr
+= span
)
1097 #ifdef SCM_POINTERS_MUNGED
1098 scmptr
= PTR2SCM (ptr
);
1100 switch SCM_TYP7 (scmptr
)
1102 case scm_tcs_cons_gloc
:
1103 if (SCM_GCMARKP (scmptr
))
1105 if (SCM_CDR (SCM_CAR (scmptr
) - 1) == (SCM
)1)
1106 SCM_SETCDR (SCM_CAR (scmptr
) - 1, (SCM
) 0);
1111 vcell
= SCM_CAR (scmptr
) - 1L;
1113 if ((SCM_CDR (vcell
) == 0) || (SCM_CDR (vcell
) == 1))
1115 SCM
*p
= (SCM
*) SCM_GCCDR (scmptr
);
1116 if (((SCM
*) vcell
)[scm_vtable_index_layout
]
1117 & SCM_STRUCTF_LIGHT
)
1119 SCM layout
= ((SCM
*)vcell
)[scm_vtable_index_layout
];
1120 m
+= SCM_LENGTH (layout
) / 2;
1125 m
+= p
[scm_struct_i_n_words
] * sizeof (SCM
);
1126 /* I feel like I'm programming in BCPL here... */
1127 free ((char *) p
[scm_struct_i_ptr
]);
1132 case scm_tcs_cons_imcar
:
1133 case scm_tcs_cons_nimcar
:
1134 case scm_tcs_closures
:
1135 if (SCM_GCMARKP (scmptr
))
1139 if (SCM_GC8MARKP (scmptr
))
1145 m
+= (1 + SCM_LENGTH (scmptr
)) * sizeof (SCM
);
1146 scm_must_free ((char *)(SCM_VELTS (scmptr
) - 1));
1150 case scm_tc7_vector
:
1151 case scm_tc7_lvector
:
1155 if (SCM_GC8MARKP (scmptr
))
1158 m
+= (SCM_LENGTH (scmptr
) * sizeof (SCM
));
1160 scm_must_free (SCM_CHARS (scmptr
));
1161 /* SCM_SETCHARS(scmptr, 0);*/
1164 if SCM_GC8MARKP (scmptr
)
1166 m
+= sizeof (long) * ((SCM_HUGE_LENGTH (scmptr
) + SCM_LONG_BIT
- 1) / SCM_LONG_BIT
);
1168 case scm_tc7_byvect
:
1169 if SCM_GC8MARKP (scmptr
)
1171 m
+= SCM_HUGE_LENGTH (scmptr
) * sizeof (char);
1175 if SCM_GC8MARKP (scmptr
)
1177 m
+= SCM_HUGE_LENGTH (scmptr
) * sizeof (long);
1180 if SCM_GC8MARKP (scmptr
)
1182 m
+= SCM_HUGE_LENGTH (scmptr
) * sizeof (short);
1185 case scm_tc7_llvect
:
1186 if SCM_GC8MARKP (scmptr
)
1188 m
+= SCM_HUGE_LENGTH (scmptr
) * sizeof (long_long
);
1192 if SCM_GC8MARKP (scmptr
)
1194 m
+= SCM_HUGE_LENGTH (scmptr
) * sizeof (float);
1197 if SCM_GC8MARKP (scmptr
)
1199 m
+= SCM_HUGE_LENGTH (scmptr
) * sizeof (double);
1202 if SCM_GC8MARKP (scmptr
)
1204 m
+= SCM_HUGE_LENGTH (scmptr
) * 2 * sizeof (double);
1206 case scm_tc7_substring
:
1207 if (SCM_GC8MARKP (scmptr
))
1210 case scm_tc7_string
:
1211 if (SCM_GC8MARKP (scmptr
))
1213 m
+= SCM_HUGE_LENGTH (scmptr
) + 1;
1215 case scm_tc7_msymbol
:
1216 if (SCM_GC8MARKP (scmptr
))
1218 m
+= ( SCM_LENGTH (scmptr
)
1220 + sizeof (SCM
) * ((SCM
*)SCM_CHARS (scmptr
) - SCM_SLOTS(scmptr
)));
1221 scm_must_free ((char *)SCM_SLOTS (scmptr
));
1223 case scm_tc7_contin
:
1224 if SCM_GC8MARKP (scmptr
)
1226 m
+= SCM_LENGTH (scmptr
) * sizeof (SCM_STACKITEM
) + sizeof (scm_contregs
);
1227 if (SCM_VELTS (scmptr
))
1229 case scm_tc7_ssymbol
:
1230 if SCM_GC8MARKP(scmptr
)
1236 if SCM_GC8MARKP (scmptr
)
1238 if SCM_OPENP (scmptr
)
1240 int k
= SCM_PTOBNUM (scmptr
);
1241 if (!(k
< scm_numptob
))
1243 /* Keep "revealed" ports alive. */
1244 if (scm_revealed_count(scmptr
) > 0)
1246 /* Yes, I really do mean scm_ptobs[k].free */
1247 /* rather than ftobs[k].close. .close */
1248 /* is for explicit CLOSE-PORT by user */
1249 (scm_ptobs
[k
].free
) (scmptr
);
1250 SCM_SETSTREAM (scmptr
, 0);
1251 scm_remove_from_port_table (scmptr
);
1252 scm_gc_ports_collected
++;
1253 SCM_SETAND_CAR (scmptr
, ~SCM_OPN
);
1257 switch SCM_GCTYP16 (scmptr
)
1259 case scm_tc_free_cell
:
1260 if SCM_GC8MARKP (scmptr
)
1264 case scm_tcs_bignums
:
1265 if SCM_GC8MARKP (scmptr
)
1267 m
+= (SCM_NUMDIGS (scmptr
) * SCM_BITSPERDIG
/ SCM_CHAR_BIT
);
1269 #endif /* def SCM_BIGDIG */
1271 if SCM_GC8MARKP (scmptr
)
1273 switch ((int) (SCM_CAR (scmptr
) >> 16))
1275 case (SCM_IMAG_PART
| SCM_REAL_PART
) >> 16:
1276 m
+= sizeof (double);
1277 case SCM_REAL_PART
>> 16:
1278 case SCM_IMAG_PART
>> 16:
1279 m
+= sizeof (double);
1288 if SCM_GC8MARKP (scmptr
)
1293 k
= SCM_SMOBNUM (scmptr
);
1294 if (!(k
< scm_numsmob
))
1296 m
+= (scm_smobs
[k
].free
) ((SCM
) scmptr
);
1302 sweeperr
:scm_wta (scmptr
, "unknown type in ", "gc_sweep");
1306 if (SCM_CAR (scmptr
) == (SCM
) scm_tc_free_cell
)
1309 /* Stick the new cell on the front of nfreelist. It's
1310 critical that we mark this cell as freed; otherwise, the
1311 conservative collector might trace it as some other type
1313 SCM_SETCAR (scmptr
, (SCM
) scm_tc_free_cell
);
1314 SCM_SETCDR (scmptr
, nfreelist
);
1319 SCM_CLRGC8MARK (scmptr
);
1322 SCM_CLRGCMARK (scmptr
);
1324 #ifdef GC_FREE_SEGMENTS
1329 scm_heap_size
-= seg_size
;
1330 free ((char *) scm_heap_table
[i
].bounds
[0]);
1331 scm_heap_table
[i
].bounds
[0] = 0;
1332 for (j
= i
+ 1; j
< scm_n_heap_segs
; j
++)
1333 scm_heap_table
[j
- 1] = scm_heap_table
[j
];
1334 scm_n_heap_segs
-= 1;
1335 i
--; /* We need to scan the segment just moved. */
1338 #endif /* ifdef GC_FREE_SEGMENTS */
1339 /* Update the real freelist pointer to point to the head of
1340 the list of free cells we've built for this segment. */
1341 *hp_freelist
= nfreelist
;
1343 #ifdef DEBUG_FREELIST
1344 scm_check_freelist ();
1345 scm_map_free_list ();
1348 scm_gc_cells_collected
+= n
;
1350 /* Scan weak vectors. */
1353 for (i
= 0; i
< scm_n_weak
; ++i
)
1355 if (!SCM_IS_WHVEC_ANY (scm_weak_vectors
[i
]))
1359 ptr
= SCM_VELTS (scm_weak_vectors
[i
]);
1360 n
= SCM_LENGTH (scm_weak_vectors
[i
]);
1361 for (j
= 0; j
< n
; ++j
)
1362 if (SCM_NIMP (ptr
[j
]) && SCM_FREEP (ptr
[j
]))
1363 ptr
[j
] = SCM_BOOL_F
;
1365 else /* if (SCM_IS_WHVEC_ANY (scm_weak_vectors[i])) */
1367 SCM obj
= scm_weak_vectors
[i
];
1368 register long n
= SCM_LENGTH (scm_weak_vectors
[i
]);
1371 ptr
= SCM_VELTS (scm_weak_vectors
[i
]);
1373 for (j
= 0; j
< n
; ++j
)
1380 weak_keys
= SCM_IS_WHVEC (obj
) || SCM_IS_WHVEC_B (obj
);
1381 weak_values
= SCM_IS_WHVEC_V (obj
) || SCM_IS_WHVEC_B (obj
);
1386 while (SCM_NIMP (alist
)
1387 && SCM_CONSP (alist
)
1388 && SCM_NIMP (SCM_CAR (alist
))
1389 && SCM_CONSP (SCM_CAR (alist
)))
1394 key
= SCM_CAAR (alist
);
1395 value
= SCM_CDAR (alist
);
1396 if ( (weak_keys
&& SCM_NIMP (key
) && SCM_FREEP (key
))
1397 || (weak_values
&& SCM_NIMP (value
) && SCM_FREEP (value
)))
1399 *fixup
= SCM_CDR (alist
);
1402 fixup
= SCM_CDRLOC (alist
);
1403 alist
= SCM_CDR (alist
);
1409 scm_cells_allocated
= (scm_heap_size
- scm_gc_cells_collected
);
1410 scm_mallocated
-= m
;
1411 scm_gc_malloc_collected
= m
;
1417 /* {Front end to malloc}
1419 * scm_must_malloc, scm_must_realloc, scm_must_free, scm_done_malloc
1421 * These functions provide services comperable to malloc, realloc, and
1422 * free. They are for allocating malloced parts of scheme objects.
1423 * The primary purpose of the front end is to impose calls to gc.
1427 * Return newly malloced storage or throw an error.
1429 * The parameter WHAT is a string for error reporting.
1430 * If the threshold scm_mtrigger will be passed by this
1431 * allocation, or if the first call to malloc fails,
1432 * garbage collect -- on the presumption that some objects
1433 * using malloced storage may be collected.
1435 * The limit scm_mtrigger may be raised by this allocation.
1438 scm_must_malloc (len
, what
)
1443 scm_sizet size
= len
;
1444 unsigned long nm
= scm_mallocated
+ size
;
1447 scm_wta (SCM_MAKINUM (len
), (char *) SCM_NALLOC
, what
);
1448 if ((nm
<= scm_mtrigger
))
1450 SCM_SYSCALL (ptr
= (char *) malloc (size
));
1453 scm_mallocated
= nm
;
1459 nm
= scm_mallocated
+ size
;
1460 SCM_SYSCALL (ptr
= (char *) malloc (size
));
1463 scm_mallocated
= nm
;
1464 if (nm
> scm_mtrigger
- SCM_MTRIGGER_HYSTERESIS
) {
1465 if (nm
> scm_mtrigger
)
1466 scm_mtrigger
= nm
+ nm
/ 2;
1468 scm_mtrigger
+= scm_mtrigger
/ 2;
1477 * is similar to scm_must_malloc.
1480 scm_must_realloc (char *where
,
1486 scm_sizet size
= len
;
1487 scm_sizet nm
= scm_mallocated
+ size
- olen
;
1490 scm_wta (SCM_MAKINUM (len
), (char *) SCM_NALLOC
, what
);
1491 if ((nm
<= scm_mtrigger
))
1493 SCM_SYSCALL (ptr
= (char *) realloc (where
, size
));
1496 scm_mallocated
= nm
;
1501 nm
= scm_mallocated
+ size
- olen
;
1502 SCM_SYSCALL (ptr
= (char *) realloc (where
, size
));
1505 scm_mallocated
= nm
;
1506 if (nm
> scm_mtrigger
- SCM_MTRIGGER_HYSTERESIS
) {
1507 if (nm
> scm_mtrigger
)
1508 scm_mtrigger
= nm
+ nm
/ 2;
1510 scm_mtrigger
+= scm_mtrigger
/ 2;
1524 scm_wta (SCM_INUM0
, "already free", "");
1527 /* Announce that there has been some malloc done that will be freed
1528 * during gc. A typical use is for a smob that uses some malloced
1529 * memory but can not get it from scm_must_malloc (for whatever
1530 * reason). When a new object of this smob is created you call
1531 * scm_done_malloc with the size of the object. When your smob free
1532 * function is called, be sure to include this size in the return
1536 scm_done_malloc (size
)
1539 scm_mallocated
+= size
;
1541 if (scm_mallocated
> scm_mtrigger
)
1543 scm_igc ("foreign mallocs");
1544 if (scm_mallocated
> scm_mtrigger
- SCM_MTRIGGER_HYSTERESIS
)
1546 if (scm_mallocated
> scm_mtrigger
)
1547 scm_mtrigger
= scm_mallocated
+ scm_mallocated
/ 2;
1549 scm_mtrigger
+= scm_mtrigger
/ 2;
1559 * Each heap segment is an array of objects of a particular size.
1560 * Every segment has an associated (possibly shared) freelist.
1561 * A table of segment records is kept that records the upper and
1562 * lower extents of the segment; this is used during the conservative
1563 * phase of gc to identify probably gc roots (because they point
1564 * into valid segments at reasonable offsets). */
1567 * is true if the first segment was smaller than INIT_HEAP_SEG.
1568 * If scm_expmem is set to one, subsequent segment allocations will
1569 * allocate segments of size SCM_EXPHEAP(scm_heap_size).
1574 * is the lowest base address of any heap segment.
1576 SCM_CELLPTR scm_heap_org
;
1578 struct scm_heap_seg_data
* scm_heap_table
= 0;
1579 int scm_n_heap_segs
= 0;
1582 * is the total number of cells in heap segments.
1584 unsigned long scm_heap_size
= 0;
1587 * initializes a new heap segment and return the number of objects it contains.
1589 * The segment origin, segment size in bytes, and the span of objects
1590 * in cells are input parameters. The freelist is both input and output.
1592 * This function presume that the scm_heap_table has already been expanded
1593 * to accomodate a new segment record.
1598 init_heap_seg (seg_org
, size
, ncells
, freelistp
)
1599 SCM_CELLPTR seg_org
;
1604 register SCM_CELLPTR ptr
;
1605 #ifdef SCM_POINTERS_MUNGED
1606 register SCM scmptr
;
1611 SCM_CELLPTR seg_end
;
1615 if (seg_org
== NULL
)
1620 /* Compute the ceiling on valid object pointers w/in this segment.
1622 seg_end
= CELL_DN ((char *) ptr
+ size
);
1624 /* Find the right place and insert the segment record.
1627 for (new_seg_index
= 0;
1628 ( (new_seg_index
< scm_n_heap_segs
)
1629 && SCM_PTR_LE (scm_heap_table
[new_seg_index
].bounds
[0], seg_org
));
1635 for (i
= scm_n_heap_segs
; i
> new_seg_index
; --i
)
1636 scm_heap_table
[i
] = scm_heap_table
[i
- 1];
1641 scm_heap_table
[new_seg_index
].valid
= 0;
1642 scm_heap_table
[new_seg_index
].ncells
= ncells
;
1643 scm_heap_table
[new_seg_index
].freelistp
= freelistp
;
1644 scm_heap_table
[new_seg_index
].bounds
[0] = (SCM_CELLPTR
)ptr
;
1645 scm_heap_table
[new_seg_index
].bounds
[1] = (SCM_CELLPTR
)seg_end
;
1648 /* Compute the least valid object pointer w/in this segment
1650 ptr
= CELL_UP (ptr
);
1653 n_new_objects
= seg_end
- ptr
;
1655 /* Prepend objects in this segment to the freelist.
1657 while (ptr
< seg_end
)
1659 #ifdef SCM_POINTERS_MUNGED
1660 scmptr
= PTR2SCM (ptr
);
1662 SCM_SETCAR (scmptr
, (SCM
) scm_tc_free_cell
);
1663 SCM_SETCDR (scmptr
, PTR2SCM (ptr
+ ncells
));
1669 /* Patch up the last freelist pointer in the segment
1670 * to join it to the input freelist.
1672 SCM_SETCDR (PTR2SCM (ptr
), *freelistp
);
1673 *freelistp
= PTR2SCM (CELL_UP (seg_org
));
1675 scm_heap_size
+= (ncells
* n_new_objects
);
1684 alloc_some_heap (ncells
, freelistp
)
1688 struct scm_heap_seg_data
* tmptable
;
1692 /* Critical code sections (such as the garbage collector)
1693 * aren't supposed to add heap segments.
1695 if (scm_gc_heap_lock
)
1696 scm_wta (SCM_UNDEFINED
, "need larger initial", "heap");
1698 /* Expand the heap tables to have room for the new segment.
1699 * Do not yet increment scm_n_heap_segs -- that is done by init_heap_seg
1700 * only if the allocation of the segment itself succeeds.
1702 len
= (1 + scm_n_heap_segs
) * sizeof (struct scm_heap_seg_data
);
1704 SCM_SYSCALL (tmptable
= ((struct scm_heap_seg_data
*)
1705 realloc ((char *)scm_heap_table
, len
)));
1707 scm_wta (SCM_UNDEFINED
, "could not grow", "hplims");
1709 scm_heap_table
= tmptable
;
1712 /* Pick a size for the new heap segment.
1713 * The rule for picking the size of a segment is explained in
1718 len
= (scm_sizet
) (SCM_EXPHEAP (scm_heap_size
) * sizeof (scm_cell
));
1719 if ((scm_sizet
) (SCM_EXPHEAP (scm_heap_size
) * sizeof (scm_cell
)) != len
)
1723 len
= SCM_HEAP_SEG_SIZE
;
1728 smallest
= (ncells
* sizeof (scm_cell
));
1730 len
= (ncells
* sizeof (scm_cell
));
1732 /* Allocate with decaying ambition. */
1733 while ((len
>= SCM_MIN_HEAP_SEG_SIZE
)
1734 && (len
>= smallest
))
1736 SCM_SYSCALL (ptr
= (SCM_CELLPTR
) malloc (len
));
1739 init_heap_seg (ptr
, len
, ncells
, freelistp
);
1746 scm_wta (SCM_UNDEFINED
, "could not grow", "heap");
1751 SCM_PROC (s_unhash_name
, "unhash-name", 1, 0, 0, scm_unhash_name
);
1753 scm_unhash_name (name
)
1758 SCM_ASSERT (SCM_NIMP (name
) && SCM_SYMBOLP (name
), name
, SCM_ARG1
, s_unhash_name
);
1760 bound
= scm_n_heap_segs
;
1761 for (x
= 0; x
< bound
; ++x
)
1765 p
= (SCM_CELLPTR
)scm_heap_table
[x
].bounds
[0];
1766 pbound
= (SCM_CELLPTR
)scm_heap_table
[x
].bounds
[1];
1771 if (1 == (7 & (int)incar
))
1774 if ( ((name
== SCM_BOOL_T
) || (SCM_CAR (incar
) == name
))
1775 && (SCM_CDR (incar
) != 0)
1776 && (SCM_CDR (incar
) != 1))
1790 /* {GC Protection Helper Functions}
1801 scm_return_first (SCM elt
, ...)
1808 scm_permanent_object (obj
)
1812 scm_permobjs
= scm_cons (obj
, scm_permobjs
);
1818 /* Protect OBJ from the garbage collector. OBJ will not be freed,
1819 even if all other references are dropped, until someone applies
1820 scm_unprotect_object to it. This function returns OBJ.
1822 Calls to scm_protect_object nest. For every object O, there is a
1823 counter which scm_protect_object(O) increments and
1824 scm_unprotect_object(O) decrements, if it is greater than zero. If
1825 an object's counter is greater than zero, the garbage collector
1828 Of course, that's not how it's implemented. scm_protect_object and
1829 scm_unprotect_object just maintain a list of references to things.
1830 Since the GC knows about this list, all objects it mentions stay
1831 alive. scm_protect_object adds its argument to the list;
1832 scm_unprotect_object removes the first occurrence of its argument
1835 scm_protect_object (obj
)
1838 scm_protects
= scm_cons (obj
, scm_protects
);
1844 /* Remove any protection for OBJ established by a prior call to
1845 scm_protect_object. This function returns OBJ.
1847 See scm_protect_object for more information. */
1849 scm_unprotect_object (obj
)
1852 SCM
*tail_ptr
= &scm_protects
;
1854 while (SCM_NIMP (*tail_ptr
) && SCM_CONSP (*tail_ptr
))
1855 if (SCM_CAR (*tail_ptr
) == obj
)
1857 *tail_ptr
= SCM_CDR (*tail_ptr
);
1861 tail_ptr
= SCM_CDRLOC (*tail_ptr
);
1869 scm_init_storage (scm_sizet init_heap_size
)
1873 j
= SCM_NUM_PROTECTS
;
1875 scm_sys_protects
[--j
] = SCM_BOOL_F
;
1877 scm_freelist
= SCM_EOL
;
1880 j
= SCM_HEAP_SEG_SIZE
;
1881 scm_mtrigger
= SCM_INIT_MALLOC_LIMIT
;
1882 scm_heap_table
= ((struct scm_heap_seg_data
*)
1883 scm_must_malloc (sizeof (struct scm_heap_seg_data
), "hplims"));
1884 if (0L == init_heap_size
)
1885 init_heap_size
= SCM_INIT_HEAP_SIZE
;
1887 if ((init_heap_size
!= j
)
1888 || !init_heap_seg ((SCM_CELLPTR
) malloc (j
), j
, 1, &scm_freelist
))
1890 j
= SCM_HEAP_SEG_SIZE
;
1891 if (!init_heap_seg ((SCM_CELLPTR
) malloc (j
), j
, 1, &scm_freelist
))
1896 scm_heap_org
= CELL_UP (scm_heap_table
[0].bounds
[0]);
1897 /* scm_hplims[0] can change. do not remove scm_heap_org */
1898 if (!(scm_weak_vectors
= (SCM
*) malloc ((scm_weak_size
= 32) * sizeof(SCM
))))
1901 /* Initialise the list of ports. */
1902 scm_port_table
= (struct scm_port_table
**) malloc ((long) (sizeof (struct scm_port_table
)
1903 * scm_port_table_room
));
1904 if (!scm_port_table
)
1908 scm_undefineds
= scm_cons (SCM_UNDEFINED
, SCM_EOL
);
1909 SCM_SETCDR (scm_undefineds
, scm_undefineds
);
1911 scm_listofnull
= scm_cons (SCM_EOL
, SCM_EOL
);
1912 scm_nullstr
= scm_makstr (0L, 0);
1913 scm_nullvect
= scm_make_vector (SCM_INUM0
, SCM_UNDEFINED
);
1914 scm_symhash
= scm_make_vector ((SCM
) SCM_MAKINUM (scm_symhash_dim
), SCM_EOL
);
1915 scm_weak_symhash
= scm_make_weak_key_hash_table ((SCM
) SCM_MAKINUM (scm_symhash_dim
));
1916 scm_symhash_vars
= scm_make_vector ((SCM
) SCM_MAKINUM (scm_symhash_dim
), SCM_EOL
);
1917 scm_stand_in_procs
= SCM_EOL
;
1918 scm_permobjs
= SCM_EOL
;
1919 scm_protects
= SCM_EOL
;
1920 scm_asyncs
= SCM_EOL
;
1921 scm_sysintern ("most-positive-fixnum", (SCM
) SCM_MAKINUM (SCM_MOST_POSITIVE_FIXNUM
));
1922 scm_sysintern ("most-negative-fixnum", (SCM
) SCM_MAKINUM (SCM_MOST_NEGATIVE_FIXNUM
));
1924 scm_sysintern ("bignum-radix", SCM_MAKINUM (SCM_BIGRAD
));