posix-threads.cc (_Jv_CondNotify,_Jv_CondNotifyAll): Rename _Jv_PthreadCheckMonitor to _Jv_MutexCheckMonitor.
2003-10-21 Jerry Quinn <jlquinn@optonline.net> * posix-threads.cc (_Jv_CondNotify,_Jv_CondNotifyAll): Rename _Jv_PthreadCheckMonitor to _Jv_MutexCheckMonitor. * include/no-threads.h (_Jv_MutexCheckMonitor): New. * include/posix-threads.h (_Jv_MutexCheckMonitor): Rename from _Jv_PthreadCheckMonitor. Simplify code. (_Jv_MutexUnlock): Use _Jv_MutexCheckMonitor. * include/win32-threads.h (_Jv_MutexCheckMonitor): New. * java/lang/Object.h (_Jv_ObjectCheckMonitor): Declare. * java/lang/Thread.java (holdsLock): New. * java/lang/natObject.cc (_Jv_ObjectCheckMonitor): New, with and without JV_HASH_SYNCHRONIZATION. * java/lang/natThread.cc (java::lang::Thread::holdsLock): New. From-SVN: r72741
This commit is contained in:
parent
036a75ac29
commit
16a10fb6fc
9 changed files with 96 additions and 8 deletions
|
@ -49,6 +49,7 @@ public:
|
|||
friend void _Jv_MonitorExit (jobject obj);
|
||||
friend void _Jv_InitializeSyncMutex (void);
|
||||
friend void _Jv_FinalizeObject (jobject obj);
|
||||
friend bool _Jv_ObjectCheckMonitor (jobject obj);
|
||||
|
||||
#ifdef JV_MARKOBJ_DECL
|
||||
friend JV_MARKOBJ_DECL;
|
||||
|
|
|
@ -181,6 +181,15 @@ public class Thread implements Runnable
|
|||
return group;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if this Thread holds the object's lock, false otherwise.
|
||||
*
|
||||
* @param obj the object to test lock ownership on.
|
||||
* @throws NullPointerException if obj is null.
|
||||
* @since 1.4
|
||||
*/
|
||||
public static native boolean holdsLock (Object obj);
|
||||
|
||||
/**
|
||||
* Interrupt this Thread. First, there is a security check,
|
||||
* <code>checkAccess</code>. Then, depending on the current state of the
|
||||
|
|
|
@ -264,6 +264,13 @@ _Jv_MonitorExit (jobject obj)
|
|||
throw new java::lang::IllegalMonitorStateException;
|
||||
}
|
||||
|
||||
bool
|
||||
_Jv_ObjectCheckMonitor (jobject obj)
|
||||
{
|
||||
_Jv_SyncInfo *si = (_Jv_SyncInfo *) obj->sync_info;
|
||||
return _Jv_MutexCheckMonitor (&si->mutex);
|
||||
}
|
||||
|
||||
#else /* JV_HASH_SYNCHRONIZATION */
|
||||
|
||||
// FIXME: We shouldn't be calling GC_register_finalizer directly.
|
||||
|
@ -1087,6 +1094,46 @@ retry:
|
|||
keep_live(addr);
|
||||
}
|
||||
|
||||
// Return false if obj's monitor is held by the current thread
|
||||
bool
|
||||
_Jv_ObjectCheckMonitor (jobject obj)
|
||||
{
|
||||
#ifdef JV_LINKER_CANNOT_8BYTE_ALIGN_STATICS
|
||||
obj_addr_t addr = (obj_addr_t)obj & ~((obj_addr_t)FLAGS);
|
||||
#else
|
||||
obj_addr_t addr = (obj_addr_t)obj;
|
||||
#endif
|
||||
obj_addr_t address;
|
||||
unsigned hash = JV_SYNC_HASH(addr);
|
||||
hash_entry * he = light_locks + hash;
|
||||
_Jv_ThreadId_t self = _Jv_ThreadSelf();
|
||||
|
||||
JvAssert(!(addr & FLAGS));
|
||||
retry:
|
||||
// Acquire the hash table entry lock
|
||||
address = ((he -> address) & ~LOCKED);
|
||||
if (!compare_and_swap(&(he -> address), address, address | LOCKED))
|
||||
{
|
||||
wait_unlocked(he);
|
||||
goto retry;
|
||||
}
|
||||
|
||||
bool not_mine;
|
||||
|
||||
if (!(address & ~FLAGS))
|
||||
not_mine = true;
|
||||
else if ((address & ~FLAGS) == addr)
|
||||
not_mine = (he -> light_thr_id != self);
|
||||
else
|
||||
{
|
||||
heavy_lock* hl = find_heavy(addr, he);
|
||||
not_mine = hl ? (hl->si.mutex.owner != self) : true;
|
||||
}
|
||||
|
||||
release_set(&(he -> address), address); // unlock hash entry
|
||||
return not_mine;
|
||||
}
|
||||
|
||||
// The rest of these are moderately thin veneers on _Jv_Cond ops.
|
||||
// The current version of Notify might be able to make the pthread
|
||||
// call AFTER releasing the lock, thus saving some context switches??
|
||||
|
|
|
@ -107,6 +107,14 @@ java::lang::Thread::destroy (void)
|
|||
(JvNewStringLatin1 ("Thread.destroy unimplemented"));
|
||||
}
|
||||
|
||||
jboolean
|
||||
java::lang::Thread::holdsLock (jobject obj)
|
||||
{
|
||||
if (!obj)
|
||||
throw new NullPointerException;
|
||||
return !_Jv_ObjectCheckMonitor (obj);
|
||||
}
|
||||
|
||||
void
|
||||
java::lang::Thread::interrupt (void)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue