Skip to content

Commit cb3f968

Browse files
committed
8314651: G1: Fix -Wconversion warnings in static fields of HeapRegion
Reviewed-by: tschatzl, iwalulya
1 parent 876a725 commit cb3f968

File tree

9 files changed

+20
-20
lines changed

9 files changed

+20
-20
lines changed

src/hotspot/share/gc/g1/c1/g1BarrierSetC1.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,13 @@ void G1BarrierSetC1::post_barrier(LIRAccess& access, LIR_Opr addr, LIR_Opr new_v
158158
__ logical_xor(xor_res, new_val, xor_res);
159159
__ move(xor_res, xor_shift_res);
160160
__ unsigned_shift_right(xor_shift_res,
161-
LIR_OprFact::intConst(HeapRegion::LogOfHRGrainBytes),
161+
LIR_OprFact::intConst(checked_cast<jint>(HeapRegion::LogOfHRGrainBytes)),
162162
xor_shift_res,
163163
LIR_Opr::illegalOpr());
164164
} else {
165165
__ logical_xor(addr, new_val, xor_res);
166166
__ unsigned_shift_right(xor_res,
167-
LIR_OprFact::intConst(HeapRegion::LogOfHRGrainBytes),
167+
LIR_OprFact::intConst(checked_cast<jint>(HeapRegion::LogOfHRGrainBytes)),
168168
xor_shift_res,
169169
LIR_Opr::illegalOpr());
170170
}

