src/share/vm/prims/jvmtiThreadState.hpp

Mon, 10 Jan 2011 17:14:53 -0500

author
kamg
date
Mon, 10 Jan 2011 17:14:53 -0500
changeset 2445
7246a374a9f2
parent 2314
f95d63e2154a
child 3468
af739d5ab23c
permissions
-rw-r--r--

6458402: 3 jvmti tests fail with CMS and +ExplicitGCInvokesConcurrent
Summary: Make JvmtiGCMark safe to run non-safepoint and instrument CMS
Reviewed-by: ysr, dcubed

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

mercurial