From 872c489a7dd7c8965d8e53be501f549ac3e60b8d Mon Sep 17 00:00:00 2001 From: Mark Shinwell Date: Fri, 8 Dec 2023 14:10:27 +0000 Subject: [PATCH 1/3] Fix caml_gc_compaction to run finalizers --- ocaml/runtime/gc_ctrl.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ocaml/runtime/gc_ctrl.c b/ocaml/runtime/gc_ctrl.c index 82ba6c93019..5ea0144ea58 100644 --- a/ocaml/runtime/gc_ctrl.c +++ b/ocaml/runtime/gc_ctrl.c @@ -299,8 +299,7 @@ CAMLprim value caml_gc_compaction(value v) Caml_check_caml_state(); CAML_EV_BEGIN(EV_EXPLICIT_GC_COMPACT); CAMLassert (v == Val_unit); - value exn = gc_major_exn(1); - ++ Caml_state->stat_forced_major_collections; + value exn = gc_full_major_exn(); CAML_EV_END(EV_EXPLICIT_GC_COMPACT); return caml_raise_async_if_exception(exn, ""); } From 5758db4d91ef855af598539ec8ba5cbc649d1e40 Mon Sep 17 00:00:00 2001 From: Mark Shinwell Date: Mon, 11 Dec 2023 09:57:09 +0000 Subject: [PATCH 2/3] force_compaction --- ocaml/runtime/gc_ctrl.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ocaml/runtime/gc_ctrl.c b/ocaml/runtime/gc_ctrl.c index 5ea0144ea58..1bf00d762cc 100644 --- a/ocaml/runtime/gc_ctrl.c +++ b/ocaml/runtime/gc_ctrl.c @@ -258,7 +258,7 @@ CAMLprim value caml_gc_major(value v) return caml_raise_async_if_exception(gc_major_exn (0), ""); } -static value gc_full_major_exn(void) +static value gc_full_major_exn(int force_compaction) { int i; value exn = Val_unit; @@ -268,7 +268,7 @@ static value gc_full_major_exn(void) currently-unreachable object to be collected. */ for (i = 0; i < 3; i++) { caml_empty_minor_heaps_once(); - caml_finish_major_cycle(0); + caml_finish_major_cycle(force_compaction); exn = caml_process_pending_actions_exn(); if (Is_exception_result(exn)) break; } @@ -281,7 +281,7 @@ CAMLprim value caml_gc_full_major(value v) { Caml_check_caml_state(); CAMLassert (v == Val_unit); - return caml_raise_async_if_exception(gc_full_major_exn (), ""); + return caml_raise_async_if_exception(gc_full_major_exn (0), ""); } CAMLprim value caml_gc_major_slice (value v) @@ -299,7 +299,7 @@ CAMLprim value caml_gc_compaction(value v) Caml_check_caml_state(); CAML_EV_BEGIN(EV_EXPLICIT_GC_COMPACT); CAMLassert (v == Val_unit); - value exn = gc_full_major_exn(); + value exn = gc_full_major_exn(1); CAML_EV_END(EV_EXPLICIT_GC_COMPACT); return caml_raise_async_if_exception(exn, ""); } @@ -308,7 +308,7 @@ CAMLprim value caml_gc_stat(value v) { value res; CAML_EV_BEGIN(EV_EXPLICIT_GC_STAT); - res = gc_full_major_exn(); + res = gc_full_major_exn(0); if (Is_exception_result(res)) goto out; res = caml_gc_quick_stat(Val_unit); out: From 9e8e9aab553dde897d2f03ead9d6c37c8325d8bc Mon Sep 17 00:00:00 2001 From: Mark Shinwell Date: Tue, 12 Dec 2023 13:56:52 +0000 Subject: [PATCH 3/3] Only compact on the third major cycle --- ocaml/runtime/gc_ctrl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ocaml/runtime/gc_ctrl.c b/ocaml/runtime/gc_ctrl.c index 1bf00d762cc..8829e984b48 100644 --- a/ocaml/runtime/gc_ctrl.c +++ b/ocaml/runtime/gc_ctrl.c @@ -268,7 +268,7 @@ static value gc_full_major_exn(int force_compaction) currently-unreachable object to be collected. */ for (i = 0; i < 3; i++) { caml_empty_minor_heaps_once(); - caml_finish_major_cycle(force_compaction); + caml_finish_major_cycle(force_compaction && i == 2); exn = caml_process_pending_actions_exn(); if (Is_exception_result(exn)) break; }