< prev index next >

src/hotspot/share/prims/jvmtiEnvBase.cpp

Print this page

 971     RegisterMap  reg_map(java_thread,
 972                          RegisterMap::UpdateMap::include,
 973                          RegisterMap::ProcessFrames::include,
 974                          RegisterMap::WalkContinuation::skip);
 975 
 976     int depth = 0;
 977     for (javaVFrame *jvf = get_cthread_last_java_vframe(java_thread, &reg_map);
 978          jvf != nullptr; jvf = jvf->java_sender()) {
 979       if (MaxJavaStackTraceDepth == 0 || depth++ < MaxJavaStackTraceDepth) {  // check for stack too deep
 980         // add locked objects for this frame into list
 981         err = get_locked_objects_in_frame(calling_thread, java_thread, jvf, owned_monitors_list, depth-1);
 982         if (err != JVMTI_ERROR_NONE) {
 983           return err;
 984         }
 985       }
 986     }
 987   }
 988 
 989   // Get off stack monitors. (e.g. acquired via jni MonitorEnter).
 990   JvmtiMonitorClosure jmc(calling_thread, owned_monitors_list, this);
 991   ObjectSynchronizer::monitors_iterate(&jmc, java_thread);
 992   err = jmc.error();
 993 
 994   return err;
 995 }
 996 
 997 jvmtiError
 998 JvmtiEnvBase::get_owned_monitors(JavaThread* calling_thread, JavaThread* java_thread, javaVFrame* jvf,
 999                                  GrowableArray<jvmtiMonitorStackDepthInfo*> *owned_monitors_list) {
1000   jvmtiError err = JVMTI_ERROR_NONE;
1001   Thread *current_thread = Thread::current();
1002   assert(java_thread->is_handshake_safe_for(current_thread),
1003          "call by myself or at handshake");
1004 
1005   int depth = 0;
1006   for ( ; jvf != nullptr; jvf = jvf->java_sender()) {
1007     if (MaxJavaStackTraceDepth == 0 || depth++ < MaxJavaStackTraceDepth) {  // check for stack too deep
1008       // Add locked objects for this frame into list.
1009       err = get_locked_objects_in_frame(calling_thread, java_thread, jvf, owned_monitors_list, depth - 1);
1010       if (err != JVMTI_ERROR_NONE) {
1011         return err;
1012       }
1013     }
1014   }
1015 
1016   // Get off stack monitors. (e.g. acquired via jni MonitorEnter).
1017   JvmtiMonitorClosure jmc(calling_thread, owned_monitors_list, this);
1018   ObjectSynchronizer::monitors_iterate(&jmc, java_thread);
1019   err = jmc.error();
1020 
1021   return err;
1022 }
1023 
1024 // Save JNI local handles for any objects that this frame owns.
1025 jvmtiError
1026 JvmtiEnvBase::get_locked_objects_in_frame(JavaThread* calling_thread, JavaThread* java_thread,
1027                                  javaVFrame *jvf, GrowableArray<jvmtiMonitorStackDepthInfo*>* owned_monitors_list, jint stack_depth) {
1028   jvmtiError err = JVMTI_ERROR_NONE;
1029   Thread* current_thread = Thread::current();
1030   ResourceMark rm(current_thread);
1031   HandleMark   hm(current_thread);
1032 
1033   GrowableArray<MonitorInfo*>* mons = jvf->monitors();
1034   if (mons->is_empty()) {
1035     return err;  // this javaVFrame holds no monitors
1036   }
1037 
1038   oop wait_obj = nullptr;

2161   // (see call_VM_base() in assembler_<cpu>.cpp).
2162 
2163   _state->set_earlyret_pending();
2164   _state->set_earlyret_oop(ret_ob_h());
2165   _state->set_earlyret_value(_value, _tos);
2166 
2167   // Set pending step flag for this early return.
2168   // It is cleared when next step event is posted.
2169   _state->set_pending_step_for_earlyret();
2170 }
2171 
2172 void
2173 JvmtiMonitorClosure::do_monitor(ObjectMonitor* mon) {
2174   if ( _error != JVMTI_ERROR_NONE) {
2175     // Error occurred in previous iteration so no need to add
2176     // to the list.
2177     return;
2178   }
2179   // Filter out on stack monitors collected during stack walk.
2180   oop obj = mon->object();







2181   bool found = false;
2182   for (int j = 0; j < _owned_monitors_list->length(); j++) {
2183     jobject jobj = ((jvmtiMonitorStackDepthInfo*)_owned_monitors_list->at(j))->monitor;
2184     oop check = JNIHandles::resolve(jobj);
2185     if (check == obj) {
2186       // On stack monitor already collected during the stack walk.
2187       found = true;
2188       break;
2189     }
2190   }
2191   if (found == false) {
2192     // This is off stack monitor (e.g. acquired via jni MonitorEnter).
2193     jvmtiError err;
2194     jvmtiMonitorStackDepthInfo *jmsdi;
2195     err = _env->allocate(sizeof(jvmtiMonitorStackDepthInfo), (unsigned char **)&jmsdi);
2196     if (err != JVMTI_ERROR_NONE) {
2197       _error = err;
2198       return;
2199     }
2200     Handle hobj(Thread::current(), obj);

 971     RegisterMap  reg_map(java_thread,
 972                          RegisterMap::UpdateMap::include,
 973                          RegisterMap::ProcessFrames::include,
 974                          RegisterMap::WalkContinuation::skip);
 975 
 976     int depth = 0;
 977     for (javaVFrame *jvf = get_cthread_last_java_vframe(java_thread, &reg_map);
 978          jvf != nullptr; jvf = jvf->java_sender()) {
 979       if (MaxJavaStackTraceDepth == 0 || depth++ < MaxJavaStackTraceDepth) {  // check for stack too deep
 980         // add locked objects for this frame into list
 981         err = get_locked_objects_in_frame(calling_thread, java_thread, jvf, owned_monitors_list, depth-1);
 982         if (err != JVMTI_ERROR_NONE) {
 983           return err;
 984         }
 985       }
 986     }
 987   }
 988 
 989   // Get off stack monitors. (e.g. acquired via jni MonitorEnter).
 990   JvmtiMonitorClosure jmc(calling_thread, owned_monitors_list, this);
 991   ObjectSynchronizer::owned_monitors_iterate(&jmc, java_thread);
 992   err = jmc.error();
 993 
 994   return err;
 995 }
 996 
 997 jvmtiError
 998 JvmtiEnvBase::get_owned_monitors(JavaThread* calling_thread, JavaThread* java_thread, javaVFrame* jvf,
 999                                  GrowableArray<jvmtiMonitorStackDepthInfo*> *owned_monitors_list) {
1000   jvmtiError err = JVMTI_ERROR_NONE;
1001   Thread *current_thread = Thread::current();
1002   assert(java_thread->is_handshake_safe_for(current_thread),
1003          "call by myself or at handshake");
1004 
1005   int depth = 0;
1006   for ( ; jvf != nullptr; jvf = jvf->java_sender()) {
1007     if (MaxJavaStackTraceDepth == 0 || depth++ < MaxJavaStackTraceDepth) {  // check for stack too deep
1008       // Add locked objects for this frame into list.
1009       err = get_locked_objects_in_frame(calling_thread, java_thread, jvf, owned_monitors_list, depth - 1);
1010       if (err != JVMTI_ERROR_NONE) {
1011         return err;
1012       }
1013     }
1014   }
1015 
1016   // Get off stack monitors. (e.g. acquired via jni MonitorEnter).
1017   JvmtiMonitorClosure jmc(calling_thread, owned_monitors_list, this);
1018   ObjectSynchronizer::owned_monitors_iterate(&jmc, java_thread);
1019   err = jmc.error();
1020 
1021   return err;
1022 }
1023 
1024 // Save JNI local handles for any objects that this frame owns.
1025 jvmtiError
1026 JvmtiEnvBase::get_locked_objects_in_frame(JavaThread* calling_thread, JavaThread* java_thread,
1027                                  javaVFrame *jvf, GrowableArray<jvmtiMonitorStackDepthInfo*>* owned_monitors_list, jint stack_depth) {
1028   jvmtiError err = JVMTI_ERROR_NONE;
1029   Thread* current_thread = Thread::current();
1030   ResourceMark rm(current_thread);
1031   HandleMark   hm(current_thread);
1032 
1033   GrowableArray<MonitorInfo*>* mons = jvf->monitors();
1034   if (mons->is_empty()) {
1035     return err;  // this javaVFrame holds no monitors
1036   }
1037 
1038   oop wait_obj = nullptr;

2161   // (see call_VM_base() in assembler_<cpu>.cpp).
2162 
2163   _state->set_earlyret_pending();
2164   _state->set_earlyret_oop(ret_ob_h());
2165   _state->set_earlyret_value(_value, _tos);
2166 
2167   // Set pending step flag for this early return.
2168   // It is cleared when next step event is posted.
2169   _state->set_pending_step_for_earlyret();
2170 }
2171 
2172 void
2173 JvmtiMonitorClosure::do_monitor(ObjectMonitor* mon) {
2174   if ( _error != JVMTI_ERROR_NONE) {
2175     // Error occurred in previous iteration so no need to add
2176     // to the list.
2177     return;
2178   }
2179   // Filter out on stack monitors collected during stack walk.
2180   oop obj = mon->object();
2181 
2182   if (obj == nullptr) {
2183     // This can happen if JNI code drops all references to the
2184     // owning object.
2185     return;
2186   }
2187 
2188   bool found = false;
2189   for (int j = 0; j < _owned_monitors_list->length(); j++) {
2190     jobject jobj = ((jvmtiMonitorStackDepthInfo*)_owned_monitors_list->at(j))->monitor;
2191     oop check = JNIHandles::resolve(jobj);
2192     if (check == obj) {
2193       // On stack monitor already collected during the stack walk.
2194       found = true;
2195       break;
2196     }
2197   }
2198   if (found == false) {
2199     // This is off stack monitor (e.g. acquired via jni MonitorEnter).
2200     jvmtiError err;
2201     jvmtiMonitorStackDepthInfo *jmsdi;
2202     err = _env->allocate(sizeof(jvmtiMonitorStackDepthInfo), (unsigned char **)&jmsdi);
2203     if (err != JVMTI_ERROR_NONE) {
2204       _error = err;
2205       return;
2206     }
2207     Handle hobj(Thread::current(), obj);
< prev index next >