Skip to content

Commit fa71f6b

Browse files
authored
flambda-backend: Increase local stack limit (#1513)
* increase local stack limit * commented out test
1 parent c1eecf6 commit fa71f6b

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

runtime/caml/gc.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,16 @@
6868

6969

7070
#define Init_local_arena_bsize 4096
71-
#ifdef ARCH_SIXTYFOUR
72-
#define Max_local_arenas 10 /* max 4G */
73-
#else
74-
#define Max_local_arenas 8 /* max 1G */
75-
#endif
71+
72+
/* We allow the local stack to quadruple 19 times, which is virtually infinite.
73+
Hardware limit will probably hit first (either out of address space on 32bit
74+
systems, or out of physical memory on 64bit)
75+
76+
19 is the biggest number without triggering some compiler errors about
77+
integer overflow during shifting; I don't know if overflow would actually
78+
happen if I make the number bigger, but 19 corresponds to 1024TB and should
79+
be sufficient for a very long time. */
80+
#define Max_local_arenas 19
7681

7782
struct caml_local_arena {
7883
char* base;

testsuite/tests/typing-local/alloc.ml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ external bytes_create :
295295
int -> local_ bytes = "caml_create_local_bytes"
296296
external bytes_set :
297297
local_ bytes -> int -> char -> unit = "%bytes_unsafe_set"
298+
external bytes_get :
299+
local_ bytes -> int -> char = "%bytes_unsafe_get"
298300
external bytes_fill :
299301
local_ bytes -> int -> int -> char -> unit = "caml_fill_bytes"
300302
external bytes_blit_string :
@@ -419,6 +421,14 @@ let[@inline never] optionaleta () =
419421
use_clos (Sys.opaque_identity optarg);
420422
()
421423

424+
(* Test big local stack. The following will allocate 5G bytes on the local stack
425+
, which is higher than the original 4G limit. *)
426+
let[@inline never] huge () =
427+
let b = bytes_create (Int.shift_left 5 30) in
428+
let pos = Int.shift_left 4 30 in
429+
bytes_set b pos 'h';
430+
assert (bytes_get b pos = 'h')
431+
422432
let run name f x =
423433
let prebefore = Gc.allocated_bytes () in
424434
let before = Gc.allocated_bytes () in
@@ -473,6 +483,10 @@ let () =
473483
run "optionalarg" optionalarg (fun_with_optional_arg, 10);
474484
run "optionaleta" optionaleta ()
475485

486+
(* The following test commented out as it require more memory than the CI has
487+
*)
488+
(* run "huge" huge () *)
489+
476490
(* In debug mode, Gc.minor () checks for minor heap->local pointers (and
477491
backwards local pointers, which can't occur here) *)
478492
let () = Gc.minor ()

0 commit comments

Comments
 (0)