Merged branch subtype-trunk into default.
[cacao.git] / src / vm / jit / trace.cpp
index 164732485ebc88818ea48663281215afd8e2fe1e..98667f76cc0692b9ef3a08a1fd9e5dcbbe01f98a 100644 (file)
@@ -23,9 +23,6 @@
 */
 
 
-// FIXME For now we export everything as C functions.
-extern "C" {
-
 #include "config.h"
 
 #include <stdio.h>
@@ -33,32 +30,31 @@ extern "C" {
 #include "arch.h"
 #include "md-abi.h"
 
-#include "mm/memory.h"
+#include "mm/memory.hpp"
 
-#include "native/jni.h"
 #include "native/llni.h"
 
-#include "native/include/java_lang_String.h"
-#include "native/include/java_lang_Throwable.h"
-
-#include "threads/thread.h"
+#include "threads/thread.hpp"
 
-#include "toolbox/logging.h"
+#include "toolbox/logging.hpp"
 
 #include "vm/global.h"
-#include "vm/stringlocal.h"
-#include "vm/jit/argument.h"
-#include "vm/jit/codegen-common.h"
+#include "vm/globals.hpp"
+#include "vm/javaobjects.hpp"
+#include "vm/options.h"
+#include "vm/string.hpp"
+#include "vm/utf8.h"
+
+#include "vm/jit/argument.hpp"
+#include "vm/jit/codegen-common.hpp"
 #include "vm/jit/trace.hpp"
-#include "vm/jit/show.h"
-
-#include "vmcore/globals.hpp"
-#include "vmcore/options.h"
-#include "vmcore/utf8.h"
+#include "vm/jit/show.hpp"
 
 
 #if !defined(NDEBUG)
 
+// FIXME For now we export everything as C functions.
+extern "C" {
 
 /* global variables ***********************************************************/
 
@@ -123,7 +119,7 @@ static char *trace_java_call_print_argument(methodinfo *m, char *logtext, s4 *lo
 
                /* Cast to java.lang.Object. */
 
-               o = (java_object_t *) (ptrint) imu.l;
+               o = (java_handle_t*) (uintptr_t) imu.l;
 
                /* Check return argument for java.lang.Class or
                   java.lang.String. */
@@ -139,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 */
@@ -169,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 */
@@ -205,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
@@ -263,11 +258,11 @@ void trace_java_call_enter(methodinfo *m, uint64_t *arg_regs, uint64_t *stack)
                strlen("...(255)") +
                strlen(")");
 
-       /* allocate memory */
-
-       DMARKER;
+       // Create new dump memory area.
+       DumpMemoryArea dma;
 
-       logtext = DMNEW(char, logtextlen);
+       // TODO Use a std::string here.
+       logtext = (char*) DumpMemory::allocate(sizeof(char) * logtextlen);
 
        TRACEJAVACALLCOUNT++;
 
@@ -316,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 ********************************************************
@@ -342,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
@@ -387,11 +376,11 @@ void trace_java_call_exit(methodinfo *m, uint64_t *return_regs)
 
        logtextlen += strlen("->0.4872328470301428 (0x0123456789abcdef)");
 
-       /* allocate memory */
-
-       DMARKER;
+       // Create new dump memory area.
+       DumpMemoryArea dma;
 
-       logtext = DMNEW(char, logtextlen);
+       // TODO Use a std::string here.
+       logtext = (char*) DumpMemory::allocate(sizeof(char) * logtextlen);
 
        /* generate the message */
 
@@ -422,10 +411,6 @@ void trace_java_call_exit(methodinfo *m, uint64_t *return_regs)
        }
 
        log_text(logtext);
-
-       /* release memory */
-
-       DRELEASE;
 }
 
 
@@ -440,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 */
 
@@ -483,11 +467,11 @@ void trace_exception(java_object_t *xptr, methodinfo *m, void *pos)
 
        logtextlen += strlen("0");
 
-       /* allocate memory */
-
-       DMARKER;
+       // Create new dump memory area.
+       DumpMemoryArea dma;
 
-       logtext = DMNEW(char, logtextlen);
+       // TODO Use a std::string here.
+       logtext = (char*) DumpMemory::allocate(sizeof(char) * logtextlen);
 
        if (xptr) {
                strcpy(logtext, "Exception ");
@@ -553,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,53 +546,52 @@ void trace_exception(java_object_t *xptr, methodinfo *m, void *pos)
 
 *******************************************************************************/
 
-void trace_exception_builtin(java_object_t *xptr)
+void trace_exception_builtin(java_handle_t* h)
 {
-       java_lang_Throwable *t;
-       java_lang_String    *s;
        char                *logtext;
        s4                   logtextlen;
-       int32_t              dumpmarker;
 
-       t = (java_lang_Throwable *) xptr;
+       java_lang_Throwable jlt(h);
+
+       // Get detail message.
+       java_handle_t* s = NULL;
+
+       if (jlt.get_handle() != NULL)
+               s = jlt.get_detailMessage();
 
-       /* get detail message */
-       if (t)
-               LLNI_field_get_ref(t, detailMessage, s);
+       java_lang_String jls(s);
 
        /* calculate message length */
 
        logtextlen = strlen("Builtin exception thrown: ") + strlen("0");
 
-       if (t) {
-               logtextlen +=
-                       utf_bytes(xptr->vftbl->clazz->name);
-               if (s) {
+       if (jlt.get_handle() != NULL) {
+               logtextlen += utf_bytes(jlt.get_vftbl()->clazz->name);
+
+               if (jls.get_handle()) {
+                       // FIXME This is not handle capable!
                        logtextlen += strlen(": ") +
-                               u2_utflength(LLNI_field_direct(s, value)->data 
-                                                               + LLNI_field_direct(s, offset),
-                                                        LLNI_field_direct(s,count));
+                               u2_utflength(jls.get_value()->data + jls.get_offset(), jls.get_count());
                }
        } 
        else {
                logtextlen += strlen("(nil)");
        }
 
-       /* allocate memory */
-
-       DMARKER;
+       // Create new dump memory area.
+       DumpMemoryArea dma;
 
-       logtext = DMNEW(char, logtextlen);
+       logtext = (char*) DumpMemory::allocate(sizeof(char) * logtextlen);
 
        strcpy(logtext, "Builtin exception thrown: ");
 
-       if (t) {
-               utf_cat_classname(logtext, xptr->vftbl->clazz->name);
+       if (jlt.get_handle()) {
+               utf_cat_classname(logtext, jlt.get_vftbl()->clazz->name);
 
                if (s) {
                        char *buf;
 
-                       buf = javastring_tochar((java_handle_t *) s);
+                       buf = javastring_tochar(jls.get_handle());
                        strcat(logtext, ": ");
                        strcat(logtext, buf);
                        MFREE(buf, char, strlen(buf) + 1);
@@ -623,16 +602,12 @@ void trace_exception_builtin(java_object_t *xptr)
        }
 
        log_text(logtext);
-
-       /* release memory */
-
-       DRELEASE;
 }
 
-#endif /* !defined(NDEBUG) */
-
 } // extern "C"
 
+#endif /* !defined(NDEBUG) */
+
 
 /*
  * These are local overrides for various environment variables in Emacs.