1995-08-09 08:06:35 -07:00
|
|
|
/***********************************************************************/
|
|
|
|
/* */
|
1996-04-30 07:53:58 -07:00
|
|
|
/* Objective Caml */
|
1995-08-09 08:06:35 -07:00
|
|
|
/* */
|
|
|
|
/* Xavier Leroy and Damien Doligez, INRIA Rocquencourt */
|
|
|
|
/* */
|
1996-04-30 07:53:58 -07:00
|
|
|
/* Copyright 1996 Institut National de Recherche en Informatique et */
|
1999-11-17 10:59:06 -08:00
|
|
|
/* en Automatique. All rights reserved. This file is distributed */
|
2001-12-07 05:41:02 -08:00
|
|
|
/* under the terms of the GNU Library General Public License, with */
|
|
|
|
/* the special exception on linking described in file ../LICENSE. */
|
1995-08-09 08:06:35 -07:00
|
|
|
/* */
|
|
|
|
/***********************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
/* To walk the memory roots for garbage collection */
|
|
|
|
|
2000-02-14 06:30:40 -08:00
|
|
|
#include "finalise.h"
|
2001-08-11 10:36:38 -07:00
|
|
|
#include "globroots.h"
|
1995-07-10 02:48:27 -07:00
|
|
|
#include "major_gc.h"
|
1999-11-08 09:10:11 -08:00
|
|
|
#include "memory.h"
|
1995-07-10 02:48:27 -07:00
|
|
|
#include "minor_gc.h"
|
1995-05-04 03:15:53 -07:00
|
|
|
#include "misc.h"
|
|
|
|
#include "mlvalues.h"
|
|
|
|
#include "roots.h"
|
|
|
|
#include "stacks.h"
|
|
|
|
|
2004-01-01 08:42:43 -08:00
|
|
|
CAMLexport struct caml__roots_block *caml_local_roots = NULL;
|
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
|
|
|
|
2004-01-01 08:42:43 -08:00
|
|
|
/* FIXME should rename to [caml_oldify_young_roots] and synchronise with
|
|
|
|
asmrun/roots.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;
|
|
|
|
struct global_root * gr;
|
1997-05-26 10:16:31 -07:00
|
|
|
struct caml__roots_block *lr;
|
|
|
|
long i, j;
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
/* The stack */
|
2003-12-31 06:20:40 -08:00
|
|
|
for (sp = caml_extern_sp; sp < caml_stack_high; sp++) {
|
|
|
|
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 ? */
|
2004-01-01 08:42:43 -08:00
|
|
|
for (lr = caml_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 */
|
2001-08-11 10:36:38 -07:00
|
|
|
for (gr = caml_global_roots.forward[0]; gr != NULL; gr = gr->forward[0]) {
|
2003-12-31 06:20:40 -08:00
|
|
|
caml_oldify_one(*(gr->root), gr->root);
|
1995-05-04 03:15:53 -07:00
|
|
|
}
|
2000-01-07 08:51:58 -08:00
|
|
|
/* Finalised values */
|
2004-01-02 11:23:29 -08:00
|
|
|
caml_final_do_young_roots (&caml_oldify_one);
|
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
|
|
|
|
2004-01-01 08:42:43 -08:00
|
|
|
void caml_darken_all_roots (void)
|
1997-05-13 07:45:38 -07:00
|
|
|
{
|
2004-01-01 08:42:43 -08:00
|
|
|
caml_do_roots (caml_darken);
|
1997-05-13 07:45:38 -07:00
|
|
|
}
|
|
|
|
|
2004-01-01 08:42:43 -08:00
|
|
|
void caml_do_roots (scanning_action f)
|
1995-05-04 03:15:53 -07:00
|
|
|
{
|
|
|
|
struct global_root * gr;
|
1995-07-10 02:48:27 -07:00
|
|
|
|
|
|
|
/* Global variables */
|
2003-12-31 06:20:40 -08:00
|
|
|
f(caml_global_data, &caml_global_data);
|
1995-07-10 02:48:27 -07:00
|
|
|
|
1997-08-29 08:37:22 -07:00
|
|
|
/* The stack and the local C roots */
|
2004-01-01 08:42:43 -08:00
|
|
|
caml_do_local_roots(f, caml_extern_sp, caml_stack_high, caml_local_roots);
|
1997-08-29 08:37:22 -07:00
|
|
|
|
|
|
|
/* Global C roots */
|
2001-08-11 10:36:38 -07:00
|
|
|
for (gr = caml_global_roots.forward[0]; gr != NULL; gr = gr->forward[0]) {
|
2001-08-13 01:46:59 -07:00
|
|
|
f(*(gr->root), gr->root);
|
1997-08-29 08:37:22 -07:00
|
|
|
}
|
2000-01-07 08:51:58 -08:00
|
|
|
/* Finalised values */
|
2004-01-02 11:23:29 -08:00
|
|
|
caml_final_do_strong_roots (f);
|
1997-08-29 08:37:22 -07:00
|
|
|
/* Hook */
|
2004-01-01 08:42:43 -08:00
|
|
|
if (caml_scan_roots_hook != NULL) (*caml_scan_roots_hook)(f);
|
1997-08-29 08:37:22 -07:00
|
|
|
}
|
|
|
|
|
2004-01-05 12:26:19 -08:00
|
|
|
CAMLexport void caml_do_local_roots (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++) {
|
1997-05-13 07:45:38 -07:00
|
|
|
f (*sp, sp);
|
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
|
|
|
}
|
1997-08-29 08:37:22 -07:00
|
|
|
|