[kaffe] CVS kaffe (guilhem): Important fix for the locking subsystem.
Kaffe CVS
cvs-commits at kaffe.org
Sat Mar 11 03:21:13 PST 2006
PatchSet 7149
Date: 2006/03/11 11:09:46
Author: guilhem
Branch: HEAD
Tag: (none)
Log:
Important fix for the locking subsystem.
* kaffe/kaffevm/thread.c
(startThread, startSpecialThread, createDaemon, firstStartThread):
Secured KSEM(get) calls against interruption.
* kaffe/kaffevm/locks.c
(getHeavyLock): Optimized the number of increments/decrements.
(slowLockMutex): Secure the call to KSEM(get) against
interruption.
Members:
ChangeLog:1.4667->1.4668
kaffe/kaffevm/locks.c:1.69->1.70
kaffe/kaffevm/thread.c:1.107->1.108
Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.4667 kaffe/ChangeLog:1.4668
--- kaffe/ChangeLog:1.4667 Thu Mar 9 02:14:03 2006
+++ kaffe/ChangeLog Sat Mar 11 11:09:46 2006
@@ -1,3 +1,14 @@
+2006-03-11 Guilhem Lavaux <guilhem at kaffe.org>
+
+ * kaffe/kaffevm/thread.c
+ (startThread, startSpecialThread, createDaemon, firstStartThread):
+ Secured KSEM(get) calls against interruption.
+
+ * kaffe/kaffevm/locks.c
+ (getHeavyLock): Optimized the number of increments/decrements.
+ (slowLockMutex): Secure the call to KSEM(get) against
+ interruption.
+
2006-03-09 Dalibor Topic <robilad at kaffe.org>
* kaffe/kaffevm/thread.c (linkNativeAndJavaThread),
Index: kaffe/kaffe/kaffevm/locks.c
diff -u kaffe/kaffe/kaffevm/locks.c:1.69 kaffe/kaffe/kaffevm/locks.c:1.70
--- kaffe/kaffe/kaffevm/locks.c:1.69 Wed Dec 28 19:05:54 2005
+++ kaffe/kaffe/kaffevm/locks.c Sat Mar 11 11:09:51 2006
@@ -153,13 +153,12 @@
lk = GET_HEAVYLOCK(lk);
/* The lock is allocated and ready to use. */
+ atomic_increment(&(lk->num_wait));
for (;;) {
/* Try to acquire the lock. We try to do an "atomic" incrementation. */
- atomic_increment(&(lk->num_wait));
if (!COMPARE_AND_EXCHANGE(&(lk->in_progress), 0, 1))
{
KSEM(get)(&lk->sem, (jlong)0);
- atomic_decrement(&(lk->num_wait));
continue;
}
lk->hlockHolder = KTHREAD(current)();
@@ -219,6 +218,7 @@
volatile iLock* lk;
jthread_t cur = KTHREAD(current) ();
threadData *tdata;
+ int r;
DBG(SLOWLOCKS,
dprintf("slowLockMutex(lk=%p, th=%p)\n",
@@ -256,8 +256,15 @@
/* Otherwise wait for holder to release it */
tdata->nextlk = lk->mux;
lk->mux = cur;
+
putHeavyLock(lk);
- KSEM(get)(&tdata->sem, (jlong)0);
+ /* KSEM(get) cannot have a timeout because it is infinite.
+ * However, it can be interrupted and we do not want that for
+ * locking.
+ */
+ do {
+ r = KSEM(get)(&tdata->sem, (jlong)0);
+ } while (!r);
}
}
@@ -342,7 +349,7 @@
!COMPARE_AND_EXCHANGE(lkp, (iLock*)cur, LOCKFREE))
return;
- /* ok, it is a heavy lock and it is acquire by someone. */
+ /* ok, it is a heavy lock and it is acquired by someone. */
lk = getHeavyLock((volatile iLock *volatile *)lkp, heavyLock);
holder = lk->holder;
putHeavyLock(lk);
Index: kaffe/kaffe/kaffevm/thread.c
diff -u kaffe/kaffe/kaffevm/thread.c:1.107 kaffe/kaffe/kaffevm/thread.c:1.108
--- kaffe/kaffe/kaffevm/thread.c:1.107 Thu Mar 9 02:14:07 2006
+++ kaffe/kaffe/kaffevm/thread.c Sat Mar 11 11:09:51 2006
@@ -170,6 +170,7 @@
{
jthread_t nativeTid;
struct _errorInfo info;
+ int r;
DBG(VMTHREAD, dprintf ("%p starting thread %p (vmthread %p)\n\n", KTHREAD(current)(), unhand(tid)->thread, tid); );
@@ -184,7 +185,9 @@
if (nativeTid == NULL) {
throwError(&info);
}
- KSEM(get)(&THREAD_DATA()->sem, (jlong)0);
+ do {
+ r = KSEM(get)(&THREAD_DATA()->sem, (jlong)0);
+ } while (!r);
linkNativeAndJavaThread (nativeTid, tid);
@@ -323,6 +326,7 @@
void *argument;
jthread_t calling_thread;
threadData *thread_data = THREAD_DATA();
+ int r;
KSEM(init)(&thread_data->sem);
@@ -338,7 +342,9 @@
/* We have now to wait the parent to synchronize the data
* and link the thread to the Java VM.
*/
- KSEM(get)(&thread_data->sem, (jlong)0);
+ do {
+ r = KSEM(get)(&thread_data->sem, (jlong)0);
+ } while (!r);
thread_data->exceptObj = NULL;
@@ -364,6 +370,7 @@
Hjava_lang_String* name;
void *specialArgument[3];
jvalue retval;
+ int r;
DBG(VMTHREAD, dprintf("createDaemon %s\n", nm); );
@@ -408,7 +415,9 @@
KTHREAD(get_data)(nativeTid)->exceptPtr = NULL;
KTHREAD(get_data)(nativeTid)->exceptObj = NULL;
- KSEM(get)(&THREAD_DATA()->sem, (jlong)0);
+ do {
+ r = KSEM(get)(&THREAD_DATA()->sem, (jlong)0);
+ } while (!r);
linkNativeAndJavaThread (nativeTid, vmtid);
@@ -430,6 +439,8 @@
jmethodID runmethod;
jthread_t calling_thread = (jthread_t) arg;
threadData *thread_data;
+ int r;
+
cur = KTHREAD(current)();
thread_data = KTHREAD(get_data)(cur);
@@ -439,7 +450,9 @@
/* We acknowledge the parent thread that this thread has been started. */
KSEM(put)(&KTHREAD(get_data)(calling_thread)->sem);
/* Now we must wait the parent to link the thread to the Java VM. */
- KSEM(get)(&thread_data->sem, (jlong)0);
+ do {
+ r = KSEM(get)(&thread_data->sem, (jlong)0);
+ } while (!r);
tid = (Hjava_lang_VMThread *)(thread_data->jlThread);
env = &thread_data->jniEnv;
More information about the kaffe
mailing list