Skip to content

Commit cdb4768

Browse files
committed
8287396: LIR_Opr::vreg_number() and data() can return negative number
Reviewed-by: kvn, chagedorn
1 parent 4caf1ef commit cdb4768

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/hotspot/share/c1/c1_LIR.hpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,13 @@ class LIR_Opr {
236236
, is_xmm_bits = 1
237237
, last_use_bits = 1
238238
, is_fpu_stack_offset_bits = 1 // used in assertion checking on x86 for FPU stack slot allocation
239-
, non_data_bits = pointer_bits + kind_bits + type_bits + size_bits + destroys_bits + virtual_bits
239+
, non_data_bits = kind_bits + type_bits + size_bits + destroys_bits + virtual_bits
240240
+ is_xmm_bits + last_use_bits + is_fpu_stack_offset_bits
241241
, data_bits = BitsPerInt - non_data_bits
242242
, reg_bits = data_bits / 2 // for two registers in one value encoding
243243
};
244244

245-
enum OprShift {
245+
enum OprShift : uintptr_t {
246246
kind_shift = 0
247247
, type_shift = kind_shift + kind_bits
248248
, size_shift = type_shift + type_bits
@@ -275,7 +275,7 @@ class LIR_Opr {
275275
, no_type_mask = (int)(~(type_mask | last_use_mask | is_fpu_stack_offset_mask))
276276
};
277277

278-
uintptr_t data() const { return value() >> data_shift; }
278+
uint32_t data() const { return (uint32_t)value() >> data_shift; }
279279
int lo_reg_half() const { return data() & lower_reg_mask; }
280280
int hi_reg_half() const { return (data() >> reg_bits) & lower_reg_mask; }
281281
OprKind kind_field() const { return (OprKind)(value() & kind_mask); }
@@ -299,7 +299,9 @@ class LIR_Opr {
299299

300300
enum {
301301
vreg_base = ConcreteRegisterImpl::number_of_registers,
302-
vreg_max = (1 << data_bits) - 1
302+
data_max = (1 << data_bits) - 1, // max unsigned value for data bit field
303+
vreg_limit = 10000, // choose a reasonable limit,
304+
vreg_max = MIN2(vreg_limit, data_max) // and make sure if fits in the bit field
303305
};
304306

305307
static inline LIR_Opr illegalOpr();
@@ -755,7 +757,6 @@ class LIR_OprFact: public AllStatic {
755757
res->validate_type();
756758
assert(res->vreg_number() == index, "conversion check");
757759
assert(index >= LIR_Opr::vreg_base, "must start at vreg_base");
758-
assert(index <= (max_jint >> LIR_Opr::data_shift), "index is too big");
759760

760761
// old-style calculation; check if old and new method are equal
761762
LIR_Opr::OprType t = as_OprType(type);
@@ -834,7 +835,7 @@ class LIR_OprFact: public AllStatic {
834835

835836
#ifdef ASSERT
836837
assert(index >= 0, "index must be positive");
837-
assert(index <= (max_jint >> LIR_Opr::data_shift), "index is too big");
838+
assert(index == (int)res->data(), "conversion check");
838839

839840
LIR_Opr old_res = (LIR_Opr)(intptr_t)((index << LIR_Opr::data_shift) |
840841
LIR_Opr::stack_value |

0 commit comments

Comments
 (0)