1 /* src/toolbox/logging.c - contains logging functions
3 Copyright (C) 1996-2005, 2006, 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
34 #include "mm/memory.h"
36 #include "threads/thread.hpp"
38 #include "toolbox/logging.h"
39 #include "toolbox/util.h"
41 #include "vm/global.h"
43 #if defined(ENABLE_STATISTICS)
44 # include "vm/statistics.h"
48 /***************************************************************************
50 ***************************************************************************/
55 void log_init(const char *fname)
59 logfile = fopen(fname, "w");
65 /* log_start *******************************************************************
67 Writes the preleading LOG: text to the protocol file (if opened) or
70 *******************************************************************************/
74 #if defined(ENABLE_THREADS)
77 tid = threads_get_current_tid();
81 #if defined(ENABLE_THREADS)
82 # if SIZEOF_VOID_P == 8
83 fprintf(logfile, "[0x%016lx] ", tid );
85 fprintf(logfile, "[0x%08x] ", tid);
90 #if defined(ENABLE_THREADS)
91 # if SIZEOF_VOID_P == 8
92 fprintf(stdout, "LOG: [0x%016lx] ", tid);
94 fprintf(stdout, "LOG: [0x%08x] ", tid);
97 fputs("LOG: ", stdout);
103 /* log_vprint ******************************************************************
105 Writes logtext to the protocol file (if opened) or to stdout.
107 *******************************************************************************/
109 void log_vprint(const char *text, va_list ap)
112 vfprintf(logfile, text, ap);
114 vfprintf(stdout, text, ap);
118 /* log_print *******************************************************************
120 Writes logtext to the protocol file (if opened) or to stdout.
122 *******************************************************************************/
124 void log_print(const char *text, ...)
129 log_vprint(text, ap);
134 /* log_println *****************************************************************
136 Writes logtext to the protocol file (if opened) or to stdout with a
139 *******************************************************************************/
141 void log_println(const char *text, ...)
148 log_vprint(text, ap);
155 /* log_finish ******************************************************************
157 Finishes a logtext line with trailing newline and a fflush.
159 *******************************************************************************/
161 void log_finish(void)
164 fputs("\n", logfile);
174 /* log_message_utf *************************************************************
176 Outputs log text like this:
178 LOG: Creating class: java/lang/Object
180 *******************************************************************************/
182 void log_message_utf(const char *msg, utf *u)
187 len = strlen(msg) + utf_bytes(u) + strlen("0");
189 buf = MNEW(char, len);
196 MFREE(buf, char, len);
200 /* log_message_class ***********************************************************
202 Outputs log text like this:
204 LOG: Loading class: java/lang/Object
206 *******************************************************************************/
208 void log_message_class(const char *msg, classinfo *c)
210 log_message_utf(msg, c->name);
214 /* log_message_class_message_class *********************************************
216 Outputs log text like this:
218 LOG: Initialize super class java/lang/Object from java/lang/VMThread
220 *******************************************************************************/
222 void log_message_class_message_class(const char *msg1, classinfo *c1,
223 const char *msg2, classinfo *c2)
229 strlen(msg1) + utf_bytes(c1->name) +
230 strlen(msg2) + utf_bytes(c2->name) + strlen("0");
232 buf = MNEW(char, len);
235 utf_cat_classname(buf, c1->name);
237 utf_cat_classname(buf, c2->name);
241 MFREE(buf, char, len);
245 /* log_message_method **********************************************************
247 Outputs log text like this:
249 LOG: Compiling: java.lang.Object.clone()Ljava/lang/Object;
251 *******************************************************************************/
253 void log_message_method(const char *msg, methodinfo *m)
258 len = strlen(msg) + utf_bytes(m->clazz->name) + strlen(".") +
259 utf_bytes(m->name) + utf_bytes(m->descriptor) + strlen("0");
261 buf = MNEW(char, len);
264 utf_cat_classname(buf, m->clazz->name);
266 utf_cat(buf, m->name);
267 utf_cat(buf, m->descriptor);
271 MFREE(buf, char, len);
276 * These are local overrides for various environment variables in Emacs.
277 * Please do not remove this and leave it at the end of the file, where
278 * Emacs will automagically detect them.
279 * ---------------------------------------------------------------------
282 * indent-tabs-mode: t
286 * vim:noexpandtab:sw=4:ts=4: