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;
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
void (*scan_roots_hook) (scanning_action f) = NULL;
|
1995-10-30 02:21:28 -08:00
|
|
|
|
1995-07-10 02:48:27 -07:00
|
|
|
/* Register a global C root */
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
void register_global_root(value *r)
|
1995-07-10 02:48:27 -07:00
|
|
|
{
|
|
|
|
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 */
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
void remove_global_root(value *r)
|
1996-12-10 07:41:11 -08:00
|
|
|
{
|
|
|
|
struct global_root ** gp, * gr;
|
|
|
|
for (gp = &global_roots; *gp != NULL; gp = &(*gp)->next) {
|
|
|
|
gr = *gp;
|
|
|
|
if (gr->root == r) {
|
|
|
|
*gp = gr->next;
|
1997-11-20 07:30:43 -08:00
|
|
|
stat_free(gr);
|
1996-12-10 07:41:11 -08:00
|
|
|
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
|
|
|
|
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
|
|
|
}
|
|
|
|
/* 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 */
|
|
|
|
|
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 */
|
|
|
|
for (gr = global_roots; gr != NULL; gr = gr->next) {
|
|
|
|
f (*(gr->root), gr->root);
|
|
|
|
}
|
|
|
|
/* Hook */
|
|
|
|
if (scan_roots_hook != NULL) (*scan_roots_hook)(f);
|
|
|
|
}
|
|
|
|
|
1997-09-02 05:55:01 -07: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
|
|
|
|