Mercurial > hg > truffle
comparison src/share/vm/runtime/thread.cpp @ 2162:ccfcb502af3f
6566340: Restore use of stillborn flag to signify a thread that was stopped before it started
Summary: Restore use of stillborn flag
Reviewed-by: acorn, alanb
author | dholmes |
---|---|
date | Tue, 25 Jan 2011 00:14:21 -0500 |
parents | 8f8dfba37802 |
children | 3582bf76420e |
comparison
equal
deleted
inserted
replaced
2157:d535bf4c1235 | 2162:ccfcb502af3f |
---|---|
1508 | 1508 |
1509 void JavaThread::thread_main_inner() { | 1509 void JavaThread::thread_main_inner() { |
1510 assert(JavaThread::current() == this, "sanity check"); | 1510 assert(JavaThread::current() == this, "sanity check"); |
1511 assert(this->threadObj() != NULL, "just checking"); | 1511 assert(this->threadObj() != NULL, "just checking"); |
1512 | 1512 |
1513 // Execute thread entry point. If this thread is being asked to restart, | 1513 // Execute thread entry point unless this thread has a pending exception |
1514 // or has been stopped before starting, do not reexecute entry point. | 1514 // or has been stopped before starting. |
1515 // Note: Due to JVM_StopThread we can have pending exceptions already! | 1515 // Note: Due to JVM_StopThread we can have pending exceptions already! |
1516 if (!this->has_pending_exception() && !java_lang_Thread::is_stillborn(this->threadObj())) { | 1516 if (!this->has_pending_exception() && |
1517 // enter the thread's entry point only if we have no pending exceptions | 1517 !java_lang_Thread::is_stillborn(this->threadObj())) { |
1518 HandleMark hm(this); | 1518 HandleMark hm(this); |
1519 this->entry_point()(this, this); | 1519 this->entry_point()(this, this); |
1520 } | 1520 } |
1521 | 1521 |
1522 DTRACE_THREAD_PROBE(stop, this); | 1522 DTRACE_THREAD_PROBE(stop, this); |
1531 Handle threadObj(thread, thread->threadObj()); | 1531 Handle threadObj(thread, thread->threadObj()); |
1532 assert(threadObj.not_null(), "java thread object must exist"); | 1532 assert(threadObj.not_null(), "java thread object must exist"); |
1533 ObjectLocker lock(threadObj, thread); | 1533 ObjectLocker lock(threadObj, thread); |
1534 // Ignore pending exception (ThreadDeath), since we are exiting anyway | 1534 // Ignore pending exception (ThreadDeath), since we are exiting anyway |
1535 thread->clear_pending_exception(); | 1535 thread->clear_pending_exception(); |
1536 // It is of profound importance that we set the stillborn bit and reset the thread object, | |
1537 // before we do the notify. Since, changing these two variable will make JVM_IsAlive return | |
1538 // false. So in case another thread is doing a join on this thread , it will detect that the thread | |
1539 // is dead when it gets notified. | |
1540 java_lang_Thread::set_stillborn(threadObj()); | |
1541 // Thread is exiting. So set thread_status field in java.lang.Thread class to TERMINATED. | 1536 // Thread is exiting. So set thread_status field in java.lang.Thread class to TERMINATED. |
1542 java_lang_Thread::set_thread_status(threadObj(), java_lang_Thread::TERMINATED); | 1537 java_lang_Thread::set_thread_status(threadObj(), java_lang_Thread::TERMINATED); |
1538 // Clear the native thread instance - this makes isAlive return false and allows the join() | |
1539 // to complete once we've done the notify_all below | |
1543 java_lang_Thread::set_thread(threadObj(), NULL); | 1540 java_lang_Thread::set_thread(threadObj(), NULL); |
1544 lock.notify_all(thread); | 1541 lock.notify_all(thread); |
1545 // Ignore pending exception (ThreadDeath), since we are exiting anyway | 1542 // Ignore pending exception (ThreadDeath), since we are exiting anyway |
1546 thread->clear_pending_exception(); | 1543 thread->clear_pending_exception(); |
1547 } | 1544 } |
1993 assert(SafepointSynchronize::is_at_safepoint(), "all threads are stopped"); | 1990 assert(SafepointSynchronize::is_at_safepoint(), "all threads are stopped"); |
1994 | 1991 |
1995 // Do not throw asynchronous exceptions against the compiler thread | 1992 // Do not throw asynchronous exceptions against the compiler thread |
1996 // (the compiler thread should not be a Java thread -- fix in 1.4.2) | 1993 // (the compiler thread should not be a Java thread -- fix in 1.4.2) |
1997 if (is_Compiler_thread()) return; | 1994 if (is_Compiler_thread()) return; |
1998 | |
1999 // This is a change from JDK 1.1, but JDK 1.2 will also do it: | |
2000 if (java_throwable->is_a(SystemDictionary::ThreadDeath_klass())) { | |
2001 java_lang_Thread::set_stillborn(threadObj()); | |
2002 } | |
2003 | 1995 |
2004 { | 1996 { |
2005 // Actually throw the Throwable against the target Thread - however | 1997 // Actually throw the Throwable against the target Thread - however |
2006 // only if there is no thread death exception installed already. | 1998 // only if there is no thread death exception installed already. |
2007 if (_pending_async_exception == NULL || !_pending_async_exception->is_a(SystemDictionary::ThreadDeath_klass())) { | 1999 if (_pending_async_exception == NULL || !_pending_async_exception->is_a(SystemDictionary::ThreadDeath_klass())) { |