Commit Graph

38 Commits

Author SHA1 Message Date
Julien Fischer
eec4f9f125 Fix more issues in the runtime identified using clang -Wall.
runtime/mercury_wrapper.c:
	Declare MR_usage to be a noreturn function.  This avoids
	warnings in other parts of this module.

runtime/mercury_context.c
	Only define MR_write_out_profiling_parallel_execution if
	MR_PROFILE_PARALLEL_EXECUTION_SUPPORT is defined; it is
	otherwise unused.

	Fix incorrect conversion specifiers in some calls to fprintf.

	Only define the function action_shutdown_engine and friends
	if MR_THREAD_SAFE is defined.

	Do not define MR_checking_pending_contexts if MR_HIGHLEVEL_CODE
	is defined.

runtime/mercury_debug.c:
	Protect a group of function prototypes with MR_LOWLEVEL_DEBUG.
	(The corresponding definitions were already protected by this
	macro.)

runtime/mercury_label.c:
	Delete the declaration of the function compare_entry_by_addr
	as that function is not defined anywhere.

	Delete an unused local variable.

runtime/mercury_make_type_info_body.h:
	Delete an unused local variable.

runtime/mercury_memory.c:
	Delete left over function prototypes for try_munprotect and
	explain_context.  (The functions were moved into the module
	mercury_memory_handlers a long time ago.)

runtime/mercury_memory_handlers.c:
	Protect functions that are only used in the low-level agc
	grades by the appropriate macros.

runtime/mercury_minimal.c:
runtime/mercury_mm_own_stacks.c:
	Don't define some global variables in high-level C grades that
	are not necessary in those grades.

runtime/mercury_tabling.c:
	Only define MR_table_assert_failed if MR_TABLE_DEBUG is defined
	since it is otherwise unused.
2014-03-21 14:56:36 +11:00
Julien Fischer
36ac880e97 Fix bug #243: the management of memory zones on Windows was broken, causing a
Branches: main, 11.07

Fix bug #243: the management of memory zones on Windows was broken, causing a
memory leak in trseg and (presumably) stseg grades.  In grades that use
conservative GC on most systems (e.g. Linux or Mac OS X), allocation of memory
for memory zones is handled by the Boehm collector.  On Windows, the situation
was a bit different because we were trying to emulate mprotect style memory
protection.  Instead of allocating the memory for the zone using the Boehm
collector, the memory was reserved using a call to VirtualAlloc and then all
the memory within the zone was added to the Boehm GC's root set.  We could
then use VirtualAlloc and friends to emulate mprotect.  In principle, this
is fine, in practice there are number of problems with it.

When a memory zone was deallocated the call to VirtualFree was silently failing
(the return value of this call wasn't checked) -- this meant that the memory in
the zone was not being freed, hence the leak.   The immediate cause of this is
that we are calling VirtualFree with the wrong argument values for those used
in the corresponding call to VirtulAlloc.  Unfortunately, putting the "correct"
value in, just results in a segmentation fault.  (I suspect we haven't actually
been allocating the memory correctly either.)

Aside from this a second problem is that while we register the words in the
memory zone as GC roots when we allocate it, we do not remove them from the
GC root set when we deallocate the zone.  One rather obvious reason for
this is that the Boehm GC doesn't support doing this on Windows!

Yet another issue with all this is that while MR_protect_pages calls
VirtualAlloc, the documentation in the code suggests it should be calling
VirtualProtect.

The fix here is to replace the VirtualAlloc way of managing memory zones on
Windows with the Boehm GC approach used on all the other systems.  The former
is pretty much completely broken and only appeared to work because most grades
only allocate a few memory zones at program startup and never deallocate them.
This does mean the mprotect emulation we were doing on Windows will no longer
work, but that's the lesser of two evils.  (It may be possible to reinstate
something like it using VirtualProtect, but that will require looking carefully
at exactly how the Boehm collector allocates memory on Windows.)

runtime/mercury_memory_zones.c:
	Use the Boehm GC for allocating memory zones on Windows when
	in grade that uses conservative GC.

	Delete the flawed approach that uses VirtualAlloc.

runtime/mercury_conf_param.h:
	Do not define the macro MR_WIN32_VIRTUAL_ALLOC on Windows: we no
	longer use VirtualAlloc anywhere.

	Do not define MR_PROTECTPAGE and MR_CHECK_OVERFLOW_VIA_MPROTECT
	on Windows, since we no longer do any mprotect emulation on
	Windows.