src/hotspot/share/gc/g1/c2/g1BarrierSetC2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ void G1BarrierSetC2::post_barrier(GraphKit* kit,
454454
// Should be able to do an unsigned compare of region_size instead of
455455
// and extra shift. Do we have an unsigned compare??
456456
// Node* region_size = __ ConI(1 << HeapRegion::LogOfHRGrainBytes);
457-
Node* xor_res = __ URShiftX ( __ XorX( cast, __ CastPX(__ ctrl(), val)), __ ConI(HeapRegion::LogOfHRGrainBytes));
457+
Node* xor_res = __ URShiftX ( __ XorX( cast, __ CastPX(__ ctrl(), val)), __ ConI(checked_cast<jint>(HeapRegion::LogOfHRGrainBytes)));
458458

459459
// if (xor_res == 0) same region so skip
460460
__ if_then(xor_res, BoolTest::ne, zeroX, likely); {

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "gc/g1/g1CollectedHeap.inline.hpp"
3131
#include "gc/g1/g1HeapVerifier.hpp"
3232
#include "gc/g1/heapRegion.hpp"
33+
#include "gc/g1/heapRegionBounds.inline.hpp"
3334
#include "gc/g1/heapRegionRemSet.hpp"
3435
#include "gc/shared/cardTable.hpp"
3536
#include "gc/shared/gcArguments.hpp"
@@ -131,11 +132,13 @@ void G1Arguments::initialize_mark_stack_size() {
131132
void G1Arguments::initialize_card_set_configuration() {
132133
assert(HeapRegion::LogOfHRGrainBytes != 0, "not initialized");
133134
// Array of Cards card set container globals.
134-
const int LOG_M = 20;
135-
uint region_size_log_mb = (uint)MAX2(HeapRegion::LogOfHRGrainBytes - LOG_M, 0);
135+
const uint LOG_M = 20;
136+
assert(log2i_exact(HeapRegionBounds::min_size()) == LOG_M, "inv");
137+
assert(HeapRegion::LogOfHRGrainBytes >= LOG_M, "from the above");
138+
uint region_size_log_mb = HeapRegion::LogOfHRGrainBytes - LOG_M;
136139

137140
if (FLAG_IS_DEFAULT(G1RemSetArrayOfCardsEntries)) {
138-
uint max_cards_in_inline_ptr = G1CardSetConfiguration::max_cards_in_inline_ptr(HeapRegion::LogOfHRGrainBytes - CardTable::card_shift());
141+
uint max_cards_in_inline_ptr = G1CardSetConfiguration::max_cards_in_inline_ptr(HeapRegion::LogCardsPerRegion);
139142
FLAG_SET_ERGO(G1RemSetArrayOfCardsEntries, MAX2(max_cards_in_inline_ptr * 2,
140143
G1RemSetArrayOfCardsEntriesBase << region_size_log_mb));
141144
}

src/hotspot/share/gc/g1/g1CardTable.inline.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
inline uint G1CardTable::region_idx_for(CardValue* p) {
3333
size_t const card_idx = pointer_delta(p, _byte_map, sizeof(CardValue));
34-
return (uint)(card_idx >> (HeapRegion::LogOfHRGrainBytes - _card_shift));
34+
return (uint)(card_idx >> HeapRegion::LogCardsPerRegion);
3535
}
3636

3737
inline bool G1CardTable::mark_clean_as_dirty(CardValue* card) {

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@
4848
#include "runtime/globals_extension.hpp"
4949
#include "utilities/powerOfTwo.hpp"
5050

51-
int HeapRegion::LogOfHRGrainBytes = 0;
52-
int HeapRegion::LogCardsPerRegion = 0;
51+
uint HeapRegion::LogOfHRGrainBytes = 0;
52+
uint HeapRegion::LogCardsPerRegion = 0;
5353
size_t HeapRegion::GrainBytes = 0;
5454
size_t HeapRegion::GrainWords = 0;
5555
size_t HeapRegion::CardsPerRegion = 0;
@@ -78,12 +78,9 @@ void HeapRegion::setup_heap_region_size(size_t max_heap_size) {
7878
// Now make sure that we don't go over or under our limits.
7979
region_size = clamp(region_size, HeapRegionBounds::min_size(), HeapRegionBounds::max_size());
8080

81-
// Calculate the log for the region size.
82-
int region_size_log = log2i_exact(region_size);
83-
8481
// Now, set up the globals.
8582
guarantee(LogOfHRGrainBytes == 0, "we should only set it once");
86-
LogOfHRGrainBytes = region_size_log;
83+
LogOfHRGrainBytes = log2i_exact(region_size);
8784

8885
guarantee(GrainBytes == 0, "we should only set it once");
8986
GrainBytes = region_size;
@@ -94,7 +91,7 @@ void HeapRegion::setup_heap_region_size(size_t max_heap_size) {
9491
guarantee(CardsPerRegion == 0, "we should only set it once");
9592
CardsPerRegion = GrainBytes >> G1CardTable::card_shift();
9693

97-
LogCardsPerRegion = log2i(CardsPerRegion);
94+
LogCardsPerRegion = log2i_exact(CardsPerRegion);
9895

9996
if (G1HeapRegionSize != GrainBytes) {
10097
FLAG_SET_ERGO(G1HeapRegionSize, GrainBytes);

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,16 +289,15 @@ class HeapRegion : public CHeapObj<mtGC> {
289289
// there's clearing to be done ourselves. We also always mangle the space.
290290
void initialize(bool clear_space = false, bool mangle_space = SpaceDecorator::Mangle);
291291

292-
static int LogOfHRGrainBytes;
293-
static int LogCardsPerRegion;
292+
static uint LogOfHRGrainBytes;
293+
static uint LogCardsPerRegion;
294294

295295
static size_t GrainBytes;
296296
static size_t GrainWords;
297297
static size_t CardsPerRegion;
298298

299299
static size_t align_up_to_region_byte_size(size_t sz) {
300-
return (sz + (size_t) GrainBytes - 1) &
301-
~((1 << (size_t) LogOfHRGrainBytes) - 1);
300+
return align_up(sz, GrainBytes);
302301
}
303302

304303
// Returns whether a field is in the same region as the obj it points to.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
static_field) \
3636
\
3737
static_field(HeapRegion, GrainBytes, size_t) \
38-
static_field(HeapRegion, LogOfHRGrainBytes, int) \
38+
static_field(HeapRegion, LogOfHRGrainBytes, uint) \
3939
\
4040
nonstatic_field(HeapRegion, _type, HeapRegionType) \
4141
nonstatic_field(HeapRegion, _bottom, HeapWord* const) \

src/hotspot/share/jvmci/jvmciCompilerToVMInit.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ jobjectArray readConfiguration0(JNIEnv *env, JVMCI_TRAPS) {
399399
assert(box.is_non_null(), "must have a box");
400400
} else if (strcmp(vmField.typeString, "int") == 0 ||
401401
strcmp(vmField.typeString, "jint") == 0 ||
402+
strcmp(vmField.typeString, "uint") == 0 ||
402403
strcmp(vmField.typeString, "uint32_t") == 0) {
403404
BOXED_LONG(box, *(jint*) vmField.address);
404405
assert(box.is_non_null(), "must have a box");

src/hotspot/share/jvmci/vmStructs_jvmci.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@
817817
#if INCLUDE_G1GC
818818

819819
#define VM_STRUCTS_JVMCI_G1GC(nonstatic_field, static_field) \
820-
static_field(HeapRegion, LogOfHRGrainBytes, int)
820+
static_field(HeapRegion, LogOfHRGrainBytes, uint)
821821

822822
#define VM_INT_CONSTANTS_JVMCI_G1GC(declare_constant, declare_constant_with_value, declare_preprocessor_constant) \
823823
declare_constant_with_value("G1CardTable::g1_young_gen", G1CardTable::g1_young_card_val()) \

0 commit comments

Comments
 (0)