X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Frts%2FMBlock.c;h=0ca384bbe6e49d5622a05fb19b2aff8de9adb2f3;hb=9428b42b8e4b21493055b54f176cffa0a5b879b6;hp=3c7fcaf41a589510d27702a01428ff209474dc08;hpb=9ac55e08e159d7a4647ab01e7872e69dd762f275;p=ghc-hetmet.git diff --git a/ghc/rts/MBlock.c b/ghc/rts/MBlock.c index 3c7fcaf..0ca384b 100644 --- a/ghc/rts/MBlock.c +++ b/ghc/rts/MBlock.c @@ -1,5 +1,5 @@ /* ----------------------------------------------------------------------------- - * $Id: MBlock.c,v 1.19 2000/12/04 12:31:21 simonmar Exp $ + * $Id: MBlock.c,v 1.25 2001/12/10 01:28:00 sebc Exp $ * * (c) The GHC Team 1998-1999 * @@ -9,7 +9,8 @@ * * ---------------------------------------------------------------------------*/ -#define NON_POSIX_SOURCE +/* This is non-posix compliant. */ +/* #include "PosixSource.h" */ #include "Rts.h" #include "RtsUtils.h" @@ -65,6 +66,9 @@ getMBlocks(nat n) #elif hpux_TARGET_OS ret = mmap(next_request, size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); +#elif darwin_TARGET_OS + ret = mmap(next_request, size, PROT_READ | PROT_WRITE, + MAP_FIXED | MAP_ANON | MAP_PRIVATE, -1, 0); #else ret = mmap(next_request, size, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0); @@ -79,10 +83,10 @@ getMBlocks(nat n) } if (((W_)ret & MBLOCK_MASK) != 0) { - barf("GetMBlock: misaligned block returned"); + barf("GetMBlock: misaligned block %p returned when allocating %d megablock(s) at %p", ret, n, next_request); } - IF_DEBUG(gc,fprintf(stderr,"Allocated %d megablock(s) at %x\n",n,(nat)ret)); + IF_DEBUG(gc,fprintf(stderr,"Allocated %d megablock(s) at %p\n",n,ret)); next_request += size; @@ -111,8 +115,8 @@ getMBlocks(nat n) char* base_non_committed = (char*)0; -/* Reserve VM 128M at the time to try to minimise the slop cost. */ -#define SIZE_RESERVED_POOL ( 128 * 1024 * 1024 ) +/* Reserve VM 256M at the time to try to minimise the slop cost. */ +#define SIZE_RESERVED_POOL ( 256 * 1024 * 1024 ) /* This predicate should be inlined, really. */ /* TODO: this only works for a single chunk */ @@ -134,32 +138,26 @@ getMBlocks(nat n) if ( (base_non_committed == 0) || (next_request + size > base_non_committed + SIZE_RESERVED_POOL) ) { -#ifdef ENABLE_WIN32_DLL_SUPPORT if (base_non_committed) - barf("Windows programs can only use 128Mb of heap; sorry!"); -#endif + barf("Windows programs can only use 256Mb of heap; sorry!"); base_non_committed = VirtualAlloc ( NULL , SIZE_RESERVED_POOL , MEM_RESERVE , PAGE_READWRITE ); if ( base_non_committed == 0 ) { -# if 1 /*def DEBUG*/ - fprintf(stderr, "getMBlocks: VirtualAlloc failed with: %d\n", GetLastError()); -# endif + fprintf(stderr, "getMBlocks: VirtualAlloc failed with: %ld\n", GetLastError()); ret=(void*)-1; } else { /* The returned pointer is not aligned on a mega-block boundary. Make it. */ base_mblocks = (char*)((unsigned long)base_non_committed & (unsigned long)0xfff00000) + MBLOCK_SIZE; -# if 0 - fprintf(stderr, "Dropping %d bytes off of 128M chunk\n", +# if 0 + fprintf(stderr, "getMBlocks: Dropping %d bytes off of 256M chunk\n", (unsigned)base_mblocks - (unsigned)base_non_committed); -# endif +# endif if ( ((char*)base_mblocks + size) > ((char*)base_non_committed + SIZE_RESERVED_POOL) ) { -# if 1 /*def DEBUG*/ - fprintf(stderr, "oops, committed too small a region to start with."); -# endif + fprintf(stderr, "getMBlocks: oops, committed too small a region to start with."); ret=(void*)-1; } else { next_request = base_mblocks; @@ -170,19 +168,20 @@ getMBlocks(nat n) if ( ret != (void*)-1 ) { ret = VirtualAlloc(next_request, size, MEM_COMMIT, PAGE_READWRITE); if (ret == NULL) { -# if 1 /*def DEBUG*/ - fprintf(stderr, "getMBlocks: VirtualAlloc failed with: %d\n", GetLastError()); -# endif + fprintf(stderr, "getMBlocks: VirtualAlloc failed with: %ld\n", GetLastError()); ret=(void*)-1; } } if (((W_)ret & MBLOCK_MASK) != 0) { - barf("GetMBlock: misaligned block returned"); + barf("getMBlocks: misaligned block returned"); } - IF_DEBUG(gc,fprintf(stderr,"Allocated %d megablock(s) at %x\n",n,(nat)ret)); + if (ret == (void*)-1) { + barf("getMBlocks: unknown memory allocation failure on Win32."); + } + IF_DEBUG(gc,fprintf(stderr,"Allocated %d megablock(s) at 0x%x\n",n,(nat)ret)); next_request = (char*)next_request + size; mblocks_allocated += n; @@ -205,9 +204,9 @@ freeMBlock(void* p, nat n) rc = VirtualFree(p, n * MBLOCK_SIZE , MEM_DECOMMIT ); if (rc == FALSE) { -# ifdef DEBUG +# ifdef DEBUG fprintf(stderr, "freeMBlocks: VirtualFree failed with: %d\n", GetLastError()); -# endif +# endif } }