static void jthread_remove_owned_monitor(jobject monitor) { vm_thread_t vm_thread = jthread_self_vm_thread(); assert(vm_thread); jvmti_thread_t jvmti_thread = &vm_thread->jvmti_thread; if (!jvmti_thread) { // nothing to do return; } CTRACE(("TM: remove owned monitor: %x", monitor)); for (int i = jvmti_thread->owned_monitors_nmb - 1; i >= 0; i--) { if (vm_objects_are_equal(jvmti_thread->owned_monitors[i], monitor)) { int disable_status = hythread_reset_suspend_disable(); vm_thread->jni_env->DeleteGlobalRef(jvmti_thread->owned_monitors[i]); hythread_set_suspend_disable(disable_status); int j; for (j = i; j < jvmti_thread->owned_monitors_nmb - 1; j++) { jvmti_thread->owned_monitors[j] = jvmti_thread->owned_monitors[j + 1]; } jvmti_thread->owned_monitors[j] = NULL; jvmti_thread->owned_monitors_nmb--; return; } } } // jthread_remove_owned_monitor
static void jthread_set_wait_monitor(jobject monitor) { vm_thread_t vm_thread = jthread_self_vm_thread(); assert(vm_thread); jvmti_thread_t jvmti_thread = &vm_thread->jvmti_thread; if (!jvmti_thread) { // nothing to do return; } CTRACE(("TM: set wait monitor: %x", monitor)); int disable_count = hythread_reset_suspend_disable(); jvmti_thread->wait_monitor = vm_thread->jni_env->NewGlobalRef(monitor); hythread_set_suspend_disable(disable_count); } // jthread_set_wait_monitor
static void jthread_add_owned_monitor(jobject monitor) { vm_thread_t vm_thread = jthread_self_vm_thread(); assert(vm_thread); jvmti_thread_t jvmti_thread = &vm_thread->jvmti_thread; if (!jvmti_thread) { // nothing to do return; } CTRACE(("TM: add owned monitor: %x", monitor)); int disable_status = hythread_reset_suspend_disable(); if (jvmti_thread->contended_monitor) { vm_thread->jni_env-> DeleteGlobalRef(jvmti_thread->contended_monitor); jvmti_thread->contended_monitor = NULL; } if (jvmti_thread->wait_monitor) { vm_thread->jni_env->DeleteGlobalRef(jvmti_thread->wait_monitor); jvmti_thread->wait_monitor = NULL; } if (jvmti_thread->owned_monitors_nmb >= jvmti_thread->owned_monitors_size) { int new_size = jvmti_thread->owned_monitors_size * 2; CTRACE(("Increasing owned_monitors_size to: %d", new_size)); jobject* new_monitors = (jobject*)apr_palloc(vm_thread->pool, new_size * sizeof(jobject)); assert(new_monitors); memcpy(new_monitors, jvmti_thread->owned_monitors, jvmti_thread->owned_monitors_size * sizeof(jobject)); jvmti_thread->owned_monitors = new_monitors; jvmti_thread->owned_monitors_size = new_size; } jvmti_thread->owned_monitors[jvmti_thread->owned_monitors_nmb] = vm_thread->jni_env->NewGlobalRef(monitor); jvmti_thread->owned_monitors_nmb++; hythread_set_suspend_disable(disable_status); } // jthread_add_owned_monitor
vm_thread_t jthread_get_vm_thread_ptr_stub() { return jthread_self_vm_thread(); }