From 94800781eae192d3e82f5635d4aad165f11eabc1 Mon Sep 17 00:00:00 2001 From: Albert Mingkun Yang Date: Tue, 12 Sep 2023 07:40:29 +0000 Subject: [PATCH] 8315550: G1: Fix -Wconversion warnings in g1NUMA Reviewed-by: tschatzl, iwalulya --- src/hotspot/share/gc/g1/g1CollectedHeap.cpp | 4 +-- src/hotspot/share/gc/g1/g1HeapTransition.cpp | 4 +-- src/hotspot/share/gc/g1/g1NUMA.cpp | 31 ++++++++++---------- src/hotspot/share/gc/g1/g1NUMA.hpp | 10 +++---- src/hotspot/share/gc/g1/g1NUMAStats.cpp | 2 +- src/hotspot/share/gc/g1/g1NUMAStats.hpp | 4 +-- src/hotspot/share/gc/g1/heapRegion.cpp | 2 +- src/hotspot/share/prims/whitebox.cpp | 6 ++-- 8 files changed, 31 insertions(+), 32 deletions(-) diff --git a/src/hotspot/share/gc/g1/g1CollectedHeap.cpp b/src/hotspot/share/gc/g1/g1CollectedHeap.cpp index fc3af65bf70..dc97b715b91 100644 --- a/src/hotspot/share/gc/g1/g1CollectedHeap.cpp +++ b/src/hotspot/share/gc/g1/g1CollectedHeap.cpp @@ -2216,10 +2216,10 @@ void G1CollectedHeap::print_on(outputStream* st) const { if (_numa->is_enabled()) { uint num_nodes = _numa->num_active_nodes(); st->print(" remaining free region(s) on each NUMA node: "); - const int* node_ids = _numa->node_ids(); + const uint* node_ids = _numa->node_ids(); for (uint node_index = 0; node_index < num_nodes; node_index++) { uint num_free_regions = _hrm.num_free_regions(node_index); - st->print("%d=%u ", node_ids[node_index], num_free_regions); + st->print("%u=%u ", node_ids[node_index], num_free_regions); } st->cr(); } diff --git a/src/hotspot/share/gc/g1/g1HeapTransition.cpp b/src/hotspot/share/gc/g1/g1HeapTransition.cpp index baead337d83..49ba19dfdba 100644 --- a/src/hotspot/share/gc/g1/g1HeapTransition.cpp +++ b/src/hotspot/share/gc/g1/g1HeapTransition.cpp @@ -115,10 +115,10 @@ static void log_regions(const char* msg, size_t before_length, size_t after_leng if (before_per_node_length != nullptr && after_per_node_length != nullptr) { G1NUMA* numa = G1NUMA::numa(); uint num_nodes = numa->num_active_nodes(); - const int* node_ids = numa->node_ids(); + const uint* node_ids = numa->node_ids(); ls.print(" ("); for (uint i = 0; i < num_nodes; i++) { - ls.print("%d: %u->%u", node_ids[i], before_per_node_length[i], after_per_node_length[i]); + ls.print("%u: %u->%u", node_ids[i], before_per_node_length[i], after_per_node_length[i]); // Skip adding below if it is the last one. if (i != num_nodes - 1) { ls.print(", "); diff --git a/src/hotspot/share/gc/g1/g1NUMA.cpp b/src/hotspot/share/gc/g1/g1NUMA.cpp index c94dbc32bc6..a275c9d6872 100644 --- a/src/hotspot/share/gc/g1/g1NUMA.cpp +++ b/src/hotspot/share/gc/g1/g1NUMA.cpp @@ -58,12 +58,11 @@ G1NUMA* G1NUMA::create() { } // Returns memory node ids -const int* G1NUMA::node_ids() const { +const uint* G1NUMA::node_ids() const { return _node_ids; } -uint G1NUMA::index_of_node_id(int node_id) const { - assert(node_id >= 0, "invalid node id %d", node_id); +uint G1NUMA::index_of_node_id(uint node_id) const { assert(node_id < _len_node_id_to_index_map, "invalid node id %d", node_id); uint node_index = _node_id_to_index_map[node_id]; assert(node_index != G1NUMA::UnknownNodeIndex, @@ -80,7 +79,7 @@ G1NUMA::G1NUMA() : void G1NUMA::initialize_without_numa() { // If NUMA is not enabled or supported, initialize as having a single node. _num_active_node_ids = 1; - _node_ids = NEW_C_HEAP_ARRAY(int, _num_active_node_ids, mtGC); + _node_ids = NEW_C_HEAP_ARRAY(uint, _num_active_node_ids, mtGC); _node_ids[0] = 0; // Map index 0 to node 0 _len_node_id_to_index_map = 1; @@ -98,10 +97,10 @@ void G1NUMA::initialize(bool use_numa) { size_t num_node_ids = os::numa_get_groups_num(); // Create an array of active node ids. - _node_ids = NEW_C_HEAP_ARRAY(int, num_node_ids, mtGC); - _num_active_node_ids = (uint)os::numa_get_leaf_groups(_node_ids, num_node_ids); + _node_ids = NEW_C_HEAP_ARRAY(uint, num_node_ids, mtGC); + _num_active_node_ids = checked_cast(os::numa_get_leaf_groups(reinterpret_cast(_node_ids), num_node_ids)); - int max_node_id = 0; + uint max_node_id = 0; for (uint i = 0; i < _num_active_node_ids; i++) { max_node_id = MAX2(max_node_id, _node_ids[i]); } @@ -111,7 +110,7 @@ void G1NUMA::initialize(bool use_numa) { _node_id_to_index_map = NEW_C_HEAP_ARRAY(uint, _len_node_id_to_index_map, mtGC); // Set all indices with unknown node id. - for (int i = 0; i < _len_node_id_to_index_map; i++) { + for (uint i = 0; i < _len_node_id_to_index_map; i++) { _node_id_to_index_map[i] = G1NUMA::UnknownNodeIndex; } @@ -125,8 +124,8 @@ void G1NUMA::initialize(bool use_numa) { G1NUMA::~G1NUMA() { delete _stats; - FREE_C_HEAP_ARRAY(int, _node_id_to_index_map); - FREE_C_HEAP_ARRAY(int, _node_ids); + FREE_C_HEAP_ARRAY(uint, _node_id_to_index_map); + FREE_C_HEAP_ARRAY(uint, _node_ids); } void G1NUMA::set_region_info(size_t region_size, size_t page_size) { @@ -159,7 +158,7 @@ uint G1NUMA::preferred_node_index_for_index(uint region_index) const { } } -int G1NUMA::numa_id(int index) const { +uint G1NUMA::numa_id(uint index) const { assert(index < _len_node_id_to_index_map, "Index %d out of range: [0,%d)", index, _len_node_id_to_index_map); return _node_ids[index]; @@ -170,7 +169,7 @@ uint G1NUMA::index_of_address(HeapWord *address) const { if (numa_id == -1) { return UnknownNodeIndex; } else { - return index_of_node_id(numa_id); + return index_of_node_id(checked_cast(numa_id)); } } @@ -218,9 +217,9 @@ void G1NUMA::request_memory_on_node(void* aligned_address, size_t size_in_bytes, assert(is_aligned(aligned_address, page_size()), "Given address (" PTR_FORMAT ") should be aligned.", p2i(aligned_address)); assert(is_aligned(size_in_bytes, page_size()), "Given size (" SIZE_FORMAT ") should be aligned.", size_in_bytes); - log_trace(gc, heap, numa)("Request memory [" PTR_FORMAT ", " PTR_FORMAT ") to be NUMA id (%d)", + log_trace(gc, heap, numa)("Request memory [" PTR_FORMAT ", " PTR_FORMAT ") to be NUMA id (%u)", p2i(aligned_address), p2i((char*)aligned_address + size_in_bytes), _node_ids[node_index]); - os::numa_make_local((char*)aligned_address, size_in_bytes, _node_ids[node_index]); + os::numa_make_local((char*)aligned_address, size_in_bytes, checked_cast(_node_ids[node_index])); } uint G1NUMA::max_search_depth() const { @@ -279,9 +278,9 @@ G1NodeIndexCheckClosure::G1NodeIndexCheckClosure(const char* desc, G1NUMA* numa, G1NodeIndexCheckClosure::~G1NodeIndexCheckClosure() { _ls->print("%s: NUMA region verification (id: matched/mismatched/total): ", _desc); - const int* numa_ids = _numa->node_ids(); + const uint* numa_ids = _numa->node_ids(); for (uint i = 0; i < _numa->num_active_nodes(); i++) { - _ls->print("%d: %u/%u/%u ", numa_ids[i], _matched[i], _mismatched[i], _total[i]); + _ls->print("%u: %u/%u/%u ", numa_ids[i], _matched[i], _mismatched[i], _total[i]); } FREE_C_HEAP_ARRAY(uint, _matched); diff --git a/src/hotspot/share/gc/g1/g1NUMA.hpp b/src/hotspot/share/gc/g1/g1NUMA.hpp index 83117b8ec14..acf5a114aeb 100644 --- a/src/hotspot/share/gc/g1/g1NUMA.hpp +++ b/src/hotspot/share/gc/g1/g1NUMA.hpp @@ -39,10 +39,10 @@ class G1NUMA: public CHeapObj { // For invalid node id, return UnknownNodeIndex. uint* _node_id_to_index_map; // Length of _num_active_node_ids_id to index map. - int _len_node_id_to_index_map; + uint _len_node_id_to_index_map; // Current active node ids. - int* _node_ids; + uint* _node_ids; // Total number of node ids. uint _num_active_node_ids; @@ -59,7 +59,7 @@ class G1NUMA: public CHeapObj { // Returns node index of the given node id. // Precondition: node_id is an active node id. - inline uint index_of_node_id(int node_id) const; + inline uint index_of_node_id(uint node_id) const; static G1NUMA* _inst; @@ -86,10 +86,10 @@ public: bool is_enabled() const; - int numa_id(int index) const; + uint numa_id(uint index) const; // Returns memory node ids - const int* node_ids() const; + const uint* node_ids() const; // Returns node index of current calling thread. uint index_of_current_thread() const; diff --git a/src/hotspot/share/gc/g1/g1NUMAStats.cpp b/src/hotspot/share/gc/g1/g1NUMAStats.cpp index e674868401a..089e4c0e8b8 100644 --- a/src/hotspot/share/gc/g1/g1NUMAStats.cpp +++ b/src/hotspot/share/gc/g1/g1NUMAStats.cpp @@ -119,7 +119,7 @@ void G1NUMAStats::NodeDataArray::copy(uint req_index, size_t* stat) { } } -G1NUMAStats::G1NUMAStats(const int* node_ids, uint num_node_ids) : +G1NUMAStats::G1NUMAStats(const uint* node_ids, uint num_node_ids) : _node_ids(node_ids), _num_node_ids(num_node_ids), _node_data() { assert(_num_node_ids > 1, "Should have at least one node id: %u", _num_node_ids); diff --git a/src/hotspot/share/gc/g1/g1NUMAStats.hpp b/src/hotspot/share/gc/g1/g1NUMAStats.hpp index fba9442c800..22997ea1358 100644 --- a/src/hotspot/share/gc/g1/g1NUMAStats.hpp +++ b/src/hotspot/share/gc/g1/g1NUMAStats.hpp @@ -91,7 +91,7 @@ public: }; private: - const int* _node_ids; + const uint* _node_ids; uint _num_node_ids; NodeDataArray* _node_data[NodeDataItemsSentinel]; @@ -101,7 +101,7 @@ private: void print_mutator_alloc_stat_debug(); public: - G1NUMAStats(const int* node_ids, uint num_node_ids); + G1NUMAStats(const uint* node_ids, uint num_node_ids); ~G1NUMAStats(); void clear(G1NUMAStats::NodeDataItems phase); diff --git a/src/hotspot/share/gc/g1/heapRegion.cpp b/src/hotspot/share/gc/g1/heapRegion.cpp index 50b9f25242e..bddff5bc44e 100644 --- a/src/hotspot/share/gc/g1/heapRegion.cpp +++ b/src/hotspot/share/gc/g1/heapRegion.cpp @@ -427,7 +427,7 @@ void HeapRegion::print_on(outputStream* st) const { if (UseNUMA) { G1NUMA* numa = G1NUMA::numa(); if (node_index() < numa->num_active_nodes()) { - st->print("|%d", numa->numa_id(node_index())); + st->print("|%u", numa->numa_id(node_index())); } else { st->print("|-"); } diff --git a/src/hotspot/share/prims/whitebox.cpp b/src/hotspot/share/prims/whitebox.cpp index c64f6981cad..8c8469e9a47 100644 --- a/src/hotspot/share/prims/whitebox.cpp +++ b/src/hotspot/share/prims/whitebox.cpp @@ -585,12 +585,12 @@ WB_END WB_ENTRY(jintArray, WB_G1MemoryNodeIds(JNIEnv* env, jobject o)) if (UseG1GC) { G1NUMA* numa = G1NUMA::numa(); - int num_node_ids = (int)numa->num_active_nodes(); - const int* node_ids = numa->node_ids(); + int num_node_ids = checked_cast(numa->num_active_nodes()); + const uint* node_ids = numa->node_ids(); typeArrayOop result = oopFactory::new_intArray(num_node_ids, CHECK_NULL); for (int i = 0; i < num_node_ids; i++) { - result->int_at_put(i, (jint)node_ids[i]); + result->int_at_put(i, checked_cast(node_ids[i])); } return (jintArray) JNIHandles::make_local(THREAD, result); }