Skip to content

Commit

Permalink
Config controlled logging
Browse files Browse the repository at this point in the history
  • Loading branch information
cshung committed Mar 27, 2024
1 parent eb5cadd commit 3f56446
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/mono/mono/metadata/sgen-mono.c
Original file line number Diff line number Diff line change
Expand Up @@ -2730,6 +2730,8 @@ mono_gc_init_icalls (void)
mono_register_jit_icall (mono_profiler_raise_gc_allocation, mono_icall_sig_void_object, FALSE);
}

gboolean andrew_logging = FALSE;

gboolean
sgen_client_handle_gc_param (const char *opt)
{
Expand All @@ -2749,9 +2751,12 @@ sgen_client_handle_gc_param (const char *opt)
} else if (g_str_has_prefix (opt, "toggleref-test")) {
/* FIXME: This should probably in MONO_GC_DEBUG */
sgen_register_test_toggleref_callback ();
} else if (g_str_has_prefix (opt, "andrew-logging")) {
/* FIXME: To be removed */
andrew_logging = TRUE;
} else if (!sgen_bridge_handle_gc_param (opt)) {
return FALSE;
}
}
return TRUE;
}

Expand Down
14 changes: 13 additions & 1 deletion src/mono/mono/sgen/sgen-gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2240,9 +2240,12 @@ major_copy_or_mark_from_roots (SgenGrayQueue *gc_thread_gray_queue, size_t *old_
}
}

extern gboolean andrew_logging;

static void
major_start_collection (SgenGrayQueue *gc_thread_gray_queue, const char *reason, gboolean concurrent, size_t *old_next_pin_slot)
{
if (andrew_logging) { fprintf(stdout, "The reason is %s\n", reason); fflush(stdout); }
SgenObjectOperations *object_ops_nopar, *object_ops_par = NULL;

#ifndef DISABLE_SGEN_MAJOR_MARKSWEEP_CONC
Expand Down Expand Up @@ -2572,6 +2575,7 @@ major_finish_concurrent_collection (gboolean forced)
sgen_current_collection_generation = -1;
}


/*
* Ensure an allocation request for @size will succeed by freeing enough memory.
*
Expand All @@ -2589,12 +2593,18 @@ sgen_ensure_free_space (size_t size, int generation)
reason = "LOS overflow";
generation_to_collect = GENERATION_OLD;
}
else
{
}
} else {
if (sgen_degraded_mode) {
if (sgen_need_major_collection (size, &forced)) {
reason = "Degraded mode overflow";
generation_to_collect = GENERATION_OLD;
}
else
{
}
} else if (sgen_need_major_collection (size, &forced)) {
reason = sgen_concurrent_collection_in_progress ? "Forced finish concurrent collection" : "Minor allowance";
generation_to_collect = GENERATION_OLD;
Expand All @@ -2603,12 +2613,14 @@ sgen_ensure_free_space (size_t size, int generation)
reason = "Nursery full";
}
}

if (generation_to_collect == -1) {
if (sgen_concurrent_collection_in_progress && sgen_workers_all_done ()) {
generation_to_collect = GENERATION_OLD;
reason = "Finish concurrent collection";
}
else
{
}
}

if (generation_to_collect == -1)
Expand Down
31 changes: 29 additions & 2 deletions src/mono/mono/sgen/sgen-memory-governor.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ sgen_memgov_calculate_minor_collection_allowance (void)
}
}

extern gboolean andrew_logging;

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

return min_heap_size > max_allowance;
if (min_heap_size > max_allowance)
{
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); }
return TRUE;
}
else
{
return FALSE;
}
}

static size_t
Expand Down Expand Up @@ -194,25 +204,42 @@ sgen_need_major_collection (mword space_needed, gboolean *forced)
* we force the finishing of the collection, to avoid increased memory usage.
*/
if ((heap_size - major_start_heap_size) > major_start_heap_size * SGEN_DEFAULT_ALLOWANCE_HEAP_SIZE_RATIO)
{
if (andrew_logging) { fprintf(stdout, "Case 1\n"); fflush(stdout); }
return TRUE;
}
return FALSE;
}

if (!sgen_major_collector.have_swept ()) {
if (sgen_need_major_collection_conservative ())
{
if (andrew_logging) { fprintf(stdout, "Case 2\n"); fflush(stdout); }
return TRUE;
}
return FALSE;
}

if (space_needed > sgen_memgov_available_free_space ())
{
if (andrew_logging) { fprintf(stdout, "Case 3\n"); fflush(stdout); }
return TRUE;
}

sgen_memgov_calculate_minor_collection_allowance ();

heap_size = get_heap_size ();

*forced = heap_size > soft_heap_limit;
return heap_size > major_collection_trigger_size;
if (heap_size > major_collection_trigger_size)
{
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); }
return TRUE;
}
else
{
return FALSE;
}
}

void
Expand Down

0 comments on commit 3f56446

Please sign in to comment.