src/share/vm/prims/jvmtiImpl.cpp

Print this page
rev 4773 : 8005849: JEP 167: Event-Based JVM Tracing
Reviewed-by: acorn, coleenp, sla
Contributed-by: Karen Kinnear <karen.kinnear@oracle.com>, Bengt Rutisson <bengt.rutisson@oracle.com>, Calvin Cheung <calvin.cheung@oracle.com>, Erik Gahlin <erik.gahlin@oracle.com>, Erik Helin <erik.helin@oracle.com>, Jesper Wilhelmsson <jesper.wilhelmsson@oracle.com>, Keith McGuigan <keith.mcguigan@oracle.com>, Mattias Tobiasson <mattias.tobiasson@oracle.com>, Markus Gronlund <markus.gronlund@oracle.com>, Mikael Auno <mikael.auno@oracle.com>, Nils Eliasson <nils.eliasson@oracle.com>, Nils Loodin <nils.loodin@oracle.com>, Rickard Backman <rickard.backman@oracle.com>, Staffan Larsen <staffan.larsen@oracle.com>, Stefan Karlsson <stefan.karlsson@oracle.com>, Yekaterina Kantserova <yekaterina.kantserova@oracle.com>


 343 
 344   tty->print("Breakpoint(%s,%s,%d,%p)",class_name, method_name, _bci, getBcp());
 345 #endif
 346 }
 347 
 348 
 349 //
 350 // class VM_ChangeBreakpoints
 351 //
 352 // Modify the Breakpoints data structure at a safepoint
 353 //
 354 
 355 void VM_ChangeBreakpoints::doit() {
 356   switch (_operation) {
 357   case SET_BREAKPOINT:
 358     _breakpoints->set_at_safepoint(*_bp);
 359     break;
 360   case CLEAR_BREAKPOINT:
 361     _breakpoints->clear_at_safepoint(*_bp);
 362     break;
 363   case CLEAR_ALL_BREAKPOINT:
 364     _breakpoints->clearall_at_safepoint();
 365     break;
 366   default:
 367     assert(false, "Unknown operation");
 368   }
 369 }
 370 
 371 void VM_ChangeBreakpoints::oops_do(OopClosure* f) {
 372   // This operation keeps breakpoints alive
 373   if (_breakpoints != NULL) {
 374     _breakpoints->oops_do(f);
 375   }
 376   if (_bp != NULL) {
 377     _bp->oops_do(f);
 378   }
 379 }
 380 
 381 //
 382 // class JvmtiBreakpoints
 383 //
 384 // a JVMTI internal collection of JvmtiBreakpoint
 385 //
 386 
 387 JvmtiBreakpoints::JvmtiBreakpoints(void listener_fun(void *,address *)) {
 388   _bps.initialize(this,listener_fun);
 389 }
 390 
 391 JvmtiBreakpoints:: ~JvmtiBreakpoints() {}
 392 
 393 void  JvmtiBreakpoints::oops_do(OopClosure* f) {
 394   _bps.oops_do(f);
 395 }


 416 void JvmtiBreakpoints::set_at_safepoint(JvmtiBreakpoint& bp) {
 417   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
 418 
 419   int i = _bps.find(bp);
 420   if (i == -1) {
 421     _bps.append(bp);
 422     bp.set();
 423   }
 424 }
 425 
 426 void JvmtiBreakpoints::clear_at_safepoint(JvmtiBreakpoint& bp) {
 427   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
 428 
 429   int i = _bps.find(bp);
 430   if (i != -1) {
 431     _bps.remove(i);
 432     bp.clear();
 433   }
 434 }
 435 
 436 void JvmtiBreakpoints::clearall_at_safepoint() {
 437   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
 438 
 439   int len = _bps.length();
 440   for (int i=0; i<len; i++) {
 441     _bps.at(i).clear();
 442   }
 443   _bps.clear();
 444 }
 445 
 446 int JvmtiBreakpoints::length() { return _bps.length(); }
 447 
 448 int JvmtiBreakpoints::set(JvmtiBreakpoint& bp) {
 449   if ( _bps.find(bp) != -1) {
 450      return JVMTI_ERROR_DUPLICATE;
 451   }
 452   VM_ChangeBreakpoints set_breakpoint(this,VM_ChangeBreakpoints::SET_BREAKPOINT, &bp);
 453   VMThread::execute(&set_breakpoint);
 454   return JVMTI_ERROR_NONE;
 455 }
 456 
 457 int JvmtiBreakpoints::clear(JvmtiBreakpoint& bp) {
 458   if ( _bps.find(bp) == -1) {
 459      return JVMTI_ERROR_NOT_FOUND;
 460   }
 461 
 462   VM_ChangeBreakpoints clear_breakpoint(this,VM_ChangeBreakpoints::CLEAR_BREAKPOINT, &bp);
 463   VMThread::execute(&clear_breakpoint);
 464   return JVMTI_ERROR_NONE;
 465 }
 466 
 467 void JvmtiBreakpoints::clearall_in_class_at_safepoint(Klass* klass) {
 468   bool changed = true;
 469   // We are going to run thru the list of bkpts
 470   // and delete some.  This deletion probably alters
 471   // the list in some implementation defined way such
 472   // that when we delete entry i, the next entry might
 473   // no longer be at i+1.  To be safe, each time we delete
 474   // an entry, we'll just start again from the beginning.
 475   // We'll stop when we make a pass thru the whole list without
 476   // deleting anything.
 477   while (changed) {
 478     int len = _bps.length();
 479     changed = false;
 480     for (int i = 0; i < len; i++) {
 481       JvmtiBreakpoint& bp = _bps.at(i);
 482       if (bp.method()->method_holder() == klass) {
 483         bp.clear();
 484         _bps.remove(i);
 485         // This changed 'i' so we have to start over.
 486         changed = true;
 487         break;
 488       }
 489     }
 490   }
 491 }
 492 
 493 void JvmtiBreakpoints::clearall() {
 494   VM_ChangeBreakpoints clearall_breakpoint(this,VM_ChangeBreakpoints::CLEAR_ALL_BREAKPOINT);
 495   VMThread::execute(&clearall_breakpoint);
 496 }
 497 
 498 //
 499 // class JvmtiCurrentBreakpoints
 500 //
 501 
 502 JvmtiBreakpoints *JvmtiCurrentBreakpoints::_jvmti_breakpoints  = NULL;
 503 address *         JvmtiCurrentBreakpoints::_breakpoint_list    = NULL;
 504 
 505 
 506 JvmtiBreakpoints& JvmtiCurrentBreakpoints::get_jvmti_breakpoints() {
 507   if (_jvmti_breakpoints != NULL) return (*_jvmti_breakpoints);
 508   _jvmti_breakpoints = new JvmtiBreakpoints(listener_fun);
 509   assert(_jvmti_breakpoints != NULL, "_jvmti_breakpoints != NULL");
 510   return (*_jvmti_breakpoints);
 511 }
 512 
 513 void  JvmtiCurrentBreakpoints::listener_fun(void *this_obj, address *cache) {
 514   JvmtiBreakpoints *this_jvmti = (JvmtiBreakpoints *) this_obj;
 515   assert(this_jvmti != NULL, "this_jvmti != NULL");
 516 
 517   debug_only(int n = this_jvmti->length(););




 343 
 344   tty->print("Breakpoint(%s,%s,%d,%p)",class_name, method_name, _bci, getBcp());
 345 #endif
 346 }
 347 
 348 
 349 //
 350 // class VM_ChangeBreakpoints
 351 //
 352 // Modify the Breakpoints data structure at a safepoint
 353 //
 354 
 355 void VM_ChangeBreakpoints::doit() {
 356   switch (_operation) {
 357   case SET_BREAKPOINT:
 358     _breakpoints->set_at_safepoint(*_bp);
 359     break;
 360   case CLEAR_BREAKPOINT:
 361     _breakpoints->clear_at_safepoint(*_bp);
 362     break;



 363   default:
 364     assert(false, "Unknown operation");
 365   }
 366 }
 367 
 368 void VM_ChangeBreakpoints::oops_do(OopClosure* f) {
 369   // The JvmtiBreakpoints in _breakpoints will be visited via
 370   // JvmtiExport::oops_do.


 371   if (_bp != NULL) {
 372     _bp->oops_do(f);
 373   }
 374 }
 375 
 376 //
 377 // class JvmtiBreakpoints
 378 //
 379 // a JVMTI internal collection of JvmtiBreakpoint
 380 //
 381 
 382 JvmtiBreakpoints::JvmtiBreakpoints(void listener_fun(void *,address *)) {
 383   _bps.initialize(this,listener_fun);
 384 }
 385 
 386 JvmtiBreakpoints:: ~JvmtiBreakpoints() {}
 387 
 388 void  JvmtiBreakpoints::oops_do(OopClosure* f) {
 389   _bps.oops_do(f);
 390 }


 411 void JvmtiBreakpoints::set_at_safepoint(JvmtiBreakpoint& bp) {
 412   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
 413 
 414   int i = _bps.find(bp);
 415   if (i == -1) {
 416     _bps.append(bp);
 417     bp.set();
 418   }
 419 }
 420 
 421 void JvmtiBreakpoints::clear_at_safepoint(JvmtiBreakpoint& bp) {
 422   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
 423 
 424   int i = _bps.find(bp);
 425   if (i != -1) {
 426     _bps.remove(i);
 427     bp.clear();
 428   }
 429 }
 430 










 431 int JvmtiBreakpoints::length() { return _bps.length(); }
 432 
 433 int JvmtiBreakpoints::set(JvmtiBreakpoint& bp) {
 434   if ( _bps.find(bp) != -1) {
 435      return JVMTI_ERROR_DUPLICATE;
 436   }
 437   VM_ChangeBreakpoints set_breakpoint(VM_ChangeBreakpoints::SET_BREAKPOINT, &bp);
 438   VMThread::execute(&set_breakpoint);
 439   return JVMTI_ERROR_NONE;
 440 }
 441 
 442 int JvmtiBreakpoints::clear(JvmtiBreakpoint& bp) {
 443   if ( _bps.find(bp) == -1) {
 444      return JVMTI_ERROR_NOT_FOUND;
 445   }
 446 
 447   VM_ChangeBreakpoints clear_breakpoint(VM_ChangeBreakpoints::CLEAR_BREAKPOINT, &bp);
 448   VMThread::execute(&clear_breakpoint);
 449   return JVMTI_ERROR_NONE;
 450 }
 451 
 452 void JvmtiBreakpoints::clearall_in_class_at_safepoint(Klass* klass) {
 453   bool changed = true;
 454   // We are going to run thru the list of bkpts
 455   // and delete some.  This deletion probably alters
 456   // the list in some implementation defined way such
 457   // that when we delete entry i, the next entry might
 458   // no longer be at i+1.  To be safe, each time we delete
 459   // an entry, we'll just start again from the beginning.
 460   // We'll stop when we make a pass thru the whole list without
 461   // deleting anything.
 462   while (changed) {
 463     int len = _bps.length();
 464     changed = false;
 465     for (int i = 0; i < len; i++) {
 466       JvmtiBreakpoint& bp = _bps.at(i);
 467       if (bp.method()->method_holder() == klass) {
 468         bp.clear();
 469         _bps.remove(i);
 470         // This changed 'i' so we have to start over.
 471         changed = true;
 472         break;
 473       }
 474     }
 475   }
 476 }
 477 





 478 //
 479 // class JvmtiCurrentBreakpoints
 480 //
 481 
 482 JvmtiBreakpoints *JvmtiCurrentBreakpoints::_jvmti_breakpoints  = NULL;
 483 address *         JvmtiCurrentBreakpoints::_breakpoint_list    = NULL;
 484 
 485 
 486 JvmtiBreakpoints& JvmtiCurrentBreakpoints::get_jvmti_breakpoints() {
 487   if (_jvmti_breakpoints != NULL) return (*_jvmti_breakpoints);
 488   _jvmti_breakpoints = new JvmtiBreakpoints(listener_fun);
 489   assert(_jvmti_breakpoints != NULL, "_jvmti_breakpoints != NULL");
 490   return (*_jvmti_breakpoints);
 491 }
 492 
 493 void  JvmtiCurrentBreakpoints::listener_fun(void *this_obj, address *cache) {
 494   JvmtiBreakpoints *this_jvmti = (JvmtiBreakpoints *) this_obj;
 495   assert(this_jvmti != NULL, "this_jvmti != NULL");
 496 
 497   debug_only(int n = this_jvmti->length(););