From 73637ad66b7f88e57dcd0e0ea93b3d7bf8fb0d78 Mon Sep 17 00:00:00 2001 From: Simon Marlow Date: Wed, 27 Jun 2007 09:36:46 +0000 Subject: [PATCH] +RTS -xbXXXXX sets the "heap base" to 0xXXXXXX When debugging the GC and storage manager we often want repeated runs of the program to allocate memory at the same addresses, so that we can set watch points. Unfortunately the OS doesn't always give us memory at predictable addresses. This flag gives the OS a hint as to where we would like our memory allocated. Previously I did this by changing the HEAP_BASE setting in MBlock.h and recompiling, this patch just adds a flag so I don't have to recompile. --- includes/RtsFlags.h | 2 ++ rts/RtsFlags.c | 22 ++++++++++++++++++++++ rts/sm/MBlock.c | 13 ++++++++++++- rts/sm/MBlock.h | 17 +---------------- rts/sm/Storage.c | 2 ++ 5 files changed, 39 insertions(+), 17 deletions(-) diff --git a/includes/RtsFlags.h b/includes/RtsFlags.h index 4bfe276..88a6346 100644 --- a/includes/RtsFlags.h +++ b/includes/RtsFlags.h @@ -43,6 +43,8 @@ struct GC_FLAGS { rtsBool frontpanel; int idleGCDelayTime; /* in milliseconds */ + + StgWord heapBase; /* address to ask the OS for memory */ }; struct DEBUG_FLAGS { diff --git a/rts/RtsFlags.c b/rts/RtsFlags.c index 47ad794..0ab1399 100644 --- a/rts/RtsFlags.c +++ b/rts/RtsFlags.c @@ -150,6 +150,18 @@ void initRtsFlagsDefaults(void) #endif RtsFlags.GcFlags.idleGCDelayTime = 300; /* millisecs */ +#if osf3_HOST_OS +/* ToDo: Perhaps by adjusting this value we can make linking without + * -static work (i.e., not generate a core-dumping executable)? */ +# if SIZEOF_VOID_P == 8 + RtsFlags.GcFlags.heapBase = 0x180000000L; +# else +# error I have no idea where to begin the heap on a non-64-bit osf3 machine. +# endif +#else + RtsFlags.GcFlags.heapBase = 0; /* means don't care */ +#endif + #ifdef DEBUG RtsFlags.DebugFlags.scheduler = rtsFalse; RtsFlags.DebugFlags.interpreter = rtsFalse; @@ -1192,6 +1204,16 @@ error = rtsTrue; error = rtsTrue; break; + case 'b': /* heapBase in hex; undocumented */ + if (rts_argv[arg][3] != '\0') { + RtsFlags.GcFlags.heapBase + = strtol(rts_argv[arg]+3, (char **) NULL, 16); + } else { + errorBelch("-xb: requires argument"); + error = rtsTrue; + } + break; + case 'c': /* Debugging tool: show current cost centre on an exception */ PROFILING_BUILD_ONLY( RtsFlags.ProfFlags.showCCSOnException = rtsTrue; diff --git a/rts/sm/MBlock.c b/rts/sm/MBlock.c index 85fe02d..601387c 100644 --- a/rts/sm/MBlock.c +++ b/rts/sm/MBlock.c @@ -49,6 +49,18 @@ lnat mblocks_allocated = 0; +#if !defined(mingw32_HOST_OS) && !defined(cygwin32_HOST_OS) +static caddr_t next_request = 0; +#endif + +void +initMBlocks(void) +{ +#if !defined(mingw32_HOST_OS) && !defined(cygwin32_HOST_OS) + next_request = (caddr_t)RtsFlags.GcFlags.heapBase; +#endif +} + /* ----------------------------------------------------------------------------- The MBlock Map: provides our implementation of HEAP_ALLOCED() -------------------------------------------------------------------------- */ @@ -258,7 +270,6 @@ gen_map_mblocks (lnat size) void * getMBlocks(nat n) { - static caddr_t next_request = (caddr_t)HEAP_BASE; caddr_t ret; lnat size = MBLOCK_SIZE * n; nat i; diff --git a/rts/sm/MBlock.h b/rts/sm/MBlock.h index 1cc0dc5..ecce6f8 100644 --- a/rts/sm/MBlock.h +++ b/rts/sm/MBlock.h @@ -11,26 +11,11 @@ extern lnat RTS_VAR(mblocks_allocated); +extern void initMBlocks(void); extern void * getMBlock(void); extern void * getMBlocks(nat n); extern void freeAllMBlocks(void); -#if osf3_HOST_OS -/* ToDo: Perhaps by adjusting this value we can make linking without - * -static work (i.e., not generate a core-dumping executable)? */ -#if SIZEOF_VOID_P == 8 -#define HEAP_BASE 0x180000000L -#else -#error I have no idea where to begin the heap on a non-64-bit osf3 machine. -#endif - -#else - -// we're using the generic method -#define HEAP_BASE 0 - -#endif - /* ----------------------------------------------------------------------------- The HEAP_ALLOCED() test. diff --git a/rts/sm/Storage.c b/rts/sm/Storage.c index 097c727..f9e32f2 100644 --- a/rts/sm/Storage.c +++ b/rts/sm/Storage.c @@ -115,6 +115,8 @@ initStorage( void ) return; } + initMBlocks(); + /* Sanity check to make sure the LOOKS_LIKE_ macros appear to be * doing something reasonable. */ -- 1.7.10.4