8273107: RunThese24H times out with "java.lang.management.ThreadInfo.getLockName()" is null

Reviewed-by: rehn, coleenp, eosterlund
This commit is contained in:
Daniel D. Daugherty 2021-12-17 21:24:51 +00:00
parent 8fbe1724e0
commit a5f5d60f25
8 changed files with 207 additions and 23 deletions

View file

@ -57,6 +57,40 @@
#include "utilities/events.hpp"
#include "utilities/preserveException.hpp"
class CleanupObjectMonitorsHashtable: StackObj {
public:
bool do_entry(void*& key, ObjectMonitorsHashtable::PtrList*& list) {
list->clear(); // clear the LinkListNodes
delete list; // then delete the LinkedList
return true;
}
};
ObjectMonitorsHashtable::~ObjectMonitorsHashtable() {
CleanupObjectMonitorsHashtable cleanup;
_ptrs->unlink(&cleanup); // cleanup the LinkedLists
delete _ptrs; // then delete the hash table
}
void ObjectMonitorsHashtable::add_entry(void* key, ObjectMonitor* om) {
ObjectMonitorsHashtable::PtrList* list = get_entry(key);
if (list == nullptr) {
// Create new list and add it to the hash table:
list = new (ResourceObj::C_HEAP, mtThread) ObjectMonitorsHashtable::PtrList();
add_entry(key, list);
}
list->add(om); // Add the ObjectMonitor to the list.
_om_count++;
}
bool ObjectMonitorsHashtable::has_entry(void* key, ObjectMonitor* om) {
ObjectMonitorsHashtable::PtrList* list = get_entry(key);
if (list == nullptr || list->find(om) == nullptr) {
return false;
}
return true;
}
void MonitorList::add(ObjectMonitor* m) {
ObjectMonitor* head;
do {
@ -992,11 +1026,18 @@ JavaThread* ObjectSynchronizer::get_lock_owner(ThreadsList * t_list, Handle h_ob
// Visitors ...
// Iterate ObjectMonitors where the owner == thread; this does NOT include
// ObjectMonitors where owner is set to a stack lock address in thread.
//
// This version of monitors_iterate() works with the in-use monitor list.
//
void ObjectSynchronizer::monitors_iterate(MonitorClosure* closure, JavaThread* thread) {
MonitorList::Iterator iter = _in_use_list.iterator();
while (iter.has_next()) {
ObjectMonitor* mid = iter.next();
if (mid->owner() != thread) {
// Not owned by the target thread and intentionally skips when owner
// is set to a stack lock address in the target thread.
continue;
}
if (!mid->is_being_async_deflated() && mid->object_peek() != NULL) {
@ -1013,6 +1054,31 @@ void ObjectSynchronizer::monitors_iterate(MonitorClosure* closure, JavaThread* t
}
}
// This version of monitors_iterate() works with the specified linked list.
//
void ObjectSynchronizer::monitors_iterate(MonitorClosure* closure,
ObjectMonitorsHashtable::PtrList* list,
JavaThread* thread) {
typedef LinkedListIterator<ObjectMonitor*> ObjectMonitorIterator;
ObjectMonitorIterator iter(list->head());
while (!iter.is_empty()) {
ObjectMonitor* mid = *iter.next();
// Owner set to a stack lock address in thread should never be seen here:
assert(mid->owner() == thread, "must be");
if (!mid->is_being_async_deflated() && mid->object_peek() != NULL) {
// Only process with closure if the object is set.
// monitors_iterate() is only called at a safepoint or when the
// target thread is suspended or when the target thread is
// operating on itself. The current closures in use today are
// only interested in an owned ObjectMonitor and ownership
// cannot be dropped under the calling contexts so the
// ObjectMonitor cannot be async deflated.
closure->do_monitor(mid);
}
}
}
static bool monitors_used_above_threshold(MonitorList* list) {
if (MonitorUsedDeflationThreshold == 0) { // disabled case is easy
return false;
@ -1338,8 +1404,17 @@ void ObjectSynchronizer::chk_for_block_req(JavaThread* current, const char* op_n
// Walk the in-use list and deflate (at most MonitorDeflationMax) idle
// ObjectMonitors. Returns the number of deflated ObjectMonitors.
//
// If table != nullptr, we gather owned ObjectMonitors indexed by the
// owner in the table. Please note that ObjectMonitors where the owner
// is set to a stack lock address are NOT associated with the JavaThread
// that holds that stack lock. All of the current consumers of
// ObjectMonitorsHashtable info only care about JNI locked monitors and
// those do not have the owner set to a stack lock address.
//
size_t ObjectSynchronizer::deflate_monitor_list(Thread* current, LogStream* ls,
elapsedTimer* timer_p) {
elapsedTimer* timer_p,
ObjectMonitorsHashtable* table) {
MonitorList::Iterator iter = _in_use_list.iterator();
size_t deflated_count = 0;
@ -1350,6 +1425,18 @@ size_t ObjectSynchronizer::deflate_monitor_list(Thread* current, LogStream* ls,
ObjectMonitor* mid = iter.next();
if (mid->deflate_monitor()) {
deflated_count++;
} else if (table != nullptr) {
// The caller is interested in the owned ObjectMonitors. This does
// not include when owner is set to a stack lock address in thread.
// This also does not capture unowned ObjectMonitors that cannot be
// deflated because of a waiter.
void* key = mid->owner();
// Since deflate_idle_monitors() and deflate_monitor_list() can be
// called more than once, we have to make sure the entry has not
// already been added.
if (key != nullptr && !table->has_entry(key, mid)) {
table->add_entry(key, mid);
}
}
if (current->is_Java_thread()) {
@ -1374,8 +1461,8 @@ class HandshakeForDeflation : public HandshakeClosure {
// This function is called by the MonitorDeflationThread to deflate
// ObjectMonitors. It is also called via do_final_audit_and_print_stats()
// by the VMThread.
size_t ObjectSynchronizer::deflate_idle_monitors() {
// and VM_ThreadDump::doit() by the VMThread.
size_t ObjectSynchronizer::deflate_idle_monitors(ObjectMonitorsHashtable* table) {
Thread* current = Thread::current();
if (current->is_Java_thread()) {
// The async deflation request has been processed.
@ -1400,7 +1487,7 @@ size_t ObjectSynchronizer::deflate_idle_monitors() {
}
// Deflate some idle ObjectMonitors.
size_t deflated_count = deflate_monitor_list(current, ls, &timer);
size_t deflated_count = deflate_monitor_list(current, ls, &timer, table);
if (deflated_count > 0 || is_final_audit()) {
// There are ObjectMonitors that have been deflated or this is the
// final audit and all the remaining ObjectMonitors have been
@ -1458,6 +1545,10 @@ size_t ObjectSynchronizer::deflate_idle_monitors() {
}
ls->print_cr("end deflating: in_use_list stats: ceiling=" SIZE_FORMAT ", count=" SIZE_FORMAT ", max=" SIZE_FORMAT,
in_use_list_ceiling(), _in_use_list.count(), _in_use_list.max());
if (table != nullptr) {
ls->print_cr("ObjectMonitorsHashtable: key_count=" SIZE_FORMAT ", om_count=" SIZE_FORMAT,
table->key_count(), table->om_count());
}
}
OM_PERFDATA_OP(MonExtant, set_value(_in_use_list.count()));
@ -1560,7 +1651,7 @@ void ObjectSynchronizer::do_final_audit_and_print_stats() {
// Do a deflation in order to reduce the in-use monitor population
// that is reported by ObjectSynchronizer::log_in_use_monitor_details()
// which is called by ObjectSynchronizer::audit_and_print_stats().
while (ObjectSynchronizer::deflate_idle_monitors() != 0) {
while (ObjectSynchronizer::deflate_idle_monitors(/* ObjectMonitorsHashtable is not needed here */ nullptr) >= (size_t)MonitorDeflationMax) {
; // empty
}
// The other audit_and_print_stats() call is done at the Debug