CACAO
hook.hpp
Go to the documentation of this file.
1 /* src/vm/hook.hpp - hook points inside the VM
2 
3  Copyright (C) 2009, 2011
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 "breakpoint.hpp" // for Breakpoint
30 #include "linker.hpp"
31 #include "method.hpp" // for methodinfo (ptr only), etc
32 #include "vm/globals.hpp" // for class_java_lang_String
33 
34 struct classinfo;
35 struct threadobject;
36 
37 #if defined(ENABLE_OPAGENT)
39 #endif
40 
41 
42 /**
43  * Hook points are inline functions acting as probes scattered throughout
44  * several VM subsystems. They can be used to implement event generation
45  * or statistics gathering without polluting the source code. Hence all
46  * compiler macro and runtime checks should be done in this file. One
47  * example of where hooks are useful is JVMTI event firing.
48  */
49 namespace Hook {
50  void breakpoint (Breakpoint *bp);
51  bool class_linked (classinfo *c);
52  void class_loaded (classinfo *c);
53  void jit_generated (methodinfo *m, codeinfo *code);
54  void jit_recycled (methodinfo *m, codeinfo *code);
55  void method_enter (methodinfo *m);
56  void method_exit (methodinfo *m);
57  void method_unwind (methodinfo *m);
58  void native_resolved(methodinfo *m, void *symbol, void **symbolptr);
59  void thread_start (threadobject *t);
60  void thread_end (threadobject *t);
61  void vm_init ();
62  void vm_preinit ();
63  void vm_shutdown ();
64 
65  // Non-inline functions
67 }
68 
69 
71 {
72 #if defined(ENABLE_JVMTI)
73  methodinfo* m = bp->method;
74  int32_t l = bp->location;
75 
76  log_message_method("JVMTI: Reached breakpoint in method ", m);
77  log_println("JVMTI: Reached breakpoint at location %d", l);
78 #endif
79 }
80 
82 {
83  if (c == class_java_lang_String)
85 
86  return class_linked_dynoffsets(c);
87 }
88 
90 {
91  /* nop */
92 }
93 
94 /**
95  * Hook point just after code was generated. Note that one method can have
96  * multiple code realizations, the hook is fired for each of them. The code
97  * was not yet executed.
98  *
99  * @param m The method for which code was generated.
100  * @param code The fully initialized codeinfo for the generated code.
101  */
103 {
104 #if defined(ENABLE_OPAGENT)
105  if (opt_EnableOpagent)
107 #endif
108 }
109 
111 {
112  /* nop */
113 }
114 
116 {
117  /* nop */
118 }
119 
121 {
122  /* nop */
123 }
124 
125 inline void Hook::native_resolved(methodinfo *m, void *symbol, void **symbolptr)
126 {
127  /* nop */
128 }
129 
131 {
132  /* nop */
133 }
134 
136 {
137  /* nop */
138 }
139 
140 /**
141  * Hook point after the VM is initialized. At this point the VM is fully
142  * operating and ready to execute Java code. Final intializations and thread
143  * startup should be done here.
144  */
145 inline void Hook::vm_init()
146 {
147  /* nop */
148 }
149 
150 /**
151  * Hook point before the VM is initialized. At this point the VM can not
152  * yet execute Java code but some central native subsystems are initialized.
153  * Only basic initialization steps should be done here.
154  */
155 inline void Hook::vm_preinit()
156 {
157 #if defined(ENABLE_OPAGENT)
158  if (opt_EnableOpagent)
160 #endif
161 }
162 
163 /**
164  * Hook point before the VM is actually destroyed. At this point the VM is
165  * still running, but all non-daemon threads have terminated and resources
166  * are ready to be reclaimed. Final cleanup tasks should be done here.
167  */
168 inline void Hook::vm_shutdown()
169 {
170 #if defined(ENABLE_OPAGENT)
171  if (opt_EnableOpagent)
173 #endif
174 }
175 
176 
177 #endif /* _HOOK_HPP */
178 
179 
180 /*
181  * These are local overrides for various environment variables in Emacs.
182  * Please do not remove this and leave it at the end of the file, where
183  * Emacs will automagically detect them.
184  * ---------------------------------------------------------------------
185  * Local variables:
186  * mode: c++
187  * indent-tabs-mode: t
188  * c-basic-offset: 4
189  * tab-width: 4
190  * End:
191  * vim:noexpandtab:sw=4:ts=4:
192  */
static void newmethod(methodinfo *)
Reports the given method to oprofile.
void native_resolved(methodinfo *m, void *symbol, void **symbolptr)
Definition: hook.hpp:125
void thread_start(threadobject *t)
Definition: hook.hpp:130
static void initialize()
Initializes the OprofileAgent system.
void log_message_method(const char *msg, methodinfo *m)
Definition: logging.cpp:275
void jit_recycled(methodinfo *m, codeinfo *code)
bool class_linked_dynoffsets(classinfo *c)
Definition: hook.cpp:32
void linker_initialize_deferred_strings()
Definition: linker.cpp:1192
This structure contains information about a breakpoint.
Definition: breakpoint.hpp:41
void vm_preinit()
Hook point before the VM is initialized.
Definition: hook.hpp:155
void log_println(const char *text,...)
Definition: logging.cpp:193
void method_exit(methodinfo *m)
Definition: hook.hpp:115
void vm_shutdown()
Hook point before the VM is actually destroyed.
Definition: hook.hpp:168
bool class_linked(classinfo *c)
Definition: hook.hpp:81
static void close()
Shuts down the OprofileAgent system.
void thread_end(threadobject *t)
Definition: hook.hpp:135
void jit_generated(methodinfo *m, codeinfo *code)
Hook point just after code was generated.
Definition: hook.hpp:102
classinfo * class_java_lang_String
Definition: globals.cpp:39
void vm_init()
Hook point after the VM is initialized.
Definition: hook.hpp:145
#define bp
Definition: md-asm.hpp:44
void breakpoint(Breakpoint *bp)
Definition: hook.hpp:70
void method_enter(methodinfo *m)
Definition: hook.hpp:110
void method_unwind(methodinfo *m)
Definition: hook.hpp:120
void class_loaded(classinfo *c)
Definition: hook.hpp:89