Skip to content

Commit 9480078

Browse files
committed
8315550: G1: Fix -Wconversion warnings in g1NUMA
Reviewed-by: tschatzl, iwalulya
1 parent d08258f commit 9480078

File tree

8 files changed

+31
-32
lines changed

8 files changed

+31
-32
lines changed

src/hotspot/share/gc/g1/g1CollectedHeap.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2216,10 +2216,10 @@ void G1CollectedHeap::print_on(outputStream* st) const {
22162216
if (_numa->is_enabled()) {
22172217
uint num_nodes = _numa->num_active_nodes();
22182218
st->print(" remaining free region(s) on each NUMA node: ");
2219-
const int* node_ids = _numa->node_ids();
2219+
const uint* node_ids = _numa->node_ids();
22202220
for (uint node_index = 0; node_index < num_nodes; node_index++) {
22212221
uint num_free_regions = _hrm.num_free_regions(node_index);
2222-
st->print("%d=%u ", node_ids[node_index], num_free_regions);
2222+
st->print("%u=%u ", node_ids[node_index], num_free_regions);
22232223
}
22242224
st->cr();
22252225
}

src/hotspot/share/gc/g1/g1HeapTransition.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@ static void log_regions(const char* msg, size_t before_length, size_t after_leng
115115
if (before_per_node_length != nullptr && after_per_node_length != nullptr) {
116116
G1NUMA* numa = G1NUMA::numa();
117117
uint num_nodes = numa->num_active_nodes();
118-
const int* node_ids = numa->node_ids();
118+
const uint* node_ids = numa->node_ids();
119119
ls.print(" (");
120120
for (uint i = 0; i < num_nodes; i++) {
121-
ls.print("%d: %u->%u", node_ids[i], before_per_node_length[i], after_per_node_length[i]);
121+
ls.print("%u: %u->%u", node_ids[i], before_per_node_length[i], after_per_node_length[i]);
122122
// Skip adding below if it is the last one.
123123
if (i != num_nodes - 1) {
124124
ls.print(", ");

src/hotspot/share/gc/g1/g1NUMA.cpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,11 @@ G1NUMA* G1NUMA::create() {
5858
}
5959

6060
// Returns memory node ids
61-
const int* G1NUMA::node_ids() const {
61+
const uint* G1NUMA::node_ids() const {
6262
return _node_ids;
6363
}
6464

65-
uint G1NUMA::index_of_node_id(int node_id) const {
66-
assert(node_id >= 0, "invalid node id %d", node_id);
65+
uint G1NUMA::index_of_node_id(uint node_id) const {
6766
assert(node_id < _len_node_id_to_index_map, "invalid node id %d", node_id);
6867
uint node_index = _node_id_to_index_map[node_id];
6968
assert(node_index != G1NUMA::UnknownNodeIndex,
@@ -80,7 +79,7 @@ G1NUMA::G1NUMA() :
8079
void G1NUMA::initialize_without_numa() {
8180
// If NUMA is not enabled or supported, initialize as having a single node.
8281
_num_active_node_ids = 1;
83-
_node_ids = NEW_C_HEAP_ARRAY(int, _num_active_node_ids, mtGC);
82+
_node_ids = NEW_C_HEAP_ARRAY(uint, _num_active_node_ids, mtGC);
8483
_node_ids[0] = 0;
8584
// Map index 0 to node 0
8685
_len_node_id_to_index_map = 1;
@@ -98,10 +97,10 @@ void G1NUMA::initialize(bool use_numa) {
9897
size_t num_node_ids = os::numa_get_groups_num();
9998

10099
// Create an array of active node ids.
101-
_node_ids = NEW_C_HEAP_ARRAY(int, num_node_ids, mtGC);
102-
_num_active_node_ids = (uint)os::numa_get_leaf_groups(_node_ids, num_node_ids);
100+
_node_ids = NEW_C_HEAP_ARRAY(uint, num_node_ids, mtGC);
101+
_num_active_node_ids = checked_cast<uint>(os::numa_get_leaf_groups(reinterpret_cast<int*>(_node_ids), num_node_ids));
103102

104-
int max_node_id = 0;
103+
uint max_node_id = 0;
105104
for (uint i = 0; i < _num_active_node_ids; i++) {
106105
max_node_id = MAX2(max_node_id, _node_ids[i]);
107106
}
@@ -111,7 +110,7 @@ void G1NUMA::initialize(bool use_numa) {
111110
_node_id_to_index_map = NEW_C_HEAP_ARRAY(uint, _len_node_id_to_index_map, mtGC);
112111

113112
// Set all indices with unknown node id.
114-
for (int i = 0; i < _len_node_id_to_index_map; i++) {
113+
for (uint i = 0; i < _len_node_id_to_index_map; i++) {
115114
_node_id_to_index_map[i] = G1NUMA::UnknownNodeIndex;
116115
}
117116

@@ -125,8 +124,8 @@ void G1NUMA::initialize(bool use_numa) {
125124

126125
G1NUMA::~G1NUMA() {
127126
delete _stats;
128-
FREE_C_HEAP_ARRAY(int, _node_id_to_index_map);
129-
FREE_C_HEAP_ARRAY(int, _node_ids);
127+
FREE_C_HEAP_ARRAY(uint, _node_id_to_index_map);
128+
FREE_C_HEAP_ARRAY(uint, _node_ids);
130129
}
131130

132131
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 {
159158
}
160159
}
161160

162-
int G1NUMA::numa_id(int index) const {
161+
uint G1NUMA::numa_id(uint index) const {
163162
assert(index < _len_node_id_to_index_map, "Index %d out of range: [0,%d)",
164163
index, _len_node_id_to_index_map);
165164
return _node_ids[index];
@@ -170,7 +169,7 @@ uint G1NUMA::index_of_address(HeapWord *address) const {
170169
if (numa_id == -1) {
171170
return UnknownNodeIndex;
172171
} else {
173-
return index_of_node_id(numa_id);
172+
return index_of_node_id(checked_cast<uint>(numa_id));
174173
}
175174
}
176175

@@ -218,9 +217,9 @@ void G1NUMA::request_memory_on_node(void* aligned_address, size_t size_in_bytes,
218217
assert(is_aligned(aligned_address, page_size()), "Given address (" PTR_FORMAT ") should be aligned.", p2i(aligned_address));
219218
assert(is_aligned(size_in_bytes, page_size()), "Given size (" SIZE_FORMAT ") should be aligned.", size_in_bytes);
220219

221-
log_trace(gc, heap, numa)("Request memory [" PTR_FORMAT ", " PTR_FORMAT ") to be NUMA id (%d)",
220+
log_trace(gc, heap, numa)("Request memory [" PTR_FORMAT ", " PTR_FORMAT ") to be NUMA id (%u)",
222221
p2i(aligned_address), p2i((char*)aligned_address + size_in_bytes), _node_ids[node_index]);
223-
os::numa_make_local((char*)aligned_address, size_in_bytes, _node_ids[node_index]);
222+
os::numa_make_local((char*)aligned_address, size_in_bytes, checked_cast<int>(_node_ids[node_index]));
224223
}
225224

226225
uint G1NUMA::max_search_depth() const {
@@ -279,9 +278,9 @@ G1NodeIndexCheckClosure::G1NodeIndexCheckClosure(const char* desc, G1NUMA* numa,
279278

280279
G1NodeIndexCheckClosure::~G1NodeIndexCheckClosure() {
281280
_ls->print("%s: NUMA region verification (id: matched/mismatched/total): ", _desc);
282-
const int* numa_ids = _numa->node_ids();
281+
const uint* numa_ids = _numa->node_ids();
283282
for (uint i = 0; i < _numa->num_active_nodes(); i++) {
284-
_ls->print("%d: %u/%u/%u ", numa_ids[i], _matched[i], _mismatched[i], _total[i]);
283+
_ls->print("%u: %u/%u/%u ", numa_ids[i], _matched[i], _mismatched[i], _total[i]);
285284
}
286285

287286
FREE_C_HEAP_ARRAY(uint, _matched);

src/hotspot/share/gc/g1/g1NUMA.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ class G1NUMA: public CHeapObj<mtGC> {
3939
// For invalid node id, return UnknownNodeIndex.
4040
uint* _node_id_to_index_map;
4141
// Length of _num_active_node_ids_id to index map.
42-
int _len_node_id_to_index_map;
42+
uint _len_node_id_to_index_map;
4343

4444
// Current active node ids.
45-
int* _node_ids;
45+
uint* _node_ids;
4646
// Total number of node ids.
4747
uint _num_active_node_ids;
4848

@@ -59,7 +59,7 @@ class G1NUMA: public CHeapObj<mtGC> {
5959

6060
// Returns node index of the given node id.
6161
// Precondition: node_id is an active node id.
62-
inline uint index_of_node_id(int node_id) const;
62+
inline uint index_of_node_id(uint node_id) const;
6363

6464
static G1NUMA* _inst;
6565

@@ -86,10 +86,10 @@ class G1NUMA: public CHeapObj<mtGC> {
8686

8787
bool is_enabled() const;
8888

89-
int numa_id(int index) const;
89+
uint numa_id(uint index) const;
9090

9191
// Returns memory node ids
92-
const int* node_ids() const;
92+
const uint* node_ids() const;
9393

9494
// Returns node index of current calling thread.
9595
uint index_of_current_thread() const;

src/hotspot/share/gc/g1/g1NUMAStats.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ void G1NUMAStats::NodeDataArray::copy(uint req_index, size_t* stat) {
119119
}
120120
}
121121

122-
G1NUMAStats::G1NUMAStats(const int* node_ids, uint num_node_ids) :
122+
G1NUMAStats::G1NUMAStats(const uint* node_ids, uint num_node_ids) :
123123
_node_ids(node_ids), _num_node_ids(num_node_ids), _node_data() {
124124

125125
assert(_num_node_ids > 1, "Should have at least one node id: %u", _num_node_ids);

src/hotspot/share/gc/g1/g1NUMAStats.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class G1NUMAStats : public CHeapObj<mtGC> {
9191
};
9292

9393
private:
94-
const int* _node_ids;
94+
const uint* _node_ids;
9595
uint _num_node_ids;
9696

9797
NodeDataArray* _node_data[NodeDataItemsSentinel];
@@ -101,7 +101,7 @@ class G1NUMAStats : public CHeapObj<mtGC> {
101101
void print_mutator_alloc_stat_debug();
102102

103103
public:
104-
G1NUMAStats(const int* node_ids, uint num_node_ids);
104+
G1NUMAStats(const uint* node_ids, uint num_node_ids);
105105
~G1NUMAStats();
106106

107107
void clear(G1NUMAStats::NodeDataItems phase);

src/hotspot/share/gc/g1/heapRegion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ void HeapRegion::print_on(outputStream* st) const {
427427
if (UseNUMA) {
428428
G1NUMA* numa = G1NUMA::numa();
429429
if (node_index() < numa->num_active_nodes()) {
430-
st->print("|%d", numa->numa_id(node_index()));
430+
st->print("|%u", numa->numa_id(node_index()));
431431
} else {
432432
st->print("|-");
433433
}

src/hotspot/share/prims/whitebox.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -585,12 +585,12 @@ WB_END
585585
WB_ENTRY(jintArray, WB_G1MemoryNodeIds(JNIEnv* env, jobject o))
586586
if (UseG1GC) {
587587
G1NUMA* numa = G1NUMA::numa();
588-
int num_node_ids = (int)numa->num_active_nodes();
589-
const int* node_ids = numa->node_ids();
588+
int num_node_ids = checked_cast<int>(numa->num_active_nodes());
589+
const uint* node_ids = numa->node_ids();
590590

591591
typeArrayOop result = oopFactory::new_intArray(num_node_ids, CHECK_NULL);
592592
for (int i = 0; i < num_node_ids; i++) {
593-
result->int_at_put(i, (jint)node_ids[i]);
593+
result->int_at_put(i, checked_cast<jint>(node_ids[i]));
594594
}
595595
return (jintArray) JNIHandles::make_local(THREAD, result);
596596
}

0 commit comments

Comments
 (0)