1 /**************************************************************************/
2 /*                                                                        */
3 /*                                 OCaml                                  */
4 /*                                                                        */
5 /*              Damien Doligez, projet Para, INRIA Rocquencourt           */
6 /*                                                                        */
7 /*   Copyright 1996 Institut National de Recherche en Informatique et     */
8 /*     en Automatique.                                                    */
9 /*                                                                        */
10 /*   All rights reserved.  This file is distributed under the terms of    */
11 /*   the GNU Lesser General Public License version 2.1, with the          */
12 /*   special exception on linking described in the file LICENSE.          */
13 /*                                                                        */
14 /**************************************************************************/
15 
16 #ifndef CAML_MAJOR_GC_H
17 #define CAML_MAJOR_GC_H
18 
19 #ifdef CAML_INTERNALS
20 
21 #include "freelist.h"
22 #include "misc.h"
23 
24 typedef struct {
25   void *block;           /* address of the malloced block this chunk lives in */
26   asize_t alloc;         /* in bytes, used for compaction */
27   asize_t size;          /* in bytes */
28   char *next;
29 } heap_chunk_head;
30 
31 #define Chunk_size(c) (((heap_chunk_head *) (c)) [-1]).size
32 #define Chunk_alloc(c) (((heap_chunk_head *) (c)) [-1]).alloc
33 #define Chunk_next(c) (((heap_chunk_head *) (c)) [-1]).next
34 #define Chunk_block(c) (((heap_chunk_head *) (c)) [-1]).block
35 
36 extern int caml_gc_phase;
37 extern int caml_gc_subphase;
38 extern uintnat caml_allocated_words;
39 extern double caml_extra_heap_resources;
40 extern uintnat caml_dependent_size, caml_dependent_allocated;
41 extern uintnat caml_fl_wsz_at_phase_change;
42 
43 #define Phase_mark 0
44 #define Phase_clean 1
45 #define Phase_sweep 2
46 #define Phase_idle 3
47 
48 /* Subphase of mark */
49 #define Subphase_mark_roots 10
50 /* Subphase_mark_roots: At the end of this subphase all the global
51    roots are marked. */
52 #define Subphase_mark_main 11
53 /* Subphase_mark_main: At the end of this subphase all the value alive at
54    the start of this subphase and created during it are marked. */
55 #define Subphase_mark_final 12
56 /* Subphase_mark_final: At the start of this subphase register which
57    value with an ocaml finalizer are not marked, the associated
58    finalizer will be run later. So we mark now these value as alive,
59    since they must be available for their finalizer.
60   */
61 
62 CAMLextern char *caml_heap_start;
63 extern uintnat total_heap_size;
64 extern char *caml_gc_sweep_hp;
65 
66 extern int caml_major_window;
67 extern double caml_major_ring[Max_major_window];
68 extern int caml_major_ring_index;
69 extern double caml_major_work_credit;
70 extern double caml_gc_clock;
71 
72 /* [caml_major_gc_hook] is called just between the end of the mark
73    phase and the beginning of the sweep phase of the major GC */
74 CAMLextern void (*caml_major_gc_hook)(void);
75 
76 void caml_init_major_heap (asize_t);           /* size in bytes */
77 asize_t caml_clip_heap_chunk_wsz (asize_t wsz);
78 void caml_darken (value, value *);
79 void caml_major_collection_slice (intnat);
80 void major_collection (void);
81 void caml_finish_major_cycle (void);
82 void caml_set_major_window (int);
83 
84 #endif /* CAML_INTERNALS */
85 
86 #endif /* CAML_MAJOR_GC_H */
87