* src/mm/dumpmemory.c: Moved to .cpp.
authorChristian Thalinger <twisti@complang.tuwien.ac.at>
Fri, 22 Aug 2008 13:03:19 +0000 (15:03 +0200)
committerChristian Thalinger <twisti@complang.tuwien.ac.at>
Fri, 22 Aug 2008 13:03:19 +0000 (15:03 +0200)
* src/mm/dumpmemory.h: Likewise.
* src/mm/dumpmemory.cpp: New file.
* src/mm/dumpmemory.hpp: Likewise.
* src/mm/Makefile.am,
src/mm/memory.h,
src/mm/tlh.h,
src/native/llni.h,
src/native/native.c,
src/native/vm/gnuclasspath/java_lang_VMRuntime.cpp,
src/threads/posix/lock.h,
src/threads/posix/thread-posix.cpp,
src/threads/posix/thread-posix.hpp,
src/threads/thread.cpp,
src/threads/thread.hpp,
src/toolbox/bitvector.c,
src/toolbox/list.c,
src/toolbox/list.h,
src/toolbox/set.c,
src/vm/exceptions.hpp,
src/vm/jit/builtin.cpp,
src/vm/jit/code.h,
src/vm/jit/jit.cpp,
src/vm/jit/optimizing/bytecode_escape.c,
src/vm/jit/optimizing/dominators.cpp,
src/vm/jit/optimizing/dominators.hpp,
src/vm/jit/optimizing/ssa3.c,
src/vm/jit/replace.cpp,
src/vm/jit/show.c,
src/vm/jit/stacktrace.hpp,
src/vm/jit/stubs.cpp,
src/vm/jit/trace.cpp,
src/vm/loader.cpp,
src/vm/resolve.h,
src/vm/vm.cpp: Include changes and a lot of dump memory changes.

--HG--
rename : src/mm/dumpmemory.c => src/mm/dumpmemory.cpp
rename : src/mm/dumpmemory.h => src/mm/dumpmemory.hpp

35 files changed:
src/mm/Makefile.am
src/mm/dumpmemory.c [deleted file]
src/mm/dumpmemory.cpp [new file with mode: 0644]
src/mm/dumpmemory.h [deleted file]
src/mm/dumpmemory.hpp [new file with mode: 0644]
src/mm/memory.h
src/mm/tlh.h
src/native/llni.h
src/native/native.c
src/native/vm/gnuclasspath/java_lang_VMRuntime.cpp
src/threads/posix/lock.h
src/threads/posix/thread-posix.cpp
src/threads/posix/thread-posix.hpp
src/threads/thread.cpp
src/threads/thread.hpp
src/toolbox/bitvector.c
src/toolbox/list.c
src/toolbox/list.h
src/toolbox/set.c
src/vm/exceptions.hpp
src/vm/jit/builtin.cpp
src/vm/jit/code.h
src/vm/jit/jit.cpp
src/vm/jit/optimizing/bytecode_escape.c
src/vm/jit/optimizing/dominators.cpp
src/vm/jit/optimizing/dominators.hpp
src/vm/jit/optimizing/ssa3.c
src/vm/jit/replace.cpp
src/vm/jit/show.c
src/vm/jit/stacktrace.hpp
src/vm/jit/stubs.cpp
src/vm/jit/trace.cpp
src/vm/loader.cpp
src/vm/resolve.h
src/vm/vm.cpp

index 203d919442b844119de43cc4ea731f9e745c9938..78ba758a196f5adfac2e806460f21703cdb2482e 100644 (file)
@@ -59,8 +59,8 @@ noinst_LTLIBRARIES = \
 libmm_la_SOURCES = \
        codememory.c \
        codememory.h \
-       dumpmemory.c \
-       dumpmemory.h \
+       dumpmemory.cpp \
+       dumpmemory.hpp \
        $(GC_FILE) \
        gc.hpp \
        memory.c \
