538 //
539 // Threads
540 //
541
542 jthread *
543 JvmtiEnvBase::new_jthreadArray(int length, Handle *handles) {
544 if (length == 0) {
545 return nullptr;
546 }
547
548 jthread* objArray = (jthread *) jvmtiMalloc(sizeof(jthread) * length);
549 NULL_CHECK(objArray, nullptr);
550
551 for (int i = 0; i < length; i++) {
552 objArray[i] = (jthread)jni_reference(handles[i]);
553 }
554 return objArray;
555 }
556
557 jthreadGroup *
558 JvmtiEnvBase::new_jthreadGroupArray(int length, objArrayHandle groups) {
559 if (length == 0) {
560 return nullptr;
561 }
562
563 jthreadGroup* objArray = (jthreadGroup *) jvmtiMalloc(sizeof(jthreadGroup) * length);
564 NULL_CHECK(objArray, nullptr);
565
566 for (int i = 0; i < length; i++) {
567 objArray[i] = (jthreadGroup)JNIHandles::make_local(groups->obj_at(i));
568 }
569 return objArray;
570 }
571
572 // Return the vframe on the specified thread and depth, null if no such frame.
573 // The thread and the oops in the returned vframe might not have been processed.
574 javaVFrame*
575 JvmtiEnvBase::jvf_for_thread_and_depth(JavaThread* java_thread, jint depth) {
576 if (!java_thread->has_last_Java_frame()) {
577 return nullptr;
578 }
843 jint count = 0;
844 Handle *thread_objs = nullptr;
845 ThreadsListEnumerator tle(current_thread, /* include_jvmti_agent_threads */ true);
846 int nthreads = tle.num_threads();
847 if (nthreads > 0) {
848 thread_objs = NEW_RESOURCE_ARRAY_RETURN_NULL(Handle, nthreads);
849 NULL_CHECK(thread_objs, JVMTI_ERROR_OUT_OF_MEMORY);
850 for (int i = 0; i < nthreads; i++) {
851 Handle thread = tle.get_threadObj(i);
852 if (thread()->is_a(vmClasses::Thread_klass()) && java_lang_Thread::threadGroup(thread()) == group_hdl()) {
853 thread_objs[count++] = thread;
854 }
855 }
856 }
857 *thread_objs_p = thread_objs;
858 *count_ptr = count;
859 return JVMTI_ERROR_NONE;
860 }
861
862 jvmtiError
863 JvmtiEnvBase::get_subgroups(JavaThread* current_thread, Handle group_hdl, jint *count_ptr, objArrayHandle *group_objs_p) {
864
865 // This call collects the strong and weak groups
866 JavaThread* THREAD = current_thread;
867 JvmtiJavaUpcallMark jjum(current_thread); // hide JVMTI events for Java upcall
868 JavaValue result(T_OBJECT);
869 JavaCalls::call_virtual(&result,
870 group_hdl,
871 vmClasses::ThreadGroup_klass(),
872 SymbolTable::new_permanent_symbol("subgroupsAsArray"),
873 vmSymbols::void_threadgroup_array_signature(),
874 THREAD);
875 if (HAS_PENDING_EXCEPTION) {
876 Symbol* ex_name = PENDING_EXCEPTION->klass()->name();
877 CLEAR_PENDING_EXCEPTION;
878 if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
879 return JVMTI_ERROR_OUT_OF_MEMORY;
880 } else {
881 return JVMTI_ERROR_INTERNAL;
882 }
883 }
884
885 assert(result.get_type() == T_OBJECT, "just checking");
886 objArrayOop groups = (objArrayOop)result.get_oop();
887
888 *count_ptr = groups == nullptr ? 0 : groups->length();
889 *group_objs_p = objArrayHandle(current_thread, groups);
890
891 return JVMTI_ERROR_NONE;
892 }
893
894 //
895 // Object Monitor Information
896 //
897
898 //
899 // Count the number of objects for a lightweight monitor. The hobj
900 // parameter is object that owns the monitor so this routine will
901 // count the number of times the same object was locked by frames
902 // in java_thread.
903 //
904 jint
905 JvmtiEnvBase::count_locked_objects(JavaThread *java_thread, Handle hobj) {
906 jint ret = 0;
907 if (!java_thread->has_last_Java_frame()) {
908 return ret; // no Java frames so no monitors
909 }
2152 }
2153 }
2154 _collector.allocate_and_fill_stacks(_final_thread_count);
2155 }
2156
2157 // Verifies that the top frame is a java frame in an expected state.
2158 // Deoptimizes frame if needed.
2159 // Checks that the frame method signature matches the return type (tos).
2160 // HandleMark must be defined in the caller only.
2161 // It is to keep a ret_ob_h handle alive after return to the caller.
2162 jvmtiError
2163 JvmtiEnvBase::check_top_frame(Thread* current_thread, JavaThread* java_thread,
2164 jvalue value, TosState tos, Handle* ret_ob_h) {
2165 ResourceMark rm(current_thread);
2166
2167 javaVFrame* jvf = jvf_for_thread_and_depth(java_thread, 0);
2168 NULL_CHECK(jvf, JVMTI_ERROR_NO_MORE_FRAMES);
2169
2170 if (jvf->method()->is_native()) {
2171 return JVMTI_ERROR_OPAQUE_FRAME;
2172 }
2173
2174 // If the frame is a compiled one, need to deoptimize it.
2175 if (jvf->is_compiled_frame()) {
2176 if (!jvf->fr().can_be_deoptimized()) {
2177 return JVMTI_ERROR_OPAQUE_FRAME;
2178 }
2179 Deoptimization::deoptimize_frame(java_thread, jvf->fr().id());
2180 }
2181
2182 // Get information about method return type
2183 Symbol* signature = jvf->method()->signature();
2184
2185 ResultTypeFinder rtf(signature);
2186 TosState fr_tos = as_TosState(rtf.type());
2187 if (fr_tos != tos) {
2188 if (tos != itos || (fr_tos != btos && fr_tos != ztos && fr_tos != ctos && fr_tos != stos)) {
2189 return JVMTI_ERROR_TYPE_MISMATCH;
2190 }
2191 }
|
538 //
539 // Threads
540 //
541
542 jthread *
543 JvmtiEnvBase::new_jthreadArray(int length, Handle *handles) {
544 if (length == 0) {
545 return nullptr;
546 }
547
548 jthread* objArray = (jthread *) jvmtiMalloc(sizeof(jthread) * length);
549 NULL_CHECK(objArray, nullptr);
550
551 for (int i = 0; i < length; i++) {
552 objArray[i] = (jthread)jni_reference(handles[i]);
553 }
554 return objArray;
555 }
556
557 jthreadGroup *
558 JvmtiEnvBase::new_jthreadGroupArray(int length, refArrayHandle groups) {
559 if (length == 0) {
560 return nullptr;
561 }
562
563 jthreadGroup* objArray = (jthreadGroup *) jvmtiMalloc(sizeof(jthreadGroup) * length);
564 NULL_CHECK(objArray, nullptr);
565
566 for (int i = 0; i < length; i++) {
567 objArray[i] = (jthreadGroup)JNIHandles::make_local(groups->obj_at(i));
568 }
569 return objArray;
570 }
571
572 // Return the vframe on the specified thread and depth, null if no such frame.
573 // The thread and the oops in the returned vframe might not have been processed.
574 javaVFrame*
575 JvmtiEnvBase::jvf_for_thread_and_depth(JavaThread* java_thread, jint depth) {
576 if (!java_thread->has_last_Java_frame()) {
577 return nullptr;
578 }
843 jint count = 0;
844 Handle *thread_objs = nullptr;
845 ThreadsListEnumerator tle(current_thread, /* include_jvmti_agent_threads */ true);
846 int nthreads = tle.num_threads();
847 if (nthreads > 0) {
848 thread_objs = NEW_RESOURCE_ARRAY_RETURN_NULL(Handle, nthreads);
849 NULL_CHECK(thread_objs, JVMTI_ERROR_OUT_OF_MEMORY);
850 for (int i = 0; i < nthreads; i++) {
851 Handle thread = tle.get_threadObj(i);
852 if (thread()->is_a(vmClasses::Thread_klass()) && java_lang_Thread::threadGroup(thread()) == group_hdl()) {
853 thread_objs[count++] = thread;
854 }
855 }
856 }
857 *thread_objs_p = thread_objs;
858 *count_ptr = count;
859 return JVMTI_ERROR_NONE;
860 }
861
862 jvmtiError
863 JvmtiEnvBase::get_subgroups(JavaThread* current_thread, Handle group_hdl, jint *count_ptr, refArrayHandle *group_objs_p) {
864
865 // This call collects the strong and weak groups
866 JavaThread* THREAD = current_thread;
867 JvmtiJavaUpcallMark jjum(current_thread); // hide JVMTI events for Java upcall
868 JavaValue result(T_OBJECT);
869 JavaCalls::call_virtual(&result,
870 group_hdl,
871 vmClasses::ThreadGroup_klass(),
872 SymbolTable::new_permanent_symbol("subgroupsAsArray"),
873 vmSymbols::void_threadgroup_array_signature(),
874 THREAD);
875 if (HAS_PENDING_EXCEPTION) {
876 Symbol* ex_name = PENDING_EXCEPTION->klass()->name();
877 CLEAR_PENDING_EXCEPTION;
878 if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
879 return JVMTI_ERROR_OUT_OF_MEMORY;
880 } else {
881 return JVMTI_ERROR_INTERNAL;
882 }
883 }
884
885 assert(result.get_type() == T_OBJECT, "just checking");
886 refArrayOop groups = (refArrayOop)result.get_oop();
887
888 *count_ptr = groups == nullptr ? 0 : groups->length();
889 *group_objs_p = refArrayHandle(current_thread, groups);
890
891 return JVMTI_ERROR_NONE;
892 }
893
894 //
895 // Object Monitor Information
896 //
897
898 //
899 // Count the number of objects for a lightweight monitor. The hobj
900 // parameter is object that owns the monitor so this routine will
901 // count the number of times the same object was locked by frames
902 // in java_thread.
903 //
904 jint
905 JvmtiEnvBase::count_locked_objects(JavaThread *java_thread, Handle hobj) {
906 jint ret = 0;
907 if (!java_thread->has_last_Java_frame()) {
908 return ret; // no Java frames so no monitors
909 }
2152 }
2153 }
2154 _collector.allocate_and_fill_stacks(_final_thread_count);
2155 }
2156
2157 // Verifies that the top frame is a java frame in an expected state.
2158 // Deoptimizes frame if needed.
2159 // Checks that the frame method signature matches the return type (tos).
2160 // HandleMark must be defined in the caller only.
2161 // It is to keep a ret_ob_h handle alive after return to the caller.
2162 jvmtiError
2163 JvmtiEnvBase::check_top_frame(Thread* current_thread, JavaThread* java_thread,
2164 jvalue value, TosState tos, Handle* ret_ob_h) {
2165 ResourceMark rm(current_thread);
2166
2167 javaVFrame* jvf = jvf_for_thread_and_depth(java_thread, 0);
2168 NULL_CHECK(jvf, JVMTI_ERROR_NO_MORE_FRAMES);
2169
2170 if (jvf->method()->is_native()) {
2171 return JVMTI_ERROR_OPAQUE_FRAME;
2172 }
2173
2174 // Prevent ForceEarlyReturnVoid from returning early from value class constructor as
2175 // the instance fields are strictly-initialized fields.
2176 if ((tos == vtos) && jvf->method()->is_object_constructor() && jvf->method()->method_holder()->is_inline_klass()) {
2177 return JVMTI_ERROR_OPAQUE_FRAME;
2178 }
2179
2180 // If the frame is a compiled one, need to deoptimize it.
2181 if (jvf->is_compiled_frame()) {
2182 if (!jvf->fr().can_be_deoptimized()) {
2183 return JVMTI_ERROR_OPAQUE_FRAME;
2184 }
2185 Deoptimization::deoptimize_frame(java_thread, jvf->fr().id());
2186 }
2187
2188 // Get information about method return type
2189 Symbol* signature = jvf->method()->signature();
2190
2191 ResultTypeFinder rtf(signature);
2192 TosState fr_tos = as_TosState(rtf.type());
2193 if (fr_tos != tos) {
2194 if (tos != itos || (fr_tos != btos && fr_tos != ztos && fr_tos != ctos && fr_tos != stos)) {
2195 return JVMTI_ERROR_TYPE_MISMATCH;
2196 }
2197 }
|