* src/vm/jit/arm/arch.h: Defined JIT_COMPILER_VIA_SIGNAL.
[cacao.git] / src / toolbox / logging.c
index 3d10140b85a931e6997a16d7aa6e08492def1887..7ff7f1b69fafe369178fa28fa28f77f1d6bb440a 100644 (file)
@@ -1,9 +1,7 @@
 /* src/toolbox/logging.c - contains logging functions
 
-   Copyright (C) 1996-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) 1996-2005, 2006, 2007, 2008
+   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
 
    This file is part of CACAO.
 
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   Contact: cacao@cacaojvm.org
-
-   Authors: Reinhard Grafl
-
-   Changes: Christian Thalinger
-
-   $Id: logging.c 4357 2006-01-22 23:33:38Z twisti $
-
 */
 
 
+#include "config.h"
+
 #include <stdio.h>
-#include <stdarg.h>
 #include <stdlib.h>
 #include <string.h>
 
-#include "config.h"
 #include "vm/types.h"
 
 #include "mm/memory.h"
+
+#include "threads/thread.hpp"
+
 #include "toolbox/logging.h"
 #include "toolbox/util.h"
+
 #include "vm/global.h"
-#include "vm/statistics.h"
 
-#if defined(USE_THREADS)
-# if defined(NATIVE_THREADS)
-#  include "threads/native/threads.h"
-# endif
+#if defined(ENABLE_STATISTICS)
+# include "vm/statistics.h"
 #endif
 
 
@@ -71,109 +62,112 @@ void log_init(const char *fname)
 }
 
 
-/* dolog ***********************************************************************
+/* log_start *******************************************************************
 
-   Writes logtext to the protocol file (if opened) or to stdout.
+   Writes the preleading LOG: text to the protocol file (if opened) or
+   to stdout.
 
 *******************************************************************************/
 
