From 2865afe759fd5362abd0947fd4c1f5c8d3519ca3 Mon Sep 17 00:00:00 2001 From: Coleen Phillimore Date: Fri, 19 Jan 2024 16:54:03 +0000 Subject: [PATCH] 8323685: PrintSystemDictionaryAtExit has mutex rank assert Co-authored-by: Thomas Schatzl Reviewed-by: tschatzl, ayang --- src/hotspot/share/gc/g1/g1CardSet.cpp | 7 +++- src/hotspot/share/gc/g1/g1CodeRootSet.cpp | 8 ++-- .../share/utilities/concurrentHashTable.hpp | 8 ++-- .../utilities/concurrentHashTable.inline.hpp | 7 ++-- .../utilities/test_concurrentHashtable.cpp | 4 +- .../ClassfilePrintingTests.java} | 37 ++++++++++++++++--- 6 files changed, 51 insertions(+), 20 deletions(-) rename test/hotspot/jtreg/runtime/{PrintStringTableStats/PrintStringTableStatsTest.java => PrintingTests/ClassfilePrintingTests.java} (57%) diff --git a/src/hotspot/share/gc/g1/g1CardSet.cpp b/src/hotspot/share/gc/g1/g1CardSet.cpp index 58ae441f51f..e6b2d5029e5 100644 --- a/src/hotspot/share/gc/g1/g1CardSet.cpp +++ b/src/hotspot/share/gc/g1/g1CardSet.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2024, 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 @@ -286,7 +286,10 @@ public: size_t initial_log_table_size = InitialLogTableSize) : _inserted_card(false), _mm(mm), - _table(mm, initial_log_table_size, false), + _table(Mutex::service-1, + mm, + initial_log_table_size, + false /* enable_statistics */), _table_scanner(&_table, BucketClaimSize) { } diff --git a/src/hotspot/share/gc/g1/g1CodeRootSet.cpp b/src/hotspot/share/gc/g1/g1CodeRootSet.cpp index 3b933dfa7f9..a1eb7b8543a 100644 --- a/src/hotspot/share/gc/g1/g1CodeRootSet.cpp +++ b/src/hotspot/share/gc/g1/g1CodeRootSet.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2024, 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 @@ -84,8 +84,10 @@ class G1CodeRootSetHashTable : public CHeapObj { public: G1CodeRootSetHashTable() : - _table(Log2DefaultNumBuckets, - HashTable::DEFAULT_MAX_SIZE_LOG2), + _table(Mutex::service-1, + nullptr, + Log2DefaultNumBuckets, + false /* enable_statistics */), _table_scanner(&_table, BucketClaimSize), _num_entries(0) { clear(); } diff --git a/src/hotspot/share/utilities/concurrentHashTable.hpp b/src/hotspot/share/utilities/concurrentHashTable.hpp index 0336f06916b..fe6fdb0a95e 100644 --- a/src/hotspot/share/utilities/concurrentHashTable.hpp +++ b/src/hotspot/share/utilities/concurrentHashTable.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2024, 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 @@ -26,6 +26,7 @@ #define SHARE_UTILITIES_CONCURRENTHASHTABLE_HPP #include "memory/allocation.hpp" +#include "runtime/mutex.hpp" #include "utilities/globalCounter.hpp" #include "utilities/globalDefinitions.hpp" #include "utilities/growableArray.hpp" @@ -406,10 +407,11 @@ class ConcurrentHashTable : public CHeapObj { size_t log2size_limit = DEFAULT_MAX_SIZE_LOG2, size_t grow_hint = DEFAULT_GROW_HINT, bool enable_statistics = DEFAULT_ENABLE_STATISTICS, + Mutex::Rank rank = Mutex::nosafepoint-2, void* context = nullptr); - explicit ConcurrentHashTable(void* context, size_t log2size = DEFAULT_START_SIZE_LOG2, bool enable_statistics = DEFAULT_ENABLE_STATISTICS) : - ConcurrentHashTable(log2size, DEFAULT_MAX_SIZE_LOG2, DEFAULT_GROW_HINT, enable_statistics, context) {} + explicit ConcurrentHashTable(Mutex::Rank rank, void* context, size_t log2size = DEFAULT_START_SIZE_LOG2, bool enable_statistics = DEFAULT_ENABLE_STATISTICS) : + ConcurrentHashTable(log2size, DEFAULT_MAX_SIZE_LOG2, DEFAULT_GROW_HINT, enable_statistics, rank, context) {} ~ConcurrentHashTable(); diff --git a/src/hotspot/share/utilities/concurrentHashTable.inline.hpp b/src/hotspot/share/utilities/concurrentHashTable.inline.hpp index ee9e7c4bfc8..13c219da212 100644 --- a/src/hotspot/share/utilities/concurrentHashTable.inline.hpp +++ b/src/hotspot/share/utilities/concurrentHashTable.inline.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2024, 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 @@ -1012,7 +1012,7 @@ inline size_t ConcurrentHashTable:: // Constructor template inline ConcurrentHashTable:: -ConcurrentHashTable(size_t log2size, size_t log2size_limit, size_t grow_hint, bool enable_statistics, void* context) +ConcurrentHashTable(size_t log2size, size_t log2size_limit, size_t grow_hint, bool enable_statistics, Mutex::Rank rank, void* context) : _context(context), _new_table(nullptr), _log2_size_limit(log2size_limit), _log2_start_size(log2size), _grow_hint(grow_hint), _size_limit_reached(false), _resize_lock_owner(nullptr), @@ -1023,8 +1023,7 @@ ConcurrentHashTable(size_t log2size, size_t log2size_limit, size_t grow_hint, bo } else { _stats_rate = nullptr; } - _resize_lock = - new Mutex(Mutex::service-1, "ConcurrentHashTableResize_lock"); + _resize_lock = new Mutex(rank, "ConcurrentHashTableResize_lock"); _table = new InternalTable(log2size); assert(log2size_limit >= log2size, "bad ergo"); _size_limit_reached = _table->_log2_size == _log2_size_limit; diff --git a/test/hotspot/gtest/utilities/test_concurrentHashtable.cpp b/test/hotspot/gtest/utilities/test_concurrentHashtable.cpp index ca41fc6b0f1..277b2c37b61 100644 --- a/test/hotspot/gtest/utilities/test_concurrentHashtable.cpp +++ b/test/hotspot/gtest/utilities/test_concurrentHashtable.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2024, 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 @@ -322,7 +322,7 @@ static void cht_reset_shrink(Thread* thr) { Allocator mem_allocator; const uint initial_log_table_size = 4; - CustomTestTable* cht = new CustomTestTable(&mem_allocator); + CustomTestTable* cht = new CustomTestTable(Mutex::nosafepoint-2, &mem_allocator); cht_insert_and_find(thr, cht, val1); cht_insert_and_find(thr, cht, val2); diff --git a/test/hotspot/jtreg/runtime/PrintStringTableStats/PrintStringTableStatsTest.java b/test/hotspot/jtreg/runtime/PrintingTests/ClassfilePrintingTests.java similarity index 57% rename from test/hotspot/jtreg/runtime/PrintStringTableStats/PrintStringTableStatsTest.java rename to test/hotspot/jtreg/runtime/PrintingTests/ClassfilePrintingTests.java index 4dfde2f1d0b..175d28cc56e 100644 --- a/test/hotspot/jtreg/runtime/PrintStringTableStats/PrintStringTableStatsTest.java +++ b/test/hotspot/jtreg/runtime/PrintingTests/ClassfilePrintingTests.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2024, 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 @@ -23,17 +23,25 @@ import jdk.test.lib.process.ProcessTools; import jdk.test.lib.process.OutputAnalyzer; +import jdk.test.lib.Platform; /* - * @test PrintStringTableStatsTest - * @bug 8211821 + * @test + * @summary Test various printing functions in classfile directory + * @bug 8211821 8323685 * @requires vm.flagless * @library /test/lib - * @run driver PrintStringTableStatsTest + * @run driver ClassfilePrintingTests */ -public class PrintStringTableStatsTest { - public static void main(String... args) throws Exception { +class SampleClass { + public static void main(java.lang.String[] unused) { + System.out.println("Hello from the sample class"); + } +} + +public class ClassfilePrintingTests { + private static void printStringTableStatsTest() throws Exception { ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder( "-XX:+PrintStringTableStatistics", "--version"); @@ -41,4 +49,21 @@ public class PrintStringTableStatsTest { output.shouldContain("Number of buckets"); output.shouldHaveExitValue(0); } + + private static void printSystemDictionaryAtExitTest() throws Exception { + ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder( + "-XX:+PrintSystemDictionaryAtExit", + "SampleClass"); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldContain(SampleClass.class.getName()); + output.shouldContain("jdk/internal/loader/ClassLoaders$AppClassLoader"); + output.shouldHaveExitValue(0); + } + + public static void main(String... args) throws Exception { + printStringTableStatsTest(); + if (Platform.isDebugBuild()) { + printSystemDictionaryAtExitTest(); + } + } }