Skip to content

Commit ee3e091

Browse files
committedAug 1, 2023
8313249: Fix -Wconversion warnings in verifier code
Reviewed-by: matsaave, iklam, dlong
1 parent e36960e commit ee3e091

File tree

6 files changed

+152
-141
lines changed

6 files changed

+152
-141
lines changed
 

‎src/hotspot/share/classfile/stackMapFrame.hpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ class StackMapFrame : public ResourceObj {
5353
// instruction modification, to allow rewinding
5454
// when/if an error occurs.
5555

56-
int32_t _max_locals;
57-
int32_t _max_stack;
56+
u2 _max_locals;
57+
u2 _max_stack;
5858

5959
u1 _flags;
6060
VerificationType* _locals; // local variable type array
@@ -100,8 +100,8 @@ class StackMapFrame : public ResourceObj {
100100
// which have _locals_size and _stack_size array elements in _locals and _stack.
101101
StackMapFrame(int32_t offset,
102102
u1 flags,
103-
u2 locals_size,
104-
u2 stack_size,
103+
int32_t locals_size,
104+
int32_t stack_size,
105105
u2 max_locals,
106106
u2 max_stack,
107107
VerificationType* locals,
@@ -122,8 +122,8 @@ class StackMapFrame : public ResourceObj {
122122
inline void set_offset(int32_t offset) { _offset = offset; }
123123
inline void set_verifier(ClassVerifier* v) { _verifier = v; }
124124
inline void set_flags(u1 flags) { _flags = flags; }
125-
inline void set_locals_size(u2 locals_size) { _locals_size = locals_size; }
126-
inline void set_stack_size(u2 stack_size) { _stack_size = _stack_mark = stack_size; }
125+
inline void set_locals_size(int32_t locals_size) { _locals_size = locals_size; }
126+
inline void set_stack_size(int32_t stack_size) { _stack_size = _stack_mark = stack_size; }
127127
inline void clear_stack() { _stack_size = 0; }
128128
inline int32_t offset() const { return _offset; }
129129
inline ClassVerifier* verifier() const { return _verifier; }
@@ -132,8 +132,8 @@ class StackMapFrame : public ResourceObj {
132132
inline VerificationType* locals() const { return _locals; }
133133
inline int32_t stack_size() const { return _stack_size; }
134134
inline VerificationType* stack() const { return _stack; }
135-
inline int32_t max_locals() const { return _max_locals; }
136-
inline int32_t max_stack() const { return _max_stack; }
135+
inline u2 max_locals() const { return _max_locals; }
136+
inline u2 max_stack() const { return _max_stack; }
137137
inline bool flag_this_uninit() const { return _flags & FLAG_THIS_UNINIT; }
138138

139139
// Set locals and stack types to bogus

‎src/hotspot/share/classfile/stackMapTableFormat.hpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ class same_frame : public stack_map_frame {
222222
static int frame_type_to_offset_delta(u1 frame_type) {
223223
return frame_type + 1; }
224224
static u1 offset_delta_to_frame_type(int offset_delta) {
225-
return (u1)(offset_delta - 1); }
225+
return checked_cast<u1>(offset_delta - 1); }
226226

227227
public:
228228

@@ -301,7 +301,7 @@ class same_frame_extended : public stack_map_frame {
301301
}
302302

303303
void set_offset_delta(int offset_delta) {
304-
Bytes::put_Java_u2(offset_delta_addr(), offset_delta - 1);
304+
Bytes::put_Java_u2(offset_delta_addr(), checked_cast<u2>(offset_delta - 1));
305305
}
306306

307307
int number_of_types() const { return 0; }
@@ -437,7 +437,7 @@ class same_locals_1_stack_item_extended : public stack_map_frame {
437437
}
438438

439439
void set_offset_delta(int offset_delta) {
440-
Bytes::put_Java_u2(offset_delta_addr(), offset_delta - 1);
440+
Bytes::put_Java_u2(offset_delta_addr(), checked_cast<u2>(offset_delta - 1));
441441
}
442442

443443
void set_type(verification_type_info* vti) {
@@ -478,7 +478,7 @@ class chop_frame : public stack_map_frame {
478478
}
479479

480480
static u1 chops_to_frame_type(int chop) {
481-
return 251 - chop;
481+
return checked_cast<u1>(251 - chop);
482482
}
483483

484484
public:
@@ -507,7 +507,7 @@ class chop_frame : public stack_map_frame {
507507
return Bytes::get_Java_u2(offset_delta_addr()) + 1;
508508
}
509509
void set_offset_delta(int offset_delta) {
510-
Bytes::put_Java_u2(offset_delta_addr(), offset_delta - 1);
510+
Bytes::put_Java_u2(offset_delta_addr(), checked_cast<u2>(offset_delta - 1));
511511
}
512512

513513
int chops() const {
@@ -549,7 +549,7 @@ class append_frame : public stack_map_frame {
549549

550550
static u1 appends_to_frame_type(int appends) {
551551
assert(appends > 0 && appends < 4, "Invalid append amount");
552-
return 251 + appends;
552+
return checked_cast<u1>(251 + appends);
553553
}
554554

555555
public:
@@ -598,7 +598,7 @@ class append_frame : public stack_map_frame {
598598
}
599599

600600
void set_offset_delta(int offset_delta) {
601-
Bytes::put_Java_u2(offset_delta_addr(), offset_delta - 1);
601+
Bytes::put_Java_u2(offset_delta_addr(), checked_cast<u2>(offset_delta - 1));
602602
}
603603

604604
void set_appends(int appends) {
@@ -748,13 +748,13 @@ class full_frame : public stack_map_frame {
748748
}
749749

750750
void set_offset_delta(int offset_delta) {
751-
Bytes::put_Java_u2(offset_delta_addr(), offset_delta - 1);
751+
Bytes::put_Java_u2(offset_delta_addr(), checked_cast<u2>(offset_delta - 1));
752752
}
753753
void set_num_locals(int num_locals) {
754-
Bytes::put_Java_u2(num_locals_addr(), num_locals);
754+
Bytes::put_Java_u2(num_locals_addr(), checked_cast<u2>(num_locals));
755755
}
756756
void set_stack_slots(address end_of_locals, int stack_slots) {
757-
Bytes::put_Java_u2(stack_slots_addr(end_of_locals), stack_slots);
757+
Bytes::put_Java_u2(stack_slots_addr(end_of_locals), checked_cast<u2>(stack_slots));
758758
}
759759

760760
// These return only the locals. Extra processing is required for stack

‎src/hotspot/share/classfile/verifier.cpp

+82-71
Large diffs are not rendered by default.

‎src/hotspot/share/classfile/verifier.hpp

+41-41
Original file line numberDiff line numberDiff line change
@@ -107,25 +107,25 @@ class TypeOrigin {
107107
} Origin;
108108

109109
Origin _origin;
110-
u2 _index; // local, stack, or constant pool index
110+
int _index; // local, stack, or constant pool index
111111
StackMapFrame* _frame; // source frame if CF or SM
112112
VerificationType _type; // The actual type
113113

114114
TypeOrigin(
115-
Origin origin, u2 index, StackMapFrame* frame, VerificationType type)
115+
Origin origin, int index, StackMapFrame* frame, VerificationType type)
116116
: _origin(origin), _index(index), _frame(frame), _type(type) {}
117117

118118
public:
119119
TypeOrigin() : _origin(NONE), _index(0), _frame(nullptr) {}
120120

121121
static TypeOrigin null();
122-
static TypeOrigin local(u2 index, StackMapFrame* frame);
123-
static TypeOrigin stack(u2 index, StackMapFrame* frame);
124-
static TypeOrigin sm_local(u2 index, StackMapFrame* frame);
125-
static TypeOrigin sm_stack(u2 index, StackMapFrame* frame);
126-
static TypeOrigin cp(u2 index, VerificationType vt);
122+
static TypeOrigin local(int index, StackMapFrame* frame);
123+
static TypeOrigin stack(int index, StackMapFrame* frame);
124+
static TypeOrigin sm_local(int index, StackMapFrame* frame);
125+
static TypeOrigin sm_stack(int index, StackMapFrame* frame);
126+
static TypeOrigin cp(int index, VerificationType vt);
127127
static TypeOrigin signature(VerificationType vt);
128-
static TypeOrigin bad_index(u2 index);
128+
static TypeOrigin bad_index(int index);
129129
static TypeOrigin implicit(VerificationType t);
130130
static TypeOrigin frame(StackMapFrame* frame);
131131

@@ -134,7 +134,7 @@ class TypeOrigin {
134134
void print_frame(outputStream* ss) const;
135135
const StackMapFrame* frame() const { return _frame; }
136136
bool is_valid() const { return _origin != NONE; }
137-
u2 index() const { return _index; }
137+
int index() const { return _index; }
138138

139139
#ifdef ASSERT
140140
void print_on(outputStream* str) const;
@@ -174,45 +174,45 @@ class ErrorContext {
174174
public:
175175
ErrorContext() : _bci(-1), _fault(NO_FAULT) {}
176176

177-
static ErrorContext bad_code(u2 bci) {
177+
static ErrorContext bad_code(int bci) {
178178
return ErrorContext(bci, INVALID_BYTECODE);
179179
}
180-
static ErrorContext bad_type(u2 bci, TypeOrigin type) {
180+
static ErrorContext bad_type(int bci, TypeOrigin type) {
181181
return ErrorContext(bci, WRONG_TYPE, type);
182182
}
183-
static ErrorContext bad_type(u2 bci, TypeOrigin type, TypeOrigin exp) {
183+
static ErrorContext bad_type(int bci, TypeOrigin type, TypeOrigin exp) {
184184
return ErrorContext(bci, WRONG_TYPE, type, exp);
185185
}
186-
static ErrorContext bad_flags(u2 bci, StackMapFrame* frame) {
186+
static ErrorContext bad_flags(int bci, StackMapFrame* frame) {
187187
return ErrorContext(bci, FLAGS_MISMATCH, TypeOrigin::frame(frame));
188188
}
189-
static ErrorContext bad_flags(u2 bci, StackMapFrame* cur, StackMapFrame* sm) {
189+
static ErrorContext bad_flags(int bci, StackMapFrame* cur, StackMapFrame* sm) {
190190
return ErrorContext(bci, FLAGS_MISMATCH,
191191
TypeOrigin::frame(cur), TypeOrigin::frame(sm));
192192
}
193-
static ErrorContext bad_cp_index(u2 bci, u2 index) {
193+
static ErrorContext bad_cp_index(int bci, int index) {
194194
return ErrorContext(bci, BAD_CP_INDEX, TypeOrigin::bad_index(index));
195195
}
196-
static ErrorContext bad_local_index(u2 bci, u2 index) {
196+
static ErrorContext bad_local_index(int bci, int index) {
197197
return ErrorContext(bci, BAD_LOCAL_INDEX, TypeOrigin::bad_index(index));
198198
}
199199
static ErrorContext locals_size_mismatch(
200-
u2 bci, StackMapFrame* frame0, StackMapFrame* frame1) {
200+
int bci, StackMapFrame* frame0, StackMapFrame* frame1) {
201201
return ErrorContext(bci, LOCALS_SIZE_MISMATCH,
202202
TypeOrigin::frame(frame0), TypeOrigin::frame(frame1));
203203
}
204204
static ErrorContext stack_size_mismatch(
205-
u2 bci, StackMapFrame* frame0, StackMapFrame* frame1) {
205+
int bci, StackMapFrame* frame0, StackMapFrame* frame1) {
206206
return ErrorContext(bci, STACK_SIZE_MISMATCH,
207207
TypeOrigin::frame(frame0), TypeOrigin::frame(frame1));
208208
}
209-
static ErrorContext stack_overflow(u2 bci, StackMapFrame* frame) {
209+
static ErrorContext stack_overflow(int bci, StackMapFrame* frame) {
210210
return ErrorContext(bci, STACK_OVERFLOW, TypeOrigin::frame(frame));
211211
}
212-
static ErrorContext stack_underflow(u2 bci, StackMapFrame* frame) {
212+
static ErrorContext stack_underflow(int bci, StackMapFrame* frame) {
213213
return ErrorContext(bci, STACK_UNDERFLOW, TypeOrigin::frame(frame));
214214
}
215-
static ErrorContext missing_stackmap(u2 bci) {
215+
static ErrorContext missing_stackmap(int bci) {
216216
return ErrorContext(bci, MISSING_STACKMAP);
217217
}
218218
static ErrorContext bad_stackmap(int index, StackMapFrame* frame) {
@@ -304,22 +304,22 @@ class ClassVerifier : public StackObj {
304304
InstanceKlass* this_class, Klass* target_class,
305305
Symbol* field_name, Symbol* field_sig, bool is_method);
306306

307-
void verify_cp_index(u2 bci, const constantPoolHandle& cp, int index, TRAPS);
308-
void verify_cp_type(u2 bci, int index, const constantPoolHandle& cp,
307+
void verify_cp_index(int bci, const constantPoolHandle& cp, u2 index, TRAPS);
308+
void verify_cp_type(int bci, u2 index, const constantPoolHandle& cp,
309309
unsigned int types, TRAPS);
310-
void verify_cp_class_type(u2 bci, int index, const constantPoolHandle& cp, TRAPS);
310+
void verify_cp_class_type(int bci, u2 index, const constantPoolHandle& cp, TRAPS);
311311

312312
u2 verify_stackmap_table(
313-
u2 stackmap_index, u2 bci, StackMapFrame* current_frame,
313+
u2 stackmap_index, int bci, StackMapFrame* current_frame,
314314
StackMapTable* stackmap_table, bool no_control_flow, TRAPS);
315315

316316
void verify_exception_handler_targets(
317-
u2 bci, bool this_uninit, StackMapFrame* current_frame,
317+
int bci, bool this_uninit, StackMapFrame* current_frame,
318318
StackMapTable* stackmap_table, TRAPS);
319319

320320
void verify_ldc(
321321
int opcode, u2 index, StackMapFrame *current_frame,
322-
const constantPoolHandle& cp, u2 bci, TRAPS);
322+
const constantPoolHandle& cp, int bci, TRAPS);
323323

324324
void verify_switch(
325325
RawBytecodeStream* bcs, u4 code_length, char* code_data,
@@ -351,24 +351,24 @@ class ClassVerifier : public StackObj {
351351
bool in_try_block, bool* this_uninit, VerificationType return_type,
352352
const constantPoolHandle& cp, StackMapTable* stackmap_table, TRAPS);
353353

354-
VerificationType get_newarray_type(u2 index, u2 bci, TRAPS);
355-
void verify_anewarray(u2 bci, u2 index, const constantPoolHandle& cp,
354+
VerificationType get_newarray_type(u2 index, int bci, TRAPS);
355+
void verify_anewarray(int bci, u2 index, const constantPoolHandle& cp,
356356
StackMapFrame* current_frame, TRAPS);
357357
void verify_return_value(
358-
VerificationType return_type, VerificationType type, u2 offset,
358+
VerificationType return_type, VerificationType type, int bci,
359359
StackMapFrame* current_frame, TRAPS);
360360

361-
void verify_iload (u2 index, StackMapFrame* current_frame, TRAPS);
362-
void verify_lload (u2 index, StackMapFrame* current_frame, TRAPS);
363-
void verify_fload (u2 index, StackMapFrame* current_frame, TRAPS);
364-
void verify_dload (u2 index, StackMapFrame* current_frame, TRAPS);
365-
void verify_aload (u2 index, StackMapFrame* current_frame, TRAPS);
366-
void verify_istore(u2 index, StackMapFrame* current_frame, TRAPS);
367-
void verify_lstore(u2 index, StackMapFrame* current_frame, TRAPS);
368-
void verify_fstore(u2 index, StackMapFrame* current_frame, TRAPS);
369-
void verify_dstore(u2 index, StackMapFrame* current_frame, TRAPS);
370-
void verify_astore(u2 index, StackMapFrame* current_frame, TRAPS);
371-
void verify_iinc (u2 index, StackMapFrame* current_frame, TRAPS);
361+
void verify_iload (int index, StackMapFrame* current_frame, TRAPS);
362+
void verify_lload (int index, StackMapFrame* current_frame, TRAPS);
363+
void verify_fload (int index, StackMapFrame* current_frame, TRAPS);
364+
void verify_dload (int index, StackMapFrame* current_frame, TRAPS);
365+
void verify_aload (int index, StackMapFrame* current_frame, TRAPS);
366+
void verify_istore(int index, StackMapFrame* current_frame, TRAPS);
367+
void verify_lstore(int index, StackMapFrame* current_frame, TRAPS);
368+
void verify_fstore(int index, StackMapFrame* current_frame, TRAPS);
369+
void verify_dstore(int index, StackMapFrame* current_frame, TRAPS);
370+
void verify_astore(int index, StackMapFrame* current_frame, TRAPS);
371+
void verify_iinc (int index, StackMapFrame* current_frame, TRAPS);
372372

373373
bool name_in_supers(Symbol* ref_name, InstanceKlass* current);
374374

‎src/hotspot/share/interpreter/bytecode.hpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ class Bytecode: public StackObj {
7171
Bytecodes::Code invoke_code() const { return (code() == Bytecodes::_invokehandle) ? code() : java_code(); }
7272

7373
// Static functions for parsing bytecodes in place.
74-
int get_index_u1(Bytecodes::Code bc) const {
74+
u1 get_index_u1(Bytecodes::Code bc) const {
7575
assert_same_format_as(bc); assert_index_size(1, bc);
76-
return *(jubyte*)addr_at(1);
76+
return *(u1*)addr_at(1);
7777
}
78-
int get_index_u2(Bytecodes::Code bc, bool is_wide = false) const {
78+
u2 get_index_u2(Bytecodes::Code bc, bool is_wide = false) const {
7979
assert_same_format_as(bc, is_wide); assert_index_size(2, bc, is_wide);
8080
address p = addr_at(is_wide ? 2 : 1);
8181
if (can_use_native_byte_order(bc, is_wide)) {
@@ -86,7 +86,7 @@ class Bytecode: public StackObj {
8686
}
8787
int get_index_u1_cpcache(Bytecodes::Code bc) const {
8888
assert_same_format_as(bc); assert_index_size(1, bc);
89-
return *(jubyte*)addr_at(1) + ConstantPool::CPCACHE_INDEX_TAG;
89+
return *(u1*)addr_at(1) + ConstantPool::CPCACHE_INDEX_TAG;
9090
}
9191
int get_index_u2_cpcache(Bytecodes::Code bc) const {
9292
assert_same_format_as(bc); assert_index_size(2, bc); assert_native_index(bc);

‎src/hotspot/share/interpreter/bytecodeStream.hpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -104,7 +104,7 @@ class BaseBytecodeStream: StackObj {
104104
int dest_w() const { return bci() + bytecode().get_offset_s4(raw_code()); }
105105

106106
// One-byte indices.
107-
int get_index_u1() const { assert_raw_index_size(1); return *(jubyte*)(bcp()+1); }
107+
u1 get_index_u1() const { assert_raw_index_size(1); return *(jubyte*)(bcp()+1); }
108108

109109
protected:
110110
void assert_raw_index_size(int size) const NOT_DEBUG_RETURN;
@@ -149,12 +149,12 @@ class RawBytecodeStream: public BaseBytecodeStream {
149149
Bytecodes::Code raw_next_special(Bytecodes::Code code);
150150

151151
// Unsigned indices, widening, with no swapping of bytes
152-
int get_index() const { return (is_wide()) ? get_index_u2_raw(bcp() + 2) : get_index_u1(); }
152+
u2 get_index() const { return (is_wide()) ? get_index_u2_raw(bcp() + 2) : get_index_u1(); }
153153
// Get an unsigned 2-byte index, with no swapping of bytes.
154-
int get_index_u2() const { assert(!is_wide(), ""); return get_index_u2_raw(bcp() + 1); }
154+
u2 get_index_u2() const { assert(!is_wide(), ""); return get_index_u2_raw(bcp() + 1); }
155155

156156
private:
157-
int get_index_u2_raw(address p) const {
157+
u2 get_index_u2_raw(address p) const {
158158
assert_raw_index_size(2); assert_raw_stream(true);
159159
return Bytes::get_Java_u2(p);
160160
}
@@ -218,9 +218,9 @@ class BytecodeStream: public BaseBytecodeStream {
218218
Bytecodes::Code code() const { return _code; }
219219

220220
// Unsigned indices, widening
221-
int get_index() const { return is_wide() ? bytecode().get_index_u2(raw_code(), true) : get_index_u1(); }
221+
u2 get_index() const { return is_wide() ? bytecode().get_index_u2(raw_code(), true) : get_index_u1(); }
222222
// Get an unsigned 2-byte index, swapping the bytes if necessary.
223-
int get_index_u2() const { assert_raw_stream(false);
223+
u2 get_index_u2() const { assert_raw_stream(false);
224224
return bytecode().get_index_u2(raw_code(), false); }
225225
// Get an unsigned 2-byte index in native order.
226226
int get_index_u2_cpcache() const { assert_raw_stream(false);

0 commit comments

Comments
 (0)
Please sign in to comment.