hotspot/src/share/vm/prims/jvmtiEventController.hpp
changeset 1 489c9b5090e2
child 5547 f4b087cbb361
equal deleted inserted replaced
0:fd16c54261b3 1:489c9b5090e2
       
     1 /*
       
     2  * Copyright 2003-2004 Sun Microsystems, Inc.  All Rights Reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
       
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
       
    21  * have any questions.
       
    22  *
       
    23  */
       
    24 
       
    25 #ifndef _JAVA_JVMTI_EVENT_CONTROLLER_H_
       
    26 #define _JAVA_JVMTI_EVENT_CONTROLLER_H_
       
    27 
       
    28 // forward declaration
       
    29 class JvmtiEventControllerPrivate;
       
    30 class JvmtiEventController;
       
    31 class JvmtiEnvThreadState;
       
    32 class JvmtiFramePop;
       
    33 class JvmtiEnvBase;
       
    34 
       
    35 
       
    36 // Extension event support
       
    37 //
       
    38 // jvmtiExtEvent is the extensions equivalent of jvmtiEvent
       
    39 // jvmtiExtCallbacks is the extensions equivalent of jvmtiEventCallbacks
       
    40 
       
    41 // Extension events start JVMTI_MIN_EVENT_TYPE_VAL-1 and work towards 0.
       
    42 typedef enum {
       
    43   EXT_EVENT_CLASS_UNLOAD = JVMTI_MIN_EVENT_TYPE_VAL-1,
       
    44   EXT_MIN_EVENT_TYPE_VAL = EXT_EVENT_CLASS_UNLOAD,
       
    45   EXT_MAX_EVENT_TYPE_VAL = EXT_EVENT_CLASS_UNLOAD
       
    46 } jvmtiExtEvent;
       
    47 
       
    48 typedef struct {
       
    49   jvmtiExtensionEvent ClassUnload;
       
    50 } jvmtiExtEventCallbacks;
       
    51 
       
    52 
       
    53 // The complete range of events is EXT_MIN_EVENT_TYPE_VAL to
       
    54 // JVMTI_MAX_EVENT_TYPE_VAL (inclusive and contiguous).
       
    55 const int TOTAL_MIN_EVENT_TYPE_VAL = EXT_MIN_EVENT_TYPE_VAL;
       
    56 const int TOTAL_MAX_EVENT_TYPE_VAL = JVMTI_MAX_EVENT_TYPE_VAL;
       
    57 
       
    58 
       
    59 ///////////////////////////////////////////////////////////////
       
    60 //
       
    61 // JvmtiEventEnabled
       
    62 //
       
    63 // Utility class
       
    64 //
       
    65 // A boolean array indexed by event_type, used as an internal
       
    66 // data structure to track what JVMTI event types are enabled.
       
    67 // Used for user set enabling and disabling (globally and on a
       
    68 // per thread basis), and for computed merges across environments,
       
    69 // threads and the VM as a whole.
       
    70 //
       
    71 // for inlines see jvmtiEventController_inline.hpp
       
    72 //
       
    73 
       
    74 class JvmtiEventEnabled VALUE_OBJ_CLASS_SPEC {
       
    75 private:
       
    76   friend class JvmtiEventControllerPrivate;
       
    77   jlong _enabled_bits;
       
    78 #ifndef PRODUCT
       
    79   enum {
       
    80     JEE_INIT_GUARD = 0xEAD0
       
    81   } _init_guard;
       
    82 #endif
       
    83   static jlong bit_for(jvmtiEvent event_type);
       
    84   jlong get_bits();
       
    85   void set_bits(jlong bits);
       
    86 public:
       
    87   JvmtiEventEnabled();
       
    88   void clear();
       
    89   bool is_enabled(jvmtiEvent event_type);
       
    90   void set_enabled(jvmtiEvent event_type, bool enabled);
       
    91 };
       
    92 
       
    93 
       
    94 ///////////////////////////////////////////////////////////////
       
    95 //
       
    96 // JvmtiEnvThreadEventEnable
       
    97 //
       
    98 // JvmtiEventController data specific to a particular environment and thread.
       
    99 //
       
   100 // for inlines see jvmtiEventController_inline.hpp
       
   101 //
       
   102 
       
   103 class JvmtiEnvThreadEventEnable VALUE_OBJ_CLASS_SPEC {
       
   104 private:
       
   105   friend class JvmtiEventControllerPrivate;
       
   106   JvmtiEventEnabled _event_user_enabled;
       
   107   JvmtiEventEnabled _event_enabled;
       
   108 
       
   109 public:
       
   110   JvmtiEnvThreadEventEnable();
       
   111   ~JvmtiEnvThreadEventEnable();
       
   112   bool is_enabled(jvmtiEvent event_type);
       
   113   void set_user_enabled(jvmtiEvent event_type, bool enabled);
       
   114 };
       
   115 
       
   116 
       
   117 ///////////////////////////////////////////////////////////////
       
   118 //
       
   119 // JvmtiThreadEventEnable
       
   120 //
       
   121 // JvmtiEventController data specific to a particular thread.
       
   122 //
       
   123 // for inlines see jvmtiEventController_inline.hpp
       
   124 //
       
   125 
       
   126 class JvmtiThreadEventEnable VALUE_OBJ_CLASS_SPEC {
       
   127 private:
       
   128   friend class JvmtiEventControllerPrivate;
       
   129   JvmtiEventEnabled _event_enabled;
       
   130 
       
   131 public:
       
   132   JvmtiThreadEventEnable();
       
   133   ~JvmtiThreadEventEnable();
       
   134   bool is_enabled(jvmtiEvent event_type);
       
   135 };
       
   136 
       
   137 
       
   138 ///////////////////////////////////////////////////////////////
       
   139 //
       
   140 // JvmtiEnvEventEnable
       
   141 //
       
   142 // JvmtiEventController data specific to a particular environment.
       
   143 //
       
   144 // for inlines see jvmtiEventController_inline.hpp
       
   145 //
       
   146 
       
   147 class JvmtiEnvEventEnable VALUE_OBJ_CLASS_SPEC {
       
   148 private:
       
   149   friend class JvmtiEventControllerPrivate;
       
   150 
       
   151   // user set global event enablement indexed by jvmtiEvent
       
   152   JvmtiEventEnabled _event_user_enabled;
       
   153 
       
   154   // this flag indicates the presence (true) or absence (false) of event callbacks
       
   155   // it is indexed by jvmtiEvent
       
   156   JvmtiEventEnabled _event_callback_enabled;
       
   157 
       
   158   // indexed by jvmtiEvent true if enabled globally or on any thread.
       
   159   // True only if there is a callback for it.
       
   160   JvmtiEventEnabled _event_enabled;
       
   161 
       
   162 public:
       
   163   JvmtiEnvEventEnable();
       
   164   ~JvmtiEnvEventEnable();
       
   165   bool is_enabled(jvmtiEvent event_type);
       
   166   void set_user_enabled(jvmtiEvent event_type, bool enabled);
       
   167 };
       
   168 
       
   169 
       
   170 ///////////////////////////////////////////////////////////////
       
   171 //
       
   172 // JvmtiEventController
       
   173 //
       
   174 // The class is the access point for all actions that change
       
   175 // which events are active, this include:
       
   176 //      enabling and disabling events
       
   177 //      changing the callbacks/eventhook (they may be null)
       
   178 //      setting and clearing field watchpoints
       
   179 //      setting frame pops
       
   180 //      encountering frame pops
       
   181 //
       
   182 // for inlines see jvmtiEventController_inline.hpp
       
   183 //
       
   184 
       
   185 class JvmtiEventController : AllStatic {
       
   186 private:
       
   187   friend class JvmtiEventControllerPrivate;
       
   188 
       
   189   // for all environments, global array indexed by jvmtiEvent
       
   190   static JvmtiEventEnabled _universal_global_event_enabled;
       
   191 
       
   192 public:
       
   193   static bool is_enabled(jvmtiEvent event_type);
       
   194 
       
   195   // events that can ONLY be enabled/disabled globally (can't toggle on individual threads).
       
   196   static bool is_global_event(jvmtiEvent event_type);
       
   197 
       
   198   // is the event_type valid?
       
   199   // to do: check against valid event array
       
   200   static bool is_valid_event_type(jvmtiEvent event_type) {
       
   201     return ((int)event_type >= TOTAL_MIN_EVENT_TYPE_VAL)
       
   202         && ((int)event_type <= TOTAL_MAX_EVENT_TYPE_VAL);
       
   203   }
       
   204 
       
   205   // Use (thread == NULL) to enable/disable an event globally.
       
   206   // Use (thread != NULL) to enable/disable an event for a particular thread.
       
   207   // thread is ignored for events that can only be specified globally
       
   208   static void set_user_enabled(JvmtiEnvBase *env, JavaThread *thread,
       
   209                                jvmtiEvent event_type, bool enabled);
       
   210 
       
   211   // Setting callbacks changes computed enablement and must be done
       
   212   // at a safepoint otherwise a NULL callback could be attempted
       
   213   static void set_event_callbacks(JvmtiEnvBase *env,
       
   214                                   const jvmtiEventCallbacks* callbacks,
       
   215                                   jint size_of_callbacks);
       
   216 
       
   217   // Sets the callback function for a single extension event and enables
       
   218   // (or disables it).
       
   219   static void set_extension_event_callback(JvmtiEnvBase* env,
       
   220                                            jint extension_event_index,
       
   221                                            jvmtiExtensionEvent callback);
       
   222 
       
   223   static void set_frame_pop(JvmtiEnvThreadState *env_thread, JvmtiFramePop fpop);
       
   224   static void clear_frame_pop(JvmtiEnvThreadState *env_thread, JvmtiFramePop fpop);
       
   225   static void clear_to_frame_pop(JvmtiEnvThreadState *env_thread, JvmtiFramePop fpop);
       
   226 
       
   227   static void change_field_watch(jvmtiEvent event_type, bool added);
       
   228 
       
   229   static void thread_started(JavaThread *thread);
       
   230   static void thread_ended(JavaThread *thread);
       
   231 
       
   232   static void env_initialize(JvmtiEnvBase *env);
       
   233   static void env_dispose(JvmtiEnvBase *env);
       
   234 
       
   235   static void vm_start();
       
   236   static void vm_init();
       
   237   static void vm_death();
       
   238 };
       
   239 
       
   240 #endif   /* _JAVA_JVMTI_EVENT_CONTROLLER_H_ */