1 /* src/toolbox/logging.c - contains logging functions
3 Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
36 #include "mm/memory.h"
37 #include "toolbox/logging.h"
38 #include "toolbox/util.h"
39 #include "vm/global.h"
41 #if defined(ENABLE_STATISTICS)
42 # include "vmcore/statistics.h"
46 /***************************************************************************
48 ***************************************************************************/
53 void log_init(const char *fname)
57 logfile = fopen(fname, "w");
63 /* log_start *******************************************************************
65 Writes the preleading LOG: text to the protocol file (if opened) or
68 *******************************************************************************/
70 /* ATTENTION: Don't include threads-common.h, because we can't
71 bootstrap this file in that case (missing java_lang_Thread.h).
72 Instead we declare threads_get_current_threadobject differently: */
74 /* #if defined(ENABLE_THREADS) */
75 /* # include "threads/threads-common.h" */
78 extern ptrint threads_get_current_tid(void);
83 #if defined(ENABLE_THREADS)
86 tid = threads_get_current_tid();
90 #if defined(ENABLE_THREADS)
91 # if SIZEOF_VOID_P == 8
92 fprintf(logfile, "[0x%016lx] ", tid );
94 fprintf(logfile, "[0x%08x] ", tid);
99 #if defined(ENABLE_THREADS)
100 # if SIZEOF_VOID_P == 8
101 fprintf(stdout, "LOG: [0x%016lx] ", tid);
103 fprintf(stdout, "LOG: [0x%08x] ", tid);
106 fputs("LOG: ", stdout);
112 /* log_vprint ******************************************************************
114 Writes logtext to the protocol file (if opened) or to stdout.
116 *******************************************************************************/
118 void log_vprint(const char *text, va_list ap)
121 vfprintf(logfile, text, ap);
123 vfprintf(stdout, text, ap);
127 /* log_print *******************************************************************
129 Writes logtext to the protocol file (if opened) or to stdout.
131 *******************************************************************************/
133 void log_print(const char *text, ...)
138 log_vprint(text, ap);
143 /* log_println *****************************************************************
145 Writes logtext to the protocol file (if opened) or to stdout with a
148 *******************************************************************************/
150 void log_println(const char *text, ...)
157 log_vprint(text, ap);
164 /* log_finish ******************************************************************
166 Finishes a logtext line with trailing newline and a fflush.
168 *******************************************************************************/
170 void log_finish(void)
173 fputs("\n", logfile);
183 /* log_message_utf *************************************************************
185 Outputs log text like this:
187 LOG: Creating class: java/lang/Object
189 *******************************************************************************/
191 void log_message_utf(const char *msg, utf *u)
196 len = strlen(msg) + utf_bytes(u) + strlen("0");
198 buf = MNEW(char, len);
205 MFREE(buf, char, len);
209 /* log_message_class ***********************************************************
211 Outputs log text like this:
213 LOG: Loading class: java/lang/Object
215 *******************************************************************************/
217 void log_message_class(const char *msg, classinfo *c)
219 log_message_utf(msg, c->name);
223 /* log_message_class_message_class *********************************************
225 Outputs log text like this:
227 LOG: Initialize super class java/lang/Object from java/lang/VMThread
229 *******************************************************************************/
231 void log_message_class_message_class(const char *msg1, classinfo *c1,
232 const char *msg2, classinfo *c2)
238 strlen(msg1) + utf_bytes(c1->name) +
239 strlen(msg2) + utf_bytes(c2->name) + strlen("0");
241 buf = MNEW(char, len);
244 utf_cat_classname(buf, c1->name);
246 utf_cat_classname(buf, c2->name);
250 MFREE(buf, char, len);
254 /* log_message_method **********************************************************
256 Outputs log text like this:
258 LOG: Compiling: java.lang.Object.clone()Ljava/lang/Object;
260 *******************************************************************************/
262 void log_message_method(const char *msg, methodinfo *m)
267 len = strlen(msg) + utf_bytes(m->class->name) + strlen(".") +
268 utf_bytes(m->name) + utf_bytes(m->descriptor) + strlen("0");
270 buf = MNEW(char, len);
273 utf_cat_classname(buf, m->class->name);
275 utf_cat(buf, m->name);
276 utf_cat(buf, m->descriptor);
280 MFREE(buf, char, len);
285 * These are local overrides for various environment variables in Emacs.
286 * Please do not remove this and leave it at the end of the file, where
287 * Emacs will automagically detect them.
288 * ---------------------------------------------------------------------
291 * indent-tabs-mode: t
295 * vim:noexpandtab:sw=4:ts=4: