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 */
|
1995-08-09 08:06:35 -07:00
|
|
|
/* Automatique. Distributed only by permission. */
|
|
|
|
/* */
|
|
|
|
/***********************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
/* To walk the memory roots for garbage collection */
|
|
|
|
|
|
|
|
#include "memory.h"
|
1995-07-10 02:48:27 -07:00
|
|
|
#include "major_gc.h"
|
|
|
|
#include "minor_gc.h"
|
1995-05-04 03:15:53 -07:00
|
|
|
#include "misc.h"
|
|
|
|
#include "mlvalues.h"
|
|
|
|
#include "roots.h"
|
|
|
|
#include "stacks.h"
|
|
|
|
|
1997-06-01 10:15:19 -07:00
|
|
|
struct caml__roots_block *local_roots = NULL;
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
struct global_root {
|
|
|
|
value * root;
|
|
|
|
struct global_root * next;
|
|
|
|
};
|
1997-05-26 10:16:31 -07:00
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
static struct global_root * global_roots = NULL;
|
|
|
|
|
1995-10-30 02:21:28 -08:00
|
|
|
void (*scan_roots_hook) P((scanning_action)) = NULL;
|
|
|
|
|
1995-07-10 02:48:27 -07:00
|
|
|
/* Register a global C root */
|
|
|
|
|
|
|
|
void register_global_root(r)
|
|
|
|
value * r;
|
|
|
|
{
|
|
|
|
struct global_root * gr;
|
|
|
|
gr = (struct global_root *) stat_alloc(sizeof(struct global_root));
|
|
|
|
gr->root = r;
|
|
|
|
gr->next = global_roots;
|
|
|
|
global_roots = gr;
|
|
|
|
}
|
|
|
|
|
1996-12-10 07:41:11 -08:00
|
|
|
/* Un-register a global C root */
|
|
|
|
|
|
|
|
void remove_global_root(r)
|
|
|
|
value * r;
|
|
|
|
{
|
|
|
|
struct global_root ** gp, * gr;
|
|
|
|
for (gp = &global_roots; *gp != NULL; gp = &(*gp)->next) {
|
|
|
|
gr = *gp;
|
|
|
|
if (gr->root == r) {
|
|
|
|
*gp = gr->next;
|
|
|
|
stat_free((char *) gr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1995-12-05 05:08:36 -08:00
|
|
|
/* Call [oldify] on all roots except [global_data] */
|
1995-07-10 02:48:27 -07:00
|
|
|
|
|
|
|
void oldify_local_roots ()
|
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
|
|
|
}
|
|
|
|
/* Local C roots */
|
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 */
|
|
|
|
for (gr = global_roots; gr != NULL; gr = gr->next) {
|
1995-10-30 02:21:28 -08:00
|
|
|
oldify(*(gr->root), gr->root);
|
1995-05-04 03:15:53 -07:00
|
|
|
}
|
1995-10-30 02:21:28 -08:00
|
|
|
/* Hook */
|
|
|
|
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 */
|
|
|
|
|
|
|
|
void darken_all_roots ()
|
1997-05-13 07:45:38 -07:00
|
|
|
{
|
|
|
|
do_roots (darken);
|
|
|
|
}
|
|
|
|
|
|
|
|
void do_roots (f)
|
|
|
|
scanning_action f;
|
1995-05-04 03:15:53 -07:00
|
|
|
{
|
1995-07-10 02:48:27 -07:00
|
|
|
register value * sp;
|
1995-05-04 03:15:53 -07:00
|
|
|
struct global_root * gr;
|
1997-05-26 10:16:31 -07:00
|
|
|
struct caml__roots_block *lr;
|
|
|
|
long i, j;
|
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
|
|
|
|
|
|
|
/* The stack */
|
|
|
|
for (sp = extern_sp; sp < stack_high; sp++) {
|
1997-05-13 07:45:38 -07:00
|
|
|
f (*sp, sp);
|
1995-07-10 02:48:27 -07:00
|
|
|
}
|
|
|
|
/* Local C roots */
|
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-07-10 02:48:27 -07:00
|
|
|
/* Global C roots */
|
|
|
|
for (gr = global_roots; gr != NULL; gr = gr->next) {
|
1997-05-13 07:45:38 -07:00
|
|
|
f (*(gr->root), gr->root);
|
1995-07-10 02:48:27 -07:00
|
|
|
}
|
1995-10-30 02:21:28 -08:00
|
|
|
/* Hook */
|
1997-05-13 07:45:38 -07:00
|
|
|
if (scan_roots_hook != NULL) (*scan_roots_hook)(f);
|
1995-05-04 03:15:53 -07:00
|
|
|
}
|