diff options
author | Damien Doligez <damien.doligez-inria.fr> | 2015-07-20 14:46:48 +0000 |
---|---|---|
committer | Damien Doligez <damien.doligez-inria.fr> | 2015-07-20 14:46:48 +0000 |
commit | 7ad5340bfef48eacfd80d770f7054d314f092f40 (patch) | |
tree | 8cedefb57dcd3e16e32cf2cd21c7113600d5b29b | |
parent | 1f248748cecc8e079d0e4f858ac85e2bd52f1eb1 (diff) | |
download | ocaml-7ad5340bfef48eacfd80d770f7054d314f092f40.tar.gz |
move GC hooks to a safe place for callbacks
git-svn-id: http://caml.inria.fr/svn/ocaml/version/4.02@16224 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
-rw-r--r-- | VERSION | 2 | ||||
-rw-r--r-- | byterun/caml/misc.h | 6 | ||||
-rw-r--r-- | byterun/finalise.c | 2 | ||||
-rw-r--r-- | byterun/major_gc.c | 7 | ||||
-rw-r--r-- | byterun/minor_gc.c | 2 |
5 files changed, 10 insertions, 9 deletions
@@ -1,4 +1,4 @@ -4.02.3+dev3-2015-07-20 +4.02.3+dev4-2015-07-20 # The version string is the first line of this file. # It must be in the format described in stdlib/sys.mli diff --git a/byterun/caml/misc.h b/byterun/caml/misc.h index db0971d2bb..9319635f60 100644 --- a/byterun/caml/misc.h +++ b/byterun/caml/misc.h @@ -63,8 +63,10 @@ typedef char * addr; extern "C" { #endif -/* GC timing hooks. These can be assigned by the user. The hook functions - must not allocate or change the heap in any way. */ +/* GC timing hooks. These can be assigned by the user. + [caml_minor_gc_begin_hook] must not allocate nor change any heap value. + The others can allocate and even call back to OCaml code. +*/ typedef void (*caml_timing_hook) (void); extern caml_timing_hook caml_major_slice_begin_hook, caml_major_slice_end_hook; extern caml_timing_hook caml_minor_gc_begin_hook, caml_minor_gc_end_hook; diff --git a/byterun/finalise.c b/byterun/finalise.c index b9ce1b1b0c..fd1c29bc07 100644 --- a/byterun/finalise.c +++ b/byterun/finalise.c @@ -125,6 +125,7 @@ void caml_final_do_calls (void) if (running_finalisation_function) return; if (to_do_hd != NULL){ + if (caml_finalise_begin_hook != NULL) (*caml_finalise_begin_hook) (); caml_gc_message (0x80, "Calling finalisation functions.\n", 0); while (1){ while (to_do_hd != NULL && to_do_hd->size == 0){ @@ -143,6 +144,7 @@ void caml_final_do_calls (void) if (Is_exception_result (res)) caml_raise (Extract_exception (res)); } caml_gc_message (0x80, "Done calling finalisation functions.\n", 0); + if (caml_finalise_end_hook != NULL) (*caml_finalise_end_hook) (); } } diff --git a/byterun/major_gc.c b/byterun/major_gc.c index 006da8471e..6a273b9736 100644 --- a/byterun/major_gc.c +++ b/byterun/major_gc.c @@ -149,7 +149,6 @@ static void mark_slice (intnat work) int marking_closure = 0; #endif - if (caml_major_slice_begin_hook != NULL) (*caml_major_slice_begin_hook) (); caml_gc_message (0x40, "Marking %ld words\n", work); caml_gc_message (0x40, "Subphase = %ld\n", caml_gc_subphase); gray_vals_ptr = gray_vals_cur; @@ -322,7 +321,6 @@ static void mark_slice (intnat work) } } gray_vals_cur = gray_vals_ptr; - if (caml_major_slice_end_hook != NULL) (*caml_major_slice_end_hook) (); } static void sweep_slice (intnat work) @@ -330,7 +328,6 @@ static void sweep_slice (intnat work) char *hp; header_t hd; - if (caml_major_slice_begin_hook != NULL) (*caml_major_slice_begin_hook) (); caml_gc_message (0x40, "Sweeping %ld words\n", work); while (work > 0){ if (caml_gc_sweep_hp < limit){ @@ -369,7 +366,6 @@ static void sweep_slice (intnat work) } } } - if (caml_major_slice_end_hook != NULL) (*caml_major_slice_end_hook) (); } /* The main entry point for the GC. Called after each minor GC. @@ -424,6 +420,8 @@ intnat caml_major_collection_slice (intnat howmuch) This slice will either mark MS words or sweep SS words. */ + if (caml_major_slice_begin_hook != NULL) (*caml_major_slice_begin_hook) (); + if (caml_gc_phase == Phase_idle) start_cycle (); p = (double) caml_allocated_words * 3.0 * (100 + caml_percent_free) @@ -471,6 +469,7 @@ intnat caml_major_collection_slice (intnat howmuch) caml_allocated_words = 0; caml_dependent_allocated = 0; caml_extra_heap_resources = 0.0; + if (caml_major_slice_end_hook != NULL) (*caml_major_slice_end_hook) (); return computed_work; } diff --git a/byterun/minor_gc.c b/byterun/minor_gc.c index ca92928b2b..8eb087c77e 100644 --- a/byterun/minor_gc.c +++ b/byterun/minor_gc.c @@ -284,9 +284,7 @@ CAMLexport void caml_minor_collection (void) caml_major_collection_slice (0); caml_force_major_slice = 0; - if (caml_finalise_begin_hook != NULL) (*caml_finalise_begin_hook) (); caml_final_do_calls (); - if (caml_finalise_end_hook != NULL) (*caml_finalise_end_hook) (); caml_empty_minor_heap (); } |