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 }
|
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 }
|