Skip to content

Commit f541292

Browse files
committed
Fix Gc.minor_{words,free} by removing [@@noalloc]
1 parent 0df693e commit f541292

File tree

5 files changed

+32
-4
lines changed

5 files changed

+32
-4
lines changed

Changes

+3
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,9 @@ Next major version (4.05.0):
511511
- GPR#1075: Ensure that zero-sized float arrays have zero tags.
512512
(Mark Shinwell, Leo White)
513513

514+
* GPR#1088: Gc.minor_words now returns accurate numbers.
515+
(Stephen Dolan)
516+
514517
Next minor version (4.04.1):
515518
----------------------------
516519

stdlib/gc.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ external stat : unit -> stat = "caml_gc_stat"
4747
external quick_stat : unit -> stat = "caml_gc_quick_stat"
4848
external counters : unit -> (float * float * float) = "caml_gc_counters"
4949
external minor_words : unit -> (float [@unboxed])
50-
= "caml_gc_minor_words" "caml_gc_minor_words_unboxed" [@@noalloc]
50+
= "caml_gc_minor_words" "caml_gc_minor_words_unboxed"
5151
external get : unit -> control = "caml_gc_get"
5252
external set : control -> unit = "caml_gc_set"
5353
external minor : unit -> unit = "caml_gc_minor"
5454
external major_slice : int -> int = "caml_gc_major_slice"
5555
external major : unit -> unit = "caml_gc_major"
5656
external full_major : unit -> unit = "caml_gc_full_major"
5757
external compact : unit -> unit = "caml_gc_compaction"
58-
external get_minor_free : unit -> int = "caml_get_minor_free" [@@noalloc]
58+
external get_minor_free : unit -> int = "caml_get_minor_free"
5959
external get_bucket : int -> int = "caml_get_major_bucket" [@@noalloc]
6060
external get_credit : unit -> int = "caml_get_major_credit" [@@noalloc]
6161
external huge_fallback_count : unit -> int = "caml_gc_huge_fallback_count"

stdlib/gc.mli

+2-2
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ external counters : unit -> float * float * float = "caml_gc_counters"
171171
is as fast as [quick_stat]. *)
172172

173173
external minor_words : unit -> (float [@unboxed])
174-
= "caml_gc_minor_words" "caml_gc_minor_words_unboxed" [@@noalloc]
174+
= "caml_gc_minor_words" "caml_gc_minor_words_unboxed"
175175
(** Number of words allocated in the minor heap since the program was
176176
started. This number is accurate in byte-code programs, but only an
177177
approximation in programs compiled to native code.
@@ -219,7 +219,7 @@ val allocated_bytes : unit -> float
219219
started. It is returned as a [float] to avoid overflow problems
220220
with [int] on 32-bit machines. *)
221221

222-
external get_minor_free : unit -> int = "caml_get_minor_free" [@@noalloc]
222+
external get_minor_free : unit -> int = "caml_get_minor_free"
223223
(** Return the current size of the free space inside the minor heap.
224224
225225
@since 4.03.0 *)

testsuite/tests/misc/gcwords.ml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
type t = Leaf of int | Branch of t * t
2+
3+
let a = [| 0.0 |]
4+
5+
let rec allocate_lots m = function
6+
| 0 -> Leaf m
7+
| n -> Branch (allocate_lots m (n-1), allocate_lots (m+1) (n-1))
8+
9+
let measure f =
10+
let a = Gc.minor_words () in
11+
f ();
12+
let c = Gc.minor_words () in
13+
c -. a
14+
15+
let () =
16+
let n = measure (fun () -> a.(0) <- Gc.minor_words ()) in
17+
(* Gc.minor_words should not allocate, although bytecode
18+
generally boxes the floats *)
19+
assert (n < 10.);
20+
if Sys.backend_type = Sys.Native then assert (n = 0.);
21+
let n = measure (fun () -> Sys.opaque_identity (allocate_lots 42 10)) in
22+
(* This should allocate > 3k words (varying slightly by unboxing) *)
23+
assert (n > 3000.);
24+
print_endline "ok"
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ok

0 commit comments

Comments
 (0)