Files
mercury/runtime/mercury_memory.h
Tyson Dowd 376f2c69af An initial implementation of the accurate garbage collector.
Estimated hours taken: 90

An initial implementation of the accurate garbage collector.

WORK_IN_PROGRESS:
	Add an entry for the accurate garbage collector.

library/builtin.m:
library/mercury_builtin.m:
library/std_util.m:
runtime/mercury_tabling.h:
	Deep copy terms using the address of the value instead of
	just the value.

library/io.m:
	Initialize the garbage collector's rootset with the globals.

runtime/Mmakefile:
	Add new files to the Mmakefile.

runtime/mercury_accurate_gc.h:
runtime/mercury_accurate_gc.c:
	The new garbage collector.

runtime/mercury_agc_debug.c:
runtime/mercury_agc_debug.h:
	Debugging utilities for the new garbage collector.

runtime/mercury_deep_copy.c:
runtime/mercury_deep_copy.h:
runtime/mercury_deep_copy_body.h:
	Put the deep copy code in mercury_deep_copy_body.h, and #include
	it with appropriate #defines in order to get a variant for
	deep_copy(), and one for agc_deep_copy().

	agc_deep_copy() forwards pointers as it copies.

	Also, deep_copy (all variants) have been modified to take
	a pointer to the data to be copied, because some variants
	need to be able to modify it.

runtime/mercury_engine.c:
runtime/mercury_engine.h:
	Add a second heap_zone which is the to-space of
	the copying collector.
	Add a debug_heap_zone, which is used as a scratch
	heap for debugging.

runtime/mercury_label.c:
	Instead of
		realloc(entry_table, ....)
	do
		entry_table = realloc(entry_table, ....)
	to avoid horrible bugs.

	Also, make sure the tables get initialized before looking up
	an entry label.

runtime/mercury_imp.h:
	Include mercury_debug.h before most of the modules.
	(mercury_engine.h adds a new MemoryZone only if we are
	debugging accurate GC).

runtime/mercury_memory.c:
	Setup the debug_memory_zone sizes.
	Remove an unnecessary prototype.

runtime/mercury_memory_handlers.c:
	Add code to get the program counter and the stack pointer
	from the signal context.

	Call MR_schedule_agc() from default_handler() if doing accurate gc.

runtime/mercury_memory_zones.c:
	Setup the hardzone regardless of whether redzones are used.

	Add some more debugging information.

runtime/mercury_regorder.h:
runtime/machdeps/alpha_regs.h:
runtime/machdeps/i386_regs.h:
	Add definitions to make the real machine registers name/number
	for MR_sp available.

runtime/mercury_trace_internal.c:
runtime/mercury_trace_util.c:
runtime/mercury_trace_util.h:
	Add MR_trace_write_variable(), which writes terms given their
	value and type_info.

runtime/mercury_wrapper.c:
runtime/mercury_wrapper.h:
	Change the size of the heap redzone when doing accurate GC.
	Use a small heap when debugging agc.

runtime/mercury_debug.h:
runtime/mercury_conf_param.h:
	Add new debugging macros and document them.

runtime/mercury_type_info.c:
	Add const to the pointer arguments of MR_make_type_info.
1998-07-22 07:55:19 +00:00

121 lines
3.3 KiB
C

/*
** Copyright (C) 1994-1998 The University of Melbourne.
** This file may only be copied under the terms of the GNU Library General
** Public License - see the file COPYING.LIB in the Mercury distribution.
*/
/*
** mercury_memory.h - general memory-allocation related stuff for the
** Mercury runtime.
**
** This defines the different memory areas used by the Mercury runtime,
** including the det & nondet stacks, the heap (and solutions heap),
** and the fake_reg array for holding Mercury virtual registers.
** It also provides interfaces for constructing new memory zones,
** and for allocating (possibly shared) memory.
*/
#ifndef MERCURY_MEMORY_H
#define MERCURY_MEMORY_H
#include "mercury_memory_zones.h"
#include <stdlib.h> /* for size_t */
#include "mercury_types.h" /* for Word */
#include "mercury_std.h" /* for bool */
/* these cannot be changed without lots of modifications elsewhere */
#define MAX_REAL_REG 32 /* r1 .. r32 */
#define NUM_SPECIAL_REG 5 /* succip, sp, hp, maxfr, curfr */
/* this can be changed at will, including by -D options to the C compiler */
#ifndef MAX_VIRTUAL_REG
#define MAX_VIRTUAL_REG 1024
#endif
#ifdef MR_LOWLEVEL_DEBUG
extern MemoryZone *dumpstack_zone;
extern int dumpindex;
#endif
/*
** round_up(amount, align) returns `amount' rounded up to the nearest
** alignment boundary. `align' must be a power of 2.
*/
#define round_up(amount, align) ((((amount) - 1) | ((align) - 1)) + 1)
/*
** For these functions, see the comments in mercury_memory.c and
** mercury_engine.c
*/
extern void init_memory(void);
extern void init_heap(void);
extern void debug_memory(void);
/*
** allocate_bytes() allocates the given number of bytes.
**
** allocate_object(type) allocates space for an object of the specified type.
**
** allocate_array(type, num) allocates space for an array of objects of the
** specified type.
**
** If shared memory is being used, these allocation routines will allocate
** in shared memory.
*/
extern void *allocate_bytes(size_t numbytes);
#define allocate_object(type) \
((type *)allocate_bytes(sizeof(type)))
#define allocate_array(type, num) \
((type *)allocate_bytes((num) * sizeof(type)))
/*
** deallocate_memory() deallocates the memory allocated by one of the
** allocate_* functions.
*/
void deallocate_memory(void *);
/*
** checked_malloc() and checked_realloc() are like the standard C
** malloc() and realloc() functions, except that the return values
** are checked.
**
** NOTE: checked_malloc()ed and checked_realloc()ed structures must
** never contain pointers into GCed memory, otherwise those pointers
** will never be traced.
*/
#include <stddef.h> /* for size_t */
void *checked_malloc(size_t n);
void *checked_realloc(void *old, size_t n);
/*
** `unit' is the size of the minimum unit of memory we allocate (in bytes).
** `page_size' is the size of a single page of memory.
*/
extern size_t unit;
extern size_t page_size;
/*
** Users need to call MR_add_root() for any global variable which
** contains pointers to the Mercury heap. This information is only
** used for agc grades.
*/
#ifdef NATIVE_GC
#define MR_add_root(root_ptr, type_info) \
MR_agc_add_root((root_ptr), (type_info))
#else
#define MR_add_root(root_ptr, type_info) /* nothing */
#endif
#endif /* not MERCURY_MEMORY_H */