0e6656bb49ed7a8acc353d31de61ae0993cbb5b1
[cacao.git] / src / vm / hook.hpp
1 /* src/vm/hook.hpp - hook points inside the VM
2
3    Copyright (C) 2009
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6    This file is part of CACAO.
7
8    This program is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License as
10    published by the Free Software Foundation; either version 2, or (at
11    your option) any later version.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23 */
24
25
26 #ifndef _HOOK_HPP
27 #define _HOOK_HPP
28
29 #include "config.h"
30
31 #if defined(ENABLE_OPAGENT)
32 #include "vm/jit/oprofile-agent.hpp"
33 #endif
34
35
36 /**
37  * Hook points are inline functions acting as probes scattered throughout
38  * several VM subsystems. They can be used to implement event generation
39  * or statistics gathering without polluting the source code. Hence all
40  * compiler macro and runtime checks should be done in this file. One
41  * example of where hooks are useful is JVMTI event firing.
42  */
43 namespace Hook {
44         void breakpoint     (Breakpoint *bp);
45         void class_linked   (classinfo *c);
46         void class_loaded   (classinfo *c);
47         void jit_generated  (methodinfo *m, codeinfo *code);
48         void jit_recycled   (methodinfo *m, codeinfo *code);
49         void method_enter   (methodinfo *m);
50         void method_exit    (methodinfo *m);
51         void method_unwind  (methodinfo *m);
52         void native_resolved(methodinfo *m, void *symbol, void **symbolptr);
53         void thread_start   (threadobject *t);
54         void thread_end     (threadobject *t);
55         void vm_init        ();
56         void vm_preinit     ();
57         void vm_shutdown    ();
58 }
59
60
61 inline void Hook::breakpoint(Breakpoint *bp)
62 {
63 #if defined(ENABLE_JVMTI)
64         methodinfo* m = bp->method;
65         int32_t     l = bp->location;
66
67         log_message_method("JVMTI: Reached breakpoint in method ", m);
68         log_println("JVMTI: Reached breakpoint at location %d", l);
69 #endif
70 }
71
72 inline void Hook::class_linked(classinfo *c)
73 {
74         /* nop */
75 }
76
77 inline void Hook::class_loaded(classinfo *c)
78 {
79         /* nop */
80 }
81
82 /**
83  * Hook point just after code was generated. Note that one method can have
84  * multiple code realizations, the hook is fired for each of them. The code
85  * was not yet executed.
86  *
87  * @param m The method for which code was generated.
88  * @param code The fully initialized codeinfo for the generated code.
89  */
90 inline void Hook::jit_generated(methodinfo *m, codeinfo *code)
91 {
92 #if defined(ENABLE_OPAGENT)
93         if (opt_EnableOpagent)
94                 OprofileAgent::newmethod(m);
95 #endif
96 }
97
98 inline void Hook::method_enter(methodinfo *m)
99 {
100         /* nop */
101 }
102
103 inline void Hook::method_exit(methodinfo *m)
104 {
105         /* nop */
106 }
107
108 inline void Hook::method_unwind(methodinfo *m)
109 {
110         /* nop */
111 }
112
113 inline void Hook::native_resolved(methodinfo *m, void *symbol, void **symbolptr)
114 {
115         /* nop */
116 }
117
118 inline void Hook::thread_start(threadobject *t)
119 {
120         /* nop */
121 }
122
123 inline void Hook::thread_end(threadobject *t)
124 {
125         /* nop */
126 }
127
128 /**
129  * Hook point after the VM is initialized. At this point the VM is fully
130  * operating and ready to execute Java code. Final intializations and thread
131  * startup should be done here.
132  */
133 inline void Hook::vm_init()
134 {
135         /* nop */
136 }
137
138 /**
139  * Hook point before the VM is initialized. At this point the VM can not
140  * yet execute Java code but some central native subsystems are initialized.
141  * Only basic initialization steps should be done here.
142  */
143 inline void Hook::vm_preinit()
144 {
145 #if defined(ENABLE_OPAGENT)
146         if (opt_EnableOpagent)
147                 OprofileAgent::initialize();
148 #endif
149 }
150
151 /**
152  * Hook point before the VM is actually destroyed. At this point the VM is
153  * still running, but all non-daemon threads have terminated and resources
154  * are ready to be reclaimed. Final cleanup tasks should be done here.
155  */
156 inline void Hook::vm_shutdown()
157 {
158 #if defined(ENABLE_OPAGENT)
159         if (opt_EnableOpagent)
160                 OprofileAgent::close();
161 #endif
162 }
163
164
165 #endif /* _HOOK_HPP */
166
167
168 /*
169  * These are local overrides for various environment variables in Emacs.
170  * Please do not remove this and leave it at the end of the file, where
171  * Emacs will automagically detect them.
172  * ---------------------------------------------------------------------
173  * Local variables:
174  * mode: c++
175  * indent-tabs-mode: t
176  * c-basic-offset: 4
177  * tab-width: 4
178  * End:
179  * vim:noexpandtab:sw=4:ts=4:
180  */