Path: blob/master/src/hotspot/share/prims/jvmtiEnvThreadState.hpp
41144 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_JVMTIENVTHREADSTATE_HPP25#define SHARE_PRIMS_JVMTIENVTHREADSTATE_HPP2627#include "jvmtifiles/jvmti.h"28#include "memory/allocation.hpp"29#include "oops/instanceKlass.hpp"30#include "prims/jvmtiEventController.hpp"31#include "utilities/globalDefinitions.hpp"32#include "utilities/growableArray.hpp"3334class JvmtiEnv;3536///////////////////////////////////////////////////////////////37//38// class JvmtiFramePop39// Used by : JvmtiFramePops40// Used by JVMTI methods: none directly.41//42// Wrapper class for FramePop, used in the JvmtiFramePops class.43//44// Two problems: 1) this isn't being used as a value class, in45// several places there are constructors for it. 2) It seems like46// overkill as a means to get an assert and name the greater than47// operator. I'm trying to to rewrite everything.4849class JvmtiFramePop {50private:51// Frame number counting from BOTTOM (oldest) frame;52// bottom frame == #053int _frame_number;54public:55JvmtiFramePop() {}56JvmtiFramePop(int frame_number) {57assert(frame_number >= 0, "invalid frame number");58_frame_number = frame_number;59}6061int frame_number() { return _frame_number; }62int above_on_stack(JvmtiFramePop& other) { return _frame_number > other._frame_number; }63void print() PRODUCT_RETURN;64};656667///////////////////////////////////////////////////////////////68//69// class JvmtiFramePops70// Used by : JvmtiThreadState71// Used by JVMTI methods: none directly.72//73// A collection of JvmtiFramePop.74// It records what frames on a threads stack should post frame_pop events when they're exited.75//7677class JvmtiFramePops : public CHeapObj<mtInternal> {78private:79GrowableArray<int>* _pops;8081// should only be used by JvmtiEventControllerPrivate82// to insure they only occur at safepoints.83// Todo: add checks for safepoint84friend class JvmtiEventControllerPrivate;85void set(JvmtiFramePop& fp);86void clear(JvmtiFramePop& fp);87int clear_to(JvmtiFramePop& fp);8889public:90JvmtiFramePops();91~JvmtiFramePops();9293bool contains(JvmtiFramePop& fp) { return _pops->contains(fp.frame_number()); }94int length() { return _pops->length(); }95void print() PRODUCT_RETURN;96};979899///////////////////////////////////////////////////////////////100//101// class JvmtiEnvThreadState102//103// 2. Cache of pending frame_pop_events, created by NotifyFramePop104// and lazily initialized.105// 3: Location of last executed instruction, used to filter out duplicate106// events due to instruction rewriting.107108class JvmtiEnvThreadState : public CHeapObj<mtInternal> {109private:110friend class JvmtiEnv;111JavaThread *_thread;112JvmtiEnv *_env;113JvmtiEnvThreadState *_next;114jmethodID _current_method_id;115int _current_bci;116bool _breakpoint_posted;117bool _single_stepping_posted;118JvmtiEnvThreadEventEnable _event_enable;119void *_agent_thread_local_storage_data; // per env and per thread agent allocated data.120121// Class used to store pending framepops.122// lazily initialized by get_frame_pops();123JvmtiFramePops *_frame_pops;124125inline void set_current_location(jmethodID method_id, int bci) {126_current_method_id = method_id;127_current_bci = bci;128}129130friend class JvmtiEnvThreadStateIterator;131JvmtiEnvThreadState* next() { return _next; }132133friend class JvmtiThreadState;134void set_next(JvmtiEnvThreadState* link) { _next = link; }135136public:137JvmtiEnvThreadState(JavaThread *thread, JvmtiEnvBase *env);138~JvmtiEnvThreadState();139140bool is_enabled(jvmtiEvent event_type) { return _event_enable.is_enabled(event_type); }141142JvmtiEnvThreadEventEnable *event_enable() { return &_event_enable; }143void *get_agent_thread_local_storage_data() { return _agent_thread_local_storage_data; }144void set_agent_thread_local_storage_data (void *data) { _agent_thread_local_storage_data = data; }145146147// If the thread is in the given method at the given148// location just return. Otherwise, reset the current location149// and reset _breakpoint_posted and _single_stepping_posted.150// _breakpoint_posted and _single_stepping_posted are only cleared151// here.152void compare_and_set_current_location(Method* method, address location, jvmtiEvent event);153154void clear_current_location() { set_current_location((jmethodID)NULL, 0); }155156void reset_current_location(jvmtiEvent event, bool enabled);157158inline void set_breakpoint_posted() { _breakpoint_posted = true; }159inline void set_single_stepping_posted() {160_single_stepping_posted = true;161}162inline bool breakpoint_posted() { return _breakpoint_posted; }163inline bool single_stepping_posted() {164return _single_stepping_posted;165}166167inline JavaThread *get_thread() { return _thread; }168inline JvmtiEnv *get_env() { return _env; }169170// lazily initialize _frame_pops171JvmtiFramePops* get_frame_pops();172173bool has_frame_pops();174175// quickly test whether we should deliver a frame pop event on return from sp176bool is_frame_pop(int cur_stack_depth);177178void set_frame_pop(int frame_number);179void clear_frame_pop(int frame_number);180181};182183#endif // SHARE_PRIMS_JVMTIENVTHREADSTATE_HPP184185186