* Updated header: Added 2006. Changed address of FSF. Changed email
[cacao.git] / src / toolbox / logging.c
index 55e9015adefbb7c50a20c175392cc625d8819fe8..3d10140b85a931e6997a16d7aa6e08492def1887 100644 (file)
@@ -1,9 +1,9 @@
-/* toolbox/logging.c - contains logging functions
+/* src/toolbox/logging.c - contains logging functions
 
-   Copyright (C) 1996-2005 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 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
 
    This file is part of CACAO.
 
 
    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., 59 Temple Place - Suite 330, Boston, MA
-   02111-1307, USA.
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.
 
-   Contact: cacao@complang.tuwien.ac.at
+   Contact: cacao@cacaojvm.org
 
    Authors: Reinhard Grafl
 
-   $Id: logging.c 2020 2005-03-09 12:01:42Z twisti $
+   Changes: Christian Thalinger
+
+   $Id: logging.c 4357 2006-01-22 23:33:38Z twisti $
 
 */
 
 #include <string.h>
 
 #include "config.h"
+#include "vm/types.h"
+
 #include "mm/memory.h"
 #include "toolbox/logging.h"
+#include "toolbox/util.h"
 #include "vm/global.h"
-#include "vm/tables.h"
 #include "vm/statistics.h"
 
+#if defined(USE_THREADS)
+# if defined(NATIVE_THREADS)
+#  include "threads/native/threads.h"
+# endif
+#endif
+
 
 /***************************************************************************
                         LOG FILE HANDLING 
@@ -51,7 +61,6 @@
 FILE *logfile = NULL;
 
 
-
 void log_init(const char *fname)
 {
        if (fname) {
@@ -62,27 +71,40 @@ void log_init(const char *fname)
 }
 
 
-/*********************** Function: dolog ************************************
+/* dolog ***********************************************************************
 
-Writes logtext to the protocol file (if opened) or to stdout.
+   Writes logtext to the protocol file (if opened) or to stdout.
 
-**************************************************************************/
+*******************************************************************************/
 
-void dolog(const char *txt, ...)
+void dolog(const char *text, ...)
 {
-       char logtext[MAXLOGTEXT];
        va_list ap;
 
-       va_start(ap, txt);
-       vsprintf(logtext, txt, ap);
-       va_end(ap);
-
        if (logfile) {
-               fprintf(logfile, "%s\n",logtext);
+#if defined(USE_THREADS) && defined(NATIVE_THREADS)
+               fprintf(logfile, "[%p] ", (void *) THREADOBJECT);
+#endif
+
+               va_start(ap, text);
+               vfprintf(logfile, text, ap);
+               va_end(ap);
+
                fflush(logfile);
 
        } else {
-               fprintf(stdout,"LOG: %s\n",logtext);
+#if defined(USE_THREADS) && defined(NATIVE_THREADS)
+               fprintf(stdout, "LOG: [%p] ", (void *) THREADOBJECT);
+#else
+               fputs("LOG: ", stdout);
+#endif
+
+               va_start(ap, text);
+               vfprintf(stdout, text, ap);
+               va_end(ap);
+
+               fprintf(stdout, "\n");
+
                fflush(stdout);
        }
 }
@@ -155,79 +177,70 @@ void log_nl(void)
 }
 
 
-/* log_cputime *****************************************************************
+/* log_message_utf *************************************************************
+
+   Outputs log text like this:
 
-   XXX
+   LOG: Creating class: java/lang/Object
 
 *******************************************************************************/
 
-#if defined(STATISTICS)
-void log_cputime(void)
+void log_message_utf(const char *msg, utf *u)
 {
-       s8 t;
-       int sec, usec;
-       char logtext[MAXLOGTEXT];
+       char *buf;
+       s4    len;
+
+       len = strlen(msg) + utf_strlen(u) + strlen("0");
 
-       t = getcputime();
-       sec = t / 1000000;
-       usec = t % 1000000;
+       buf = MNEW(char, len);
+
+       strcpy(buf, msg);
+       utf_strcat(buf, u);
+
+       log_text(buf);
 
-       sprintf(logtext, "Total CPU usage: %d seconds and %d milliseconds",
-                       sec, usec / 1000);
-       log_text(logtext);
+       MFREE(buf, char, len);
 }
