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_jamvm.c - code to be #included in jamvm */
21 #include <vmlog_jamvm.h>
25 /*** global variables ************************************************/
27 static vmlog_log *vmlog_global_log = NULL;
28 static VMLock vmlog_global_lock;
30 /*** locking *********************************************************/
32 #define VMLOG_LOCK(vml) lockVMLock(vmlog_global_lock,threadSelf())
33 #define VMLOG_UNLOCK(vml) unlockVMLock(vmlog_global_lock,threadSelf())
35 /*** include the vmlog code ******************************************/
39 /*** internal functions **********************************************/
41 void vmlog_jamvm_init(int *pargc,char **argv)
45 opts = vmlog_opt_parse_cmd_line(pargc,argv);
50 vmlog_global_log = vmlog_log_new(opts->prefix,1);
52 if (opts->ignoreprefix) {
53 vmlog_log_load_ignorelist(vmlog_global_log,
57 if (opts->stringprefix) {
58 vmlog_load_stringhash(vmlog_global_log,
65 static void vmlog_jamvm_do_log(vmlog_log_function fun,
66 Object *thread,MethodBlock *mb)
74 if (!vmlog_global_log)
77 cb = CLASS_CB(mb->class);
79 name = vmlog_concat4len(
80 cb->name,strlen(cb->name),
82 mb->name,strlen(mb->name),
83 mb->type,strlen(mb->type),
86 fun(vmlog_global_log,thread,name,namelen);
88 VMLOG_FREE_ARRAY(char,namelen+1,name);
91 /*** functions callable from jamvm ***********************************/
93 void vmlog_jamvm_enter_method(Object *thread,MethodBlock *mb)
95 vmlog_jamvm_do_log(vmlog_log_enter,thread,mb);
98 void vmlog_jamvm_leave_method(Object *thread,MethodBlock *mb)
100 vmlog_jamvm_do_log(vmlog_log_leave,thread,mb);
103 void vmlog_jamvm_unwnd_method(Object *thread,MethodBlock *mb)
105 vmlog_jamvm_do_log(vmlog_log_unwnd,thread,mb);
108 void vmlog_jamvm_throw(Object *thread,Object *exp)
114 if (!vmlog_global_log)
117 cb = CLASS_CB(exp->class);
120 vmlog_log_throw(vmlog_global_log,thread,cb->name,strlen(cb->name));
123 void vmlog_jamvm_catch(Object *thread,Object *exp)
129 if (!vmlog_global_log)
132 cb = CLASS_CB(exp->class);
135 vmlog_log_catch(vmlog_global_log,thread,cb->name,strlen(cb->name));
138 /* vim: noet ts=8 sw=8