8377455: Replace LinkedList with GrowableArray in VM.ThreadDump's OMTable

Reviewed-by: dholmes, coleenp
This commit is contained in:
Johan Sjölen 2026-02-13 10:56:13 +00:00
parent 4e7106d891
commit 486ff5d3fc

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -51,6 +51,7 @@
#include "runtime/threadSMR.inline.hpp"
#include "runtime/vmOperations.hpp"
#include "services/threadService.hpp"
#include "utilities/growableArray.hpp"
#include "utilities/ticks.hpp"
#define VM_OP_NAME_INITIALIZE(name) #name,
@ -286,42 +287,27 @@ class ObjectMonitorsDump : public MonitorClosure, public ObjectMonitorsView {
}
private:
class ObjectMonitorLinkedList :
public LinkedListImpl<ObjectMonitor*,
AnyObj::C_HEAP, mtThread,
AllocFailStrategy::RETURN_NULL> {};
using ObjectMonitorList = GrowableArrayCHeap<ObjectMonitor*, mtThread>;
// HashTable SIZE is specified at compile time so we
// use 1031 which is the first prime after 1024.
typedef HashTable<int64_t, ObjectMonitorLinkedList*, 1031, AnyObj::C_HEAP, mtThread,
typedef HashTable<int64_t, ObjectMonitorList, 1031, AnyObj::C_HEAP, mtThread,
&ObjectMonitorsDump::ptr_hash> PtrTable;
PtrTable* _ptrs;
size_t _key_count;
size_t _om_count;
void add_list(int64_t key, ObjectMonitorLinkedList* list) {
_ptrs->put(key, list);
_key_count++;
}
ObjectMonitorLinkedList* get_list(int64_t key) {
ObjectMonitorLinkedList** listpp = _ptrs->get(key);
return (listpp == nullptr) ? nullptr : *listpp;
}
void add(ObjectMonitor* monitor) {
int64_t key = monitor->owner();
ObjectMonitorLinkedList* list = get_list(key);
if (list == nullptr) {
// Create new list and add it to the hash table:
list = new (mtThread) ObjectMonitorLinkedList;
_ptrs->put(key, list);
bool created = false;
ObjectMonitorList* list = _ptrs->put_if_absent(key, &created);
if (created) {
_key_count++;
}
assert(list->find(monitor) == nullptr, "Should not contain duplicates");
list->add(monitor); // Add the ObjectMonitor to the list.
assert(list->find(monitor) == -1, "Should not contain duplicates");
list->push(monitor); // Add the ObjectMonitor to the list.
_om_count++;
}
@ -332,17 +318,7 @@ class ObjectMonitorsDump : public MonitorClosure, public ObjectMonitorsView {
ObjectMonitorsDump() : _ptrs(new (mtThread) PtrTable), _key_count(0), _om_count(0) {}
~ObjectMonitorsDump() {
class CleanupObjectMonitorsDump: StackObj {
public:
bool do_entry(int64_t& key, ObjectMonitorLinkedList*& list) {
list->clear(); // clear the LinkListNodes
delete list; // then delete the LinkedList
return true;
}
} cleanup;
_ptrs->unlink(&cleanup); // cleanup the LinkedLists
delete _ptrs; // then delete the hash table
delete _ptrs;
}
// Implements MonitorClosure used to collect all owned monitors in the system
@ -368,11 +344,12 @@ class ObjectMonitorsDump : public MonitorClosure, public ObjectMonitorsView {
// Implements the ObjectMonitorsView interface
void visit(MonitorClosure* closure, JavaThread* thread) override {
int64_t key = ObjectMonitor::owner_id_from(thread);
ObjectMonitorLinkedList* list = get_list(key);
LinkedListIterator<ObjectMonitor*> iter(list != nullptr ? list->head() : nullptr);
while (!iter.is_empty()) {
ObjectMonitor* monitor = *iter.next();
closure->do_monitor(monitor);
ObjectMonitorList* list = _ptrs->get(key);
if (list == nullptr) {
return;
}
for (int i = 0; i < list->length(); i++) {
closure->do_monitor(list->at(i));
}
}