11/*
2- * Copyright (c) 1997, 2025 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 1997, 2026 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
5151#include " runtime/threadSMR.inline.hpp"
5252#include " runtime/vmOperations.hpp"
5353#include " services/threadService.hpp"
54+ #include " utilities/growableArray.hpp"
5455#include " utilities/ticks.hpp"
5556
5657#define VM_OP_NAME_INITIALIZE (name ) #name,
@@ -286,42 +287,27 @@ class ObjectMonitorsDump : public MonitorClosure, public ObjectMonitorsView {
286287 }
287288
288289 private:
289- class ObjectMonitorLinkedList :
290- public LinkedListImpl<ObjectMonitor*,
291- AnyObj::C_HEAP, mtThread,
292- AllocFailStrategy::RETURN_NULL> {};
290+ using ObjectMonitorList = GrowableArrayCHeap<ObjectMonitor*, mtThread>;
293291
294292 // HashTable SIZE is specified at compile time so we
295293 // use 1031 which is the first prime after 1024.
296- typedef HashTable<int64_t , ObjectMonitorLinkedList* , 1031 , AnyObj::C_HEAP, mtThread,
294+ typedef HashTable<int64_t , ObjectMonitorList , 1031 , AnyObj::C_HEAP, mtThread,
297295 &ObjectMonitorsDump::ptr_hash> PtrTable;
298296 PtrTable* _ptrs;
299297 size_t _key_count;
300298 size_t _om_count;
301299
302- void add_list (int64_t key, ObjectMonitorLinkedList* list) {
303- _ptrs->put (key, list);
304- _key_count++;
305- }
306-
307- ObjectMonitorLinkedList* get_list (int64_t key) {
308- ObjectMonitorLinkedList** listpp = _ptrs->get (key);
309- return (listpp == nullptr ) ? nullptr : *listpp;
310- }
311-
312300 void add (ObjectMonitor* monitor) {
313301 int64_t key = monitor->owner ();
314302
315- ObjectMonitorLinkedList* list = get_list (key);
316- if (list == nullptr ) {
317- // Create new list and add it to the hash table:
318- list = new (mtThread) ObjectMonitorLinkedList;
319- _ptrs->put (key, list);
303+ bool created = false ;
304+ ObjectMonitorList* list = _ptrs->put_if_absent (key, &created);
305+ if (created) {
320306 _key_count++;
321307 }
322308
323- assert (list->find (monitor) == nullptr , " Should not contain duplicates" );
324- list->add (monitor); // Add the ObjectMonitor to the list.
309+ assert (list->find (monitor) == - 1 , " Should not contain duplicates" );
310+ list->push (monitor); // Add the ObjectMonitor to the list.
325311 _om_count++;
326312 }
327313
@@ -332,17 +318,7 @@ class ObjectMonitorsDump : public MonitorClosure, public ObjectMonitorsView {
332318 ObjectMonitorsDump () : _ptrs(new (mtThread) PtrTable), _key_count(0 ), _om_count(0 ) {}
333319
334320 ~ObjectMonitorsDump () {
335- class CleanupObjectMonitorsDump : StackObj {
336- public:
337- bool do_entry (int64_t & key, ObjectMonitorLinkedList*& list) {
338- list->clear (); // clear the LinkListNodes
339- delete list; // then delete the LinkedList
340- return true ;
341- }
342- } cleanup;
343-
344- _ptrs->unlink (&cleanup); // cleanup the LinkedLists
345- delete _ptrs; // then delete the hash table
321+ delete _ptrs;
346322 }
347323
348324 // Implements MonitorClosure used to collect all owned monitors in the system
@@ -368,11 +344,12 @@ class ObjectMonitorsDump : public MonitorClosure, public ObjectMonitorsView {
368344 // Implements the ObjectMonitorsView interface
369345 void visit (MonitorClosure* closure, JavaThread* thread) override {
370346 int64_t key = ObjectMonitor::owner_id_from (thread);
371- ObjectMonitorLinkedList* list = get_list (key);
372- LinkedListIterator<ObjectMonitor*> iter (list != nullptr ? list->head () : nullptr );
373- while (!iter.is_empty ()) {
374- ObjectMonitor* monitor = *iter.next ();
375- closure->do_monitor (monitor);
347+ ObjectMonitorList* list = _ptrs->get (key);
348+ if (list == nullptr ) {
349+ return ;
350+ }
351+ for (int i = 0 ; i < list->length (); i++) {
352+ closure->do_monitor (list->at (i));
376353 }
377354 }
378355
0 commit comments