diff --git a/src/mm/dumpmemory.c b/src/mm/dumpmemory.c
deleted file mode 100644 (file)
index 943a9c6..0000000
+++ /dev/null
@@ -1,481 +0,0 @@
-/* src/mm/dumpmemory.c - dump memory management
-
-   Copyright (C) 1996-2005, 2006, 2007, 2008
-   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
-
-   This file is part of CACAO.
-
-   This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 2, or (at
-   your option) any later version.
-
-   This program is distributed in the hope that it will be useful, but
-   WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-   02110-1301, USA.
-
-*/
-
-
-#include "config.h"
-
-#include <stdint.h>
-
-#include "mm/dumpmemory.h"
-#include "mm/memory.h"
-
-#include "threads/thread.hpp"
-
-#include "vm/options.h"
-#include "vm/os.hpp"
-
-#if defined(ENABLE_STATISTICS)
-# include "vm/statistics.h"
-#endif
-
-#include "vm/vm.hpp"
-
-
-/*******************************************************************************
-
-  This structure is used for dump memory allocation if cacao
-  runs without threads.
-
-*******************************************************************************/
-
-#if !defined(ENABLE_THREADS)
-static dumpinfo_t _no_threads_dumpinfo;
-#endif
-
-#if defined(ENABLE_THREADS)
-#define DUMPINFO    &((threadobject *) THREADOBJECT)->dumpinfo
-#else
-#define DUMPINFO    &_no_threads_dumpinfo
-#endif
-
-
-/* dump_check_canaries *********************************************************
-
-   Check canaries in dump memory.
-
-   IN:
-      di...........dumpinfo_t * of the dump area to check
-         bottomsize...dump size down to which the dump area should be checked
-                      (specify 0 to check the whole dump area)
-
-   ERROR HANDLING:
-      If any canary has been changed, this function aborts the VM with
-         an error message.
-
-*******************************************************************************/
-
-#if defined(ENABLE_MEMCHECK)
-static void dump_check_canaries(dumpinfo_t *di, s4 bottomsize)
-{
-       dump_allocation_t *da;
-       uint8_t           *pm;
-       int                i, j;
-
-       /* iterate over all dump memory allocations above bottomsize */
-
-       da = di->allocations;
-
-       while (da && da->used >= bottomsize) {
-               /* check canaries */
-
-               pm = ((uint8_t *) da->mem) - MEMORY_CANARY_SIZE;
-
-               for (i = 0; i < MEMORY_CANARY_SIZE; ++i) {
-                       if (pm[i] != i + MEMORY_CANARY_FIRST_BYTE) {
-                               fprintf(stderr, "canary bytes:");
-
-                               for (j = 0; j < MEMORY_CANARY_SIZE; ++j)
-                                       fprintf(stderr, " %02x", pm[j]);
-
-                               fprintf(stderr,"\n");
-
-                               vm_abort("error: dump memory bottom canary killed: "
-                                                "%p (%d bytes allocated at %p)\n",
-                                                pm + i, da->size, da->mem);
-                       }
-               }
-
-               pm = ((uint8_t *) da->mem) + da->size;
-
-               for (i = 0; i < MEMORY_CANARY_SIZE; ++i) {
-                       if (pm[i] != i + MEMORY_CANARY_FIRST_BYTE) {
-                               fprintf(stderr, "canary bytes:");
-
-                               for (j = 0; j < MEMORY_CANARY_SIZE; ++j)
-                                       fprintf(stderr, " %02x", pm[j]);
-
-                               fprintf(stderr, "\n");
-
-                               vm_abort("error: dump memory top canary killed: "
-                                                "%p (%d bytes allocated at %p)\n",
-                                                pm + i, da->size, da->mem);
-                       }
-               }
-
-               da = da->next;
-       }
-}
-#endif /* defined(ENABLE_MEMCHECK) */
-
-
-/* dumpmemory_alloc ************************************************************
-
-   ATTENTION: This function must only be called from dumpmemory_get!
-
-   Allocate a new dump memory block.
-
-   IN:
-      di ..... dumpinfo_t of the current thread
-      size ... required memory size
-
-*******************************************************************************/
-
-void dumpmemory_alloc(dumpinfo_t *di, size_t size)
-{
-       dumpblock_t *db;
-       size_t       newblocksize;
-
-       /* Allocate a new dumpblock_t structure. */
-
-       db = memory_checked_alloc(sizeof(dumpblock_t));
-
-       /* If requested size is greater than the default, make the new
-          dump block as big as the size requested. Else use the default
-          size. */
-
-       if (size > DUMPBLOCKSIZE) {
-               newblocksize = size;
-       }
-       else {
-               newblocksize = DUMPBLOCKSIZE;
-       }
-
-       /* allocate dumpblock memory */
-
-       db->dumpmem = memory_checked_alloc(newblocksize);
-
-       db->size  = newblocksize;
-       db->prev  = di->block;
-       di->block = db;
-
-       /* Used dump size is previously allocated dump size, because the
-          remaining free memory of the previous dump block cannot be
-          used. */
-
-       di->used = di->allocated;
-
-       /* Increase the allocated dump size by the size of the new dump
-          block. */
-
-       di->allocated += newblocksize;
-
-#if defined(ENABLE_STATISTICS)
-       /* The amount of globally allocated dump memory (thread save). */
-
-       if (opt_stat)
-               globalallocateddumpsize += newblocksize;
-#endif
-}
-
-
-/* dumpmemory_get **************************************************************
-
-   Allocate memory in the dump area.
-
-   IN:
-      size.........size of block to allocate, in bytes
-                                  may be zero, in which case NULL is returned
-
-   RETURN VALUE:
-      pointer to allocated memory, or
-         NULL iff `size` was zero
-
-   ERROR HANDLING:
-      XXX This function uses `memory_checked_alloc`, which *exits* if
-         no memory could be allocated.
-
-   THREADS:
-      dumpmemory_get is thread safe. Each thread has its own dump
-      memory area.
-
-   This function is a fast allocator suitable for scratch memory that
-   can be collectively freed when the current activity (eg. compiling)
-   is done.
-
-   You cannot selectively free dump memory. Before you start
-   allocating it, you remember the current size returned by
-   `dumpmemory_marker`. Later, when you no longer need the memory,
-   call `dumpmemory_release` with the remembered size and all dump
-   memory allocated since the call to `dumpmemory_marker` will be
-   freed.
-
-*******************************************************************************/
-
-void *dumpmemory_get(size_t size)
-{
-#if defined(DISABLE_DUMP)
-
-       /* use malloc memory for dump memory (for debugging only!) */
-
-       return mem_alloc(size);
-
-#else /* !defined(DISABLE_DUMP) */
-
-       void       *p;
-       dumpinfo_t *di;
-#if defined(ENABLE_MEMCHECK)
-       s4          origsize = size; /* needed for the canary system */
-#endif
-
-       di = DUMPINFO;
-
-       if (size == 0)
-               return NULL;
-
-#if defined(ENABLE_MEMCHECK)
-       size += 2 * MEMORY_CANARY_SIZE;
-#endif
-
-       size = MEMORY_ALIGN(size, ALIGNSIZE);
-
-       /* Check if we have enough memory in the current memory block. */
-
-       if (di->used + size > di->allocated) {
-               /* If not, allocate a new one. */
-
-               dumpmemory_alloc(di, size);
-       }
-
-       /* current dump block base address + the size of the current dump
-          block - the size of the unused memory = new start address  */
-
-       p = ((uint8_t *) di->block->dumpmem) + di->block->size -
-               (di->allocated - di->used);
-
-#if defined(ENABLE_MEMCHECK)
-       {
-               dump_allocation_t *da = NEW(dump_allocation_t);
-               uint8_t           *pm;
-               int                i;
-
-               /* add the allocation to our linked list of allocations */
-
-               da->next = di->allocations;
-               da->mem  = ((uint8_t *) p) + MEMORY_CANARY_SIZE;
-               da->size = origsize;
-               da->used = di->used;
-
-               di->allocations = da;
-
-               /* write the canaries */
-
-               pm = (uint8_t *) p;
-
-               for (i = 0; i < MEMORY_CANARY_SIZE; ++i)
-                       pm[i] = i + MEMORY_CANARY_FIRST_BYTE;
-
-               pm = ((uint8_t *) da->mem) + da->size;
-
-               for (i = 0; i < MEMORY_CANARY_SIZE; ++i)
-                       pm[i] = i + MEMORY_CANARY_FIRST_BYTE;
-
-               /* make m point after the bottom canary */
-
-               p = ((uint8_t *) p) + MEMORY_CANARY_SIZE;
-
-               /* clear the memory */
-
-               (void) os_memset(p, MEMORY_CLEAR_BYTE, da->size);
-       }
-#endif /* defined(ENABLE_MEMCHECK) */
-
-       /* Increase used dump size by the allocated memory size. */
-
-       di->used += size;
-
-#if defined(ENABLE_STATISTICS)
-       if (opt_stat)
-               if (di->used > maxdumpsize)
-                       maxdumpsize = di->used;
-#endif
-
-       return p;
-
-#endif /* defined(DISABLE_DUMP) */
-}
-
-
-/* dumpmemory_realloc **********************************************************
-
-   Stupid realloc implementation for dump memory. Avoid, if possible.
-
-*******************************************************************************/
-
-void *dumpmemory_realloc(void *src, s4 len1, s4 len2)
-{
-#if defined(DISABLE_DUMP)
-       /* use malloc memory for dump memory (for debugging only!) */
-
-       return mem_realloc(src, len1, len2);
-#else
-       void *dst;
-
-       dst = dumpmemory_get(len2);
-
-       (void) os_memcpy(dst, src, len1);
-
-#if defined(ENABLE_MEMCHECK)
-       /* destroy the source */
-
-       (void) os_memset(src, MEMORY_CLEAR_BYTE, len1);
-#endif
-
-       return dst;
-#endif
-}
-
-
-/* dumpmemory_release **********************************************************
-
-   Release dump memory above the given size.
-
-   IN:
-       size........All dump memory above this mark will be freed. Usually
-                      `size` will be the return value of a `dumpmemory_marker`
-                                  call made earlier.
-
-       ERROR HANDLING:
-          XXX If the given size is invalid, this function *exits* with an
-              error message.
-                                  
-       See `dump_alloc`.
-
-*******************************************************************************/
-
-void dumpmemory_release(s4 size)
-{
-#if defined(DISABLE_DUMP)
-
-       /* use malloc memory for dump memory (for debugging only!) */
-
-       /* do nothing */
-
-#else /* !defined(DISABLE_DUMP) */
-
-       dumpinfo_t *di;
-
-       di = DUMPINFO;
-
-       if ((size < 0) || (size > di->used))
-               vm_abort("dump_release: Illegal dump release size: %d", size);
-
-#if defined(ENABLE_MEMCHECK)
-       {
-               dump_allocation_t *da, *next;
-
-               /* check canaries */
-
-               dump_check_canaries(di, size);
-
-               /* iterate over all dump memory allocations about to be released */
-
-               da = di->allocations;
-
-               while ((da != NULL) && (da->used >= size)) {
-                       next = da->next;
-
-                       /* invalidate the freed memory */
-
-                       (void) os_memset(da->mem, MEMORY_CLEAR_BYTE, da->size);
-
-                       FREE(da, dump_allocation_t);
-
-                       da = next;
-               }
-               di->allocations = da;
-       }
-#endif /* defined(ENABLE_MEMCHECK) */
-
-       /* Reset the used dump size to the size specified. */
-
-       di->used = size;
-
-       while ((di->block != NULL) && di->allocated - di->block->size >= di->used) {
-               dumpblock_t *tmp = di->block;
-
-               di->allocated -= tmp->size;
-               di->block      = tmp->prev;
-
-#if defined(ENABLE_STATISTICS)
-               /* the amount of globally allocated dump memory (thread save) */
-
-               if (opt_stat)
-                       globalallocateddumpsize -= tmp->size;
-#endif
-
-               /* Release the dump memory and the dumpinfo structure. */
-
-               os_free(tmp->dumpmem);
-               os_free(tmp);
-       }
-
-#endif /* defined(DISABLE_DUMP) */
-}
-
-
-/* dumpmemory_marker ***********************************************************
-
-   Returns a marker of the dump memory area.  This marker is actually
-   the used size of the dump memory area.
-
-   RETURN VALUE:
-       marker of the current dump memory status
-
-*******************************************************************************/
-
-int32_t dumpmemory_marker(void)
-{
-#if defined(DISABLE_DUMP)
-       /* use malloc memory for dump memory (for debugging only!) */
-
-       return 0;
-
-#else /* !defined(DISABLE_DUMP) */
-
-       dumpinfo_t *di;
-
-       di = DUMPINFO;
-
-       if (di == NULL)
-               return 0;
-
-       return di->used;
-
-#endif /* defined(DISABLE_DUMP) */
-}
-
-
-/*
- * These are local overrides for various environment variables in Emacs.
- * Please do not remove this and leave it at the end of the file, where
- * Emacs will automagically detect them.
- * ---------------------------------------------------------------------
- * Local variables:
- * mode: c
- * indent-tabs-mode: t
- * c-basic-offset: 4
- * tab-width: 4
- * End:
- * vim:noexpandtab:sw=4:ts=4:
- */
diff --git a/src/mm/dumpmemory.cpp b/src/mm/dumpmemory.cpp
new file mode 100644 (file)
index 0000000..b630563
--- /dev/null
@@ -0,0 +1,343 @@
+/* src/mm/dumpmemory.cpp - dump memory management
+
+   Copyright (C) 1996-2005, 2006, 2007, 2008
+   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
+   Copyright (C) 2008 Theobroma Systems Ltd.
+
+   This file is part of CACAO.
+
+   This program is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License as
+   published by the Free Software Foundation; either version 2, or (at
+   your option) any later version.
+
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.
+
+*/
+
+
+#include "config.h"
+
+#include <stdint.h>
+
+#include "mm/dumpmemory.hpp"
+#include "mm/memory.h"
+
+#include "threads/thread.hpp"
+
+#include "vm/options.h"
+#include "vm/os.hpp"
+
+#if defined(ENABLE_STATISTICS)
+# include "vm/statistics.h"
+#endif
+
+#include "vm/vm.hpp"
+
+
+/*******************************************************************************
+
+  This structure is used for dump memory allocation if cacao
+  runs without threads.
+
+*******************************************************************************/
+
+#if !defined(ENABLE_THREADS)
+static dumpinfo_t _no_threads_dumpinfo;
+#endif
+
+
+/* dump_check_canaries *********************************************************
+
+   Check canaries in dump memory.
+
+   IN:
+      di...........dumpinfo_t * of the dump area to check
+         bottomsize...dump size down to which the dump area should be checked
+                      (specify 0 to check the whole dump area)
+
+   ERROR HANDLING:
+      If any canary has been changed, this function aborts the VM with
+         an error message.
+
+*******************************************************************************/
+
+#if defined(ENABLE_MEMCHECK)
+static void dump_check_canaries(dumpinfo_t *di, s4 bottomsize)
+{
+       dump_allocation_t *da;
+       uint8_t           *pm;
+       int                i, j;
+
+       /* iterate over all dump memory allocations above bottomsize */
+
+       da = di->allocations;
+
+       while (da && da->used >= bottomsize) {
+               /* check canaries */
+
+               pm = ((uint8_t *) da->mem) - MEMORY_CANARY_SIZE;
+
+               for (i = 0; i < MEMORY_CANARY_SIZE; ++i) {
+                       if (pm[i] != i + MEMORY_CANARY_FIRST_BYTE) {
+                               fprintf(stderr, "canary bytes:");
+
+                               for (j = 0; j < MEMORY_CANARY_SIZE; ++j)
+                                       fprintf(stderr, " %02x", pm[j]);
+
+                               fprintf(stderr,"\n");
+
+                               vm_abort("error: dump memory bottom canary killed: "
+                                                "%p (%d bytes allocated at %p)\n",
+                                                pm + i, da->size, da->mem);
+                       }
+               }
+
+               pm = ((uint8_t *) da->mem) + da->size;
+
+               for (i = 0; i < MEMORY_CANARY_SIZE; ++i) {
+                       if (pm[i] != i + MEMORY_CANARY_FIRST_BYTE) {
+                               fprintf(stderr, "canary bytes:");
+
+                               for (j = 0; j < MEMORY_CANARY_SIZE; ++j)
+                                       fprintf(stderr, " %02x", pm[j]);
+
+                               fprintf(stderr, "\n");
+
+                               vm_abort("error: dump memory top canary killed: "
+                                                "%p (%d bytes allocated at %p)\n",
+                                                pm + i, da->size, da->mem);
+                       }
+               }
+
+               da = da->next;
+       }
+}
+#endif /* defined(ENABLE_MEMCHECK) */
+
+
+/**
+ * Allocate a new thread-local dump memory structure.
+ */
+DumpMemory::DumpMemory() : _size(0), _used(0)
+{
+}
+
+
+/**
+ * Stupid realloc implementation for dump memory.  Avoid, if possible.
+ */
+void* DumpMemory::reallocate(void* src, size_t len1, size_t len2)
+{
+       void* dst = allocate(len2);
+
+       (void) os::memcpy(dst, src, len1);
+
+#if defined(ENABLE_MEMCHECK)
+       // Destroy the source.
+       (void) os::memset(src, MEMORY_CLEAR_BYTE, len1);
+#endif
+
+       return dst;
+}
+
+
+/**
+ * Add the given dump area to the area list.
+ *
+ * @param dm Pointer to dump area.
+ */
+void DumpMemory::add_area(DumpMemoryArea* dma)
+{
+       _areas.push_back(dma);
+
+       // Increase the size count of the dump memory.
+       _size += dma->get_size();
+
+#if defined(ENABLE_STATISTICS)
+       if (opt_stat) {
+               if (_size > (size_t) maxdumpsize)
+                       maxdumpsize = _size;
+       }
+#endif
+}
+
+
+/**
+ * Remove the given dump area from the area list.
+ *
+ * @param dm Pointer to dump area.
+ */
+void DumpMemory::remove_area(DumpMemoryArea* dma)
+{
+       // Sanity check.
+       assert(_areas.back() == dma);
+
+       // Remove the last area from the list.  The check above guarantees
+       // we are removing the correct area.
+       _areas.pop_back();
+
+       // Decrease the size and used count.
+       _size -= dma->get_size();
+       _used -= dma->get_used();
+}
+
+
+/**
+ * Allocate a new dump memory area.
+ *
+ * @ param size Required memory size.
+ */
+DumpMemoryArea::DumpMemoryArea(size_t size) : _size(0), _used(0)
+{
+       // Get the DumpMemory object of the current thread.
+       DumpMemory* dm = DumpMemory::get_current();
+
+       // Add this area to the areas list.
+       dm->add_area(this);
+}
+
+
+/**
+ * Release all dump memory blocks in the current dump area.
+ */
+DumpMemoryArea::~DumpMemoryArea()
+{
+       // Get the DumpMemory object of the current thread.
+       DumpMemory* dm = DumpMemory::get_current();
+
+#if defined(ENABLE_MEMCHECK)
+       {
+               dump_allocation_t *da, *next;
+
+               /* check canaries */
+
+               dump_check_canaries(di, size);
+
+               /* iterate over all dump memory allocations about to be released */
+
+               da = di->allocations;
+
+               while ((da != NULL) && (da->used >= size)) {
+                       next = da->next;
+
+                       /* invalidate the freed memory */
+
+                       (void) os_memset(da->mem, MEMORY_CLEAR_BYTE, da->size);
+
+                       FREE(da, dump_allocation_t);
+
+                       da = next;
+               }
+               di->allocations = da;
+       }
+#endif /* defined(ENABLE_MEMCHECK) */
+
+
+       // Free all memory blocks.
+       for (std::vector<DumpMemoryBlock*>::iterator it = _blocks.begin(); it != _blocks.end(); it++) {
+               // Call the destructor of the current block.
+               delete *it;
+       }
+
+       // Remove this area for the area list.
+       dm->remove_area(this);
+}
+
+
+/**
+ * Allocate a dump memory block for the current dump memory area.
+ *
+ * @param size Required memory size.
+ *
+ * @return Pointer to the newly allocated block.
+ */
+DumpMemoryBlock* DumpMemoryArea::allocate_new_block(size_t size)
+{
+       DumpMemoryBlock* dmb = new DumpMemoryBlock(size);
+       _blocks.push_back(dmb);
+
+#if defined(ENABLE_STATISTICS)
+       if (opt_stat) {
+               DumpMemory* dm = DumpMemory::get_current();
+               dm->add_size(dmb->get_size());
+
+               if (dm->get_size() > (size_t) maxdumpsize)
+                       maxdumpsize = dm->get_size();
+       }
+#endif
+
+       return dmb;
+}
+
+
+/**
+ * Allocate a memory block for the current dump memory block.
+ *
+ * @param size Required memory size.
+ */
+DumpMemoryBlock::DumpMemoryBlock(size_t size) : _size(0), _used(0), _block(0)
+{
+       // If requested size is greater than the default, make the new
+       // memory block as big as the requested size.  Otherwise use the
+       // default size.
+       _size = (size > DEFAULT_SIZE) ? size : DEFAULT_SIZE;
+
+       // Allocate a memory block.
+       _block = memory_checked_alloc(_size);
+
+#if defined(ENABLE_STATISTICS)
+       // The amount of globally allocated dump memory (thread safe).
+       if (opt_stat)
+               globalallocateddumpsize += _size;
+#endif
+}
+
+
+/**
+ * Release the memory block for the dump memory block.
+ *
+ * @param size Required memory size.
+ */
+DumpMemoryBlock::~DumpMemoryBlock()
+{
+       // Release the memory block.
+       mem_free(_block, /* XXX */ 1);
+
+#if defined(ENABLE_STATISTICS)
+       // The amount of globally allocated dump memory (thread safe).
+       if (opt_stat)
+               globalallocateddumpsize -= _size;
+#endif
+}
+
+
+// Legacy C interface.
+
+extern "C" {
+       void* DumpMemory_allocate(size_t size) { return DumpMemory::allocate(size); }
+       void* DumpMemory_reallocate(void* src, size_t len1, size_t len2) { return DumpMemory::reallocate(src, len1, len2); }
+}
+
+
+/*
+ * These are local overrides for various environment variables in Emacs.
+ * Please do not remove this and leave it at the end of the file, where
+ * Emacs will automagically detect them.
+ * ---------------------------------------------------------------------
+ * Local variables:
+ * mode: c++
+ * indent-tabs-mode: t
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ * vim:noexpandtab:sw=4:ts=4:
+ */
diff --git a/src/mm/dumpmemory.h b/src/mm/dumpmemory.h
deleted file mode 100644 (file)
index 54fdb6a..0000000
+++ /dev/null
@@ -1,126 +0,0 @@
-/* src/mm/dumpmemory.h - dump memory management
-
-   Copyright (C) 1996-2005, 2006, 2007, 2008
-   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
-
-   This file is part of CACAO.
-
-   This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 2, or (at
-   your option) any later version.
-
-   This program is distributed in the hope that it will be useful, but
-   WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-   02110-1301, USA.
-
-*/
-
-
-#ifndef _DUMPMEMORY_H
-#define _DUMPMEMORY_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* forward typedefs ***********************************************************/
-
-typedef struct dumpblock_t dumpblock_t;
-typedef struct dumpinfo_t  dumpinfo_t;
-
-#include "config.h"
-
-#include <stdint.h>
-#include <string.h>
-
-
-/* ATTENTION: We need to define dumpblock_t and dumpinfo_t before
-   internal includes, as we need dumpinfo_t as nested structure in
-   threadobject. */
-
-/* dumpblock ******************************************************************/
-
-#define DUMPBLOCKSIZE    2 << 13    /* 2 * 8192 bytes */
-#define ALIGNSIZE        8
-
-struct dumpblock_t {
-       dumpblock_t *prev;
-       void        *dumpmem;
-       int32_t      size;
-};
-
-
-/* dump_allocation *************************************************************
-
-   This struct is used to record dump memory allocations for ENABLE_MEMCHECK.
-
-*******************************************************************************/
-
-#if defined(ENABLE_MEMCHECK)
-typedef struct dump_allocation_t dump_allocation_t;
-
-struct dump_allocation_t {
-       dump_allocation_t *next;
-       void              *mem;
-       int32_t            used;
-       int32_t            size;
-};
-#endif
-
-
-/* dumpinfo *******************************************************************/
-
-struct dumpinfo_t {
-       dumpblock_t       *block;                   /* the current top-most block */
-       int32_t            allocated;             /* allocated bytes in this area */
-       int32_t            used;                  /* used bytes in this dump area */
-#if defined(ENABLE_MEMCHECK)
-       dump_allocation_t *allocations;       /* list of allocations in this area */
-#endif
-};
-
-
-/* convenience macros *********************************************************/
-
-#define DMARKER               dumpmarker = dumpmemory_marker()
-#define DRELEASE              dumpmemory_release(dumpmarker)
-
-#define DNEW(type)            ((type *) dumpmemory_get(sizeof(type)))
-#define DMNEW(type,num)       ((type *) dumpmemory_get(sizeof(type) * (num)))
-#define DMREALLOC(ptr,type,num1,num2) ((type*) dumpmemory_realloc((ptr), sizeof(type) * (num1), \
-                                                                                                                                 sizeof(type) * (num2)))
-
-/* function prototypes ********************************************************/
-
-void    *dumpmemory_get(size_t size);
-void    *dumpmemory_realloc(void *src, int32_t len1, int32_t len2);
-int32_t  dumpmemory_marker(void);
-void     dumpmemory_release(int32_t size);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _DUMPMEMORY_H */
-
-
-/*
- * These are local overrides for various environment variables in Emacs.
- * Please do not remove this and leave it at the end of the file, where
- * Emacs will automagically detect them.
- * ---------------------------------------------------------------------
- * Local variables:
- * mode: c
- * indent-tabs-mode: t
- * c-basic-offset: 4
- * tab-width: 4
- * End:
- * vim:noexpandtab:sw=4:ts=4:
- */
diff --git a/src/mm/dumpmemory.hpp b/src/mm/dumpmemory.hpp
new file mode 100644 (file)
index 0000000..1621eab
--- /dev/null
@@ -0,0 +1,395 @@
+/* src/mm/dumpmemory.hpp - dump memory management
+
+   Copyright (C) 1996-2005, 2006, 2007, 2008
+   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
+   Copyright (C) 2008 Theobroma Systems Ltd.
+
+   This file is part of CACAO.
+
+   This program is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License as
+   published by the Free Software Foundation; either version 2, or (at
+   your option) any later version.
+
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.
+
+*/
+
+
+#ifndef _DUMPMEMORY_HPP
+#define _DUMPMEMORY_HPP
+
+#include "config.h"
+
+#include <assert.h>
+#include <stddef.h>
+#include <stdint.h>
+
+#ifdef __cplusplus
+
+#include <cstddef>
+#include <list>
+#include <vector>
+#include <stdio.h> // REMOVEME
+
+
+// Forward declaration.
+class DumpMemoryArea;
+class DumpMemoryBlock;
+
+
+/**
+ * Thread-local dump memory structure.
+ */
+class DumpMemory {
+private:
+       size_t                     _size;  ///< Size of the dump areas in this dump memory.
+       size_t                     _used;  ///< Used memory in this dump memory.
+       std::list<DumpMemoryArea*> _areas; ///< Pointer to the current dump area.
+
+#if 0
+#if defined(ENABLE_MEMCHECK)
+       dump_allocation_t *allocations;       /* list of allocations in this area */
+#endif
+#endif
+
+public:
+       DumpMemory();
+       ~DumpMemory();
+
+       static inline DumpMemory* get_current();
+       static inline void*       allocate(size_t size);
+
+       inline void   add_size(size_t size) { _size += size; }
+
+       inline size_t get_size() const { return _size; }
+       inline size_t get_used() const { return _used; }
+
+       inline DumpMemoryArea* get_current_area() const;
+
+       static void* reallocate(void* src, size_t len1, size_t len2);
+
+       void  add_area(DumpMemoryArea* dma);
+       void  remove_area(DumpMemoryArea* dma);
+};
+
+
+/**
+ * Dump memory area.
+ */
+class DumpMemoryArea {
+private:
+       size_t                        _size;   ///< Size of the current memory block.
+       size_t                        _used;   ///< Used memory in the current memory block.
+       std::vector<DumpMemoryBlock*> _blocks; ///< List of memory blocks in this area.
+
+public:
+       DumpMemoryArea(size_t size = 0);
+       ~DumpMemoryArea();
+
+       inline size_t get_size() const { return _size; }
+       inline size_t get_used() const { return _used; }
+
+       // Inline functions.
+       inline void*            allocate(size_t size);
+       inline DumpMemoryBlock* get_current_block() const;
+
+       DumpMemoryBlock* allocate_new_block(size_t size);
+};
+
+
+/**
+ * Dump memory block.
+ */
+class DumpMemoryBlock {
+private:
+       static const size_t DEFAULT_SIZE = 2 << 13; // 2 * 8192 bytes
+
+       size_t _size;  ///< Size of the current memory block.
+       size_t _used;  ///< Used memory in the current memory block.
+       void*  _block; ///< List of memory blocks in this area.
+
+public:
+       DumpMemoryBlock(size_t size = 0);
+       ~DumpMemoryBlock();
+
+       inline size_t get_size() const { return _size; }
+       inline size_t get_used() const { return _used; }
+       inline size_t get_free() const { return _size - _used; }
+
+       // Inline functions.
+       inline void* allocate(size_t size);
+};
+
+
+/**
+ * Allocator for the dump memory.
+ */
+template<class T> class DumpMemoryAllocator {
+public:
+       // Type definitions.
+       typedef T              value_type;
+       typedef T*             pointer;
+       typedef const T*       const_pointer;
+       typedef T&             reference;
+       typedef const T&       const_reference;
+       typedef std::size_t    size_type;
+       typedef std::ptrdiff_t difference_type;
+
+       // Rebind allocator to type U.
+       template <class U> struct rebind {
+               typedef DumpMemoryAllocator<U> other;
+       };
+
+       /* constructors and destructor
+        * - nothing to do because the allocator has no state
+        */
+       DumpMemoryAllocator() throw() {
+       }
+
+       DumpMemoryAllocator(const DumpMemoryAllocator&) throw() {
+       }
+
+       template <class U> DumpMemoryAllocator(const DumpMemoryAllocator<U>&) throw() {
+       }
+
+       ~DumpMemoryAllocator() throw() {
+       }
+
+       pointer allocate(size_type n, void* = 0) {
+               printf("allocate: n=%d * %d\n", n, sizeof(T));
+               return static_cast<pointer>(DumpMemory::allocate(n * sizeof(T)));
+       }
+
+       // Initialize elements of allocated storage p with value value.
+       void construct(pointer p, const T& value) {
+               printf("construct: p=%p, value=%p\n", p, value);
+               // Initialize memory with placement new.
+               new ((void*) p) T(value);
+       }
+
+       // Destroy elements of initialized storage p.
+       void destroy(pointer p) {
+               printf("destroy: p=%p\n", p);
+               // Destroy objects by calling their destructor.
+               p->~T();
+       }
+
+       void deallocate(pointer p, size_type n) {
+               printf("deallocate: p=%p, n=%d\n", p, n);
+               // We don't need to deallocate on dump memory.
+       }
+};
+
+
+/* dump_allocation *************************************************************
+
+   This struct is used to record dump memory allocations for ENABLE_MEMCHECK.
+
+*******************************************************************************/
+
+#if 0
+#if defined(ENABLE_MEMCHECK)
+typedef struct dump_allocation_t dump_allocation_t;
+
+struct dump_allocation_t {
+       dump_allocation_t *next;
+       void              *mem;
+       int32_t            used;
+       int32_t            size;
+};
+#endif
+#endif
+
+
+// Includes.
+#include "mm/memory.h"
+
+#include "threads/thread.hpp"
+
+#include "vm/options.h"
+
+#if defined(ENABLE_STATISTICS)
+# include "vm/statistics.h"
+#endif
+
+
+// Inline functions.
+
+inline DumpMemory* DumpMemory::get_current()
+{
+       // Get the DumpMemory object of the current thread.
+       threadobject* t = thread_get_current();
+       DumpMemory* dm = t->_dumpmemory;
+       return dm;
+}
+
+inline DumpMemoryArea* DumpMemory::get_current_area() const
+{
+       return _areas.back();
+}
+
+inline void* DumpMemory::allocate(size_t size)
+{
+       DumpMemory* dm = get_current();
+       DumpMemoryArea* dma = dm->get_current_area();
+
+       size_t alignedsize = size;
+
+#if defined(ENABLE_MEMCHECK)
+       alignedsize += 2 * MEMORY_CANARY_SIZE;
+#endif
+
+       // Align the allocation size.
+       alignedsize = MEMORY_ALIGN(alignedsize, ALIGNSIZE);
+
+       void* p = dma->allocate(alignedsize);
+
+       // Increase the used count of the dump memory.
+       dm->_used += alignedsize;
+
+       return p;
+}
+
+inline DumpMemoryBlock* DumpMemoryArea::get_current_block() const
+{
+       return _blocks.empty() ? NULL : _blocks.back();
+}
+
+inline void* DumpMemoryArea::allocate(size_t size)
+{
+       DumpMemoryBlock* dmb = get_current_block();
+
+       // Check if we have a memory block or have enough memory in the
+       // current memory block.
+       if (dmb == NULL || size > dmb->get_free()) {
+               // No, allocate a new one.
+               dmb = allocate_new_block(size);
+
+               // Increase the size of the memory area.  We use get_size()
+               // here because the default size is very likely to be bigger
+               // than size.
+               _size += dmb->get_size();
+       }
+
+       void* p = dmb->allocate(size);
+
+       // Increase the used size of the memory area.
+       _used += size;
+
+       return p;
+}
+
+/**
+ * Allocate memory in the current dump memory area.
+ *
+ * This function is a fast allocator suitable for scratch memory that
+ * can be collectively freed when the current activity (eg. compiling)
+ * is done.
+ *
+ * You cannot selectively free dump memory. Before you start
+ * allocating it, you remember the current size returned by
+ * `dumpmemory_marker`. Later, when you no longer need the memory,
+ * call `dumpmemory_release` with the remembered size and all dump
+ * memory allocated since the call to `dumpmemory_marker` will be
+ * freed.
+ *
+ * @parm size Size of block to allocate in bytes. May be zero, in which case NULL is returned
+ *
+ * @return Pointer to allocated memory, or NULL iff size was zero.
+ */
+void* DumpMemoryBlock::allocate(size_t size)
+{
+#if defined(ENABLE_MEMCHECK)
+       size_t origsize = size; /* needed for the canary system */
+#endif
+
+       if (size == 0)
+               return NULL;
+
+       // Sanity check.
+       assert(size <= (_size - _used));
+
+       // Calculate the memory address of the newly allocated memory.
+       void* p = (void*) (((uint8_t*) _block) + _used);
+
+#if defined(ENABLE_MEMCHECK)
+       {
+               dump_allocation_t *da = NEW(dump_allocation_t);
+               uint8_t           *pm;
+               int                i;
+
+               /* add the allocation to our linked list of allocations */
+
+               da->next = di->allocations;
+               da->mem  = ((uint8_t *) p) + MEMORY_CANARY_SIZE;
+               da->size = origsize;
+               da->used = di->used;
+
+               di->allocations = da;
+
+               /* write the canaries */
+
+               pm = (uint8_t *) p;
+
+               for (i = 0; i < MEMORY_CANARY_SIZE; ++i)
+                       pm[i] = i + MEMORY_CANARY_FIRST_BYTE;
+
+               pm = ((uint8_t *) da->mem) + da->size;
+
+               for (i = 0; i < MEMORY_CANARY_SIZE; ++i)
+                       pm[i] = i + MEMORY_CANARY_FIRST_BYTE;
+
+               /* make m point after the bottom canary */
+
+               p = ((uint8_t *) p) + MEMORY_CANARY_SIZE;
+
+               /* clear the memory */
+
+               (void) os_memset(p, MEMORY_CLEAR_BYTE, da->size);
+       }
+#endif /* defined(ENABLE_MEMCHECK) */
+
+       // Increase used memory block size by the allocated memory size.
+       _used += size;
+
+       return p;
+}
+
+#else
+
+// Legacy C interface.
+
+void* DumpMemory_allocate(size_t size);
+void* DumpMemory_reallocate(void* src, size_t len1, size_t len2);
+
+#define DNEW(type)                    ((type*) DumpMemory_allocate(sizeof(type)))
+#define DMNEW(type,num)               ((type*) DumpMemory_allocate(sizeof(type) * (num)))
+#define DMREALLOC(ptr,type,num1,num2) ((type*) DumpMemory_reallocate((ptr), sizeof(type) * (num1), sizeof(type) * (num2)))
+
+#endif
+
+#endif // _DUMPMEMORY_HPP
+
+
+/*
+ * These are local overrides for various environment variables in Emacs.
+ * Please do not remove this and leave it at the end of the file, where
+ * Emacs will automagically detect them.
+ * ---------------------------------------------------------------------
+ * Local variables:
+ * mode: c++
+ * indent-tabs-mode: t
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ * vim:noexpandtab:sw=4:ts=4:
+ */
index 12ca651c2eecd3f1b4ac872fab8ae2b73cc09d4c..ec6393f19f8a4ac959748a64750ca26a7cae8c89 100644 (file)
 
 #include "config.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <string.h>
