Skip to content

Commit 280120d

Browse files
authored
Merge pull request #1013 from Unity-Technologies/boehm-gc-params
Make gc params work for Boehm
2 parents def3444 + 7194a04 commit 280120d

File tree

5 files changed

+75
-63
lines changed

5 files changed

+75
-63
lines changed

mono/metadata/boehm-gc.c

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ void
117117
mono_gc_base_init (void)
118118
{
119119
char *env;
120+
char *params_opts = NULL;
121+
char *debug_opts = NULL;
120122

121123
if (gc_initialized)
122124
return;
@@ -189,19 +191,21 @@ mono_gc_base_init (void)
189191
/* If GC_no_dls is set to true, GC_find_limit is not called. This causes a seg fault on Android With Mono's Older Boehm. */
190192
GC_no_dls = TRUE;
191193
#endif
194+
195+
debug_opts = mono_gc_debug_get();
196+
if (debug_opts)
192197
{
193-
if ((env = g_getenv ("MONO_GC_DEBUG"))) {
194-
char **opts = g_strsplit (env, ",", -1);
195-
for (char **ptr = opts; ptr && *ptr; ptr ++) {
196-
char *opt = *ptr;
197-
if (!strcmp (opt, "do-not-finalize")) {
198-
mono_do_not_finalize = 1;
199-
} else if (!strcmp (opt, "log-finalizers")) {
200-
log_finalizers = 1;
201-
}
198+
char **opts = g_strsplit (debug_opts, ",", -1);
199+
for (char **ptr = opts; ptr && *ptr; ptr ++) {
200+
char *opt = *ptr;
201+
if (!strcmp (opt, "do-not-finalize")) {
202+
mono_do_not_finalize = 1;
203+
} else if (!strcmp (opt, "log-finalizers")) {
204+
log_finalizers = 1;
202205
}
203-
g_free (env);
204206
}
207+
g_strfreev (opts);
208+
g_free (debug_opts);
205209
}
206210

207211
GC_init ();
@@ -213,10 +217,12 @@ mono_gc_base_init (void)
213217
GC_init_gcj_malloc (5, NULL);
214218
GC_allow_register_threads ();
215219

216-
if ((env = g_getenv ("MONO_GC_PARAMS"))) {
217-
char **ptr, **opts = g_strsplit (env, ",", -1);
220+
params_opts = mono_gc_params_get();
221+
if (params_opts) {
222+
char **ptr, **opts = g_strsplit (params_opts, ",", -1);
218223
for (ptr = opts; *ptr; ++ptr) {
219224
char *opt = *ptr;
225+
220226
if (g_str_has_prefix (opt, "max-heap-size=")) {
221227
size_t max_heap;
222228

@@ -260,8 +266,8 @@ mono_gc_base_init (void)
260266
*/
261267
}
262268
}
263-
g_free (env);
264269
g_strfreev (opts);
270+
g_free (params_opts);
265271
}
266272

267273
mono_thread_callbacks_init ();
@@ -763,6 +769,10 @@ mono_gc_alloc_obj (MonoVTable *vtable, size_t size)
763769
{
764770
MonoObject *obj;
765771

772+
if (strcmp(vtable->klass->name, "RuntimeTestInfo") == 0)
773+
{
774+
printf("hello");
775+
}
766776
if (!vtable->klass->has_references) {
767777
obj = (MonoObject *)GC_MALLOC_ATOMIC (size);
768778
if (G_UNLIKELY (!obj))
@@ -1579,16 +1589,6 @@ mono_gc_get_logfile (void)
15791589
return NULL;
15801590
}
15811591

1582-
void
1583-
mono_gc_params_set (const char* options)
1584-
{
1585-
}
1586-
1587-
void
1588-
mono_gc_debug_set (const char* options)
1589-
{
1590-
}
1591-
15921592
void
15931593
mono_gc_conservatively_scan_area (void *start, void *end)
15941594
{

mono/metadata/gc.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ static MonoCoopCond pending_done_cond;
8787
static MonoCoopMutex pending_done_mutex;
8888
#endif
8989

90+
static char* gc_params_options;
91+
static char* gc_debug_options;
92+
93+
#define MONO_GC_PARAMS_NAME "MONO_GC_PARAMS"
94+
#define MONO_GC_DEBUG_NAME "MONO_GC_DEBUG"
95+
9096
static void object_register_finalizer (MonoObject *obj, void (*callback)(void *, void*));
9197

9298
static void reference_queue_proccess_all (void);
@@ -161,6 +167,48 @@ coop_cond_timedwait_alertable (MonoCoopCond *cond, MonoCoopMutex *mutex, guint32
161167
return res;
162168
}
163169

170+
void
171+
mono_gc_params_set (const char* options)
172+
{
173+
if (gc_params_options)
174+
g_free (gc_params_options);
175+
176+
gc_params_options = g_strdup (options);
177+
}
178+
179+
char *
180+
mono_gc_params_get ()
181+
{
182+
char *env;
183+
if ((env = g_getenv (MONO_GC_PARAMS_NAME)) || gc_params_options) {
184+
char *params_opts = g_strdup_printf ("%s,%s", gc_params_options ? gc_params_options : "", env ? env : "");
185+
g_free (env);
186+
return params_opts;
187+
}
188+
return NULL;
189+
}
190+
191+
void
192+
mono_gc_debug_set (const char* options)
193+
{
194+
if (gc_debug_options)
195+
g_free (gc_debug_options);
196+
197+
gc_debug_options = g_strdup (options);
198+
}
199+
200+
char *
201+
mono_gc_debug_get ()
202+
{
203+
char *env;
204+
if ((env = g_getenv (MONO_GC_DEBUG_NAME)) || gc_debug_options) {
205+
char *debug_opts = g_strdup_printf ("%s,%s", gc_debug_options ? gc_debug_options : "", env ? env : "");
206+
g_free (env);
207+
return debug_opts;
208+
}
209+
return NULL;
210+
}
211+
164212
/*
165213
* actually, we might want to queue the finalize requests in a separate thread,
166214
* but we need to be careful about the execution domain of the thread...

mono/metadata/null-gc.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -458,16 +458,6 @@ mono_gc_get_logfile (void)
458458
return NULL;
459459
}
460460

461-
void
462-
mono_gc_params_set (const char* options)
463-
{
464-
}
465-
466-
void
467-
mono_gc_debug_set (const char* options)
468-
{
469-
}
470-
471461
void
472462
mono_gc_conservatively_scan_area (void *start, void *end)
473463
{

mono/sgen/gc-internal-agnostic.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ FILE *mono_gc_get_logfile (void);
117117

118118
/* equivalent to options set via MONO_GC_PARAMS */
119119
void mono_gc_params_set (const char* options);
120+
char* mono_gc_params_get();
120121
/* equivalent to options set via MONO_GC_DEBUG */
121122
void mono_gc_debug_set (const char* options);
123+
char *mono_gc_debug_get();
122124

123125
#endif

mono/sgen/sgen-gc.c

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,6 @@ static SGEN_TV_DECLARE (time_major_conc_collection_end);
302302

303303
int gc_debug_level = 0;
304304
FILE* gc_debug_file;
305-
static char* gc_params_options;
306-
static char* gc_debug_options;
307305

308306
/*
309307
void
@@ -1022,24 +1020,6 @@ mono_gc_get_logfile (void)
10221020
return gc_debug_file;
10231021
}
10241022

1025-
void
1026-
mono_gc_params_set (const char* options)
1027-
{
1028-
if (gc_params_options)
1029-
g_free (gc_params_options);
1030-
1031-
gc_params_options = g_strdup (options);
1032-
}
1033-
1034-
void
1035-
mono_gc_debug_set (const char* options)
1036-
{
1037-
if (gc_debug_options)
1038-
g_free (gc_debug_options);
1039-
1040-
gc_debug_options = g_strdup (options);
1041-
}
1042-
10431023
static void
10441024
scan_finalizer_entries (SgenPointerQueue *fin_queue, ScanCopyContext ctx)
10451025
{
@@ -3326,11 +3306,7 @@ sgen_gc_init (void)
33263306

33273307
mono_coop_mutex_init (&sgen_interruption_mutex);
33283308

3329-
if ((env = g_getenv (MONO_GC_PARAMS_NAME)) || gc_params_options) {
3330-
params_opts = g_strdup_printf ("%s,%s", gc_params_options ? gc_params_options : "", env ? env : "");
3331-
g_free (env);
3332-
}
3333-
3309+
params_opts = mono_gc_params_get();
33343310
if (params_opts) {
33353311
opts = g_strsplit (params_opts, ",", -1);
33363312
for (ptr = opts; *ptr; ++ptr) {
@@ -3541,11 +3517,7 @@ sgen_gc_init (void)
35413517
sgen_pinning_init ();
35423518
sgen_cement_init (cement_enabled);
35433519

3544-
if ((env = g_getenv (MONO_GC_DEBUG_NAME)) || gc_debug_options) {
3545-
debug_opts = g_strdup_printf ("%s,%s", gc_debug_options ? gc_debug_options : "", env ? env : "");
3546-
g_free (env);
3547-
}
3548-
3520+
debug_opts = mono_gc_debug_get();
35493521
if (debug_opts) {
35503522
gboolean usage_printed = FALSE;
35513523

0 commit comments

Comments
 (0)