-void dolog(const char *text, ...)
+void log_start(void)
 {
-       va_list ap;
+#if defined(ENABLE_THREADS)
+       ptrint tid;
 
-       if (logfile) {
-#if defined(USE_THREADS) && defined(NATIVE_THREADS)
-               fprintf(logfile, "[%p] ", (void *) THREADOBJECT);
+       tid = threads_get_current_tid();
 #endif
 
-               va_start(ap, text);
-               vfprintf(logfile, text, ap);
-               va_end(ap);
-
-               fflush(logfile);
-
-       } else {
-#if defined(USE_THREADS) && defined(NATIVE_THREADS)
-               fprintf(stdout, "LOG: [%p] ", (void *) THREADOBJECT);
+       if (logfile) {
+#if defined(ENABLE_THREADS)
+# if SIZEOF_VOID_P == 8
+               fprintf(logfile, "[0x%016lx] ", tid );
+# else
+               fprintf(logfile, "[0x%08x] ", tid);
+# endif
+#endif
+       }
+       else {
+#if defined(ENABLE_THREADS)
+# if SIZEOF_VOID_P == 8
+               fprintf(stdout, "LOG: [0x%016lx] ", tid);
+# else
+               fprintf(stdout, "LOG: [0x%08x] ", tid);
+# endif
 #else
                fputs("LOG: ", stdout);
 #endif
+       }
+}
 
-               va_start(ap, text);
-               vfprintf(stdout, text, ap);
-               va_end(ap);
 
-               fprintf(stdout, "\n");
+/* log_vprint ******************************************************************
 
-               fflush(stdout);
-       }
+   Writes logtext to the protocol file (if opened) or to stdout.
+
+*******************************************************************************/
+
+void log_vprint(const char *text, va_list ap)
+{
+       if (logfile)
+               vfprintf(logfile, text, ap);
+       else
+               vfprintf(stdout, text, ap);
 }
 
 
-/******************** Function: dolog_plain *******************************
+/* log_print *******************************************************************
 
-Writes logtext to the protocol file (if opened) or to stdout.
+   Writes logtext to the protocol file (if opened) or to stdout.
 
-**************************************************************************/
+*******************************************************************************/
 
-void dolog_plain(const char *txt, ...)
+void log_print(const char *text, ...)
 {
-       char logtext[MAXLOGTEXT];
        va_list ap;
 
-       va_start(ap, txt);
-       vsprintf(logtext, txt, ap);
+       va_start(ap, text);
+       log_vprint(text, ap);
        va_end(ap);
-
-       if (logfile) {
-               fprintf(logfile, "%s", logtext);
-               fflush(logfile);
-
-       } else {
-               fprintf(stdout,"%s", logtext);
-               fflush(stdout);
-       }
 }
 
 
-/********************* Function: log_text ********************************/
-
-void log_text(const char *text)
-{
-       dolog("%s", text);
-}
+/* log_println *****************************************************************
 
+   Writes logtext to the protocol file (if opened) or to stdout with a
+   trailing newline.
 
-/******************** Function: log_plain *******************************/
+*******************************************************************************/
 
-void log_plain(const char *text)
+void log_println(const char *text, ...)
 {
-       dolog_plain("%s", text);
-}
+       va_list ap;
 
+       log_start();
 
-/****************** Function: get_logfile *******************************/
+       va_start(ap, text);
+       log_vprint(text, ap);
+       va_end(ap);
 
-FILE *get_logfile(void)
-{
-       return (logfile) ? logfile : stdout;
+       log_finish();
 }
 
 
-/****************** Function: log_flush *********************************/
+/* log_finish ******************************************************************
 
-void log_flush(void)
-{
-       fflush(get_logfile());
-}
+   Finishes a logtext line with trailing newline and a fflush.
 
+*******************************************************************************/
 
-/********************* Function: log_nl *********************************/
-
-void log_nl(void)
+void log_finish(void)
 {
-       log_plain("\n");
-       fflush(get_logfile());
+       if (logfile) {
+               fputs("\n", logfile);
+               fflush(logfile);
+       }
+       else {
+               fputs("\n", stdout);
+               fflush(stdout);
+       }
 }
 
 
@@ -190,12 +184,12 @@ void log_message_utf(const char *msg, utf *u)
        char *buf;
        s4    len;
 
-       len = strlen(msg) + utf_strlen(u) + strlen("0");
+       len = strlen(msg) + utf_bytes(u) + strlen("0");
 
        buf = MNEW(char, len);
 
        strcpy(buf, msg);
-       utf_strcat(buf, u);
+       utf_cat(buf, u);
 
        log_text(buf);
 
@@ -232,15 +226,15 @@ void log_message_class_message_class(const char *msg1, classinfo *c1,
        s4    len;
 
        len =
-               strlen(msg1) + utf_strlen(c1->name) +
-               strlen(msg2) + utf_strlen(c2->name) + strlen("0");
+               strlen(msg1) + utf_bytes(c1->name) +
+               strlen(msg2) + utf_bytes(c2->name) + strlen("0");
 
        buf = MNEW(char, len);
 
        strcpy(buf, msg1);
-       utf_strcat(buf, c1->name);
+       utf_cat_classname(buf, c1->name);
        strcat(buf, msg2);
-       utf_strcat(buf, c2->name);
+       utf_cat_classname(buf, c2->name);
 
        log_text(buf);
 
@@ -261,16 +255,16 @@ void log_message_method(const char *msg, methodinfo *m)
        char *buf;
        s4    len;
 
-       len = strlen(msg) + utf_strlen(m->class->name) + strlen(".") +
-               utf_strlen(m->name) + utf_strlen(m->descriptor) + strlen("0");
+       len = strlen(msg) + utf_bytes(m->clazz->name) + strlen(".") +
+               utf_bytes(m->name) + utf_bytes(m->descriptor) + strlen("0");
 
        buf = MNEW(char, len);
 
        strcpy(buf, msg);
-       utf_strcat_classname(buf, m->class->name);
+       utf_cat_classname(buf, m->clazz->name);
        strcat(buf, ".");
-       utf_strcat(buf, m->name);
-       utf_strcat(buf, m->descriptor);
+       utf_cat(buf, m->name);
+       utf_cat(buf, m->descriptor);
 
        log_text(buf);
 
@@ -278,34 +272,6 @@ void log_message_method(const char *msg, methodinfo *m)
 }
 
 
-/* log_utf *********************************************************************
-
-   Log utf symbol.
-
-*******************************************************************************/
-
-void log_utf(utf *u)
-{
-       char buf[MAXLOGTEXT];
-       utf_sprint(buf, u);
-       dolog("%s", buf);
-}
-
-
-/* log_plain_utf ***************************************************************
-
-   Log utf symbol (without printing "LOG: " and newline).
-
-*******************************************************************************/
-
-void log_plain_utf(utf *u)
-{
-       char buf[MAXLOGTEXT];
-       utf_sprint(buf, u);
-       dolog_plain("%s", buf);
-}
-
-
 /*
  * 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
@@ -317,4 +283,5 @@ void log_plain_utf(utf *u)
  * c-basic-offset: 4
  * tab-width: 4
  * End:
+ * vim:noexpandtab:sw=4:ts=4:
  */