From 47d82d11dc092abdbabdc2bfab746ed3429044eb Mon Sep 17 00:00:00 2001 From: Michael Starzinger Date: Mon, 2 Nov 2009 13:19:05 +0100 Subject: [PATCH] * src/vm/hook.hpp: Use hook points for OProfile agent. * src/vm/jit/jit.cpp: Likewise and also fire jit_generated hook. * src/vm/jit/oprofile-agent.cpp (OprofileAgent::initialize): Fixed minor typo. * src/vm/vm.cpp: Fire vm_preinit and vm_shutdown hooks. --- src/vm/hook.hpp | 55 +++++++++++++++++++++++++++++++++++ src/vm/jit/jit.cpp | 27 ++++------------- src/vm/jit/oprofile-agent.cpp | 2 +- src/vm/vm.cpp | 6 ++++ 4 files changed, 68 insertions(+), 22 deletions(-) diff --git a/src/vm/hook.hpp b/src/vm/hook.hpp index 02964e71a..0e6656bb4 100644 --- a/src/vm/hook.hpp +++ b/src/vm/hook.hpp @@ -28,6 +28,10 @@ #include "config.h" +#if defined(ENABLE_OPAGENT) +#include "vm/jit/oprofile-agent.hpp" +#endif + /** * Hook points are inline functions acting as probes scattered throughout @@ -40,6 +44,8 @@ namespace Hook { void breakpoint (Breakpoint *bp); void class_linked (classinfo *c); void class_loaded (classinfo *c); + void jit_generated (methodinfo *m, codeinfo *code); + void jit_recycled (methodinfo *m, codeinfo *code); void method_enter (methodinfo *m); void method_exit (methodinfo *m); void method_unwind (methodinfo *m); @@ -47,6 +53,8 @@ namespace Hook { void thread_start (threadobject *t); void thread_end (threadobject *t); void vm_init (); + void vm_preinit (); + void vm_shutdown (); } @@ -71,6 +79,22 @@ inline void Hook::class_loaded(classinfo *c) /* nop */ } +/** + * Hook point just after code was generated. Note that one method can have + * multiple code realizations, the hook is fired for each of them. The code + * was not yet executed. + * + * @param m The method for which code was generated. + * @param code The fully initialized codeinfo for the generated code. + */ +inline void Hook::jit_generated(methodinfo *m, codeinfo *code) +{ +#if defined(ENABLE_OPAGENT) + if (opt_EnableOpagent) + OprofileAgent::newmethod(m); +#endif +} + inline void Hook::method_enter(methodinfo *m) { /* nop */ @@ -101,11 +125,42 @@ inline void Hook::thread_end(threadobject *t) /* nop */ } +/** + * Hook point after the VM is initialized. At this point the VM is fully + * operating and ready to execute Java code. Final intializations and thread + * startup should be done here. + */ inline void Hook::vm_init() { /* nop */ } +/** + * Hook point before the VM is initialized. At this point the VM can not + * yet execute Java code but some central native subsystems are initialized. + * Only basic initialization steps should be done here. + */ +inline void Hook::vm_preinit() +{ +#if defined(ENABLE_OPAGENT) + if (opt_EnableOpagent) + OprofileAgent::initialize(); +#endif +} + +/** + * Hook point before the VM is actually destroyed. At this point the VM is + * still running, but all non-daemon threads have terminated and resources + * are ready to be reclaimed. Final cleanup tasks should be done here. + */ +inline void Hook::vm_shutdown() +{ +#if defined(ENABLE_OPAGENT) + if (opt_EnableOpagent) + OprofileAgent::close(); +#endif +} + #endif /* _HOOK_HPP */ diff --git a/src/vm/jit/jit.cpp b/src/vm/jit/jit.cpp index a8ac2b160..b633292c0 100644 --- a/src/vm/jit/jit.cpp +++ b/src/vm/jit/jit.cpp @@ -43,6 +43,7 @@ #include "vm/class.hpp" #include "vm/global.h" #include "vm/globals.hpp" +#include "vm/hook.hpp" #include "vm/initialize.hpp" #include "vm/loader.hpp" #include "vm/method.hpp" @@ -65,10 +66,6 @@ #include "vm/jit/stack.h" #include "vm/jit/stubs.hpp" -#if defined(ENABLE_OPAGENT) -#include "vm/jit/oprofile-agent.hpp" -#endif - #include "vm/jit/allocator/simplereg.h" #if defined(ENABLE_LSRA) && !defined(ENABLE_SSA) # include "vm/jit/allocator/lsra.h" @@ -173,11 +170,6 @@ void jit_init(void) #else intrp_md_init(); #endif - -#if defined(ENABLE_OPAGENT) - if (opt_EnableOpagent) - OprofileAgent::initialize(); -#endif } @@ -189,10 +181,7 @@ void jit_init(void) void jit_close(void) { -#if defined(ENABLE_OPAGENT) - if (opt_EnableOpagent) - OprofileAgent::close(); -#endif + /* nop */ } @@ -401,10 +390,8 @@ u1 *jit_compile(methodinfo *m) compilingtime_stop(); #endif -#if defined(ENABLE_OPAGENT) - if (opt_EnableOpagent) - OprofileAgent::newmethod(m); -#endif + // Hook point just after code was generated. + Hook::jit_generated(m, m->code); /* leave the monitor */ @@ -512,10 +499,8 @@ u1 *jit_recompile(methodinfo *m) compilingtime_stop(); #endif -#if defined(ENABLE_OPAGENT) - if (opt_EnableOpagent) - OprofileAgent::newmethod(m); -#endif + // Hook point just after code was generated. + Hook::jit_generated(m, m->code); DEBUG_JIT_COMPILEVERBOSE("Recompiling done: "); diff --git a/src/vm/jit/oprofile-agent.cpp b/src/vm/jit/oprofile-agent.cpp index 0846f9941..5d35c222f 100644 --- a/src/vm/jit/oprofile-agent.cpp +++ b/src/vm/jit/oprofile-agent.cpp @@ -43,7 +43,7 @@ void OprofileAgent::initialize(void) { _handle = op_open_agent(); if (!_handle) - os::abort_errno("unable to open opagent handle:"); + os::abort_errno("unable to open opagent handle"); } /** diff --git a/src/vm/vm.cpp b/src/vm/vm.cpp index 384018e33..70c0ae53c 100644 --- a/src/vm/vm.cpp +++ b/src/vm/vm.cpp @@ -1284,6 +1284,9 @@ VM::VM(JavaVMInitArgs* vm_args) utf8_init(); + // Hook point before the VM is initialized. + Hook::vm_preinit(); + #if defined(ENABLE_JVMTI) // AFTER: utf8_init if (!_nativeagents.load_agents()) @@ -1786,6 +1789,9 @@ int vm_destroy(JavaVM *vm) threads_join_all_threads(); #endif + // Hook point before the VM is actually destroyed. + Hook::vm_shutdown(); + /* VM is gone. */ // _created = false; -- 2.25.1