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;
30 static vmlog_options *vmlog_cacao_options = NULL;
32 /*** locking *********************************************************/
34 #define VMLOG_LOCK(vml) lock_monitor_enter(vmlog_global_lock)
35 #define VMLOG_UNLOCK(vml) lock_monitor_exit(vmlog_global_lock)
37 /*** include the vmlog code ******************************************/
41 /*** internal functions **********************************************/
43 void vmlog_cacao_init()
45 if (!vmlog_cacao_options->prefix)
48 vmlog_global_log = vmlog_log_new(vmlog_cacao_options->prefix,1);
50 if (vmlog_cacao_options->ignoreprefix) {
51 vmlog_log_load_ignorelist(vmlog_global_log,
52 vmlog_cacao_options->ignoreprefix);
55 if (vmlog_cacao_options->stringprefix) {
56 vmlog_load_stringhash(vmlog_global_log,
57 vmlog_cacao_options->stringprefix);
60 vmlog_opt_free(vmlog_cacao_options);
61 vmlog_cacao_options = NULL;
64 void vmlog_cacao_init_lock(void)
66 vmlog_global_lock = NEW(java_object_t);
67 lock_init_object_lock(vmlog_global_lock);
70 static void vmlog_cacao_do_log(vmlog_log_function fun,
78 if (!vmlog_global_log)
81 name = vmlog_concat4len(m->class->name->text,m->class->name->blength,
83 m->name->text,m->name->blength,
84 m->descriptor->text,m->descriptor->blength,
87 fun(vmlog_global_log,(void*) THREADOBJECT,name,namelen);
89 VMLOG_FREE_ARRAY(char,namelen+1,name);
92 /*** functions callable from cacao ***********************************/
94 void vmlog_cacao_enter_method(methodinfo *m)
96 vmlog_cacao_do_log(vmlog_log_enter,m);
99 void vmlog_cacao_leave_method(methodinfo *m)
101 vmlog_cacao_do_log(vmlog_log_leave,m);
104 void vmlog_cacao_unrol_method(methodinfo *m)
106 vmlog_cacao_do_log(vmlog_log_unrol,m);
109 void vmlog_cacao_rerol_method(methodinfo *m)
111 vmlog_cacao_do_log(vmlog_log_rerol,m);
114 void vmlog_cacao_unwnd_method(methodinfo *m)
116 vmlog_cacao_do_log(vmlog_log_unwnd,m);
119 void vmlog_cacao_throw(java_object_t *xptr)
123 if (!vmlog_global_log)
127 c = xptr->vftbl->class;
128 vmlog_log_throw(vmlog_global_log,(void*) THREADOBJECT,
129 c->name->text,c->name->blength);
132 vmlog_log_throw(vmlog_global_log,(void*) THREADOBJECT,
133 "unknown Throwable",strlen("unknown Throwable"));
137 void vmlog_cacao_catch(java_object_t *xptr)
141 if (!vmlog_global_log)
145 c = xptr->vftbl->class;
146 vmlog_log_catch(vmlog_global_log,(void*) THREADOBJECT,
147 c->name->text,c->name->blength);
150 vmlog_log_catch(vmlog_global_log,(void*) THREADOBJECT,
151 "unknown Throwable",strlen("unknown Throwable"));
155 void vmlog_cacao_signl(const char *name)
157 if (!vmlog_global_log)
160 vmlog_log_signl(vmlog_global_log,(void*) THREADOBJECT,
164 void vmlog_cacao_init_options(void)
166 vmlog_cacao_options = vmlog_opt_new();
169 void vmlog_cacao_set_prefix(const char *arg)
171 vmlog_opt_set_prefix(vmlog_cacao_options, arg);
174 void vmlog_cacao_set_stringprefix(const char *arg)
176 vmlog_opt_set_stringprefix(vmlog_cacao_options, arg);
179 void vmlog_cacao_set_ignoreprefix(const char *arg)
181 vmlog_opt_set_ignoreprefix(vmlog_cacao_options, arg);
184 /* vim: noet ts=8 sw=8