Path: blob/master/src/hotspot/share/prims/jvmtiEventController.hpp
41145 views
/*1* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_PRIMS_JVMTIEVENTCONTROLLER_HPP25#define SHARE_PRIMS_JVMTIEVENTCONTROLLER_HPP2627#include "jvmtifiles/jvmti.h"28#include "memory/allocation.hpp"29#include "utilities/globalDefinitions.hpp"3031// forward declaration32class JvmtiEventControllerPrivate;33class JvmtiEventController;34class JvmtiEnvThreadState;35class JvmtiFramePop;36class JvmtiEnvBase;373839// Extension event support40//41// jvmtiExtEvent is the extensions equivalent of jvmtiEvent42// jvmtiExtCallbacks is the extensions equivalent of jvmtiEventCallbacks4344// Extension events start JVMTI_MIN_EVENT_TYPE_VAL-1 and work towards 0.45typedef enum {46EXT_EVENT_CLASS_UNLOAD = JVMTI_MIN_EVENT_TYPE_VAL-1,47EXT_MIN_EVENT_TYPE_VAL = EXT_EVENT_CLASS_UNLOAD,48EXT_MAX_EVENT_TYPE_VAL = EXT_EVENT_CLASS_UNLOAD49} jvmtiExtEvent;5051typedef struct {52jvmtiExtensionEvent ClassUnload;53} jvmtiExtEventCallbacks;545556// The complete range of events is EXT_MIN_EVENT_TYPE_VAL to57// JVMTI_MAX_EVENT_TYPE_VAL (inclusive and contiguous).58const int TOTAL_MIN_EVENT_TYPE_VAL = EXT_MIN_EVENT_TYPE_VAL;59const int TOTAL_MAX_EVENT_TYPE_VAL = JVMTI_MAX_EVENT_TYPE_VAL;606162///////////////////////////////////////////////////////////////63//64// JvmtiEventEnabled65//66// Utility class67//68// A boolean array indexed by event_type, used as an internal69// data structure to track what JVMTI event types are enabled.70// Used for user set enabling and disabling (globally and on a71// per thread basis), and for computed merges across environments,72// threads and the VM as a whole.73//74// for inlines see jvmtiEventController_inline.hpp75//7677class JvmtiEventEnabled {78private:79friend class JvmtiEventControllerPrivate;80jlong _enabled_bits;81#ifndef PRODUCT82enum {83JEE_INIT_GUARD = 0xEAD084} _init_guard;85#endif86static jlong bit_for(jvmtiEvent event_type);87jlong get_bits();88void set_bits(jlong bits);89public:90JvmtiEventEnabled();91void clear();92bool is_enabled(jvmtiEvent event_type);93void set_enabled(jvmtiEvent event_type, bool enabled);94};959697///////////////////////////////////////////////////////////////98//99// JvmtiEnvThreadEventEnable100//101// JvmtiEventController data specific to a particular environment and thread.102//103// for inlines see jvmtiEventController_inline.hpp104//105106class JvmtiEnvThreadEventEnable {107private:108friend class JvmtiEventControllerPrivate;109JvmtiEventEnabled _event_user_enabled;110JvmtiEventEnabled _event_enabled;111112public:113JvmtiEnvThreadEventEnable();114~JvmtiEnvThreadEventEnable();115bool is_enabled(jvmtiEvent event_type);116void set_user_enabled(jvmtiEvent event_type, bool enabled);117};118119120///////////////////////////////////////////////////////////////121//122// JvmtiThreadEventEnable123//124// JvmtiEventController data specific to a particular thread.125//126// for inlines see jvmtiEventController_inline.hpp127//128129class JvmtiThreadEventEnable {130private:131friend class JvmtiEventControllerPrivate;132JvmtiEventEnabled _event_enabled;133134public:135JvmtiThreadEventEnable();136~JvmtiThreadEventEnable();137bool is_enabled(jvmtiEvent event_type);138};139140141///////////////////////////////////////////////////////////////142//143// JvmtiEnvEventEnable144//145// JvmtiEventController data specific to a particular environment.146//147// for inlines see jvmtiEventController_inline.hpp148//149150class JvmtiEnvEventEnable {151private:152friend class JvmtiEventControllerPrivate;153154// user set global event enablement indexed by jvmtiEvent155JvmtiEventEnabled _event_user_enabled;156157// this flag indicates the presence (true) or absence (false) of event callbacks158// it is indexed by jvmtiEvent159JvmtiEventEnabled _event_callback_enabled;160161// indexed by jvmtiEvent true if enabled globally or on any thread.162// True only if there is a callback for it.163JvmtiEventEnabled _event_enabled;164165public:166JvmtiEnvEventEnable();167~JvmtiEnvEventEnable();168bool is_enabled(jvmtiEvent event_type);169void set_user_enabled(jvmtiEvent event_type, bool enabled);170};171172173///////////////////////////////////////////////////////////////174//175// JvmtiEventController176//177// The class is the access point for all actions that change178// which events are active, this include:179// enabling and disabling events180// changing the callbacks/eventhook (they may be null)181// setting and clearing field watchpoints182// setting frame pops183// encountering frame pops184//185// for inlines see jvmtiEventController_inline.hpp186//187188class JvmtiEventController : AllStatic {189private:190friend class JvmtiEventControllerPrivate;191192// for all environments, global array indexed by jvmtiEvent193static JvmtiEventEnabled _universal_global_event_enabled;194195public:196static bool is_enabled(jvmtiEvent event_type);197198// events that can ONLY be enabled/disabled globally (can't toggle on individual threads).199static bool is_global_event(jvmtiEvent event_type);200201// is the event_type valid?202// to do: check against valid event array203static bool is_valid_event_type(jvmtiEvent event_type) {204return ((int)event_type >= TOTAL_MIN_EVENT_TYPE_VAL)205&& ((int)event_type <= TOTAL_MAX_EVENT_TYPE_VAL);206}207208// Use (thread == NULL) to enable/disable an event globally.209// Use (thread != NULL) to enable/disable an event for a particular thread.210// thread is ignored for events that can only be specified globally211static void set_user_enabled(JvmtiEnvBase *env, JavaThread *thread,212jvmtiEvent event_type, bool enabled);213214// Setting callbacks changes computed enablement and must be done215// at a safepoint otherwise a NULL callback could be attempted216static void set_event_callbacks(JvmtiEnvBase *env,217const jvmtiEventCallbacks* callbacks,218jint size_of_callbacks);219220// Sets the callback function for a single extension event and enables221// (or disables it).222static void set_extension_event_callback(JvmtiEnvBase* env,223jint extension_event_index,224jvmtiExtensionEvent callback);225226static void set_frame_pop(JvmtiEnvThreadState *env_thread, JvmtiFramePop fpop);227static void clear_frame_pop(JvmtiEnvThreadState *env_thread, JvmtiFramePop fpop);228229static void change_field_watch(jvmtiEvent event_type, bool added);230231static void thread_started(JavaThread *thread);232static void thread_ended(JavaThread *thread);233234static void env_initialize(JvmtiEnvBase *env);235static void env_dispose(JvmtiEnvBase *env);236237static void vm_start();238static void vm_init();239static void vm_death();240};241242#endif // SHARE_PRIMS_JVMTIEVENTCONTROLLER_HPP243244245