< prev index next >

src/hotspot/share/prims/jvmtiEnvBase.cpp

Print this page
rev 59864 : 8249192: MonitorInfo stores raw oops across safepoints
Summary: Change raw oops in MonitorInfo to Handles and update Resource/HandleMarks.
Reviewed-by: sspitsyn, dholmes, coleenp, dcubed


 707           return err;
 708         }
 709       }
 710     }
 711   }
 712 
 713   // Get off stack monitors. (e.g. acquired via jni MonitorEnter).
 714   JvmtiMonitorClosure jmc(java_thread, calling_thread, owned_monitors_list, this);
 715   ObjectSynchronizer::monitors_iterate(&jmc);
 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();


1009         // the monitor.
1010         if (!at_safepoint && !owning_thread->is_thread_fully_suspended(true, &debug_bits)) {
1011           // Don't worry! This return of JVMTI_ERROR_THREAD_NOT_SUSPENDED
1012           // will not make it back to the JVM/TI agent. The error code will
1013           // get intercepted in JvmtiEnv::GetObjectMonitorUsage() which
1014           // will retry the call via a VM_GetObjectMonitorUsage VM op.
1015           return JVMTI_ERROR_THREAD_NOT_SUSPENDED;
1016         }
1017         HandleMark hm;
1018         Handle     th(current_thread, owning_thread->threadObj());
1019         ret.owner = (jthread)jni_reference(calling_thread, th);
1020       }
1021       // implied else: no owner
1022     } // ThreadsListHandle is destroyed here.
1023 
1024     if (owning_thread != NULL) {  // monitor is owned
1025       // The recursions field of a monitor does not reflect recursions
1026       // as lightweight locks before inflating the monitor are not included.
1027       // We have to count the number of recursive monitor entries the hard way.
1028       // We pass a handle to survive any GCs along the way.
1029       ResourceMark rm;
1030       ret.entry_count = count_locked_objects(owning_thread, hobj);
1031     }
1032     // implied else: entry_count == 0
1033   }
1034 
1035   jint nWant = 0, nWait = 0;
1036   if (mon != NULL) {
1037     // this object has a heavyweight monitor
1038     nWant = mon->contentions(); // # of threads contending for monitor
1039     nWait = mon->waiters();     // # of threads in Object.wait()
1040     ret.waiter_count = nWant + nWait;
1041     ret.notify_waiter_count = nWait;
1042   } else {
1043     // this object has a lightweight monitor
1044     ret.waiter_count = 0;
1045     ret.notify_waiter_count = 0;
1046   }
1047 
1048   // Allocate memory for heavyweight and lightweight monitor.
1049   jvmtiError err;




 707           return err;
 708         }
 709       }
 710     }
 711   }
 712 
 713   // Get off stack monitors. (e.g. acquired via jni MonitorEnter).
 714   JvmtiMonitorClosure jmc(java_thread, calling_thread, owned_monitors_list, this);
 715   ObjectSynchronizer::monitors_iterate(&jmc);
 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   HandleMark hm;
 728 
 729   GrowableArray<MonitorInfo*>* mons = jvf->monitors();
 730   if (mons->is_empty()) {
 731     return err;  // this javaVFrame holds no monitors
 732   }
 733 

 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();


1009         // the monitor.
1010         if (!at_safepoint && !owning_thread->is_thread_fully_suspended(true, &debug_bits)) {
1011           // Don't worry! This return of JVMTI_ERROR_THREAD_NOT_SUSPENDED
1012           // will not make it back to the JVM/TI agent. The error code will
1013           // get intercepted in JvmtiEnv::GetObjectMonitorUsage() which
1014           // will retry the call via a VM_GetObjectMonitorUsage VM op.
1015           return JVMTI_ERROR_THREAD_NOT_SUSPENDED;
1016         }
1017         HandleMark hm;
1018         Handle     th(current_thread, owning_thread->threadObj());
1019         ret.owner = (jthread)jni_reference(calling_thread, th);
1020       }
1021       // implied else: no owner
1022     } // ThreadsListHandle is destroyed here.
1023 
1024     if (owning_thread != NULL) {  // monitor is owned
1025       // The recursions field of a monitor does not reflect recursions
1026       // as lightweight locks before inflating the monitor are not included.
1027       // We have to count the number of recursive monitor entries the hard way.
1028       // We pass a handle to survive any GCs along the way.

1029       ret.entry_count = count_locked_objects(owning_thread, hobj);
1030     }
1031     // implied else: entry_count == 0
1032   }
1033 
1034   jint nWant = 0, nWait = 0;
1035   if (mon != NULL) {
1036     // this object has a heavyweight monitor
1037     nWant = mon->contentions(); // # of threads contending for monitor
1038     nWait = mon->waiters();     // # of threads in Object.wait()
1039     ret.waiter_count = nWant + nWait;
1040     ret.notify_waiter_count = nWait;
1041   } else {
1042     // this object has a lightweight monitor
1043     ret.waiter_count = 0;
1044     ret.notify_waiter_count = 0;
1045   }
1046 
1047   // Allocate memory for heavyweight and lightweight monitor.
1048   jvmtiError err;


< prev index next >