1 /* src/vm/hook.hpp - hook points inside the VM
3 Copyright (C) 2009, 2010
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
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.
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.
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
30 #include "vm/globals.hpp"
32 #if defined(ENABLE_OPAGENT)
33 #include "vm/jit/oprofile-agent.hpp"
38 * Hook points are inline functions acting as probes scattered throughout
39 * several VM subsystems. They can be used to implement event generation
40 * or statistics gathering without polluting the source code. Hence all
41 * compiler macro and runtime checks should be done in this file. One
42 * example of where hooks are useful is JVMTI event firing.
45 void breakpoint (Breakpoint *bp);
46 void class_linked (classinfo *c);
47 void class_loaded (classinfo *c);
48 void jit_generated (methodinfo *m, codeinfo *code);
49 void jit_recycled (methodinfo *m, codeinfo *code);
50 void method_enter (methodinfo *m);
51 void method_exit (methodinfo *m);
52 void method_unwind (methodinfo *m);
53 void native_resolved(methodinfo *m, void *symbol, void **symbolptr);
54 void thread_start (threadobject *t);
55 void thread_end (threadobject *t);
62 inline void Hook::breakpoint(Breakpoint *bp)
64 #if defined(ENABLE_JVMTI)
65 methodinfo* m = bp->method;
66 int32_t l = bp->location;
68 log_message_method("JVMTI: Reached breakpoint in method ", m);
69 log_println("JVMTI: Reached breakpoint at location %d", l);
73 inline void Hook::class_linked(classinfo *c)
75 if (c == class_java_lang_String)
76 linker_initialize_deferred_strings();
79 inline void Hook::class_loaded(classinfo *c)
85 * Hook point just after code was generated. Note that one method can have
86 * multiple code realizations, the hook is fired for each of them. The code
87 * was not yet executed.
89 * @param m The method for which code was generated.
90 * @param code The fully initialized codeinfo for the generated code.
92 inline void Hook::jit_generated(methodinfo *m, codeinfo *code)
94 #if defined(ENABLE_OPAGENT)
95 if (opt_EnableOpagent)
96 OprofileAgent::newmethod(m);
100 inline void Hook::method_enter(methodinfo *m)
105 inline void Hook::method_exit(methodinfo *m)
110 inline void Hook::method_unwind(methodinfo *m)
115 inline void Hook::native_resolved(methodinfo *m, void *symbol, void **symbolptr)
120 inline void Hook::thread_start(threadobject *t)
125 inline void Hook::thread_end(threadobject *t)
131 * Hook point after the VM is initialized. At this point the VM is fully
132 * operating and ready to execute Java code. Final intializations and thread
133 * startup should be done here.
135 inline void Hook::vm_init()
141 * Hook point before the VM is initialized. At this point the VM can not
142 * yet execute Java code but some central native subsystems are initialized.
143 * Only basic initialization steps should be done here.
145 inline void Hook::vm_preinit()
147 #if defined(ENABLE_OPAGENT)
148 if (opt_EnableOpagent)
149 OprofileAgent::initialize();
154 * Hook point before the VM is actually destroyed. At this point the VM is
155 * still running, but all non-daemon threads have terminated and resources
156 * are ready to be reclaimed. Final cleanup tasks should be done here.
158 inline void Hook::vm_shutdown()
160 #if defined(ENABLE_OPAGENT)
161 if (opt_EnableOpagent)
162 OprofileAgent::close();
167 #endif /* _HOOK_HPP */
171 * These are local overrides for various environment variables in Emacs.
172 * Please do not remove this and leave it at the end of the file, where
173 * Emacs will automagically detect them.
174 * ---------------------------------------------------------------------
177 * indent-tabs-mode: t
181 * vim:noexpandtab:sw=4:ts=4: