Move mono_runtime_set_shutting_down and mono_runtime_is_shutting_down to runtime.c
[mono.git] / mono / metadata / sgen-memory-governor.c
index 445328c193e0a0696c2324d901905b2fd25c5482..7dc35fdbe3e88d61c372dd6aa97612c931b72960 100644 (file)
@@ -156,7 +156,10 @@ sgen_memgov_try_calculate_minor_collection_allowance (gboolean overwrite)
 gboolean
 sgen_need_major_collection (mword space_needed)
 {
-       mword los_alloced = los_memory_usage - MIN (last_collection_los_memory_usage, los_memory_usage);
+       mword los_alloced;
+       if (sgen_concurrent_collection_in_progress ())
+               return FALSE;
+       los_alloced = los_memory_usage - MIN (last_collection_los_memory_usage, los_memory_usage);
        return (space_needed > sgen_memgov_available_free_space ()) ||
                minor_collection_sections_alloced * major_collector.section_size + los_alloced > minor_collection_allowance;
 }
@@ -283,11 +286,11 @@ prot_flags_for_activate (int activate)
 }
 
 void
-sgen_assert_memory_alloc (void *ptr, const char *assert_description)
+sgen_assert_memory_alloc (void *ptr, size_t requested_size, const char *assert_description)
 {
        if (ptr || !assert_description)
                return;
-       fprintf (stderr, "Error: Garbage collector could not allocate memory for %s.\n", assert_description);
+       fprintf (stderr, "Error: Garbage collector could not allocate %zu bytes of memory for %s.\n", requested_size, assert_description);
        exit (1);
 }
 
@@ -303,7 +306,7 @@ sgen_alloc_os_memory (size_t size, SgenAllocFlags flags, const char *assert_desc
        g_assert (!(flags & ~(SGEN_ALLOC_HEAP | SGEN_ALLOC_ACTIVATE)));
 
        ptr = mono_valloc (0, size, prot_flags_for_activate (flags & SGEN_ALLOC_ACTIVATE));
-       sgen_assert_memory_alloc (ptr, assert_description);
+       sgen_assert_memory_alloc (ptr, size, assert_description);
        if (ptr) {
                SGEN_ATOMIC_ADD_P (total_alloc, size);
                if (flags & SGEN_ALLOC_HEAP)
@@ -321,7 +324,7 @@ sgen_alloc_os_memory_aligned (size_t size, mword alignment, SgenAllocFlags flags
        g_assert (!(flags & ~(SGEN_ALLOC_HEAP | SGEN_ALLOC_ACTIVATE)));
 
        ptr = mono_valloc_aligned (size, alignment, prot_flags_for_activate (flags & SGEN_ALLOC_ACTIVATE));
-       sgen_assert_memory_alloc (ptr, assert_description);
+       sgen_assert_memory_alloc (ptr, size, assert_description);
        if (ptr) {
                SGEN_ATOMIC_ADD_P (total_alloc, size);
                if (flags & SGEN_ALLOC_HEAP)
@@ -392,13 +395,13 @@ sgen_memgov_init (glong max_heap, glong soft_limit, gboolean debug_allowance, do
                return;
 
        if (max_heap < soft_limit) {
-               fprintf (stderr, "max-heap-size must be at least as large as soft-heap-limit.\n");
-               exit (1);
+               sgen_env_var_error (MONO_GC_PARAMS_NAME, "Setting to minimum.", "`max-heap-size` must be at least as large as `soft-heap-limit`.");
+               max_heap = soft_limit;
        }
 
        if (max_heap < sgen_nursery_size * 4) {
-               fprintf (stderr, "max-heap-size must be at least 4 times larger than nursery size.\n");
-               exit (1);
+               sgen_env_var_error (MONO_GC_PARAMS_NAME, "Setting to minimum.", "`max-heap-size` must be at least 4 times as large as `nursery size`.");
+               max_heap = sgen_nursery_size * 4;
        }
        max_heap_size = max_heap - sgen_nursery_size;