1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/prims/jvmtiEnvThreadState.hpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,175 @@ 1.4 +/* 1.5 + * Copyright 2003-2006 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + * 1.26 + */ 1.27 +#ifndef _JAVA_JVMTIENVTHREADSTATE_H_ 1.28 +#define _JAVA_JVMTIENVTHREADSTATE_H_ 1.29 + 1.30 +/////////////////////////////////////////////////////////////// 1.31 +// 1.32 +// class JvmtiFramePop 1.33 +// Used by : JvmtiFramePops 1.34 +// Used by JVMTI methods: none directly. 1.35 +// 1.36 +// Wrapper class for FramePop, used in the JvmtiFramePops class. 1.37 +// 1.38 +// Two problems: 1) this isn't being used as a ValueObj class, in 1.39 +// several places there are constructors for it. 2) It seems like 1.40 +// overkill as a means to get an assert and name the geater than 1.41 +// operator. I'm trying to to rewrite everything. 1.42 + 1.43 +class JvmtiFramePop VALUE_OBJ_CLASS_SPEC { 1.44 + private: 1.45 + // Frame number counting from BOTTOM (oldest) frame; 1.46 + // bottom frame == #0 1.47 + int _frame_number; 1.48 + public: 1.49 + JvmtiFramePop() {} 1.50 + JvmtiFramePop(int frame_number) { 1.51 + assert(frame_number >= 0, "invalid frame number"); 1.52 + _frame_number = frame_number; 1.53 + } 1.54 + 1.55 + int frame_number() { return _frame_number; } 1.56 + int above_on_stack(JvmtiFramePop& other) { return _frame_number > other._frame_number; } 1.57 + void print() PRODUCT_RETURN; 1.58 +}; 1.59 + 1.60 + 1.61 +/////////////////////////////////////////////////////////////// 1.62 +// 1.63 +// class JvmtiFramePops 1.64 +// Used by : JvmtiThreadState 1.65 +// Used by JVMTI methods: none directly. 1.66 +// 1.67 +// A collection of JvmtiFramePop. 1.68 +// It records what frames on a threads stack should post frame_pop events when they're exited. 1.69 +// 1.70 + 1.71 +class JvmtiFramePops : public CHeapObj { 1.72 + private: 1.73 + GrowableArray<int>* _pops; 1.74 + 1.75 + // should only be used by JvmtiEventControllerPrivate 1.76 + // to insure they only occur at safepoints. 1.77 + // Todo: add checks for safepoint 1.78 + friend class JvmtiEventControllerPrivate; 1.79 + void set(JvmtiFramePop& fp); 1.80 + void clear(JvmtiFramePop& fp); 1.81 + int clear_to(JvmtiFramePop& fp); 1.82 + 1.83 + public: 1.84 + JvmtiFramePops(); 1.85 + ~JvmtiFramePops(); 1.86 + 1.87 + bool contains(JvmtiFramePop& fp) { return _pops->contains(fp.frame_number()); } 1.88 + int length() { return _pops->length(); } 1.89 + void print() PRODUCT_RETURN; 1.90 +}; 1.91 + 1.92 + 1.93 +/////////////////////////////////////////////////////////////// 1.94 +// 1.95 +// class JvmtiEnvThreadState 1.96 +// 1.97 +// 2. Cache of pending frame_pop_events, created by NotifyFramePop 1.98 +// and lazily initialized. 1.99 +// 3: Location of last executed instruction, used to filter out duplicate 1.100 +// events due to instruction rewriting. 1.101 + 1.102 +class JvmtiEnvThreadState : public CHeapObj { 1.103 +private: 1.104 + friend class JvmtiEnv; 1.105 + JavaThread *_thread; 1.106 + JvmtiEnv *_env; 1.107 + JvmtiEnvThreadState *_next; 1.108 + jmethodID _current_method_id; 1.109 + int _current_bci; 1.110 + bool _breakpoint_posted; 1.111 + bool _single_stepping_posted; 1.112 + JvmtiEnvThreadEventEnable _event_enable; 1.113 + void *_agent_thread_local_storage_data; // per env and per thread agent allocated data. 1.114 + 1.115 + // Class used to store pending framepops. 1.116 + // lazily initialized by get_frame_pops(); 1.117 + JvmtiFramePops *_frame_pops; 1.118 + 1.119 + inline void set_current_location(jmethodID method_id, int bci) { 1.120 + _current_method_id = method_id; 1.121 + _current_bci = bci; 1.122 + } 1.123 + 1.124 + friend class JvmtiEnvThreadStateIterator; 1.125 + JvmtiEnvThreadState* next() { return _next; } 1.126 + 1.127 + friend class JvmtiThreadState; 1.128 + void set_next(JvmtiEnvThreadState* link) { _next = link; } 1.129 + 1.130 +public: 1.131 + JvmtiEnvThreadState(JavaThread *thread, JvmtiEnvBase *env); 1.132 + ~JvmtiEnvThreadState(); 1.133 + 1.134 + bool is_enabled(jvmtiEvent event_type) { return _event_enable.is_enabled(event_type); } 1.135 + 1.136 + JvmtiEnvThreadEventEnable *event_enable() { return &_event_enable; } 1.137 + void *get_agent_thread_local_storage_data() { return _agent_thread_local_storage_data; } 1.138 + void set_agent_thread_local_storage_data (void *data) { _agent_thread_local_storage_data = data; } 1.139 + 1.140 + 1.141 + // If the thread is in the given method at the given 1.142 + // location just return. Otherwise, reset the current location 1.143 + // and reset _breakpoint_posted and _single_stepping_posted. 1.144 + // _breakpoint_posted and _single_stepping_posted are only cleared 1.145 + // here. 1.146 + void compare_and_set_current_location(methodOop method, address location, jvmtiEvent event); 1.147 + 1.148 + void clear_current_location() { set_current_location((jmethodID)NULL, 0); } 1.149 + 1.150 + void reset_current_location(jvmtiEvent event, bool enabled); 1.151 + 1.152 + inline void set_breakpoint_posted() { _breakpoint_posted = true; } 1.153 + inline void set_single_stepping_posted() { 1.154 + _single_stepping_posted = true; 1.155 + } 1.156 + inline bool breakpoint_posted() { return _breakpoint_posted; } 1.157 + inline bool single_stepping_posted() { 1.158 + return _single_stepping_posted; 1.159 + } 1.160 + 1.161 + inline JavaThread *get_thread() { return _thread; } 1.162 + inline JvmtiEnv *get_env() { return _env; } 1.163 + 1.164 + // lazily initialize _frame_pops 1.165 + JvmtiFramePops* get_frame_pops(); 1.166 + 1.167 + bool has_frame_pops(); 1.168 + 1.169 + // quickly test whether we should deliver a frame pop event on return from sp 1.170 + bool is_frame_pop(int cur_stack_depth); 1.171 + 1.172 + void set_frame_pop(int frame_number); 1.173 + void clear_frame_pop(int frame_number); 1.174 + void clear_to_frame_pop(int frame_number); 1.175 + 1.176 +}; 1.177 + 1.178 +#endif /* _JAVA_JVMTIENVTHREADSTATE_H_ */