+#include <stdint.h>
 
-#include "vm/types.h"
 
-#include "mm/codememory.h"
-#include "mm/dumpmemory.h"
+// Align the size of memory allocations to this size.
+#define ALIGNSIZE 8
+#define MEMORY_ALIGN(pos,size) ((((pos) + (size) - 1) / (size)) * (size))
 
 
-/* constants for ENABLE_MEMCHECK **********************************************/
+// Constants for ENABLE_MEMCHECK.
 
 #if defined(ENABLE_MEMCHECK)
 #define MEMORY_CANARY_SIZE          16
 #define MEMORY_CANARY_FIRST_BYTE    0xca
 #define MEMORY_CLEAR_BYTE           0xa5
-#endif /* defined(ENABLE_MEMCHECK) */
-
+#endif
 
-/* internal includes **********************************************************/
 
+// Includes.
+#include "mm/codememory.h"
+#include "mm/dumpmemory.hpp"
 #include "mm/gc.hpp"
 
 
@@ -91,7 +88,6 @@ Some more macros:
 
 */
 
-#define MEMORY_ALIGN(pos,size) ((((pos) + (size) - 1) / (size)) * (size))
 #define PADDING(pos,size)     (MEMORY_ALIGN((pos),(size)) - (pos))
 #define OFFSET(s,el)          ((int32_t) ((ptrint) &(((s*) 0)->el)))
 
