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
|
|
|
/* */
|
|
|
|
/* Damien Doligez, projet Para, 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
|
|
|
#include "alloc.h"
|
1997-05-13 07:45:38 -07:00
|
|
|
#include "compact.h"
|
2000-02-10 06:04:59 -08:00
|
|
|
#include "custom.h"
|
2000-03-10 11:04:31 -08:00
|
|
|
#include "finalise.h"
|
1995-05-04 03:15:53 -07:00
|
|
|
#include "gc.h"
|
|
|
|
#include "gc_ctrl.h"
|
|
|
|
#include "major_gc.h"
|
|
|
|
#include "minor_gc.h"
|
|
|
|
#include "misc.h"
|
|
|
|
#include "mlvalues.h"
|
1997-05-13 07:45:38 -07:00
|
|
|
#include "stacks.h"
|
1995-05-04 03:15:53 -07:00
|
|
|
|
1997-10-14 08:48:45 -07:00
|
|
|
#ifndef NATIVE_CODE
|
2005-09-22 07:21:50 -07:00
|
|
|
extern uintnat caml_max_stack_size; /* defined in stacks.c */
|
1997-10-14 08:48:45 -07:00
|
|
|
#endif
|
|
|
|
|
2004-01-02 11:23:29 -08:00
|
|
|
double caml_stat_minor_words = 0.0,
|
|
|
|
caml_stat_promoted_words = 0.0,
|
|
|
|
caml_stat_major_words = 0.0;
|
2001-02-05 06:59:02 -08:00
|
|
|
|
2005-09-22 07:21:50 -07:00
|
|
|
intnat caml_stat_minor_collections = 0,
|
|
|
|
caml_stat_major_collections = 0,
|
|
|
|
caml_stat_heap_size = 0, /* bytes */
|
|
|
|
caml_stat_top_heap_size = 0, /* bytes */
|
|
|
|
caml_stat_compactions = 0,
|
|
|
|
caml_stat_heap_chunks = 0;
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2003-12-31 06:20:40 -08:00
|
|
|
extern asize_t caml_major_heap_increment; /* bytes; see major_gc.c */
|
2005-09-22 07:21:50 -07:00
|
|
|
extern uintnat caml_percent_free; /* see major_gc.c */
|
|
|
|
extern uintnat caml_percent_max; /* see compact.c */
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
#define Next(hp) ((hp) + Bhsize_hp (hp))
|
|
|
|
|
1999-11-08 09:02:14 -08:00
|
|
|
#ifdef DEBUG
|
1995-05-04 03:15:53 -07:00
|
|
|
|
1999-11-08 09:02:14 -08:00
|
|
|
/* Check that [v]'s header looks good. [v] must be a block in the heap. */
|
|
|
|
static void check_head (value v)
|
|
|
|
{
|
2000-08-23 10:10:03 -07:00
|
|
|
Assert (Is_block (v));
|
|
|
|
Assert (Is_in_heap (v));
|
1999-11-08 09:02:14 -08:00
|
|
|
|
|
|
|
Assert (Wosize_val (v) != 0);
|
2000-01-02 08:10:00 -08:00
|
|
|
Assert (Color_hd (Hd_val (v)) != Caml_blue);
|
1999-11-08 09:02:14 -08:00
|
|
|
Assert (Is_in_heap (v));
|
|
|
|
if (Tag_val (v) == Infix_tag){
|
|
|
|
int offset = Wsize_bsize (Infix_offset_val (v));
|
|
|
|
value trueval = Val_op (&Field (v, -offset));
|
|
|
|
Assert (Tag_val (trueval) == Closure_tag);
|
|
|
|
Assert (Wosize_val (trueval) > offset);
|
|
|
|
Assert (Is_in_heap (&Field (trueval, Wosize_val (trueval) - 1)));
|
|
|
|
}else{
|
|
|
|
Assert (Is_in_heap (&Field (v, Wosize_val (v) - 1)));
|
|
|
|
}
|
|
|
|
if (Tag_val (v) == Double_tag){
|
|
|
|
Assert (Wosize_val (v) == Double_wosize);
|
|
|
|
}else if (Tag_val (v) == Double_array_tag){
|
|
|
|
Assert (Wosize_val (v) % Double_wosize == 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void check_block (char *hp)
|
|
|
|
{
|
|
|
|
mlsize_t i;
|
|
|
|
value v = Val_hp (hp);
|
|
|
|
value f;
|
|
|
|
|
|
|
|
check_head (v);
|
|
|
|
switch (Tag_hp (hp)){
|
|
|
|
case Abstract_tag: break;
|
|
|
|
case String_tag:
|
|
|
|
break;
|
|
|
|
case Double_tag:
|
|
|
|
Assert (Wosize_val (v) == Double_wosize);
|
|
|
|
break;
|
|
|
|
case Double_array_tag:
|
|
|
|
Assert (Wosize_val (v) % Double_wosize == 0);
|
|
|
|
break;
|
2000-02-10 06:04:59 -08:00
|
|
|
case Custom_tag:
|
|
|
|
Assert (!Is_in_heap (Custom_ops_val (v)));
|
1999-11-08 09:02:14 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Infix_tag:
|
|
|
|
Assert (0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Assert (Tag_hp (hp) < No_scan_tag);
|
|
|
|
for (i = 0; i < Wosize_hp (hp); i++){
|
|
|
|
f = Field (v, i);
|
|
|
|
if (Is_block (f) && Is_in_heap (f)) check_head (f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
|
|
|
/* Check the heap structure (if compiled in debug mode) and
|
|
|
|
gather statistics; return the stats if [returnstats] is true,
|
|
|
|
otherwise return [Val_unit].
|
|
|
|
*/
|
|
|
|
static value heap_stats (int returnstats)
|
1995-05-04 03:15:53 -07:00
|
|
|
{
|
2001-02-05 06:59:02 -08:00
|
|
|
CAMLparam0 ();
|
2005-09-22 07:21:50 -07:00
|
|
|
intnat live_words = 0, live_blocks = 0,
|
|
|
|
free_words = 0, free_blocks = 0, largest_free = 0,
|
|
|
|
fragments = 0, heap_chunks = 0;
|
2003-12-31 06:20:40 -08:00
|
|
|
char *chunk = caml_heap_start, *chunk_end;
|
1995-05-04 03:15:53 -07:00
|
|
|
char *cur_hp, *prev_hp;
|
|
|
|
header_t cur_hd;
|
|
|
|
|
1999-11-08 09:02:14 -08:00
|
|
|
#ifdef DEBUG
|
2003-12-29 14:15:02 -08:00
|
|
|
caml_gc_message (-1, "### O'Caml runtime: heap check ###\n", 0);
|
1999-11-08 09:02:14 -08:00
|
|
|
#endif
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
while (chunk != NULL){
|
|
|
|
++ heap_chunks;
|
|
|
|
chunk_end = chunk + Chunk_size (chunk);
|
|
|
|
prev_hp = NULL;
|
|
|
|
cur_hp = chunk;
|
|
|
|
while (cur_hp < chunk_end){
|
|
|
|
cur_hd = Hd_hp (cur_hp);
|
1999-11-08 09:02:14 -08:00
|
|
|
Assert (Next (cur_hp) <= chunk_end);
|
1995-05-04 03:15:53 -07:00
|
|
|
switch (Color_hd (cur_hd)){
|
2000-01-02 08:10:00 -08:00
|
|
|
case Caml_white:
|
1997-05-19 08:42:21 -07:00
|
|
|
if (Wosize_hd (cur_hd) == 0){
|
2002-05-28 09:57:31 -07:00
|
|
|
++ fragments;
|
1997-05-21 08:28:15 -07:00
|
|
|
Assert (prev_hp == NULL
|
2001-12-13 05:12:04 -08:00
|
|
|
|| Color_hp (prev_hp) != Caml_blue
|
2003-12-31 06:20:40 -08:00
|
|
|
|| cur_hp == caml_gc_sweep_hp);
|
1999-11-08 09:02:14 -08:00
|
|
|
}else{
|
2003-12-31 06:20:40 -08:00
|
|
|
if (caml_gc_phase == Phase_sweep && cur_hp >= caml_gc_sweep_hp){
|
2001-01-05 05:54:56 -08:00
|
|
|
++ free_blocks;
|
|
|
|
free_words += Whsize_hd (cur_hd);
|
|
|
|
if (Whsize_hd (cur_hd) > largest_free){
|
|
|
|
largest_free = Whsize_hd (cur_hd);
|
|
|
|
}
|
|
|
|
}else{
|
1999-11-08 09:02:14 -08:00
|
|
|
++ live_blocks;
|
|
|
|
live_words += Whsize_hd (cur_hd);
|
|
|
|
#ifdef DEBUG
|
|
|
|
check_block (cur_hp);
|
|
|
|
#endif
|
|
|
|
}
|
1997-05-19 08:42:21 -07:00
|
|
|
}
|
1999-11-08 09:02:14 -08:00
|
|
|
break;
|
2000-01-02 08:10:00 -08:00
|
|
|
case Caml_gray: case Caml_black:
|
1997-05-19 08:42:21 -07:00
|
|
|
Assert (Wosize_hd (cur_hd) > 0);
|
|
|
|
++ live_blocks;
|
|
|
|
live_words += Whsize_hd (cur_hd);
|
1999-11-08 09:02:14 -08:00
|
|
|
#ifdef DEBUG
|
|
|
|
check_block (cur_hp);
|
|
|
|
#endif
|
1997-05-19 08:42:21 -07:00
|
|
|
break;
|
2000-01-02 08:10:00 -08:00
|
|
|
case Caml_blue:
|
1997-05-19 08:42:21 -07:00
|
|
|
Assert (Wosize_hd (cur_hd) > 0);
|
|
|
|
++ free_blocks;
|
|
|
|
free_words += Whsize_hd (cur_hd);
|
|
|
|
if (Whsize_hd (cur_hd) > largest_free){
|
|
|
|
largest_free = Whsize_hd (cur_hd);
|
|
|
|
}
|
2002-12-12 10:59:11 -08:00
|
|
|
/* not true any more with big heap chunks
|
1997-05-21 08:28:15 -07:00
|
|
|
Assert (prev_hp == NULL
|
2000-01-02 08:10:00 -08:00
|
|
|
|| (Color_hp (prev_hp) != Caml_blue && Wosize_hp (prev_hp) > 0)
|
2003-12-31 06:20:40 -08:00
|
|
|
|| cur_hp == caml_gc_sweep_hp);
|
1997-05-19 08:42:21 -07:00
|
|
|
Assert (Next (cur_hp) == chunk_end
|
2000-01-02 08:10:00 -08:00
|
|
|
|| (Color_hp (Next (cur_hp)) != Caml_blue
|
1997-05-21 08:28:15 -07:00
|
|
|
&& Wosize_hp (Next (cur_hp)) > 0)
|
2002-12-12 10:59:11 -08:00
|
|
|
|| (Whsize_hd (cur_hd) + Wosize_hp (Next (cur_hp)) > Max_wosize)
|
2003-12-31 06:20:40 -08:00
|
|
|
|| Next (cur_hp) == caml_gc_sweep_hp);
|
2002-12-12 10:59:11 -08:00
|
|
|
*/
|
1997-05-19 08:42:21 -07:00
|
|
|
break;
|
1995-05-04 03:15:53 -07:00
|
|
|
}
|
|
|
|
prev_hp = cur_hp;
|
|
|
|
cur_hp = Next (cur_hp);
|
|
|
|
} Assert (cur_hp == chunk_end);
|
|
|
|
chunk = Chunk_next (chunk);
|
|
|
|
}
|
1999-11-08 09:02:14 -08:00
|
|
|
|
2004-01-02 11:23:29 -08:00
|
|
|
Assert (heap_chunks == caml_stat_heap_chunks);
|
|
|
|
Assert (live_words + free_words + fragments
|
|
|
|
== Wsize_bsize (caml_stat_heap_size));
|
1995-05-04 03:15:53 -07:00
|
|
|
|
1999-11-08 09:02:14 -08:00
|
|
|
if (returnstats){
|
2001-02-05 06:59:02 -08:00
|
|
|
CAMLlocal1 (res);
|
|
|
|
|
2001-08-13 06:53:51 -07:00
|
|
|
/* get a copy of these before allocating anything... */
|
2004-01-02 11:23:29 -08:00
|
|
|
double minwords = caml_stat_minor_words
|
2003-12-31 06:20:40 -08:00
|
|
|
+ (double) Wsize_bsize (caml_young_end - caml_young_ptr);
|
2004-01-02 11:23:29 -08:00
|
|
|
double prowords = caml_stat_promoted_words;
|
|
|
|
double majwords = caml_stat_major_words + (double) caml_allocated_words;
|
2005-09-22 07:21:50 -07:00
|
|
|
intnat mincoll = caml_stat_minor_collections;
|
|
|
|
intnat majcoll = caml_stat_major_collections;
|
|
|
|
intnat heap_words = Wsize_bsize (caml_stat_heap_size);
|
|
|
|
intnat cpct = caml_stat_compactions;
|
|
|
|
intnat top_heap_words = Wsize_bsize (caml_stat_top_heap_size);
|
2001-08-13 06:53:51 -07:00
|
|
|
|
2003-12-29 14:15:02 -08:00
|
|
|
res = caml_alloc_tuple (15);
|
2004-01-02 11:23:29 -08:00
|
|
|
Store_field (res, 0, caml_copy_double (minwords));
|
|
|
|
Store_field (res, 1, caml_copy_double (prowords));
|
|
|
|
Store_field (res, 2, caml_copy_double (majwords));
|
2001-08-13 06:53:51 -07:00
|
|
|
Store_field (res, 3, Val_long (mincoll));
|
|
|
|
Store_field (res, 4, Val_long (majcoll));
|
2002-01-18 07:13:26 -08:00
|
|
|
Store_field (res, 5, Val_long (heap_words));
|
2001-02-05 06:59:02 -08:00
|
|
|
Store_field (res, 6, Val_long (heap_chunks));
|
|
|
|
Store_field (res, 7, Val_long (live_words));
|
|
|
|
Store_field (res, 8, Val_long (live_blocks));
|
|
|
|
Store_field (res, 9, Val_long (free_words));
|
|
|
|
Store_field (res, 10, Val_long (free_blocks));
|
|
|
|
Store_field (res, 11, Val_long (largest_free));
|
|
|
|
Store_field (res, 12, Val_long (fragments));
|
2001-08-13 06:53:51 -07:00
|
|
|
Store_field (res, 13, Val_long (cpct));
|
2002-05-28 09:57:31 -07:00
|
|
|
Store_field (res, 14, Val_long (top_heap_words));
|
2001-02-05 06:59:02 -08:00
|
|
|
CAMLreturn (res);
|
1999-11-08 09:02:14 -08:00
|
|
|
}else{
|
2001-02-05 06:59:02 -08:00
|
|
|
CAMLreturn (Val_unit);
|
1999-11-08 09:02:14 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2004-01-02 11:23:29 -08:00
|
|
|
void caml_heap_check (void)
|
1999-11-08 09:02:14 -08:00
|
|
|
{
|
|
|
|
heap_stats (0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-01-02 11:23:29 -08:00
|
|
|
CAMLprim value caml_gc_stat(value v)
|
1999-11-08 09:02:14 -08:00
|
|
|
{
|
|
|
|
Assert (v == Val_unit);
|
|
|
|
return heap_stats (1);
|
1995-05-04 03:15:53 -07:00
|
|
|
}
|
|
|
|
|
2004-01-30 06:29:04 -08:00
|
|
|
CAMLprim value caml_gc_quick_stat(value v)
|
|
|
|
{
|
|
|
|
CAMLparam0 ();
|
|
|
|
CAMLlocal1 (res);
|
|
|
|
|
|
|
|
/* get a copy of these before allocating anything... */
|
|
|
|
double minwords = caml_stat_minor_words
|
|
|
|
+ (double) Wsize_bsize (caml_young_end - caml_young_ptr);
|
|
|
|
double prowords = caml_stat_promoted_words;
|
|
|
|
double majwords = caml_stat_major_words + (double) caml_allocated_words;
|
2005-09-22 07:21:50 -07:00
|
|
|
intnat mincoll = caml_stat_minor_collections;
|
|
|
|
intnat majcoll = caml_stat_major_collections;
|
|
|
|
intnat heap_words = caml_stat_heap_size / sizeof (value);
|
|
|
|
intnat top_heap_words = caml_stat_top_heap_size / sizeof (value);
|
|
|
|
intnat cpct = caml_stat_compactions;
|
|
|
|
intnat heap_chunks = caml_stat_heap_chunks;
|
2004-01-30 06:29:04 -08:00
|
|
|
|
|
|
|
res = caml_alloc_tuple (15);
|
|
|
|
Store_field (res, 0, caml_copy_double (minwords));
|
|
|
|
Store_field (res, 1, caml_copy_double (prowords));
|
|
|
|
Store_field (res, 2, caml_copy_double (majwords));
|
|
|
|
Store_field (res, 3, Val_long (mincoll));
|
|
|
|
Store_field (res, 4, Val_long (majcoll));
|
|
|
|
Store_field (res, 5, Val_long (heap_words));
|
|
|
|
Store_field (res, 6, Val_long (heap_chunks));
|
|
|
|
Store_field (res, 7, Val_long (0));
|
|
|
|
Store_field (res, 8, Val_long (0));
|
|
|
|
Store_field (res, 9, Val_long (0));
|
|
|
|
Store_field (res, 10, Val_long (0));
|
|
|
|
Store_field (res, 11, Val_long (0));
|
|
|
|
Store_field (res, 12, Val_long (0));
|
|
|
|
Store_field (res, 13, Val_long (cpct));
|
|
|
|
Store_field (res, 14, Val_long (top_heap_words));
|
|
|
|
CAMLreturn (res);
|
|
|
|
}
|
|
|
|
|
2004-01-02 11:23:29 -08:00
|
|
|
CAMLprim value caml_gc_counters(value v)
|
1999-11-29 12:02:33 -08:00
|
|
|
{
|
2001-02-05 06:59:02 -08:00
|
|
|
CAMLparam0 (); /* v is ignored */
|
1999-11-29 12:02:33 -08:00
|
|
|
CAMLlocal1 (res);
|
|
|
|
|
2001-08-13 06:53:51 -07:00
|
|
|
/* get a copy of these before allocating anything... */
|
2004-01-02 11:23:29 -08:00
|
|
|
double minwords = caml_stat_minor_words
|
2003-12-31 06:20:40 -08:00
|
|
|
+ (double) Wsize_bsize (caml_young_end - caml_young_ptr);
|
2004-01-02 11:23:29 -08:00
|
|
|
double prowords = caml_stat_promoted_words;
|
|
|
|
double majwords = caml_stat_major_words + (double) caml_allocated_words;
|
2001-08-13 06:53:51 -07:00
|
|
|
|
2003-12-29 14:15:02 -08:00
|
|
|
res = caml_alloc_tuple (3);
|
2004-01-02 11:23:29 -08:00
|
|
|
Store_field (res, 0, caml_copy_double (minwords));
|
|
|
|
Store_field (res, 1, caml_copy_double (prowords));
|
|
|
|
Store_field (res, 2, caml_copy_double (majwords));
|
1999-11-29 12:02:33 -08:00
|
|
|
CAMLreturn (res);
|
|
|
|
}
|
|
|
|
|
2004-01-02 11:23:29 -08:00
|
|
|
CAMLprim value caml_gc_get(value v)
|
1995-05-04 03:15:53 -07:00
|
|
|
{
|
2001-02-05 06:59:02 -08:00
|
|
|
CAMLparam0 (); /* v is ignored */
|
|
|
|
CAMLlocal1 (res);
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2003-12-29 14:15:02 -08:00
|
|
|
res = caml_alloc_tuple (6);
|
2003-12-31 06:20:40 -08:00
|
|
|
Store_field (res, 0, Val_long (Wsize_bsize (caml_minor_heap_size))); /* s */
|
|
|
|
Store_field (res, 1,Val_long(Wsize_bsize(caml_major_heap_increment)));/* i */
|
|
|
|
Store_field (res, 2, Val_long (caml_percent_free)); /* o */
|
2003-12-29 14:15:02 -08:00
|
|
|
Store_field (res, 3, Val_long (caml_verb_gc)); /* v */
|
2003-12-31 06:20:40 -08:00
|
|
|
Store_field (res, 4, Val_long (caml_percent_max)); /* O */
|
1997-10-14 08:48:45 -07:00
|
|
|
#ifndef NATIVE_CODE
|
2003-12-31 06:20:40 -08:00
|
|
|
Store_field (res, 5, Val_long (caml_max_stack_size)); /* l */
|
1997-10-14 08:48:45 -07:00
|
|
|
#else
|
2001-02-05 06:59:02 -08:00
|
|
|
Store_field (res, 5, Val_long (0));
|
1997-10-14 08:48:45 -07:00
|
|
|
#endif
|
2001-02-05 06:59:02 -08:00
|
|
|
CAMLreturn (res);
|
1995-05-04 03:15:53 -07:00
|
|
|
}
|
|
|
|
|
1997-05-13 07:45:38 -07:00
|
|
|
#define Max(x,y) ((x) < (y) ? (y) : (x))
|
|
|
|
|
2005-09-22 07:21:50 -07:00
|
|
|
static uintnat norm_pfree (uintnat p)
|
1995-05-04 03:15:53 -07:00
|
|
|
{
|
1997-05-13 07:45:38 -07:00
|
|
|
return Max (p, 1);
|
|
|
|
}
|
|
|
|
|
2005-09-22 07:21:50 -07:00
|
|
|
static uintnat norm_pmax (uintnat p)
|
1997-05-13 07:45:38 -07:00
|
|
|
{
|
1997-07-29 06:06:05 -07:00
|
|
|
return p;
|
1995-05-04 03:15:53 -07:00
|
|
|
}
|
|
|
|
|
2005-09-22 07:21:50 -07:00
|
|
|
static intnat norm_heapincr (uintnat i)
|
1995-05-04 03:15:53 -07:00
|
|
|
{
|
1997-05-21 08:28:15 -07:00
|
|
|
#define Psv (Wsize_bsize (Page_size))
|
|
|
|
i = ((i + Psv - 1) / Psv) * Psv;
|
1995-05-04 03:15:53 -07:00
|
|
|
if (i < Heap_chunk_min) i = Heap_chunk_min;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2005-09-22 07:21:50 -07:00
|
|
|
static intnat norm_minsize (intnat s)
|
1995-05-04 03:15:53 -07:00
|
|
|
{
|
|
|
|
if (s < Minor_heap_min) s = Minor_heap_min;
|
|
|
|
if (s > Minor_heap_max) s = Minor_heap_max;
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2004-01-02 11:23:29 -08:00
|
|
|
CAMLprim value caml_gc_set(value v)
|
1995-05-04 03:15:53 -07:00
|
|
|
{
|
2005-09-22 07:21:50 -07:00
|
|
|
uintnat newpf, newpm;
|
1997-05-03 11:33:16 -07:00
|
|
|
asize_t newheapincr;
|
|
|
|
asize_t newminsize;
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2003-12-29 14:15:02 -08:00
|
|
|
caml_verb_gc = Long_val (Field (v, 3));
|
1995-05-04 03:15:53 -07:00
|
|
|
|
1997-05-13 07:45:38 -07:00
|
|
|
#ifndef NATIVE_CODE
|
2003-12-31 06:20:40 -08:00
|
|
|
caml_change_max_stack_size (Long_val (Field (v, 5)));
|
1997-05-13 07:45:38 -07:00
|
|
|
#endif
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
newpf = norm_pfree (Long_val (Field (v, 2)));
|
2003-12-31 06:20:40 -08:00
|
|
|
if (newpf != caml_percent_free){
|
|
|
|
caml_percent_free = newpf;
|
|
|
|
caml_gc_message (0x20, "New space overhead: %d%%\n", caml_percent_free);
|
1995-05-04 03:15:53 -07:00
|
|
|
}
|
|
|
|
|
1997-05-13 07:45:38 -07:00
|
|
|
newpm = norm_pmax (Long_val (Field (v, 4)));
|
2003-12-31 06:20:40 -08:00
|
|
|
if (newpm != caml_percent_max){
|
|
|
|
caml_percent_max = newpm;
|
|
|
|
caml_gc_message (0x20, "New max overhead: %d%%\n", caml_percent_max);
|
1997-05-13 07:45:38 -07:00
|
|
|
}
|
|
|
|
|
2002-11-15 08:15:19 -08:00
|
|
|
newheapincr = Bsize_wsize (norm_heapincr (Long_val (Field (v, 1))));
|
2003-12-31 06:20:40 -08:00
|
|
|
if (newheapincr != caml_major_heap_increment){
|
|
|
|
caml_major_heap_increment = newheapincr;
|
2003-12-29 14:15:02 -08:00
|
|
|
caml_gc_message (0x20, "New heap increment size: %luk bytes\n",
|
2003-12-31 06:20:40 -08:00
|
|
|
caml_major_heap_increment/1024);
|
1995-05-04 03:15:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Minor heap size comes last because it will trigger a minor collection
|
|
|
|
(thus invalidating [v]) and it can raise [Out_of_memory]. */
|
1997-05-03 11:33:16 -07:00
|
|
|
newminsize = norm_minsize (Bsize_wsize (Long_val (Field (v, 0))));
|
2003-12-31 06:20:40 -08:00
|
|
|
if (newminsize != caml_minor_heap_size){
|
2003-12-29 14:15:02 -08:00
|
|
|
caml_gc_message (0x20, "New minor heap size: %luk bytes\n",
|
|
|
|
newminsize/1024);
|
2003-12-31 06:20:40 -08:00
|
|
|
caml_set_minor_heap_size (newminsize);
|
1995-05-04 03:15:53 -07:00
|
|
|
}
|
1995-06-18 07:44:56 -07:00
|
|
|
return Val_unit;
|
1995-05-04 03:15:53 -07:00
|
|
|
}
|
|
|
|
|
2004-01-02 11:23:29 -08:00
|
|
|
CAMLprim value caml_gc_minor(value v)
|
1995-06-18 07:44:56 -07:00
|
|
|
{ Assert (v == Val_unit);
|
2003-12-31 06:20:40 -08:00
|
|
|
caml_minor_collection ();
|
1995-06-18 07:44:56 -07:00
|
|
|
return Val_unit;
|
1995-05-04 03:15:53 -07:00
|
|
|
}
|
|
|
|
|
2005-03-24 09:20:54 -08:00
|
|
|
static void test_and_compact (void)
|
|
|
|
{
|
|
|
|
float fp;
|
|
|
|
|
|
|
|
fp = 100.0 * caml_fl_cur_size
|
|
|
|
/ (Wsize_bsize (caml_stat_heap_size) - caml_fl_cur_size);
|
|
|
|
if (fp > 1000000.0) fp = 1000000.0;
|
2005-09-22 07:21:50 -07:00
|
|
|
caml_gc_message (0x200, "Estimated overhead (lower bound) = %"
|
|
|
|
ARCH_INTNAT_PRINTF_FORMAT "u%%\n",
|
|
|
|
(uintnat) fp);
|
2005-03-24 09:20:54 -08:00
|
|
|
if (fp >= caml_percent_max && caml_stat_heap_chunks > 1){
|
|
|
|
caml_gc_message (0x200, "Automatic compaction triggered.\n", 0);
|
|
|
|
caml_compact_heap ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-02 11:23:29 -08:00
|
|
|
CAMLprim value caml_gc_major(value v)
|
1995-06-18 07:44:56 -07:00
|
|
|
{ Assert (v == Val_unit);
|
2005-03-24 09:20:54 -08:00
|
|
|
caml_gc_message (0x1, "Major GC cycle requested\n", 0);
|
2003-12-31 06:20:40 -08:00
|
|
|
caml_empty_minor_heap ();
|
|
|
|
caml_finish_major_cycle ();
|
2005-03-24 09:20:54 -08:00
|
|
|
test_and_compact ();
|
2004-01-02 11:23:29 -08:00
|
|
|
caml_final_do_calls ();
|
1995-06-18 07:44:56 -07:00
|
|
|
return Val_unit;
|
1995-05-04 03:15:53 -07:00
|
|
|
}
|
|
|
|
|
2004-01-02 11:23:29 -08:00
|
|
|
CAMLprim value caml_gc_full_major(value v)
|
1995-06-18 07:44:56 -07:00
|
|
|
{ Assert (v == Val_unit);
|
2005-03-24 09:20:54 -08:00
|
|
|
caml_gc_message (0x1, "Full major GC cycle requested\n", 0);
|
2003-12-31 06:20:40 -08:00
|
|
|
caml_empty_minor_heap ();
|
|
|
|
caml_finish_major_cycle ();
|
2004-01-02 11:23:29 -08:00
|
|
|
caml_final_do_calls ();
|
2003-12-31 06:20:40 -08:00
|
|
|
caml_empty_minor_heap ();
|
|
|
|
caml_finish_major_cycle ();
|
2005-03-24 09:20:54 -08:00
|
|
|
test_and_compact ();
|
2004-01-02 11:23:29 -08:00
|
|
|
caml_final_do_calls ();
|
1995-06-18 07:44:56 -07:00
|
|
|
return Val_unit;
|
1995-05-04 03:15:53 -07:00
|
|
|
}
|
|
|
|
|
2004-01-02 11:23:29 -08:00
|
|
|
CAMLprim value caml_gc_major_slice (value v)
|
2002-02-05 09:11:33 -08:00
|
|
|
{
|
|
|
|
Assert (Is_long (v));
|
2003-12-31 06:20:40 -08:00
|
|
|
caml_empty_minor_heap ();
|
|
|
|
return Val_long (caml_major_collection_slice (Long_val (v)));
|
2002-02-05 09:11:33 -08:00
|
|
|
}
|
|
|
|
|
2004-01-02 11:23:29 -08:00
|
|
|
CAMLprim value caml_gc_compaction(value v)
|
1997-05-13 07:45:38 -07:00
|
|
|
{ Assert (v == Val_unit);
|
2003-12-31 06:20:40 -08:00
|
|
|
caml_empty_minor_heap ();
|
|
|
|
caml_finish_major_cycle ();
|
|
|
|
caml_finish_major_cycle ();
|
|
|
|
caml_compact_heap ();
|
2004-04-15 08:00:27 -07:00
|
|
|
caml_final_do_calls ();
|
1997-05-13 07:45:38 -07:00
|
|
|
return Val_unit;
|
|
|
|
}
|
|
|
|
|
2005-09-22 07:21:50 -07:00
|
|
|
void caml_init_gc (uintnat minor_size, uintnat major_size,
|
|
|
|
uintnat major_incr, uintnat percent_fr,
|
|
|
|
uintnat percent_m)
|
1995-05-04 03:15:53 -07:00
|
|
|
{
|
2005-09-22 07:21:50 -07:00
|
|
|
uintnat major_heap_size = Bsize_wsize (norm_heapincr (major_size));
|
1999-11-08 09:02:14 -08:00
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
#ifdef DEBUG
|
2004-01-08 14:28:48 -08:00
|
|
|
caml_gc_message (-1, "### O'Caml runtime: debug mode ###\n", 0);
|
2000-04-17 13:01:40 -07:00
|
|
|
#endif
|
1999-11-08 09:02:14 -08:00
|
|
|
|
2003-12-31 06:20:40 -08:00
|
|
|
caml_set_minor_heap_size (Bsize_wsize (norm_minsize (minor_size)));
|
|
|
|
caml_major_heap_increment = Bsize_wsize (norm_heapincr (major_incr));
|
|
|
|
caml_percent_free = norm_pfree (percent_fr);
|
|
|
|
caml_percent_max = norm_pmax (percent_m);
|
|
|
|
caml_init_major_heap (major_heap_size);
|
2003-12-29 14:15:02 -08:00
|
|
|
caml_gc_message (0x20, "Initial minor heap size: %luk bytes\n",
|
2003-12-31 06:20:40 -08:00
|
|
|
caml_minor_heap_size / 1024);
|
2003-12-29 14:15:02 -08:00
|
|
|
caml_gc_message (0x20, "Initial major heap size: %luk bytes\n",
|
|
|
|
major_heap_size / 1024);
|
2003-12-31 06:20:40 -08:00
|
|
|
caml_gc_message (0x20, "Initial space overhead: %lu%%\n", caml_percent_free);
|
|
|
|
caml_gc_message (0x20, "Initial max overhead: %lu%%\n", caml_percent_max);
|
2003-12-29 14:15:02 -08:00
|
|
|
caml_gc_message (0x20, "Initial heap increment: %luk bytes\n",
|
2003-12-31 06:20:40 -08:00
|
|
|
caml_major_heap_increment / 1024);
|
1995-05-04 03:15:53 -07:00
|
|
|
}
|