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, projet Cristal, 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 initialize and resize the stacks */
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include "config.h"
|
|
|
|
#include "fail.h"
|
|
|
|
#include "misc.h"
|
|
|
|
#include "mlvalues.h"
|
|
|
|
#include "stacks.h"
|
|
|
|
|
|
|
|
value * stack_low;
|
|
|
|
value * stack_high;
|
|
|
|
value * stack_threshold;
|
|
|
|
value * extern_sp;
|
|
|
|
value * trapsp;
|
1996-11-29 10:36:42 -08:00
|
|
|
value * trap_barrier;
|
1995-05-04 03:15:53 -07:00
|
|
|
value global_data;
|
|
|
|
|
1997-05-13 07:45:38 -07:00
|
|
|
unsigned long max_stack_size;
|
|
|
|
|
|
|
|
void init_stack (initial_max_size)
|
|
|
|
unsigned long initial_max_size;
|
1995-05-04 03:15:53 -07:00
|
|
|
{
|
|
|
|
stack_low = (value *) stat_alloc(Stack_size);
|
|
|
|
stack_high = stack_low + Stack_size / sizeof (value);
|
|
|
|
stack_threshold = stack_low + Stack_threshold / sizeof (value);
|
|
|
|
extern_sp = stack_high;
|
|
|
|
trapsp = stack_high;
|
1996-11-29 10:36:42 -08:00
|
|
|
trap_barrier = stack_high + 1;
|
1997-05-13 07:45:38 -07:00
|
|
|
max_stack_size = initial_max_size;
|
1997-05-21 08:28:15 -07:00
|
|
|
gc_message ("Initial stack limit: %luk bytes\n",
|
|
|
|
max_stack_size / 1024 * sizeof (value));
|
1995-05-04 03:15:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void realloc_stack()
|
|
|
|
{
|
|
|
|
asize_t size;
|
|
|
|
value * new_low, * new_high, * new_sp;
|
|
|
|
value * p;
|
|
|
|
|
|
|
|
Assert(extern_sp >= stack_low);
|
|
|
|
size = stack_high - stack_low;
|
1997-05-15 06:26:08 -07:00
|
|
|
if (size >= max_stack_size) raise_stack_overflow();
|
1995-05-04 03:15:53 -07:00
|
|
|
size *= 2;
|
1997-05-13 07:45:38 -07:00
|
|
|
gc_message ("Growing stack to %luk bytes\n",
|
1997-05-19 08:42:21 -07:00
|
|
|
(unsigned long) size * sizeof(value) / 1024);
|
1995-05-04 03:15:53 -07:00
|
|
|
new_low = (value *) stat_alloc(size * sizeof(value));
|
|
|
|
new_high = new_low + size;
|
|
|
|
|
|
|
|
#define shift(ptr) \
|
|
|
|
((char *) new_high - ((char *) stack_high - (char *) (ptr)))
|
|
|
|
|
|
|
|
new_sp = (value *) shift(extern_sp);
|
|
|
|
bcopy((char *) extern_sp,
|
|
|
|
(char *) new_sp,
|
|
|
|
(stack_high - extern_sp) * sizeof(value));
|
|
|
|
stat_free((char *) stack_low);
|
|
|
|
trapsp = (value *) shift(trapsp);
|
1996-11-29 10:36:42 -08:00
|
|
|
trap_barrier = (value *) shift(trap_barrier);
|
1995-05-04 03:15:53 -07:00
|
|
|
for (p = trapsp; p < new_high; p = Trap_link(p))
|
|
|
|
Trap_link(p) = (value *) shift(Trap_link(p));
|
|
|
|
stack_low = new_low;
|
|
|
|
stack_high = new_high;
|
|
|
|
stack_threshold = stack_low + Stack_threshold / sizeof (value);
|
|
|
|
extern_sp = new_sp;
|
|
|
|
|
|
|
|
#undef shift
|
|
|
|
}
|
|
|
|
|
1997-05-13 07:45:38 -07:00
|
|
|
void change_max_stack_size (new_max_size)
|
|
|
|
unsigned long new_max_size;
|
|
|
|
{
|
|
|
|
asize_t size = stack_high - extern_sp + Stack_threshold / sizeof (value);
|
|
|
|
|
|
|
|
if (new_max_size < size) new_max_size = size;
|
|
|
|
gc_message ("Changing stack limit to %luk bytes\n",
|
1997-05-19 08:42:21 -07:00
|
|
|
new_max_size * sizeof (value) / 1024);
|
1997-05-13 07:45:38 -07:00
|
|
|
max_stack_size = new_max_size;
|
|
|
|
}
|