A deadlock can happen when a relocating thread holds the lock and tries to log information about the current thread, which can trigger a load barrier and a secondary relocation. The first relocation is holding the _ref_lock and the second relocation hangs when trying to reacquiring it. This is the stack trace:
#1 0x00007ff375c1fc90 in os::PlatformMonitor::wait
#2 0x00007ff3760cbf92 in ZForwarding::wait_page_released
#3 0x00007ff376118065 in ZRelocate::relocate_object
#4 0x00007ff374f7097b in AccessInternal::PostRuntimeDispatch<ZBarrierSet::AccessBarrier<286790ul, ZBarrierSet>,
#5 0x00007ff375176134 in oopDesc::obj_field
#6 0x00007ff37551c5cb in java_lang_Thread::name
#7 0x00007ff375f2e7ee in JavaThread::get_thread_name_string
#8 0x00007ff376126323 in ZStatPhase::log_end
#9 0x00007ff3761272e8 in ZStatCriticalPhase::register_end
#10 0x00007ff3760cc0b0 in ZForwarding::wait_page_released
#11 0x00007ff376118065 in ZRelocate::relocate_object
#12 0x00007ff3760989c5 in ZLoadBarrierOopClosure::do_oop
#13 0x00007ff375408ca8 in HandleArea::oops_do
#14 0x00007ff375f2e0e9 in JavaThread::oops_do_no_frames
This started to happen after:
8261759: ZGC: ZWorker Threads Continue Marking After System.exit() called