Skip to content

Commit

Permalink
8311077: Fix -Wconversion warnings in jvmti code
Browse files Browse the repository at this point in the history
Reviewed-by: fparain, matsaave, dholmes
  • Loading branch information
coleenp committed Jul 5, 2023
1 parent 00ac46c commit cf82e31
Show file tree
Hide file tree
Showing 16 changed files with 98 additions and 95 deletions.
2 changes: 1 addition & 1 deletion src/hotspot/share/oops/constMethod.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ class ConstMethod : public MetaspaceObj {
static bool is_read_only_by_default() { return true; }

// code size
int code_size() const { return _code_size; }
u2 code_size() const { return _code_size; }
void set_code_size(int size) {
assert(max_method_code_size < (1 << 16),
"u2 is too small to hold method code size in general");
Expand Down
16 changes: 8 additions & 8 deletions src/hotspot/share/oops/constantPool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -587,16 +587,16 @@ class ConstantPool : public Metadata {
"Corrupted CP operands");
return operand_offset_at(operands(), bsms_attribute_index);
}
int operand_bootstrap_method_ref_index_at(int bsms_attribute_index) {
u2 operand_bootstrap_method_ref_index_at(int bsms_attribute_index) {
int offset = operand_offset_at(bsms_attribute_index);
return operands()->at(offset + _indy_bsm_offset);
}
int operand_argument_count_at(int bsms_attribute_index) {
u2 operand_argument_count_at(int bsms_attribute_index) {
int offset = operand_offset_at(bsms_attribute_index);
int argc = operands()->at(offset + _indy_argc_offset);
u2 argc = operands()->at(offset + _indy_argc_offset);
return argc;
}
int operand_argument_index_at(int bsms_attribute_index, int j) {
u2 operand_argument_index_at(int bsms_attribute_index, int j) {
int offset = operand_offset_at(bsms_attribute_index);
return operands()->at(offset + _indy_argv_offset + j);
}
Expand All @@ -618,21 +618,21 @@ class ConstantPool : public Metadata {
// Shrink the operands array to a smaller array with new_len length
void shrink_operands(int new_len, TRAPS);

int bootstrap_method_ref_index_at(int which) {
u2 bootstrap_method_ref_index_at(int which) {
assert(tag_at(which).has_bootstrap(), "Corrupted constant pool");
int op_base = bootstrap_operand_base(which);
return operands()->at(op_base + _indy_bsm_offset);
}
int bootstrap_argument_count_at(int which) {
u2 bootstrap_argument_count_at(int which) {
assert(tag_at(which).has_bootstrap(), "Corrupted constant pool");
int op_base = bootstrap_operand_base(which);
int argc = operands()->at(op_base + _indy_argc_offset);
u2 argc = operands()->at(op_base + _indy_argc_offset);
DEBUG_ONLY(int end_offset = op_base + _indy_argv_offset + argc;
int next_offset = bootstrap_operand_limit(which));
assert(end_offset == next_offset, "matched ending");
return argc;
}
int bootstrap_argument_index_at(int which, int j) {
u2 bootstrap_argument_index_at(int which, int j) {
int op_base = bootstrap_operand_base(which);
DEBUG_ONLY(int argc = operands()->at(op_base + _indy_argc_offset));
assert((uint)j < (uint)argc, "oob");
Expand Down
8 changes: 4 additions & 4 deletions src/hotspot/share/oops/fieldStreams.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,26 +140,26 @@ class JavaFieldStream : public FieldStreamBase {
public:
JavaFieldStream(const InstanceKlass* k): FieldStreamBase(k->fieldinfo_stream(), k->constants(), 0, k->java_fields_count()) {}

int name_index() const {
u2 name_index() const {
assert(!field()->field_flags().is_injected(), "regular only");
return field()->name_index();
}

int signature_index() const {
u2 signature_index() const {
assert(!field()->field_flags().is_injected(), "regular only");
return field()->signature_index();
return -1;
}

int generic_signature_index() const {
u2 generic_signature_index() const {
assert(!field()->field_flags().is_injected(), "regular only");
if (field()->field_flags().is_generic()) {
return field()->generic_signature_index();
}
return 0;
}

int initval_index() const {
u2 initval_index() const {
assert(!field()->field_flags().is_injected(), "regular only");
return field()->initializer_index();
}
Expand Down
22 changes: 11 additions & 11 deletions src/hotspot/share/oops/method.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ class Method : public Metadata {
void set_orig_method_idnum(u2 idnum) { constMethod()->set_orig_method_idnum(idnum); }

// code size
int code_size() const { return constMethod()->code_size(); }
u2 code_size() const { return constMethod()->code_size(); }

// method size in words
int method_size() const { return sizeof(Method)/wordSize + ( is_native() ? 2 : 0 ); }
Expand All @@ -265,13 +265,13 @@ class Method : public Metadata {

// max stack
// return original max stack size for method verification
int verifier_max_stack() const { return constMethod()->max_stack(); }
int max_stack() const { return constMethod()->max_stack() + extra_stack_entries(); }
void set_max_stack(int size) { constMethod()->set_max_stack(size); }
u2 verifier_max_stack() const { return constMethod()->max_stack(); }
int max_stack() const { return constMethod()->max_stack() + extra_stack_entries(); }
void set_max_stack(int size) { constMethod()->set_max_stack(size); }

// max locals
int max_locals() const { return constMethod()->max_locals(); }
void set_max_locals(int size) { constMethod()->set_max_locals(size); }
u2 max_locals() const { return constMethod()->max_locals(); }
void set_max_locals(int size) { constMethod()->set_max_locals(size); }

int highest_comp_level() const;
void set_highest_comp_level(int level);
Expand Down Expand Up @@ -520,18 +520,18 @@ class Method : public Metadata {
int method_parameters_length() const
{ return constMethod()->method_parameters_length(); }
MethodParametersElement* method_parameters_start() const
{ return constMethod()->method_parameters_start(); }
{ return constMethod()->method_parameters_start(); }

// checked exceptions
int checked_exceptions_length() const
u2 checked_exceptions_length() const
{ return constMethod()->checked_exceptions_length(); }
CheckedExceptionElement* checked_exceptions_start() const
{ return constMethod()->checked_exceptions_start(); }
{ return constMethod()->checked_exceptions_start(); }

// localvariable table
bool has_localvariable_table() const
{ return constMethod()->has_localvariable_table(); }
int localvariable_table_length() const
u2 localvariable_table_length() const
{ return constMethod()->localvariable_table_length(); }
LocalVariableTableElement* localvariable_table_start() const
{ return constMethod()->localvariable_table_start(); }
Expand Down Expand Up @@ -1038,7 +1038,7 @@ class ExceptionTable : public StackObj {
}
}

int length() const {
u2 length() const {
return _length;
}

Expand Down
60 changes: 30 additions & 30 deletions src/hotspot/share/prims/jvmtiClassFileReconstituter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ void JvmtiClassFileReconstituter::write_field_infos() {
// Compute the real number of Java fields
int java_fields = ik()->java_fields_count();

write_u2(java_fields);
write_u2(checked_cast<u2>(java_fields));
for (JavaFieldStream fs(ik()); !fs.done(); fs.next()) {
AccessFlags access_flags = fs.access_flags();
int name_index = fs.name_index();
int signature_index = fs.signature_index();
int initial_value_index = fs.initval_index();
u2 name_index = fs.name_index();
u2 signature_index = fs.signature_index();
u2 initial_value_index = fs.initval_index();
guarantee(name_index != 0 && signature_index != 0, "bad constant pool index for field");
// int offset = ik()->field_offset( index );
int generic_signature_index = fs.generic_signature_index();
u2 generic_signature_index = fs.generic_signature_index();
AnnotationArray* anno = fields_anno == nullptr ? nullptr : fields_anno->at(fs.index());
AnnotationArray* type_anno = fields_type_anno == nullptr ? nullptr : fields_type_anno->at(fs.index());

Expand All @@ -84,10 +84,10 @@ void JvmtiClassFileReconstituter::write_field_infos() {
// JVMSpec| attribute_info attributes[attributes_count];
// JVMSpec| }

write_u2(access_flags.as_int() & JVM_RECOGNIZED_FIELD_MODIFIERS);
write_u2(access_flags.get_flags() & JVM_RECOGNIZED_FIELD_MODIFIERS);
write_u2(name_index);
write_u2(signature_index);
int attr_count = 0;
u2 attr_count = 0;
if (initial_value_index != 0) {
++attr_count;
}
Expand Down Expand Up @@ -147,11 +147,11 @@ void JvmtiClassFileReconstituter::write_code_attribute(const methodHandle& metho
ConstMethod* const_method = method->constMethod();
u2 line_num_cnt = 0;
int stackmap_len = 0;
int local_variable_table_length = 0;
int local_variable_type_table_length = 0;
u2 local_variable_table_length = 0;
u2 local_variable_type_table_length = 0;

// compute number and length of attributes
int attr_count = 0;
u2 attr_count = 0;
int attr_size = 0;
if (const_method->has_linenumber_table()) {
line_num_cnt = line_number_table_entries(method);
Expand Down Expand Up @@ -229,7 +229,7 @@ void JvmtiClassFileReconstituter::write_code_attribute(const methodHandle& metho
}

ExceptionTable exception_table(method());
int exception_table_length = exception_table.length();
u2 exception_table_length = exception_table.length();
int code_size = const_method->code_size();
int size =
2+2+4 + // max_stack, max_locals, code_length
Expand Down Expand Up @@ -276,7 +276,7 @@ void JvmtiClassFileReconstituter::write_code_attribute(const methodHandle& metho
// JVMSpec| }
void JvmtiClassFileReconstituter::write_exceptions_attribute(ConstMethod* const_method) {
CheckedExceptionElement* checked_exceptions = const_method->checked_exceptions_start();
int checked_exceptions_length = const_method->checked_exceptions_length();
u2 checked_exceptions_length = const_method->checked_exceptions_length();
int size =
2 + // number_of_exceptions
2 * checked_exceptions_length; // exception_index_table
Expand Down Expand Up @@ -307,7 +307,7 @@ void JvmtiClassFileReconstituter::write_method_parameter_attribute(const ConstMe

write_attribute_name_index("MethodParameters");
write_u4(size);
write_u1(length);
write_u1((u1)length);
for (int index = 0; index < length; index++) {
write_u2(parameters[index].name_cp_index);
write_u2(parameters[index].flags);
Expand Down Expand Up @@ -361,7 +361,7 @@ void JvmtiClassFileReconstituter::write_signature_attribute(u2 generic_signature
// Compute the number of entries in the InnerClasses attribute
u2 JvmtiClassFileReconstituter::inner_classes_attribute_length() {
InnerClassesIterator iter(ik());
return iter.length();
return checked_cast<u2>(iter.length());
}

// Write an annotation attribute. The VM stores them in raw form, so all we need
Expand Down Expand Up @@ -394,17 +394,17 @@ void JvmtiClassFileReconstituter::write_bootstrapmethod_attribute() {
int num_bootstrap_methods = ConstantPool::operand_array_length(operands);

// calculate length of attribute
int length = sizeof(u2); // num_bootstrap_methods
u4 length = sizeof(u2); // num_bootstrap_methods
for (int n = 0; n < num_bootstrap_methods; n++) {
u2 num_bootstrap_arguments = cpool()->operand_argument_count_at(n);
length += sizeof(u2); // bootstrap_method_ref
length += sizeof(u2); // num_bootstrap_arguments
length += sizeof(u2) * num_bootstrap_arguments; // bootstrap_arguments[num_bootstrap_arguments]
length += (u4)sizeof(u2) * num_bootstrap_arguments; // bootstrap_arguments[num_bootstrap_arguments]
}
write_u4(length);

// write attribute
write_u2(num_bootstrap_methods);
write_u2(checked_cast<u2>(num_bootstrap_methods));
for (int n = 0; n < num_bootstrap_methods; n++) {
u2 bootstrap_method_ref = cpool()->operand_bootstrap_method_ref_index_at(n);
u2 num_bootstrap_arguments = cpool()->operand_argument_count_at(n);
Expand All @@ -424,7 +424,7 @@ void JvmtiClassFileReconstituter::write_bootstrapmethod_attribute() {
// }
void JvmtiClassFileReconstituter::write_nest_host_attribute() {
int length = sizeof(u2);
int host_class_index = ik()->nest_host_index();
u2 host_class_index = ik()->nest_host_index();

write_attribute_name_index("NestHost");
write_u4(length);
Expand All @@ -444,7 +444,7 @@ void JvmtiClassFileReconstituter::write_nest_members_attribute() {

write_attribute_name_index("NestMembers");
write_u4(length);
write_u2(number_of_classes);
write_u2(checked_cast<u2>(number_of_classes));
for (int i = 0; i < number_of_classes; i++) {
u2 class_cp_index = nest_members->at(i);
write_u2(class_cp_index);
Expand All @@ -464,7 +464,7 @@ void JvmtiClassFileReconstituter::write_permitted_subclasses_attribute() {

write_attribute_name_index("PermittedSubclasses");
write_u4(length);
write_u2(number_of_classes);
write_u2(checked_cast<u2>(number_of_classes));
for (int i = 0; i < number_of_classes; i++) {
u2 class_cp_index = permitted_subclasses->at(i);
write_u2(class_cp_index);
Expand All @@ -488,7 +488,7 @@ void JvmtiClassFileReconstituter::write_record_attribute() {
int number_of_components = components->length();

// Each component has a u2 for name, descr, attribute count
int length = sizeof(u2) + (sizeof(u2) * 3 * number_of_components);
u4 length = checked_cast<u4>(sizeof(u2) + (sizeof(u2) * 3 * number_of_components));
for (int x = 0; x < number_of_components; x++) {
RecordComponent* component = components->at(x);
if (component->generic_signature_index() != 0) {
Expand All @@ -505,7 +505,7 @@ void JvmtiClassFileReconstituter::write_record_attribute() {

write_attribute_name_index("Record");
write_u4(length);
write_u2(number_of_components);
write_u2(checked_cast<u2>(number_of_components));
for (int i = 0; i < number_of_components; i++) {
RecordComponent* component = components->at(i);
write_u2(component->name_index());
Expand Down Expand Up @@ -538,7 +538,7 @@ void JvmtiClassFileReconstituter::write_inner_classes_attribute(int length) {
InnerClassesIterator iter(ik());
guarantee(iter.length() != 0 && iter.length() == length,
"caller must check");
u2 entry_count = length / InstanceKlass::inner_class_next_offset;
u2 entry_count = checked_cast<u2>(length / InstanceKlass::inner_class_next_offset);
u4 size = 2 + entry_count * (2+2+2+2);

write_attribute_name_index("InnerClasses");
Expand Down Expand Up @@ -592,8 +592,8 @@ void JvmtiClassFileReconstituter::write_line_number_table_attribute(const method

CompressedLineNumberReadStream stream(method->compressed_linenumber_table());
while (stream.read_pair()) {
write_u2(stream.bci());
write_u2(stream.line());
write_u2(checked_cast<u2>(stream.bci()));
write_u2(checked_cast<u2>(stream.line()));
}
}

Expand Down Expand Up @@ -736,7 +736,7 @@ void JvmtiClassFileReconstituter::write_method_info(const methodHandle& method)
++attr_count; // has RuntimeVisibleTypeAnnotations attribute
}

write_u2(attr_count);
write_u2(checked_cast<u2>(attr_count));
if (const_method->code_size() > 0) {
write_code_attribute(method);
}
Expand Down Expand Up @@ -776,7 +776,7 @@ void JvmtiClassFileReconstituter::write_class_attributes() {
AnnotationArray* anno = ik()->class_annotations();
AnnotationArray* type_anno = ik()->class_type_annotations();

int attr_count = 0;
u2 attr_count = 0;
if (generic_signature != nullptr) {
++attr_count;
}
Expand Down Expand Up @@ -867,7 +867,7 @@ void JvmtiClassFileReconstituter::write_method_infos() {
}
}

write_u2(num_methods - num_overpass);
write_u2(checked_cast<u2>(num_methods - num_overpass));
if (JvmtiExport::can_maintain_original_method_order()) {
int index;
int original_index;
Expand Down Expand Up @@ -911,7 +911,7 @@ void JvmtiClassFileReconstituter::write_class_file_format() {

// JVMSpec| u2 constant_pool_count;
// JVMSpec| cp_info constant_pool[constant_pool_count-1];
write_u2(cpool()->length());
write_u2(checked_cast<u2>(cpool()->length()));
copy_cpool_bytes(writeable_address(cpool_size()));

// JVMSpec| u2 access_flags;
Expand All @@ -928,7 +928,7 @@ void JvmtiClassFileReconstituter::write_class_file_format() {
// JVMSpec| u2 interfaces[interfaces_count];
Array<InstanceKlass*>* interfaces = ik()->local_interfaces();
int num_interfaces = interfaces->length();
write_u2(num_interfaces);
write_u2(checked_cast<u2>(num_interfaces));
for (int index = 0; index < num_interfaces; index++) {
HandleMark hm(thread());
InstanceKlass* iik = interfaces->at(index);
Expand Down
4 changes: 1 addition & 3 deletions src/hotspot/share/prims/jvmtiCodeBlobEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,7 @@ void JvmtiCodeBlobEvents::build_jvmti_addr_location_map(nmethod *nm,

if (!mh->is_native()) {
PcDesc *pcd;
int pcds_in_method;

pcds_in_method = (nm->scopes_pcs_end() - nm->scopes_pcs_begin());
int pcds_in_method = pointer_delta_as_int(nm->scopes_pcs_end(), nm->scopes_pcs_begin());
map = NEW_C_HEAP_ARRAY(jvmtiAddrLocationMap, pcds_in_method, mtInternal);

address scopes_data = nm->scopes_data_begin();
Expand Down
Loading

1 comment on commit cf82e31

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.