/** * Returns all monitors owned by the specific thread. * * @param[in] java_thread thread which owns monitors * @param[out] monitor_count_ptr number of owned monitors * @param[out] monitors_ptr array of owned monitors */ IDATA VMCALL jthread_get_owned_monitors(jthread java_thread, jint *monitor_count_ptr, jobject **monitors_ptr) { assert(java_thread); assert(monitors_ptr); assert(monitor_count_ptr); IDATA status = hythread_global_lock(); if (status != TM_ERROR_NONE) { return status; } vm_thread_t vm_thread = jthread_get_vm_thread_from_java(java_thread); if (!vm_thread) { status = hythread_global_unlock(); return status; } jvmti_thread_t jvmti_thread = &vm_thread->jvmti_thread; if (!jvmti_thread) { status = hythread_global_unlock(); return status; } jobject *monitors = (jobject *) malloc(sizeof(jobject *) * jvmti_thread->owned_monitors_nmb); if (!monitors) { hythread_global_unlock(); return TM_ERROR_OUT_OF_MEMORY; } tmn_suspend_disable(); for (int i = 0; i < jvmti_thread->owned_monitors_nmb; i++) { jobject new_ref = oh_allocate_local_handle_from_jni(); if (NULL != new_ref) new_ref->object = jvmti_thread->owned_monitors[i]->object; else { tmn_suspend_enable(); hythread_global_unlock(); return TM_ERROR_OUT_OF_MEMORY; } // change the order of reported monitors to be compliant with RI monitors[jvmti_thread->owned_monitors_nmb - 1 - i] = new_ref; } tmn_suspend_enable(); *monitors_ptr = monitors; *monitor_count_ptr = jvmti_thread->owned_monitors_nmb; status = hythread_global_unlock(); return status; } // jthread_get_owned_monitors
/** * Returns the monitor the specific thread is currently waiting on. * * @param[in] java_thread thread to be explored for contention * @param[out] monitor monitor the thread <code>thread</code> is currently contending for, * or NULL if thread doesn't contend for any monitor. */ IDATA VMCALL jthread_get_wait_monitor(jthread java_thread, jobject * monitor) { assert(java_thread); assert(monitor); *monitor = NULL; vm_thread_t vm_thread = jthread_get_vm_thread_from_java(java_thread); if (!vm_thread) { return TM_ERROR_NONE; } jvmti_thread_t jvmti_thread = &vm_thread->jvmti_thread; if (jvmti_thread) { *monitor = jvmti_thread->wait_monitor; } return TM_ERROR_NONE; } // jthread_get_wait_monitor
int check_structure(tested_thread_sturct_t *tts){ jthread java_thread = tts->java_thread; vm_thread_t vm_thread; jvmti_thread_t jvmti_thread; hythread_t hythread; vm_thread = jthread_get_vm_thread_from_java(java_thread); tf_assert(vm_thread); hythread = (hythread_t)vm_thread; tf_assert_same(hythread, tts->native_thread); jvmti_thread = &(vm_thread->jvmti_thread); tf_assert(jvmti_thread); return TEST_PASSED; }