diff: fix bug with memory profiling and interactive queries
Fergus Henderson
fjh at cs.mu.OZ.AU
Thu Apr 1 17:58:23 AEST 1999
It turns out that the following additional fix is needed.
--------------------
Estimated hours taken: 0.25
runtime/mercury_prof_mem.h:
runtime/mercury_prof_mem.c:
Change MR_prof_malloc() to ensure that the memory that it
allocates will be Word-aligned. This change is needed
as a result of my previous change to mercury_heap_profile.c
which made it allocate strings using MR_prof_malloc().
Index: runtime/mercury_prof_mem.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_prof_mem.c,v
retrieving revision 1.3
diff -u -r1.3 mercury_prof_mem.c
--- mercury_prof_mem.c 1997/12/05 15:56:45 1.3
+++ mercury_prof_mem.c 1999/04/01 07:48:44
@@ -22,6 +22,7 @@
#include "mercury_prof_mem.h"
#include "mercury_std.h" /* for newmem() */
+#include "mercury_types.h" /* for Word */
/*----------------------------------------------------------------------------*/
@@ -53,6 +54,18 @@
MR_prof_malloc(size_t size)
{
register void *p;
+
+ /*
+ ** Ensure all allocations are word-aligned, by rounding size
+ ** up to the nearest multiple of the word size.
+ **
+ ** Note that the current implementation of MR_prof_malloc only
+ ** guarantees that the memory will be Word-aligned; if you want to
+ ** allocate types that contain data types (e.g. `double') which might
+ ** require stricter alignment than that, then you will need to
+ ** change this to round the size up accordingly.
+ */
+ size = (size + sizeof(Word) - 1) / sizeof(Word);
/* Here we waste a bit of space but hopefully not to much */
if (mem_left < size) {
Index: runtime/mercury_prof_mem.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_prof_mem.h,v
retrieving revision 1.3
diff -u -r1.3 mercury_prof_mem.h
--- mercury_prof_mem.h 1997/12/05 15:56:46 1.3
+++ mercury_prof_mem.h 1999/04/01 06:02:07
@@ -17,11 +17,17 @@
#include <stddef.h> /* for size_t */
/*
-** prof_malloc() allocates memory in large chunks using newmem(),
+** MR_prof_malloc() allocates memory in large chunks using newmem(),
** and then doles out portions of these chunks one at a time.
** We use prof_malloc() to reduce the chance of calling newmem()
** from a profiling interrupt that interrupted another call to newmem().
** Doing that is bad news, because newmem() is not re-entrant.
+**
+** Note that the current implementation of MR_prof_malloc only guarantees
+** that the memory will be Word-aligned; if you want to allocate types
+** that contain data types (e.g. `double') which might require stricter
+** alignment than that, then you will need to change the implementation of
+** MR_prof_malloc().
*/
extern void *MR_prof_malloc(size_t);
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3 | -- the last words of T. S. Garp.
More information about the developers
mailing list