2016-02-18 07:11:59 -08:00
|
|
|
/**************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* OCaml */
|
|
|
|
/* */
|
|
|
|
/* Xavier Leroy and Damien Doligez, INRIA Rocquencourt */
|
|
|
|
/* */
|
|
|
|
/* Copyright 1996 Institut National de Recherche en Informatique et */
|
|
|
|
/* en Automatique. */
|
|
|
|
/* */
|
|
|
|
/* All rights reserved. This file is distributed under the terms of */
|
|
|
|
/* the GNU Lesser General Public License version 2.1, with the */
|
|
|
|
/* special exception on linking described in the file LICENSE. */
|
|
|
|
/* */
|
|
|
|
/**************************************************************************/
|
1995-08-09 08:06:35 -07:00
|
|
|
|
2016-07-04 10:00:57 -07:00
|
|
|
#define CAML_INTERNALS
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
/* To walk the memory roots for garbage collection */
|
|
|
|
|
2020-06-14 07:03:03 -07:00
|
|
|
#include "caml/codefrag.h"
|
2014-12-27 06:41:49 -08:00
|
|
|
#include "caml/finalise.h"
|
|
|
|
#include "caml/globroots.h"
|
|
|
|
#include "caml/major_gc.h"
|
|
|
|
#include "caml/memory.h"
|
|
|
|
#include "caml/minor_gc.h"
|
|
|
|
#include "caml/misc.h"
|
|
|
|
#include "caml/mlvalues.h"
|
|
|
|
#include "caml/roots.h"
|
|
|
|
#include "caml/stacks.h"
|
2019-05-29 06:32:05 -07:00
|
|
|
#include "caml/memprof.h"
|
2019-11-15 04:52:35 -08:00
|
|
|
#include "caml/eventlog.h"
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2004-01-05 12:26:19 -08:00
|
|
|
CAMLexport void (*caml_scan_roots_hook) (scanning_action f) = NULL;
|
1995-10-30 02:21:28 -08:00
|
|
|
|
2015-11-20 08:54:26 -08:00
|
|
|
/* FIXME should rename to [caml_oldify_minor_roots] and synchronise with
|
2018-06-20 08:43:29 -07:00
|
|
|
roots_nat.c */
|
2003-12-31 06:20:40 -08:00
|
|
|
/* Call [caml_oldify_one] on (at least) all the roots that point to the minor
|
2002-01-18 07:13:26 -08:00
|
|
|
heap. */
|
2004-01-01 08:42:43 -08:00
|
|
|
void caml_oldify_local_roots (void)
|
1995-05-04 03:15:53 -07:00
|
|
|
{
|
|
|
|
register value * sp;
|
1997-05-26 10:16:31 -07:00
|
|
|
struct caml__roots_block *lr;
|
2005-09-22 07:21:50 -07:00
|
|
|
intnat i, j;
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
/* The stack */
|
2020-06-14 07:03:03 -07:00
|
|
|
/* [caml_oldify_one] acts only on pointers into the minor heap.
|
|
|
|
So, it is safe to pass code pointers to [caml_oldify_one],
|
|
|
|
even in no-naked-pointers mode */
|
2019-06-07 03:49:28 -07:00
|
|
|
for (sp = Caml_state->extern_sp; sp < Caml_state->stack_high; sp++) {
|
2003-12-31 06:20:40 -08:00
|
|
|
caml_oldify_one (*sp, sp);
|
1995-05-04 03:15:53 -07:00
|
|
|
}
|
2000-01-07 08:51:58 -08:00
|
|
|
/* Local C roots */ /* FIXME do the old-frame trick ? */
|
2019-06-09 10:37:42 -07:00
|
|
|
for (lr = Caml_state->local_roots; lr != NULL; lr = lr->next) {
|
1997-05-26 10:16:31 -07:00
|
|
|
for (i = 0; i < lr->ntables; i++){
|
|
|
|
for (j = 0; j < lr->nitems; j++){
|
|
|
|
sp = &(lr->tables[i][j]);
|
2003-12-31 06:20:40 -08:00
|
|
|
caml_oldify_one (*sp, sp);
|
1997-05-26 10:16:31 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1995-05-04 03:15:53 -07:00
|
|
|
/* Global C roots */
|
2008-03-10 12:56:39 -07:00
|
|
|
caml_scan_global_young_roots(&caml_oldify_one);
|
2000-01-07 08:51:58 -08:00
|
|
|
/* Finalised values */
|
2016-07-06 08:59:25 -07:00
|
|
|
caml_final_oldify_young_roots ();
|
2019-05-29 06:32:05 -07:00
|
|
|
/* Memprof */
|
2019-09-04 05:36:23 -07:00
|
|
|
caml_memprof_oldify_young_roots ();
|
1995-10-30 02:21:28 -08:00
|
|
|
/* Hook */
|
2004-01-01 08:42:43 -08:00
|
|
|
if (caml_scan_roots_hook != NULL) (*caml_scan_roots_hook)(&caml_oldify_one);
|
1995-05-04 03:15:53 -07:00
|
|
|
}
|
|
|
|
|
2003-12-31 06:20:40 -08:00
|
|
|
/* Call [caml_darken] on all roots */
|
1995-07-10 02:48:27 -07:00
|
|
|
|
2015-11-20 08:54:26 -08:00
|
|
|
void caml_darken_all_roots_start (void)
|
1997-05-13 07:45:38 -07:00
|
|
|
{
|
2015-11-20 08:54:26 -08:00
|
|
|
caml_do_roots (caml_darken, 1);
|
1997-05-13 07:45:38 -07:00
|
|
|
}
|
|
|
|
|
2015-11-20 08:54:26 -08:00
|
|
|
uintnat caml_incremental_roots_count = 1;
|
|
|
|
|
|
|
|
intnat caml_darken_all_roots_slice (intnat work)
|
|
|
|
{
|
2015-12-17 05:54:51 -08:00
|
|
|
return work;
|
2015-11-20 08:54:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Note, in byte-code there is only one global root, so [do_globals] is
|
|
|
|
ignored and [caml_darken_all_roots_slice] does nothing. */
|
|
|
|
void caml_do_roots (scanning_action f, int do_globals)
|
1995-05-04 03:15:53 -07:00
|
|
|
{
|
1995-07-10 02:48:27 -07:00
|
|
|
/* Global variables */
|
2019-11-15 04:52:35 -08:00
|
|
|
CAML_EV_BEGIN(EV_MAJOR_ROOTS_GLOBAL);
|
2003-12-31 06:20:40 -08:00
|
|
|
f(caml_global_data, &caml_global_data);
|
2019-11-15 04:52:35 -08:00
|
|
|
CAML_EV_END(EV_MAJOR_ROOTS_GLOBAL);
|
1997-08-29 08:37:22 -07:00
|
|
|
/* The stack and the local C roots */
|
2019-11-15 04:52:35 -08:00
|
|
|
CAML_EV_BEGIN(EV_MAJOR_ROOTS_LOCAL);
|
2020-08-25 13:22:34 -07:00
|
|
|
caml_do_local_roots_byt(f, Caml_state->extern_sp, Caml_state->stack_high,
|
|
|
|
Caml_state->local_roots);
|
2019-11-15 04:52:35 -08:00
|
|
|
CAML_EV_END(EV_MAJOR_ROOTS_LOCAL);
|
1997-08-29 08:37:22 -07:00
|
|
|
/* Global C roots */
|
2019-11-15 04:52:35 -08:00
|
|
|
CAML_EV_BEGIN(EV_MAJOR_ROOTS_C);
|
2008-03-10 12:56:39 -07:00
|
|
|
caml_scan_global_roots(f);
|
2019-11-15 04:52:35 -08:00
|
|
|
CAML_EV_END(EV_MAJOR_ROOTS_C);
|
2000-01-07 08:51:58 -08:00
|
|
|
/* Finalised values */
|
2019-11-15 04:52:35 -08:00
|
|
|
CAML_EV_BEGIN(EV_MAJOR_ROOTS_FINALISED);
|
2016-06-05 09:35:59 -07:00
|
|
|
caml_final_do_roots (f);
|
2019-11-15 04:52:35 -08:00
|
|
|
CAML_EV_END(EV_MAJOR_ROOTS_FINALISED);
|
2019-05-29 06:32:05 -07:00
|
|
|
/* Memprof */
|
2019-11-15 04:52:35 -08:00
|
|
|
CAML_EV_BEGIN(EV_MAJOR_ROOTS_MEMPROF);
|
2019-09-04 05:36:23 -07:00
|
|
|
caml_memprof_do_roots (f);
|
2019-11-15 04:52:35 -08:00
|
|
|
CAML_EV_END(EV_MAJOR_ROOTS_MEMPROF);
|
1997-08-29 08:37:22 -07:00
|
|
|
/* Hook */
|
2019-11-15 04:52:35 -08:00
|
|
|
CAML_EV_BEGIN(EV_MAJOR_ROOTS_HOOK);
|
2004-01-01 08:42:43 -08:00
|
|
|
if (caml_scan_roots_hook != NULL) (*caml_scan_roots_hook)(f);
|
2019-11-15 04:52:35 -08:00
|
|
|
CAML_EV_END(EV_MAJOR_ROOTS_HOOK);
|
1997-08-29 08:37:22 -07:00
|
|
|
}
|
|
|
|
|
2020-08-25 13:22:34 -07:00
|
|
|
CAMLexport void caml_do_local_roots_byt (scanning_action f, value *stack_low,
|
|
|
|
value *stack_high,
|
|
|
|
struct caml__roots_block *local_roots)
|
1997-08-29 08:37:22 -07:00
|
|
|
{
|
|
|
|
register value * sp;
|
|
|
|
struct caml__roots_block *lr;
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
for (sp = stack_low; sp < stack_high; sp++) {
|
2020-06-14 07:03:03 -07:00
|
|
|
#ifdef NO_NAKED_POINTERS
|
|
|
|
/* Code pointers inside the stack are naked pointers.
|
|
|
|
We must avoid passing them to function [f]. */
|
|
|
|
value v = *sp;
|
|
|
|
if (Is_block(v) && caml_find_code_fragment_by_pc((char *) v) == NULL) {
|
|
|
|
f(v, sp);
|
|
|
|
}
|
|
|
|
#else
|
1997-05-13 07:45:38 -07:00
|
|
|
f (*sp, sp);
|
2020-06-14 07:03:03 -07:00
|
|
|
#endif
|
1995-07-10 02:48:27 -07:00
|
|
|
}
|
1997-06-01 10:15:19 -07:00
|
|
|
for (lr = local_roots; lr != NULL; lr = lr->next) {
|
1997-05-26 10:16:31 -07:00
|
|
|
for (i = 0; i < lr->ntables; i++){
|
|
|
|
for (j = 0; j < lr->nitems; j++){
|
|
|
|
sp = &(lr->tables[i][j]);
|
|
|
|
f (*sp, sp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1995-05-04 03:15:53 -07:00
|
|
|
}
|