< prev index next >

src/hotspot/share/prims/jvmtiThreadState.cpp

Print this page


   1 /*
   2  * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 186 
 187     JvmtiEnvThreadStateIterator it(this);
 188     JvmtiEnvThreadState* previous_ets = NULL;
 189     for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
 190       previous_ets = ets;
 191     }
 192     if (previous_ets == NULL) {
 193       set_head_env_thread_state(new_ets);
 194     } else {
 195       previous_ets->set_next(new_ets);
 196     }
 197   }
 198 }
 199 
 200 
 201 
 202 
 203 void JvmtiThreadState::enter_interp_only_mode() {
 204   assert(_thread->get_interp_only_mode() == 0, "entering interp only when mode not zero");
 205   _thread->increment_interp_only_mode();

 206 }
 207 
 208 
 209 void JvmtiThreadState::leave_interp_only_mode() {
 210   assert(_thread->get_interp_only_mode() == 1, "leaving interp only when mode not one");
 211   _thread->decrement_interp_only_mode();
 212 }
 213 
 214 
 215 // Helper routine used in several places
 216 int JvmtiThreadState::count_frames() {
 217   guarantee(SafepointSynchronize::is_at_safepoint() ||
 218     (JavaThread *)Thread::current() == get_thread(),
 219     "must be current thread or at safepoint");
 220 
 221   if (!get_thread()->has_last_Java_frame()) return 0;  // no Java frames
 222 
 223   ResourceMark rm;
 224   RegisterMap reg_map(get_thread());
 225   javaVFrame *jvf = get_thread()->last_java_vframe(&reg_map);
 226   int n = 0;
 227   while (jvf != NULL) {
 228     Method* method = jvf->method();
 229     jvf = jvf->java_sender();
 230     n++;
 231   }
 232   return n;
 233 }
 234 
 235 
 236 void JvmtiThreadState::invalidate_cur_stack_depth() {
 237   guarantee(SafepointSynchronize::is_at_safepoint() ||
 238     (JavaThread *)Thread::current() == get_thread(),
 239     "must be current thread or at safepoint");
 240 
 241   _cur_stack_depth = UNKNOWN_STACK_DEPTH;
 242 }
 243 
 244 void JvmtiThreadState::incr_cur_stack_depth() {
 245   guarantee(JavaThread::current() == get_thread(), "must be current thread");
 246 
 247   if (!is_interp_only_mode()) {
 248     _cur_stack_depth = UNKNOWN_STACK_DEPTH;
 249   }
 250   if (_cur_stack_depth != UNKNOWN_STACK_DEPTH) {
 251     ++_cur_stack_depth;






 252   }
 253 }
 254 
 255 void JvmtiThreadState::decr_cur_stack_depth() {
 256   guarantee(JavaThread::current() == get_thread(), "must be current thread");
 257 
 258   if (!is_interp_only_mode()) {
 259     _cur_stack_depth = UNKNOWN_STACK_DEPTH;
 260   }
 261   if (_cur_stack_depth != UNKNOWN_STACK_DEPTH) {






 262     --_cur_stack_depth;
 263     assert(_cur_stack_depth >= 0, "incr/decr_cur_stack_depth mismatch");
 264   }
 265 }
 266 
 267 int JvmtiThreadState::cur_stack_depth() {
 268   guarantee(SafepointSynchronize::is_at_safepoint() ||
 269     (JavaThread *)Thread::current() == get_thread(),
 270     "must be current thread or at safepoint");
 271 
 272   if (!is_interp_only_mode() || _cur_stack_depth == UNKNOWN_STACK_DEPTH) {
 273     _cur_stack_depth = count_frames();
 274   } else {

 275     // heavy weight assert
 276     assert(_cur_stack_depth == count_frames(),
 277            "cur_stack_depth out of sync");

 278   }
 279   return _cur_stack_depth;
 280 }
 281 
 282 bool JvmtiThreadState::may_be_walked() {
 283   return (get_thread()->is_being_ext_suspended() || (JavaThread::current() == get_thread()));
 284 }
 285 
 286 
 287 void JvmtiThreadState::process_pending_step_for_popframe() {
 288   // We are single stepping as the last part of the PopFrame() dance
 289   // so we have some house keeping to do.
 290 
 291   JavaThread *thr = get_thread();
 292   if (thr->popframe_condition() != JavaThread::popframe_inactive) {
 293     // If the popframe_condition field is not popframe_inactive, then
 294     // we missed all of the popframe_field cleanup points:
 295     //
 296     // - unpack_frames() was not called (nothing to deopt)
 297     // - remove_activation_preserving_args_entry() was not called


   1 /*
   2  * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 186 
 187     JvmtiEnvThreadStateIterator it(this);
 188     JvmtiEnvThreadState* previous_ets = NULL;
 189     for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
 190       previous_ets = ets;
 191     }
 192     if (previous_ets == NULL) {
 193       set_head_env_thread_state(new_ets);
 194     } else {
 195       previous_ets->set_next(new_ets);
 196     }
 197   }
 198 }
 199 
 200 
 201 
 202 
 203 void JvmtiThreadState::enter_interp_only_mode() {
 204   assert(_thread->get_interp_only_mode() == 0, "entering interp only when mode not zero");
 205   _thread->increment_interp_only_mode();
 206   invalidate_cur_stack_depth();
 207 }
 208 
 209 
 210 void JvmtiThreadState::leave_interp_only_mode() {
 211   assert(_thread->get_interp_only_mode() == 1, "leaving interp only when mode not one");
 212   _thread->decrement_interp_only_mode();
 213 }
 214 
 215 
 216 // Helper routine used in several places
 217 int JvmtiThreadState::count_frames() {
 218   guarantee(SafepointSynchronize::is_at_safepoint() ||
 219     (JavaThread *)Thread::current() == get_thread(),
 220     "must be current thread or at safepoint");
 221 
 222   if (!get_thread()->has_last_Java_frame()) return 0;  // no Java frames
 223 
 224   ResourceMark rm;
 225   RegisterMap reg_map(get_thread(), true, true);
 226   javaVFrame *jvf = get_thread()->last_java_vframe(&reg_map);
 227   int n = 0;
 228   while (jvf != NULL) {
 229     Method* method = jvf->method();
 230     jvf = jvf->java_sender();
 231     n++;
 232   }
 233   return n;
 234 }
 235 
 236 
 237 void JvmtiThreadState::invalidate_cur_stack_depth() {
 238   guarantee(SafepointSynchronize::is_at_safepoint() ||
 239     (JavaThread *)Thread::current() == get_thread(),
 240     "must be current thread or at safepoint");
 241 
 242   _cur_stack_depth = UNKNOWN_STACK_DEPTH;
 243 }
 244 
 245 void JvmtiThreadState::incr_cur_stack_depth() {
 246   guarantee(JavaThread::current() == get_thread(), "must be current thread");
 247 
 248   if (!is_interp_only_mode()) {
 249     _cur_stack_depth = UNKNOWN_STACK_DEPTH;
 250   }
 251   if (_cur_stack_depth != UNKNOWN_STACK_DEPTH) {
 252     ++_cur_stack_depth;
 253 #ifdef ASSERT
 254     // heavy weight assert
 255     // fiber fixme: remove this before merging loom with main jdk repo
 256     jint num_frames = count_frames();
 257     assert(_cur_stack_depth == num_frames, "cur_stack_depth out of sync");
 258 #endif
 259   }
 260 }
 261 
 262 void JvmtiThreadState::decr_cur_stack_depth() {
 263   guarantee(JavaThread::current() == get_thread(), "must be current thread");
 264 
 265   if (!is_interp_only_mode()) {
 266     _cur_stack_depth = UNKNOWN_STACK_DEPTH;
 267   }
 268   if (_cur_stack_depth != UNKNOWN_STACK_DEPTH) {
 269 #ifdef ASSERT
 270     // heavy weight assert
 271     // fiber fixme: remove this before merging loom with main jdk repo
 272     jint num_frames = count_frames();
 273     assert(_cur_stack_depth == num_frames, "cur_stack_depth out of sync");
 274 #endif
 275     --_cur_stack_depth;
 276     assert(_cur_stack_depth >= 0, "incr/decr_cur_stack_depth mismatch");
 277   }
 278 }
 279 
 280 int JvmtiThreadState::cur_stack_depth() {
 281   guarantee(SafepointSynchronize::is_at_safepoint() ||
 282     (JavaThread *)Thread::current() == get_thread(),
 283     "must be current thread or at safepoint");
 284 
 285   if (!is_interp_only_mode() || _cur_stack_depth == UNKNOWN_STACK_DEPTH) {
 286     _cur_stack_depth = count_frames();
 287   } else {
 288 #ifdef ASSERT
 289     // heavy weight assert
 290     jint num_frames = count_frames();
 291     assert(_cur_stack_depth == num_frames, "cur_stack_depth out of sync");
 292 #endif
 293   }
 294   return _cur_stack_depth;
 295 }
 296 
 297 bool JvmtiThreadState::may_be_walked() {
 298   return (get_thread()->is_being_ext_suspended() || (JavaThread::current() == get_thread()));
 299 }
 300 
 301 
 302 void JvmtiThreadState::process_pending_step_for_popframe() {
 303   // We are single stepping as the last part of the PopFrame() dance
 304   // so we have some house keeping to do.
 305 
 306   JavaThread *thr = get_thread();
 307   if (thr->popframe_condition() != JavaThread::popframe_inactive) {
 308     // If the popframe_condition field is not popframe_inactive, then
 309     // we missed all of the popframe_field cleanup points:
 310     //
 311     // - unpack_frames() was not called (nothing to deopt)
 312     // - remove_activation_preserving_args_entry() was not called


< prev index next >