/* 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
Changes: Christian Thalinger
+ Edwin Steiner
- $Id: logging.c 2133 2005-03-30 09:49:41Z twisti $
+ $Id: logging.c 4967 2006-05-26 16:24:58Z edwin $
*/
+#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 "toolbox/logging.h"
+#include "toolbox/util.h"
#include "vm/global.h"
-#include "vm/tables.h"
#include "vm/statistics.h"
+#if defined(ENABLE_THREADS)
+# include "threads/native/threads.h"
+#endif
+
/***************************************************************************
LOG FILE HANDLING
}
-/*********************** 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(const char *txt, ...)
+void log_start(void)
{
- char logtext[MAXLOGTEXT];
- va_list ap;
-
- va_start(ap, txt);
- vsprintf(logtext, txt, ap);
- va_end(ap);
-
if (logfile) {
- fprintf(logfile, "%s\n",logtext);
- fflush(logfile);
+#if defined(ENABLE_THREADS)
+ fprintf(logfile, "[%p] ", (void *) THREADOBJECT);
+#endif
} else {
- fprintf(stdout,"LOG: %s\n",logtext);
- fflush(stdout);
+#if defined(ENABLE_THREADS)
+ fprintf(stdout, "LOG: [%p] ", (void *) THREADOBJECT);
+#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(const 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(const char *text)
-{
- dolog("%s", text);
-}
+/* log_print *******************************************************************
+ Writes logtext to the protocol file (if opened) or to stdout.
-/******************** Function: log_plain *******************************/
+*******************************************************************************/
-void log_plain(const 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 *******************************/
-FILE *get_logfile(void)
-{
- return (logfile) ? logfile : stdout;
-}
+/* log_println *****************************************************************
+ Writes logtext to the protocol file (if opened) or to stdout with a
+ trailing newline.
-/****************** Function: log_flush *********************************/
+*******************************************************************************/
-void log_flush(void)
+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(void)
-{
- log_plain("\n");
- fflush(get_logfile());
+ log_finish();
}
-/* log_cputime *****************************************************************
+/* log_finish ******************************************************************
- XXX
+ Finishes a logtext line with trailing newline and a fflush.
*******************************************************************************/
-#if defined(STATISTICS)
-void log_cputime(void)
+void log_finish(void)
{
- s8 t;
- int sec, usec;
- char logtext[MAXLOGTEXT];
+ if (logfile) {
+ fflush(logfile);
- t = getcputime();
- sec = t / 1000000;
- usec = t % 1000000;
+ } else {
+ fputs("\n", stdout);
- sprintf(logtext, "Total CPU usage: %d seconds and %d milliseconds",
- sec, usec / 1000);
- log_text(logtext);
+ fflush(stdout);
+ }
}
-#endif
-/* 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(const char *msg, classinfo *c)
+void log_message_utf(const char *msg, utf *u)
{
char *buf;
s4 len;
- len = strlen(msg) + utf_strlen(c->name) + strlen("0");
+ len = strlen(msg) + utf_bytes(u) + strlen("0");
buf = MNEW(char, len);
strcpy(buf, msg);
- utf_strcat(buf, c->name);
+ utf_cat(buf, u);
log_text(buf);
}
-/* 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(const char *msg, methodinfo *m)
+void log_message_class(const char *msg, classinfo *c)
{
- char *buf;
- s4 len;
-
- len = strlen(msg) + utf_strlen(m->class->name) + strlen(".") +
- utf_strlen(m->name) + utf_strlen(m->descriptor) + strlen("0");
-
- buf = MNEW(char, len);
-
- 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);
-
- MFREE(buf, char, len);
+ log_message_utf(msg, c->name);
}
-/* error ***********************************************************************
+/* log_message_class_message_class *********************************************
+
+ Outputs log text like this:
- Like dolog(), but terminates the program immediately.
+ LOG: Initialize super class java/lang/Object from java/lang/VMThread
*******************************************************************************/
-void error(const char *txt, ...)
+void log_message_class_message_class(const char *msg1, classinfo *c1,
+ const char *msg2, classinfo *c2)
{
- 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(msg1) + utf_bytes(c1->name) +
+ strlen(msg2) + utf_bytes(c2->name) + strlen("0");
-/* panic ***********************************************************************
+ buf = MNEW(char, len);
- Like error(), takes the text to output as an argument.
+ strcpy(buf, msg1);
+ utf_cat_classname(buf, c1->name);
+ strcat(buf, msg2);
+ utf_cat_classname(buf, c2->name);
-*******************************************************************************/
+ log_text(buf);
-void panic(const char *txt)
-{
- error("%s", txt);
+ MFREE(buf, char, len);
}
-/* log_utf *********************************************************************
+/* log_message_method **********************************************************
+
+ Outputs log text like this:
- Log utf symbol.
+ LOG: Compiling: java.lang.Object.clone()Ljava/lang/Object;
*******************************************************************************/
-void log_utf(utf *u)
+void log_message_method(const char *msg, methodinfo *m)
{
- char buf[MAXLOGTEXT];
- utf_sprint(buf, u);
- dolog("%s", buf);
-}
+ char *buf;
+ s4 len;
+ len = strlen(msg) + utf_bytes(m->class->name) + strlen(".") +
+ utf_bytes(m->name) + utf_bytes(m->descriptor) + strlen("0");
-/* log_plain_utf ***************************************************************
+ buf = MNEW(char, len);
- Log utf symbol (without printing "LOG: " and newline).
+ strcpy(buf, msg);
+ utf_cat_classname(buf, m->class->name);
+ strcat(buf, ".");
+ utf_cat(buf, m->name);
+ utf_cat(buf, m->descriptor);
-*******************************************************************************/
+ log_text(buf);
-void log_plain_utf(utf *u)
-{
- char buf[MAXLOGTEXT];
- utf_sprint(buf, u);
- dolog_plain("%s", buf);
+ MFREE(buf, char, len);
}
* c-basic-offset: 4
* tab-width: 4
* End:
+ * vim:noexpandtab:sw=4:ts=4:
*/