We never clear a JavaThread's _threadObj.
If JavaThread is exiting the oop may be rubbish.
I think we should clear the field before removing us from the master threadslist.
Otherwise if you have a ThreadsList snapshot, you must always check is_exiting before touching the oop, which feels cumbersome.
But clearing may force you to always null check it instead.
Maybe we must try to keep the oop alive, which I really don't want to.
Crashing thread:
#9 <signal handler called>
#10 RawAccessBarrier<64ul>::load_internal<64ul, long> (addr=0x83a85000640)
at /home/rehn/source/jdk/vanilla-jdk/open/src/hotspot/share/oops/accessBackend.hpp:729
#11 RawAccessBarrier<64ul>::load<long> (addr=0x83a85000640) at /home/rehn/source/jdk/vanilla-jdk/open/src/hotspot/share/oops/accessBackend.hpp:344
#12 AccessInternal::PreRuntimeDispatch::load<544848ul, long> (addr=0x83a85000640)
at /home/rehn/source/jdk/vanilla-jdk/open/src/hotspot/share/oops/accessBackend.hpp:734
#13 AccessInternal::PreRuntimeDispatch::load_at<544848ul, long> (offset=<optimized out>, base=...)
at /home/rehn/source/jdk/vanilla-jdk/open/src/hotspot/share/oops/accessBackend.hpp:767
#14 AccessInternal::PreRuntimeDispatch::load_at<540752ul, long> (offset=<optimized out>, base=...)
at /home/rehn/source/jdk/vanilla-jdk/open/src/hotspot/share/oops/accessBackend.hpp:776
#15 AccessInternal::load_at<524288ul, long> (offset=<optimized out>, base=...)
at /home/rehn/source/jdk/vanilla-jdk/open/src/hotspot/share/oops/accessBackend.hpp:1190
#16 AccessInternal::LoadAtProxy<524288ul>::operator long<long>() const (this=0x7f91249323e0)
at /home/rehn/source/jdk/vanilla-jdk/open/src/hotspot/share/oops/accessBackend.hpp:1314
#17 oopDesc::long_field (this=<optimized out>, offset=<optimized out>) at /home/rehn/source/jdk/vanilla-jdk/open/src/hotspot/share/oops/oop.inline.hpp:282
--Type <RET> for more, q to quit, c to continue without paging--
#18 0x00007f93d58e53be in java_lang_Thread::thread_id (java_thread=...)
at /home/rehn/source/jdk/vanilla-jdk/open/src/hotspot/share/oops/oopsHierarchy.hpp:101
#19 0x00007f93d61f020f in ThreadsList::find_JavaThread_from_java_tid (this=0x7f90b83919b0, java_tid=99284)
at /home/rehn/source/jdk/vanilla-jdk/open/src/hotspot/share/oops/oopsHierarchy.hpp:86
#20 0x00007f93d5da9fd5 in do_thread_dump (dump_result=dump_result@entry=0x7f91249326a0, ids_ah=..., num_threads=num_threads@entry=352,
max_depth=max_depth@entry=-1, with_locked_monitors=with_locked_monitors@entry=false, with_locked_synchronizers=with_locked_synchronizers@entry=false,
__the_thread__=0x7f93d0a4f8b0) at /home/rehn/source/jdk/vanilla-jdk/open/src/hotspot/share/runtime/threadSMR.hpp:285
#21 0x00007f93d5daaaab in jmm_GetThreadInfo (env=<optimized out>, ids=<optimized out>, maxDepth=-1, infoArray=<optimized out>)
at /home/rehn/source/jdk/vanilla-jdk/open/src/hotspot/share/services/management.cpp:1112
The JavaThread whose oop we are trying to use:
#0 0x00007f93d6b3674d in __lll_lock_wait () from /lib64/libpthread.so.0
#1 0x00007f93d6b2fcf9 in pthread_mutex_lock () from /lib64/libpthread.so.0
#2 0x00007f93d5e81d28 in os::PlatformMutex::lock (this=0x7f93d0063fd0) at /home/rehn/source/jdk/vanilla-jdk/open/src/hotspot/os/posix/os_posix.hpp:279
#3 Mutex::lock_contended (this=this@entry=0x7f93d0063fc0, self=self@entry=0x7f8f40026da0) at /home/rehn/source/jdk/vanilla-jdk/open/src/hotspot/share/runtime/mutex.cpp:96
#4 0x00007f93d5e81efe in Mutex::lock (this=0x7f93d0063fc0, self=0x7f8f40026da0) at /home/rehn/source/jdk/vanilla-jdk/open/src/hotspot/share/runtime/mutex.cpp:109
#5 0x00007f93d61f2d37 in MutexLocker::MutexLocker (flag=Mutex::_safepoint_check_flag, mutex=0x7f93d0063fc0, this=<synthetic pointer>) at /home/rehn/source/jdk/vanilla-jdk/open/src/hotspot/share/runtime/mutexLocker.hpp:202
#6 ThreadsSMRSupport::smr_delete (thread=<optimized out>) at /home/rehn/source/jdk/vanilla-jdk/open/src/hotspot/share/runtime/threadSMR.cpp:965
#7 0x00007f93d61e26c0 in Thread::call_run (this=this@entry=0x7f8f40026da0) at /home/rehn/source/jdk/vanilla-jdk/open/src/hotspot/share/runtime/thread.cpp:409
#8 0x00007f93d5f14856 in thread_native_entry (thread=0x7f8f40026da0) at /home/rehn/source/jdk/vanilla-jdk/open/src/hotspot/os/linux/os_linux.cpp:789
#9 0x00007f93d6b2d4c0 in start_thread () from /lib64/libpthread.so.0
#10 0x00007f93d6a55163 in clone () from /lib64/libc.so.6