LCOV - code coverage report
Current view: top level - vm - hook.hpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 20 26 76.9 %
Date: 2017-07-14 10:03:36 Functions: 9 12 75.0 %

          Line data    Source code
       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)
      38             : #include "vm/jit/oprofile-agent.hpp"
      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
      66             :         bool class_linked_dynoffsets(classinfo *c);
      67             : }
      68             : 
      69             : 
      70           0 : inline void Hook::breakpoint(Breakpoint *bp)
      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           0 : }
      80             : 
      81       42202 : inline bool Hook::class_linked(classinfo *c)
      82             : {
      83       42202 :         if (c == class_java_lang_String)
      84         163 :                 linker_initialize_deferred_strings();
      85             : 
      86       42202 :         return class_linked_dynoffsets(c);
      87             : }
      88             : 
      89       35788 : inline void Hook::class_loaded(classinfo *c)
      90             : {
      91             :         /* nop */
      92       35788 : }
      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             :  */
     102       92267 : inline void Hook::jit_generated(methodinfo *m, codeinfo *code)
     103             : {
     104             : #if defined(ENABLE_OPAGENT)
     105             :         if (opt_EnableOpagent)
     106             :                 OprofileAgent::newmethod(m);
     107             : #endif
     108       92267 : }
     109             : 
     110           0 : inline void Hook::method_enter(methodinfo *m)
     111             : {
     112             :         /* nop */
     113           0 : }
     114             : 
     115           0 : inline void Hook::method_exit(methodinfo *m)
     116             : {
     117             :         /* nop */
     118           0 : }
     119             : 
     120             : inline void Hook::method_unwind(methodinfo *m)
     121             : {
     122             :         /* nop */
     123             : }
     124             : 
     125        5832 : inline void Hook::native_resolved(methodinfo *m, void *symbol, void **symbolptr)
     126             : {
     127             :         /* nop */
     128        5832 : }
     129             : 
     130         499 : inline void Hook::thread_start(threadobject *t)
     131             : {
     132             :         /* nop */
     133         499 : }
     134             : 
     135         151 : inline void Hook::thread_end(threadobject *t)
     136             : {
     137             :         /* nop */
     138         151 : }
     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         163 : inline void Hook::vm_init()
     146             : {
     147             :         /* nop */
     148         163 : }
     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         163 : inline void Hook::vm_preinit()
     156             : {
     157             : #if defined(ENABLE_OPAGENT)
     158             :         if (opt_EnableOpagent)
     159             :                 OprofileAgent::initialize();
     160             : #endif
     161         163 : }
     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         131 : inline void Hook::vm_shutdown()
     169             : {
     170             : #if defined(ENABLE_OPAGENT)
     171             :         if (opt_EnableOpagent)
     172             :                 OprofileAgent::close();
     173             : #endif
     174         131 : }
     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             :  */

Generated by: LCOV version 1.11