#include "thread.h"
#include "locks.h"
+#include "builtin.h"
#include "tables.h"
#include "native.h"
#include "loader.h"
+#include "toolbox/memory.h"
-static classinfo *class_java_lang_IllegalMonitorStateException;
-#if 1
-#define DBG(s)
-#else
-#define DBG(s) s
-#endif
+#if !defined(NATIVE_THREADS)
extern thread* currentThread;
-#if defined(USE_INTERNAL_THREADS)
-
mutexHashEntry *mutexHashTable;
int mutexHashTableSize;
long mutexHashMask;
int i;
mutexHashTableSize = MUTEX_HASH_TABLE_SIZE;
- mutexHashTable = (mutexHashEntry*)malloc(sizeof(mutexHashEntry) * mutexHashTableSize);
+ mutexHashTable = MNEW(mutexHashEntry, mutexHashTableSize);
mutexHashMask = (mutexHashTableSize - 1) << 3;
for (i = 0; i < mutexHashTableSize; ++i)
}
mutexOverflowTableSize = MUTEX_OVERFLOW_TABLE_SIZE;
- mutexOverflowTable = (mutexHashEntry*)malloc(sizeof(mutexHashEntry)
- * mutexOverflowTableSize);
+ mutexOverflowTable = MNEW(mutexHashEntry, mutexOverflowTableSize);
firstFreeOverflowEntry = &mutexOverflowTable[0];
mutexOverflowTable[i - 1].next = 0;
conditionHashTableSize = CONDITION_HASH_TABLE_SIZE;
- conditionHashTable = (conditionHashEntry*)malloc(sizeof(conditionHashEntry)
- * conditionHashTableSize);
+ conditionHashTable = MNEW(conditionHashEntry, conditionHashTableSize);
conditionHashMask = (conditionHashTableSize - 1) << 3;
for (i = 0; i < conditionHashTableSize; ++i)
conditionHashTable[i].condition.cvWaiters = 0;
conditionHashTable[i].condition.mux = 0;
}
-
- /* Load exception classes */
- class_java_lang_IllegalMonitorStateException =
- loader_load(utf_new_char("java/lang/IllegalMonitorStateException"));
}
+
/*
* Reorders part of the condition hash table. Must be called after an entry has been deleted.
*/
void
internal_lock_mutex(iMux* mux)
{
- assert(blockInts == 1);
+ assert(blockInts > 0);
if (mux->holder == 0)
{
{
thread* tid;
- assert(blockInts == 1);
+ assert(blockInts > 0);
assert(mux->holder == currentThread);
if (mux->muxWaiters != 0)
{
tid = mux->muxWaiters;
- mux->muxWaiters = tid->next;
+ mux->muxWaiters = tid->vmThread->next;
iresumeThread(tid);
}
}
DBG( fprintf(stderr, "waiting on %p\n", cv); );
if (mux->holder != currentThread) {
- exceptionptr = native_new_and_init(class_java_lang_IllegalMonitorStateException);
+ *exceptionptr = new_exception(string_java_lang_IllegalMonitorStateException);
}
- assert(blockInts == 1);
+ assert(blockInts > 0);
count = mux->count;
mux->holder = 0;
/* If there's anyone waiting here, wake them up */
if (mux->muxWaiters != 0) {
tid = mux->muxWaiters;
- mux->muxWaiters = tid->next;
+ mux->muxWaiters = tid->vmThread->next;
iresumeThread(tid);
}
}
if (cv->mux->holder != currentThread) {
- exceptionptr = native_new_and_init(class_java_lang_IllegalMonitorStateException);
+ *exceptionptr = new_exception(string_java_lang_IllegalMonitorStateException);
}
- assert(blockInts == 1);
+ assert(blockInts > 0);
/* Remove one thread from cv list */
if (cv->cvWaiters != 0) {
DBG( fprintf(stderr, "releasing a waiter\n"); );
tid = cv->cvWaiters;
- cv->cvWaiters = tid->next;
+ cv->cvWaiters = tid->vmThread->next;
/* Place it on mux list */
- tid->next = cv->mux->muxWaiters;
+ tid->vmThread->next = cv->mux->muxWaiters;
cv->mux->muxWaiters = tid;
}
}
}
if (cv->mux->holder != currentThread) {
- exceptionptr = native_new_and_init(class_java_lang_IllegalMonitorStateException);
+ *exceptionptr = new_exception(string_java_lang_IllegalMonitorStateException);
}
- assert(blockInts == 1);
+ assert(blockInts > 0);
/* Find the end of the cv list */
if (cv->cvWaiters) {
- for (tidp = &cv->cvWaiters; *tidp != 0; tidp = &(*tidp)->next)
+ for (tidp = &cv->cvWaiters; *tidp != 0; tidp = &(*tidp)->vmThread->next)
;
/* Place entire cv list on mux list */