/* CURRENT ALGORITHM */ /* Enter() { retry: if (acquire_thinlock_first_time()) return OK if (lock_is_thin()) { if (lock_is_mine) { if (recursive_count == MAX) { inflate_lock(); goto retry; *try lock inflated lock* } else { increase_recursive_count(); return OK; } } else { *contention* if (owner == NULL) goto retry; *we read lockword "early"* lock_thread_mutex(owner); old_flag = get_contention_flag(owner); set_contention_flag(owner); if (owner_thread_id == thinlock_id(lockword)) { notified = TRUE; add_youself_to_requester_wait_list(owner); } else { *owner has changed* notified = FALSE; restore_old_contention_flag; } unlock_thread_mutex(owner); stop_java(); lock_thread_mutex(owner); if (!notified) goto retry; while (still_on_requester_wait_list(owner)) cond_wait(my_cond,owner_mutex); unlock_thread_mutex(owner); resume_java(); goto retry; } } else { *lock is fat already* stop_java(); lock_fatlock(object->fatlock->mutex); while (somebody_owns_the_fatlock()) cond_wait(fatlock_cond, fatlock); handle_recusive_count(); fatlock->owner = self; unlock_fatlock(); resume_java(); } return OK; } Leave() { if (is_thin()) { decrement_count(); if (releasing_lock) goto handle_contention; return OK; } else { *is fat* lock_fatlock(); decrement_count(); released == (count == 0); if (released) cond_bradcast(fatlock_cond); unlock_fatlock(); if (released) goto handle_contention; return OK; } handle_contention: if (our_contention_flat_is_set()) { lock_thread_mutex(self); for (all_waiting_threads) { inflate_contented_locks_we_still_hold(); signal_waiting_thread(); } clean_waiting_list(); zero_contention_flag(); unlock_thread_mutex(self); } return OK; } Inflate_lock() { lock_global(); get_a_free_fat_lock(); unlock_global(); lock_fatlock(); set_fatlock_owner_recursive_count(); modify_object_lockword_for_fatlock(); unlock_fatlock(); } */