Skip to content

Commit f66cd50

Browse files
committed
8313564: Fix -Wconversion warnings in classfile code
Reviewed-by: matsaave, dholmes
1 parent e8a37b9 commit f66cd50

19 files changed

+57
-52
lines changed

src/hotspot/cpu/x86/vm_version_x86.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1805,7 +1805,7 @@ void VM_Version::get_processor_features() {
18051805
}
18061806

18071807
// Allocation prefetch settings
1808-
intx cache_line_size = prefetch_data_size();
1808+
int cache_line_size = checked_cast<int>(prefetch_data_size());
18091809
if (FLAG_IS_DEFAULT(AllocatePrefetchStepSize) &&
18101810
(cache_line_size > AllocatePrefetchStepSize)) {
18111811
FLAG_SET_DEFAULT(AllocatePrefetchStepSize, cache_line_size);

src/hotspot/share/classfile/altHashing.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ static void halfsiphash_adddata(uint32_t v[4], uint32_t newdata, int rounds) {
110110

111111
static void halfsiphash_init32(uint32_t v[4], uint64_t seed) {
112112
v[0] = seed & 0xffffffff;
113-
v[1] = seed >> 32;
113+
v[1] = (uint32_t)(seed >> 32);
114114
v[2] = 0x6c796765 ^ v[0];
115115
v[3] = 0x74656462 ^ v[1];
116116
}

src/hotspot/share/classfile/classFileParser.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -965,12 +965,12 @@ class AnnotationCollector : public ResourceObj{
965965
// Set the annotation name:
966966
void set_annotation(ID id) {
967967
assert((int)id >= 0 && (int)id < (int)_annotation_LIMIT, "oob");
968-
_annotations_present |= nth_bit((int)id);
968+
_annotations_present |= (int)nth_bit((int)id);
969969
}
970970

971971
void remove_annotation(ID id) {
972972
assert((int)id >= 0 && (int)id < (int)_annotation_LIMIT, "oob");
973-
_annotations_present &= ~nth_bit((int)id);
973+
_annotations_present &= (int)~nth_bit((int)id);
974974
}
975975

976976
// Report if the annotation is present.
@@ -1737,8 +1737,8 @@ const ClassFileParser::unsafe_u2* ClassFileParser::parse_localvariable_table(con
17371737
TRAPS) {
17381738
const char* const tbl_name = (isLVTT) ? "LocalVariableTypeTable" : "LocalVariableTable";
17391739
*localvariable_table_length = cfs->get_u2(CHECK_NULL);
1740-
const unsigned int size =
1741-
(*localvariable_table_length) * sizeof(Classfile_LVT_Element) / sizeof(u2);
1740+
const unsigned int size = checked_cast<unsigned>(
1741+
(*localvariable_table_length) * sizeof(Classfile_LVT_Element) / sizeof(u2));
17421742

17431743
const ConstantPool* const cp = _cp;
17441744

@@ -2349,23 +2349,23 @@ Method* ClassFileParser::parse_method(const ClassFileStream* const cfs,
23492349

23502350
calculated_attribute_length =
23512351
sizeof(max_stack) + sizeof(max_locals) + sizeof(code_length);
2352-
calculated_attribute_length +=
2352+
calculated_attribute_length += checked_cast<unsigned int>(
23532353
code_length +
23542354
sizeof(exception_table_length) +
23552355
sizeof(code_attributes_count) +
23562356
exception_table_length *
23572357
( sizeof(u2) + // start_pc
23582358
sizeof(u2) + // end_pc
23592359
sizeof(u2) + // handler_pc
2360-
sizeof(u2) ); // catch_type_index
2360+
sizeof(u2) )); // catch_type_index
23612361

23622362
while (code_attributes_count--) {
23632363
cfs->guarantee_more(6, CHECK_NULL); // code_attribute_name_index, code_attribute_length
23642364
const u2 code_attribute_name_index = cfs->get_u2_fast();
23652365
const u4 code_attribute_length = cfs->get_u4_fast();
23662366
calculated_attribute_length += code_attribute_length +
2367-
sizeof(code_attribute_name_index) +
2368-
sizeof(code_attribute_length);
2367+
(unsigned)sizeof(code_attribute_name_index) +
2368+
(unsigned)sizeof(code_attribute_length);
23692369
check_property(valid_symbol_at(code_attribute_name_index),
23702370
"Invalid code attribute name index %u in class file %s",
23712371
code_attribute_name_index,
@@ -2479,7 +2479,7 @@ Method* ClassFileParser::parse_method(const ClassFileStream* const cfs,
24792479
}
24802480
method_parameters_seen = true;
24812481
method_parameters_length = cfs->get_u1_fast();
2482-
const u2 real_length = (method_parameters_length * 4u) + 1u;
2482+
const u4 real_length = (method_parameters_length * 4u) + 1u;
24832483
if (method_attribute_length != real_length) {
24842484
classfile_parse_error(
24852485
"Invalid MethodParameters method attribute length %u in class file",
@@ -3202,7 +3202,7 @@ u2 ClassFileParser::parse_classfile_permitted_subclasses_attribute(const ClassFi
32023202
// u2 attributes_count;
32033203
// attribute_info_attributes[attributes_count];
32043204
// }
3205-
u2 ClassFileParser::parse_classfile_record_attribute(const ClassFileStream* const cfs,
3205+
u4 ClassFileParser::parse_classfile_record_attribute(const ClassFileStream* const cfs,
32063206
const ConstantPool* cp,
32073207
const u1* const record_attribute_start,
32083208
TRAPS) {
@@ -3404,7 +3404,7 @@ void ClassFileParser::parse_classfile_bootstrap_methods_attribute(const ClassFil
34043404
// The attribute contains a counted array of counted tuples of shorts,
34053405
// represending bootstrap specifiers:
34063406
// length*{bootstrap_method_index, argument_count*{argument_index}}
3407-
const int operand_count = (attribute_byte_length - sizeof(u2)) / sizeof(u2);
3407+
const unsigned int operand_count = (attribute_byte_length - (unsigned)sizeof(u2)) / (unsigned)sizeof(u2);
34083408
// operand_count = number of shorts in attr, except for leading length
34093409

34103410
// The attribute is copied into a short[] array.
@@ -4812,7 +4812,7 @@ const char* ClassFileParser::skip_over_field_signature(const char* signature,
48124812
const char* c = (const char*) memchr(signature, JVM_SIGNATURE_ENDCLASS, length - 1);
48134813
// Format check signature
48144814
if (c != nullptr) {
4815-
int newlen = c - (char*) signature;
4815+
int newlen = pointer_delta_as_int(c, (char*) signature);
48164816
bool legal = verify_unqualified_name(signature, newlen, LegalClass);
48174817
if (!legal) {
48184818
classfile_parse_error("Class name is empty or contains illegal character "
@@ -5022,7 +5022,7 @@ int ClassFileParser::verify_legal_method_signature(const Symbol* name,
50225022
if (p[0] == 'J' || p[0] == 'D') {
50235023
args_size++;
50245024
}
5025-
length -= nextp - p;
5025+
length -= pointer_delta_as_int(nextp, p);
50265026
p = nextp;
50275027
nextp = skip_over_field_signature(p, false, length, CHECK_0);
50285028
}
@@ -5241,7 +5241,7 @@ void ClassFileParser::fill_instance_klass(InstanceKlass* ik,
52415241
// size is equal to the number of methods in the class. If
52425242
// that changes, then InstanceKlass::idnum_can_increment()
52435243
// has to be changed accordingly.
5244-
ik->set_initial_method_idnum(ik->methods()->length());
5244+
ik->set_initial_method_idnum(checked_cast<u2>(ik->methods()->length()));
52455245

52465246
ik->set_this_class_index(_this_class_index);
52475247

src/hotspot/share/classfile/classFileParser.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ class ClassFileParser {
330330
const u1* const permitted_subclasses_attribute_start,
331331
TRAPS);
332332

333-
u2 parse_classfile_record_attribute(const ClassFileStream* const cfs,
333+
u4 parse_classfile_record_attribute(const ClassFileStream* const cfs,
334334
const ConstantPool* cp,
335335
const u1* const record_attribute_start,
336336
TRAPS);

src/hotspot/share/classfile/classLoader.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ Symbol* ClassLoader::package_from_class_name(const Symbol* name, bool* bad_class
218218
}
219219
return nullptr;
220220
}
221-
return SymbolTable::new_symbol(name, start - base, end - base);
221+
return SymbolTable::new_symbol(name, pointer_delta_as_int(start, base), pointer_delta_as_int(end, base));
222222
}
223223

224224
// Given a fully qualified package name, find its defining package in the class loader's
@@ -269,9 +269,11 @@ ClassFileStream* ClassPathDirEntry::open_stream(JavaThread* current, const char*
269269
// debug builds so that we guard against use-after-free bugs.
270270
FREE_RESOURCE_ARRAY_IN_THREAD(current, char, path, path_len);
271271
#endif
272+
// We don't verify the length of the classfile stream fits in an int, but this is the
273+
// bootloader so we have control of this.
272274
// Resource allocated
273275
return new ClassFileStream(buffer,
274-
st.st_size,
276+
checked_cast<int>(st.st_size),
275277
_dir,
276278
ClassFileStream::verify);
277279
}
@@ -420,7 +422,7 @@ ClassFileStream* ClassPathImageEntry::open_stream_for_loader(JavaThread* current
420422
// Resource allocated
421423
assert(this == (ClassPathImageEntry*)ClassLoader::get_jrt_entry(), "must be");
422424
return new ClassFileStream((u1*)data,
423-
(int)size,
425+
checked_cast<int>(size),
424426
_name,
425427
ClassFileStream::verify,
426428
true); // from_boot_loader_modules_image

src/hotspot/share/classfile/classLoaderExt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ void ClassLoaderExt::process_jar_manifest(JavaThread* current, ClassPathEntry* e
215215
if (dir_tail == nullptr) {
216216
dir_len = 0;
217217
} else {
218-
dir_len = dir_tail - dir_name + 1;
218+
dir_len = pointer_delta_as_int(dir_tail, dir_name) + 1;
219219
}
220220

221221
// Split the cp_attr by spaces, and add each file

src/hotspot/share/classfile/compactHashtable.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,8 @@ int HashtableTextDump::scan_symbol_prefix() {
365365
return utf8_length;
366366
}
367367

368-
jchar HashtableTextDump::unescape(const char* from, const char* end, int count) {
369-
jchar value = 0;
368+
int HashtableTextDump::unescape(const char* from, const char* end, int count) {
369+
int value = 0;
370370

371371
corrupted_if(from + count > end, "Truncated");
372372

@@ -409,7 +409,7 @@ void HashtableTextDump::get_utf8(char* utf8_buffer, int utf8_length) {
409409
switch (c) {
410410
case 'x':
411411
{
412-
jchar value = unescape(from, end, 2);
412+
int value = unescape(from, end, 2);
413413
from += 2;
414414
assert(value <= 0xff, "sanity");
415415
*to++ = (char)(value & 0xff);

src/hotspot/share/classfile/compactHashtable.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ class HashtableTextDump {
427427
int scan_string_prefix();
428428
int scan_symbol_prefix();
429429

430-
jchar unescape(const char* from, const char* end, int count);
430+
int unescape(const char* from, const char* end, int count);
431431
void get_utf8(char* utf8_buffer, int utf8_length);
432432
static void put_utf8(outputStream* st, const char* utf8_string, int utf8_length);
433433
};

src/hotspot/share/classfile/klassFactory.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ InstanceKlass* KlassFactory::check_shared_class_file_load_hook(
7676
ClassLoaderData::class_loader_data(class_loader());
7777
s2 path_index = ik->shared_classpath_index();
7878
ClassFileStream* stream = new ClassFileStream(ptr,
79-
end_ptr - ptr,
79+
pointer_delta_as_int(end_ptr, ptr),
8080
cfs->source(),
8181
ClassFileStream::verify);
8282
ClassLoadInfo cl_info(protection_domain);
@@ -155,7 +155,7 @@ static ClassFileStream* check_class_file_load_hook(ClassFileStream* stream,
155155
// JVMTI agent has modified class file data.
156156
// Set new class file stream using JVMTI agent modified class file data.
157157
stream = new ClassFileStream(ptr,
158-
end_ptr - ptr,
158+
pointer_delta_as_int(end_ptr, ptr),
159159
stream->source(),
160160
stream->need_verify());
161161
}

src/hotspot/share/classfile/loaderConstraints.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ void LoaderConstraintTable::print_table_statistics(outputStream* st) {
495495
int len = set.num_constraints();
496496
for (int i = 0; i < len; i++) {
497497
LoaderConstraint* probe = set.constraint_at(i);
498-
sum += sizeof(*probe) + (probe->num_loaders() * sizeof(ClassLoaderData*));
498+
sum += (int)(sizeof(*probe) + (probe->num_loaders() * sizeof(ClassLoaderData*)));
499499
}
500500
return sum;
501501
};

0 commit comments

Comments
 (0)