< prev index next >

src/hotspot/share/prims/jvmtiEnvBase.cpp

Print this page
rev 59077 : 8153224.v2.09b.patch combined with 8153224.v2.10.patch; merge with jdk-15+21.
rev 59078 : eosterlund v2.10 CR: reorganize deflate_monitor_using_JT() to use "early exit" style; dcubed - clarify/fix/rearrange a few comments in deflate_monitor_using_JT(); eosterlund v2.10 CR: simplify install_displaced_markword_in_object() and save_om_ptr(); save_om_ptr()'s call to install_displaced_markword_in_object() can race with the deflater thread's clearing of the object field so handle that; fold 8153224.OMHandle_experiment into 8153224.v2.11.patch; merge with jdk-15+21.


 636 
 637         // see if owner of the monitor is our object
 638         if (mi->owner() != NULL && mi->owner() == hobj()) {
 639           ret++;
 640         }
 641       }
 642     }
 643   }
 644   return ret;
 645 }
 646 
 647 
 648 
 649 jvmtiError
 650 JvmtiEnvBase::get_current_contended_monitor(JavaThread *java_thread, jobject *monitor_ptr) {
 651   JavaThread *current_jt = JavaThread::current();
 652   assert(current_jt == java_thread ||
 653          current_jt == java_thread->active_handshaker(),
 654          "call by myself or at direct handshake");
 655   oop obj = NULL;



 656   ObjectMonitor *mon = java_thread->current_waiting_monitor();
 657   if (mon == NULL) {
 658     // thread is not doing an Object.wait() call
 659     mon = java_thread->current_pending_monitor();
 660     if (mon != NULL) {
 661       // The thread is trying to enter() an ObjectMonitor.
 662       obj = (oop)mon->object();
 663       assert(obj != NULL, "ObjectMonitor should have a valid object!");
 664     }
 665     // implied else: no contended ObjectMonitor
 666   } else {
 667     // thread is doing an Object.wait() call
 668     obj = (oop)mon->object();
 669     assert(obj != NULL, "Object.wait() should have an object");
 670   }
 671 
 672   if (obj == NULL) {
 673     *monitor_ptr = NULL;
 674   } else {
 675     HandleMark hm;


 713   err = jmc.error();
 714 
 715   return err;
 716 }
 717 
 718 // Save JNI local handles for any objects that this frame owns.
 719 jvmtiError
 720 JvmtiEnvBase::get_locked_objects_in_frame(JavaThread* calling_thread, JavaThread* java_thread,
 721                                  javaVFrame *jvf, GrowableArray<jvmtiMonitorStackDepthInfo*>* owned_monitors_list, jint stack_depth) {
 722   jvmtiError err = JVMTI_ERROR_NONE;
 723   ResourceMark rm;
 724 
 725   GrowableArray<MonitorInfo*>* mons = jvf->monitors();
 726   if (mons->is_empty()) {
 727     return err;  // this javaVFrame holds no monitors
 728   }
 729 
 730   HandleMark hm;
 731   oop wait_obj = NULL;
 732   {
 733     // save object of current wait() call (if any) for later comparison



 734     ObjectMonitor *mon = java_thread->current_waiting_monitor();
 735     if (mon != NULL) {
 736       wait_obj = (oop)mon->object();
 737     }
 738   }
 739   oop pending_obj = NULL;
 740   {
 741     // save object of current enter() call (if any) for later comparison



 742     ObjectMonitor *mon = java_thread->current_pending_monitor();
 743     if (mon != NULL) {
 744       pending_obj = (oop)mon->object();
 745     }
 746   }
 747 
 748   for (int i = 0; i < mons->length(); i++) {
 749     MonitorInfo *mi = mons->at(i);
 750 
 751     if (mi->owner_is_scalar_replaced()) continue;
 752 
 753     oop obj = mi->owner();
 754     if (obj == NULL) {
 755       // this monitor doesn't have an owning object so skip it
 756       continue;
 757     }
 758 
 759     if (wait_obj == obj) {
 760       // the thread is waiting on this monitor so it isn't really owned
 761       continue;




 636 
 637         // see if owner of the monitor is our object
 638         if (mi->owner() != NULL && mi->owner() == hobj()) {
 639           ret++;
 640         }
 641       }
 642     }
 643   }
 644   return ret;
 645 }
 646 
 647 
 648 
 649 jvmtiError
 650 JvmtiEnvBase::get_current_contended_monitor(JavaThread *java_thread, jobject *monitor_ptr) {
 651   JavaThread *current_jt = JavaThread::current();
 652   assert(current_jt == java_thread ||
 653          current_jt == java_thread->active_handshaker(),
 654          "call by myself or at direct handshake");
 655   oop obj = NULL;
 656   // The ObjectMonitor* can't be async deflated since we are either
 657   // at a safepoint or the calling thread is operating on itself so
 658   // it cannot leave the underlying wait()/enter() call.
 659   ObjectMonitor *mon = java_thread->current_waiting_monitor();
 660   if (mon == NULL) {
 661     // thread is not doing an Object.wait() call
 662     mon = java_thread->current_pending_monitor();
 663     if (mon != NULL) {
 664       // The thread is trying to enter() an ObjectMonitor.
 665       obj = (oop)mon->object();
 666       assert(obj != NULL, "ObjectMonitor should have a valid object!");
 667     }
 668     // implied else: no contended ObjectMonitor
 669   } else {
 670     // thread is doing an Object.wait() call
 671     obj = (oop)mon->object();
 672     assert(obj != NULL, "Object.wait() should have an object");
 673   }
 674 
 675   if (obj == NULL) {
 676     *monitor_ptr = NULL;
 677   } else {
 678     HandleMark hm;


 716   err = jmc.error();
 717 
 718   return err;
 719 }
 720 
 721 // Save JNI local handles for any objects that this frame owns.
 722 jvmtiError
 723 JvmtiEnvBase::get_locked_objects_in_frame(JavaThread* calling_thread, JavaThread* java_thread,
 724                                  javaVFrame *jvf, GrowableArray<jvmtiMonitorStackDepthInfo*>* owned_monitors_list, jint stack_depth) {
 725   jvmtiError err = JVMTI_ERROR_NONE;
 726   ResourceMark rm;
 727 
 728   GrowableArray<MonitorInfo*>* mons = jvf->monitors();
 729   if (mons->is_empty()) {
 730     return err;  // this javaVFrame holds no monitors
 731   }
 732 
 733   HandleMark hm;
 734   oop wait_obj = NULL;
 735   {
 736     // The ObjectMonitor* can't be async deflated since we are either
 737     // at a safepoint or the calling thread is operating on itself so
 738     // it cannot leave the underlying wait() call.
 739     // Save object of current wait() call (if any) for later comparison.
 740     ObjectMonitor *mon = java_thread->current_waiting_monitor();
 741     if (mon != NULL) {
 742       wait_obj = (oop)mon->object();
 743     }
 744   }
 745   oop pending_obj = NULL;
 746   {
 747     // The ObjectMonitor* can't be async deflated since we are either
 748     // at a safepoint or the calling thread is operating on itself so
 749     // it cannot leave the underlying enter() call.
 750     // Save object of current enter() call (if any) for later comparison.
 751     ObjectMonitor *mon = java_thread->current_pending_monitor();
 752     if (mon != NULL) {
 753       pending_obj = (oop)mon->object();
 754     }
 755   }
 756 
 757   for (int i = 0; i < mons->length(); i++) {
 758     MonitorInfo *mi = mons->at(i);
 759 
 760     if (mi->owner_is_scalar_replaced()) continue;
 761 
 762     oop obj = mi->owner();
 763     if (obj == NULL) {
 764       // this monitor doesn't have an owning object so skip it
 765       continue;
 766     }
 767 
 768     if (wait_obj == obj) {
 769       // the thread is waiting on this monitor so it isn't really owned
 770       continue;


< prev index next >