* 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
libmm_la_SOURCES = \
codememory.c \
codememory.h \
- dumpmemory.c \
- dumpmemory.h \
+ dumpmemory.cpp \
+ dumpmemory.hpp \
$(GC_FILE) \
gc.hpp \
memory.c \
+++ /dev/null
-/* 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:
- */
--- /dev/null
+/* 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:
+ */
+++ /dev/null
-/* 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:
- */
--- /dev/null
+/* 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:
+ */
#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"
*/
-#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)))
/* function prototypes ********************************************************/
+#ifdef __cplusplus
+extern "C" {
+#endif
+
bool memory_init(void);
void memory_mprotect(void *addr, size_t len, int prot);
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>
unsigned overflows;
} tlh_t;
+#ifdef __cplusplus
+extern "C" {
+#endif
+
void tlh_init(tlh_t *tlh);
void tlh_destroy(tlh_t *tlh);
void *tlh_alloc(tlh_t *tlh, size_t size);
+#ifdef __cplusplus
+}
+#endif
+
#endif
/*
#ifndef _LLNI_H
#define _LLNI_H
-#ifdef __cplusplus
-extern "C" {
-#endif
-
#include "config.h"
/* forward defines ************************************************************/
# 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);
u2 c;
s4 i;
utf *u;
- int32_t dumpmarker;
-
- /* mark memory */
-
- DMARKER;
utf_ptr = descriptor->text;
namelen = strlen(name->text) + strlen("__") + strlen("0");
i = strlen(name->text);
- newname = DMNEW(char, namelen);
+ newname = MNEW(char, namelen);
MCOPY(newname, name->text, char, i);
utf_ptr = descriptor->text;
/* release memory */
- DRELEASE;
+ MFREE(newname, char, namelen);
return u;
}
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
/* allocate memory */
- name = DMNEW(char, namelen);
+ name = MNEW(char, namelen);
/* generate name of native functions */
/* release memory */
- DRELEASE;
+ MFREE(name, char, namelen);
return u;
}
# include <mach/mach.h>
#endif
-#include "mm/dumpmemory.h"
+#include "mm/memory.h"
#include "mm/gc.hpp"
#include "native/jni.hpp"
char *buffer;
int32_t buffer_len;
java_handle_t *o;
- int32_t dumpmarker;
if (libname == NULL) {
exceptions_throw_nullpointerexception();
strlen(NATIVE_LIBRARY_SUFFIX) +
strlen("0");
- DMARKER;
-
- buffer = DMNEW(char, buffer_len);
+ buffer = MNEW(char, buffer_len);
/* generate library name */
/* release memory */
- DRELEASE;
+ MFREE(buffer, char, buffer_len);
return (jstring) o;
}
#include "config.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
-
#include <pthread.h>
#include "vm/types.h"
#include "vm/global.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
/* typedefs *******************************************************************/
#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. */
t->es = NULL;
#endif
- MZERO(&t->dumpinfo, dumpinfo_t, 1);
+ // Simply reuse the existing dump memory.
}
/* threads_impl_thread_reuse ***************************************************
#endif
-} // extern "C"
-
/*
* These are local overrides for various environment variables in Emacs.
#ifndef _THREAD_POSIX_HPP
#define _THREAD_POSIX_HPP
-/* forward typedefs ***********************************************************/
-
-typedef struct threadobject threadobject;
-
-
#include "config.h"
#include <pthread.h>
#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 ****************************************************************
#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 */
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 */
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 */
};
+/* 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)
#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;
}
-/* 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;
#include "vm/jit/stacktrace.hpp"
-// FIXME
-extern "C" {
-
/* global variables ***********************************************************/
static methodinfo *thread_method_init;
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. */
threadlist_unlock();
}
-} // extern "C"
-
/*
* These are local overrides for various environment variables in Emacs.
#include "config.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
-
#include "vm/types.h"
// Include early to get threadobject.
#endif
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/* inline functions ***********************************************************/
/* thread_get_object ***********************************************************
/* 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"
/* 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;
{
list_t *l;
- l = DNEW(list_t);
+ l = DumpMemory_allocate(sizeof(list_t));
l->mutex = NULL;
l->first = NULL;
*/
-#ifndef _LIST_H
-#define _LIST_H
+#ifndef _TOOLBOX_LIST_H
+#define _TOOLBOX_LIST_H
#include "config.h"
}
#endif
-#endif /* _LIST_H */
+#endif /* _TOOLBOX_LIST_H */
/*
*******************************************************************************/
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;
#ifndef _EXCEPTIONS_HPP
#define _EXCEPTIONS_HPP
-#ifdef __cplusplus
-extern "C" {
-#endif
-
#include "config.h"
#include "vm/types.h"
/* 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);
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 */
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++) {
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 */
}
}
- /* release dump area */
-
- DRELEASE;
-
return true;
}
};
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/* inline functions ***********************************************************/
/* code_xxx_invalid ************************************************************
void code_free_code_of_method(methodinfo *m);
+#ifdef __cplusplus
+}
+#endif
+
#endif /* _CODE_H */
/* 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. */
{
u1 *r;
jitdata *jd;
- int32_t dumpmarker;
STATISTICS(count_jit_calls++);
compilingtime_start();
#endif
- /* mark start of dump memory area */
-
- DMARKER;
+ // Create new dump memory area.
+ DumpMemoryArea dma;
/* create jitdata structure */
DEBUG_JIT_COMPILEVERBOSE("Running: ");
}
- /* release dump area */
-
- DRELEASE;
-
#if defined(ENABLE_STATISTICS)
/* measure time */
u1 *r;
jitdata *jd;
u1 optlevel;
- int32_t dumpmarker;
/* check for max. optimization level */
compilingtime_start();
#endif
- /* mark start of dump memory area */
-
- DMARKER;
+ // Create new dump memory area.
+ DumpMemoryArea dma;
/* create jitdata structure */
code_codeinfo_free(jd->code);
}
- /* release dump area */
-
- DRELEASE;
-
#if defined(ENABLE_STATISTICS)
/* measure time */
/*&& 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);
#include "config.h"
-#include "mm/dumpmemory.h"
+#include <stdint.h>
+
+#include "mm/dumpmemory.hpp"
#include "mm/memory.h"
#include "toolbox/bitvector.h"
*/
+#include "config.h"
+
#include "config.h"
#include "mm/memory.h"
graphiterator iter;
dominatordata *dd;
- dd = DNEW(dominatordata);
+ dd = (dominatordata*) DumpMemory::allocate(sizeof(dominatordata));
dom_Dominators_init(dd, basicblockcount);
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);
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);
}
}
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;
}
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;
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 */
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);
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;
};
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;
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;
}
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);
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;
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);
}
}
}
-
- 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
/* function prototypes */
+#ifdef __cplusplus
+extern "C" {
+#endif
dominatordata *compute_Dominators(graphdata *gd, int basicblockcount);
void computeDF(graphdata *gd, dominatordata *dd, int basicblockcount, int n);
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.
* 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>
# include "mm/cacao-gc/gc.h"
#endif
+#include "mm/dumpmemory.hpp"
#include "mm/memory.h"
#include "threads/thread.hpp"
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) {
{
sourceframe_t *frame;
- frame = DNEW(sourceframe_t);
+ frame = (sourceframe_t*) DumpMemory::allocate(sizeof(sourceframe_t));
MZERO(frame, sourceframe_t, 1);
frame->down = ss->frames;
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) {
/* 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 */
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);
}
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 */
}
/* 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 */
#if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
threadobject *thread;
#endif
- int32_t dumpmarker;
origcode = es->code;
origrp = rp;
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. */
if (opt_TestReplacement)
es->pc += REPLACEMENT_PATCH_SIZE;
#endif
-
- /* release dump area */
-
- DRELEASE;
}
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! */
int res;
char *method_name;
s4 len;
- int32_t dumpmarker;
/* compose full name of method */
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, ".");
}
}
- /* release memory */
-
- DRELEASE;
+ // Release memory.
+ MFREE(method_name, char, len);
}
#define STATE_IS_INITIAL() ((FILTERVERBOSECALLCTR[0] == 0) && (FILTERVERBOSECALLCTR[1] == 0))
#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;
/* 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);
// Include machine dependent headers.
#include "md.h"
-#include "mm/dumpmemory.h"
+#include "mm/dumpmemory.hpp"
#include "vm/method.h"
#include "vm/options.h"
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 */
md_cacheflush(cd->mcodebase, 2 * SIZEOF_VOID_P + get_code_size());
#endif
- /* release dump memory */
-
- DRELEASE;
-
/* return native stub code */
return c;
jitdata *jd;
codeinfo *code;
int skipparams;
- int32_t dumpmarker;
- /* mark dump memory */
-
- DMARKER;
+ // Create new dump memory area.
+ DumpMemoryArea dma;
/* Create JIT data structure. */
dseg_display(jd);
}
#endif /* !defined(NDEBUG) && defined(ENABLE_DISASSEMBLER) */
-
- /* release memory */
-
- DRELEASE;
}
methoddesc *md;
methoddesc *nmd;
int skipparams;
- int32_t dumpmarker;
-
- /* mark dump memory */
- DMARKER;
+ // Create new dump memory area.
+ DumpMemoryArea dma;
/* Create JIT data structure. */
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 */
}
#endif /* !defined(NDEBUG) && defined(ENABLE_DISASSEMBLER) */
- /* release memory */
-
- DRELEASE;
-
/* return native stub code */
return code;
/* 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 */
/* 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 */
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
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++;
log_text(logtext);
- /* release memory */
-
- DRELEASE;
-
TRACEJAVACALLINDENT++;
-
}
/* trace_java_call_exit ********************************************************
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
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 */
}
log_text(logtext);
-
- /* release memory */
-
- DRELEASE;
}
char *logtext;
s4 logtextlen;
codeinfo *code;
- int32_t dumpmarker;
/* calculate message length */
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 ");
strcat(logtext, "call_java_method");
log_text(logtext);
-
- /* release memory */
-
- DRELEASE;
}
{
char *logtext;
s4 logtextlen;
- int32_t dumpmarker;
java_lang_Throwable jlt(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: ");
}
log_text(logtext);
-
- /* release memory */
-
- DRELEASE;
}
} // extern "C"
#include "vm/types.h"
+#include "mm/dumpmemory.hpp"
#include "mm/memory.h"
#include "native/llni.h"
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;
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;
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;
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;
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. */
/* 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);
{
classinfo *c;
bool result;
- int32_t dumpmarker;
/* Get the classbuffer's class. */
log_message_class("Loading class: ", c);
#endif
- /* Mark start of dump memory area. */
-
- DMARKER;
-
/* Class is currently loading. */
c->state |= CLASS_LOADING;
result = load_class_from_classbuffer_intern(cb);
- /* Release dump area. */
-
- DRELEASE;
-
/* An error occurred. */
if (result == false) {
/* function prototypes ********************************************************/
+#ifdef __cplusplus
+extern "C" {
+#endif
+
void resolve_handle_pending_exception(bool throwError);
bool resolve_class_from_name(classinfo* referer,methodinfo *refmethod,
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 */
#include "vm/jit/abi-asm.h"
#include "mm/codememory.h"
+#include "mm/dumpmemory.hpp"
#include "mm/gc.hpp"
#include "mm/memory.h"
{ \
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; \
{ \
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; \
java_handle_t *xptr;
java_handle_t *ro;
imm_union value;
- int32_t dumpmarker;
/* Prevent compiler warnings. */
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;
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;