@@ -7151,7 +7151,6 @@ void gc_mechanisms::init_mechanisms()
71517151 found_finalizers = FALSE;
71527152#ifdef BACKGROUND_GC
71537153 background_p = gc_heap::background_running_p() != FALSE;
7154- allocations_allowed = TRUE;
71557154#endif //BACKGROUND_GC
71567155
71577156 entry_memory_load = 0;
@@ -7444,15 +7443,6 @@ void gc_heap::reset_allocation_pointers (generation* gen, uint8_t* start)
74447443
74457444bool gc_heap::new_allocation_allowed (int gen_number)
74467445{
7447- #ifdef BACKGROUND_GC
7448- //TODO BACKGROUND_GC this is for test only
7449- if (!settings.allocations_allowed)
7450- {
7451- dprintf (2, ("new allocation not allowed"));
7452- return FALSE;
7453- }
7454- #endif //BACKGROUND_GC
7455-
74567446 if (dd_new_allocation (dynamic_data_of (gen_number)) < 0)
74577447 {
74587448 if (gen_number != 0)
@@ -16084,18 +16074,22 @@ void gc_heap::wait_for_background (alloc_wait_reason awr, bool loh_p)
1608416074 add_saved_spinlock_info (loh_p, me_acquire, mt_wait_bgc);
1608516075}
1608616076
16087- void gc_heap::wait_for_bgc_high_memory (alloc_wait_reason awr, bool loh_p)
16077+ bool gc_heap::wait_for_bgc_high_memory (alloc_wait_reason awr, bool loh_p)
1608816078{
16079+ bool wait_p = false;
1608916080 if (gc_heap::background_running_p())
1609016081 {
1609116082 uint32_t memory_load;
1609216083 get_memory_info (&memory_load);
1609316084 if (memory_load >= m_high_memory_load_th)
1609416085 {
16086+ wait_p = true;
1609516087 dprintf (GTC_LOG, ("high mem - wait for BGC to finish, wait reason: %d", awr));
1609616088 wait_for_background (awr, loh_p);
1609716089 }
1609816090 }
16091+
16092+ return wait_p;
1609916093}
1610016094
1610116095#endif //BACKGROUND_GC
@@ -17203,18 +17197,27 @@ allocation_state gc_heap::try_allocate_more_space (alloc_context* acontext, size
1720317197 }
1720417198
1720517199#ifdef BACKGROUND_GC
17206- wait_for_bgc_high_memory (awr_gen0_alloc, loh_p);
17200+ bool recheck_p = wait_for_bgc_high_memory (awr_gen0_alloc, loh_p);
1720717201#endif //BACKGROUND_GC
1720817202
1720917203#ifdef SYNCHRONIZATION_STATS
1721017204 bad_suspension++;
1721117205#endif //SYNCHRONIZATION_STATS
1721217206 dprintf (2, ("h%d running out of budget on gen%d, gc", heap_number, gen_number));
1721317207
17214- if (!settings.concurrent || (gen_number == 0))
17208+ #ifdef BACKGROUND_GC
17209+ bool trigger_gc_p = true;
17210+ if (recheck_p)
17211+ trigger_gc_p = !(new_allocation_allowed (gen_number));
17212+
17213+ if (trigger_gc_p)
17214+ #endif //BACKGROUND_GC
1721517215 {
17216- trigger_gc_for_alloc (0, ((gen_number == 0) ? reason_alloc_soh : reason_alloc_loh),
17217- msl, loh_p, mt_try_budget);
17216+ if (!settings.concurrent || (gen_number == 0))
17217+ {
17218+ trigger_gc_for_alloc (0, ((gen_number == 0) ? reason_alloc_soh : reason_alloc_loh),
17219+ msl, loh_p, mt_try_budget);
17220+ }
1721817221 }
1721917222 }
1722017223 }
0 commit comments