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,
80 if (!vmlog_global_log)
84 cname = m->class->name->text;
85 cnamelen = m->class->name->blength;
92 name = vmlog_concat4len(cname,cnamelen,
94 m->name->text,m->name->blength,
95 m->descriptor->text,m->descriptor->blength,
98 fun(vmlog_global_log,(void*) THREADOBJECT,name,namelen);
100 VMLOG_FREE_ARRAY(char,namelen+1,name);
103 /*** functions callable from cacao ***********************************/
105 void vmlog_cacao_enter_method(methodinfo *m)
107 vmlog_cacao_do_log(vmlog_log_enter,m);
110 void vmlog_cacao_leave_method(methodinfo *m)
112 vmlog_cacao_do_log(vmlog_log_leave,m);
115 void vmlog_cacao_unrol_method(methodinfo *m)
117 vmlog_cacao_do_log(vmlog_log_unrol,m);
120 void vmlog_cacao_rerol_method(methodinfo *m)
122 vmlog_cacao_do_log(vmlog_log_rerol,m);
125 void vmlog_cacao_unwnd_method(methodinfo *m)
127 vmlog_cacao_do_log(vmlog_log_unwnd,m);
130 void vmlog_cacao_throw(java_object_t *xptr)
134 if (!vmlog_global_log)
138 c = xptr->vftbl->class;
139 vmlog_log_throw(vmlog_global_log,(void*) THREADOBJECT,
140 c->name->text,c->name->blength);
143 vmlog_log_throw(vmlog_global_log,(void*) THREADOBJECT,
144 "unknown Throwable",strlen("unknown Throwable"));
148 void vmlog_cacao_catch(java_object_t *xptr)
152 if (!vmlog_global_log)
156 c = xptr->vftbl->class;
157 vmlog_log_catch(vmlog_global_log,(void*) THREADOBJECT,
158 c->name->text,c->name->blength);
161 vmlog_log_catch(vmlog_global_log,(void*) THREADOBJECT,
162 "unknown Throwable",strlen("unknown Throwable"));
166 void vmlog_cacao_signl(const char *name)
168 if (!vmlog_global_log)
171 vmlog_log_signl(vmlog_global_log,(void*) THREADOBJECT,
175 void vmlog_cacao_signl_type(int type)
179 if (!vmlog_global_log)
182 sprintf(message, "EXC %d", type);
184 vmlog_log_signl(vmlog_global_log,(void*) THREADOBJECT,
185 message, strlen(message));
188 void vmlog_cacao_init_options(void)
190 vmlog_cacao_options = vmlog_opt_new();
193 void vmlog_cacao_set_prefix(const char *arg)
195 vmlog_opt_set_prefix(vmlog_cacao_options, arg);
198 void vmlog_cacao_set_stringprefix(const char *arg)
200 vmlog_opt_set_stringprefix(vmlog_cacao_options, arg);
203 void vmlog_cacao_set_ignoreprefix(const char *arg)
205 vmlog_opt_set_ignoreprefix(vmlog_cacao_options, arg);
208 /* vim: noet ts=8 sw=8