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"
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLexport struct caml__roots_block *local_roots = NULL;
|
1995-05-04 03:15:53 -07:00
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
void (*scan_roots_hook) (scanning_action f) = NULL;
|
1995-10-30 02:21:28 -08:00
|
|
|
|
2000-01-07 08:51:58 -08:00
|
|
|
/* FIXME rename to [oldify_young_roots] and synchronise with asmrun/roots.c */
|
|
|
|
/* Call [oldify] on (at least) all the roots that point to the minor heap. */
|
1997-09-02 05:55:01 -07:00
|
|
|
void 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 */
|
|
|
|
for (sp = extern_sp; sp < stack_high; sp++) {
|
1995-10-30 02:21:28 -08:00
|
|
|
oldify (*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 ? */
|
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]);
|
|
|
|
oldify (*sp, sp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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]) {
|
1995-10-30 02:21:28 -08:00
|
|
|
oldify(*(gr->root), gr->root);
|
1995-05-04 03:15:53 -07:00
|
|
|
}
|
2000-01-07 08:51:58 -08:00
|
|
|
/* Finalised values */
|
|
|
|
final_do_young_roots (&oldify);
|
1995-10-30 02:21:28 -08:00
|
|
|
/* Hook */
|
2000-01-07 08:51:58 -08:00
|
|
|
if (scan_roots_hook != NULL) (*scan_roots_hook)(&oldify);
|
1995-05-04 03:15:53 -07:00
|
|
|
}
|
|
|
|
|
1995-07-10 02:48:27 -07:00
|
|
|
/* Call [darken] on all roots */
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
void darken_all_roots (void)
|
1997-05-13 07:45:38 -07:00
|
|
|
{
|
|
|
|
do_roots (darken);
|
|
|
|
}
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
void 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 */
|
1997-05-13 07:45:38 -07:00
|
|
|
f(global_data, &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 */
|
|
|
|
do_local_roots(f, extern_sp, stack_high, local_roots);
|
|
|
|
|
|
|
|
/* 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 */
|
|
|
|
final_do_strong_roots (f);
|
1997-08-29 08:37:22 -07:00
|
|
|
/* Hook */
|
|
|
|
if (scan_roots_hook != NULL) (*scan_roots_hook)(f);
|
|
|
|
}
|
|
|
|
|
2000-01-07 08:51:58 -08:00
|
|
|
void 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
|
|
|
|