1 /* vmlog - high-speed logging for free VMs */
2 /* Copyright (C) 2006 Edwin Steiner <edwin.steiner@gmx.net> */
4 /* This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 /* vmlog_cacao.c - code to be #included in cacao */
21 #include <vmlog_cacao.h>
22 #define VMLOG_HAVE_PTRINT
26 /*** global variables ************************************************/
28 static vmlog_log *vmlog_global_log = NULL;
29 static java_object_t *vmlog_global_lock = NULL;
31 /*** locking *********************************************************/
33 #define VMLOG_LOCK(vml) lock_monitor_enter(vmlog_global_lock)
34 #define VMLOG_UNLOCK(vml) lock_monitor_exit(vmlog_global_lock)
36 /*** include the vmlog code ******************************************/
40 /*** internal functions **********************************************/
42 void vmlog_cacao_init(JavaVMInitArgs *vmargs)
46 opts = vmlog_opt_parse_vmargs(vmargs);
51 vmlog_global_log = vmlog_log_new(opts->prefix,1);
53 if (opts->ignoreprefix) {
54 vmlog_log_load_ignorelist(vmlog_global_log,
58 if (opts->stringprefix) {
59 vmlog_load_stringhash(vmlog_global_log,
66 void vmlog_cacao_init_lock(void)
68 vmlog_global_lock = NEW(java_object_t);
69 lock_init_object_lock(vmlog_global_lock);
72 static void vmlog_cacao_do_log(vmlog_log_function fun,
80 if (!vmlog_global_log)
83 name = vmlog_concat4len(m->class->name->text,m->class->name->blength,
85 m->name->text,m->name->blength,
86 m->descriptor->text,m->descriptor->blength,
89 fun(vmlog_global_log,(void*) THREADOBJECT,name,namelen);
91 VMLOG_FREE_ARRAY(char,namelen+1,name);
94 /*** functions callable from cacao ***********************************/
96 void vmlog_cacao_enter_method(methodinfo *m)
98 vmlog_cacao_do_log(vmlog_log_enter,m);
101 void vmlog_cacao_leave_method(methodinfo *m)
103 vmlog_cacao_do_log(vmlog_log_leave,m);
106 void vmlog_cacao_unrol_method(methodinfo *m)
108 vmlog_cacao_do_log(vmlog_log_unrol,m);
111 void vmlog_cacao_rerol_method(methodinfo *m)
113 vmlog_cacao_do_log(vmlog_log_rerol,m);
116 void vmlog_cacao_unwnd_method(methodinfo *m)
118 vmlog_cacao_do_log(vmlog_log_unwnd,m);
121 void vmlog_cacao_throw(java_object_t *xptr)
125 if (!vmlog_global_log)
129 c = xptr->vftbl->class;
130 vmlog_log_throw(vmlog_global_log,(void*) THREADOBJECT,
131 c->name->text,c->name->blength);
134 vmlog_log_throw(vmlog_global_log,(void*) THREADOBJECT,
135 "unknown Throwable",strlen("unknown Throwable"));
139 void vmlog_cacao_catch(java_object_t *xptr)
143 if (!vmlog_global_log)
147 c = xptr->vftbl->class;
148 vmlog_log_catch(vmlog_global_log,(void*) THREADOBJECT,
149 c->name->text,c->name->blength);
152 vmlog_log_catch(vmlog_global_log,(void*) THREADOBJECT,
153 "unknown Throwable",strlen("unknown Throwable"));
157 void vmlog_cacao_signl(const char *name)
159 if (!vmlog_global_log)
162 vmlog_log_signl(vmlog_global_log,(void*) THREADOBJECT,
166 /* vim: noet ts=8 sw=8