src/share/vm/prims/jvmtiThreadState.cpp

Thu, 27 May 2010 19:08:38 -0700

author
trims
date
Thu, 27 May 2010 19:08:38 -0700
changeset 1907
c18cbe5936b8
parent 435
a61af66fc99e
child 2314
f95d63e2154a
permissions
-rw-r--r--

6941466: Oracle rebranding changes for Hotspot repositories
Summary: Change all the Sun copyrights to Oracle copyright
Reviewed-by: ohair

duke@435 1 /*
trims@1907 2 * Copyright (c) 2003, 2006, 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
duke@435 25 # include "incls/_precompiled.incl"
duke@435 26 # include "incls/_jvmtiThreadState.cpp.incl"
duke@435 27
duke@435 28 // marker for when the stack depth has been reset and is now unknown.
duke@435 29 // any negative number would work but small ones might obscure an
duke@435 30 // underrun error.
duke@435 31 static const int UNKNOWN_STACK_DEPTH = -99;
duke@435 32
duke@435 33 ///////////////////////////////////////////////////////////////
duke@435 34 //
duke@435 35 // class JvmtiThreadState
duke@435 36 //
duke@435 37 // Instances of JvmtiThreadState hang off of each thread.
duke@435 38 // Thread local storage for JVMTI.
duke@435 39 //
duke@435 40
duke@435 41 JvmtiThreadState *JvmtiThreadState::_head = NULL;
duke@435 42
duke@435 43 JvmtiThreadState::JvmtiThreadState(JavaThread* thread)
duke@435 44 : _thread_event_enable() {
duke@435 45 assert(JvmtiThreadState_lock->is_locked(), "sanity check");
duke@435 46 _thread = thread;
duke@435 47 _exception_detected = false;
duke@435 48 _exception_caught = false;
duke@435 49 _debuggable = true;
duke@435 50 _hide_single_stepping = false;
duke@435 51 _hide_level = 0;
duke@435 52 _pending_step_for_popframe = false;
duke@435 53 _class_being_redefined = NULL;
duke@435 54 _class_load_kind = jvmti_class_load_kind_load;
duke@435 55 _head_env_thread_state = NULL;
duke@435 56 _dynamic_code_event_collector = NULL;
duke@435 57 _vm_object_alloc_event_collector = NULL;
duke@435 58 _the_class_for_redefinition_verification = NULL;
duke@435 59 _scratch_class_for_redefinition_verification = NULL;
duke@435 60
duke@435 61 // JVMTI ForceEarlyReturn support
duke@435 62 _pending_step_for_earlyret = false;
duke@435 63 _earlyret_state = earlyret_inactive;
duke@435 64 _earlyret_tos = ilgl;
duke@435 65 _earlyret_value.j = 0L;
duke@435 66 _earlyret_oop = NULL;
duke@435 67
duke@435 68 // add all the JvmtiEnvThreadState to the new JvmtiThreadState
duke@435 69 {
duke@435 70 JvmtiEnvIterator it;
duke@435 71 for (JvmtiEnvBase* env = it.first(); env != NULL; env = it.next(env)) {
duke@435 72 if (env->is_valid()) {
duke@435 73 add_env(env);
duke@435 74 }
duke@435 75 }
duke@435 76 }
duke@435 77
duke@435 78 // link us into the list
duke@435 79 {
duke@435 80 // The thread state list manipulation code must not have safepoints.
duke@435 81 // See periodic_clean_up().
duke@435 82 debug_only(No_Safepoint_Verifier nosafepoint;)
duke@435 83
duke@435 84 _prev = NULL;
duke@435 85 _next = _head;
duke@435 86 if (_head != NULL) {
duke@435 87 _head->_prev = this;
duke@435 88 }
duke@435 89 _head = this;
duke@435 90 }
duke@435 91
duke@435 92 // set this as the state for the thread
duke@435 93 thread->set_jvmti_thread_state(this);
duke@435 94 }
duke@435 95
duke@435 96
duke@435 97 JvmtiThreadState::~JvmtiThreadState() {
duke@435 98 assert(JvmtiThreadState_lock->is_locked(), "sanity check");
duke@435 99
duke@435 100 // clear this as the state for the thread
duke@435 101 get_thread()->set_jvmti_thread_state(NULL);
duke@435 102
duke@435 103 // zap our env thread states
duke@435 104 {
duke@435 105 JvmtiEnvBase::entering_dying_thread_env_iteration();
duke@435 106 JvmtiEnvThreadStateIterator it(this);
duke@435 107 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ) {
duke@435 108 JvmtiEnvThreadState* zap = ets;
duke@435 109 ets = it.next(ets);
duke@435 110 delete zap;
duke@435 111 }
duke@435 112 JvmtiEnvBase::leaving_dying_thread_env_iteration();
duke@435 113 }
duke@435 114
duke@435 115 // remove us from the list
duke@435 116 {
duke@435 117 // The thread state list manipulation code must not have safepoints.
duke@435 118 // See periodic_clean_up().
duke@435 119 debug_only(No_Safepoint_Verifier nosafepoint;)
duke@435 120
duke@435 121 if (_prev == NULL) {
duke@435 122 assert(_head == this, "sanity check");
duke@435 123 _head = _next;
duke@435 124 } else {
duke@435 125 assert(_head != this, "sanity check");
duke@435 126 _prev->_next = _next;
duke@435 127 }
duke@435 128 if (_next != NULL) {
duke@435 129 _next->_prev = _prev;
duke@435 130 }
duke@435 131 _next = NULL;
duke@435 132 _prev = NULL;
duke@435 133 }
duke@435 134 }
duke@435 135
duke@435 136
duke@435 137 void
duke@435 138 JvmtiThreadState::periodic_clean_up() {
duke@435 139 assert(SafepointSynchronize::is_at_safepoint(), "at safepoint");
duke@435 140
duke@435 141 // This iteration is initialized with "_head" instead of "JvmtiThreadState::first()"
duke@435 142 // because the latter requires the JvmtiThreadState_lock.
duke@435 143 // This iteration is safe at a safepoint as well, see the No_Safepoint_Verifier
duke@435 144 // asserts at all list manipulation sites.
duke@435 145 for (JvmtiThreadState *state = _head; state != NULL; state = state->next()) {
duke@435 146 // For each environment thread state corresponding to an invalid environment
duke@435 147 // unlink it from the list and deallocate it.
duke@435 148 JvmtiEnvThreadStateIterator it(state);
duke@435 149 JvmtiEnvThreadState* previous_ets = NULL;
duke@435 150 JvmtiEnvThreadState* ets = it.first();
duke@435 151 while (ets != NULL) {
duke@435 152 if (ets->get_env()->is_valid()) {
duke@435 153 previous_ets = ets;
duke@435 154 ets = it.next(ets);
duke@435 155 } else {
duke@435 156 // This one isn't valid, remove it from the list and deallocate it
duke@435 157 JvmtiEnvThreadState* defunct_ets = ets;
duke@435 158 ets = ets->next();
duke@435 159 if (previous_ets == NULL) {
duke@435 160 assert(state->head_env_thread_state() == defunct_ets, "sanity check");
duke@435 161 state->set_head_env_thread_state(ets);
duke@435 162 } else {
duke@435 163 previous_ets->set_next(ets);
duke@435 164 }
duke@435 165 delete defunct_ets;
duke@435 166 }
duke@435 167 }
duke@435 168 }
duke@435 169 }
duke@435 170
duke@435 171 void JvmtiThreadState::add_env(JvmtiEnvBase *env) {
duke@435 172 assert(JvmtiThreadState_lock->is_locked(), "sanity check");
duke@435 173
duke@435 174 JvmtiEnvThreadState *new_ets = new JvmtiEnvThreadState(_thread, env);
duke@435 175 // add this environment thread state to the end of the list (order is important)
duke@435 176 {
duke@435 177 // list deallocation (which occurs at a safepoint) cannot occur simultaneously
duke@435 178 debug_only(No_Safepoint_Verifier nosafepoint;)
duke@435 179
duke@435 180 JvmtiEnvThreadStateIterator it(this);
duke@435 181 JvmtiEnvThreadState* previous_ets = NULL;
duke@435 182 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
duke@435 183 previous_ets = ets;
duke@435 184 }
duke@435 185 if (previous_ets == NULL) {
duke@435 186 set_head_env_thread_state(new_ets);
duke@435 187 } else {
duke@435 188 previous_ets->set_next(new_ets);
duke@435 189 }
duke@435 190 }
duke@435 191 }
duke@435 192
duke@435 193
duke@435 194
duke@435 195
duke@435 196 void JvmtiThreadState::enter_interp_only_mode() {
duke@435 197 assert(_thread->get_interp_only_mode() == 0, "entering interp only when mode not zero");
duke@435 198 _thread->increment_interp_only_mode();
duke@435 199 }
duke@435 200
duke@435 201
duke@435 202 void JvmtiThreadState::leave_interp_only_mode() {
duke@435 203 assert(_thread->get_interp_only_mode() == 1, "leaving interp only when mode not one");
duke@435 204 _thread->decrement_interp_only_mode();
duke@435 205 }
duke@435 206
duke@435 207
duke@435 208 // Helper routine used in several places
duke@435 209 int JvmtiThreadState::count_frames() {
duke@435 210 #ifdef ASSERT
duke@435 211 uint32_t debug_bits = 0;
duke@435 212 #endif
duke@435 213 assert(SafepointSynchronize::is_at_safepoint() ||
duke@435 214 JvmtiEnv::is_thread_fully_suspended(get_thread(), false, &debug_bits),
duke@435 215 "at safepoint or must be suspended");
duke@435 216
duke@435 217 if (!get_thread()->has_last_Java_frame()) return 0; // no Java frames
duke@435 218
duke@435 219 ResourceMark rm;
duke@435 220 RegisterMap reg_map(get_thread());
duke@435 221 javaVFrame *jvf = get_thread()->last_java_vframe(&reg_map);
duke@435 222 int n = 0;
duke@435 223 // tty->print_cr("CSD: counting frames on %s ...",
duke@435 224 // JvmtiTrace::safe_get_thread_name(get_thread()));
duke@435 225 while (jvf != NULL) {
duke@435 226 methodOop method = jvf->method();
duke@435 227 // tty->print_cr("CSD: frame - method %s.%s - loc %d",
duke@435 228 // method->klass_name()->as_C_string(),
duke@435 229 // method->name()->as_C_string(),
duke@435 230 // jvf->bci() );
duke@435 231 jvf = jvf->java_sender();
duke@435 232 n++;
duke@435 233 }
duke@435 234 // tty->print_cr("CSD: frame count: %d", n);
duke@435 235 return n;
duke@435 236 }
duke@435 237
duke@435 238
duke@435 239 void JvmtiThreadState::invalidate_cur_stack_depth() {
duke@435 240 Thread *cur = Thread::current();
duke@435 241 uint32_t debug_bits = 0;
duke@435 242
duke@435 243 // The caller can be the VMThread at a safepoint, the current thread
duke@435 244 // or the target thread must be suspended.
duke@435 245 guarantee((cur->is_VM_thread() && SafepointSynchronize::is_at_safepoint()) ||
duke@435 246 (JavaThread *)cur == get_thread() ||
duke@435 247 JvmtiEnv::is_thread_fully_suspended(get_thread(), false, &debug_bits),
duke@435 248 "sanity check");
duke@435 249
duke@435 250 _cur_stack_depth = UNKNOWN_STACK_DEPTH;
duke@435 251 }
duke@435 252
duke@435 253 void JvmtiThreadState::incr_cur_stack_depth() {
duke@435 254 guarantee(JavaThread::current() == get_thread(), "must be current thread");
duke@435 255
duke@435 256 if (!is_interp_only_mode()) {
duke@435 257 _cur_stack_depth = UNKNOWN_STACK_DEPTH;
duke@435 258 }
duke@435 259 if (_cur_stack_depth != UNKNOWN_STACK_DEPTH) {
duke@435 260 ++_cur_stack_depth;
duke@435 261 }
duke@435 262 }
duke@435 263
duke@435 264 void JvmtiThreadState::decr_cur_stack_depth() {
duke@435 265 guarantee(JavaThread::current() == get_thread(), "must be current thread");
duke@435 266
duke@435 267 if (!is_interp_only_mode()) {
duke@435 268 _cur_stack_depth = UNKNOWN_STACK_DEPTH;
duke@435 269 }
duke@435 270 if (_cur_stack_depth != UNKNOWN_STACK_DEPTH) {
duke@435 271 --_cur_stack_depth;
duke@435 272 assert(_cur_stack_depth >= 0, "incr/decr_cur_stack_depth mismatch");
duke@435 273 }
duke@435 274 }
duke@435 275
duke@435 276 int JvmtiThreadState::cur_stack_depth() {
duke@435 277 uint32_t debug_bits = 0;
duke@435 278 guarantee(JavaThread::current() == get_thread() ||
duke@435 279 JvmtiEnv::is_thread_fully_suspended(get_thread(), false, &debug_bits),
duke@435 280 "must be current thread or suspended");
duke@435 281
duke@435 282 if (!is_interp_only_mode() || _cur_stack_depth == UNKNOWN_STACK_DEPTH) {
duke@435 283 _cur_stack_depth = count_frames();
duke@435 284 } else {
duke@435 285 // heavy weight assert
duke@435 286 assert(_cur_stack_depth == count_frames(),
duke@435 287 "cur_stack_depth out of sync");
duke@435 288 }
duke@435 289 return _cur_stack_depth;
duke@435 290 }
duke@435 291
duke@435 292 bool JvmtiThreadState::may_be_walked() {
duke@435 293 return (get_thread()->is_being_ext_suspended() || (JavaThread::current() == get_thread()));
duke@435 294 }
duke@435 295
duke@435 296
duke@435 297 void JvmtiThreadState::process_pending_step_for_popframe() {
duke@435 298 // We are single stepping as the last part of the PopFrame() dance
duke@435 299 // so we have some house keeping to do.
duke@435 300
duke@435 301 JavaThread *thr = get_thread();
duke@435 302 if (thr->popframe_condition() != JavaThread::popframe_inactive) {
duke@435 303 // If the popframe_condition field is not popframe_inactive, then
duke@435 304 // we missed all of the popframe_field cleanup points:
duke@435 305 //
duke@435 306 // - unpack_frames() was not called (nothing to deopt)
duke@435 307 // - remove_activation_preserving_args_entry() was not called
duke@435 308 // (did not get suspended in a call_vm() family call and did
duke@435 309 // not complete a call_vm() family call on the way here)
duke@435 310 thr->clear_popframe_condition();
duke@435 311 }
duke@435 312
duke@435 313 // clearing the flag indicates we are done with the PopFrame() dance
duke@435 314 clr_pending_step_for_popframe();
duke@435 315
duke@435 316 // If step is pending for popframe then it may not be
duke@435 317 // a repeat step. The new_bci and method_id is same as current_bci
duke@435 318 // and current method_id after pop and step for recursive calls.
duke@435 319 // Force the step by clearing the last location.
duke@435 320 JvmtiEnvThreadStateIterator it(this);
duke@435 321 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
duke@435 322 ets->clear_current_location();
duke@435 323 }
duke@435 324 }
duke@435 325
duke@435 326
duke@435 327 // Class: JvmtiThreadState
duke@435 328 // Function: update_for_pop_top_frame
duke@435 329 // Description:
duke@435 330 // This function removes any frame pop notification request for
duke@435 331 // the top frame and invalidates both the current stack depth and
duke@435 332 // all cached frameIDs.
duke@435 333 //
duke@435 334 // Called by: PopFrame
duke@435 335 //
duke@435 336 void JvmtiThreadState::update_for_pop_top_frame() {
duke@435 337 if (is_interp_only_mode()) {
duke@435 338 // remove any frame pop notification request for the top frame
duke@435 339 // in any environment
duke@435 340 int popframe_number = cur_stack_depth();
duke@435 341 {
duke@435 342 JvmtiEnvThreadStateIterator it(this);
duke@435 343 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
duke@435 344 if (ets->is_frame_pop(popframe_number)) {
duke@435 345 ets->clear_frame_pop(popframe_number);
duke@435 346 }
duke@435 347 }
duke@435 348 }
duke@435 349 // force stack depth to be recalculated
duke@435 350 invalidate_cur_stack_depth();
duke@435 351 } else {
duke@435 352 assert(!is_enabled(JVMTI_EVENT_FRAME_POP), "Must have no framepops set");
duke@435 353 }
duke@435 354 }
duke@435 355
duke@435 356
duke@435 357 void JvmtiThreadState::process_pending_step_for_earlyret() {
duke@435 358 // We are single stepping as the last part of the ForceEarlyReturn
duke@435 359 // dance so we have some house keeping to do.
duke@435 360
duke@435 361 if (is_earlyret_pending()) {
duke@435 362 // If the earlyret_state field is not earlyret_inactive, then
duke@435 363 // we missed all of the earlyret_field cleanup points:
duke@435 364 //
duke@435 365 // - remove_activation() was not called
duke@435 366 // (did not get suspended in a call_vm() family call and did
duke@435 367 // not complete a call_vm() family call on the way here)
duke@435 368 //
duke@435 369 // One legitimate way for us to miss all the cleanup points is
duke@435 370 // if we got here right after handling a compiled return. If that
duke@435 371 // is the case, then we consider our return from compiled code to
duke@435 372 // complete the ForceEarlyReturn request and we clear the condition.
duke@435 373 clr_earlyret_pending();
duke@435 374 set_earlyret_oop(NULL);
duke@435 375 clr_earlyret_value();
duke@435 376 }
duke@435 377
duke@435 378 // clearing the flag indicates we are done with
duke@435 379 // the ForceEarlyReturn() dance
duke@435 380 clr_pending_step_for_earlyret();
duke@435 381
duke@435 382 // If step is pending for earlyret then it may not be a repeat step.
duke@435 383 // The new_bci and method_id is same as current_bci and current
duke@435 384 // method_id after earlyret and step for recursive calls.
duke@435 385 // Force the step by clearing the last location.
duke@435 386 JvmtiEnvThreadStateIterator it(this);
duke@435 387 for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
duke@435 388 ets->clear_current_location();
duke@435 389 }
duke@435 390 }
duke@435 391
duke@435 392 void JvmtiThreadState::oops_do(OopClosure* f) {
duke@435 393 f->do_oop((oop*) &_earlyret_oop);
duke@435 394 }

mercurial