src/share/vm/prims/jvmtiThreadState.hpp

Tue, 06 Jan 2009 07:05:05 -0800

author
jmasa
date
Tue, 06 Jan 2009 07:05:05 -0800
changeset 952
e9be0e04635a
parent 435
a61af66fc99e
child 1043
0386097d43d8
permissions
-rw-r--r--

6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
Summary: Added safe_object_iterate() for use by JMapPerm.
Reviewed-by: tonyp

duke@435 1 /*
duke@435 2 * Copyright 2003-2006 Sun Microsystems, Inc. All Rights Reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 #ifndef _JAVA_JVMTITHREADSTATE_H_
duke@435 26 #define _JAVA_JVMTITHREADSTATE_H_
duke@435 27
duke@435 28 //
duke@435 29 // Forward Declarations
duke@435 30 //
duke@435 31
duke@435 32 class JvmtiEnvBase;
duke@435 33 class JvmtiEnvThreadState;
duke@435 34 class JvmtiDynamicCodeEventCollector;
duke@435 35
duke@435 36 enum JvmtiClassLoadKind {
duke@435 37 jvmti_class_load_kind_load = 100,
duke@435 38 jvmti_class_load_kind_retransform,
duke@435 39 jvmti_class_load_kind_redefine
duke@435 40 };
duke@435 41
duke@435 42 ///////////////////////////////////////////////////////////////
duke@435 43 //
duke@435 44 // class JvmtiEnvThreadStateIterator
duke@435 45 //
duke@435 46 // The only safe means of iterating through the JvmtiEnvThreadStates
duke@435 47 // in a JvmtiThreadState.
duke@435 48 // Note that this iteratation includes invalid environments pending
duke@435 49 // deallocation -- in fact, some uses depend on this behavior.
duke@435 50 //
duke@435 51 class JvmtiEnvThreadStateIterator : public StackObj {
duke@435 52 private:
duke@435 53 JvmtiThreadState* state;
duke@435 54 public:
duke@435 55 JvmtiEnvThreadStateIterator(JvmtiThreadState* thread_state);
duke@435 56 ~JvmtiEnvThreadStateIterator();
duke@435 57 JvmtiEnvThreadState* first();
duke@435 58 JvmtiEnvThreadState* next(JvmtiEnvThreadState* ets);
duke@435 59 };
duke@435 60
duke@435 61
duke@435 62 ///////////////////////////////////////////////////////////////
duke@435 63 //
duke@435 64 // class JvmtiThreadState
duke@435 65 //
duke@435 66 // The Jvmti state for each thread (across all JvmtiEnv):
duke@435 67 // 1. Local table of enabled events.
duke@435 68 class JvmtiThreadState : public CHeapObj {
duke@435 69 private:
duke@435 70 friend class JvmtiEnv;
duke@435 71 JavaThread *_thread;
duke@435 72 bool _exception_detected;
duke@435 73 bool _exception_caught;
duke@435 74 bool _hide_single_stepping;
duke@435 75 bool _pending_step_for_popframe;
duke@435 76 bool _pending_step_for_earlyret;
duke@435 77 int _hide_level;
duke@435 78
duke@435 79 // Used to send class being redefined/retransformed and kind of transform
duke@435 80 // info to the class file load hook event handler.
duke@435 81 KlassHandle *_class_being_redefined;
duke@435 82 JvmtiClassLoadKind _class_load_kind;
duke@435 83
duke@435 84 // This is only valid when is_interp_only_mode() returns true
duke@435 85 int _cur_stack_depth;
duke@435 86
duke@435 87 JvmtiThreadEventEnable _thread_event_enable;
duke@435 88
duke@435 89 // for support of JvmtiEnvThreadState
duke@435 90 JvmtiEnvThreadState* _head_env_thread_state;
duke@435 91
duke@435 92 // doubly-linked linear list of active thread state
duke@435 93 // needed in order to iterate the list without holding Threads_lock
duke@435 94 static JvmtiThreadState *_head;
duke@435 95 JvmtiThreadState *_next;
duke@435 96 JvmtiThreadState *_prev;
duke@435 97
duke@435 98 // holds the current dynamic code event collector, NULL if no event collector in use
duke@435 99 JvmtiDynamicCodeEventCollector* _dynamic_code_event_collector;
duke@435 100 // holds the current vm object alloc event collector, NULL if no event collector in use
duke@435 101 JvmtiVMObjectAllocEventCollector* _vm_object_alloc_event_collector;
duke@435 102
duke@435 103 // Should only be created by factory methods
duke@435 104 JvmtiThreadState(JavaThread *thread);
duke@435 105
duke@435 106 friend class JvmtiEnvThreadStateIterator;
duke@435 107 inline JvmtiEnvThreadState* head_env_thread_state();
duke@435 108 inline void set_head_env_thread_state(JvmtiEnvThreadState* ets);
duke@435 109
duke@435 110 public:
duke@435 111 ~JvmtiThreadState();
duke@435 112
duke@435 113 // is event_type enabled and usable for this thread in any enviroments?
duke@435 114 bool is_enabled(jvmtiEvent event_type) {
duke@435 115 return _thread_event_enable.is_enabled(event_type);
duke@435 116 }
duke@435 117
duke@435 118 JvmtiThreadEventEnable *thread_event_enable() {
duke@435 119 return &_thread_event_enable;
duke@435 120 }
duke@435 121
duke@435 122 // Must only be called in situations where the state is for the current thread and
duke@435 123 // the environment can not go away. To be safe, the returned JvmtiEnvThreadState
duke@435 124 // must be used in such a way as there can be no intervening safepoints.
duke@435 125 inline JvmtiEnvThreadState* env_thread_state(JvmtiEnvBase *env);
duke@435 126
duke@435 127 static void periodic_clean_up();
duke@435 128
duke@435 129 void add_env(JvmtiEnvBase *env);
duke@435 130
duke@435 131 // Used by the interpreter for fullspeed debugging support
duke@435 132 bool is_interp_only_mode() { return _thread->is_interp_only_mode(); }
duke@435 133 void enter_interp_only_mode();
duke@435 134 void leave_interp_only_mode();
duke@435 135
duke@435 136 // access to the linked list of all JVMTI thread states
duke@435 137 static JvmtiThreadState *first() {
duke@435 138 assert(Threads::number_of_threads() == 0 || JvmtiThreadState_lock->is_locked(), "sanity check");
duke@435 139 return _head;
duke@435 140 }
duke@435 141
duke@435 142 JvmtiThreadState *next() {
duke@435 143 return _next;
duke@435 144 }
duke@435 145
duke@435 146 // Current stack depth is only valid when is_interp_only_mode() returns true.
duke@435 147 // These functions should only be called at a safepoint - usually called from same thread.
duke@435 148 // Returns the number of Java activations on the stack.
duke@435 149 int cur_stack_depth();
duke@435 150 void invalidate_cur_stack_depth();
duke@435 151 void incr_cur_stack_depth();
duke@435 152 void decr_cur_stack_depth();
duke@435 153
duke@435 154 int count_frames();
duke@435 155
duke@435 156 inline JavaThread *get_thread() { return _thread; }
duke@435 157 inline bool is_exception_detected() { return _exception_detected; }
duke@435 158 inline bool is_exception_caught() { return _exception_caught; }
duke@435 159 inline void set_exception_detected() { _exception_detected = true;
duke@435 160 _exception_caught = false; }
duke@435 161 inline void set_exception_caught() { _exception_caught = true;
duke@435 162 _exception_detected = false; }
duke@435 163
duke@435 164 inline void clear_hide_single_stepping() {
duke@435 165 if (_hide_level > 0) {
duke@435 166 _hide_level--;
duke@435 167 } else {
duke@435 168 assert(_hide_single_stepping, "hide_single_stepping is out of phase");
duke@435 169 _hide_single_stepping = false;
duke@435 170 }
duke@435 171 }
duke@435 172 inline bool hide_single_stepping() { return _hide_single_stepping; }
duke@435 173 inline void set_hide_single_stepping() {
duke@435 174 if (_hide_single_stepping) {
duke@435 175 _hide_level++;
duke@435 176 } else {
duke@435 177 assert(_hide_level == 0, "hide_level is out of phase");
duke@435 178 _hide_single_stepping = true;
duke@435 179 }
duke@435 180 }
duke@435 181
duke@435 182 // Step pending flag is set when PopFrame is called and it is cleared
duke@435 183 // when step for the Pop Frame is completed.
duke@435 184 // This logic is used to distinguish b/w step for pop frame and repeat step.
duke@435 185 void set_pending_step_for_popframe() { _pending_step_for_popframe = true; }
duke@435 186 void clr_pending_step_for_popframe() { _pending_step_for_popframe = false; }
duke@435 187 bool is_pending_step_for_popframe() { return _pending_step_for_popframe; }
duke@435 188 void process_pending_step_for_popframe();
duke@435 189
duke@435 190 // Step pending flag is set when ForceEarlyReturn is called and it is cleared
duke@435 191 // when step for the ForceEarlyReturn is completed.
duke@435 192 // This logic is used to distinguish b/w step for early return and repeat step.
duke@435 193 void set_pending_step_for_earlyret() { _pending_step_for_earlyret = true; }
duke@435 194 void clr_pending_step_for_earlyret() { _pending_step_for_earlyret = false; }
duke@435 195 bool is_pending_step_for_earlyret() { return _pending_step_for_earlyret; }
duke@435 196 void process_pending_step_for_earlyret();
duke@435 197
duke@435 198 // Setter and getter method is used to send redefined class info
duke@435 199 // when class file load hook event is posted.
duke@435 200 // It is set while loading redefined class and cleared before the
duke@435 201 // class file load hook event is posted.
duke@435 202 inline void set_class_being_redefined(KlassHandle *h_class, JvmtiClassLoadKind kind) {
duke@435 203 _class_being_redefined = h_class;
duke@435 204 _class_load_kind = kind;
duke@435 205 }
duke@435 206
duke@435 207 inline void clear_class_being_redefined() {
duke@435 208 _class_being_redefined = NULL;
duke@435 209 _class_load_kind = jvmti_class_load_kind_load;
duke@435 210 }
duke@435 211
duke@435 212 inline KlassHandle *get_class_being_redefined() {
duke@435 213 return _class_being_redefined;
duke@435 214 }
duke@435 215
duke@435 216 inline JvmtiClassLoadKind get_class_load_kind() {
duke@435 217 return _class_load_kind;
duke@435 218 }
duke@435 219
duke@435 220 // RedefineClasses support
duke@435 221 // The bug 6214132 caused the verification to fail.
duke@435 222 //
duke@435 223 // Below is the detailed description of the fix approach taken:
duke@435 224 // 1. What's done in RedefineClasses() before verification:
duke@435 225 // a) A reference to the class being redefined (_the_class) and a
duke@435 226 // reference to new version of the class (_scratch_class) are
duke@435 227 // saved here for use during the bytecode verification phase of
duke@435 228 // RedefineClasses. See RedefineVerifyMark for how these fields
duke@435 229 // are managed.
duke@435 230 // b) The _java_mirror field from _the_class is copied to the
duke@435 231 // _java_mirror field in _scratch_class. This means that a jclass
duke@435 232 // returned for _the_class or _scratch_class will refer to the
duke@435 233 // same Java mirror. The verifier will see the "one true mirror"
duke@435 234 // for the class being verified.
duke@435 235 // 2. What is done at verification:
duke@435 236 // When the verifier makes calls into the VM to ask questions about
duke@435 237 // the class being verified, it will pass the jclass to JVM_* functions.
duke@435 238 // The jclass is always pointing to the mirror of _the_class.
duke@435 239 // ~28 JVM_* functions called by the verifier for the information
duke@435 240 // about CP entries and klass structure should check the jvmtiThreadState
duke@435 241 // info about equivalent klass versions and use it to replace a klassOop
duke@435 242 // of _the_class with a klassOop of _scratch_class. The function
duke@435 243 // class_to_verify_considering_redefinition() must be called for it.
duke@435 244 //
duke@435 245 // Note again, that this redirection happens only for the verifier thread.
duke@435 246 // Other threads have very small overhead by checking the existence
duke@435 247 // of the jvmtiThreadSate and the information about klasses equivalence.
duke@435 248 // No JNI functions need to be changed, they don't reference the klass guts.
duke@435 249 // The JavaThread pointer is already available in all JVM_* functions
duke@435 250 // used by the verifier, so there is no extra performance issue with it.
duke@435 251
duke@435 252 private:
duke@435 253 KlassHandle *_the_class_for_redefinition_verification;
duke@435 254 KlassHandle *_scratch_class_for_redefinition_verification;
duke@435 255
duke@435 256 public:
duke@435 257 inline void set_class_versions_map(KlassHandle *the_class,
duke@435 258 KlassHandle *scratch_class) {
duke@435 259 _the_class_for_redefinition_verification = the_class;
duke@435 260 _scratch_class_for_redefinition_verification = scratch_class;
duke@435 261 }
duke@435 262
duke@435 263 inline void clear_class_versions_map() { set_class_versions_map(NULL, NULL); }
duke@435 264
duke@435 265 static inline
duke@435 266 klassOop class_to_verify_considering_redefinition(klassOop klass,
duke@435 267 JavaThread *thread) {
duke@435 268 JvmtiThreadState *state = thread->jvmti_thread_state();
duke@435 269 if (state != NULL && state->_the_class_for_redefinition_verification != NULL) {
duke@435 270 if ((*(state->_the_class_for_redefinition_verification))() == klass) {
duke@435 271 klass = (*(state->_scratch_class_for_redefinition_verification))();
duke@435 272 }
duke@435 273 }
duke@435 274 return klass;
duke@435 275 }
duke@435 276
duke@435 277 // Todo: get rid of this!
duke@435 278 private:
duke@435 279 bool _debuggable;
duke@435 280 public:
duke@435 281 // Should the thread be enumerated by jvmtiInternal::GetAllThreads?
duke@435 282 bool is_debuggable() { return _debuggable; }
duke@435 283 // If a thread cannot be suspended (has no valid last_java_frame) then it gets marked !debuggable
duke@435 284 void set_debuggable(bool debuggable) { _debuggable = debuggable; }
duke@435 285
duke@435 286 public:
duke@435 287
duke@435 288 bool may_be_walked();
duke@435 289
duke@435 290 // Thread local event collector setter and getter methods.
duke@435 291 JvmtiDynamicCodeEventCollector* get_dynamic_code_event_collector() {
duke@435 292 return _dynamic_code_event_collector;
duke@435 293 }
duke@435 294 JvmtiVMObjectAllocEventCollector* get_vm_object_alloc_event_collector() {
duke@435 295 return _vm_object_alloc_event_collector;
duke@435 296 }
duke@435 297 void set_dynamic_code_event_collector(JvmtiDynamicCodeEventCollector* collector) {
duke@435 298 _dynamic_code_event_collector = collector;
duke@435 299 }
duke@435 300 void set_vm_object_alloc_event_collector(JvmtiVMObjectAllocEventCollector* collector) {
duke@435 301 _vm_object_alloc_event_collector = collector;
duke@435 302 }
duke@435 303
duke@435 304
duke@435 305 //
duke@435 306 // Frame routines
duke@435 307 //
duke@435 308
duke@435 309 public:
duke@435 310
duke@435 311 // true when the thread was suspended with a pointer to the last Java frame.
duke@435 312 bool has_last_frame() { return _thread->has_last_Java_frame(); }
duke@435 313
duke@435 314 void update_for_pop_top_frame();
duke@435 315
duke@435 316 // already holding JvmtiThreadState_lock - retrieve or create JvmtiThreadState
duke@435 317 inline static JvmtiThreadState *state_for_while_locked(JavaThread *thread) {
duke@435 318 assert(JvmtiThreadState_lock->is_locked(), "sanity check");
duke@435 319
duke@435 320 JvmtiThreadState *state = thread->jvmti_thread_state();
duke@435 321 if (state == NULL) {
duke@435 322 state = new JvmtiThreadState(thread);
duke@435 323 }
duke@435 324 return state;
duke@435 325 }
duke@435 326
duke@435 327 // retrieve or create JvmtiThreadState
duke@435 328 inline static JvmtiThreadState *state_for(JavaThread *thread) {
duke@435 329 JvmtiThreadState *state = thread->jvmti_thread_state();
duke@435 330 if (state == NULL) {
duke@435 331 MutexLocker mu(JvmtiThreadState_lock);
duke@435 332 // check again with the lock held
duke@435 333 state = state_for_while_locked(thread);
duke@435 334 } else {
duke@435 335 CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops());
duke@435 336 }
duke@435 337 return state;
duke@435 338 }
duke@435 339
duke@435 340 // JVMTI ForceEarlyReturn support
duke@435 341
duke@435 342 // This is set to earlyret_pending to signal that top Java frame
duke@435 343 // should be returned immediately
duke@435 344 public:
duke@435 345 int _earlyret_state;
duke@435 346 TosState _earlyret_tos;
duke@435 347 jvalue _earlyret_value;
duke@435 348 oop _earlyret_oop; // Used to return an oop result into Java code from
duke@435 349 // ForceEarlyReturnObject, GC-preserved
duke@435 350
duke@435 351 // Setting and clearing earlyret_state
duke@435 352 // earlyret_pending indicates that a ForceEarlyReturn() has been
duke@435 353 // requested and not yet been completed.
duke@435 354 public:
duke@435 355 enum EarlyretState {
duke@435 356 earlyret_inactive = 0,
duke@435 357 earlyret_pending = 1
duke@435 358 };
duke@435 359
duke@435 360 void set_earlyret_pending(void) { _earlyret_state = earlyret_pending; }
duke@435 361 void clr_earlyret_pending(void) { _earlyret_state = earlyret_inactive; }
duke@435 362 bool is_earlyret_pending(void) { return (_earlyret_state == earlyret_pending); }
duke@435 363
duke@435 364 TosState earlyret_tos() { return _earlyret_tos; }
duke@435 365 oop earlyret_oop() const { return _earlyret_oop; }
duke@435 366 void set_earlyret_oop (oop x) { _earlyret_oop = x; }
duke@435 367 jvalue earlyret_value() { return _earlyret_value; }
duke@435 368 void set_earlyret_value(jvalue val, TosState tos) { _earlyret_tos = tos; _earlyret_value = val; }
duke@435 369 void clr_earlyret_value() { _earlyret_tos = ilgl; _earlyret_value.j = 0L; }
duke@435 370
duke@435 371 static ByteSize earlyret_state_offset() { return byte_offset_of(JvmtiThreadState, _earlyret_state); }
duke@435 372 static ByteSize earlyret_tos_offset() { return byte_offset_of(JvmtiThreadState, _earlyret_tos); }
duke@435 373 static ByteSize earlyret_oop_offset() { return byte_offset_of(JvmtiThreadState, _earlyret_oop); }
duke@435 374 static ByteSize earlyret_value_offset() { return byte_offset_of(JvmtiThreadState, _earlyret_value); }
duke@435 375
duke@435 376 void oops_do(OopClosure* f); // GC support
duke@435 377 };
duke@435 378
duke@435 379 class RedefineVerifyMark : public StackObj {
duke@435 380 private:
duke@435 381 JvmtiThreadState *_state;
duke@435 382
duke@435 383 public:
duke@435 384 RedefineVerifyMark(KlassHandle *the_class, KlassHandle *scratch_class,
duke@435 385 JvmtiThreadState *state) : _state(state)
duke@435 386 {
duke@435 387 _state->set_class_versions_map(the_class, scratch_class);
duke@435 388 (*scratch_class)->set_java_mirror((*the_class)->java_mirror());
duke@435 389 }
duke@435 390
duke@435 391 ~RedefineVerifyMark() {
duke@435 392 _state->clear_class_versions_map();
duke@435 393 }
duke@435 394 };
duke@435 395
duke@435 396 #endif /* _JAVA_JVMTITHREADSTATE_H_ */

mercurial