* src/vm/jit/i386/darwin/md-asm.h: Repaired --enable-cycles-stats.
[cacao.git] / contrib / vmlog / vmlog_cacao.c
1 /* vmlog - high-speed logging for free VMs                  */
2 /* Copyright (C) 2006 Edwin Steiner <edwin.steiner@gmx.net> */
3
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.
8  *
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.
13  *
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
17  */
18
19 /* vmlog_cacao.c - code to be #included in cacao */
20
21 #include <vmlog_cacao.h>
22 #define VMLOG_HAVE_PTRINT
23 #include <vmlog.h>
24 #include <assert.h>
25
26 /*** global variables ************************************************/
27
28 static vmlog_log *vmlog_global_log = NULL;
29 static java_objectheader vmlog_global_lock;
30
31 /*** locking *********************************************************/
32
33 #define VMLOG_LOCK(vml)    lock_monitor_enter(&vmlog_global_lock)
34 #define VMLOG_UNLOCK(vml)  lock_monitor_exit(&vmlog_global_lock)
35
36 /*** include the vmlog code ******************************************/
37
38 #include <vmlog.c>
39
40 /*** internal functions **********************************************/
41
42 void vmlog_cacao_init(JavaVMInitArgs *vmargs)
43 {
44         vmlog_options *opts;
45
46         opts = vmlog_opt_parse_vmargs(vmargs);
47         
48         if (!opts->prefix)
49                 return;
50
51         vmlog_global_log = vmlog_log_new(opts->prefix,1);
52
53         if (opts->ignoreprefix) {
54                 vmlog_log_load_ignorelist(vmlog_global_log,
55                                 opts->ignoreprefix);
56         }
57
58         if (opts->stringprefix) {
59                 vmlog_load_stringhash(vmlog_global_log,
60                                 opts->stringprefix);
61         }
62
63         vmlog_opt_free(opts);
64 }
65
66 void vmlog_cacao_init_lock(void)
67 {
68         lock_init_object_lock(&vmlog_global_lock);
69 }
70
71 static void vmlog_cacao_do_log(vmlog_log_function fun,
72                                methodinfo *m)
73 {
74         char *name;
75         int namelen;
76
77         assert(m);
78
79         if (!vmlog_global_log)
80                 return;
81
82         name = vmlog_concat4len(m->class->name->text,m->class->name->blength,
83                                 ".",1,
84                                 m->name->text,m->name->blength,
85                                 m->descriptor->text,m->descriptor->blength,
86                                 &namelen);
87
88         fun(vmlog_global_log,(void*) THREADOBJECT,name,namelen);
89
90         VMLOG_FREE_ARRAY(char,namelen+1,name);
91 }
92
93 /*** functions callable from cacao ***********************************/
94
95 void vmlog_cacao_enter_method(methodinfo *m)
96 {
97         vmlog_cacao_do_log(vmlog_log_enter,m);
98 }
99
100 void vmlog_cacao_leave_method(methodinfo *m)
101 {
102         vmlog_cacao_do_log(vmlog_log_leave,m);
103 }
104
105 void vmlog_cacao_unrol_method(methodinfo *m)
106 {
107         vmlog_cacao_do_log(vmlog_log_unrol,m);
108 }
109
110 void vmlog_cacao_rerol_method(methodinfo *m)
111 {
112         vmlog_cacao_do_log(vmlog_log_rerol,m);
113 }
114
115 void vmlog_cacao_unwnd_method(methodinfo *m)
116 {
117         vmlog_cacao_do_log(vmlog_log_unwnd,m);
118 }
119
120 void vmlog_cacao_throw(java_objectheader *xptr)
121 {
122         classinfo *c;
123         
124         if (!vmlog_global_log)
125                 return;
126
127         if (xptr) {
128                 c = xptr->vftbl->class;
129                 vmlog_log_throw(vmlog_global_log,(void*) THREADOBJECT,
130                                 c->name->text,c->name->blength);
131         }
132         else {
133                 vmlog_log_throw(vmlog_global_log,(void*) THREADOBJECT,
134                                 "unknown Throwable",strlen("unknown Throwable"));
135         }
136 }
137
138 void vmlog_cacao_catch(java_objectheader *xptr)
139 {
140         classinfo *c;
141         
142         if (!vmlog_global_log)
143                 return;
144
145         if (xptr) {
146                 c = xptr->vftbl->class;
147                 vmlog_log_catch(vmlog_global_log,(void*) THREADOBJECT,
148                                 c->name->text,c->name->blength);
149         }
150         else {
151                 vmlog_log_catch(vmlog_global_log,(void*) THREADOBJECT,
152                                 "unknown Throwable",strlen("unknown Throwable"));
153         }
154 }
155
156 void vmlog_cacao_signl(const char *name)
157 {
158         if (!vmlog_global_log)
159                 return;
160
161         vmlog_log_signl(vmlog_global_log,(void*) THREADOBJECT,
162                         name, strlen(name));
163 }
164
165 /* vim: noet ts=8 sw=8
166  */
167