* src/vm/hook.hpp: Use hook points for OProfile agent.
authorMichael Starzinger <michi@complang.tuwien.ac.at>
Mon, 2 Nov 2009 12:19:05 +0000 (13:19 +0100)
committerMichael Starzinger <michi@complang.tuwien.ac.at>
Mon, 2 Nov 2009 12:19:05 +0000 (13:19 +0100)
* 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
src/vm/jit/jit.cpp
src/vm/jit/oprofile-agent.cpp
src/vm/vm.cpp

index 02964e71a838298bf3260377535b059b1d2de74a..0e6656bb49ed7a8acc353d31de61ae0993cbb5b1 100644 (file)
 
 #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 */
 
index a8ac2b160a196c7f7c1873db3e80bf196fab7e86..b633292c04ea796831a4f08049c4052f0683432a 100644 (file)
@@ -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"
 #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: ");
 
index 0846f99410d49e11d2a06a40c7b0323ab6877997..5d35c222f1f0e9351a25ba3003d9b5308420f54b 100644 (file)
@@ -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");
 }
 
 /**
index 384018e337973f173d2c7f4f90b9ce2b3f42dff5..70c0ae53c8f896e79e5872fdbe74bbccd4f1af4d 100644 (file)
@@ -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;