duke@435: /* stefank@2314: * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #ifndef SHARE_VM_PRIMS_JVMTIEVENTCONTROLLER_HPP stefank@2314: #define SHARE_VM_PRIMS_JVMTIEVENTCONTROLLER_HPP stefank@2314: stefank@2314: #include "jvmtifiles/jvmti.h" stefank@2314: #include "memory/allocation.hpp" stefank@2314: #include "memory/allocation.inline.hpp" stefank@2314: #include "utilities/globalDefinitions.hpp" duke@435: duke@435: // forward declaration duke@435: class JvmtiEventControllerPrivate; duke@435: class JvmtiEventController; duke@435: class JvmtiEnvThreadState; duke@435: class JvmtiFramePop; duke@435: class JvmtiEnvBase; duke@435: duke@435: duke@435: // Extension event support duke@435: // duke@435: // jvmtiExtEvent is the extensions equivalent of jvmtiEvent duke@435: // jvmtiExtCallbacks is the extensions equivalent of jvmtiEventCallbacks duke@435: duke@435: // Extension events start JVMTI_MIN_EVENT_TYPE_VAL-1 and work towards 0. duke@435: typedef enum { duke@435: EXT_EVENT_CLASS_UNLOAD = JVMTI_MIN_EVENT_TYPE_VAL-1, duke@435: EXT_MIN_EVENT_TYPE_VAL = EXT_EVENT_CLASS_UNLOAD, duke@435: EXT_MAX_EVENT_TYPE_VAL = EXT_EVENT_CLASS_UNLOAD duke@435: } jvmtiExtEvent; duke@435: duke@435: typedef struct { duke@435: jvmtiExtensionEvent ClassUnload; duke@435: } jvmtiExtEventCallbacks; duke@435: duke@435: duke@435: // The complete range of events is EXT_MIN_EVENT_TYPE_VAL to duke@435: // JVMTI_MAX_EVENT_TYPE_VAL (inclusive and contiguous). duke@435: const int TOTAL_MIN_EVENT_TYPE_VAL = EXT_MIN_EVENT_TYPE_VAL; duke@435: const int TOTAL_MAX_EVENT_TYPE_VAL = JVMTI_MAX_EVENT_TYPE_VAL; duke@435: duke@435: duke@435: /////////////////////////////////////////////////////////////// duke@435: // duke@435: // JvmtiEventEnabled duke@435: // duke@435: // Utility class duke@435: // duke@435: // A boolean array indexed by event_type, used as an internal duke@435: // data structure to track what JVMTI event types are enabled. duke@435: // Used for user set enabling and disabling (globally and on a duke@435: // per thread basis), and for computed merges across environments, duke@435: // threads and the VM as a whole. duke@435: // duke@435: // for inlines see jvmtiEventController_inline.hpp duke@435: // duke@435: duke@435: class JvmtiEventEnabled VALUE_OBJ_CLASS_SPEC { duke@435: private: duke@435: friend class JvmtiEventControllerPrivate; duke@435: jlong _enabled_bits; duke@435: #ifndef PRODUCT duke@435: enum { duke@435: JEE_INIT_GUARD = 0xEAD0 duke@435: } _init_guard; duke@435: #endif duke@435: static jlong bit_for(jvmtiEvent event_type); duke@435: jlong get_bits(); duke@435: void set_bits(jlong bits); duke@435: public: duke@435: JvmtiEventEnabled(); duke@435: void clear(); duke@435: bool is_enabled(jvmtiEvent event_type); duke@435: void set_enabled(jvmtiEvent event_type, bool enabled); duke@435: }; duke@435: duke@435: duke@435: /////////////////////////////////////////////////////////////// duke@435: // duke@435: // JvmtiEnvThreadEventEnable duke@435: // duke@435: // JvmtiEventController data specific to a particular environment and thread. duke@435: // duke@435: // for inlines see jvmtiEventController_inline.hpp duke@435: // duke@435: duke@435: class JvmtiEnvThreadEventEnable VALUE_OBJ_CLASS_SPEC { duke@435: private: duke@435: friend class JvmtiEventControllerPrivate; duke@435: JvmtiEventEnabled _event_user_enabled; duke@435: JvmtiEventEnabled _event_enabled; duke@435: duke@435: public: duke@435: JvmtiEnvThreadEventEnable(); duke@435: ~JvmtiEnvThreadEventEnable(); duke@435: bool is_enabled(jvmtiEvent event_type); duke@435: void set_user_enabled(jvmtiEvent event_type, bool enabled); duke@435: }; duke@435: duke@435: duke@435: /////////////////////////////////////////////////////////////// duke@435: // duke@435: // JvmtiThreadEventEnable duke@435: // duke@435: // JvmtiEventController data specific to a particular thread. duke@435: // duke@435: // for inlines see jvmtiEventController_inline.hpp duke@435: // duke@435: duke@435: class JvmtiThreadEventEnable VALUE_OBJ_CLASS_SPEC { duke@435: private: duke@435: friend class JvmtiEventControllerPrivate; duke@435: JvmtiEventEnabled _event_enabled; duke@435: duke@435: public: duke@435: JvmtiThreadEventEnable(); duke@435: ~JvmtiThreadEventEnable(); duke@435: bool is_enabled(jvmtiEvent event_type); duke@435: }; duke@435: duke@435: duke@435: /////////////////////////////////////////////////////////////// duke@435: // duke@435: // JvmtiEnvEventEnable duke@435: // duke@435: // JvmtiEventController data specific to a particular environment. duke@435: // duke@435: // for inlines see jvmtiEventController_inline.hpp duke@435: // duke@435: duke@435: class JvmtiEnvEventEnable VALUE_OBJ_CLASS_SPEC { duke@435: private: duke@435: friend class JvmtiEventControllerPrivate; duke@435: duke@435: // user set global event enablement indexed by jvmtiEvent duke@435: JvmtiEventEnabled _event_user_enabled; duke@435: duke@435: // this flag indicates the presence (true) or absence (false) of event callbacks duke@435: // it is indexed by jvmtiEvent duke@435: JvmtiEventEnabled _event_callback_enabled; duke@435: duke@435: // indexed by jvmtiEvent true if enabled globally or on any thread. duke@435: // True only if there is a callback for it. duke@435: JvmtiEventEnabled _event_enabled; duke@435: duke@435: public: duke@435: JvmtiEnvEventEnable(); duke@435: ~JvmtiEnvEventEnable(); duke@435: bool is_enabled(jvmtiEvent event_type); duke@435: void set_user_enabled(jvmtiEvent event_type, bool enabled); duke@435: }; duke@435: duke@435: duke@435: /////////////////////////////////////////////////////////////// duke@435: // duke@435: // JvmtiEventController duke@435: // duke@435: // The class is the access point for all actions that change duke@435: // which events are active, this include: duke@435: // enabling and disabling events duke@435: // changing the callbacks/eventhook (they may be null) duke@435: // setting and clearing field watchpoints duke@435: // setting frame pops duke@435: // encountering frame pops duke@435: // duke@435: // for inlines see jvmtiEventController_inline.hpp duke@435: // duke@435: duke@435: class JvmtiEventController : AllStatic { duke@435: private: duke@435: friend class JvmtiEventControllerPrivate; duke@435: duke@435: // for all environments, global array indexed by jvmtiEvent duke@435: static JvmtiEventEnabled _universal_global_event_enabled; duke@435: duke@435: public: duke@435: static bool is_enabled(jvmtiEvent event_type); duke@435: duke@435: // events that can ONLY be enabled/disabled globally (can't toggle on individual threads). duke@435: static bool is_global_event(jvmtiEvent event_type); duke@435: duke@435: // is the event_type valid? duke@435: // to do: check against valid event array duke@435: static bool is_valid_event_type(jvmtiEvent event_type) { duke@435: return ((int)event_type >= TOTAL_MIN_EVENT_TYPE_VAL) duke@435: && ((int)event_type <= TOTAL_MAX_EVENT_TYPE_VAL); duke@435: } duke@435: duke@435: // Use (thread == NULL) to enable/disable an event globally. duke@435: // Use (thread != NULL) to enable/disable an event for a particular thread. duke@435: // thread is ignored for events that can only be specified globally duke@435: static void set_user_enabled(JvmtiEnvBase *env, JavaThread *thread, duke@435: jvmtiEvent event_type, bool enabled); duke@435: duke@435: // Setting callbacks changes computed enablement and must be done duke@435: // at a safepoint otherwise a NULL callback could be attempted duke@435: static void set_event_callbacks(JvmtiEnvBase *env, duke@435: const jvmtiEventCallbacks* callbacks, duke@435: jint size_of_callbacks); duke@435: duke@435: // Sets the callback function for a single extension event and enables duke@435: // (or disables it). duke@435: static void set_extension_event_callback(JvmtiEnvBase* env, duke@435: jint extension_event_index, duke@435: jvmtiExtensionEvent callback); duke@435: duke@435: static void set_frame_pop(JvmtiEnvThreadState *env_thread, JvmtiFramePop fpop); duke@435: static void clear_frame_pop(JvmtiEnvThreadState *env_thread, JvmtiFramePop fpop); duke@435: static void clear_to_frame_pop(JvmtiEnvThreadState *env_thread, JvmtiFramePop fpop); duke@435: duke@435: static void change_field_watch(jvmtiEvent event_type, bool added); duke@435: duke@435: static void thread_started(JavaThread *thread); duke@435: static void thread_ended(JavaThread *thread); duke@435: duke@435: static void env_initialize(JvmtiEnvBase *env); duke@435: static void env_dispose(JvmtiEnvBase *env); duke@435: duke@435: static void vm_start(); duke@435: static void vm_init(); duke@435: static void vm_death(); duke@435: }; duke@435: stefank@2314: #endif // SHARE_VM_PRIMS_JVMTIEVENTCONTROLLER_HPP