diff --git a/src/classpath-openjdk.cpp b/src/classpath-openjdk.cpp index 9869538cf6..49750e7fb7 100644 --- a/src/classpath-openjdk.cpp +++ b/src/classpath-openjdk.cpp @@ -604,15 +604,21 @@ class MyClasspath : public Classpath { virtual void runThread(Thread* t) { + // force monitor creation so we don't get an OutOfMemory error + // later when we try to acquire it: + objectMonitor(t, t->javaThread, true); + + THREAD_RESOURCE0(t, { + vm::acquire(t, t->javaThread); + t->flags &= ~Thread::ActiveFlag; + vm::notifyAll(t, t->javaThread); + vm::release(t, t->javaThread); + }); + object method = resolveMethod (t, root(t, Machine::BootLoader), "java/lang/Thread", "run", "()V"); t->m->processor->invoke(t, method, t->javaThread); - - acquire(t, t->javaThread); - t->flags &= ~Thread::ActiveFlag; - notifyAll(t, t->javaThread); - release(t, t->javaThread); } virtual void