/* toolbox/memory.c -
- Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
- R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser,
- M. Probst, S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck,
- P. Tomsich, J. Wenninger
+ Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
+ R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
+ C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
+ Institut f. Computersprachen - TU Wien
This file is part of CACAO.
Authors: Reinhard Grafl
- $Id: memory.c 1437 2004-11-05 09:51:07Z twisti $
+ $Id: memory.c 1735 2004-12-07 14:33:27Z twisti $
*/
#include <stdio.h>
#include <stdlib.h>
-#include <assert.h>
#include <string.h>
+
+#if defined(__DARWIN__)
+/* If we compile with -ansi on darwin, <sys/types.h> is not included. So */
+/* let's do it here. */
+# include <sys/types.h>
+#endif
+
#include <sys/mman.h>
#include <unistd.h>
-#include "exceptions.h"
-#include "global.h"
-#include "native.h"
-#include "options.h"
-#include "statistics.h"
-#include "threads/nativethread.h"
+#include "config.h"
+#include "mm/memory.h"
+#include "vm/exceptions.h"
+#include "vm/global.h"
+#include "vm/options.h"
+#include "vm/statistics.h"
+#include "native/native.h"
+
+#if defined(USE_THREADS)
+# if defined(NATIVE_THREADS)
+# include "threads/native/threads.h"
+# else
+# include "threads/green/threads.h"
+# endif
+#endif
+
#include "toolbox/logging.h"
-#include "toolbox/memory.h"
/********* general types, variables and auxiliary functions *********/
*******************************************************************************/
-#if !defined(USE_THREADS)
+#if !defined(USE_THREADS) || (defined(USE_THREADS) && !defined(NATIVE_THREADS))
static dumpinfo nothreads_dumpinfo;
#endif
-void *mem_mmap(int size)
+void *mem_mmap(s4 size)
{
void *m;
mmapcodeptr = mmap(NULL,
(size_t) mmapcodesize,
PROT_READ | PROT_WRITE | PROT_EXEC,
- MAP_PRIVATE | MAP_ANONYMOUS,
+ MAP_PRIVATE |
+#if defined(HAVE_MAP_ANONYMOUS)
+ MAP_ANONYMOUS,
+#elif defined(HAVE_MAP_ANON)
+ MAP_ANON,
+#else
+ 0,
+#endif
-1,
(off_t) 0);
}
-static void *checked_alloc(int size)
+static void *checked_alloc(s4 size)
{
/* always allocate memory zeroed out */
void *m = calloc(size, 1);
}
-void *mem_alloc(int size)
+void *mem_alloc(s4 size)
{
if (size == 0)
return NULL;
}
-void *mem_realloc(void *src, int len1, int len2)
+void *mem_realloc(void *src, s4 len1, s4 len2)
{
void *dst;
}
-void mem_free(void *m, int size)
+void mem_free(void *m, s4 size)
{
if (!m) {
if (size == 0)
}
-void *dump_alloc(int size)
+void *dump_alloc(s4 size)
{
void *m;
dumpinfo *di;
/* If no threads are used, the dumpinfo structure is a static structure */
/* defined at the top of this file. */
-#if defined(USE_THREADS)
+#if defined(USE_THREADS) && defined(NATIVE_THREADS)
di = &((threadobject *) THREADOBJECT)->dumpinfo;
#else
di = ¬hreads_dumpinfo;
}
/* allocate dumpblock memory */
- //printf("new dumpblock: %d\n", newdumpblocksize);
+ /*printf("new dumpblock: %d\n", newdumpblocksize);*/
newdumpblock->dumpmem = checked_alloc(newdumpblocksize);
newdumpblock->prev = di->currentdumpblock;
/* Used dump size is previously allocated dump size, because the */
/* remaining free memory of the previous dump block cannot be used. */
- //printf("unused memory: %d\n", allocateddumpsize - useddumpsize);
+ /*printf("unused memory: %d\n", allocateddumpsize - useddumpsize);*/
di->useddumpsize = di->allocateddumpsize;
/* increase the allocated dump size by the size of the new dump block */
}
-void *dump_realloc(void *src, int len1, int len2)
+void *dump_realloc(void *src, s4 len1, s4 len2)
{
void *dst = dump_alloc(len2);
}
-void dump_release(int size)
+void dump_release(s4 size)
{
dumpinfo *di;
/* If no threads are used, the dumpinfo structure is a static structure */
/* defined at the top of this file. */
-#if defined(USE_THREADS)
+#if defined(USE_THREADS) && defined(NATIVE_THREADS)
di = &((threadobject *) THREADOBJECT)->dumpinfo;
#else
di = ¬hreads_dumpinfo;
}
-long dump_size()
+s4 dump_size()
{
dumpinfo *di;
/* If no threads are used, the dumpinfo structure is a static structure */
/* defined at the top of this file. */
-#if defined(USE_THREADS)
+#if defined(USE_THREADS) && defined(NATIVE_THREADS)
di = &((threadobject *) THREADOBJECT)->dumpinfo;
#else
di = ¬hreads_dumpinfo;
#endif
+ if (!di)
+ return 0;
+
return di->useddumpsize;
}