/* -----------------------------------------------------------------------------
- * $Id: Storage.c,v 1.63 2002/04/25 04:54:55 sof Exp $
+ * $Id: Storage.c,v 1.69 2002/10/15 11:02:32 simonmar Exp $
*
* (c) The GHC Team, 1998-1999
*
#include "RetainerProfile.h" // for counting memory blocks (memInventory)
+#include <stdlib.h>
+#include <string.h>
+
#ifdef darwin_TARGET_OS
#include <mach-o/getsect.h>
unsigned long macho_etext = 0;
StgClosure *caf_list = NULL;
bdescr *small_alloc_list; /* allocate()d small objects */
-bdescr *large_alloc_list; /* allocate()d large objects */
bdescr *pinned_object_block; /* allocate pinned objects into this block */
nat alloc_blocks; /* number of allocate()d blocks since GC */
nat alloc_blocks_lim; /* approximate limit on alloc_blocks */
/* initialise the allocate() interface */
small_alloc_list = NULL;
- large_alloc_list = NULL;
alloc_blocks = 0;
alloc_blocks_lim = RtsFlags.GcFlags.minAllocAreaSize;
lnat
allocated_bytes( void )
{
- return (alloc_blocks * BLOCK_SIZE_W - (alloc_HpLim - alloc_Hp));
+ lnat allocated;
+
+ allocated = alloc_blocks * BLOCK_SIZE_W - (alloc_HpLim - alloc_Hp);
+ if (pinned_object_block != NULL) {
+ allocated -= (pinned_object_block->start + BLOCK_SIZE_W) -
+ pinned_object_block->free;
+ }
+
+ return allocated;
}
/* ---------------------------------------------------------------------------
// we always return 8-byte aligned memory. bd->free must be
// 8-byte aligned to begin with, so we just round up n to
// the nearest multiple of 8 bytes.
- ASSERT(((StgWord)bd->free & 7) == 0);
- n = (n+7) & ~7;
+ if (sizeof(StgWord) == 4) {
+ n = (n+1) & ~1;
+ }
// If we don't have a block of pinned objects yet, or the current
// one isn't large enough to hold the new object, allocate a new one.
StgArrWords* arr;
nat data_size_in_words, total_size_in_words;
- /* should be a multiple of sizeof(StgWord) (whole no. of limbs) */
- ASSERT(size_in_bytes % sizeof(W_) == 0);
-
- data_size_in_words = size_in_bytes / sizeof(W_);
+ /* round up to a whole number of words */
+ data_size_in_words = (size_in_bytes + sizeof(W_) + 1) / sizeof(W_);
total_size_in_words = sizeofW(StgArrWords) + data_size_in_words;
/* allocate and fill it in. */
for (bd = small_alloc_list; bd; bd = bd->link) {
total_blocks += bd->blocks;
}
- for (bd = large_alloc_list; bd; bd = bd->link) {
- total_blocks += bd->blocks;
- }
#ifdef PROFILING
if (RtsFlags.ProfFlags.doHeapProfile == HEAP_BY_RETAINER) {