* src/vm/hook.hpp: Use hook points for OProfile agent.
[cacao.git] / src / vm / hook.hpp
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 */