Commit | Line | Data |
---|---|---|
c7743d02 HWN |
1 | /* Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2002 Free Software Foundation, Inc. |
2 | * | |
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) | |
6 | * any later version. | |
7 | * | |
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. | |
12 | * | |
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 | |
17 | * | |
18 | * As a special exception, the Free Software Foundation gives permission | |
19 | * for additional uses of the text contained in its release of GUILE. | |
20 | * | |
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. | |
26 | * | |
27 | * This exception does not however invalidate any other reasons why | |
28 | * the executable file might be covered by the GNU General Public License. | |
29 | * | |
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. | |
37 | * | |
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. */ | |
41 | ||
42 | #include <assert.h> | |
43 | ||
44 | #include "libguile/private-gc.h" | |
45 | #include "libguile/gc.h" | |
46 | #include "libguile/deprecation.h" | |
47 | #include "libguile/private-gc.h" | |
48 | ||
49 | scm_t_cell_type_statistics scm_i_master_freelist; | |
50 | scm_t_cell_type_statistics scm_i_master_freelist2; | |
51 | ||
52 | ||
53 | ||
54 | ||
55 | /* | |
56 | ||
57 | In older versions of GUILE GC there was extensive support for | |
58 | debugging freelists. This was useful, since the freelist was kept | |
59 | inside the heap, and writing to an object that was GC'd would mangle | |
60 | the list. Mark bits are now separate, and checking for sane cell | |
61 | access can be done much more easily by simply checking if the mark bit | |
62 | is unset before allocation. --hwn | |
63 | ||
64 | ||
65 | ||
66 | */ | |
67 | ||
68 | #if (SCM_ENABLE_DEPRECATED == 1) | |
69 | #if defined(GUILE_DEBUG_FREELIST) | |
70 | ||
71 | SCM_DEFINE (scm_map_free_list, "map-free-list", 0, 0, 0, | |
72 | (), | |
73 | "DEPRECATED\n") | |
74 | #define FUNC_NAME s_scm_map_free_list | |
75 | { | |
76 | scm_c_issue_deprecation_warning ("map-free-list has been removed from GUILE. Doing nothing\n"); | |
77 | return SCM_UNSPECIFIED; | |
78 | } | |
79 | ||
80 | SCM_DEFINE (scm_gc_set_debug_check_freelist_x, "gc-set-debug-check-freelist!", 1, 0, 0, | |
81 | (SCM flag), | |
82 | "DEPRECATED.\n") | |
83 | #define FUNC_NAME s_scm_gc_set_debug_check_freelist_x | |
84 | { | |
85 | scm_c_issue_deprecation_warning ("gc-set-debug-check-freelist! has been removed from GUILE. Doing nothing\n"); | |
86 | return SCM_UNSPECIFIED; | |
87 | } | |
88 | #undef FUNC_NAME | |
89 | ||
90 | ||
91 | #endif /* defined (GUILE_DEBUG) */ | |
92 | #endif /* deprecated */ | |
93 | ||
94 | ||
95 | ||
96 | ||
97 | /* | |
98 | This adjust FREELIST variables to decide wether or not to allocate | |
99 | more heap in the next GC run. It uses scm_gc_cells_collected and scm_gc_cells_collected1 | |
100 | */ | |
101 | ||
102 | void | |
103 | scm_i_adjust_min_yield (scm_t_cell_type_statistics *freelist) | |
104 | { | |
105 | /* min yield is adjusted upwards so that next predicted total yield | |
106 | * (allocated cells actually freed by GC) becomes | |
107 | * `min_yield_fraction' of total heap size. Note, however, that | |
108 | * the absolute value of min_yield will correspond to `collected' | |
109 | * on one master (the one which currently is triggering GC). | |
110 | * | |
111 | * The reason why we look at total yield instead of cells collected | |
112 | * on one list is that we want to take other freelists into account. | |
113 | * On this freelist, we know that (local) yield = collected cells, | |
114 | * but that's probably not the case on the other lists. | |
115 | * | |
116 | * (We might consider computing a better prediction, for example | |
117 | * by computing an average over multiple GC:s.) | |
118 | */ | |
119 | if (freelist->min_yield_fraction) | |
120 | { | |
121 | /* Pick largest of last two yields. */ | |
122 | long delta = ((SCM_HEAP_SIZE * freelist->min_yield_fraction / 100) | |
123 | - (long) SCM_MAX (scm_gc_cells_collected_1, scm_gc_cells_collected)); | |
124 | #ifdef DEBUGINFO | |
125 | fprintf (stderr, " after GC = %lu, delta = %ld\n", | |
126 | (long) scm_cells_allocated, | |
127 | (long) delta); | |
128 | #endif | |
129 | if (delta > 0) | |
130 | freelist->min_yield += delta; | |
131 | } | |
132 | } | |
133 | ||
134 | ||
135 | static void | |
136 | scm_init_freelist (scm_t_cell_type_statistics *freelist, | |
137 | int span, | |
138 | int min_yield) | |
139 | { | |
140 | freelist->heap_segment_idx = -1; | |
141 | freelist->min_yield = 0; | |
142 | freelist->min_yield_fraction = min_yield; | |
143 | freelist->span = span; | |
144 | freelist->collected = 0; | |
145 | freelist->collected_1 = 0; | |
146 | freelist->heap_size = 0; | |
147 | } | |
148 | ||
149 | #if (SCM_ENABLE_DEPRECATED == 1) | |
150 | size_t scm_default_init_heap_size_1; | |
151 | int scm_default_min_yield_1; | |
152 | size_t scm_default_init_heap_size_2; | |
153 | int scm_default_min_yield_2; | |
154 | size_t scm_default_max_segment_size; | |
155 | #endif | |
156 | ||
157 | void | |
158 | scm_gc_init_freelist (void) | |
159 | { | |
160 | size_t init_heap_size_1 | |
161 | = scm_getenv_int ("GUILE_INIT_SEGMENT_SIZE_1", SCM_DEFAULT_INIT_HEAP_SIZE_1); | |
162 | ||
163 | size_t init_heap_size_2 | |
164 | = scm_getenv_int ("GUILE_INIT_SEGMENT_SIZE_2", SCM_DEFAULT_INIT_HEAP_SIZE_2); | |
165 | ||
166 | scm_i_freelist = SCM_EOL; | |
167 | scm_i_freelist2 = SCM_EOL; | |
168 | ||
169 | scm_init_freelist (&scm_i_master_freelist2, 2, | |
170 | scm_getenv_int ("GUILE_MIN_YIELD_2", SCM_DEFAULT_MIN_YIELD_2)); | |
171 | scm_init_freelist (&scm_i_master_freelist, 1, | |
172 | scm_getenv_int ("GUILE_MIN_YIELD_1", SCM_DEFAULT_MIN_YIELD_1)); | |
173 | ||
174 | ||
175 | scm_max_segment_size = scm_getenv_int ("GUILE_MAX_SEGMENT_SIZE", SCM_DEFAULT_MAX_SEGMENT_SIZE); | |
176 | ||
177 | scm_i_make_initial_segment (init_heap_size_1, &scm_i_master_freelist); | |
178 | scm_i_make_initial_segment (init_heap_size_2, &scm_i_master_freelist2); | |
179 | ||
180 | ||
181 | #if (SCM_ENABLE_DEPRECATED == 1) | |
182 | if ( scm_default_init_heap_size_1 || | |
183 | scm_default_min_yield_1|| | |
184 | scm_default_init_heap_size_2|| | |
185 | scm_default_min_yield_2|| | |
186 | scm_default_max_segment_size) | |
187 | { | |
188 | scm_c_issue_deprecation_warning ("Tuning heap parameters with C variables is deprecated. Use environment variables instead."); | |
189 | } | |
190 | #endif | |
191 | } | |
192 | ||
193 | ||
194 | void | |
195 | scm_i_gc_sweep_freelist_reset (scm_t_cell_type_statistics *freelist) | |
196 | { | |
197 | freelist->collected_1 = freelist->collected; | |
198 | freelist->collected = 0; | |
199 | ||
200 | /* | |
201 | at the end we simply start with the lowest segment again. | |
202 | */ | |
203 | freelist->heap_segment_idx = -1; | |
204 | } | |
205 | ||
206 | int | |
207 | scm_i_gc_grow_heap_p (scm_t_cell_type_statistics * freelist) | |
208 | { | |
209 | return SCM_MAX (freelist->collected,freelist->collected_1) < freelist->min_yield; | |
210 | } |