-/* toolbox/logging.c - contains logging functions
+/* src/toolbox/logging.c - contains logging functions
- Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
- Institut f. Computersprachen, TU Wien
- R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser, M. Probst,
- S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich,
- J. Wenninger
+ Copyright (C) 1996-2005, 2006, 2007, 2008
+ CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
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.
-
- Contact: cacao@complang.tuwien.ac.at
-
- Authors: Reinhard Grafl
-
- $Id: logging.c 1107 2004-05-28 12:18:44Z twisti $
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
*/
+#include "config.h"
+
#include <stdio.h>
-#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
-#include <sys/time.h>
-#include <sys/resource.h>
-#include "global.h"
-#include "tables.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"
+
+#if defined(ENABLE_STATISTICS)
+# include "vm/statistics.h"
+#endif
/***************************************************************************
FILE *logfile = NULL;
-
-void log_init(char *fname)
+void log_init(const char *fname)
{
if (fname) {
if (fname[0]) {
}
-/*********************** Function: 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(char *txt, ...)
+void log_start(void)
{
- char logtext[MAXLOGTEXT];
- va_list ap;
+#if defined(ENABLE_THREADS)
+ ptrint tid;
- va_start(ap, txt);
- vsprintf(logtext, txt, ap);
- va_end(ap);
+ tid = threads_get_current_tid();
+#endif
if (logfile) {
- fprintf(logfile, "%s\n",logtext);
- fflush(logfile);
-
- } else {
- fprintf(stdout,"LOG: %s\n",logtext);
- fflush(stdout);
+#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
}
}
-/******************** Function: dolog_plain *******************************
+/* log_vprint ******************************************************************
-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(char *txt, ...)
+void log_vprint(const char *text, va_list ap)
{
- char logtext[MAXLOGTEXT];
- va_list ap;
-
- va_start(ap, txt);
- vsprintf(logtext, txt, ap);
- va_end(ap);
-
- if (logfile) {
- fprintf(logfile, "%s", logtext);
- fflush(logfile);
-
- } else {
- fprintf(stdout,"%s", logtext);
- fflush(stdout);
- }
+ if (logfile)
+ vfprintf(logfile, text, ap);
+ else
+ vfprintf(stdout, text, ap);
}
-/********************* Function: log_text ********************************/
-
-void log_text(char *text)
-{
- dolog("%s", text);
-}
+/* log_print *******************************************************************
+ Writes logtext to the protocol file (if opened) or to stdout.
-/******************** Function: log_plain *******************************/
+*******************************************************************************/
-void log_plain(char *text)
+void log_print(const char *text, ...)
{
- dolog_plain("%s", text);
+ va_list ap;
+
+ va_start(ap, text);
+ log_vprint(text, ap);
+ va_end(ap);
}
-/****************** Function: get_logfile *******************************/
+/* log_println *****************************************************************
-FILE *get_logfile()
-{
- return (logfile) ? logfile : stdout;
-}
+ Writes logtext to the protocol file (if opened) or to stdout with a
+ trailing newline.
+*******************************************************************************/
-/****************** Function: log_flush *********************************/
-
-void log_flush()
+void log_println(const char *text, ...)
{
- fflush(get_logfile());
-}
+ va_list ap;
+ log_start();
-/********************* Function: log_nl *********************************/
+ va_start(ap, text);
+ log_vprint(text, ap);
+ va_end(ap);
-void log_nl()
-{
- log_plain("\n");
- fflush(get_logfile());
+ log_finish();
}
-/********************* Function: log_cputime ****************************/
+/* log_finish ******************************************************************
-void log_cputime()
-{
- s8 t;
- int sec, usec;
- char logtext[MAXLOGTEXT];
+ Finishes a logtext line with trailing newline and a fflush.
- t = getcputime();
- sec = t / 1000000;
- usec = t % 1000000;
+*******************************************************************************/
- sprintf(logtext, "Total CPU usage: %d seconds and %d milliseconds",
- sec, usec / 1000);
- log_text(logtext);
+void log_finish(void)
+{
+ if (logfile) {
+ fputs("\n", logfile);
+ fflush(logfile);
+ }
+ else {
+ fputs("\n", stdout);
+ fflush(stdout);
+ }
}
-/* log_message_method **********************************************************
+/* log_message_utf *************************************************************
- outputs log text like this:
+ Outputs log text like this:
- LOG: Loading class: java.lang.Object
+ LOG: Creating class: java/lang/Object
*******************************************************************************/
-void log_message_class(char *msg, classinfo *c)
+void log_message_utf(const char *msg, utf *u)
{
- char logtext[MAXLOGTEXT];
+ char *buf;
+ s4 len;
+
+ len = strlen(msg) + utf_bytes(u) + strlen("0");
+
+ buf = MNEW(char, len);
+
+ strcpy(buf, msg);
+ utf_cat(buf, u);
- sprintf(logtext, msg);
- utf_sprint_classname(logtext + strlen(logtext), c->name);
+ log_text(buf);
- log_text(logtext);
+ MFREE(buf, char, len);
}
-/* log_message_method **********************************************************
+/* log_message_class ***********************************************************
- outputs log text like this:
+ Outputs log text like this:
- LOG: Compiling: java.lang.Object.clone()Ljava.lang.Object;
+ LOG: Loading class: java/lang/Object
*******************************************************************************/
-void log_message_method(char *msg, methodinfo *m)
+void log_message_class(const char *msg, classinfo *c)
{
- char logtext[MAXLOGTEXT];
-
- sprintf(logtext, msg);
- utf_sprint_classname(logtext + strlen(logtext), m->class->name);
- strcpy(logtext + strlen(logtext), ".");
- utf_sprint(logtext + strlen(logtext), m->name);
- utf_sprint_classname(logtext + strlen(logtext), m->descriptor);
-
- log_text(logtext);
+ log_message_utf(msg, c->name);
}
-/************************** Function: error *******************************
+/* log_message_class_message_class *********************************************
-Like dolog(), but terminates the program immediately.
+ Outputs log text like this:
-**************************************************************************/
+ LOG: Initialize super class java/lang/Object from java/lang/VMThread
+
+*******************************************************************************/
-void error(char *txt, ...)
+void log_message_class_message_class(const char *msg1, classinfo *c1,
+ const char *msg2, classinfo *c2)
{
- char logtext[MAXLOGTEXT];
- va_list ap;
+ char *buf;
+ s4 len;
- va_start(ap, txt);
- vsprintf(logtext, txt, ap);
- va_end(ap);
+ len =
+ strlen(msg1) + utf_bytes(c1->name) +
+ strlen(msg2) + utf_bytes(c2->name) + strlen("0");
- if (logfile) {
- fprintf(logfile, "ERROR: %s\n", logtext);
- }
+ buf = MNEW(char, len);
- fprintf(stderr, "ERROR: %s\n", logtext);
+ strcpy(buf, msg1);
+ utf_cat_classname(buf, c1->name);
+ strcat(buf, msg2);
+ utf_cat_classname(buf, c2->name);
- exit(1);
+ log_text(buf);
+
+ MFREE(buf, char, len);
}
-/************************ Function: panic (txt) ****************************
+/* log_message_method **********************************************************
- Like error(), takes the text to output as an argument
+ Outputs log text like this:
-***************************************************************************/
+ LOG: Compiling: java.lang.Object.clone()Ljava/lang/Object;
-void panic(char *txt)
-{
- error("%s", txt);
-}
+*******************************************************************************/
+void log_message_method(const char *msg, methodinfo *m)
+{
+ char *buf;
+ s4 len;
-/********************** Function: getcputime ********************************
+ len = strlen(msg) + utf_bytes(m->clazz->name) + strlen(".") +
+ utf_bytes(m->name) + utf_bytes(m->descriptor) + strlen("0");
- Returns the used CPU time in microseconds
-
-****************************************************************************/
+ buf = MNEW(char, len);
-s8 getcputime()
-{
- struct rusage ru;
- int sec, usec;
+ strcpy(buf, msg);
+ utf_cat_classname(buf, m->clazz->name);
+ strcat(buf, ".");
+ utf_cat(buf, m->name);
+ utf_cat(buf, m->descriptor);
- getrusage(RUSAGE_SELF, &ru);
- sec = ru.ru_utime.tv_sec + ru.ru_stime.tv_sec;
- usec = ru.ru_utime.tv_usec + ru.ru_stime.tv_usec;
+ log_text(buf);
- return sec * 1000000 + usec;
+ MFREE(buf, char, len);
}
* c-basic-offset: 4
* tab-width: 4
* End:
+ * vim:noexpandtab:sw=4:ts=4:
*/