Skip to content

Commit 3f56446

Browse files
committed
Config controlled logging
1 parent eb5cadd commit 3f56446

File tree

3 files changed

+48
-4
lines changed

3 files changed

+48
-4
lines changed

src/mono/mono/metadata/sgen-mono.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2730,6 +2730,8 @@ mono_gc_init_icalls (void)
27302730
mono_register_jit_icall (mono_profiler_raise_gc_allocation, mono_icall_sig_void_object, FALSE);
27312731
}
27322732

2733+
gboolean andrew_logging = FALSE;
2734+
27332735
gboolean
27342736
sgen_client_handle_gc_param (const char *opt)
27352737
{
@@ -2749,9 +2751,12 @@ sgen_client_handle_gc_param (const char *opt)
27492751
} else if (g_str_has_prefix (opt, "toggleref-test")) {
27502752
/* FIXME: This should probably in MONO_GC_DEBUG */
27512753
sgen_register_test_toggleref_callback ();
2754+
} else if (g_str_has_prefix (opt, "andrew-logging")) {
2755+
/* FIXME: To be removed */
2756+
andrew_logging = TRUE;
27522757
} else if (!sgen_bridge_handle_gc_param (opt)) {
27532758
return FALSE;
2754-
}
2759+
}
27552760
return TRUE;
27562761
}
27572762

src/mono/mono/sgen/sgen-gc.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2240,9 +2240,12 @@ major_copy_or_mark_from_roots (SgenGrayQueue *gc_thread_gray_queue, size_t *old_
22402240
}
22412241
}
22422242

2243+
extern gboolean andrew_logging;
2244+
22432245
static void
22442246
major_start_collection (SgenGrayQueue *gc_thread_gray_queue, const char *reason, gboolean concurrent, size_t *old_next_pin_slot)
22452247
{
2248+
if (andrew_logging) { fprintf(stdout, "The reason is %s\n", reason); fflush(stdout); }
22462249
SgenObjectOperations *object_ops_nopar, *object_ops_par = NULL;
22472250

22482251
#ifndef DISABLE_SGEN_MAJOR_MARKSWEEP_CONC
@@ -2572,6 +2575,7 @@ major_finish_concurrent_collection (gboolean forced)
25722575
sgen_current_collection_generation = -1;
25732576
}
25742577

2578+
25752579
/*
25762580
* Ensure an allocation request for @size will succeed by freeing enough memory.
25772581
*
@@ -2589,12 +2593,18 @@ sgen_ensure_free_space (size_t size, int generation)
25892593
reason = "LOS overflow";
25902594
generation_to_collect = GENERATION_OLD;
25912595
}
2596+
else
2597+
{
2598+
}
25922599
} else {
25932600
if (sgen_degraded_mode) {
25942601
if (sgen_need_major_collection (size, &forced)) {
25952602
reason = "Degraded mode overflow";
25962603
generation_to_collect = GENERATION_OLD;
25972604
}
2605+
else
2606+
{
2607+
}
25982608
} else if (sgen_need_major_collection (size, &forced)) {
25992609
reason = sgen_concurrent_collection_in_progress ? "Forced finish concurrent collection" : "Minor allowance";
26002610
generation_to_collect = GENERATION_OLD;
@@ -2603,12 +2613,14 @@ sgen_ensure_free_space (size_t size, int generation)
26032613
reason = "Nursery full";
26042614
}
26052615
}
2606-
26072616
if (generation_to_collect == -1) {
26082617
if (sgen_concurrent_collection_in_progress && sgen_workers_all_done ()) {
26092618
generation_to_collect = GENERATION_OLD;
26102619
reason = "Finish concurrent collection";
26112620
}
2621+
else
2622+
{
2623+
}
26122624
}
26132625

26142626
if (generation_to_collect == -1)

src/mono/mono/sgen/sgen-memory-governor.c

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ sgen_memgov_calculate_minor_collection_allowance (void)
130130
}
131131
}
132132

133+
extern gboolean andrew_logging;
134+
133135
// This can be called while sweep is running to determine earlier if there is so much memory growth
134136
// that we know we will require a GC once sweep finishes.
135137
static gboolean
@@ -141,7 +143,15 @@ sgen_need_major_collection_conservative (void)
141143
size_t max_allowance = GDOUBLE_TO_SIZE (max_last_collection_heap_size * SGEN_DEFAULT_ALLOWANCE_HEAP_SIZE_RATIO);
142144
max_allowance = MAX (max_allowance, GDOUBLE_TO_SIZE (MIN_MINOR_COLLECTION_ALLOWANCE));
143145

144-
return min_heap_size > max_allowance;
146+
if (min_heap_size > max_allowance)
147+
{
148+
if (andrew_logging) { fprintf(stdout, "sgen_need_major_collection_conservative %lld > %lld\n", (long long int)min_heap_size, (long long int)max_allowance); fflush(stdout); }
149+
return TRUE;
150+
}
151+
else
152+
{
153+
return FALSE;
154+
}
145155
}
146156

147157
static size_t
@@ -194,25 +204,42 @@ sgen_need_major_collection (mword space_needed, gboolean *forced)
194204
* we force the finishing of the collection, to avoid increased memory usage.
195205
*/
196206
if ((heap_size - major_start_heap_size) > major_start_heap_size * SGEN_DEFAULT_ALLOWANCE_HEAP_SIZE_RATIO)
207+
{
208+
if (andrew_logging) { fprintf(stdout, "Case 1\n"); fflush(stdout); }
197209
return TRUE;
210+
}
198211
return FALSE;
199212
}
200213

201214
if (!sgen_major_collector.have_swept ()) {
202215
if (sgen_need_major_collection_conservative ())
216+
{
217+
if (andrew_logging) { fprintf(stdout, "Case 2\n"); fflush(stdout); }
203218
return TRUE;
219+
}
204220
return FALSE;
205221
}
206222

207223
if (space_needed > sgen_memgov_available_free_space ())
224+
{
225+
if (andrew_logging) { fprintf(stdout, "Case 3\n"); fflush(stdout); }
208226
return TRUE;
227+
}
209228

210229
sgen_memgov_calculate_minor_collection_allowance ();
211230

212231
heap_size = get_heap_size ();
213232

214233
*forced = heap_size > soft_heap_limit;
215-
return heap_size > major_collection_trigger_size;
234+
if (heap_size > major_collection_trigger_size)
235+
{
236+
if (andrew_logging) { fprintf(stdout, "The heap_size is %lld, the major_collection_trigger_size is %lld\n", (long long int)heap_size, (long long int)major_collection_trigger_size); fflush(stdout); }
237+
return TRUE;
238+
}
239+
else
240+
{
241+
return FALSE;
242+
}
216243
}
217244

218245
void

0 commit comments

Comments
 (0)