@@ -130,6 +126,10 @@ Some more macros:
 
 /* function prototypes ********************************************************/
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 bool  memory_init(void);
 
 void  memory_mprotect(void *addr, size_t len, int prot);
index 48b40e307257225d88478007651bd12946923c47..6a6eab8afbeafd529563b21c58e5522a65f33c96 100644 (file)
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
+
 */
 
+
 #ifndef _MM_TLH_H
 #define _MM_TLH_H
 
+#include "config.h"
+
 #include <stddef.h>
 #include <stdint.h>
 
@@ -35,6 +39,10 @@ typedef struct {
        unsigned overflows;
 } tlh_t;
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 void tlh_init(tlh_t *tlh);
 
 void tlh_destroy(tlh_t *tlh);
@@ -45,6 +53,10 @@ void tlh_remove_frame(tlh_t *tlh);
 
 void *tlh_alloc(tlh_t *tlh, size_t size);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
 
 /*
index 043d82964baa26a3bcd6e12dc88b8e9857ab4735..0301f6800258354383c5b13a313ec6263335e50a 100644 (file)
 #ifndef _LLNI_H
 #define _LLNI_H
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 #include "config.h"
 
 /* forward defines ************************************************************/
@@ -149,6 +145,10 @@ extern "C" {
 # define LLNI_CRITICAL_END_THREAD(t)
 #endif
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 void llni_critical_start();
 void llni_critical_end();
 void llni_critical_start_thread(threadobject *t);
index 7b56350e7d1d13dc812427300bb3d65dbc119dee..4d120918b9c1dd1107a3c6999555ccacb6b514c9 100644 (file)
@@ -164,11 +164,6 @@ static utf *native_make_overloaded_function(utf *name, utf *descriptor)
        u2    c;
        s4    i;
        utf  *u;
-       int32_t dumpmarker;
-
-       /* mark memory */
-
-       DMARKER;
 
        utf_ptr = descriptor->text;
        namelen = strlen(name->text) + strlen("__") + strlen("0");
@@ -207,7 +202,7 @@ static utf *native_make_overloaded_function(utf *name, utf *descriptor)
 
        i = strlen(name->text);
 
-       newname = DMNEW(char, namelen);
+       newname = MNEW(char, namelen);
        MCOPY(newname, name->text, char, i);
 
        utf_ptr = descriptor->text;
@@ -260,7 +255,7 @@ static utf *native_make_overloaded_function(utf *name, utf *descriptor)
 
        /* release memory */
 
-       DRELEASE;
+       MFREE(newname, char, namelen);
 
        return u;
 }
@@ -344,11 +339,6 @@ static utf *native_method_symbol(utf *classname, utf *methodname)
        u2    c;
        u4    pos;
        utf  *u;
-       int32_t dumpmarker;
-
-       /* mark memory */
-
-       DMARKER;
 
        /* Calculate length of native function name.  We multiply the
           class and method name length by 6 as this is the maxium
@@ -363,7 +353,7 @@ static utf *native_method_symbol(utf *classname, utf *methodname)
 
        /* allocate memory */
 
-       name = DMNEW(char, namelen);
+       name = MNEW(char, namelen);
 
        /* generate name of native functions */
 
@@ -404,7 +394,7 @@ static utf *native_method_symbol(utf *classname, utf *methodname)
 
        /* release memory */
 
-       DRELEASE;
+       MFREE(name, char, namelen);
 
        return u;
 }
index 3ad67e4620c981528ade3a4e17582439bec605d9..ba23fcc7e0b617072f4df84b8561f581edc8ed99 100644 (file)
@@ -39,7 +39,7 @@
 # include <mach/mach.h>
 #endif
 
-#include "mm/dumpmemory.h"
+#include "mm/memory.h"
 #include "mm/gc.hpp"
 
 #include "native/jni.hpp"
