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"
|
|
|
|
|
|
|
|
value * local_roots = NULL;
|
|
|
|
|
|
|
|
struct global_root {
|
|
|
|
value * root;
|
|
|
|
struct global_root * next;
|
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
value * block;
|
|
|
|
struct global_root * gr;
|
|
|
|
|
|
|
|
/* 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 */
|
|
|
|
for (block = local_roots; block != NULL; block = (value *) block [1]){
|
|
|
|
for (sp = block - (long) block [0]; sp < block; sp++){
|
1995-10-30 02:21:28 -08:00
|
|
|
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 ()
|
1995-05-04 03:15:53 -07:00
|
|
|
{
|
1995-07-10 02:48:27 -07:00
|
|
|
register value * sp;
|
|
|
|
value * block;
|
1995-05-04 03:15:53 -07:00
|
|
|
struct global_root * gr;
|
1995-07-10 02:48:27 -07:00
|
|
|
|
|
|
|
/* Global variables */
|
|
|
|
darken(global_data);
|
|
|
|
|
|
|
|
/* The stack */
|
|
|
|
for (sp = extern_sp; sp < stack_high; sp++) {
|
|
|
|
darken (*sp);
|
|
|
|
}
|
|
|
|
/* Local C roots */
|
|
|
|
for (block = local_roots; block != NULL; block = (value *) block [1]){
|
|
|
|
for (sp = block - (long) block [0]; sp < block; sp++){
|
|
|
|
darken (*sp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Global C roots */
|
|
|
|
for (gr = global_roots; gr != NULL; gr = gr->next) {
|
|
|
|
darken (*(gr->root));
|
|
|
|
}
|
1995-10-30 02:21:28 -08:00
|
|
|
/* Hook */
|
|
|
|
if (scan_roots_hook != NULL) (*scan_roots_hook)(darken);
|
1995-05-04 03:15:53 -07:00
|
|
|
}
|