runtime/mercury_memory_handlers.c:
	Properly protect some code in the handler for Windows memory
	access errors that assumes that memory zones have a redzone.
	(After this change they won't have a redzone.)
2011-12-07 11:29:16 +00:00
Julien Fischer
2239f59b30 Fix minor problems in the runtime identified by Visual C.
Branches: main, 11.07

Fix minor problems in the runtime identified by Visual C.

runtime/mercury_memory_zones.c:
	Fix a call to a function that no longer exists.

runtime/mercury_stack_trace.h:
	Fix argument type mismatches between function prototypes
	and definitions.
2011-07-16 07:51:30 +00:00
Paul Bone
ca7878f01a Make improvements to stack segments code.
The main benefits of these changes are:

    Stack segments (and other memory zones) are cached when they are released
    and can be re-used.

    Some thread safety-fixes have been added.

    All stack segments on all stacks are now the same size:
        Small contexts (which had small stacks) aren't used with stack
        segments.

        The first segment on any stack is the same size as any other segment.

    The first segment on any stack no-longer has a redzone.

    Hard zones on all memory zones have been set to the minimum of one page
    rather than one MR_unit which is usually two pages.

The caching of stack segments results in the following benchmark results.  The
benefit is negligible under normal circumstances, but becomes important when
small segment sizes are used.  Small segment sizes are common in
asm_fast.gc.par.stseg configurations as they reduce the memory required for
suspended contexts.

Non-segmented stack (32MB)
    asm_fast.gc                      average of 5 with ignore=1     18.16 (1.00)

With 512KB (normal) segments:
    asm_fast.gc.stseg and NO caching average of 5 with ignore=1     19.20 (1.06)
    asm_fast.gc.stseg WITH caching   average of 5 with ignore=1     19.16 (1.06)

With 4KB segments:
    asm_fast.gc.stseg and NO caching average of 5 with ignore=1     20.66 (1.14)
    asm_fast.gc.stseg WITH caching   average of 5 with ignore=1     19.66 (1.08)

Other changes include corrections in code comments, clearer function names and
a documentation fix.

runtime/mercury_memory_zones.h:
runtime/mercury_memory_zones.c:
    Re-write a lot of the code that managed the zone lists.  The old code did
    not re-use previously allocated but saved zones.  The changes ensure that
    MR_create_or_reuse_zone (formerly MR_create_zone) checks for a free zone
    of at least the required size before allocating a new one.  When zones are
    released they are put on the free list.

    As above MR_create_zone is now MR_create_or_reuse_zone,

    MR_unget_zone is now MR_release_zone.

    MR_construct_zone has been removed, it was only ever called by
    MR_create_or_reuse_zone.  MR_create_or_reuse_zone now contains the code for
    MR_construct_zone.

    To avoid an unnecessary sychronisation in parallel code some zones are not
    added to the used list.  The only zones put on the used list are those that
    are useful to have on the used list because they have a non-default signal
    handler or a redzone.

    Updates to used_memory_zones now use a pthread mutex so that only one
    thread may be updating the list at once.  This lock is shared with the
    free_memory_zones structure.

    Updates to used_memory_zones now use memory barriers to guarantee that
    concurrent reads always read a consistent, but possibly incomplete,
    data-structure.  This is necessary because it is read from a signal handler
    which cannot call pthread_mutex().

    Rename MR_get_used_memory_zones() to MR_get_used_memory_zones_readonly()
    and document that the zone lists may be incomplete.

    Make the MR_zone_next field of the MR_MemoryZone_Struct structure volatile.

    Remove MAX_ZONES, it wasn't being used anywhere.

    Insert some calls to MR_debug_log_message to help with debugging.

    Use the correct printf integer length modifier for MR_Unsigned values.

    Rename MR_context_id_counter to zone_id_counter, protect it with a lock in
    HLC thread safe grades and use atomic operations in LLC thread-safe
    grades..

    The offset at which we start using a memory zone is allocated in sequence
    from a table.  This table was protected by Mercury's global lock, this is
    now a CAS operation which prevents deadlocks when using trail segment,
    parallel grades.

runtime/mercury_stacks.c:
    Conform to changes in mercury_memory_zones.c.

    Use MR_debug_log_message for printf-style debugging rather than printf.

runtime/mercury_wrapper.h:
runtime/mercury_wrapper.c:
    Remove support for the smaller sized stacks in grades with stack segments.

    Disable redzones when using stack segments.  The MR_(non)detstack_zone_size
    variables affect the first segment on every stack.  Regardless of the type
    of contaxt that owns that stack.

    Conform to changes in runtime/mercury_memory_zones.h.

runtime/mercury_context.h:
runtime/mercury_context.c:
    Removed an extra declaration for MR_init_context_maybe_generator

    Small contexts are problematic since it's unclear to the programmer which
    computations will be executed on smaller contexts and therefore whether
    their stacks would overflow.

    Conform to changes in runtime/mercury_memory_zones.h.
    Conform to changes in runtime/mercury_wrapper.h.

runtime/mercury_memory.c:
    Adjust the definition of MR_unit.  It is now guaranteed to be a multiple of
    the page size which is required by its use in mercury_memory_zones.c

    Conform to changes in mercury_wrapper.h.

runtime/mercury_engine.c:
runtime/mercury_memory_handlers.c:
runtime/mercury_trail.c:
    Conform to changes in runtime/mercury_memory_zones.h.

runtime/mercury_memory_handlers.c:
    Use the correct printf integer length modifier for MR_Unsigned values.

runtime/mercury_misc.c:
    Print out the meaning of errno if it is nonzero in MR_fatal_error.

    Use the correct printf integer length modifier for MR_Unsigned values.

runtime/mercury_atomic_ops.h:
    Define MR_THREADSAFE_VOLATILE to expand to volatile when MR_THREADSAFE is
    defined.  Otherwise it expands to nothing.

    Make memory fences macros and atomic operations available in all thread safe
    grades, not just low level C grades.

doc/user_guide.texi:
    Corrected the default detstack size.
2011-04-05 10:27:26 +00:00
Paul Bone
f6e5c3c647 Fix a crash that can occur in low-level C, parallel, stack-segment grades.
MR_destroy_context will cache contexts in case the runtime needs a context in
the near future.  Because the context no-longer represents an on-going
computation MR_destroy_context did not copy context-data out of the
MercuryEngine and real machine registers into the context before caching it.
However in a stack segments grade a one of these values is the current stack
segment, this means that a context may be cached and later re-used which refers
to a stack segment that another context is now using, the cached context will
then trash the other context's stack.

The solution is to save the context before caching it.

This change also contains code that was helpful in diagnosing this problem.

runtime/mercury_context.c:
    Fix the bug (as above).

    Initialise the MR_init_engine_array_lock in MR_setup_thread_stuff.

    Print out logging messages if MR_DEBUG_STACK_SEGMENTS is defined in various
    places.

runtime/mercury_debug.h:
runtime/mercury_debug.c:
    Write code for printing out debug log messages in a grade appropriate-way.

runtime/mercury_memory_handlers.c:
    When exiting a signal handler flush the threadscope buffers of all engines
    before re-raising the signal.

runtime/mercury_engine.h:
runtime/mercury_engine.c:
    In thread safe grades provide an array of pointers to Mercury engines in
    the runtime.  This is used to flush the threadscope buffers in the signal
    handlers.  It may be used to improve work stealing in the future.

runtime/mercury_thread.h:
runtime/mercury_thread.c:
    When creating threads add each one's engine to the array of engine pointers.

runtime/mercury_wrapper.c:
    Allocate the array of engine pointers when the runtime starts up.
2010-05-26 07:45:49 +00:00
Paul Bone
344b85e8fd Re-throw unhandled signals.
The Mercury runtime uses signal handlers to implement redzones and to provide
extra information in the case of a segmentation violation.  However this
prevents Mercury programs from dumping core.  It also prevents a parent process
from distinguishing whether a child was killed by a signal or exited with a
non-zero exit status.  This change re-throws signals that cannot be handled so
that the program can dump core and does this in a way that is compatible with
the existing signal handlers.

runtime/mercury_memory_handlers.c:
    Use MR_reset_signal() and raise() to re-throw signals that we can't handle.

runtime/mercury_signal.h:
runtime/mercury_signal.c:
    Create MR_reset_signal() that resets the handler for a signal back to the
    default (SIG_DFL).
2010-05-23 04:54:22 +00:00
Peter Wang
f886caca9d Retry interrupted system calls which return an error code and set `errno' to
Estimated hours taken: 1.5
Branches: main

Retry interrupted system calls which return an error code and set `errno' to
EINTR.

compiler/prog_event.m:
library/io.m:
runtime/mercury_context.c:
runtime/mercury_memory_handlers.c:
runtime/mercury_trace_base.c:
runtime/mercury_wrapper.c:
	As above.

extras/posix/posix.dup.m:
extras/posix/posix.exec.m:
extras/posix/posix.lseek.m:
extras/posix/posix.open.m:
extras/posix/posix.readdir.m:
extras/posix/posix.select.m:
extras/posix/posix.socket.m:
extras/posix/posix.stat.m:
extras/posix/posix.wait.m:
extras/posix/posix.write.m:
	As above.

	Use `pragma foreign_enum' in some places.

extras/posix/posix.read.m:
	Use `pragma foreign_proc' instead of `pragma c_code' in a spot.
2007-10-30 00:46:23 +00:00
Ian MacLarty
bd8bf4edc0 Instead of just aborting when a "strange" segfault or bus error is
Estimated hours taken: 0.5
Branches: main

runtime/mercury_memory_handlers.c:
	Instead of just aborting when a "strange" segfault or bus error is
	caught, call MR_fatal_abort which will print a stack dump and display
	the last trace event in debugging grades.  Call MR_fatal_abort
	instead of MR_fatal_error because the comment above MR_fatal_abort says
	it is safe to call from signal handlers.
2006-03-18 15:57:58 +00:00
Julien Fischer
72bab3c057 Add missing `MR_zone' prefixes to some field names.
Estimated hours taken: 0.1
Branches: main

runtime/mercury_memory_handlers.c:
	Add missing `MR_zone' prefixes to some field names.
2005-12-15 10:40:37 +00:00
Zoltan Somogyi
1ed891b7b1 Introduce a mechanism for extending the det and nondet stacks when needed.
Estimated hours taken: 24
Branches: main

Introduce a mechanism for extending the det and nondet stacks when needed.
The mechanism takes the form of a new grade component, .exts ("extend stacks").

While the new mechanism may be useful in its own right, it is intended mainly
to support a new implementation of minimal model tabling, which will use a
separate Mercury context for each distinct subgoal. Each context has its own
det and nondet stack. Clearly, we can't have hundreds of contexts each with
megabyte sized det stacks. The intention is that the stacks of the subgoals
will start small, and be expanded when needed.

The runtime expansion of stacks doesn't work yet, but it is unnecessarily
hard to debug without an installed compiler that understands the new grade
component, which is why this diff will be committed before that is fixed.

compiler/handle_options.m:
compiler/options.m:
runtime/mercury_grade.h:
scripts/canonical_grade.sh-subr
scripts/init_grade_options.sh-subr
scripts/parse_grade_options.sh-subr
scripts/mgnuc.in
	Handle the new grade component.

runtime/mercury_memory_zones.h:
	Add MR_ prefixes to the names of the fields of the zone structure.

	Record not just the actual size of each zone, which includes various
	kinds of buffers, but also the desired size of the zone exclusive of
	buffers.

	Format the documentation of the zone structure fields more
	comprehensibly.

runtime/mercury_memory_zones.c:
	Instead of implementing memalign if it is not provided by the operating
	system, implement a function that allows us to reallocate the returned
	area of memory.

	Provide a prototype implementation of memory zone extension. It doesn't
	work yet.

	Factor out the code for setting up redzones, since it is now needed
	in more than place.

	Convert to four space indentation.

	Make the debugging functions a bit more flexible.

runtime/mercury_wrapper.c:
	Conform to the improved interface of the debugging functions.

runtime/mercury_overflow.h:
runtime/mercury_std.h:
	Move a generally useful macro from mercury_overflow.h to mercury_std.h.

runtime/mercury_stacks.c:
	Add functions to extend the stacks.

runtime/mercury_stacks.h:
	Add the tests required to invoke the functions that extend the stacks.

	Add the macros needed by the change to compiler/llds.m.

	Convert to four space indentation.

runtime/mercury_conf.h.in:
	Prepare for the use of the posix_memalign function, which is the
	current replacement of the obsolete memalign library function.
	We don't yet use it.

runtime/mercury_context.h:
	Format the documentation of the context structure fields more
	comprehensibly.

	Put MR_ prefixes on the names of the fields of some structures
	that didn't previously have them.

	Conform to the new names of the fields of the zone structure.

runtime/mercury_context.c:
runtime/mercury_debug.c:
runtime/mercury_deep_copy.c:
runtime/mercury_engine.c:
runtime/mercury_memory_handlers.c:
library/benchmarking.m:
library/exception.m:
	Conform to the new names of the fields of the zone structure.

	In some cases, add missing MR_ prefixes to function names
	and/or convert to four space indentation.

runtime/mercury_engine.h:
	Add a new low level debug flag for debugging stack extensions.

	Format the documentation of the engine structure fields more
	comprehensibly.

	Convert to four space indentation.

runtime/mercury_conf_param.h:
	Document a new low level debug flag for debugging stack extensions.

compiler/compile_target_code.m:
compiler/handle_options.m:
compiler/options.m:
	Handle the new grade component.

compiler/llds.m:
	Add two new kinds of LLDS instructions, save_maxfr and restore_maxfr.
	These are needed because the nondet stack may be relocated between
	saving and the restoring of maxfr, and the saved maxfr may point to
	the old stack. In .exts grades, these instructions will save not a
	pointer but the offset of maxfr from the start of the nondet stack,
	since offsets are not affected by the movement of the nondet stack.

compiler/code_info.m:
	Use the new instructions where relevant. (Some more work may be
	needed on this score; the relevant places are marked with XXX.)

compiler/dupelim.m:
compiler/dupproc.m:
compiler/exprn_aux.m:
compiler/jumpopt.m:
compiler/livemap.m:
compiler/llds_out.m:
compiler/middle_rec.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/reassign.m:
compiler/use_local_vars.m:
	Handle the new LLDS instructions.

tools/bootcheck:
	Provide a mechanism for setting the initial stack sizes for a
	bootcheck.
2005-09-13 08:25:44 +00:00
Peter Ross
07c3648d0f Disable code that accesses the fields redzone and handler when they
Estimated hours taken: 0.25
Branches: main

runtime/mercury_memory_handlers.c:
	Disable code that accesses the fields redzone and handler when they
	don't exist.
2004-10-18 20:51:28 +00:00
Fergus Henderson
17d5aa732e Add support for interfacing Mercury with the MPS garbage collector.
Estimated hours taken: 20
Branches: main

Add support for interfacing Mercury with the MPS garbage collector.

This change is broken into three parts:

	1. Import version 1.100.1 of the MPS kit into the Mercury
	   CVS repository, in the directory `mps_gc'.

	2. Make some changes to the MPS kit for Mercury,
	   to support fully-conservative collection and tagged pointers,
	   and to wrap it in an interface that is similar to that of
	   the Boehm collector.

	3. Modify the rest of the Mercury implementation
	   to support linking with the MPS kit instead
	   of the Boehm collector.  This involved defining
	   `mps' as a new GC method and a new grade component.

This is part 3 of 3.

Mmake.workspace:
	Include the MPS directories in the header file and library search
	paths.

tools/bootcheck:
	Link the mps_gc directory into the stage2 and stage3 directories.

Mmake.workspace:
runtime/Mmakefile:
scripts/ml.in:
	For *.mps grades, link in mps.a.
	(XXX ml.in is linking in libmps.a, which is wrong.)

runtime/Mmakefile:
trace/Mmakefile:
	In the rule for `check_headers', which checks macro namespace
	cleanliness, allow names to start with `MPS_' or `mps_'.

runtime/RESERVED_MACRO_NAMES:
	Add `mercury_mps_h', which is used by mps_gc/code/mercury_mps.h
	for its header guard.  (Normally it would be better to use
	uppercase for header guard macro names, but that would be
	inconsistent with the coding style used in mps_gc/code.)

scripts/canonical_grade.sh-subr:
scripts/init_grade_options.sh-subr:
scripts/parse_grade_options.sh-subr:
scripts/canonical_grade.sh-subr:
	Handle the new `mps' GC method and grade component.

compiler/globals.m:
compiler/options.m:
doc/user_guide.texi:
	Replace gc_method `conservative' with two alternatives
	`boehm' and `mps'. ("--gc conservative" is still allowed,
	and treated as equivalent to "--gc boehm".)
	Add new function `gc_is_conservative' to globals.m.

compiler/mercury_compile.m:
compiler/handle_options.m:
	Use `gc_is_conservative' rather than `= conservative'.

compiler/handle_options.m:
	Handle the "mps" grade component.
	(XXX need to document this in options.m and user_guide.texi)

compiler/compile_target_code.m:
	Pass the appropriate C defines for the new GC methods.

compiler/mercury_compile.m:
	Wrap the work-around for a Boehm GC bug inside `#ifndef MR_MPS_GC'.

library/array.m:
	Use GC_FREE() rather than GC_free().
	This is needed for two reasons:
	- so that it works with MPS, which only defines GC_FREE
	- so that it works with then Boehm collector when
	  GC debugging is enabled

library/benchmarking.m:
	Output GC statistics for the MPS collector.

runtime/mercury.h:
runtime/mercury_heap.h:
runtime/mercury_init.h:
runtime/mercury_memory.h:
	If MR_MPS_GC is defined, use mercury_mps.h rather than gc.h.

runtime/mercury_conf_param.h:
	Add configuration macros MR_BOEHM_GC and MR_MPS_GC.
	Set MR_CONSERVATIVE_GC if either of these is set.
	Default to MR_BOEHM_GC if only MR_CONSERVATIVE_GC is set.

runtime/mercury_context.h:
runtime/mercury_deep_copy.h:
runtime/mercury_engine.h:
runtime/mercury_float.h:
runtime/mercury_heap.h:
	Explictly #include "mercury_conf.h", so that
	MR_CONSERVATIVE_GC will be set properly before it is tested.

runtime/mercury_grade.h:
	Handle the .mps grade component.

runtime/mercury_memory.c:
runtime/mercury_wrapper.c:
runtime/mercury_memory_handlers.c:
	Move the call to MR_setup_signals() earlier in the
	initialization sequence, so that the MPS signal handlers
	get installed after our signal handlers.  This is needed
	because our signal handlers assume that any signals that
	they can't handle are fatal errors, which interfere's
	with MPS's use of signal handlers for memory barriers.

runtime/mercury_wrapper.c:
	Add code to initialize the MPS collector.
	Put code which is specific to the Boehm collector inside
	#ifdef MR_BOEHM_GC rather than #ifdef MR_CONSERVATIVE_GC.

runtime/mercury_wrapper.h:
	Update a comment.
2002-08-21 11:28:01 +00:00
Simon Taylor
b7c4a317e9 Add MR_ prefixes to the remaining non-prefixed symbols.
Estimated hours taken: 4
Branches: main

Add MR_ prefixes to the remaining non-prefixed symbols.

This change will require all workspaces to be updated
The compiler will start generating references to MR_TRUE,
MR_bool, etc., which are not defined in the old runtime
header files.

runtime/mercury_std.h:
	Add MR_ prefixes to bool, TRUE, FALSE, max, min,
	streq, strdiff, strtest, strntest, strneq, strndiff,
	strntest, NO_RETURN.

	Delete a commented out definition of `reg'.

runtime/mercury_tags.h:
	Add an MR_ prefix to TAGBITS.

configure.in:
runtime/mercury_goto.h:
runtime/machdeps/i386_regs.h/mercury_goto.h:
	Add an MR_ prefix to PIC.

runtime/mercury_conf_param.h:
	Allow non-prefixed PIC and HIGHTAGS to be defined on
	the command line.

runtime/mercury_bootstrap.h:
	Add backwards compatibility definitions.

RESERVED_MACRO_NAMES:
	Remove the renamed macros.

compiler/export.m:
compiler/ml_code_gen.m:
	Use MR_bool rather than MR_Bool (MR_Bool is
	meant to be for references to the Mercury type
	bool__bool).

runtime/mercury_types.h:
	Add a comment the MR_Bool is for references to
	bool__bool.

*/*.c:
*/*.h:
*/*.m:
	Add MR_ prefixes.
2002-02-18 07:01:33 +00:00
Simon Taylor
c66cea0665 Add MR_ prefixes to uses of configuration macros.
Estimated hours taken: 2.5
Branches: main

Add MR_ prefixes to uses of configuration macros.
Bootcheck now succeeds with MR_NO_CONF_BACKWARDS_COMPAT.

Mmake.common.in:
	Define MR_NO_CONF_BACKWARDS_COMPAT when checking
	for namespace cleanliness.

RESERVED_MACRO_NAMES:
	Remove the configuration macros.

runtime/mercury_conf_bootstrap.h:
	Remove a duplicate definition of BOXED_FLOAT.

configure.in:
*/*.c:
*/*.h:
*/*.m:
	Add MR_ prefixes.
2002-02-13 09:56:49 +00:00
Simon Taylor
e3157727fd Add a comment that mercury_signal.h must be included
Estimated hours taken: 0.2

runtime/mercury_signal.h:
runtime/mercury_memory.c:
runtime/mercury_memory_handlers.c:
	Add a comment that mercury_signal.h must be included
	before <signal.h> if `struct_sigcontext' is needed.
2002-02-01 08:43:20 +00:00
Simon Taylor
e1c9ac5299 Fix a bug in my last change.
Estimated hours taken: 0.2

runtime/mercury_signal.h:
	Fix a bug in my last change.
	<signal.h> needs to be included here for `struct sigaction'.

runtime/mercury_signal.c:
runtime/mercury_memory.c:
runtime/mercury_memory_handlers.c:
	Remove some duplicated code.
2002-01-31 17:10:17 +00:00
Simon Taylor
1b127a6111 Improve the handling of the mdb's `--window' option.
Estimated hours taken: 10

Improve the handling of the mdb's `--window' option.
`mdb --window' now creates a window for mdb, not the program.
The main advantage of this is that redirection of the program's
input and output now works. The new behaviour should also be
implementable using the Windows API. The old behaviour is still
available with `mdb --program-in-window'.

Unfortunately, the code to open a pseudo-terminal for mdb's I/O
isn't very portable. It works on everything we run nightly tests on,
but isn't likely to work on older systems or BSD systems.

NEWS:
	Document the change.

scripts/mdb.in:
	Handle the new behaviour of `--window'.
	Add `--program-in-window'.

trace/mercury_trace_internal.c:
	If `--window' was passed in MERCURY_OPTIONS, redirect
	mdb's I/O to a window created using `xterm -S'.

	Rename occurrences of `close' to avoid gcc warnings.

runtime/mercury_trace_base.h:
runtime/mercury_trace_base.c:
	Kill the mdb window on exit.

runtime/mercury_wrapper.h:
runtime/mercury_wrapper.c:
	Add a runtime options `--mdb-in-window' for use by the mdb script.

runtime/mercury_signal.h:
runtime/mercury_signal.c:
	Add a version of MR_setup_signal which doesn't cause
	system calls to be restarted after a signal is received.
	This is needed to allow a read() from the mdb window
	to timeout if the window failed to start.

	Add functions to get and set the action for a given signal.

configure.in:
runtime/mercury_conf.h.in:
runtime/RESERVED_MACRO_NAMES.
	Check for functions open, close, dup, dup2, fdopen, setpgid,
	fork, execlp, wait, kill, grantpt, unlockpt, pstname, tcgetattr,
	tcsetattr and ioctl.

	Check for type pid_t.

	Check for header files <fcntl.h>, <termios.h>, <sys/ioctl.h>,
	<sys/stropts.h>.

	Check for /dev/ptmx, used to open pseudo-terminals.

runtime/mercury_misc.c:
runtime/mercury_misc.h:
	Add MR_mdb_warning, which prefixes messages from the
	debugger with "mdb: ".

	Add MR_perror and MR_mdb_perror, which are versions
	of perror which prefix the printed message with
	"Mercury runtime: " and "mdb: " respectively.

runtime/mercury_prof_time.c:
runtime/mercury_prof.c:
runtime/mercury_memory_handlers.c:
	Don't prefix error messages passed to MR_setup_signal
	with "Mercury runtime:". MR_setup_signal now uses
	MR_perror.
2002-01-30 14:51:11 +00:00
Fergus Henderson
71c25b3d11 More improvements to accurate GC for the MLDS->C back-end.
Estimated hours taken: 8
Branches: main

More improvements to accurate GC for the MLDS->C back-end.

runtime/mercury_accurate_gc.h:
runtime/mercury_accurate_gc.c:
	Add new routine MR_garbage_collect().

runtime/mercury_memory_handlers.c:
	Wrap `#ifndef MR_HIGHLEVEL_CODE' around some LLDS-specific
	code for accurate GC.

runtime/mercury_accurate_gc.c:
runtime/mercury_memory_handlers.c:
	Fix some software rot: missing `MR_' and `MR_eng_' prefixes.

runtime/mercury.h:
	Add MR_GC_check() macro, which invokes MR_garbage_collect()
	if needed.

compiler/mlds.m:
	Add gc_check as a new mlds__atomic_statement.

compiler/ml_elim_nested.m:
	Insert gc_check statements at the start of every procedure
	that does any heap allocation.

compiler/ml_elim_nested.m:
compiler/mlds_to_c.m:
compiler/mlds_to_java.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
	Minor changes to handle gc_check statements.

compiler/ml_code_util.m:
	Fix some bugs in the way that we were calling
	private_builtin__gc_trace/1.
2002-01-28 05:30:32 +00:00
Fergus Henderson
3895856810 Apply Samuel Tardieu <sam@inf.enst.fr>'s fixes for FreeBSD
Estimated hours taken: 2
Branches: main release

Apply Samuel Tardieu <sam@inf.enst.fr>'s fixes for FreeBSD
(with some additional documentation).

configure.in:
runtime/mercury_conf.h.in:
	Check for <sys/signal.h>.

runtime/mercury_memory_zones.c:
runtime/mercury_memory_handlers.c:
	Include <sys/signal.h> (if present) before <ucontext.h>.
	This is needed on FREEBSD because <ucontext.h> refers to
	sigset_t without defining it.

configure.in:
runtime/mercury_memory_handlers.c:
	Change the autoconf test for siginfo_t so that it doesn't use macros
	like BUS_ADRALN etc.  Instead, surround all uses of such macros
	with #ifdef BUS_ADRALN ... #endif.

boehm_gc/dyn_load.c:
	Enable support for ELF shared libraries on FREEBSD
	(using the same code as on Linux).
2001-03-13 18:02:26 +00:00
Peter Ross
a389e6cc49 Add a missing MR_ prefix.
Estimated hours taken: 0.1

runtime/mercury_memory_handlers.c:
    Add a missing MR_ prefix.
2000-11-27 13:18:07 +00:00
Zoltan Somogyi
090552c993 Make everything in the runtime use MR_ prefixes, and make the compiler
Estimated hours taken: 10

Make everything in the runtime use MR_ prefixes, and make the compiler
bootstrap with -DMR_NO_BACKWARDS_COMPAT.

runtime/mercury_*.[ch]
	Add MR_ prefixes to all functions, global variables and almost all
	macros that could pollute the namespace. The (intentional) exceptions
	are

	1. some function, variable, type and label names that already start
	   with MR_, mercury_, Mercury or _entry;
	2. some standard C macros in mercury_std.h;
	3. the macros used in autoconfiguration (since they are used in scripts
	   as well as the runtime, the MR_ prefix may not be appropriate for
	   those).

	In some cases, I deleted things instead of adding prefixes
	if the "things" were obsolete and not user visible.

runtime/mercury_bootstrap.h:
	Provide MR_-less forms of the macros for bootstrapping and for
	backward compatibility for user code.

runtime/mercury_debug.[ch]:
	Add a FILE * parameter to a function that needs it.

compiler/code_info.m:
compiler/export.m:
compiler/fact_table.m:
compiler/llds.m:
compiler/llds_out.m:
compiler/pragma_c_gen.m:
compiler/trace.m:
	Add MR_ prefixes to the C code generated by the compiler.

library/*.m:
	Add MR_ prefixes to handwritten code.

trace/mercury_trace_*.c:
util/mkinit.c:
	Add MR_ prefixes as necessary.

extras/concurrency/semaphore.m:
	Add MR_ prefixes as necessary.
2000-11-23 02:01:11 +00:00
Tyson Dowd
5384f88ac2 Updates to the accurage garbage collector (including fixes to get it to
Estimated hours taken: 8

Updates to the accurage garbage collector (including fixes to get it to
compile and also to use the MR_Long_Lval and MR_Short_Lval code).
A prototype of non-det stack tracing.

runtime/mercury_accurate_gc.c:
runtime/mercury_accurate_gc.h:
runtime/mercury_agc_debug.c:
runtime/mercury_agc_debug.h:
	Updates to the GC necessary to get it to compile.

runtime/mercury_conf_param.h:
runtime/mercury_wrapper.c:
	Add an option to set the heap very small (useful for debugging).

runtime/mercury_deep_copy.c:
runtime/mercury_deep_copy_body.h:
	Start adding checks for traversal range (things that aren't on
	the heap, but might contain pointers into the heap).
	Not all of the checks have been done yet.

runtime/mercury_layout_util.c:
runtime/mercury_layout_util.h:
	Fix a type -- MR_TypeInfo instead of MR_Word.

runtime/mercury_memory_handlers.c:
	Add get_curfr_from_context

runtime/mercury_stack_layout.h:
	Fix a comment.
	Define MR_SHORT_LVAL_NUMBER to find the number (e.g. register
	number or stack from) from a short lval.
2000-11-07 08:58:35 +00:00
Fergus Henderson
ada9593c53 Add a forward declaration of `struct sigcontext' to avoid a
Estimated hours taken: 0.5

runtime/mercury_signal.c:
runtime/mercury_memory.c:
runtime/mercury_memory_handlers.c:
        Add a forward declaration of `struct sigcontext' to avoid a
        gcc warning inside <signal.h>.  This is needed since our
        `#define sigcontext_struct sigcontext' hack breaks the Linux
        headers a bit -- it means that an earlier forward declaration
        of `struct sigcontext_struct' won't prevent this warning.
        Also add an XXX comment about the code being duplicated three times.
2000-09-12 19:51:07 +00:00
Tyson Dowd
0f03f0f40a Don't set SA_SIGINFO if we expect a struct sigcontext to be
Estimated hours taken: 2

runtime/mercury_signal.c:
	Don't set SA_SIGINFO if we expect a struct sigcontext to be
	passed to us.
	Fix some incorrect comments in #defines.

runtime/mercury_memory_handlers.c:
	Change the stack dump message, since I am tired of people
	telling me that they recompiled with --low-level-debug and
	didn't get a stack dump.
2000-09-11 04:29:16 +00:00
Tyson Dowd
db64a3588d Add MR_ prefixes to the types used when generating C code.
Estimated hours taken: 4

Add MR_ prefixes to the types used when generating C code.
This means types such as Word, String, Bool, Float become MR_Word,
MR_String, MR_Bool, MR_Float.  Also define MR_Box for both the LLDS and
MLDS backends so we can use it uniformly.

This is very important in environments where String or Bool have already
been used as system types (for example, managed C++).  And besides, we
should do it anyway as part of the grand namespace cleanup.

I have fixed all of the uses of the non-prefixed types in the runtime
and trace directories.  I haven't done it for the library and compiler
directories yet (no promises that I will do it in future either).  But
if you see a non-prefixed type in code from now on, please consider it a
bug and fix it.

mercury_bootstrap.h contains #defines to map the non-prefixed types into
the prefixed ones.  Like many of the other namespace cleaning backwards
compatibility macros, this can be turned off with
MR_NO_BACKWARDS_COMPAT.

This shouldn't break any code, but this kind of change affects so many
things that of course there could be problems lurking in there somewhere.

If you start getting errors from the C compiler after this change is
installed, you will want to make sure you at least have the runtime
system updated so that you are getting the backwards compatibility
definitions in mercury_bootstrap.h.  Then if you continue to have
problems you can bug me about it.

compiler/export.m:
compiler/llds_out.m:
compiler/mlds_to_c.m:
	Use MR_Word, MR_Float, MR_Bool, etc when generating C.

doc/reference_manual.texi:
	Update the reference manual to talk about MR_Word, MR_String,
	MR_Char, etc.

runtime/mercury_bootstrap.h:
	Add bootstrapping typedefs.

runtime/*:
trace/*:
	Change Word, Float, Bool, Code, String, etc to
	MR_Word, MR_Float, MR_Bool, MR_Code, MR_String.
2000-08-03 06:19:31 +00:00
Peter Ross
2c78c8d480 Print a newline before dumping the stack.
Estimated hours taken: 0.2

runtime/mercury_memory_handlers.c:
    Print a newline before dumping the stack.
2000-07-27 11:52:35 +00:00
Peter Ross
201413d997 Use Win32 exceptions to report problems when Win32 structured exceptions
Estimated hours taken: 48

Use Win32 exceptions to report problems when Win32 structured exceptions
are available.

configure.in:
runtime/mercury_conf.h.in:
    No longer define MR_WIN32, just because we are using a Microsoft
    compiler, instead we use _WIN32 to detect the presence of the Win32
    API.

runtime/mercury_conf_param.h:
    Define the following symbolic constants:
        MR_WIN32 which is true if the Win32 API is available.
        MR_WIN32_GETSYSTEMINFO which is true if GetSystemInfo() is
        availabe.
        MR_WIN32_VIRTUALALLOC which is true if VirtualAlloc() is
        availabe.
        MR_MSVC_STRUCTURED_EXCEPTIONS if we can use Microsoft Visual C
        structured exceptions.
        MR_PROTECTPAGE if can provide mprotect like functionality.
    All of the above are assumed true if the Win32 API is available.
    MR_CHECK_OVERFLOW_VIA_MPROTECT is also true if MR_WIN32, because the
    Win32 API provides mprotect like functionality.

runtime/mercury_memory_zones.c:
    Define a function MR_protect_pages() which has the same interface as
    mprotect.  It just calls mprotect when it exists or equivalent code
    to emulate it under Win32.
    Use MR_PROTECTPAGE in place of HAVE_MPROTECT, and replace all calls
    to mprotect() with MR_protect_pages().
    Define a Win32 version of memalign.

runtime/mercury_memory_handlers.c:
    Use MR_protect_pages() instead of mprotect().
    Don't use signal handlers when in a Win32 structured exceptions are
    available.
    Code to explain Win32 exceptions on stderr.

runtime/mercury_memory_handlers.h:
    Export MR_filter_win32_exception for use in mercury_wrapper.c

runtime/mercury_memory_zones.h:
    Use MR_PROTECTPAGE in place of HAVE_MPROTECT.
    Define PROT_{NONE,READ,WRITE} if we the Win32 API is available and
    they are not already defined.
    Export the definition of MR_protect_pages().

runtime/mercury_wrapper.c:
    Wrap the call to main in a __try __except block if we are using
    Win32 structured exceptions, so that any exceptions generated are
    caught and debugging info about them printed to stderr.

runtime/mercury_memory.c:
    Add a Win32 version of getpagesize().
2000-06-29 09:55:37 +00:00
Peter Ross
a68df3d95f Allow compilation of the mercury compiler *ONLY* in the grade hlc.gc
Estimated hours taken: 40

Allow compilation of the mercury compiler *ONLY* in the grade hlc.gc
using the Microsoft Visual C++ compiler (MSVC).  This is still
work-in-progress.

configure.in:
    Test to see whether or not we are using the Microsoft compiler.
    Don't fail if we can't interpret return values from system.

boehm_gc/Mmakefile:
    Use NT_MAKEFILE if we are using MSVC.

boehm_gc/NT_MAKEFILE:
    Apply the the changes to boehm_gc/Makefile to this file.

browser/Mmakefile:
library/Mmakefile:
runtime/Mmakefile:
trace/Mmakefile:
    Use the correct executable to create libraries.
    Use AR_LIBFILE_OPT to name the library.

compiler/llds_out.m:
    Export output_c_file_intro_and_grade so that the correct header can
    be placed at the start of each C file.

compiler/mlds_to_c.m:
    Output the header at the start of each C file, so that configure
    doesn't delete the file when checking the compatability with
    the configured settings.
    When initializing empty arrays place a dummy entry in the array, so
    that the MSVC compiler generates a symbol for that array.

compiler/passes_aux.m:
    Add invoke_shell_command.  This predicate wraps commands with
    a bash -c 'command ' when shell scripts aren't supported by the
    target system.

compiler/mercury_compile.m:
compiler/modules.m:
    Use invoke_shell_command instead of invoke_system_command for shell
    scripts.

library/io.m:
    Call _unlink in io_rename_file, when compiling with MSVC.


runtime/mercury_wrapper.c:
    Initialise MR_runqueue_head so that the segment containing this
    variable is registered with the garbage collector.  This stops
    intermittent failures of the GC_is_visible() test.

runtime/mercury_conf.h.in:
    Define MR_WIN32 when we are using MSVC.

runtime/mercury_memory.c:
runtime/mercury_memory_handlers.c:
runtime/mercury_memory_zones.c:
runtime/mercury_prof.c:
runtime/mercury_reg_workarounds.c:
runtime/mercury_reg_workarounds.h:
runtime/mercury_signal.c:
runtime/mercury_timing.c:
runtime/mercury_timing.h:
runtime/mercury_trace_base.c:
util/mkinit.c:
    Only include unistd.h and sys/times.h when they exist.
    MSVC doesn't have SIGBUS so #ifdef sections which refer to it.

scripts/Mmake.rules:
    Use /Fo instead of -o to generate .o files if compiling with MSVC.

scripts/Mmake.vars.in:
    Define AR to use the autoconfed executable for linking.

scripts/mgnuc.in:
    Only add option -Wno-uninitialized if we are using gcc.

util/Mmakefile:
    Explicitly locate the getopt src, and use it in compiling the
    utilities.
2000-06-08 07:59:13 +00:00
Zoltan Somogyi
6447794de3 Remove unused variables and code identified by -Wunused.
Estimated hours taken: 0.2

runtime/mercury_memory_handlers.c:
runtime/mercury_memory_zones.c:
	Remove unused variables and code identified by -Wunused.
2000-03-09 07:27:46 +00:00
Tyson Dowd
09ad0c4f15 Port to Linux-m68k. A lot of this work was done by Roman Hodek,
Estimated hours taken: 20

Port to Linux-m68k.  A lot of this work was done by Roman Hodek,
<Roman.Hodek@informatik.uni-erlangen.de>.

README.Linux-m68k:
	Mention that we have a port to the 68k.

configure.in:
	Add a test for two different sorts of signal handlers
	  void handler(int signum, struct sigcontext_struct context)
	and
	  void handler(int signum, int code, struct sigcontext_struct context)
	Set HAVE_SIGCONTEXT_STRUCT_2ARG or HAVE_SIGCONTEXT_STRUCT_3ARG
	appropriately.

	Add support for shared libraries on the m68k as they should
	work.

	Make "working struct sigcontext" tests use MR_GET_FAULT_ADDR.

boehm_gc/config.h:
	Add some definitions for the m68k.

boehm_gc/os_dep.c:
	Get fault addresses using m68k specific code.

runtime/mercury_conf.h.in:
	Add new configuration definitions HAVE_SIGCONTEXT_STRUCT_2ARG,
	and HAVE_SIGCONTEXT_STRUCT_3ARG.

runtime/mercury_faultaddr.h:
	Add MR_GET_FAULT_ADDR.

runtime/mercury_goto.h:
	Add support for non-local gotos with Linux-68k.

runtime/mercury_memory_handlers.c:
	Handle 2 or 3 argument signal handlers.
1998-10-02 05:35:56 +00:00
Zoltan Somogyi
8ddce575d4 Introduce two new directories, trace and browser, containing libraries
Estimated hours taken: 10

Introduce two new directories, trace and browser, containing libraries
holding the C and Mercury code of the debugger respectively. (Although
the browser directory does not have a browser in it yet, the browser
should soon become its biggest component.) Take the opportunity to
rename the existing libraries, for consistency.

After this change, the linking order becomes:

	the object of the auto-generated init file
	program object files
	trace library (libmer_trace.a)
	browser library (libmer_browser.a)
	standard library (libmer_std.a)
	runtime library (libmer_rt.a)
	Boehm collector (libgc.a)

To avoid circularities, libraries cannot contain direct calls to
any routines that are defined in libraries (or object files) that
occur earlier in the above list.  Any such calls must be made into
indirect calls via function pointers.

In particular, there was a circularity caused by the library calling
MR_trace() which invokes the tracer which in turn invokes the
library.  This circularity was broken by having MR_trace(),
which is defined in the runtime, call the tracer indirectly via
a global variable named MR_trace_func_ptr.  This global variable
is initialized by the auto-generated *_init.c file.

To avoid linking in the tracer even when it is not being used,
this global variable is only set to point to MR_trace_real()
if you're using a debugging grade or if c2init was invoked
with the `-t' flag.  Otherwise it is set to MR_trace_fake()
which just prints an error message telling the user to
rebuild the executable with debugging enabled.

Makefile.DLLs:
	Reserve random locations for the two new libraries. Whether they work
	will be decided by testing on Windows.

Mmake.common.in:
	Add variables naming the new directories, and create variables
	naming the libraries.

Mmakefile:
	Add targets for the new directories, and modify existing rules
	as appropriate.

browser/Mmakefile:
	Mmakefile for the new directory, modelled on library/Mmakefile.

browser/browser_library.m:
	Umbrella file for the new directory, modelled on library/library.m.

{browser,library}/debugger_interface.m:
	Moved this file from library to browser without change.

browser/help.m:
	A new module for the help system of the debugger. Not yet used.

compiler/Mmakefile:
	Update to refer to the new directories and libraries where
	appropriate.

compiler/mercury_compile.m:
	If we are doing tracing, then pass -t instead of -i to c2init.

compiler/modules.m:
	When generating the .dep file, get the grade flags passed to c2init.

doc/Mmakefile:
	Remove the special treatment of library/debugger_interface.m.

library/Mmakefile:
	Update to refer to the new directories and libraries where
	appropriate, and to conform to the new name of the library.

library/library.m:
	Do not import debugger_interface.

profiler/Mmakefile:
	Update to refer to the new directories and libraries where
	appropriate.

runtime/Mmakefile:
	Update to refer to the new directories and libraries where
	appropriate, and to conform to the new name of the library.

	Remove references to files being moved to the trace directory.

runtime/mercury_init.h:
	Refer to the automatically generated dll header file by its new name
	(renamed because the runtime library is renamed).

	Add declarations to support the new global variable MR_trace_func_ptr.

runtime/mercury_memory_handlers.c:
runtime/mercury_memory_zones.c:
runtime/mercury_misc.c:
	Remove inappropriate #includes of "mercury_trace.h", and substitute
	a #include of "mercury_trace_base.h" if necessary.

{runtime,trace}/mercury_trace.[ch]:
{runtime,trace}/mercury_trace_external.[ch]:
{runtime,trace}/mercury_trace_internal.[ch]:
	Move these files from the runtime to the trace directory.

	The only changes are the removal from mercury_trace.h of declarations
	added to runtime/mercury_trace_base.h, and the change from MR_trace
	to MR_trace_real.

runtime/mercury_trace_base.[ch]:
	Define MR_trace(), which does an indirect call through
	MR_trace_func_ptr if the event should be traced.

	Define MR_trace_fake, which just prints an error message.
	Its address will be assigned to MR_trace_func_ptr if tracing
	is not enabled.

	Define the types needed by the signature of MR_trace.

	Fix an old bug: s/MERCURY_TRACE_PERMANENT_H/MERCURY_TRACE_BASE_H/.

runtime/mercury_wrapper.[ch]:
	Add the new global variable MR_trace_func_ptr.

scripts/c2init.in:
	Add a new option, -t/--trace, which enables tracing by causing the
	address of MR_trace_real to be assigned to MR_trace_func_ptr.

	Have this option be implied by the grade. Also have the old option
	-i (need initialization code) be implied by the grade, as well as by
	-t.

scripts/ml.in:
	Include the new libraries in the link command.

tests/debugger/Mmakefile:
	Include -t instead of -i in the list of c2init options. (-t implies
	-i.)

tools/bootcheck:
	Copy and build the new directories as appropriate. The trace directory
	is treated like the runtime, the browser directory is treated like the
	library.

trace/Mmakefile:
	Mmakefile for the new directory, modelled on runtime/Mmakefile.

util/mkinit.c:
	Add the new option -t, as discussed above.
	Mmakefile for the new directory, modelled on runtime/Mmakefile.

util/Mmakefile:
	Specify -O0, since with the default optimization level, gcc on
	cyclone ignores the assignment of TRUE to need_tracing when -t is
	given (!!!).
1998-09-29 05:12:06 +00:00
Zoltan Somogyi
5ea739d0bd Fix some bugs in tabling, to enable the boyer test case to work.
Estimated hours taken: 6

Fix some bugs in tabling, to enable the boyer test case to work.

runtime/mercury_tabling.h:
	Add a new set of macros that optionally print debugging info at
	tabling actions. Debugging recquires compilation with -DMR_TABLE_DEBUG
	and -dT in MERCURY_OPTIONS.

runtime/mercury_table_any.c:
	Use the debugging macros. Fix two bugs, one found with their help.
	One is that a tagged pointer to the table giving information about
	remote secondary tags did not have its tag stripped before use.
	The other is that the extraction of local secondary tags from words
	was done by subtracting the tag, and not by shifting out the tag,
	leaving the secondary tag value too high by a factor of 4 or 8.

runtime/mercury_table_any.[ch]:
runtime/mercury_table_enum.[ch]:
	Change the order of some function arguments to be consistent with
	the orders in the macros that call these functions.

runtime/mercury_table_enum.c:
	Add an optional sanity check that detects the second bug above.

runtime/mercury_engine.[ch]:
	Add a new debug flag, MR_tabledebug. Rename the flags so they always
	start with MR_.

runtime/mercury_wrapper.c:
	Allow -dT in MERCURY_OPTIONS to set MR_tabledebug.

runtime/*.[ch]:
	Trivial changes for the new names of the debug flags.

runtime/Mmakefile:
	Reimpose alphabetical order on the list of C files.

library/private_builtin.m:
	Use the new debugging macros in the C code that does tabling.

	Expose the equivalence between ml_table, ml_subgoal_table_node etc
	and c_pointer. The reason is

	% These equivalences should be local to private_builtin. However,
	% at the moment table_gen.m assumes that it can use a single variable
	% sometimes as an ml_table and other times as an ml_subgoal_table_node
	% (e.g. by giving the output of table_lookup_insert_int as input to
	% table_have_all_ans). The proper fix would be for table_gen.m to
	% use additional variables and insert unsafe casts. However, this
	% would require significant work for no real gain, so for now
	% we fix the problem by exposing the equivalences to code generated
	% by table_gen.m.

library/mercury_builtin.m:
	Delete the contents of this obsolete file, leaving only a pointer
	to builtin.m and private_builtin.m.

tests/tabling/Mmakefile:
	Enable the boyer benchmark, since we now pass it.
1998-08-24 08:24:58 +00:00
Tyson Dowd
c7d6b89566 Fix a bug in get_pc_from_context that was causing compile
Estimated hours taken: 0.5

Fix a bug in get_pc_from_context that was causing compile
errors on IRIX and Solaris.

runtime/mercury_memory_handlers.c:
	Fix a bug in get_pc_from_context -- it wasn't using the correct
	type (ucontext_t) for the context.
1998-07-26 11:32:04 +00:00
Tyson Dowd
c8ba3551ea 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:53:35 +00:00
Fergus Henderson
2f0454447d Fix some problems that caused compilation errors when compiling with
Estimated hours taken: 3

Fix some problems that caused compilation errors when compiling with
C compilers other than gcc.

runtime/mercury_engine.c:
runtime/mercury_ho_call.c:
runtime/mercury_memory_handlers.c:
runtime/mercury_signal.c:
runtime/mercury_table_builtins.c:
	Add casts to fix various type errors.

runtime/mercury_heap.h:
	Add LVALUE_CAST()s in hp_alloc() and hp_alloc_atomic()
	to cast MR_hp to Word when calling incr_hp() and incr_hp_atomic().

runtime/mercury_ho_call.c:
runtime/mercury_wrapper.c:
runtime/mercury_engine.c:
runtime/mercury_type_info.c:
runtime/mercury_wrapper.c:
	Delete extraneous semicolons after occurrences
	of the MR_MAKE_STACK_LAYOUT_* macros.

runtime/mercury_tabling.h:
	Delete extraneous semicolons in the definitions of the
	table_allocate(), table_reallocate(), and table_free() macros.
	Use <stdarg.h> instead of <varargs.h> and add missing call
	to va_end().

runtime/mercury_goto.h:
	Change the ANSI C versions of the ENTRY(), STATIC(), LOCAL(),
	and LABEL() macros to cast their results to type `Code *'.
	The reason is that although the `Code *' type is actually `void *',
	there is no implicit conversion from pointer to function
	to pointer to void in ANSI C.

runtime/mercury_tabling.h:

runtime/mercury_context.h:
runtime/mercury_context.c:
	`free_context_list' was declared extern in the header file
	but also declared static in the `.c' file, so I deleted
	the declaration in the header file, and moved the comment
	there into the `.c' file.

runtime/mercury_deep_copy.c:
	Add a missing `static' on the declaration of deep_copy_type_info().

runtime/mercury_trace_external.c:
	Avoid unterminated string literals even inside `#if 0 ... #endif'.

runtime/mercury_types.h:
	Minor changes to a couple of comments.
1998-07-13 22:44:15 +00:00
Tyson Dowd
cd3914c609 More cleanup of the memory management code.
Estimated hours taken: 5

More cleanup of the memory management code.
This time we clean up the signal handler setup code.

runtime/Mmakefile:
	Add new files.

runtime/mercury_memory.c:
	Rename setup_signal() to setup_signals().

runtime/mercury_memory_handlers.c:
runtime/mercury_memory_handlers.h:
	Clean up signal handling.
	Use MR_setup_signal to setup signal handlers.
	Define bus_handler and segv_handler signal handlers, the
	old signal handlers are just one or the other (or both).

runtime/mercury_prof.c:
	Use MR_setup_signal to setup signal handler.

runtime/mercury_signal.c:
runtime/mercury_signal.h:
	New files -- a standard interface for setting up signal
	handlers (a porting base, if you like).
1998-05-14 06:35:16 +00:00
Tyson Dowd
aa641c6121 Clean up memory management code. This mostly involves cleaning up
Estimated hours taken: 5

Clean up memory management code.  This mostly involves cleaning up
the #defines and removing duplicate code.  This is just an incremental
improvement, more changes are expected.

runtime/mercury_conf_param.h:
	Add definitions for MR_CAN_GET_PC_AT_SIGNAL and
	MR_CHECK_OVERFLOW_VIA_MPROTECT.

runtime/mercury_context.c:
	Rename reset_zone() as reset_redzone().

runtime/mercury_memory_handlers.c:
	Define one set of functions with conditional bodies, rather
	than conditional defintions of functions.

runtime/mercury_memory_zones.c:
	Use MR_CHECK_OVERFLOW_VIA_MPROTECT rather than just looking
	for HAVE_MPROTECT and HAVE_SIGINFO.

runtime/mercury_memory_zones.h:
	Only use redzones with MR_CHECK_OVERFLOW_VIA_MPROTECT.

	Correct a comment about how much memory is should be
	given to construct_zone.
	The correct caculation is
		size + unit (for offset) + unit (for hardmax)

	Rename reset_zone as reset_redzone.
1998-05-11 08:23:26 +00:00
Tyson Dowd
917c158436 Split mercury_memory.{c,h} into several files.
Estimated hours taken: 5

Split mercury_memory.{c,h} into several files.  Added a few
comments about functions whose declarations have been moved into
the header files, otherwise the content is unchanged.

runtime/Mmakefile:
	Add new files.

runtime/mercury_context.c:
	Add a #include "mercury_memory_handlers.h" as this module
	creates new zones using default_handler.

runtime/mercury_memory.c:
runtime/mercury_memory.h:
	Other code (mostly code to set up the actual memory
	zones we use in the Mercury runtime).

runtime/mercury_memory_handlers.c:
runtime/mercury_memory_handlers.h:
	Signal handlers for memory access violations.

runtime/mercury_memory_zones.c:
runtime/mercury_memory_zones.h:
	The implementation MemoryZone data type.
1998-05-08 02:53:41 +00:00