* Removed all Id tags.
[cacao.git] / src / mm / memory.c
index cdc2d4582f3d32803f6bee922cbe687630c2a07d..9c3034491c051994ef2c9aeaf20061b81fb5308d 100644 (file)
@@ -22,8 +22,6 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: memory.c 7341 2007-02-13 00:51:01Z twisti $
-
 */
 
 
 #include "arch.h"
 
 #include "mm/memory.h"
-#include "native/native.h"
 
-#if defined(ENABLE_THREADS)
-# include "threads/threads-common.h"
+#include "native/native.h"
 
-# 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/stringlocal.h"
 #include "vm/vm.h"
+
 #include "vmcore/options.h"
 
 #if defined(ENABLE_STATISTICS)
@@ -103,18 +98,11 @@ static dumpinfo_t _no_threads_dumpinfo;
 #define DEFAULT_CODE_MEMORY_SIZE    128 * 1024 /* defaulting to 128kB         */
 
 #if defined(ENABLE_THREADS)
-static java_objectheader *lock_code_memory = NULL;
-#endif
-static void              *code_memory      = NULL;
-static int                code_memory_size = 0;
-static int                pagesize         = 0;
-
-
-/* global variables ***********************************************************/
-
-#if defined(ENABLE_THREADS)
-static threadobject *thread_memory;
+static java_object_t *lock_code_memory = NULL;
 #endif
+static void          *code_memory      = NULL;
+static int            code_memory_size = 0;
+static int            pagesize         = 0;
 
 
 /* memory_init *****************************************************************
@@ -128,7 +116,7 @@ bool memory_init(void)
 #if defined(ENABLE_THREADS)
        /* create lock for code memory */
 
-       lock_code_memory = NEW(java_objectheader);
+       lock_code_memory = NEW(java_object_t);
 
        lock_init_object_lock(lock_code_memory);
 #endif
@@ -382,15 +370,38 @@ void mem_free(void *m, s4 size)
 #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 for 2 seconds */
+               /* sleep thread */
 
-               threads_sleep(2 * 1000, 0);
+               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 */
 
-               statistics_print_memory_usage();
+               if (opt_ProfileMemoryUsage)
+                       statistics_print_memory_usage();
+
+               /* print GC memory usage */
+
+               if (opt_ProfileGCMemoryUsage)
+                       statistics_print_gc_memory_usage();
 # endif
        }
 }
@@ -410,15 +421,11 @@ bool memory_start_thread(void)
 
        name = utf_new_char("Memory Profiler");
 
-       thread_memory = threads_create_thread(name);
+       /* start the memory profiling thread */
 
-       if (thread_memory == NULL)
+       if (!threads_thread_start_internal(name, memory_thread))
                return false;
 
-       /* actually start the memory profiling thread */
-
-       threads_start_thread(thread_memory, memory_thread);
-
        /* everything's ok */
 
        return true;