Skip to content

Commit 2418ffb

Browse files
authored
add in_minor_collection and port #1743 (Add some checks that the minor GC does not recurse) (#2075)
1 parent c31e025 commit 2418ffb

File tree

5 files changed

+11
-0
lines changed

5 files changed

+11
-0
lines changed

ocaml/otherlibs/systhreads/st_stubs.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ static void caml_thread_scan_roots(
188188

189189
static void save_runtime_state(void)
190190
{
191+
if (Caml_state->in_minor_collection)
192+
caml_fatal_error("Thread switch from inside minor GC");
191193
CAMLassert(This_thread != NULL);
192194
caml_thread_t this_thread = This_thread;
193195
this_thread->current_stack = Caml_state->current_stack;

ocaml/runtime/caml/domain_state.tbl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ DOMAIN_STATE(int, parser_trace)
109109

110110
DOMAIN_STATE(asize_t, minor_heap_wsz)
111111

112+
DOMAIN_STATE(intnat, in_minor_collection)
113+
112114
DOMAIN_STATE(struct caml_heap_state*, shared_heap)
113115

114116
DOMAIN_STATE(int, id)

ocaml/runtime/caml/minor_gc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#define caml_young_alloc_start Caml_state->young_start
2828
#define caml_young_alloc_end Caml_state->young_end
2929
#define caml_minor_heap_wsz Caml_state->minor_heap_wsz
30+
#define caml_in_minor_collection Caml_state->in_minor_collection
3031

3132

3233
#define CAML_TABLE_STRUCT(t) { \

ocaml/runtime/domain.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,8 @@ static void domain_create(uintnat initial_minor_heap_wsize) {
629629
goto reallocate_minor_heap_failure;
630630
}
631631

632+
domain_state->in_minor_collection = 0;
633+
632634
domain_state->dls_root = Val_unit;
633635
caml_register_generational_global_root(&domain_state->dls_root);
634636

ocaml/runtime/minor_gc.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,9 @@ void caml_empty_minor_heap_promote(caml_domain_state* domain,
493493
caml_gc_log ("Minor collection of domain %d starting", domain->id);
494494
CAML_EV_BEGIN(EV_MINOR);
495495
call_timing_hook(&caml_minor_gc_begin_hook);
496+
if (Caml_state->in_minor_collection)
497+
caml_fatal_error("Minor GC triggered recursively");
498+
Caml_state->in_minor_collection = 1;
496499

497500
if( participating[0] == Caml_state ) {
498501
CAML_EV_BEGIN(EV_MINOR_GLOBAL_ROOTS);
@@ -639,6 +642,7 @@ void caml_empty_minor_heap_promote(caml_domain_state* domain,
639642
domain->stat_minor_words += Wsize_bsize (minor_allocated_bytes);
640643
domain->stat_promoted_words += domain->allocated_words - prev_alloc_words;
641644

645+
Caml_state->in_minor_collection = 0;
642646
call_timing_hook(&caml_minor_gc_end_hook);
643647
CAML_EV_COUNTER(EV_C_MINOR_PROMOTED,
644648
Bsize_wsize(domain->allocated_words - prev_alloc_words));

0 commit comments

Comments
 (0)