src/share/vm/prims/jvmtiThreadState.hpp

Sun, 15 Sep 2013 15:28:58 +0200

author
goetz
date
Sun, 15 Sep 2013 15:28:58 +0200
changeset 6470
abe03600372a
parent 4165
fb19af007ffc
child 6876
710a3c8b516e
permissions
-rw-r--r--

8024468: PPC64 (part 201): cppInterpreter: implement bytecode profiling
Summary: Implement profiling for c2 jit compilation. Also enable new cppInterpreter features.
Reviewed-by: kvn

duke@435 1 /*
coleenp@4037 2 * Copyright (c) 2003, 2012, 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.
zgu@3900 75 class JvmtiThreadState : public CHeapObj<mtInternal> {
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; }
bpittore@3468 168 inline void clear_exception_detected() {
bpittore@3468 169 _exception_detected = false;
bpittore@3468 170 assert(_exception_caught == false, "_exception_caught is out of phase");
bpittore@3468 171 }
duke@435 172 inline void set_exception_caught() { _exception_caught = true;
duke@435 173 _exception_detected = false; }
duke@435 174
duke@435 175 inline void clear_hide_single_stepping() {
duke@435 176 if (_hide_level > 0) {
duke@435 177 _hide_level--;
duke@435 178 } else {
duke@435 179 assert(_hide_single_stepping, "hide_single_stepping is out of phase");
duke@435 180 _hide_single_stepping = false;
duke@435 181 }
duke@435 182 }
duke@435 183 inline bool hide_single_stepping() { return _hide_single_stepping; }
duke@435 184 inline void set_hide_single_stepping() {
duke@435 185 if (_hide_single_stepping) {
duke@435 186 _hide_level++;
duke@435 187 } else {
duke@435 188 assert(_hide_level == 0, "hide_level is out of phase");
duke@435 189 _hide_single_stepping = true;
duke@435 190 }
duke@435 191 }
duke@435 192
duke@435 193 // Step pending flag is set when PopFrame is called and it is cleared
duke@435 194 // when step for the Pop Frame is completed.
duke@435 195 // This logic is used to distinguish b/w step for pop frame and repeat step.
duke@435 196 void set_pending_step_for_popframe() { _pending_step_for_popframe = true; }
duke@435 197 void clr_pending_step_for_popframe() { _pending_step_for_popframe = false; }
duke@435 198 bool is_pending_step_for_popframe() { return _pending_step_for_popframe; }
duke@435 199 void process_pending_step_for_popframe();
duke@435 200
duke@435 201 // Step pending flag is set when ForceEarlyReturn is called and it is cleared
duke@435 202 // when step for the ForceEarlyReturn is completed.
duke@435 203 // This logic is used to distinguish b/w step for early return and repeat step.
duke@435 204 void set_pending_step_for_earlyret() { _pending_step_for_earlyret = true; }
duke@435 205 void clr_pending_step_for_earlyret() { _pending_step_for_earlyret = false; }
duke@435 206 bool is_pending_step_for_earlyret() { return _pending_step_for_earlyret; }
duke@435 207 void process_pending_step_for_earlyret();
duke@435 208
duke@435 209 // Setter and getter method is used to send redefined class info
duke@435 210 // when class file load hook event is posted.
duke@435 211 // It is set while loading redefined class and cleared before the
duke@435 212 // class file load hook event is posted.
duke@435 213 inline void set_class_being_redefined(KlassHandle *h_class, JvmtiClassLoadKind kind) {
duke@435 214 _class_being_redefined = h_class;
duke@435 215 _class_load_kind = kind;
duke@435 216 }
duke@435 217
duke@435 218 inline void clear_class_being_redefined() {
duke@435 219 _class_being_redefined = NULL;
duke@435 220 _class_load_kind = jvmti_class_load_kind_load;
duke@435 221 }
duke@435 222
duke@435 223 inline KlassHandle *get_class_being_redefined() {
duke@435 224 return _class_being_redefined;
duke@435 225 }
duke@435 226
duke@435 227 inline JvmtiClassLoadKind get_class_load_kind() {
duke@435 228 return _class_load_kind;
duke@435 229 }
duke@435 230
duke@435 231 // RedefineClasses support
duke@435 232 // The bug 6214132 caused the verification to fail.
duke@435 233 //
duke@435 234 // Below is the detailed description of the fix approach taken:
duke@435 235 // 1. What's done in RedefineClasses() before verification:
duke@435 236 // a) A reference to the class being redefined (_the_class) and a
duke@435 237 // reference to new version of the class (_scratch_class) are
duke@435 238 // saved here for use during the bytecode verification phase of
duke@435 239 // RedefineClasses. See RedefineVerifyMark for how these fields
duke@435 240 // are managed.
duke@435 241 // b) The _java_mirror field from _the_class is copied to the
duke@435 242 // _java_mirror field in _scratch_class. This means that a jclass
duke@435 243 // returned for _the_class or _scratch_class will refer to the
duke@435 244 // same Java mirror. The verifier will see the "one true mirror"
duke@435 245 // for the class being verified.
duke@435 246 // 2. What is done at verification:
duke@435 247 // When the verifier makes calls into the VM to ask questions about
duke@435 248 // the class being verified, it will pass the jclass to JVM_* functions.
duke@435 249 // The jclass is always pointing to the mirror of _the_class.
duke@435 250 // ~28 JVM_* functions called by the verifier for the information
duke@435 251 // about CP entries and klass structure should check the jvmtiThreadState
coleenp@4037 252 // info about equivalent klass versions and use it to replace a Klass*
coleenp@4037 253 // of _the_class with a Klass* of _scratch_class. The function
duke@435 254 // class_to_verify_considering_redefinition() must be called for it.
duke@435 255 //
duke@435 256 // Note again, that this redirection happens only for the verifier thread.
duke@435 257 // Other threads have very small overhead by checking the existence
duke@435 258 // of the jvmtiThreadSate and the information about klasses equivalence.
duke@435 259 // No JNI functions need to be changed, they don't reference the klass guts.
duke@435 260 // The JavaThread pointer is already available in all JVM_* functions
duke@435 261 // used by the verifier, so there is no extra performance issue with it.
duke@435 262
duke@435 263 private:
duke@435 264 KlassHandle *_the_class_for_redefinition_verification;
duke@435 265 KlassHandle *_scratch_class_for_redefinition_verification;
duke@435 266
duke@435 267 public:
duke@435 268 inline void set_class_versions_map(KlassHandle *the_class,
duke@435 269 KlassHandle *scratch_class) {
duke@435 270 _the_class_for_redefinition_verification = the_class;
duke@435 271 _scratch_class_for_redefinition_verification = scratch_class;
duke@435 272 }
duke@435 273
duke@435 274 inline void clear_class_versions_map() { set_class_versions_map(NULL, NULL); }
duke@435 275
duke@435 276 static inline
coleenp@4037 277 Klass* class_to_verify_considering_redefinition(Klass* klass,
duke@435 278 JavaThread *thread) {
duke@435 279 JvmtiThreadState *state = thread->jvmti_thread_state();
duke@435 280 if (state != NULL && state->_the_class_for_redefinition_verification != NULL) {
duke@435 281 if ((*(state->_the_class_for_redefinition_verification))() == klass) {
duke@435 282 klass = (*(state->_scratch_class_for_redefinition_verification))();
duke@435 283 }
duke@435 284 }
duke@435 285 return klass;
duke@435 286 }
duke@435 287
duke@435 288 // Todo: get rid of this!
duke@435 289 private:
duke@435 290 bool _debuggable;
duke@435 291 public:
duke@435 292 // Should the thread be enumerated by jvmtiInternal::GetAllThreads?
duke@435 293 bool is_debuggable() { return _debuggable; }
duke@435 294 // If a thread cannot be suspended (has no valid last_java_frame) then it gets marked !debuggable
duke@435 295 void set_debuggable(bool debuggable) { _debuggable = debuggable; }
duke@435 296
duke@435 297 public:
duke@435 298
duke@435 299 bool may_be_walked();
duke@435 300
duke@435 301 // Thread local event collector setter and getter methods.
duke@435 302 JvmtiDynamicCodeEventCollector* get_dynamic_code_event_collector() {
duke@435 303 return _dynamic_code_event_collector;
duke@435 304 }
duke@435 305 JvmtiVMObjectAllocEventCollector* get_vm_object_alloc_event_collector() {
duke@435 306 return _vm_object_alloc_event_collector;
duke@435 307 }
duke@435 308 void set_dynamic_code_event_collector(JvmtiDynamicCodeEventCollector* collector) {
duke@435 309 _dynamic_code_event_collector = collector;
duke@435 310 }
duke@435 311 void set_vm_object_alloc_event_collector(JvmtiVMObjectAllocEventCollector* collector) {
duke@435 312 _vm_object_alloc_event_collector = collector;
duke@435 313 }
duke@435 314
duke@435 315
duke@435 316 //
duke@435 317 // Frame routines
duke@435 318 //
duke@435 319
duke@435 320 public:
duke@435 321
duke@435 322 // true when the thread was suspended with a pointer to the last Java frame.
duke@435 323 bool has_last_frame() { return _thread->has_last_Java_frame(); }
duke@435 324
duke@435 325 void update_for_pop_top_frame();
duke@435 326
duke@435 327 // already holding JvmtiThreadState_lock - retrieve or create JvmtiThreadState
dcubed@1044 328 // Can return NULL if JavaThread is exiting.
duke@435 329 inline static JvmtiThreadState *state_for_while_locked(JavaThread *thread) {
duke@435 330 assert(JvmtiThreadState_lock->is_locked(), "sanity check");
duke@435 331
duke@435 332 JvmtiThreadState *state = thread->jvmti_thread_state();
duke@435 333 if (state == NULL) {
dcubed@1043 334 if (thread->is_exiting()) {
dcubed@1043 335 // don't add a JvmtiThreadState to a thread that is exiting
dcubed@1043 336 return NULL;
dcubed@1043 337 }
dcubed@1043 338
duke@435 339 state = new JvmtiThreadState(thread);
duke@435 340 }
duke@435 341 return state;
duke@435 342 }
duke@435 343
duke@435 344 // retrieve or create JvmtiThreadState
dcubed@1044 345 // Can return NULL if JavaThread is exiting.
duke@435 346 inline static JvmtiThreadState *state_for(JavaThread *thread) {
duke@435 347 JvmtiThreadState *state = thread->jvmti_thread_state();
duke@435 348 if (state == NULL) {
duke@435 349 MutexLocker mu(JvmtiThreadState_lock);
duke@435 350 // check again with the lock held
duke@435 351 state = state_for_while_locked(thread);
duke@435 352 } else {
duke@435 353 CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops());
duke@435 354 }
duke@435 355 return state;
duke@435 356 }
duke@435 357
duke@435 358 // JVMTI ForceEarlyReturn support
duke@435 359
duke@435 360 // This is set to earlyret_pending to signal that top Java frame
duke@435 361 // should be returned immediately
duke@435 362 public:
duke@435 363 int _earlyret_state;
duke@435 364 TosState _earlyret_tos;
duke@435 365 jvalue _earlyret_value;
duke@435 366 oop _earlyret_oop; // Used to return an oop result into Java code from
duke@435 367 // ForceEarlyReturnObject, GC-preserved
duke@435 368
duke@435 369 // Setting and clearing earlyret_state
duke@435 370 // earlyret_pending indicates that a ForceEarlyReturn() has been
duke@435 371 // requested and not yet been completed.
duke@435 372 public:
duke@435 373 enum EarlyretState {
duke@435 374 earlyret_inactive = 0,
duke@435 375 earlyret_pending = 1
duke@435 376 };
duke@435 377
duke@435 378 void set_earlyret_pending(void) { _earlyret_state = earlyret_pending; }
duke@435 379 void clr_earlyret_pending(void) { _earlyret_state = earlyret_inactive; }
duke@435 380 bool is_earlyret_pending(void) { return (_earlyret_state == earlyret_pending); }
duke@435 381
duke@435 382 TosState earlyret_tos() { return _earlyret_tos; }
duke@435 383 oop earlyret_oop() const { return _earlyret_oop; }
duke@435 384 void set_earlyret_oop (oop x) { _earlyret_oop = x; }
duke@435 385 jvalue earlyret_value() { return _earlyret_value; }
duke@435 386 void set_earlyret_value(jvalue val, TosState tos) { _earlyret_tos = tos; _earlyret_value = val; }
duke@435 387 void clr_earlyret_value() { _earlyret_tos = ilgl; _earlyret_value.j = 0L; }
duke@435 388
duke@435 389 static ByteSize earlyret_state_offset() { return byte_offset_of(JvmtiThreadState, _earlyret_state); }
duke@435 390 static ByteSize earlyret_tos_offset() { return byte_offset_of(JvmtiThreadState, _earlyret_tos); }
duke@435 391 static ByteSize earlyret_oop_offset() { return byte_offset_of(JvmtiThreadState, _earlyret_oop); }
duke@435 392 static ByteSize earlyret_value_offset() { return byte_offset_of(JvmtiThreadState, _earlyret_value); }
duke@435 393
jprovino@4165 394 void oops_do(OopClosure* f) NOT_JVMTI_RETURN; // GC support
dcubed@1648 395
dcubed@1648 396 public:
dcubed@1648 397 void set_should_post_on_exceptions(bool val) { _thread->set_should_post_on_exceptions_flag(val ? JNI_TRUE : JNI_FALSE); }
duke@435 398 };
duke@435 399
duke@435 400 class RedefineVerifyMark : public StackObj {
duke@435 401 private:
duke@435 402 JvmtiThreadState *_state;
coleenp@4037 403 KlassHandle _scratch_class;
coleenp@4037 404 Handle _scratch_mirror;
duke@435 405
duke@435 406 public:
duke@435 407 RedefineVerifyMark(KlassHandle *the_class, KlassHandle *scratch_class,
coleenp@4037 408 JvmtiThreadState *state) : _state(state), _scratch_class(*scratch_class)
duke@435 409 {
duke@435 410 _state->set_class_versions_map(the_class, scratch_class);
coleenp@4037 411 _scratch_mirror = Handle(_scratch_class->java_mirror());
duke@435 412 (*scratch_class)->set_java_mirror((*the_class)->java_mirror());
duke@435 413 }
duke@435 414
duke@435 415 ~RedefineVerifyMark() {
coleenp@4037 416 // Restore the scratch class's mirror, so when scratch_class is removed
coleenp@4037 417 // the correct mirror pointing to it can be cleared.
coleenp@4037 418 _scratch_class->set_java_mirror(_scratch_mirror());
duke@435 419 _state->clear_class_versions_map();
duke@435 420 }
duke@435 421 };
duke@435 422
stefank@2314 423 #endif // SHARE_VM_PRIMS_JVMTITHREADSTATE_HPP

mercurial