< prev index next >

src/hotspot/share/prims/jvmtiEnvThreadState.cpp

Print this page


   1 /*
   2  * Copyright (c) 2003, 2017, 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  *


 174       // If step is pending for popframe then it may not be
 175       // a repeat step. The new_bci and method_id is same as current_bci
 176       // and current method_id after pop and step for recursive calls.
 177       // This has been handled by clearing the location
 178       _single_stepping_posted = true;
 179       break;
 180     default:
 181       assert(false, "invalid event value passed");
 182       break;
 183     }
 184     return;
 185   }
 186 
 187   set_current_location(new_method_id, new_bci);
 188   _breakpoint_posted = false;
 189   _single_stepping_posted = false;
 190 }
 191 
 192 
 193 JvmtiFramePops* JvmtiEnvThreadState::get_frame_pops() {
 194   assert(get_thread() == Thread::current() || SafepointSynchronize::is_at_safepoint(),
 195          "frame pop data only accessible from same thread or at safepoint");



 196   if (_frame_pops == NULL) {
 197     _frame_pops = new JvmtiFramePops();
 198     assert(_frame_pops != NULL, "_frame_pops != NULL");
 199   }
 200   return _frame_pops;
 201 }
 202 
 203 
 204 bool JvmtiEnvThreadState::has_frame_pops() {
 205   return _frame_pops == NULL? false : (_frame_pops->length() > 0);
 206 }
 207 
 208 void JvmtiEnvThreadState::set_frame_pop(int frame_number) {
 209   assert(get_thread() == Thread::current() || SafepointSynchronize::is_at_safepoint(),
 210          "frame pop data only accessible from same thread or at safepoint");



 211   JvmtiFramePop fpop(frame_number);
 212   JvmtiEventController::set_frame_pop(this, fpop);
 213 }
 214 
 215 
 216 void JvmtiEnvThreadState::clear_frame_pop(int frame_number) {
 217   assert(get_thread() == Thread::current() || SafepointSynchronize::is_at_safepoint(),
 218          "frame pop data only accessible from same thread or at safepoint");



 219   JvmtiFramePop fpop(frame_number);
 220   JvmtiEventController::clear_frame_pop(this, fpop);
 221 }
 222 
 223 
 224 void JvmtiEnvThreadState::clear_to_frame_pop(int frame_number)  {
 225   assert(get_thread() == Thread::current() || SafepointSynchronize::is_at_safepoint(),
 226          "frame pop data only accessible from same thread or at safepoint");



 227   JvmtiFramePop fpop(frame_number);
 228   JvmtiEventController::clear_to_frame_pop(this, fpop);
 229 }
 230 
 231 
 232 bool JvmtiEnvThreadState::is_frame_pop(int cur_frame_number) {
 233   assert(get_thread() == Thread::current() || SafepointSynchronize::is_at_safepoint(),
 234          "frame pop data only accessible from same thread or at safepoint");



 235   if (!get_thread()->is_interp_only_mode() || _frame_pops == NULL) {
 236     return false;
 237   }
 238   JvmtiFramePop fp(cur_frame_number);
 239   return get_frame_pops()->contains(fp);
 240 }
 241 
 242 
 243 class VM_GetCurrentLocation : public VM_Operation {
 244  private:
 245    JavaThread *_thread;
 246    jmethodID _method_id;
 247    int _bci;
 248 
 249  public:
 250   VM_GetCurrentLocation(JavaThread *thread) {
 251      _thread = thread;
 252    }
 253   VMOp_Type type() const { return VMOp_GetCurrentLocation; }
 254   void doit() {
 255     ResourceMark rmark; // _thread != Thread::current()
 256     RegisterMap rm(_thread, false);

 257     // There can be a race condition between a VM_Operation reaching a safepoint
 258     // and the target thread exiting from Java execution.
 259     // We must recheck the last Java frame still exists.
 260     if (!_thread->is_exiting() && _thread->has_last_Java_frame()) {
 261       javaVFrame* vf = _thread->last_java_vframe(&rm);
 262       assert(vf != NULL, "must have last java frame");
 263       Method* method = vf->method();
 264       _method_id = method->jmethod_id();
 265       _bci = vf->bci();
 266     } else {
 267       // Clear current location as the target thread has no Java frames anymore.
 268       _method_id = (jmethodID)NULL;
 269       _bci = 0;
 270     }
 271   }
 272   void get_current_location(jmethodID *method_id, int *bci) {
 273     *method_id = _method_id;
 274     *bci = _bci;
 275   }
 276 };
 277 
 278 void JvmtiEnvThreadState::reset_current_location(jvmtiEvent event_type, bool enabled) {
 279   assert(event_type == JVMTI_EVENT_SINGLE_STEP || event_type == JVMTI_EVENT_BREAKPOINT,
 280          "must be single-step or breakpoint event");
 281 


 290 
 291   // If single-stepping is enabled, set the current location to the
 292   // current method and bcp. This covers the following type of case,
 293   // e.g., the debugger stepi command:
 294   // - bytecode single stepped
 295   // - SINGLE_STEP event posted and SINGLE_STEP event disabled
 296   // - SINGLE_STEP event reenabled
 297   // - bytecode rewritten to fast version
 298 
 299   // If breakpoint event is disabled, clear current location only if
 300   // single-stepping is not enabled.  Otherwise, keep the thread location
 301   // to detect any duplicate events.
 302 
 303   if (enabled) {
 304     // If enabling breakpoint, no need to reset.
 305     // Can't do anything if empty stack.
 306     if (event_type == JVMTI_EVENT_SINGLE_STEP && _thread->has_last_Java_frame()) {
 307       jmethodID method_id;
 308       int bci;
 309       // The java thread stack may not be walkable for a running thread
 310       // so get current location at safepoint.
 311       VM_GetCurrentLocation op(_thread);
 312       VMThread::execute(&op);





 313       op.get_current_location(&method_id, &bci);
 314       set_current_location(method_id, bci);
 315     }
 316   } else if (event_type == JVMTI_EVENT_SINGLE_STEP || !is_enabled(JVMTI_EVENT_SINGLE_STEP)) {
 317     // If this is to disable breakpoint, also check if single-step is not enabled
 318     clear_current_location();
 319   }
 320 }
   1 /*
   2  * Copyright (c) 2003, 2020, 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  *


 174       // If step is pending for popframe then it may not be
 175       // a repeat step. The new_bci and method_id is same as current_bci
 176       // and current method_id after pop and step for recursive calls.
 177       // This has been handled by clearing the location
 178       _single_stepping_posted = true;
 179       break;
 180     default:
 181       assert(false, "invalid event value passed");
 182       break;
 183     }
 184     return;
 185   }
 186 
 187   set_current_location(new_method_id, new_bci);
 188   _breakpoint_posted = false;
 189   _single_stepping_posted = false;
 190 }
 191 
 192 
 193 JvmtiFramePops* JvmtiEnvThreadState::get_frame_pops() {
 194 #ifdef ASSERT
 195   Thread *current = Thread::current();
 196 #endif
 197   assert(get_thread() == current || current == get_thread()->active_handshaker(),
 198          "frame pop data only accessible from same thread or direct handshake");
 199   if (_frame_pops == NULL) {
 200     _frame_pops = new JvmtiFramePops();
 201     assert(_frame_pops != NULL, "_frame_pops != NULL");
 202   }
 203   return _frame_pops;
 204 }
 205 
 206 
 207 bool JvmtiEnvThreadState::has_frame_pops() {
 208   return _frame_pops == NULL? false : (_frame_pops->length() > 0);
 209 }
 210 
 211 void JvmtiEnvThreadState::set_frame_pop(int frame_number) {
 212 #ifdef ASSERT
 213   Thread *current = Thread::current();
 214 #endif
 215   assert(get_thread() == current || current == get_thread()->active_handshaker(),
 216          "frame pop data only accessible from same thread or direct handshake");
 217   JvmtiFramePop fpop(frame_number);
 218   JvmtiEventController::set_frame_pop(this, fpop);
 219 }
 220 
 221 
 222 void JvmtiEnvThreadState::clear_frame_pop(int frame_number) {
 223 #ifdef ASSERT
 224   Thread *current = Thread::current();
 225 #endif
 226   assert(get_thread() == current || current == get_thread()->active_handshaker(),
 227          "frame pop data only accessible from same thread or direct handshake");
 228   JvmtiFramePop fpop(frame_number);
 229   JvmtiEventController::clear_frame_pop(this, fpop);
 230 }
 231 
 232 
 233 void JvmtiEnvThreadState::clear_to_frame_pop(int frame_number)  {
 234 #ifdef ASSERT
 235   Thread *current = Thread::current();
 236 #endif
 237   assert(get_thread() == current || current == get_thread()->active_handshaker(),
 238          "frame pop data only accessible from same thread or direct handshake");
 239   JvmtiFramePop fpop(frame_number);
 240   JvmtiEventController::clear_to_frame_pop(this, fpop);
 241 }
 242 
 243 
 244 bool JvmtiEnvThreadState::is_frame_pop(int cur_frame_number) {
 245 #ifdef ASSERT
 246   Thread *current = Thread::current();
 247 #endif
 248   assert(get_thread() == current || current == get_thread()->active_handshaker(),
 249          "frame pop data only accessible from same thread or direct handshake");
 250   if (!get_thread()->is_interp_only_mode() || _frame_pops == NULL) {
 251     return false;
 252   }
 253   JvmtiFramePop fp(cur_frame_number);
 254   return get_frame_pops()->contains(fp);
 255 }
 256 
 257 
 258 class GetCurrentLocationClosure : public HandshakeClosure {
 259  private:

 260    jmethodID _method_id;
 261    int _bci;
 262 
 263  public:
 264   GetCurrentLocationClosure()
 265     : HandshakeClosure("GetCurrentLocation"),
 266       _method_id(NULL),
 267       _bci(0) {}
 268   void do_thread(Thread *target) {
 269     JavaThread *jt = (JavaThread *)target;
 270     ResourceMark rmark; // jt != Thread::current()
 271     RegisterMap rm(jt, false);
 272     // There can be a race condition between a VM_Operation reaching a safepoint
 273     // and the target thread exiting from Java execution.
 274     // We must recheck the last Java frame still exists.
 275     if (!jt->is_exiting() && jt->has_last_Java_frame()) {
 276       javaVFrame* vf = jt->last_java_vframe(&rm);
 277       assert(vf != NULL, "must have last java frame");
 278       Method* method = vf->method();
 279       _method_id = method->jmethod_id();
 280       _bci = vf->bci();
 281     } else {
 282       // Clear current location as the target thread has no Java frames anymore.
 283       _method_id = (jmethodID)NULL;
 284       _bci = 0;
 285     }
 286   }
 287   void get_current_location(jmethodID *method_id, int *bci) {
 288     *method_id = _method_id;
 289     *bci = _bci;
 290   }
 291 };
 292 
 293 void JvmtiEnvThreadState::reset_current_location(jvmtiEvent event_type, bool enabled) {
 294   assert(event_type == JVMTI_EVENT_SINGLE_STEP || event_type == JVMTI_EVENT_BREAKPOINT,
 295          "must be single-step or breakpoint event");
 296 


 305 
 306   // If single-stepping is enabled, set the current location to the
 307   // current method and bcp. This covers the following type of case,
 308   // e.g., the debugger stepi command:
 309   // - bytecode single stepped
 310   // - SINGLE_STEP event posted and SINGLE_STEP event disabled
 311   // - SINGLE_STEP event reenabled
 312   // - bytecode rewritten to fast version
 313 
 314   // If breakpoint event is disabled, clear current location only if
 315   // single-stepping is not enabled.  Otherwise, keep the thread location
 316   // to detect any duplicate events.
 317 
 318   if (enabled) {
 319     // If enabling breakpoint, no need to reset.
 320     // Can't do anything if empty stack.
 321     if (event_type == JVMTI_EVENT_SINGLE_STEP && _thread->has_last_Java_frame()) {
 322       jmethodID method_id;
 323       int bci;
 324       // The java thread stack may not be walkable for a running thread
 325       // so get current location with direct handshake.
 326       GetCurrentLocationClosure op;
 327       Thread *current = Thread::current();
 328       if ((current == _thread) || (_thread->active_handshaker() == current)) {
 329         op.do_thread(_thread);
 330       } else {
 331         Handshake::execute_direct(&op, _thread);
 332       }
 333       op.get_current_location(&method_id, &bci);
 334       set_current_location(method_id, bci);
 335     }
 336   } else if (event_type == JVMTI_EVENT_SINGLE_STEP || !is_enabled(JVMTI_EVENT_SINGLE_STEP)) {
 337     // If this is to disable breakpoint, also check if single-step is not enabled
 338     clear_current_location();
 339   }
 340 }
< prev index next >