remove thread from thread group on termination

In the OpenJDK library, ThreadGroup maintains an array of all Threads
in that group, so the VM must explicitly remove threads as they exit
or else neither they nor any objects they reference will be eligable
for GC.
This commit is contained in:
Joel Dice 2013-03-05 09:06:19 -07:00
parent c6185c8034
commit 84f99f0dca
2 changed files with 11 additions and 2 deletions

View File

@ -1231,10 +1231,11 @@ class Machine {
Shutdown,
VirtualFileFinders,
VirtualFiles,
ArrayInterfaceTable
ArrayInterfaceTable,
ThreadTerminated
};
static const unsigned RootCount = ArrayInterfaceTable + 1;
static const unsigned RootCount = ThreadTerminated + 1;
Machine(System* system, Heap* heap, Finder* bootFinder, Finder* appFinder,
Processor* processor, Classpath* classpath, const char** properties,

View File

@ -613,6 +613,10 @@ class MyClasspath : public Classpath {
t->flags &= ~Thread::ActiveFlag;
vm::notifyAll(t, t->javaThread);
vm::release(t, t->javaThread);
t->m->processor->invoke
(t, root(t, Machine::ThreadTerminated),
threadGroup(t, t->javaThread), t->javaThread);
});
object method = resolveMethod
@ -653,6 +657,10 @@ class MyClasspath : public Classpath {
resolveSystemClass(t, root(t, Machine::BootLoader),
className(t, type(t, Machine::ClassLoaderType)));
setRoot(t, Machine::ThreadTerminated, resolveMethod
(t, root(t, Machine::BootLoader), "java/lang/ThreadGroup",
"threadTerminated", "(Ljava/lang/Thread;)V"));
#ifdef AVIAN_OPENJDK_SRC
interceptFileOperations(t);
#else // not AVIAN_OPENJDK_SRC