gc.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. /* classes: h_files */
  2. #ifndef GCH
  3. #define GCH
  4. /* Copyright (C) 1995, 96, 98, 99, 2000, 2002 Free Software Foundation, Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2, or (at your option)
  9. * any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this software; see the file COPYING. If not, write to
  18. * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  19. * Boston, MA 02111-1307 USA
  20. *
  21. * As a special exception, the Free Software Foundation gives permission
  22. * for additional uses of the text contained in its release of GUILE.
  23. *
  24. * The exception is that, if you link the GUILE library with other files
  25. * to produce an executable, this does not by itself cause the
  26. * resulting executable to be covered by the GNU General Public License.
  27. * Your use of that executable is in no way restricted on account of
  28. * linking the GUILE library code into it.
  29. *
  30. * This exception does not however invalidate any other reasons why
  31. * the executable file might be covered by the GNU General Public License.
  32. *
  33. * This exception applies only to the code released by the
  34. * Free Software Foundation under the name GUILE. If you copy
  35. * code from other Free Software Foundation releases into a copy of
  36. * GUILE, as the General Public License permits, the exception does
  37. * not apply to the code that you add in this way. To avoid misleading
  38. * anyone as to the status of such modified files, you must delete
  39. * this exception notice from them.
  40. *
  41. * If you write modifications of your own for GUILE, it is your choice
  42. * whether to permit this exception to apply to your modifications.
  43. * If you do not wish that, delete this exception notice. */
  44. #include "libguile/__scm.h"
  45. #include "libguile/hooks.h"
  46. typedef struct scm_cell
  47. {
  48. scm_bits_t word_0;
  49. scm_bits_t word_1;
  50. } scm_cell;
  51. /* SCM_CELLPTR is a pointer to a cons cell which may be compared or
  52. * differenced.
  53. */
  54. typedef scm_cell * SCM_CELLPTR;
  55. /* Cray machines have pointers that are incremented once for each word,
  56. * rather than each byte, the 3 most significant bits encode the byte
  57. * within the word. The following macros deal with this by storing the
  58. * native Cray pointers like the ones that looks like scm expects. This
  59. * is done for any pointers that might appear in the car of a scm_cell,
  60. * pointers to scm_vector elts, functions, &c are not munged.
  61. */
  62. #ifdef _UNICOS
  63. # define SCM2PTR(x) ((SCM_CELLPTR) (SCM_UNPACK (x) >> 3))
  64. # define PTR2SCM(x) (SCM_PACK (((scm_bits_t) (x)) << 3))
  65. #else
  66. # define SCM2PTR(x) ((SCM_CELLPTR) (SCM_UNPACK (x)))
  67. # define PTR2SCM(x) (SCM_PACK ((scm_bits_t) (x)))
  68. #endif /* def _UNICOS */
  69. /* Low level cell data accessing macros:
  70. */
  71. #if SCM_DEBUG_CELL_ACCESSES == 1
  72. #define SCM_VALIDATE_CELL(cell, expr) \
  73. (!scm_cellp (cell) ? abort (), 0 : (expr))
  74. #else
  75. #define SCM_VALIDATE_CELL(cell, expr) expr
  76. #endif
  77. #define SCM_CELL_WORD(x, n) \
  78. SCM_VALIDATE_CELL ((x), \
  79. ((scm_bits_t *) SCM2PTR (x)) [n])
  80. #define SCM_CELL_WORD_0(x) SCM_CELL_WORD (x, 0)
  81. #define SCM_CELL_WORD_1(x) SCM_CELL_WORD (x, 1)
  82. #define SCM_CELL_WORD_2(x) SCM_CELL_WORD (x, 2)
  83. #define SCM_CELL_WORD_3(x) SCM_CELL_WORD (x, 3)
  84. #define SCM_CELL_OBJECT(x, n) \
  85. SCM_VALIDATE_CELL ((x), \
  86. SCM_PACK (((scm_bits_t *) SCM2PTR (x)) [n]))
  87. #define SCM_CELL_OBJECT_0(x) SCM_CELL_OBJECT (x, 0)
  88. #define SCM_CELL_OBJECT_1(x) SCM_CELL_OBJECT (x, 1)
  89. #define SCM_CELL_OBJECT_2(x) SCM_CELL_OBJECT (x, 2)
  90. #define SCM_CELL_OBJECT_3(x) SCM_CELL_OBJECT (x, 3)
  91. #define SCM_SET_CELL_WORD(x, n, v) \
  92. SCM_VALIDATE_CELL ((x), \
  93. ((scm_bits_t *) SCM2PTR (x)) [n] = (scm_bits_t) (v))
  94. #define SCM_SET_CELL_WORD_0(x, v) SCM_SET_CELL_WORD (x, 0, v)
  95. #define SCM_SET_CELL_WORD_1(x, v) SCM_SET_CELL_WORD (x, 1, v)
  96. #define SCM_SET_CELL_WORD_2(x, v) SCM_SET_CELL_WORD (x, 2, v)
  97. #define SCM_SET_CELL_WORD_3(x, v) SCM_SET_CELL_WORD (x, 3, v)
  98. #define SCM_SET_CELL_OBJECT(x, n, v) \
  99. SCM_VALIDATE_CELL ((x), \
  100. ((scm_bits_t *) SCM2PTR (x)) [n] = SCM_UNPACK (v))
  101. #define SCM_SET_CELL_OBJECT_0(x, v) SCM_SET_CELL_OBJECT (x, 0, v)
  102. #define SCM_SET_CELL_OBJECT_1(x, v) SCM_SET_CELL_OBJECT (x, 1, v)
  103. #define SCM_SET_CELL_OBJECT_2(x, v) SCM_SET_CELL_OBJECT (x, 2, v)
  104. #define SCM_SET_CELL_OBJECT_3(x, v) SCM_SET_CELL_OBJECT (x, 3, v)
  105. #define SCM_CELL_TYPE(x) SCM_CELL_WORD_0 (x)
  106. #define SCM_SET_CELL_TYPE(x, t) SCM_SET_CELL_WORD_0 (x, t)
  107. #define SCM_SETAND_CAR(x, y) \
  108. (SCM_SETCAR ((x), SCM_PACK (SCM_UNPACK (SCM_CAR (x)) & (y))))
  109. #define SCM_SETAND_CDR(x, y)\
  110. (SCM_SETCDR ((x), SCM_PACK (SCM_UNPACK (SCM_CDR (x)) & (y))))
  111. #define SCM_SETOR_CAR(x, y)\
  112. (SCM_SETCAR ((x), SCM_PACK (SCM_UNPACK (SCM_CAR (x)) | (y))))
  113. #define SCM_SETOR_CDR(x, y)\
  114. (SCM_SETCDR ((x), SCM_PACK (SCM_UNPACK (SCM_CDR (x)) | (y))))
  115. #define SCM_CELL_WORD_LOC(x, n) (&SCM_CELL_WORD (x, n))
  116. #define SCM_CARLOC(x) ((SCM *) (&(((scm_bits_t *) SCM2PTR (x)) [0])))
  117. #define SCM_CDRLOC(x) ((SCM *) (&(((scm_bits_t *) SCM2PTR (x)) [1])))
  118. /* SCM_PTR_LT and friends define how to compare two SCM_CELLPTRs (which may
  119. * point to cells in different heap segments).
  120. */
  121. #define SCM_PTR_LT(x, y) ((x) < (y))
  122. #define SCM_PTR_GT(x, y) (SCM_PTR_LT (y, x))
  123. #define SCM_PTR_LE(x, y) (!SCM_PTR_GT (x, y))
  124. #define SCM_PTR_GE(x, y) (!SCM_PTR_LT (x, y))
  125. /* Dirk:FIXME:: */
  126. /* Freelists consist of linked cells where the type entry holds the value
  127. * scm_tc_free_cell and the second entry holds a pointer to the next cell of
  128. * the freelist. Due to this structure, freelist cells are not cons cells
  129. * and thus may not be accessed using SCM_CAR and SCM_CDR.
  130. */
  131. /* the allocated thing: The car of new cells is set to
  132. scm_tc16_allocated to avoid the fragile state of newcells wrt the
  133. gc. If it stays as a freecell, any allocation afterwards could
  134. cause the cell to go back on the freelist, which will bite you
  135. sometime afterwards. */
  136. #ifdef GUILE_DEBUG_FREELIST
  137. #define SCM_NEWCELL(_into) do { _into = scm_debug_newcell (); } while (0)
  138. #define SCM_NEWCELL2(_into) do { _into = scm_debug_newcell2 (); } while (0)
  139. #else
  140. /* When we introduce POSIX threads support, every thread will have
  141. a freelist of its own. Then it won't any longer be necessary to
  142. initialize cells with scm_tc16_allocated. */
  143. #define SCM_NEWCELL(_into) \
  144. do { \
  145. if (SCM_IMP (scm_freelist)) \
  146. _into = scm_gc_for_newcell (&scm_master_freelist, \
  147. &scm_freelist); \
  148. else \
  149. { \
  150. _into = scm_freelist; \
  151. scm_freelist = SCM_CDR (scm_freelist); \
  152. SCM_SET_CELL_TYPE (_into, scm_tc16_allocated); \
  153. } \
  154. } while(0)
  155. #define SCM_NEWCELL2(_into) \
  156. do { \
  157. if (SCM_IMP (scm_freelist2)) \
  158. _into = scm_gc_for_newcell (&scm_master_freelist2, \
  159. &scm_freelist2); \
  160. else \
  161. { \
  162. _into = scm_freelist2; \
  163. scm_freelist2 = SCM_CDR (scm_freelist2); \
  164. SCM_SET_CELL_TYPE (_into, scm_tc16_allocated); \
  165. } \
  166. } while(0)
  167. #endif
  168. #define SCM_FREEP(x) (SCM_NIMP (x) && (SCM_CELL_TYPE (x) == scm_tc_free_cell))
  169. #define SCM_NFREEP(x) (!SCM_FREEP (x))
  170. /* 1. This shouldn't be used on immediates.
  171. 2. It thinks that subrs are always unmarked (harmless). */
  172. #define SCM_MARKEDP(x) ((SCM_CELL_TYPE (x) & 5) == 5 \
  173. ? SCM_GC8MARKP (x) \
  174. : SCM_GCMARKP (x))
  175. #define SCM_NMARKEDP(x) (!SCM_MARKEDP (x))
  176. extern struct scm_heap_seg_data_t *scm_heap_table;
  177. extern int scm_n_heap_segs;
  178. extern int scm_take_stdin;
  179. extern int scm_block_gc;
  180. extern int scm_gc_heap_lock;
  181. extern int scm_default_init_heap_size_1;
  182. extern int scm_default_min_yield_1;
  183. extern int scm_default_init_heap_size_2;
  184. extern int scm_default_min_yield_2;
  185. extern int scm_default_max_segment_size;
  186. extern scm_sizet scm_max_segment_size;
  187. extern SCM_CELLPTR scm_heap_org;
  188. extern SCM scm_freelist;
  189. extern struct scm_freelist_t scm_master_freelist;
  190. extern SCM scm_freelist2;
  191. extern struct scm_freelist_t scm_master_freelist2;
  192. extern unsigned long scm_gc_cells_collected;
  193. extern unsigned long scm_gc_yield;
  194. extern unsigned long scm_gc_malloc_collected;
  195. extern unsigned long scm_gc_ports_collected;
  196. extern unsigned long scm_cells_allocated;
  197. extern long scm_mallocated;
  198. extern unsigned long scm_mtrigger;
  199. extern SCM scm_after_gc_hook;
  200. extern scm_c_hook_t scm_before_gc_c_hook;
  201. extern scm_c_hook_t scm_before_mark_c_hook;
  202. extern scm_c_hook_t scm_before_sweep_c_hook;
  203. extern scm_c_hook_t scm_after_sweep_c_hook;
  204. extern scm_c_hook_t scm_after_gc_c_hook;
  205. #if defined (GUILE_DEBUG) || defined (GUILE_DEBUG_FREELIST)
  206. extern SCM scm_map_free_list (void);
  207. extern SCM scm_free_list_length (void);
  208. #endif
  209. #ifdef GUILE_DEBUG_FREELIST
  210. extern SCM scm_debug_newcell (void);
  211. extern SCM scm_debug_newcell2 (void);
  212. extern SCM scm_gc_set_debug_check_freelist_x (SCM flag);
  213. #endif
  214. extern SCM scm_object_address (SCM obj);
  215. extern SCM scm_unhash_name (SCM name);
  216. extern SCM scm_gc_stats (void);
  217. extern void scm_gc_start (const char *what);
  218. extern void scm_gc_end (void);
  219. extern SCM scm_gc (void);
  220. extern void scm_gc_for_alloc (struct scm_freelist_t *freelist);
  221. extern SCM scm_gc_for_newcell (struct scm_freelist_t *master, SCM *freelist);
  222. #if 0
  223. extern void scm_alloc_cluster (struct scm_freelist_t *master);
  224. #endif
  225. extern void scm_igc (const char *what);
  226. extern void scm_gc_mark (SCM p);
  227. extern void scm_mark_locations (SCM_STACKITEM x[], scm_sizet n);
  228. extern int scm_cellp (SCM value);
  229. extern void scm_gc_sweep (void);
  230. extern void * scm_must_malloc (scm_sizet len, const char *what);
  231. extern void * scm_must_realloc (void *where,
  232. scm_sizet olen, scm_sizet len,
  233. const char *what);
  234. extern void scm_done_malloc (long size);
  235. extern void scm_must_free (void *obj);
  236. extern void scm_remember (SCM * ptr);
  237. extern SCM scm_return_first (SCM elt, ...);
  238. extern int scm_return_first_int (int x, ...);
  239. extern SCM scm_permanent_object (SCM obj);
  240. extern SCM scm_protect_object (SCM obj);
  241. extern SCM scm_unprotect_object (SCM obj);
  242. extern int scm_init_storage (scm_sizet init_heap_size, int trig,
  243. scm_sizet init_heap2_size, int trig2,
  244. scm_sizet max_segment_size);
  245. extern void scm_init_gc (void);
  246. #endif /* GCH */
  247. /*
  248. Local Variables:
  249. c-file-style: "gnu"
  250. End:
  251. */