/** * Completely releases the ownership over monitor. */ IDATA VMCALL hythread_thin_monitor_release(hythread_thin_monitor_t *lockword_ptr) { IDATA status; U_32 lockword = *lockword_ptr; hythread_t self = hythread_self(); if (self != hythread_thin_monitor_get_owner(lockword_ptr)) { // nothing to do, thread is not an owner of monitor return TM_ERROR_NONE; } if (IS_FAT_LOCK(lockword)) { // this is fat monitor hythread_monitor_t monitor = locktable_get_fat_monitor(FAT_LOCK_ID(lockword)); monitor->recursion_count = 0; status = port_mutex_unlock(&monitor->mutex); assert(status == TM_ERROR_NONE); } else { // this is thin monitor while (RECURSION(lockword)) { RECURSION_DEC(lockword_ptr, lockword); lockword = *lockword_ptr; } *lockword_ptr = lockword & 0xffff; } return TM_ERROR_NONE; }
/** * Returns the number of times given thread have entered given monitor; * * If the given monitor is not owned by this thread, 0 is returned. * * @param[in] monitor monitor those owner needs to be determined * @param[in] owner thread which owns the monitor */ IDATA VMCALL jthread_get_lock_recursion(jobject monitor, jthread owner) { assert(monitor); hythread_t given_thread = owner ? jthread_get_native_thread(owner) : NULL; hythread_suspend_disable(); hythread_thin_monitor_t *lockword = vm_object_get_lockword_addr(monitor); hythread_t lock_owner = hythread_thin_monitor_get_owner(lockword); IDATA recursion = 0; if (lock_owner && (!given_thread || hythread_get_id(lock_owner) == hythread_get_id(given_thread))) { recursion = hythread_thin_monitor_get_recursion(lockword); } hythread_suspend_enable(); return recursion; } // jthread_get_lock_recursion
/** * Returns the owner of the lock associated with the given monitor. * * If the given monitor is not owned by any thread, NULL is returned. * * @param[in] monitor monitor those owner needs to be determined * @param[out] lock_owner thread which owns the monitor */ IDATA VMCALL jthread_get_lock_owner(jobject monitor, jthread * lock_owner) { assert(monitor); assert(lock_owner); *lock_owner = NULL; IDATA status = TM_ERROR_NONE; hythread_suspend_disable(); hythread_thin_monitor_t *lockword = vm_object_get_lockword_addr(monitor); hythread_t native_thread = hythread_thin_monitor_get_owner(lockword); if (native_thread) { vm_thread_t vm_thread = jthread_get_vm_thread(native_thread); if (vm_thread) { *lock_owner = vm_thread->java_thread; } else { status = TM_ERROR_ILLEGAL_STATE; } } hythread_suspend_enable(); return status; } // jthread_get_lock_owner