summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2023-04-25 08:37:05 +0300
committerIvan Maidanski <ivmai@mail.ru>2023-04-27 14:33:44 +0300
commit2dff48cb381746ab520dc205bd5cf03edcb6a74a (patch)
treefe81d61838542d9c44ff2bea22b21c473eb8bb4a
parent41d40dcfdaf766b39d29297a3190e9721638c95f (diff)
downloadbdwgc-2dff48cb381746ab520dc205bd5cf03edcb6a74a.tar.gz
Fix infinite loop in disable_gc_for_dlopen and GC_wait_for_gc_completion
(a cherry-pick of commit 2e5646ba3 from 'master') Issue #257 (bdwgc). * alloc.c (GC_start_incremental_collection, GC_collect_a_little): Do not call GC_collect_a_little_inner() and ENTER/EXIT_GC() if GC_dont_gc. * alloc.c (GC_collect_a_little_inner): Call GC_mark_some() (in a loop) even if GC_dont_gc. * alloc.c (GC_allocobj): Do not call GC_collect_a_little_inner() if GC_dont_gc. * tests/test.c (check_heap_stats): Do not call GC_collect_a_little() (repeatedly) if GC_is_disabled().
-rw-r--r--alloc.c27
-rw-r--r--tests/test.c3
2 files changed, 17 insertions, 13 deletions
diff --git a/alloc.c b/alloc.c
index 0a4435b4..a2505ad5 100644
--- a/alloc.c
+++ b/alloc.c
@@ -417,9 +417,11 @@ GC_API void GC_CALL GC_start_incremental_collection(void)
if (!GC_incremental) return;
LOCK();
GC_should_start_incremental_collection = TRUE;
- ENTER_GC();
- GC_collect_a_little_inner(1);
- EXIT_GC();
+ if (!GC_dont_gc) {
+ ENTER_GC();
+ GC_collect_a_little_inner(1);
+ EXIT_GC();
+ }
UNLOCK();
# endif
}
@@ -715,8 +717,6 @@ GC_INNER void GC_collect_a_little_inner(int n)
IF_CANCEL(int cancel_state;)
GC_ASSERT(I_HOLD_LOCK());
- if (GC_dont_gc) return;
-
DISABLE_CANCEL(cancel_state);
if (GC_incremental && GC_collection_in_progress()) {
int i;
@@ -734,7 +734,7 @@ GC_INNER void GC_collect_a_little_inner(int n)
GC_parallel_mark_disabled = FALSE;
# endif
- if (i < max_deficit) {
+ if (i < max_deficit && !GC_dont_gc) {
/* Need to finish a collection. */
# ifdef SAVE_CALL_CHAIN
GC_save_callers(GC_last_stack);
@@ -765,7 +765,7 @@ GC_INNER void GC_collect_a_little_inner(int n)
if (GC_deficit < 0)
GC_deficit = 0;
}
- } else {
+ } else if (!GC_dont_gc) {
GC_maybe_gc();
}
RESTORE_CANCEL(cancel_state);
@@ -780,9 +780,11 @@ GC_API int GC_CALL GC_collect_a_little(void)
DCL_LOCK_STATE;
LOCK();
- ENTER_GC();
- GC_collect_a_little_inner(1);
- EXIT_GC();
+ if (!GC_dont_gc) {
+ ENTER_GC();
+ GC_collect_a_little_inner(1);
+ EXIT_GC();
+ }
result = (int)GC_collection_in_progress();
UNLOCK();
if (!result && GC_debugging_started) GC_print_all_smashed();
@@ -1759,7 +1761,8 @@ GC_INNER ptr_t GC_allocobj(size_t gran, int kind)
while (*flh == 0) {
ENTER_GC();
# ifndef GC_DISABLE_INCREMENTAL
- if (GC_incremental && GC_time_limit != GC_TIME_UNLIMITED) {
+ if (GC_incremental && GC_time_limit != GC_TIME_UNLIMITED
+ && !GC_dont_gc) {
/* True incremental mode, not just generational. */
/* Do our share of marking work. */
GC_collect_a_little_inner(1);
@@ -1782,7 +1785,7 @@ GC_INNER ptr_t GC_allocobj(size_t gran, int kind)
if (NULL == *flh) {
ENTER_GC();
if (GC_incremental && GC_time_limit == GC_TIME_UNLIMITED
- && !tried_minor) {
+ && !tried_minor && !GC_dont_gc) {
GC_collect_a_little_inner(1);
tried_minor = TRUE;
} else {
diff --git a/tests/test.c b/tests/test.c
index c14866e3..e3b91808 100644
--- a/tests/test.c
+++ b/tests/test.c
@@ -1753,7 +1753,8 @@ void check_heap_stats(void)
# endif
/* Garbage collect repeatedly so that all inaccessible objects */
/* can be finalized. */
- while (GC_collect_a_little()) { }
+ if (!GC_is_disabled())
+ while (GC_collect_a_little()) { }
for (i = 0; i < 16; i++) {
GC_gcollect();
# ifndef GC_NO_FINALIZATION