clean up OS resources immediately upon thread exit

Previously, we waited until the next GC to do this, but that can be
too long for workloads which create a lot of short-lived threads but
don't do much allocation.
This commit is contained in:
Joel Dice 2010-11-09 15:46:16 -07:00
parent 44f55673d6
commit f64d6c857b
2 changed files with 19 additions and 3 deletions

View File

@ -45,7 +45,11 @@ void
join(Thread* t, Thread* o) join(Thread* t, Thread* o)
{ {
if (t != o) { if (t != o) {
o->systemThread->join(); if (o->state != Thread::ZombieState
and o->state != Thread::JoinedState)
{
o->systemThread->join();
}
o->state = Thread::JoinedState; o->state = Thread::JoinedState;
} }
} }
@ -2281,6 +2285,12 @@ Thread::exit()
} else { } else {
threadPeer(this, javaThread) = 0; threadPeer(this, javaThread) = 0;
enter(this, Thread::ZombieState); enter(this, Thread::ZombieState);
lock->dispose();
lock = 0;
systemThread->dispose();
systemThread = 0;
} }
} }
} }
@ -2288,7 +2298,9 @@ Thread::exit()
void void
Thread::dispose() Thread::dispose()
{ {
lock->dispose(); if (lock) {
lock->dispose();
}
if (systemThread) { if (systemThread) {
systemThread->dispose(); systemThread->dispose();

View File

@ -2746,7 +2746,11 @@ notifyAll(Thread* t, object o)
inline void inline void
interrupt(Thread*, Thread* target) interrupt(Thread*, Thread* target)
{ {
target->systemThread->interrupt(); if (target->state != Thread::ZombieState
and target->state != Thread::JoinedState)
{
target->systemThread->interrupt();
}
} }
inline void inline void