8313564: Fix -Wconversion warnings in classfile code

Reviewed-by: matsaave, dholmes
This commit is contained in:
Coleen Phillimore 2023-08-04 14:06:16 +00:00
parent e8a37b90db
commit f66cd5008d
19 changed files with 57 additions and 52 deletions

View File

@ -1805,7 +1805,7 @@ void VM_Version::get_processor_features() {
}
// Allocation prefetch settings
intx cache_line_size = prefetch_data_size();
int cache_line_size = checked_cast<int>(prefetch_data_size());
if (FLAG_IS_DEFAULT(AllocatePrefetchStepSize) &&
(cache_line_size > AllocatePrefetchStepSize)) {
FLAG_SET_DEFAULT(AllocatePrefetchStepSize, cache_line_size);

View File

@ -110,7 +110,7 @@ static void halfsiphash_adddata(uint32_t v[4], uint32_t newdata, int rounds) {
static void halfsiphash_init32(uint32_t v[4], uint64_t seed) {
v[0] = seed & 0xffffffff;
v[1] = seed >> 32;
v[1] = (uint32_t)(seed >> 32);
v[2] = 0x6c796765 ^ v[0];
v[3] = 0x74656462 ^ v[1];
}

View File

@ -965,12 +965,12 @@ public:
// Set the annotation name:
void set_annotation(ID id) {
assert((int)id >= 0 && (int)id < (int)_annotation_LIMIT, "oob");
_annotations_present |= nth_bit((int)id);
_annotations_present |= (int)nth_bit((int)id);
}
void remove_annotation(ID id) {
assert((int)id >= 0 && (int)id < (int)_annotation_LIMIT, "oob");
_annotations_present &= ~nth_bit((int)id);
_annotations_present &= (int)~nth_bit((int)id);
}
// Report if the annotation is present.
@ -1737,8 +1737,8 @@ const ClassFileParser::unsafe_u2* ClassFileParser::parse_localvariable_table(con
TRAPS) {
const char* const tbl_name = (isLVTT) ? "LocalVariableTypeTable" : "LocalVariableTable";
*localvariable_table_length = cfs->get_u2(CHECK_NULL);
const unsigned int size =
(*localvariable_table_length) * sizeof(Classfile_LVT_Element) / sizeof(u2);
const unsigned int size = checked_cast<unsigned>(
(*localvariable_table_length) * sizeof(Classfile_LVT_Element) / sizeof(u2));
const ConstantPool* const cp = _cp;
@ -2349,7 +2349,7 @@ Method* ClassFileParser::parse_method(const ClassFileStream* const cfs,
calculated_attribute_length =
sizeof(max_stack) + sizeof(max_locals) + sizeof(code_length);
calculated_attribute_length +=
calculated_attribute_length += checked_cast<unsigned int>(
code_length +
sizeof(exception_table_length) +
sizeof(code_attributes_count) +
@ -2357,15 +2357,15 @@ Method* ClassFileParser::parse_method(const ClassFileStream* const cfs,
( sizeof(u2) + // start_pc
sizeof(u2) + // end_pc
sizeof(u2) + // handler_pc
sizeof(u2) ); // catch_type_index
sizeof(u2) )); // catch_type_index
while (code_attributes_count--) {
cfs->guarantee_more(6, CHECK_NULL); // code_attribute_name_index, code_attribute_length
const u2 code_attribute_name_index = cfs->get_u2_fast();
const u4 code_attribute_length = cfs->get_u4_fast();
calculated_attribute_length += code_attribute_length +
sizeof(code_attribute_name_index) +
sizeof(code_attribute_length);
(unsigned)sizeof(code_attribute_name_index) +
(unsigned)sizeof(code_attribute_length);
check_property(valid_symbol_at(code_attribute_name_index),
"Invalid code attribute name index %u in class file %s",
code_attribute_name_index,
@ -2479,7 +2479,7 @@ Method* ClassFileParser::parse_method(const ClassFileStream* const cfs,
}
method_parameters_seen = true;
method_parameters_length = cfs->get_u1_fast();
const u2 real_length = (method_parameters_length * 4u) + 1u;
const u4 real_length = (method_parameters_length * 4u) + 1u;
if (method_attribute_length != real_length) {
classfile_parse_error(
"Invalid MethodParameters method attribute length %u in class file",
@ -3202,7 +3202,7 @@ u2 ClassFileParser::parse_classfile_permitted_subclasses_attribute(const ClassFi
// u2 attributes_count;
// attribute_info_attributes[attributes_count];
// }
u2 ClassFileParser::parse_classfile_record_attribute(const ClassFileStream* const cfs,
u4 ClassFileParser::parse_classfile_record_attribute(const ClassFileStream* const cfs,
const ConstantPool* cp,
const u1* const record_attribute_start,
TRAPS) {
@ -3404,7 +3404,7 @@ void ClassFileParser::parse_classfile_bootstrap_methods_attribute(const ClassFil
// The attribute contains a counted array of counted tuples of shorts,
// represending bootstrap specifiers:
// length*{bootstrap_method_index, argument_count*{argument_index}}
const int operand_count = (attribute_byte_length - sizeof(u2)) / sizeof(u2);
const unsigned int operand_count = (attribute_byte_length - (unsigned)sizeof(u2)) / (unsigned)sizeof(u2);
// operand_count = number of shorts in attr, except for leading length
// The attribute is copied into a short[] array.
@ -4812,7 +4812,7 @@ const char* ClassFileParser::skip_over_field_signature(const char* signature,
const char* c = (const char*) memchr(signature, JVM_SIGNATURE_ENDCLASS, length - 1);
// Format check signature
if (c != nullptr) {
int newlen = c - (char*) signature;
int newlen = pointer_delta_as_int(c, (char*) signature);
bool legal = verify_unqualified_name(signature, newlen, LegalClass);
if (!legal) {
classfile_parse_error("Class name is empty or contains illegal character "
@ -5022,7 +5022,7 @@ int ClassFileParser::verify_legal_method_signature(const Symbol* name,
if (p[0] == 'J' || p[0] == 'D') {
args_size++;
}
length -= nextp - p;
length -= pointer_delta_as_int(nextp, p);
p = nextp;
nextp = skip_over_field_signature(p, false, length, CHECK_0);
}
@ -5241,7 +5241,7 @@ void ClassFileParser::fill_instance_klass(InstanceKlass* ik,
// size is equal to the number of methods in the class. If
// that changes, then InstanceKlass::idnum_can_increment()
// has to be changed accordingly.
ik->set_initial_method_idnum(ik->methods()->length());
ik->set_initial_method_idnum(checked_cast<u2>(ik->methods()->length()));
ik->set_this_class_index(_this_class_index);

View File

@ -330,7 +330,7 @@ class ClassFileParser {
const u1* const permitted_subclasses_attribute_start,
TRAPS);
u2 parse_classfile_record_attribute(const ClassFileStream* const cfs,
u4 parse_classfile_record_attribute(const ClassFileStream* const cfs,
const ConstantPool* cp,
const u1* const record_attribute_start,
TRAPS);

View File

@ -218,7 +218,7 @@ Symbol* ClassLoader::package_from_class_name(const Symbol* name, bool* bad_class
}
return nullptr;
}
return SymbolTable::new_symbol(name, start - base, end - base);
return SymbolTable::new_symbol(name, pointer_delta_as_int(start, base), pointer_delta_as_int(end, base));
}
// 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*
// debug builds so that we guard against use-after-free bugs.
FREE_RESOURCE_ARRAY_IN_THREAD(current, char, path, path_len);
#endif
// We don't verify the length of the classfile stream fits in an int, but this is the
// bootloader so we have control of this.
// Resource allocated
return new ClassFileStream(buffer,
st.st_size,
checked_cast<int>(st.st_size),
_dir,
ClassFileStream::verify);
}
@ -420,7 +422,7 @@ ClassFileStream* ClassPathImageEntry::open_stream_for_loader(JavaThread* current
// Resource allocated
assert(this == (ClassPathImageEntry*)ClassLoader::get_jrt_entry(), "must be");
return new ClassFileStream((u1*)data,
(int)size,
checked_cast<int>(size),
_name,
ClassFileStream::verify,
true); // from_boot_loader_modules_image

View File

@ -215,7 +215,7 @@ void ClassLoaderExt::process_jar_manifest(JavaThread* current, ClassPathEntry* e
if (dir_tail == nullptr) {
dir_len = 0;
} else {
dir_len = dir_tail - dir_name + 1;
dir_len = pointer_delta_as_int(dir_tail, dir_name) + 1;
}
// Split the cp_attr by spaces, and add each file

View File

@ -365,8 +365,8 @@ int HashtableTextDump::scan_symbol_prefix() {
return utf8_length;
}
jchar HashtableTextDump::unescape(const char* from, const char* end, int count) {
jchar value = 0;
int HashtableTextDump::unescape(const char* from, const char* end, int count) {
int value = 0;
corrupted_if(from + count > end, "Truncated");
@ -409,7 +409,7 @@ void HashtableTextDump::get_utf8(char* utf8_buffer, int utf8_length) {
switch (c) {
case 'x':
{
jchar value = unescape(from, end, 2);
int value = unescape(from, end, 2);
from += 2;
assert(value <= 0xff, "sanity");
*to++ = (char)(value & 0xff);

View File

@ -427,7 +427,7 @@ public:
int scan_string_prefix();
int scan_symbol_prefix();
jchar unescape(const char* from, const char* end, int count);
int unescape(const char* from, const char* end, int count);
void get_utf8(char* utf8_buffer, int utf8_length);
static void put_utf8(outputStream* st, const char* utf8_string, int utf8_length);
};

View File

@ -76,7 +76,7 @@ InstanceKlass* KlassFactory::check_shared_class_file_load_hook(
ClassLoaderData::class_loader_data(class_loader());
s2 path_index = ik->shared_classpath_index();
ClassFileStream* stream = new ClassFileStream(ptr,
end_ptr - ptr,
pointer_delta_as_int(end_ptr, ptr),
cfs->source(),
ClassFileStream::verify);
ClassLoadInfo cl_info(protection_domain);
@ -155,7 +155,7 @@ static ClassFileStream* check_class_file_load_hook(ClassFileStream* stream,
// JVMTI agent has modified class file data.
// Set new class file stream using JVMTI agent modified class file data.
stream = new ClassFileStream(ptr,
end_ptr - ptr,
pointer_delta_as_int(end_ptr, ptr),
stream->source(),
stream->need_verify());
}

View File

@ -495,7 +495,7 @@ void LoaderConstraintTable::print_table_statistics(outputStream* st) {
int len = set.num_constraints();
for (int i = 0; i < len; i++) {
LoaderConstraint* probe = set.constraint_at(i);
sum += sizeof(*probe) + (probe->num_loaders() * sizeof(ClassLoaderData*));
sum += (int)(sizeof(*probe) + (probe->num_loaders() * sizeof(ClassLoaderData*)));
}
return sum;
};

View File

@ -121,7 +121,7 @@ volatile bool _alt_hash = false;
static bool _rehashed = false;
static uint64_t _alt_hash_seed = 0;
uintx hash_string(const jchar* s, int len, bool useAlt) {
unsigned int hash_string(const jchar* s, int len, bool useAlt) {
return useAlt ?
AltHashing::halfsiphash_32(_alt_hash_seed, s, len) :
java_lang_String::hash_code(s, len);
@ -241,12 +241,12 @@ void StringTable::create_table() {
#endif
}
size_t StringTable::item_added() {
return Atomic::add(&_items_count, (size_t)1);
void StringTable::item_added() {
Atomic::inc(&_items_count);
}
void StringTable::item_removed() {
Atomic::add(&_items_count, (size_t)-1);
Atomic::dec(&_items_count);
}
double StringTable::get_load_factor() {
@ -802,7 +802,7 @@ oop StringTable::lookup_shared(const jchar* name, int len) {
void StringTable::allocate_shared_strings_array(TRAPS) {
assert(DumpSharedSpaces, "must be");
if (_items_count > (size_t)max_jint) {
fatal("Too many strings to be archived: " SIZE_FORMAT, _items_count);
fatal("Too many strings to be archived: %zu", _items_count);
}
int total = (int)_items_count;
@ -825,7 +825,7 @@ void StringTable::allocate_shared_strings_array(TRAPS) {
// This can only happen if you have an extremely large number of classes that
// refer to more than 16384 * 16384 = 26M interned strings! Not a practical concern
// but bail out for safety.
log_error(cds)("Too many strings to be archived: " SIZE_FORMAT, _items_count);
log_error(cds)("Too many strings to be archived: %zu", _items_count);
MetaspaceShared::unrecoverable_writing_error();
}
@ -888,7 +888,7 @@ oop StringTable::init_shared_table(const DumpedInternedStrings* dumped_interned_
verify_secondary_array_index_bits();
_shared_table.reset();
CompactHashtableWriter writer(_items_count, ArchiveBuilder::string_stats());
CompactHashtableWriter writer((int)_items_count, ArchiveBuilder::string_stats());
int index = 0;
auto copy_into_array = [&] (oop string, bool value_ignored) {

View File

@ -66,7 +66,7 @@ class StringTable : public CHeapObj<mtSymbol>{
static void gc_notification(size_t num_dead);
static void trigger_concurrent_work();
static size_t item_added();
static void item_added();
static void item_removed();
static oop intern(Handle string_or_null_h, const jchar* name, int len, TRAPS);

View File

@ -115,14 +115,14 @@ static inline void log_trace_symboltable_helper(Symbol* sym, const char* msg) {
}
// Pick hashing algorithm.
static uintx hash_symbol(const char* s, int len, bool useAlt) {
static unsigned int hash_symbol(const char* s, int len, bool useAlt) {
return useAlt ?
AltHashing::halfsiphash_32(_alt_hash_seed, (const uint8_t*)s, len) :
java_lang_String::hash_code((const jbyte*)s, len);
}
#if INCLUDE_CDS
static uintx hash_shared_symbol(const char* s, int len) {
static unsigned int hash_shared_symbol(const char* s, int len) {
return java_lang_String::hash_code((const jbyte*)s, len);
}
#endif
@ -237,7 +237,7 @@ void SymbolTable::item_removed() {
}
double SymbolTable::get_load_factor() {
return (double)_items_count/_current_size;
return (double)_items_count/(double)_current_size;
}
size_t SymbolTable::table_size() {
@ -657,6 +657,9 @@ void SymbolTable::copy_shared_symbol_table(GrowableArray<Symbol*>* symbols,
}
size_t SymbolTable::estimate_size_for_archive() {
if (_items_count > (size_t)max_jint) {
fatal("Too many symbols to be archived: %zu", _items_count);
}
return CompactHashtableWriter::estimate_size(int(_items_count));
}
@ -923,14 +926,14 @@ void SymbolTable::print_histogram() {
tty->print_cr(" Total removed " SIZE_FORMAT_W(7), _symbols_removed);
if (_symbols_counted > 0) {
tty->print_cr(" Percent removed %3.2f",
((float)_symbols_removed / _symbols_counted) * 100);
((double)_symbols_removed / (double)_symbols_counted) * 100);
}
tty->print_cr(" Reference counts " SIZE_FORMAT_W(7), Symbol::_total_count);
tty->print_cr(" Symbol arena used " SIZE_FORMAT_W(7) "K", arena()->used() / K);
tty->print_cr(" Symbol arena size " SIZE_FORMAT_W(7) "K", arena()->size_in_bytes() / K);
tty->print_cr(" Total symbol length " SIZE_FORMAT_W(7), hi.total_length);
tty->print_cr(" Maximum symbol length " SIZE_FORMAT_W(7), hi.max_length);
tty->print_cr(" Average symbol length %7.2f", ((float)hi.total_length / hi.total_count));
tty->print_cr(" Average symbol length %7.2f", ((double)hi.total_length / (double)hi.total_count));
tty->print_cr(" Symbol length histogram:");
tty->print_cr(" %6s %10s %10s", "Length", "#Symbols", "Size");
for (size_t i = 0; i < hi.results_length; i++) {

View File

@ -597,9 +597,9 @@ public:
ClassLoaderData* loader_b = b[0]->class_loader_data();
if (loader_a != loader_b) {
return intx(loader_a) - intx(loader_b);
return checked_cast<int>(intptr_t(loader_a) - intptr_t(loader_b));
} else {
return intx(a[0]) - intx(b[0]);
return checked_cast<int>(intptr_t(a[0]) - intptr_t(b[0]));
}
}

View File

@ -806,21 +806,21 @@ vmSymbolID vmIntrinsics::class_for(vmIntrinsics::ID id) {
jlong info = intrinsic_info(id);
int shift = 2*vmSymbols::log2_SID_LIMIT + log2_FLAG_LIMIT, mask = right_n_bits(vmSymbols::log2_SID_LIMIT);
assert(((ID4(1021,1022,1023,7) >> shift) & mask) == 1021, "");
return vmSymbols::as_SID( (info >> shift) & mask );
return vmSymbols::as_SID( checked_cast<int>((info >> shift) & mask));
}
vmSymbolID vmIntrinsics::name_for(vmIntrinsics::ID id) {
jlong info = intrinsic_info(id);
int shift = vmSymbols::log2_SID_LIMIT + log2_FLAG_LIMIT, mask = right_n_bits(vmSymbols::log2_SID_LIMIT);
assert(((ID4(1021,1022,1023,7) >> shift) & mask) == 1022, "");
return vmSymbols::as_SID( (info >> shift) & mask );
return vmSymbols::as_SID( checked_cast<int>((info >> shift) & mask));
}
vmSymbolID vmIntrinsics::signature_for(vmIntrinsics::ID id) {
jlong info = intrinsic_info(id);
int shift = log2_FLAG_LIMIT, mask = right_n_bits(vmSymbols::log2_SID_LIMIT);
assert(((ID4(1021,1022,1023,7) >> shift) & mask) == 1023, "");
return vmSymbols::as_SID( (info >> shift) & mask );
return vmSymbols::as_SID( checked_cast<int>((info >> shift) & mask));
}
vmIntrinsics::Flags vmIntrinsics::flags_for(vmIntrinsics::ID id) {

View File

@ -265,7 +265,7 @@ JVMCIObjectArray CompilerToVM::initialize_intrinsics(JVMCI_TRAPS) {
do_bool_flag(CITimeEach) \
do_uintx_flag(CodeCacheSegmentSize) \
do_intx_flag(CodeEntryAlignment) \
do_intx_flag(ContendedPaddingWidth) \
do_int_flag(ContendedPaddingWidth) \
do_bool_flag(DontCompileHugeMethods) \
do_bool_flag(EagerJVMCI) \
do_bool_flag(EnableContended) \

View File

@ -53,10 +53,10 @@ JVMFlag::Error ObjectAlignmentInBytesConstraintFunc(int value, bool verbose) {
// Need to enforce the padding not to break the existing field alignments.
// It is sufficient to check against the largest type size.
JVMFlag::Error ContendedPaddingWidthConstraintFunc(intx value, bool verbose) {
JVMFlag::Error ContendedPaddingWidthConstraintFunc(int value, bool verbose) {
if ((value % BytesPerLong) != 0) {
JVMFlag::printError(verbose,
"ContendedPaddingWidth (" INTX_FORMAT ") must be "
"ContendedPaddingWidth (%d) must be "
"a multiple of %d\n",
value, BytesPerLong);
return JVMFlag::VIOLATES_CONSTRAINT;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -35,7 +35,7 @@
#define RUNTIME_CONSTRAINTS(f) \
f(int, ObjectAlignmentInBytesConstraintFunc) \
f(intx, ContendedPaddingWidthConstraintFunc) \
f(int, ContendedPaddingWidthConstraintFunc) \
f(intx, PerfDataSamplingIntervalFunc) \
f(uintx, VMPageSizeConstraintFunc) \
f(size_t, NUMAInterleaveGranularityConstraintFunc)

View File

@ -802,7 +802,7 @@ const int ObjectAlignmentInBytes = 8;
/* 8K is well beyond the reasonable HW cache line size, even with */\
/* aggressive prefetching, while still leaving the room for segregating */\
/* among the distinct pages. */\
product(intx, ContendedPaddingWidth, 128, \
product(int, ContendedPaddingWidth, 128, \
"How many bytes to pad the fields/classes marked @Contended with")\
range(0, 8192) \
constraint(ContendedPaddingWidthConstraintFunc,AfterErgo) \