-/* src/mm/memory.c -
+/* src/mm/memory.c - memory management
- Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
+ Copyright (C) 1996-2005, 2006, 2007 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
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
- Contact: cacao@cacaojvm.org
-
- Authors: Reinhard Grafl
- Christian Thalinger
- Edwin Steiner
-
- $Id: memory.c 6286 2007-01-10 10:03:38Z twisti $
-
*/
#include "arch.h"
#include "mm/memory.h"
+
#include "native/native.h"
-#if defined(ENABLE_THREADS)
-# include "threads/native/lock.h"
-# include "threads/native/threads.h"
-#else
-# include "threads/none/lock.h"
-#endif
+#include "threads/lock-common.h"
+#include "threads/threads-common.h"
#include "toolbox/logging.h"
+
#include "vm/exceptions.h"
#include "vm/global.h"
-#include "vm/options.h"
-#include "vm/statistics.h"
#include "vm/stringlocal.h"
#include "vm/vm.h"
+#include "vmcore/options.h"
+
+#if defined(ENABLE_STATISTICS)
+# include "vmcore/statistics.h"
+#endif
+
/* constants for ENABLE_MEMCHECK **********************************************/
#define DEFAULT_CODE_MEMORY_SIZE 128 * 1024 /* defaulting to 128kB */
#if defined(ENABLE_THREADS)
-static java_objectheader *lock_code_memory = NULL;
+static java_object_t *lock_code_memory = NULL;
#endif
-static void *code_memory = NULL;
-static int code_memory_size = 0;
-static int pagesize = 0;
+static void *code_memory = NULL;
+static int code_memory_size = 0;
+static int pagesize = 0;
/* memory_init *****************************************************************
bool memory_init(void)
{
#if defined(ENABLE_THREADS)
- lock_code_memory = NEW(java_objectheader);
+ /* create lock for code memory */
+
+ lock_code_memory = NEW(java_object_t);
lock_init_object_lock(lock_code_memory);
#endif
{
void *dst;
+ /* prevent compiler warnings */
+
+ dst = NULL;
+
if (src == NULL)
if (len1 != 0)
vm_abort("mem_realloc: reallocating memoryblock with address NULL, length != 0");
}
+/* memory_thread ***************************************************************
+
+ Prints regularly memory statistics.
+
+*******************************************************************************/
+
+#if defined(ENABLE_THREADS) && !defined(NDEBUG)
+static void memory_thread(void)
+{
+ int32_t seconds;
+
+ /* If both arguments are specified, use the value of
+ ProfileMemoryUsage. */
+
+ if (opt_ProfileGCMemoryUsage)
+ seconds = opt_ProfileGCMemoryUsage;
+
+ if (opt_ProfileMemoryUsage)
+ seconds = opt_ProfileMemoryUsage;
+
+ while (true) {
+ /* sleep thread */
+
+ threads_sleep(seconds * 1000, 0);
+
+# if defined(ENABLE_STATISTICS)
+ /* Print current date and time (only when we print to the
+ stdout). */
+
+ if (!opt_ProfileMemoryUsageGNUPlot)
+ statistics_print_date();
+
+ /* print memory usage */
+
+ if (opt_ProfileMemoryUsage)
+ statistics_print_memory_usage();
+
+ /* print GC memory usage */
+
+ if (opt_ProfileGCMemoryUsage)
+ statistics_print_gc_memory_usage();
+# endif
+ }
+}
+#endif
+
+
+/* memory_start_thread *********************************************************
+
+ Starts the memory profiling thread.
+
+*******************************************************************************/
+
+#if defined(ENABLE_THREADS) && !defined(NDEBUG)
+bool memory_start_thread(void)
+{
+ utf *name;
+
+ name = utf_new_char("Memory Profiler");
+
+ /* start the memory profiling thread */
+
+ if (!threads_thread_start_internal(name, memory_thread))
+ return false;
+
+ /* everything's ok */
+
+ return true;
+}
+#endif
+
+
/* dump_check_canaries *********************************************************
Check canaries in dump memory.