@@ -232,7 +232,6 @@ JNIEXPORT jstring JNICALL Java_java_lang_VMRuntime_mapLibraryName(JNIEnv *env, j
        char          *buffer;
        int32_t        buffer_len;
        java_handle_t *o;
-       int32_t        dumpmarker;
 
        if (libname == NULL) {
                exceptions_throw_nullpointerexception();
@@ -249,9 +248,7 @@ JNIEXPORT jstring JNICALL Java_java_lang_VMRuntime_mapLibraryName(JNIEnv *env, j
                strlen(NATIVE_LIBRARY_SUFFIX) +
                strlen("0");
 
-       DMARKER;
-
-       buffer = DMNEW(char, buffer_len);
+       buffer = MNEW(char, buffer_len);
 
        /* generate library name */
 
@@ -263,7 +260,7 @@ JNIEXPORT jstring JNICALL Java_java_lang_VMRuntime_mapLibraryName(JNIEnv *env, j
 
        /* release memory */
 
-       DRELEASE;
+       MFREE(buffer, char, buffer_len);
 
        return (jstring) o;
 }
index 17971d0672c2f58356350490f3d085896e4b32e9..263459ddc65c25aa79f9fa8feefdfd2cfdd88ddf 100644 (file)
 
 #include "config.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 #include <pthread.h>
 
 #include "vm/types.h"
@@ -45,6 +41,9 @@ extern "C" {
 #include "vm/global.h"
 
 
+#ifdef __cplusplus
+extern "C" {
+#endif
 
 /* typedefs *******************************************************************/
 
index eb62ce6a91b4378555768ddf993e8d6888ec8bbb..84603487e29c50a023979176c840f7909dcc5853 100644 (file)
@@ -99,9 +99,6 @@
 #endif
 
 
-// FIXME For now we export everything as C functions.
-extern "C" {
-
 #if defined(__DARWIN__)
 /* Darwin has no working semaphore implementation.  This one is taken
    from Boehm-GC. */
@@ -482,7 +479,7 @@ void threads_impl_thread_clear(threadobject *t)
        t->es = NULL;
 #endif
 
-       MZERO(&t->dumpinfo, dumpinfo_t, 1);
+       // Simply reuse the existing dump memory.
 }
 
 /* threads_impl_thread_reuse ***************************************************
@@ -1580,8 +1577,6 @@ void threads_tlh_remove_frame() {
 
 #endif
 
-} // extern "C"
-
 
 /*
  * These are local overrides for various environment variables in Emacs.
index a084bd9244004257046cad10b674778407237141..89c6d1671ee46eb6dd5b78262b7f40d24704f5d1 100644 (file)
 #ifndef _THREAD_POSIX_HPP
 #define _THREAD_POSIX_HPP
 
-/* forward typedefs ***********************************************************/
-
-typedef struct threadobject threadobject;
-
-
 #include "config.h"
 
 #include <pthread.h>
@@ -38,69 +33,16 @@ typedef struct threadobject threadobject;
 
 #include "vm/types.h"
 
-#include "mm/memory.h"
+
+// Includes required by Thread.
 
 #if defined(ENABLE_TLH)
-#include "mm/tlh.h"
+# include "mm/tlh.h"
 #endif
 
-#include "native/localref.h"
-
 #include "threads/condition.hpp"
 #include "threads/mutex.hpp"
 
-#include "threads/posix/lock.h"
-
-#include "vm/global.h"
-#include "vm/vm.hpp"
-
-#if defined(ENABLE_GC_CACAO)
-# include "vm/jit/executionstate.h"
-# include "vm/jit/replace.hpp"
-#endif
-
-#include "vm/jit/stacktrace.hpp"
-
-#if defined(ENABLE_INTRP)
-#include "vm/jit/intrp/intrp.h"
-#endif
-
-#if defined(__DARWIN__)
-# include <mach/mach.h>
-
-typedef struct {
-       Mutex* mutex;
-       Condition* cond;
-       int value;
-} sem_t;
-
-#else
-# include <semaphore.h>
-#endif
-
-
-// FIXME
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* current threadobject *******************************************************/
-
-#if defined(HAVE___THREAD)
-
-#define THREADOBJECT      thread_current
-
-extern __thread threadobject *thread_current;
-
-#else /* defined(HAVE___THREAD) */
-
-#define THREADOBJECT \
-       ((threadobject *) pthread_getspecific(thread_current_key))
-
-extern pthread_key_t thread_current_key;
-
-#endif /* defined(HAVE___THREAD) */
-
 
 /* threadobject ****************************************************************
 
@@ -117,6 +59,8 @@ extern pthread_key_t thread_current_key;
 #define SUSPEND_REASON_STOPWORLD 2      /* suspended from stop-thw-world      */
 
 
+typedef struct threadobject threadobject;
+
 struct threadobject {
        java_object_t        *object;       /* link to java.lang.Thread object    */
 
@@ -156,8 +100,8 @@ struct threadobject {
        u1                   *pc;           /* current PC (used for profiling)    */
 
        java_object_t        *_exceptionptr;     /* current exception             */
-       stackframeinfo_t     *_stackframeinfo;   /* current native stackframeinfo */
-       localref_table       *_localref_table;   /* JNI local references          */
+       struct stackframeinfo_t     *_stackframeinfo;   /* current native stackframeinfo */
+       struct localref_table       *_localref_table;   /* JNI local references          */
 
 #if defined(ENABLE_INTRP)
        Cell                 *_global_sp;        /* stack pointer for interpreter */
@@ -170,7 +114,7 @@ struct threadobject {
        executionstate_t     *es;
 #endif
 
-       dumpinfo_t            dumpinfo;     /* dump memory info structure         */
+       struct DumpMemory*    _dumpmemory;     ///< Dump memory structure.
 
 #if defined(ENABLE_DEBUG_FILTER)
        u2                    filterverbosecallctr[2]; /* counters for verbose call filter */
@@ -194,6 +138,24 @@ struct threadobject {
 };
 
 
+/* current threadobject *******************************************************/
+
+#if defined(HAVE___THREAD)
+
+#define THREADOBJECT      thread_current
+
+extern __thread threadobject *thread_current;
+
+#else /* defined(HAVE___THREAD) */
+
+#define THREADOBJECT \
+       ((threadobject *) pthread_getspecific(thread_current_key))
+
+extern pthread_key_t thread_current_key;
+
+#endif /* defined(HAVE___THREAD) */
+
+
 /* native-world flags *********************************************************/
 
 #if defined(ENABLE_GC_CACAO)
@@ -219,18 +181,64 @@ struct threadobject {
 #endif
 
 
-/* inline functions ***********************************************************/
+// FIXME
+#ifdef __cplusplus
+extern "C" {
+#endif
+inline static threadobject* thread_get_current(void);
+#ifdef __cplusplus
+}
+#endif
 
-/* thread_get_current **********************************************************
 
-   Return the threadobject of the current thread.
-   
-   RETURN:
-       the current threadobject *
+// Includes.
+#include "mm/memory.h"
 
-*******************************************************************************/
+#include "native/localref.h"
+
+#include "threads/posix/lock.h"
+
+#include "vm/global.h"
+#include "vm/vm.hpp"
+
+#if defined(ENABLE_GC_CACAO)
+# include "vm/jit/executionstate.h"
+# include "vm/jit/replace.hpp"
+#endif
 
-inline static threadobject *thread_get_current(void)
+#include "vm/jit/stacktrace.hpp"
+
+#if defined(ENABLE_INTRP)
+#include "vm/jit/intrp/intrp.h"
+#endif
+
+#if defined(__DARWIN__)
+# include <mach/mach.h>
+
+typedef struct {
+       Mutex* mutex;
+       Condition* cond;
+       int value;
+} sem_t;
+
+#else
+# include <semaphore.h>
+#endif
+
+
+// FIXME
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* inline functions ***********************************************************/
+
+/**
+ * Return the Thread object of the current thread.
+ *
+ * @return The current Thread object.
+ */
+inline static threadobject* thread_get_current(void)
 {
        threadobject *t;
 
@@ -244,16 +252,12 @@ inline static threadobject *thread_get_current(void)
 }
 
 
-/* thread_set_current **********************************************************
-
-   Set the current thread object.
-   
-   IN:
-      t ... the thread object to set
-
-*******************************************************************************/
-
-inline static void thread_set_current(threadobject *t)
+/**
+ * Set the current Thread object.
+ *
+ * @param t The thread object to set.
+ */
+inline static void thread_set_current(threadobject* t)
 {
 #if defined(HAVE___THREAD)
        thread_current = t;
index 0b7e0c472209ce2c75643184e01a6fabb798d260..f41502504764bc6e82f3a5d027f93269c13cbe89 100644 (file)
@@ -64,9 +64,6 @@
 #include "vm/jit/stacktrace.hpp"
 
 
-// FIXME
-extern "C" {
-
 /* global variables ***********************************************************/
 
 static methodinfo    *thread_method_init;
@@ -506,6 +503,8 @@ static threadobject *thread_new(void)
                gc_reference_register(&(t->object), GC_REFTYPE_THREADOBJECT);
                gc_reference_register(&(t->_exceptionptr), GC_REFTYPE_THREADOBJECT);
 #endif
+
+               t->_dumpmemory = new DumpMemory();
        }
 
        /* Pre-compute the thinlock-word. */
@@ -1238,8 +1237,6 @@ void threads_dump(void)
        threadlist_unlock();
 }
 
-} // extern "C"
-
 
 /*
  * These are local overrides for various environment variables in Emacs.
index 463cd370a0075458e1a03cb904e314ee8ec68d7a..21dff9df65a891b5a289fe17b8af0d8a55718229 100644 (file)
 
 #include "config.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 #include "vm/types.h"
 
 // Include early to get threadobject.
@@ -96,6 +92,10 @@ extern bool threads_pthreads_implementation_nptl;
 #endif
 
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /* inline functions ***********************************************************/
 
 /* thread_get_object ***********************************************************
index bde41ff7ce95d2f4aecff7f569eede28e8d8ede1..66b9df11561033c0222f2486dd8a1f527b5551a0 100644 (file)
@@ -1,9 +1,8 @@
 /* src/toolbox/bitvector.c - bitvector implementation
 
-   Copyright (C) 2005, 2006 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
+   Copyright (C) 2005, 2006
+   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
+   Copyright (C) 2008 Theobroma Systems Ltd.
 
    This file is part of CACAO.
 
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
    02111-1307, USA.
 
-   Contact: cacao@complang.tuwien.ac.at
-
-   Authors: Christian Ullrich
+*/
 
 
-*/
+#include "config.h"
 
 #include "mm/memory.h"
 #include "toolbox/bitvector.h"
@@ -115,7 +112,7 @@ bitvector bv_new(int size) {
     /* n = (((size+7)/8) + sizeof(int) - 1)/sizeof(int);  */
        n = BV_NUM_INTS(size);
 
-       bv = DMNEW(int, n);
+       bv = DumpMemory_allocate(sizeof(int) * n);
 
        for(i = 0; i < n; i++) bv[i] = 0;
    
index b6187027d78c413e0109d37d06eb7f75fa245d05..a9cf705417b64af1b8e20768fc668a12899df058 100644 (file)
@@ -86,7 +86,7 @@ list_t *list_create_dump(int nodeoffset)
 {
        list_t *l;
 
-       l = DNEW(list_t);
+       l = DumpMemory_allocate(sizeof(list_t));
 
        l->mutex      = NULL;
        l->first      = NULL;
index 6d3da672117d1043022459beb9452cbc2116b7a5..b39df6b02bd33940159d8c780273e1928a9c93ff 100644 (file)
@@ -23,8 +23,8 @@
 */
 
 
-#ifndef _LIST_H
-#define _LIST_H
+#ifndef _TOOLBOX_LIST_H
+#define _TOOLBOX_LIST_H
 
 #include "config.h"
 
@@ -145,7 +145,7 @@ void   *list_prev(list_t *l, void *element);
 }
 #endif
 
-#endif /* _LIST_H */
+#endif /* _TOOLBOX_LIST_H */
 
 
 /*
index e27647b503ebca4cb350790d002238dbd09e2f4d..c63ddf8827f91b68d35225c7f09820a02111219d 100644 (file)
@@ -63,9 +63,9 @@ struct set {
 *******************************************************************************/
 
 set *set_new(unsigned capacity) {
-       set *s = DNEW(set);
+       set *s = DumpMemory_allocate(sizeof(set));
 
-       s->elements = DMNEW(void *, capacity);
+       s->elements = DumpMemory_allocate(sizeof(void*) * capacity);
        MZERO(s->elements, void *, capacity);
        s->capacity = capacity;
        s->size = 0;
index 355c98634dc2de31d1023816e742a0b69df1fbef..924679b7d96d049f3a32945ef869e600b89335fa 100644 (file)
 #ifndef _EXCEPTIONS_HPP
 #define _EXCEPTIONS_HPP
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 #include "config.h"
 #include "vm/types.h"
 
@@ -40,6 +36,10 @@ extern "C" {
 
 /* function prototypes ********************************************************/
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 java_handle_t *exceptions_get_exception(void);
 void           exceptions_set_exception(java_handle_t *o);
 void           exceptions_clear_exception(void);
index ef5545fff2cd74e61f8d501bcfa8cb13af29ac7f..a343bd4065d4ffdfd7f3ad7d5e7538fbd317de90 100644 (file)
@@ -108,11 +108,9 @@ static bool builtintable_init(void)
        descriptor_pool    *descpool;
        builtintable_entry *bte;
        methodinfo         *m;
-       int32_t             dumpmarker;
 
-       /* mark start of dump memory area */
-
-       DMARKER;
+       // Create new dump memory area.
+       DumpMemoryArea dma;
 
        /* create a new descriptor pool */
 
@@ -132,22 +130,15 @@ static bool builtintable_init(void)
                bte->name       = utf_new_char(bte->cname);
                bte->descriptor = utf_new_char(bte->cdescriptor);
 
-               if (!descriptor_pool_add(descpool, bte->descriptor, NULL)) {
-                       /* release dump area */
-
-                       DRELEASE;
-
+               if (!descriptor_pool_add(descpool, bte->descriptor, NULL))
                        return false;
-               }
        }
 
        for (bte = builtintable_automatic; bte->fp != NULL; bte++) {
                bte->descriptor = utf_new_char(bte->cdescriptor);
 
-               if (!descriptor_pool_add(descpool, bte->descriptor, NULL)) {
-                       DRELEASE;
+               if (!descriptor_pool_add(descpool, bte->descriptor, NULL))
                        return false;
-               }
        }
 
        for (bte = builtintable_function; bte->fp != NULL; bte++) {
@@ -155,10 +146,8 @@ static bool builtintable_init(void)
                bte->name       = utf_new_char(bte->cname);
                bte->descriptor = utf_new_char(bte->cdescriptor);
 
-               if (!descriptor_pool_add(descpool, bte->descriptor, NULL)) {
-                       DRELEASE;
+               if (!descriptor_pool_add(descpool, bte->descriptor, NULL))
                        return false;
-               }
        }
 
        /* create the class reference table */
@@ -214,10 +203,6 @@ static bool builtintable_init(void)
                }
        }
 
-       /* release dump area */
-
-       DRELEASE;
-
        return true;
 }
 
index c859984caf2aa029a4d35f4060c2b0d526aca121..4e88fb0a1fe6075623e25d05e42f1b0fb36f4e41 100644 (file)
@@ -111,6 +111,10 @@ struct codeinfo {
 };
 
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /* inline functions ***********************************************************/
 
 /* code_xxx_invalid ************************************************************
@@ -221,6 +225,10 @@ int code_get_sync_slot_count(codeinfo *code);
 
 void code_free_code_of_method(methodinfo *m);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* _CODE_H */
 
 
index a664dd42e57b4c0572481848685a579385b81060..1875ceb10716fd5c3d0ae6aaf59bf6fd7b3126f9 100644 (file)
@@ -217,13 +217,13 @@ jitdata *jit_jitdata_new(methodinfo *m)
 
        /* allocate jitdata structure and fill it */
 
-       jd = DNEW(jitdata);
+       jd = (jitdata*) DumpMemory::allocate(sizeof(jitdata));
 
        jd->m     = m;
-       jd->cd    = DNEW(codegendata);
-       jd->rd    = DNEW(registerdata);
+       jd->cd    = (codegendata*) DumpMemory::allocate(sizeof(codegendata));
+       jd->rd    = (registerdata*) DumpMemory::allocate(sizeof(registerdata));
 #if defined(ENABLE_LOOP)
-       jd->ld    = DNEW(loopdata);
+       jd->ld    = (loopdata*) DumpMemory::allocate(sizeof(loopdata));
 #endif
 
        /* Allocate codeinfo memory from the heap as we need to keep them. */
@@ -271,7 +271,6 @@ u1 *jit_compile(methodinfo *m)
 {
        u1      *r;
        jitdata *jd;
-       int32_t  dumpmarker;
 
        STATISTICS(count_jit_calls++);
 
@@ -320,9 +319,8 @@ u1 *jit_compile(methodinfo *m)
                compilingtime_start();
 #endif
 
-       /* mark start of dump memory area */
-
-       DMARKER;
+       // Create new dump memory area.
+       DumpMemoryArea dma;
 
        /* create jitdata structure */
 
@@ -404,10 +402,6 @@ u1 *jit_compile(methodinfo *m)
                DEBUG_JIT_COMPILEVERBOSE("Running: ");
        }
 
-       /* release dump area */
-
-       DRELEASE;
-
 #if defined(ENABLE_STATISTICS)
        /* measure time */
 
@@ -441,7 +435,6 @@ u1 *jit_recompile(methodinfo *m)
        u1      *r;
        jitdata *jd;
        u1       optlevel;
-       int32_t  dumpmarker;
 
        /* check for max. optimization level */
 
@@ -465,9 +458,8 @@ u1 *jit_recompile(methodinfo *m)
                compilingtime_start();
 #endif
 
-       /* mark start of dump memory area */
-
-       DMARKER;
+       // Create new dump memory area.
+       DumpMemoryArea dma;
 
        /* create jitdata structure */
 
@@ -521,10 +513,6 @@ u1 *jit_recompile(methodinfo *m)
                code_codeinfo_free(jd->code);
        }
 
-       /* release dump area */
-
-       DRELEASE;
-
 #if defined(ENABLE_STATISTICS)
        /* measure time */
 
@@ -759,7 +747,7 @@ static u1 *jit_compile_intern(jitdata *jd)
                        /*&& jd->exceptiontablelength == 0*/
                ) {
                        /*printf("=== %s ===\n", jd->m->name->text);*/
-                       jd->ls = DNEW(lsradata);
+                       jd->ls = (lsradata*) DumpMemory::allocate(sizeof(lsradata));
                        jd->ls = NULL;
                        ssa(jd);
                        /*lsra(jd);*/ regalloc(jd);
index 70b942431c92042f32d43a5d841527f78361dc87..ac9456ab0b40f90a50ad232567b4a36ea7b3c6c4 100644 (file)
@@ -25,7 +25,9 @@
 
 #include "config.h"
 
-#include "mm/dumpmemory.h"
+#include <stdint.h>
+
+#include "mm/dumpmemory.hpp"
 #include "mm/memory.h"
 
 #include "toolbox/bitvector.h"
index 77849914970156b122cb90dd336cfc25572245c4..b04045e5e19be336cf366e6d63c962725b29818a 100644 (file)
@@ -23,6 +23,8 @@
 */
 
 
+#include "config.h"
+
 #include "config.h"
 
 #include "mm/memory.h"
@@ -56,7 +58,7 @@ dominatordata *compute_Dominators(graphdata *gd, int basicblockcount) {
        graphiterator iter;
        dominatordata *dd;
 
-       dd = DNEW(dominatordata);
+       dd = (dominatordata*) DumpMemory::allocate(sizeof(dominatordata));
 
        dom_Dominators_init(dd, basicblockcount);
        
@@ -138,7 +140,7 @@ void computeDF(graphdata *gd, dominatordata *dd, int basicblockcount, int n) {
        bool *_S;
        graphiterator iter;
 
-       _S = DMNEW(bool, basicblockcount);
+       _S = (bool*) DumpMemory::allocate(sizeof(bool) * basicblockcount);
        for(i = 0; i < basicblockcount; i++)
                _S[i] = false;
        i = graph_get_first_successor(gd, n, &iter);
@@ -170,25 +172,25 @@ void computeDF(graphdata *gd, dominatordata *dd, int basicblockcount, int n) {
 void dom_Dominators_init(dominatordata *dd, int basicblockcount) {
        int i;
 
-       dd->dfnum  = DMNEW(int, basicblockcount);
-       dd->vertex = DMNEW(int, basicblockcount);
-       dd->parent = DMNEW(int, basicblockcount);
-       dd->semi   = DMNEW(int, basicblockcount);
-       dd->ancestor = DMNEW(int, basicblockcount);
-       dd->idom     = DMNEW(int, basicblockcount);
-       dd->samedom  = DMNEW(int, basicblockcount);
-       dd->bucket   = DMNEW(int*, basicblockcount);
-       dd->num_bucket = DMNEW(int, basicblockcount);
-       dd->DF       = DMNEW(int*, basicblockcount);
-       dd->num_DF   = DMNEW(int, basicblockcount);
-       dd->best     = DMNEW(int, basicblockcount);
+       dd->dfnum      = (int*)  DumpMemory::allocate(sizeof(int) * basicblockcount);
+       dd->vertex     = (int*)  DumpMemory::allocate(sizeof(int) * basicblockcount);
+       dd->parent     = (int*)  DumpMemory::allocate(sizeof(int) * basicblockcount);
+       dd->semi       = (int*)  DumpMemory::allocate(sizeof(int) * basicblockcount);
+       dd->ancestor   = (int*)  DumpMemory::allocate(sizeof(int) * basicblockcount);
+       dd->idom       = (int*)  DumpMemory::allocate(sizeof(int) * basicblockcount);
+       dd->samedom    = (int*)  DumpMemory::allocate(sizeof(int) * basicblockcount);
+       dd->bucket     = (int**) DumpMemory::allocate(sizeof(int*) * basicblockcount);
+       dd->num_bucket = (int*)  DumpMemory::allocate(sizeof(int) * basicblockcount);
+       dd->DF         = (int**) DumpMemory::allocate(sizeof(int*) * basicblockcount);
+       dd->num_DF     = (int*)  DumpMemory::allocate(sizeof(int) * basicblockcount);
+       dd->best       = (int*)  DumpMemory::allocate(sizeof(int) * basicblockcount);
        for (i=0; i < basicblockcount; i++) {
                dd->dfnum[i] = -1;
                dd->semi[i] = dd->ancestor[i] = dd->idom[i] = dd->samedom[i] = -1;
                dd->num_bucket[i] = 0;
-               dd->bucket[i] = DMNEW(int, basicblockcount);
+               dd->bucket[i] = (int*) DumpMemory::allocate(sizeof(int) * basicblockcount);
                dd->num_DF[i] = 0;
-               dd->DF[i] = DMNEW(int, basicblockcount);
+               dd->DF[i] = (int*) DumpMemory::allocate(sizeof(int) * basicblockcount);
        }
 }
 
@@ -289,16 +291,16 @@ static dominator_tree_info *dominator_tree_init(jitdata *jd) {
        basicblock *itb;
        basicblock_info *iti;
 
-       di = DNEW(dominator_tree_info);
+       di = (dominator_tree_info*) DumpMemory::allocate(sizeof(dominator_tree_info));
 
        di->jd = jd;
 
-       di->basicblocks = DMNEW(basicblock_info, jd->basicblockcount);
+       di->basicblocks = (basicblock_info*) DumpMemory::allocate(sizeof(basicblock_info) * jd->basicblockcount);
        MZERO(di->basicblocks, basicblock_info, jd->basicblockcount);
        
        for (iti = di->basicblocks; iti != di->basicblocks + jd->basicblockcount; ++iti) {
                iti->dfnum = -1;
-               iti->bucket = DMNEW(basicblock_info *, jd->basicblockcount);
+               iti->bucket = (basicblock_info**) DumpMemory::allocate(sizeof(basicblock_info*) * jd->basicblockcount);
                iti->bucketcount = 0;
        }
 
@@ -306,7 +308,7 @@ static dominator_tree_info *dominator_tree_init(jitdata *jd) {
                di->basicblocks[itb->nr].bb = itb;
        }
 
-       di->df_map = DMNEW(basicblock_info *, jd->basicblockcount);
+       di->df_map = (basicblock_info**) DumpMemory::allocate(sizeof(basicblock_info*) * jd->basicblockcount);
        MZERO(di->df_map, basicblock_info *, jd->basicblockcount);
 
        di->df_counter = 0;
@@ -432,22 +434,23 @@ void dominator_tree_build_intern(jitdata *jd) {
 
 void dominator_tree_link_children(jitdata *jd) {
        basicblock *bb;
-       int32_t ds;
        /* basicblock number => current number of successors */
        unsigned *numsuccessors;
 
+       // Create new dump memory area.
+       DumpMemoryArea dma();
+
        /* Allocate memory for successors */
 
        for (bb = jd->basicblocks; bb; bb = bb->next) {
                if (bb->domsuccessorcount > 0) {
-                       bb->domsuccessors = DMNEW(basicblock *, bb->domsuccessorcount);
+                       bb->domsuccessors = (basicblock**) DumpMemory::allocate(sizeof(basicblock*) * bb->domsuccessorcount);
                }
        }
 
        /* Allocate memory for per basic block counter of successors */
 
-       ds = dumpmemory_marker();
-       numsuccessors = DMNEW(unsigned, jd->basicblockcount);
+       numsuccessors = (unsigned*) DumpMemory::allocate(sizeof(unsigned) * jd->basicblockcount);
        MZERO(numsuccessors, unsigned, jd->basicblockcount);
 
        /* Link immediate dominators with successors */
@@ -458,18 +461,13 @@ void dominator_tree_link_children(jitdata *jd) {
                        numsuccessors[bb->idom->nr] += 1;
                }
        }
-
-       /* Free memory */
-
-       dumpmemory_release(ds);
 }
 
 bool dominator_tree_build(jitdata *jd) {
-       int32_t ds;
-       
-       ds = dumpmemory_marker();
+       // Create new dump memory area.
+       DumpMemoryArea dma();
+
        dominator_tree_build_intern(jd);
-       dumpmemory_release(ds);
 
        dominator_tree_link_children(jd);
 
@@ -497,7 +495,7 @@ void dominance_frontier_list_add(dominance_frontier_list *list, basicblock *bb)
                if (item->bb == bb) return;
        }
 
-       item = DNEW(dominance_frontier_item);
+       item = (dominance_frontier_item*) DumpMemory::allocate(sizeof(dominance_frontier_item));
        item->bb = bb;
        item->next = list->first;
        list->first = item;
@@ -512,11 +510,11 @@ struct dominance_frontier_info {
 };
 
 dominance_frontier_info *dominance_frontier_init(jitdata *jd) {
-       dominance_frontier_info *dfi = DNEW(dominance_frontier_info);
+       dominance_frontier_info *dfi = (dominance_frontier_info*) DumpMemory::allocate(sizeof(dominance_frontier_info));
 
        dfi->jd = jd;
 
-       dfi->map = DMNEW(dominance_frontier_list, jd->basicblockcount);
+       dfi->map = (dominance_frontier_list*) DumpMemory::allocate(sizeof(dominance_frontier_list) * jd->basicblockcount);
        MZERO(dfi->map, dominance_frontier_list, jd->basicblockcount);
 
        return dfi;
@@ -567,7 +565,7 @@ void dominance_frontier_store(dominance_frontier_info *dfi) {
                if (bb->nr < dfi->jd->basicblockcount) {
                        if (dfi->map[bb->nr].count > 0) {
                                bb->domfrontiercount = dfi->map[bb->nr].count;
-                               itout = bb->domfrontier = DMNEW(basicblock *, bb->domfrontiercount);
+                               itout = bb->domfrontier = (basicblock**) DumpMemory::allocate(sizeof(basicblock*) * bb->domfrontiercount);
                                for (itdf = dfi->map[bb->nr].first; itdf; itdf = itdf->next) {
                                        *itout = itdf->bb;
                                        itout += 1;
@@ -578,7 +576,8 @@ void dominance_frontier_store(dominance_frontier_info *dfi) {
 }
 
 bool dominance_frontier_build(jitdata *jd) {
-       int32_t ds = dumpmemory_marker();
+       // Create new dump memory area.
+       DumpMemoryArea dma();
 
        dominance_frontier_info *dfi = dominance_frontier_init(jd);
        dominance_frontier_for_block(dfi, jd->basicblocks);
@@ -591,7 +590,6 @@ bool dominance_frontier_build(jitdata *jd) {
 extern "C" void graph_add_edge( graphdata *gd, int from, int to );
 
 void dominator_tree_validate(jitdata *jd, dominatordata *_dd) {
-       int32_t ds = dumpmemory_marker();
        graphdata *gd;
        int i, j;
        basicblock *bptr, **it;
@@ -599,6 +597,9 @@ void dominator_tree_validate(jitdata *jd, dominatordata *_dd) {
        int *itnr;
        bool found;
 
+       // Create new dump memory area.
+       DumpMemoryArea dma();
+
        fprintf(stderr, "%s/%s: \n", jd->m->clazz->name->text, jd->m->name->text);
        gd = graph_init(jd->basicblockcount);
 
@@ -639,10 +640,9 @@ void dominator_tree_validate(jitdata *jd, dominatordata *_dd) {
                        }
                }
        }
-
-       dumpmemory_release(ds);
 }
 
+
 /*
  * These are local overrides for various environment variables in Emacs.
  * Please do not remove this and leave it at the end of the file, where
index 10b2251654744d9341eb415110c79cdf8ba116be..bd7df65b9716c14d77d79d99feed5de4ee0def40 100644 (file)
@@ -63,6 +63,9 @@ typedef struct dominatordata dominatordata;
 
 /* function prototypes */
 
+#ifdef __cplusplus
+extern "C" {
+#endif
 
 dominatordata *compute_Dominators(graphdata *gd, int basicblockcount);
 void computeDF(graphdata *gd, dominatordata *dd, int basicblockcount, int n);
@@ -75,7 +78,12 @@ bool dominance_frontier_build(jitdata *jd);
 
 void dominator_tree_validate(jitdata *jd, dominatordata *dd);
 
-#endif /* _DOMINATORS_H */
+#ifdef __cplusplus
+}
+#endif
+
+#endif // _DOMINATORS_HPP
+
 
 /*
  * These are local overrides for various environment variables in Emacs.
index 4e891051b3f42f4844d9d85ebd75f7d892e18dc1..5a8da53d0fe9f78f5a4f6f2a479be34b41aae650 100644 (file)
    * Unify access to phi args.
 */
 
+
+#include "config.h"
+
 #include "vm/jit/jit.hpp"
 #include "vm/global.h"
 #include "mm/memory.h"
-#include "mm/dumpmemory.h"
+#include "mm/dumpmemory.hpp"
 #include "toolbox/list.h"
 
 #include <limits.h>
index a4ea93b19b7deb217a3e33d6efbebfecb93f86c6..97ff92d10a7667dbeffdc8bcbdec7369a71a71ea 100644 (file)
@@ -37,6 +37,7 @@
 # include "mm/cacao-gc/gc.h"
 #endif
 
+#include "mm/dumpmemory.hpp"
 #include "mm/memory.h"
 
 #include "threads/thread.hpp"
@@ -446,7 +447,7 @@ bool replace_create_replacement_points(jitdata *jd)
        count = 0;
        alloccount = 0;
 
-       javalocals = DMNEW(s4, jd->maxlocals);
+       javalocals = (s4*) DumpMemory::allocate(sizeof(s4) * jd->maxlocals);
 
        for (bptr = jd->basicblocks; bptr; bptr = bptr->next) {
 
@@ -1082,7 +1083,7 @@ static sourceframe_t *replace_new_sourceframe(sourcestate_t *ss)
 {
        sourceframe_t *frame;
 
-       frame = DNEW(sourceframe_t);
+       frame = (sourceframe_t*) DumpMemory::allocate(sizeof(sourceframe_t));
        MZERO(frame, sourceframe_t, 1);
 
        frame->down = ss->frames;
@@ -1169,8 +1170,8 @@ static void replace_read_executionstate(rplpoint *rp,
 
        count = m->maxlocals;
        frame->javalocalcount = count;
-       frame->javalocals = DMNEW(replace_val_t, count);
-       frame->javalocaltype = DMNEW(u1, count);
+       frame->javalocals = (replace_val_t*) DumpMemory::allocate(sizeof(replace_val_t) * count);
+       frame->javalocaltype = (u1*) DumpMemory::allocate(sizeof(u1) * count);
 
        /* mark values as undefined */
        for (i=0; i<count; ++i) {
@@ -1244,8 +1245,8 @@ static void replace_read_executionstate(rplpoint *rp,
        /* read stack slots */
 
        frame->javastackdepth = count;
-       frame->javastack = DMNEW(replace_val_t, count);
-       frame->javastacktype = DMNEW(u1, count);
+       frame->javastack = (replace_val_t*) DumpMemory::allocate(sizeof(replace_val_t) * count);
+       frame->javastacktype = (u1*) DumpMemory::allocate(sizeof(u1) * count);
 
 #if !defined(NDEBUG)
        /* mark values as undefined */
@@ -1307,7 +1308,7 @@ static void replace_read_executionstate(rplpoint *rp,
                                assert(calleeframe->syncslots == NULL);
 
                                calleeframe->syncslotcount = 1;
-                               calleeframe->syncslots = DMNEW(replace_val_t, 1);
+                               calleeframe->syncslots = (replace_val_t*) DumpMemory::allocate(sizeof(replace_val_t));
                                replace_read_value(es,ra,calleeframe->syncslots);
                        }
 
@@ -1797,7 +1798,7 @@ u1* replace_pop_activation_record(executionstate_t *es,
        assert(frame->syncslots == NULL);
        count = code_get_sync_slot_count(es->code);
        frame->syncslotcount = count;
-       frame->syncslots = DMNEW(replace_val_t, count);
+       frame->syncslots = (replace_val_t*) DumpMemory::allocate(sizeof(replace_val_t) * count);
        for (i=0; i<count; ++i) {
                frame->syncslots[i].p = sp[es->code->memuse + i]; /* XXX md_ function */
        }
@@ -2515,7 +2516,7 @@ sourcestate_t *replace_recover_source_state(rplpoint *rp,
 
        /* create the source frame structure in dump memory */
 
-       ss = DNEW(sourcestate_t);
+       ss = (sourcestate_t*) DumpMemory::allocate(sizeof(sourcestate_t));
        ss->frames = NULL;
 
        /* each iteration of the loop recovers one source frame */
@@ -2865,7 +2866,6 @@ static void replace_me(rplpoint *rp, executionstate_t *es)
 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
        threadobject        *thread;
 #endif
-       int32_t              dumpmarker;
 
        origcode = es->code;
        origrp   = rp;
@@ -2885,9 +2885,8 @@ static void replace_me(rplpoint *rp, executionstate_t *es)
 
        REPLACE_COUNT(stat_replacements);
 
-       /* mark start of dump memory area */
-
-       DMARKER;
+       // Create new dump memory area.
+       DumpMemoryArea dma();
 
        /* Get the stackframeinfo for the current thread. */
 
@@ -2967,10 +2966,6 @@ static void replace_me(rplpoint *rp, executionstate_t *es)
        if (opt_TestReplacement)
                es->pc += REPLACEMENT_PATCH_SIZE;
 #endif
-
-       /* release dump area */
-
-       DRELEASE;
 }
 
 
@@ -3084,7 +3079,7 @@ void replace_gc_from_native(threadobject *thread, u1 *pc, u1 *sp)
        sfi = threads_get_current_stackframeinfo();
 
        /* create the execution state */
-       es = DNEW(executionstate_t);
+       es = (executionstate_t*) DumpMemory::allocate(sizeof(executionstate_t));
        es->pc = pc;
        es->sp = sp;
        es->pv = 0;      /* since we are in a native, PV is invalid! */
index 3c52ed352092328ce36a2ce1ab3ae14be593d9d3..6075ffa8f689b871060814bf10e15c8de5630757 100644 (file)
@@ -1558,7 +1558,6 @@ void show_filters_apply(methodinfo *m) {
        int res;
        char *method_name;
        s4 len;
-       int32_t dumpmarker;
 
        /* compose full name of method */
 
@@ -1569,9 +1568,7 @@ void show_filters_apply(methodinfo *m) {
                utf_bytes(m->descriptor) +
                1;
 
-       DMARKER;
-
-       method_name = DMNEW(char, len);
+       method_name = MNEW(char, len);
 
        utf_cat_classname(method_name, m->clazz->name);
        strcat(method_name, ".");
@@ -1596,9 +1593,8 @@ void show_filters_apply(methodinfo *m) {
                }
        }
 
-       /* release memory */
-
-       DRELEASE; 
+       // Release memory.
+       MFREE(method_name, char, len);
 }
 
 #define STATE_IS_INITIAL() ((FILTERVERBOSECALLCTR[0] == 0) && (FILTERVERBOSECALLCTR[1] == 0))
index 2d449c3dc2a62559dbce14c824b3792ffe05c1e9..a3e847162b351412a73332237f868995d190133f 100644 (file)
 #ifndef _STACKTRACE_HPP
 #define _STACKTRACE_HPP
 
-// FIXME Use C-linkage for now.
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 /* forward typedefs ***********************************************************/
 
 typedef struct stackframeinfo_t   stackframeinfo_t;
@@ -99,6 +94,11 @@ struct stacktrace_t {
 
 /* function prototypes ********************************************************/
 
+// FIXME Use C-linkage for now.
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 void                       stacktrace_stackframeinfo_add(stackframeinfo_t* sfi, void* pv, void* sp, void* ra, void* xpc);
 void                       stacktrace_stackframeinfo_remove(stackframeinfo_t *sfi);
 
index 08b74fb3596e75b2dad5794a03a6ab4c419bc5f4..6827c385948a39c52cdb96378eecc18399219d2f 100644 (file)
@@ -31,7 +31,7 @@
 // Include machine dependent headers.
 #include "md.h"
 
-#include "mm/dumpmemory.h"
+#include "mm/dumpmemory.hpp"
 
 #include "vm/method.h"
 #include "vm/options.h"
@@ -59,18 +59,16 @@ void* CompilerStub::generate(methodinfo *m)
        codegendata *cd;
        ptrint      *d;                     /* pointer to data memory             */
        u1          *c;                     /* pointer to code memory             */
-       int32_t      dumpmarker;
 
-       /* mark dump memory */
-
-       DMARKER;
+       // Create new dump memory area.
+       DumpMemoryArea dma;
 
        /* allocate required data structures */
 
-       jd = DNEW(jitdata);
+       jd = (jitdata*) DumpMemory::allocate(sizeof(jitdata));
 
        jd->m     = m;
-       jd->cd    = DNEW(codegendata);
+       jd->cd    = (codegendata*) DumpMemory::allocate(sizeof(codegendata));
        jd->flags = 0;
 
        /* get required compiler data */
@@ -144,10 +142,6 @@ void* CompilerStub::generate(methodinfo *m)
        md_cacheflush(cd->mcodebase, 2 * SIZEOF_VOID_P + get_code_size());
 #endif
 
-       /* release dump memory */
-
-       DRELEASE;
-
        /* return native stub code */
 
        return c;
@@ -201,11 +195,9 @@ void BuiltinStub::generate(methodinfo* m, builtintable_entry* bte)
        jitdata  *jd;
        codeinfo *code;
        int       skipparams;
-       int32_t   dumpmarker;
 
-       /* mark dump memory */
-
-       DMARKER;
+       // Create new dump memory area.
+       DumpMemoryArea dma;
 
        /* Create JIT data structure. */
 
@@ -267,10 +259,6 @@ void BuiltinStub::generate(methodinfo* m, builtintable_entry* bte)
                        dseg_display(jd);
        }
 #endif /* !defined(NDEBUG) && defined(ENABLE_DISASSEMBLER) */
-
-       /* release memory */
-
-       DRELEASE;
 }
 
 
@@ -289,11 +277,9 @@ codeinfo* NativeStub::generate(methodinfo* m, functionptr f)
        methoddesc  *md;
        methoddesc  *nmd;       
        int          skipparams;
-       int32_t      dumpmarker;
-
-       /* mark dump memory */
 
-       DMARKER;
+       // Create new dump memory area.
+       DumpMemoryArea dma;
 
        /* Create JIT data structure. */
 
@@ -339,13 +325,13 @@ codeinfo* NativeStub::generate(methodinfo* m, functionptr f)
        else
                skipparams = 1;
        
-       nmd = (methoddesc *) DMNEW(u1, sizeof(methoddesc) - sizeof(typedesc) +
-                                                          md->paramcount * sizeof(typedesc) +
-                                                          skipparams * sizeof(typedesc));
+       nmd = (methoddesc*) DumpMemory::allocate(sizeof(methoddesc) - sizeof(typedesc) +
+                                                                                        md->paramcount * sizeof(typedesc) +
+                                                                                        skipparams * sizeof(typedesc));
 
        nmd->paramcount = md->paramcount + skipparams;
 
-       nmd->params = DMNEW(paramdesc, nmd->paramcount);
+       nmd->params = (paramdesc*) DumpMemory::allocate(sizeof(paramdesc) * nmd->paramcount);
 
        nmd->paramtypes[0].type = TYPE_ADR; /* add environment pointer            */
 
@@ -408,10 +394,6 @@ codeinfo* NativeStub::generate(methodinfo* m, functionptr f)
        }
 #endif /* !defined(NDEBUG) && defined(ENABLE_DISASSEMBLER) */
 
-       /* release memory */
-
-       DRELEASE;
-
        /* return native stub code */
 
        return code;
index 86a6e0a613b0ea08fca5dfb3b24e1c14ffaef4cd..ebd26a390290ac29c11b2033f5ca7af2bf180230 100644 (file)
@@ -135,7 +135,7 @@ static char *trace_java_call_print_argument(methodinfo *m, char *logtext, s4 *lo
 
                                /* realloc memory for string length */
 
-                               logtext = DMREALLOC(logtext, char, *logtextlen, *logtextlen + len);
+                               logtext = (char*) DumpMemory::reallocate(logtext, *logtextlen, *logtextlen + len);
                                *logtextlen += len;
 
                                /* convert to utf8 string and strcat it to the logtext */
@@ -165,7 +165,7 @@ static char *trace_java_call_print_argument(methodinfo *m, char *logtext, s4 *lo
 
                                /* realloc memory for string length */
 
-                               logtext = DMREALLOC(logtext, char, *logtextlen, *logtextlen + len);
+                               logtext = (char*) DumpMemory::reallocate(logtext, *logtextlen, *logtextlen + len);
                                *logtextlen += len;
 
                                /* strcat to the logtext */
@@ -201,7 +201,6 @@ void trace_java_call_enter(methodinfo *m, uint64_t *arg_regs, uint64_t *stack)
        s4          logtextlen;
        s4          i;
        s4          pos;
-       int32_t     dumpmarker;
 
        /* We don't trace builtin functions here because the argument
           passing happens via the native ABI and does not fit these
@@ -259,11 +258,11 @@ void trace_java_call_enter(methodinfo *m, uint64_t *arg_regs, uint64_t *stack)
                strlen("...(255)") +
                strlen(")");
 
-       /* allocate memory */
+       // Create new dump memory area.
+       DumpMemoryArea dma();
 
-       DMARKER;
-
-       logtext = DMNEW(char, logtextlen);
+       // TODO Use a std::string here.
+       logtext = (char*) DumpMemory::allocate(sizeof(char) * logtextlen);
 
        TRACEJAVACALLCOUNT++;
 
@@ -312,12 +311,7 @@ void trace_java_call_enter(methodinfo *m, uint64_t *arg_regs, uint64_t *stack)
 
        log_text(logtext);
 
-       /* release memory */
-
-       DRELEASE;
-
        TRACEJAVACALLINDENT++;
-
 }
 
 /* trace_java_call_exit ********************************************************
@@ -338,7 +332,6 @@ void trace_java_call_exit(methodinfo *m, uint64_t *return_regs)
        s4          i;
        s4          pos;
        imm_union   val;
-       int32_t     dumpmarker;
 
        /* We don't trace builtin functions here because the argument
           passing happens via the native ABI and does not fit these
@@ -383,11 +376,11 @@ void trace_java_call_exit(methodinfo *m, uint64_t *return_regs)
 
        logtextlen += strlen("->0.4872328470301428 (0x0123456789abcdef)");
 
-       /* allocate memory */
+       // Create new dump memory area.
+       DumpMemoryArea dma();
 
-       DMARKER;
-
-       logtext = DMNEW(char, logtextlen);
+       // TODO Use a std::string here.
+       logtext = (char*) DumpMemory::allocate(sizeof(char) * logtextlen);
 
        /* generate the message */
 
@@ -418,10 +411,6 @@ void trace_java_call_exit(methodinfo *m, uint64_t *return_regs)
        }
 
        log_text(logtext);
-
-       /* release memory */
-
-       DRELEASE;
 }
 
 
@@ -436,7 +425,6 @@ void trace_exception(java_object_t *xptr, methodinfo *m, void *pos)
        char *logtext;
        s4    logtextlen;
        codeinfo *code;
-       int32_t   dumpmarker;
 
        /* calculate message length */
 
@@ -479,11 +467,11 @@ void trace_exception(java_object_t *xptr, methodinfo *m, void *pos)
 
        logtextlen += strlen("0");
 
-       /* allocate memory */
+       // Create new dump memory area.
+       DumpMemoryArea dma();
 
-       DMARKER;
-
-       logtext = DMNEW(char, logtextlen);
+       // TODO Use a std::string here.
+       logtext = (char*) DumpMemory::allocate(sizeof(char) * logtextlen);
 
        if (xptr) {
                strcpy(logtext, "Exception ");
@@ -549,10 +537,6 @@ void trace_exception(java_object_t *xptr, methodinfo *m, void *pos)
                strcat(logtext, "call_java_method");
 
        log_text(logtext);
-
-       /* release memory */
-
-       DRELEASE;
 }
 
 
@@ -566,7 +550,6 @@ void trace_exception_builtin(java_handle_t* h)
 {
        char                *logtext;
        s4                   logtextlen;
-       int32_t              dumpmarker;
 
        java_lang_Throwable jlt(h);
 
@@ -595,11 +578,10 @@ void trace_exception_builtin(java_handle_t* h)
                logtextlen += strlen("(nil)");
        }
 
-       /* allocate memory */
+       // Create new dump memory area.
+       DumpMemoryArea dma();
 
-       DMARKER;
-
-       logtext = DMNEW(char, logtextlen);
+       logtext = (char*) DumpMemory::allocate(sizeof(char) * logtextlen);
 
        strcpy(logtext, "Builtin exception thrown: ");
 
@@ -620,10 +602,6 @@ void trace_exception_builtin(java_handle_t* h)
        }
 
        log_text(logtext);
-
-       /* release memory */
-
-       DRELEASE;
 }
 
 } // extern "C"
index b2dcab6f97e48eee7f481d2b44041c471663aab6..e7417acaad154872063f86c12764645c4951eb8a 100644 (file)
@@ -31,6 +31,7 @@
 
 #include "vm/types.h"
 
+#include "mm/dumpmemory.hpp"
 #include "mm/memory.h"
 
 #include "native/llni.h"
@@ -589,7 +590,8 @@ static bool load_constantpool(classbuffer *cb, descriptor_pool *descpool)
 
                switch (t) {
                case CONSTANT_Class:
-                       nfc = DNEW(forward_class);
+#warning Use list.
+                       nfc = (forward_class*) DumpMemory::allocate(sizeof(forward_class));
 
                        nfc->next = forward_classes;
                        forward_classes = nfc;
@@ -605,7 +607,8 @@ static bool load_constantpool(classbuffer *cb, descriptor_pool *descpool)
                        break;
                        
                case CONSTANT_String:
-                       nfs = DNEW(forward_string);
+#warning Use list.
+                       nfs = (forward_string*) DumpMemory::allocate(sizeof(forward_string));
                                
                        nfs->next = forward_strings;
                        forward_strings = nfs;
@@ -622,7 +625,8 @@ static bool load_constantpool(classbuffer *cb, descriptor_pool *descpool)
                        break;
 
                case CONSTANT_NameAndType:
-                       nfn = DNEW(forward_nameandtype);
+#warning Use list.
+                       nfn = (forward_nameandtype*) DumpMemory::allocate(sizeof(forward_nameandtype));
                                
                        nfn->next = forward_nameandtypes;
                        forward_nameandtypes = nfn;
@@ -645,7 +649,8 @@ static bool load_constantpool(classbuffer *cb, descriptor_pool *descpool)
                case CONSTANT_Fieldref:
                case CONSTANT_Methodref:
                case CONSTANT_InterfaceMethodref:
-                       nff = DNEW(forward_fieldmethint);
+#warning Use list.
+                       nff = (forward_fieldmethint*) DumpMemory::allocate(sizeof(forward_fieldmethint));
                        
                        nff->next = forward_fieldmethints;
                        forward_fieldmethints = nff;
@@ -1397,6 +1402,9 @@ static bool load_class_from_classbuffer_intern(classbuffer *cb)
                                        time_parsecpool, time_verify, time_attrs;
 #endif
 
+       // Create new dump memory area.
+       DumpMemoryArea dma;
+
        RT_TIMING_GET_TIME(time_start);
 
        /* Get the classbuffer's class. */
@@ -1557,7 +1565,7 @@ static bool load_class_from_classbuffer_intern(classbuffer *cb)
 
        /* Get the names of the super interfaces. */
 
-       interfacesnames = DMNEW(utf*, c->interfacescount);
+       interfacesnames = (utf**) DumpMemory::allocate(sizeof(utf*) * c->interfacescount);
 
        for (int32_t i = 0; i < c->interfacescount; i++) {
                index = suck_u2(cb);
@@ -1946,7 +1954,6 @@ classinfo *load_class_from_classbuffer(classbuffer *cb)
 {
        classinfo *c;
        bool       result;
-       int32_t    dumpmarker;
 
        /* Get the classbuffer's class. */
 
@@ -1967,10 +1974,6 @@ classinfo *load_class_from_classbuffer(classbuffer *cb)
                log_message_class("Loading class: ", c);
 #endif
 
-       /* Mark start of dump memory area. */
-
-       DMARKER;
-
        /* Class is currently loading. */
 
        c->state |= CLASS_LOADING;
@@ -1979,10 +1982,6 @@ classinfo *load_class_from_classbuffer(classbuffer *cb)
 
        result = load_class_from_classbuffer_intern(cb);
 
-       /* Release dump area. */
-
-       DRELEASE;
-
        /* An error occurred. */
 
        if (result == false) {
index bf88132432128eec790c7e891d6cdac1f4413810..2f9d5b305c92f650e6b5007f1e620fa294adb95c 100644 (file)
@@ -116,6 +116,10 @@ struct unresolved_method {
 
 /* function prototypes ********************************************************/
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 void resolve_handle_pending_exception(bool throwError);
 
 bool resolve_class_from_name(classinfo* referer,methodinfo *refmethod,
@@ -257,6 +261,10 @@ void unresolved_field_debug_dump(unresolved_field *ref,FILE *file);
 void unresolved_method_debug_dump(unresolved_method *ref,FILE *file);
 void unresolved_subtype_set_debug_dump(unresolved_subtype_set *stset,FILE *file);
 #endif
+
+#ifdef __cplusplus
+}
+#endif
        
 #endif /* _RESOLVE_H */
 
index 93c154abb43fb3e6e8532fc88d9b3c9c802e048f..0e232dfd7dc91c5e546a956fef8333c3d2987d2e 100644 (file)
@@ -41,6 +41,7 @@
 #include "vm/jit/abi-asm.h"
 
 #include "mm/codememory.h"
+#include "mm/dumpmemory.hpp"
 #include "mm/gc.hpp"
 #include "mm/memory.h"
 
@@ -2484,19 +2485,18 @@ type vm_call_method##name##_valist(methodinfo *m, java_handle_t *o,     \
 {                                                                       \
        uint64_t *array;                                                    \
        type      value;                                                    \
-       int32_t   dumpmarker;                                               \
                                                                         \
        if (m->code == NULL)                                                \
                if (!jit_compile(m))                                            \
                        return 0;                                                   \
                                                                         \
        THREAD_NATIVEWORLD_EXIT;                                            \
-       DMARKER;                                                            \
+                                                                                                                                               \
+       DumpMemoryArea dma;                                                                                                     \
                                                                         \
        array = argument_vmarray_from_valist(m, o, ap);                     \
        value = vm_call##name##_array(m, array);                            \
                                                                         \
-       DRELEASE;                                                           \
        THREAD_NATIVEWORLD_ENTER;                                           \
                                                                         \
        return value;                                                       \
@@ -2522,19 +2522,18 @@ type vm_call_method##name##_jvalue(methodinfo *m, java_handle_t *o,     \
 {                                                                       \
        uint64_t *array;                                                    \
        type      value;                                                    \
-       int32_t   dumpmarker;                                               \
                                                                         \
        if (m->code == NULL)                                                \
                if (!jit_compile(m))                                            \
                        return 0;                                                   \
                                                                         \
        THREAD_NATIVEWORLD_EXIT;                                            \
-       DMARKER;                                                            \
+                                                                                                                                               \
+       DumpMemoryArea dma;                                                                                                     \
                                                                         \
        array = argument_vmarray_from_jvalue(m, o, args);                   \
        value = vm_call##name##_array(m, array);                            \
                                                                         \
-       DRELEASE;                                                           \
        THREAD_NATIVEWORLD_ENTER;                                           \
                                                                         \
        return value;                                                       \
@@ -2561,7 +2560,6 @@ java_handle_t *vm_call_method_objectarray(methodinfo *m, java_handle_t *o,
        java_handle_t *xptr;
        java_handle_t *ro;
        imm_union      value;
-       int32_t        dumpmarker;
 
        /* Prevent compiler warnings. */
 
@@ -2577,19 +2575,14 @@ java_handle_t *vm_call_method_objectarray(methodinfo *m, java_handle_t *o,
 
        THREAD_NATIVEWORLD_EXIT;
 
-       /* mark start of dump memory area */
-
-       DMARKER;
+       // Create new dump memory area.
+       DumpMemoryArea dma;
 
        /* Fill the argument array from a object-array. */
 
        array = argument_vmarray_from_objectarray(m, o, params);
 
        if (array == NULL) {
-               /* release dump area */
-
-               DRELEASE;
-
                /* enter the nativeworld again */
 
                THREAD_NATIVEWORLD_ENTER;
@@ -2632,10 +2625,6 @@ java_handle_t *vm_call_method_objectarray(methodinfo *m, java_handle_t *o,
                VM::get_current()->abort("vm_call_method_objectarray: invalid return type %d", m->parseddesc->returntype.primitivetype);
        }
 
-       /* release dump area */
-
-       DRELEASE;
-
        /* enter the nativeworld again */
 
        THREAD_NATIVEWORLD_ENTER;