< prev index next >

src/hotspot/share/prims/jvmtiEnvBase.cpp

Print this page

 539 //
 540 // Threads
 541 //
 542 
 543 jthread *
 544 JvmtiEnvBase::new_jthreadArray(int length, Handle *handles) {
 545   if (length == 0) {
 546     return nullptr;
 547   }
 548 
 549   jthread* objArray = (jthread *) jvmtiMalloc(sizeof(jthread) * length);
 550   NULL_CHECK(objArray, nullptr);
 551 
 552   for (int i = 0; i < length; i++) {
 553     objArray[i] = (jthread)jni_reference(handles[i]);
 554   }
 555   return objArray;
 556 }
 557 
 558 jthreadGroup *
 559 JvmtiEnvBase::new_jthreadGroupArray(int length, objArrayHandle groups) {
 560   if (length == 0) {
 561     return nullptr;
 562   }
 563 
 564   jthreadGroup* objArray = (jthreadGroup *) jvmtiMalloc(sizeof(jthreadGroup) * length);
 565   NULL_CHECK(objArray, nullptr);
 566 
 567   for (int i = 0; i < length; i++) {
 568     objArray[i] = (jthreadGroup)JNIHandles::make_local(groups->obj_at(i));
 569   }
 570   return objArray;
 571 }
 572 
 573 // Return the vframe on the specified thread and depth, null if no such frame.
 574 // The thread and the oops in the returned vframe might not have been processed.
 575 javaVFrame*
 576 JvmtiEnvBase::jvf_for_thread_and_depth(JavaThread* java_thread, jint depth) {
 577   if (!java_thread->has_last_Java_frame()) {
 578     return nullptr;
 579   }

 844   jint count = 0;
 845   Handle *thread_objs = nullptr;
 846   ThreadsListEnumerator tle(current_thread, /* include_jvmti_agent_threads */ true);
 847   int nthreads = tle.num_threads();
 848   if (nthreads > 0) {
 849     thread_objs = NEW_RESOURCE_ARRAY_RETURN_NULL(Handle, nthreads);
 850     NULL_CHECK(thread_objs, JVMTI_ERROR_OUT_OF_MEMORY);
 851     for (int i = 0; i < nthreads; i++) {
 852       Handle thread = tle.get_threadObj(i);
 853       if (thread()->is_a(vmClasses::Thread_klass()) && java_lang_Thread::threadGroup(thread()) == group_hdl()) {
 854         thread_objs[count++] = thread;
 855       }
 856     }
 857   }
 858   *thread_objs_p = thread_objs;
 859   *count_ptr = count;
 860   return JVMTI_ERROR_NONE;
 861 }
 862 
 863 jvmtiError
 864 JvmtiEnvBase::get_subgroups(JavaThread* current_thread, Handle group_hdl, jint *count_ptr, objArrayHandle *group_objs_p) {
 865 
 866   // This call collects the strong and weak groups
 867   JavaThread* THREAD = current_thread;
 868   JvmtiJavaUpcallMark jjum(current_thread); // hide JVMTI events for Java upcall
 869   JavaValue result(T_OBJECT);
 870   JavaCalls::call_virtual(&result,
 871                           group_hdl,
 872                           vmClasses::ThreadGroup_klass(),
 873                           SymbolTable::new_permanent_symbol("subgroupsAsArray"),
 874                           vmSymbols::void_threadgroup_array_signature(),
 875                           THREAD);
 876   if (HAS_PENDING_EXCEPTION) {
 877     Symbol* ex_name = PENDING_EXCEPTION->klass()->name();
 878     CLEAR_PENDING_EXCEPTION;
 879     if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
 880       return JVMTI_ERROR_OUT_OF_MEMORY;
 881     } else {
 882       return JVMTI_ERROR_INTERNAL;
 883     }
 884   }
 885 
 886   assert(result.get_type() == T_OBJECT, "just checking");
 887   objArrayOop groups = (objArrayOop)result.get_oop();
 888 
 889   *count_ptr = groups == nullptr ? 0 : groups->length();
 890   *group_objs_p = objArrayHandle(current_thread, groups);
 891 
 892   return JVMTI_ERROR_NONE;
 893 }
 894 
 895 //
 896 // Object Monitor Information
 897 //
 898 
 899 //
 900 // Count the number of objects for a lightweight monitor. The hobj
 901 // parameter is object that owns the monitor so this routine will
 902 // count the number of times the same object was locked by frames
 903 // in java_thread.
 904 //
 905 jint
 906 JvmtiEnvBase::count_locked_objects(JavaThread *java_thread, Handle hobj) {
 907   jint ret = 0;
 908   if (!java_thread->has_last_Java_frame()) {
 909     return ret;  // no Java frames so no monitors
 910   }

2155   _collector.allocate_and_fill_stacks(_final_thread_count);
2156 }
2157 
2158 // Verifies that the top frame is a java frame in an expected state.
2159 // Deoptimizes frame if needed.
2160 // Checks that the frame method signature matches the return type (tos).
2161 // HandleMark must be defined in the caller only.
2162 // It is to keep a ret_ob_h handle alive after return to the caller.
2163 jvmtiError
2164 JvmtiEnvBase::check_top_frame(Thread* current_thread, JavaThread* java_thread,
2165                               jvalue value, TosState tos, Handle* ret_ob_h) {
2166   ResourceMark rm(current_thread);
2167 
2168   javaVFrame* jvf = jvf_for_thread_and_depth(java_thread, 0);
2169   NULL_CHECK(jvf, JVMTI_ERROR_NO_MORE_FRAMES);
2170 
2171   if (jvf->method()->is_native()) {
2172     return JVMTI_ERROR_OPAQUE_FRAME;
2173   }
2174 






2175   // If the frame is a compiled one, need to deoptimize it.
2176   if (jvf->is_compiled_frame()) {
2177     if (!jvf->fr().can_be_deoptimized()) {
2178       return JVMTI_ERROR_OPAQUE_FRAME;
2179     }
2180     Deoptimization::deoptimize_frame(java_thread, jvf->fr().id());
2181   }
2182 
2183   // Get information about method return type
2184   Symbol* signature = jvf->method()->signature();
2185 
2186   ResultTypeFinder rtf(signature);
2187   TosState fr_tos = as_TosState(rtf.type());
2188   if (fr_tos != tos) {
2189     if (tos != itos || (fr_tos != btos && fr_tos != ztos && fr_tos != ctos && fr_tos != stos)) {
2190       return JVMTI_ERROR_TYPE_MISMATCH;
2191     }
2192   }
2193 
2194   // Check that the jobject class matches the return type signature.

 539 //
 540 // Threads
 541 //
 542 
 543 jthread *
 544 JvmtiEnvBase::new_jthreadArray(int length, Handle *handles) {
 545   if (length == 0) {
 546     return nullptr;
 547   }
 548 
 549   jthread* objArray = (jthread *) jvmtiMalloc(sizeof(jthread) * length);
 550   NULL_CHECK(objArray, nullptr);
 551 
 552   for (int i = 0; i < length; i++) {
 553     objArray[i] = (jthread)jni_reference(handles[i]);
 554   }
 555   return objArray;
 556 }
 557 
 558 jthreadGroup *
 559 JvmtiEnvBase::new_jthreadGroupArray(int length, refArrayHandle groups) {
 560   if (length == 0) {
 561     return nullptr;
 562   }
 563 
 564   jthreadGroup* objArray = (jthreadGroup *) jvmtiMalloc(sizeof(jthreadGroup) * length);
 565   NULL_CHECK(objArray, nullptr);
 566 
 567   for (int i = 0; i < length; i++) {
 568     objArray[i] = (jthreadGroup)JNIHandles::make_local(groups->obj_at(i));
 569   }
 570   return objArray;
 571 }
 572 
 573 // Return the vframe on the specified thread and depth, null if no such frame.
 574 // The thread and the oops in the returned vframe might not have been processed.
 575 javaVFrame*
 576 JvmtiEnvBase::jvf_for_thread_and_depth(JavaThread* java_thread, jint depth) {
 577   if (!java_thread->has_last_Java_frame()) {
 578     return nullptr;
 579   }

 844   jint count = 0;
 845   Handle *thread_objs = nullptr;
 846   ThreadsListEnumerator tle(current_thread, /* include_jvmti_agent_threads */ true);
 847   int nthreads = tle.num_threads();
 848   if (nthreads > 0) {
 849     thread_objs = NEW_RESOURCE_ARRAY_RETURN_NULL(Handle, nthreads);
 850     NULL_CHECK(thread_objs, JVMTI_ERROR_OUT_OF_MEMORY);
 851     for (int i = 0; i < nthreads; i++) {
 852       Handle thread = tle.get_threadObj(i);
 853       if (thread()->is_a(vmClasses::Thread_klass()) && java_lang_Thread::threadGroup(thread()) == group_hdl()) {
 854         thread_objs[count++] = thread;
 855       }
 856     }
 857   }
 858   *thread_objs_p = thread_objs;
 859   *count_ptr = count;
 860   return JVMTI_ERROR_NONE;
 861 }
 862 
 863 jvmtiError
 864 JvmtiEnvBase::get_subgroups(JavaThread* current_thread, Handle group_hdl, jint *count_ptr, refArrayHandle *group_objs_p) {
 865 
 866   // This call collects the strong and weak groups
 867   JavaThread* THREAD = current_thread;
 868   JvmtiJavaUpcallMark jjum(current_thread); // hide JVMTI events for Java upcall
 869   JavaValue result(T_OBJECT);
 870   JavaCalls::call_virtual(&result,
 871                           group_hdl,
 872                           vmClasses::ThreadGroup_klass(),
 873                           SymbolTable::new_permanent_symbol("subgroupsAsArray"),
 874                           vmSymbols::void_threadgroup_array_signature(),
 875                           THREAD);
 876   if (HAS_PENDING_EXCEPTION) {
 877     Symbol* ex_name = PENDING_EXCEPTION->klass()->name();
 878     CLEAR_PENDING_EXCEPTION;
 879     if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
 880       return JVMTI_ERROR_OUT_OF_MEMORY;
 881     } else {
 882       return JVMTI_ERROR_INTERNAL;
 883     }
 884   }
 885 
 886   assert(result.get_type() == T_OBJECT, "just checking");
 887   refArrayOop groups = (refArrayOop)result.get_oop();
 888 
 889   *count_ptr = groups == nullptr ? 0 : groups->length();
 890   *group_objs_p = refArrayHandle(current_thread, groups);
 891 
 892   return JVMTI_ERROR_NONE;
 893 }
 894 
 895 //
 896 // Object Monitor Information
 897 //
 898 
 899 //
 900 // Count the number of objects for a lightweight monitor. The hobj
 901 // parameter is object that owns the monitor so this routine will
 902 // count the number of times the same object was locked by frames
 903 // in java_thread.
 904 //
 905 jint
 906 JvmtiEnvBase::count_locked_objects(JavaThread *java_thread, Handle hobj) {
 907   jint ret = 0;
 908   if (!java_thread->has_last_Java_frame()) {
 909     return ret;  // no Java frames so no monitors
 910   }

2155   _collector.allocate_and_fill_stacks(_final_thread_count);
2156 }
2157 
2158 // Verifies that the top frame is a java frame in an expected state.
2159 // Deoptimizes frame if needed.
2160 // Checks that the frame method signature matches the return type (tos).
2161 // HandleMark must be defined in the caller only.
2162 // It is to keep a ret_ob_h handle alive after return to the caller.
2163 jvmtiError
2164 JvmtiEnvBase::check_top_frame(Thread* current_thread, JavaThread* java_thread,
2165                               jvalue value, TosState tos, Handle* ret_ob_h) {
2166   ResourceMark rm(current_thread);
2167 
2168   javaVFrame* jvf = jvf_for_thread_and_depth(java_thread, 0);
2169   NULL_CHECK(jvf, JVMTI_ERROR_NO_MORE_FRAMES);
2170 
2171   if (jvf->method()->is_native()) {
2172     return JVMTI_ERROR_OPAQUE_FRAME;
2173   }
2174 
2175   // Prevent ForceEarlyReturnVoid from returning early from value class constructor as
2176   // the instance fields are strictly-initialized fields.
2177   if ((tos == vtos) && jvf->method()->is_object_constructor() && jvf->method()->method_holder()->is_inline_klass()) {
2178     return JVMTI_ERROR_OPAQUE_FRAME;
2179   }
2180 
2181   // If the frame is a compiled one, need to deoptimize it.
2182   if (jvf->is_compiled_frame()) {
2183     if (!jvf->fr().can_be_deoptimized()) {
2184       return JVMTI_ERROR_OPAQUE_FRAME;
2185     }
2186     Deoptimization::deoptimize_frame(java_thread, jvf->fr().id());
2187   }
2188 
2189   // Get information about method return type
2190   Symbol* signature = jvf->method()->signature();
2191 
2192   ResultTypeFinder rtf(signature);
2193   TosState fr_tos = as_TosState(rtf.type());
2194   if (fr_tos != tos) {
2195     if (tos != itos || (fr_tos != btos && fr_tos != ztos && fr_tos != ctos && fr_tos != stos)) {
2196       return JVMTI_ERROR_TYPE_MISMATCH;
2197     }
2198   }
2199 
2200   // Check that the jobject class matches the return type signature.
< prev index next >