< prev index next >
src/hotspot/share/runtime/thread.cpp
Print this page
rev 52112 : [mq]: 8021335
@@ -1817,10 +1817,13 @@
lock.notify_all(thread);
// Ignore pending exception (ThreadDeath), since we are exiting anyway
thread->clear_pending_exception();
}
+static bool is_daemon(oop threadObj) {
+ return (threadObj != NULL && java_lang_Thread::is_daemon(threadObj));
+}
// For any new cleanup additions, please check to see if they need to be applied to
// cleanup_failed_attach_current_thread as well.
void JavaThread::exit(bool destroy_vm, ExitType exit_type) {
assert(this == JavaThread::current(), "thread consistency check");
@@ -1908,11 +1911,10 @@
while (true) {
{
MutexLockerEx ml(SR_lock(), Mutex::_no_safepoint_check_flag);
if (!is_external_suspend()) {
set_terminated(_thread_exiting);
- ThreadService::current_thread_exiting(this);
break;
}
// Implied else:
// Things get a little tricky here. We have a pending external
// suspend request, but we are holding the SR_lock so we
@@ -1927,11 +1929,15 @@
// and check again. Eventually we will get SR_lock without a pending
// external suspend request and will be able to mark ourselves as
// exiting.
}
// no more external suspends are allowed at this point
+ { MutexLocker mu(Threads_lock);
+ ThreadService::current_thread_exiting(this, is_daemon(threadObj()));
+ }
} else {
+ assert(!is_terminated() && !is_exiting(), "must not be exiting");
// before_exit() has already posted JVMTI THREAD_END events
}
if (log_is_enabled(Debug, os, thread, timer)) {
_timer_exit_phase1.stop();
@@ -4330,11 +4336,11 @@
}
void Threads::add(JavaThread* p, bool force_daemon) {
// The threads lock must be owned at this point
- assert_locked_or_safepoint(Threads_lock);
+ assert(Threads_lock->owned_by_self(), "must have threads lock");
BarrierSet::barrier_set()->on_thread_attach(p);
p->set_next(_thread_list);
_thread_list = p;
@@ -4346,11 +4352,11 @@
_number_of_threads++;
oop threadObj = p->threadObj();
bool daemon = true;
// Bootstrapping problem: threadObj can be null for initial
// JavaThread (or for threads attached via JNI)
- if ((!force_daemon) && (threadObj == NULL || !java_lang_Thread::is_daemon(threadObj))) {
+ if ((!force_daemon) && !is_daemon((threadObj))) {
_number_of_non_daemon_threads++;
daemon = false;
}
ThreadService::add_thread(p, daemon);
@@ -4391,11 +4397,11 @@
}
_number_of_threads--;
oop threadObj = p->threadObj();
bool daemon = true;
- if (threadObj == NULL || !java_lang_Thread::is_daemon(threadObj)) {
+ if (!is_daemon(threadObj)) {
_number_of_non_daemon_threads--;
daemon = false;
// Only one thread left, do a notify on the Threads_lock so a thread waiting
// on destroy_vm will wake up.
< prev index next >