-#endif
 
 
-/* log_message_method **********************************************************
+/* log_message_class ***********************************************************
 
-   outputs log text like this:
+   Outputs log text like this:
 
-   LOG: Loading class: java.lang.Object
+   LOG: Loading class: java/lang/Object
 
 *******************************************************************************/
 
 void log_message_class(const char *msg, classinfo *c)
 {
-       char *buf;
-       s4    len;
-
-       len = strlen(msg) + utf_strlen(c->name) + 1;
-
-       buf = MNEW(char, len);
-
-       sprintf(buf, msg);
-       utf_sprint_classname(buf + strlen(buf), c->name);
-
-       log_text(buf);
-
-       MFREE(buf, char, len);
+       log_message_utf(msg, c->name);
 }
 
 
-/* log_message_method **********************************************************
+/* log_message_class_message_class *********************************************
 
-   outputs log text like this:
+   Outputs log text like this:
 
-   LOG: Compiling: java.lang.Object.clone()Ljava.lang.Object;
+   LOG: Initialize super class java/lang/Object from java/lang/VMThread
 
 *******************************************************************************/
 
-void log_message_method(const char *msg, methodinfo *m)
+void log_message_class_message_class(const char *msg1, classinfo *c1,
+                                                                        const char *msg2, classinfo *c2)
 {
        char *buf;
        s4    len;
 
-       len = strlen(msg) + utf_strlen(m->class->name) + 1 +
-               utf_strlen(m->name) + utf_strlen(m->descriptor) + 1;
+       len =
+               strlen(msg1) + utf_strlen(c1->name) +
+               strlen(msg2) + utf_strlen(c2->name) + strlen("0");
 
        buf = MNEW(char, len);
 
-       sprintf(buf, msg);
-       utf_sprint_classname(buf + strlen(buf), m->class->name);
-       strcpy(buf + strlen(buf), ".");
-       utf_sprint(buf + strlen(buf), m->name);
-       utf_sprint_classname(buf + strlen(buf), m->descriptor);
+       strcpy(buf, msg1);
+       utf_strcat(buf, c1->name);
+       strcat(buf, msg2);
+       utf_strcat(buf, c2->name);
 
        log_text(buf);
 
@@ -235,40 +248,33 @@ void log_message_method(const char *msg, methodinfo *m)
 }
 
 
-/* error ***********************************************************************
+/* log_message_method **********************************************************
+
+   Outputs log text like this:
 
-   Like dolog(), but terminates the program immediately.
+   LOG: Compiling: java.lang.Object.clone()Ljava/lang/Object;
 
 *******************************************************************************/
 
-void error(const char *txt, ...)
+void log_message_method(const char *msg, methodinfo *m)
 {
-       char logtext[MAXLOGTEXT];
-       va_list ap;
-
-       va_start(ap, txt);
-       vsprintf(logtext, txt, ap);
-       va_end(ap);
-
-       if (logfile) {
-               fprintf(logfile, "ERROR: %s\n", logtext);
-       }
-
-       fprintf(stderr, "ERROR: %s\n", logtext);
-
-       exit(1);
-}
+       char *buf;
+       s4    len;
 
+       len = strlen(msg) + utf_strlen(m->class->name) + strlen(".") +
+               utf_strlen(m->name) + utf_strlen(m->descriptor) + strlen("0");
 
-/* panic ***********************************************************************
+       buf = MNEW(char, len);
 
-   Like error(), takes the text to output as an argument.
+       strcpy(buf, msg);
+       utf_strcat_classname(buf, m->class->name);
+       strcat(buf, ".");
+       utf_strcat(buf, m->name);
+       utf_strcat(buf, m->descriptor);
 
-*******************************************************************************/
+       log_text(buf);
 
-void panic(const char *txt)
-{
-       error("%s", txt);
+       MFREE(buf, char, len);
 }