8314114: Fix -Wconversion warnings in os code, primarily linux

Reviewed-by: dholmes, dlong
This commit is contained in:
Coleen Phillimore 2023-08-15 11:05:31 +00:00
parent a02d65efcc
commit 9ded86821b
18 changed files with 129 additions and 127 deletions

View File

@ -108,7 +108,7 @@ class AixAttachListener: AllStatic {
static bool is_shutdown() { return _shutdown; }
// write the given buffer to a socket
static int write_fully(int s, char* buf, int len);
static int write_fully(int s, char* buf, size_t len);
static AixAttachOperation* dequeue();
};
@ -276,7 +276,7 @@ AixAttachOperation* AixAttachListener::read_request(int s) {
// where <ver> is the protocol version (1), <cmd> is the command
// name ("load", "datadump", ...), and <arg> is an argument
int expected_str_count = 2 + AttachOperation::arg_count_max;
const int max_len = (sizeof(ver_str) + 1) + (AttachOperation::name_length_max + 1) +
const size_t max_len = (sizeof(ver_str) + 1) + (AttachOperation::name_length_max + 1) +
AttachOperation::arg_count_max*(AttachOperation::arg_length_max + 1);
char buf[max_len];
@ -285,15 +285,15 @@ AixAttachOperation* AixAttachListener::read_request(int s) {
// Read until all (expected) strings have been read, the buffer is
// full, or EOF.
int off = 0;
int left = max_len;
size_t off = 0;
size_t left = max_len;
do {
int n;
ssize_t n;
// Don't block on interrupts because this will
// hang in the clean-up when shutting down.
n = read(s, buf+off, left);
assert(n <= left, "buffer was too small, impossible!");
assert(n <= checked_cast<ssize_t>(left), "buffer was too small, impossible!");
buf[max_len - 1] = '\0';
if (n == -1) {
return nullptr; // reset by peer or other error
@ -414,9 +414,9 @@ AixAttachOperation* AixAttachListener::dequeue() {
}
// write the given buffer to the socket
int AixAttachListener::write_fully(int s, char* buf, int len) {
int AixAttachListener::write_fully(int s, char* buf, size_t len) {
do {
int n = ::write(s, buf, len);
ssize_t n = ::write(s, buf, len);
if (n == -1) {
if (errno != EINTR) return -1;
} else {

View File

@ -2985,7 +2985,7 @@ int os::get_core_path(char* buffer, size_t bufferSize) {
jio_snprintf(buffer, bufferSize, "%s/core or core.%d",
p, current_process_id());
return strlen(buffer);
return checked_cast<int>(strlen(buffer));
}
bool os::start_debugging(char *buf, int buflen) {
@ -3023,7 +3023,7 @@ static inline time_t get_mtime(const char* filename) {
int os::compare_file_modified_times(const char* file1, const char* file2) {
time_t t1 = get_mtime(file1);
time_t t2 = get_mtime(file2);
return t1 - t2;
return primitive_compare(t1, t2);
}
bool os::supports_map_sync() {

View File

@ -77,7 +77,7 @@ static bool read_psinfo(const u_longlong_t& pid, psinfo_t& psinfo) {
FILE* fp;
char buf[BUF_LENGTH];
int len;
size_t len;
jio_snprintf(buf, BUF_LENGTH, "/proc/%llu/psinfo", pid);
fp = fopen(buf, "r");

View File

@ -102,7 +102,7 @@ class BsdAttachListener: AllStatic {
static int listener() { return _listener; }
// write the given buffer to a socket
static int write_fully(int s, char* buf, int len);
static int write_fully(int s, char* buf, size_t len);
static BsdAttachOperation* dequeue();
};
@ -257,7 +257,7 @@ BsdAttachOperation* BsdAttachListener::read_request(int s) {
// where <ver> is the protocol version (1), <cmd> is the command
// name ("load", "datadump", ...), and <arg> is an argument
int expected_str_count = 2 + AttachOperation::arg_count_max;
const int max_len = (sizeof(ver_str) + 1) + (AttachOperation::name_length_max + 1) +
const size_t max_len = (sizeof(ver_str) + 1) + (AttachOperation::name_length_max + 1) +
AttachOperation::arg_count_max*(AttachOperation::arg_length_max + 1);
char buf[max_len];
@ -266,13 +266,13 @@ BsdAttachOperation* BsdAttachListener::read_request(int s) {
// Read until all (expected) strings have been read, the buffer is
// full, or EOF.
int off = 0;
int left = max_len;
size_t off = 0;
size_t left = max_len;
do {
int n;
ssize_t n;
RESTARTABLE(read(s, buf+off, left), n);
assert(n <= left, "buffer was too small, impossible!");
assert(n <= checked_cast<ssize_t>(left), "buffer was too small, impossible!");
buf[max_len - 1] = '\0';
if (n == -1) {
return nullptr; // reset by peer or other error
@ -280,7 +280,7 @@ BsdAttachOperation* BsdAttachListener::read_request(int s) {
if (n == 0) {
break;
}
for (int i=0; i<n; i++) {
for (ssize_t i=0; i<n; i++) {
if (buf[off+i] == 0) {
// EOS found
str_count++;
@ -383,9 +383,9 @@ BsdAttachOperation* BsdAttachListener::dequeue() {
}
// write the given buffer to the socket
int BsdAttachListener::write_fully(int s, char* buf, int len) {
int BsdAttachListener::write_fully(int s, char* buf, size_t len) {
do {
int n = ::write(s, buf, len);
ssize_t n = ::write(s, buf, len);
if (n == -1) {
if (errno != EINTR) return -1;
} else {

View File

@ -2208,9 +2208,9 @@ static inline struct timespec get_mtime(const char* filename) {
int os::compare_file_modified_times(const char* file1, const char* file2) {
struct timespec filetime1 = get_mtime(file1);
struct timespec filetime2 = get_mtime(file2);
int diff = filetime1.tv_sec - filetime2.tv_sec;
int diff = primitive_compare(filetime1.tv_sec, filetime2.tv_sec);
if (diff == 0) {
return filetime1.tv_nsec - filetime2.tv_nsec;
diff = primitive_compare(filetime1.tv_nsec, filetime2.tv_nsec);
}
return diff;
}

View File

@ -103,7 +103,7 @@ class LinuxAttachListener: AllStatic {
static int listener() { return _listener; }
// write the given buffer to a socket
static int write_fully(int s, char* buf, int len);
static int write_fully(int s, char* buf, size_t len);
static LinuxAttachOperation* dequeue();
};
@ -257,7 +257,7 @@ LinuxAttachOperation* LinuxAttachListener::read_request(int s) {
// where <ver> is the protocol version (1), <cmd> is the command
// name ("load", "datadump", ...), and <arg> is an argument
int expected_str_count = 2 + AttachOperation::arg_count_max;
const int max_len = (sizeof(ver_str) + 1) + (AttachOperation::name_length_max + 1) +
const size_t max_len = (sizeof(ver_str) + 1) + (AttachOperation::name_length_max + 1) +
AttachOperation::arg_count_max*(AttachOperation::arg_length_max + 1);
char buf[max_len];
@ -266,13 +266,13 @@ LinuxAttachOperation* LinuxAttachListener::read_request(int s) {
// Read until all (expected) strings have been read, the buffer is
// full, or EOF.
int off = 0;
int left = max_len;
size_t off = 0;
size_t left = max_len;
do {
int n;
ssize_t n;
RESTARTABLE(read(s, buf+off, left), n);
assert(n <= left, "buffer was too small, impossible!");
assert(n <= checked_cast<ssize_t>(left), "buffer was too small, impossible!");
buf[max_len - 1] = '\0';
if (n == -1) {
return nullptr; // reset by peer or other error
@ -280,7 +280,7 @@ LinuxAttachOperation* LinuxAttachListener::read_request(int s) {
if (n == 0) {
break;
}
for (int i=0; i<n; i++) {
for (ssize_t i=0; i<n; i++) {
if (buf[off+i] == 0) {
// EOS found
str_count++;
@ -383,7 +383,7 @@ LinuxAttachOperation* LinuxAttachListener::dequeue() {
}
// write the given buffer to the socket
int LinuxAttachListener::write_fully(int s, char* buf, int len) {
int LinuxAttachListener::write_fully(int s, char* buf, size_t len) {
do {
ssize_t n = ::write(s, buf, len);
if (n == -1) {

View File

@ -401,7 +401,7 @@ bool os::Linux::get_tick_information(CPUPerfTicks* pticks, int which_logical_cpu
// Returns the kernel thread id of the currently running thread. Kernel
// thread id is used to access /proc.
pid_t os::Linux::gettid() {
int rslt = syscall(SYS_gettid);
long rslt = syscall(SYS_gettid);
assert(rslt != -1, "must be."); // old linuxthreads implementation?
return (pid_t)rslt;
}
@ -423,7 +423,7 @@ static const char *unstable_chroot_error = "/proc file system not found.\n"
"environment on Linux when /proc filesystem is not mounted.";
void os::Linux::initialize_system_info() {
set_processor_count(sysconf(_SC_NPROCESSORS_CONF));
set_processor_count((int)sysconf(_SC_NPROCESSORS_CONF));
if (processor_count() == 1) {
pid_t pid = os::Linux::gettid();
char fname[32];
@ -742,7 +742,7 @@ static void *thread_native_entry(Thread *thread) {
OSThread* osthread = thread->osthread();
Monitor* sync = osthread->startThread_lock();
osthread->set_thread_id(os::current_thread_id());
osthread->set_thread_id(checked_cast<OSThread::thread_id_t>(os::current_thread_id()));
if (UseNUMA) {
int lgrp_id = os::numa_get_group_id();
@ -1265,7 +1265,7 @@ void os::Linux::capture_initial_stack(size_t max_size) {
// by email from Hans Boehm. /proc/self/stat begins with current pid,
// followed by command name surrounded by parentheses, state, etc.
char stat[2048];
int statlen;
size_t statlen;
fp = os::fopen("/proc/self/stat", "r");
if (fp) {
@ -1474,7 +1474,7 @@ bool os::dll_address_to_function_name(address addr, char *buf,
if (!(demangle && Decoder::demangle(dlinfo.dli_sname, buf, buflen))) {
jio_snprintf(buf, buflen, "%s", dlinfo.dli_sname);
}
if (offset != nullptr) *offset = addr - (address)dlinfo.dli_saddr;
if (offset != nullptr) *offset = pointer_delta_as_int(addr, (address)dlinfo.dli_saddr);
return true;
}
// no matching symbol so try for just file info
@ -1502,7 +1502,7 @@ bool os::dll_address_to_library_name(address addr, char* buf,
jio_snprintf(buf, buflen, "%s", dlinfo.dli_fname);
}
if (dlinfo.dli_fbase != nullptr && offset != nullptr) {
*offset = addr - (address)dlinfo.dli_fbase;
*offset = pointer_delta_as_int(addr, (address)dlinfo.dli_fbase);
}
return true;
}
@ -1601,14 +1601,14 @@ void * os::dll_load(const char *filename, char *ebuf, int ebuflen) {
}
Elf32_Ehdr elf_head;
int diag_msg_max_length=ebuflen-strlen(ebuf);
char* diag_msg_buf=ebuf+strlen(ebuf);
if (diag_msg_max_length==0) {
size_t prefix_len = strlen(ebuf);
ssize_t diag_msg_max_length = ebuflen - prefix_len;
if (diag_msg_max_length <= 0) {
// No more space in ebuf for additional diagnostics message
return nullptr;
}
char* diag_msg_buf = ebuf + prefix_len;
int file_descriptor= ::open(filename, O_RDONLY | O_NONBLOCK);
@ -1891,7 +1891,7 @@ static bool _print_ascii_file(const char* filename, outputStream* st, unsigned*
}
char buf[33];
int bytes;
ssize_t bytes;
buf[32] = '\0';
unsigned lines = 0;
while ((bytes = ::read(fd, buf, sizeof(buf)-1)) > 0) {
@ -2382,7 +2382,7 @@ void os::Linux::print_steal_info(outputStream* st) {
uint64_t total_ticks_difference = pticks.total - initial_total_ticks;
double steal_ticks_perc = 0.0;
if (total_ticks_difference != 0) {
steal_ticks_perc = (double) steal_ticks_difference / total_ticks_difference;
steal_ticks_perc = (double) steal_ticks_difference / (double)total_ticks_difference;
}
st->print_cr("Steal ticks since vm start: " UINT64_FORMAT, steal_ticks_difference);
st->print_cr("Steal ticks percentage since vm start:%7.3f", steal_ticks_perc);
@ -2424,7 +2424,7 @@ static bool print_model_name_and_flags(outputStream* st, char* buf, size_t bufle
if (fp) {
bool model_name_printed = false;
while (!feof(fp)) {
if (fgets(buf, buflen, fp)) {
if (fgets(buf, (int)buflen, fp)) {
// Assume model name comes before flags
if (strstr(buf, "model name") != nullptr) {
if (!model_name_printed) {
@ -2667,7 +2667,7 @@ void os::jvm_path(char *buf, jint buflen) {
// determine if this is a legacy image or modules image
// modules image doesn't have "jre" subdirectory
len = strlen(buf);
len = checked_cast<int>(strlen(buf));
assert(len < buflen, "Ran out of buffer room");
jrelib_p = buf + len;
snprintf(jrelib_p, buflen-len, "/jre/lib");
@ -2677,7 +2677,7 @@ void os::jvm_path(char *buf, jint buflen) {
if (0 == access(buf, F_OK)) {
// Use current module name "libjvm.so"
len = strlen(buf);
len = (int)strlen(buf);
snprintf(buf + len, buflen-len, "/hotspot/libjvm.so");
} else {
// Go back to path of .so
@ -2970,7 +2970,7 @@ char *os::scan_pages(char *start, char* end, page_info* page_expected,
int os::Linux::sched_getcpu_syscall(void) {
unsigned int cpu = 0;
int retval = -1;
long retval = -1;
#if defined(IA32)
#ifndef SYS_getcpu
@ -2989,7 +2989,7 @@ int os::Linux::sched_getcpu_syscall(void) {
retval = vgetcpu(&cpu, nullptr, nullptr);
#endif
return (retval == -1) ? retval : cpu;
return (retval == -1) ? -1 : cpu;
}
void os::Linux::sched_getcpu_init() {
@ -3142,30 +3142,30 @@ void os::Linux::rebuild_nindex_to_node_map() {
// rebuild_cpu_to_node_map() constructs a table mapping cpud id to node id.
// The table is later used in get_node_by_cpu().
void os::Linux::rebuild_cpu_to_node_map() {
const size_t NCPUS = 32768; // Since the buffer size computation is very obscure
// in libnuma (possible values are starting from 16,
// and continuing up with every other power of 2, but less
// than the maximum number of CPUs supported by kernel), and
// is a subject to change (in libnuma version 2 the requirements
// are more reasonable) we'll just hardcode the number they use
// in the library.
const size_t BitsPerCLong = sizeof(long) * CHAR_BIT;
const int NCPUS = 32768; // Since the buffer size computation is very obscure
// in libnuma (possible values are starting from 16,
// and continuing up with every other power of 2, but less
// than the maximum number of CPUs supported by kernel), and
// is a subject to change (in libnuma version 2 the requirements
// are more reasonable) we'll just hardcode the number they use
// in the library.
constexpr int BitsPerCLong = (int)sizeof(long) * CHAR_BIT;
size_t cpu_num = processor_count();
size_t cpu_map_size = NCPUS / BitsPerCLong;
size_t cpu_map_valid_size =
int cpu_num = processor_count();
int cpu_map_size = NCPUS / BitsPerCLong;
int cpu_map_valid_size =
MIN2((cpu_num + BitsPerCLong - 1) / BitsPerCLong, cpu_map_size);
cpu_to_node()->clear();
cpu_to_node()->at_grow(cpu_num - 1);
size_t node_num = get_existing_num_nodes();
int node_num = get_existing_num_nodes();
int distance = 0;
int closest_distance = INT_MAX;
int closest_node = 0;
unsigned long *cpu_map = NEW_C_HEAP_ARRAY(unsigned long, cpu_map_size, mtInternal);
for (size_t i = 0; i < node_num; i++) {
for (int i = 0; i < node_num; i++) {
// Check if node is configured (not a memory-less node). If it is not, find
// the closest configured node. Check also if node is bound, i.e. it's allowed
// to allocate memory from the node. If it's not allowed, map cpus in that node
@ -3176,7 +3176,7 @@ void os::Linux::rebuild_cpu_to_node_map() {
// Check distance from all remaining nodes in the system. Ignore distance
// from itself, from another non-configured node, and from another non-bound
// node.
for (size_t m = 0; m < node_num; m++) {
for (int m = 0; m < node_num; m++) {
if (m != i &&
is_node_in_configured_nodes(nindex_to_node()->at(m)) &&
is_node_in_bound_nodes(nindex_to_node()->at(m))) {
@ -3198,10 +3198,10 @@ void os::Linux::rebuild_cpu_to_node_map() {
// Get cpus from the original node and map them to the closest node. If node
// is a configured node (not a memory-less node), then original node and
// closest node are the same.
if (numa_node_to_cpus(nindex_to_node()->at(i), cpu_map, cpu_map_size * sizeof(unsigned long)) != -1) {
for (size_t j = 0; j < cpu_map_valid_size; j++) {
if (numa_node_to_cpus(nindex_to_node()->at(i), cpu_map, cpu_map_size * (int)sizeof(unsigned long)) != -1) {
for (int j = 0; j < cpu_map_valid_size; j++) {
if (cpu_map[j] != 0) {
for (size_t k = 0; k < BitsPerCLong; k++) {
for (int k = 0; k < BitsPerCLong; k++) {
if (cpu_map[j] & (1UL << k)) {
int cpu_index = j * BitsPerCLong + k;
@ -3286,7 +3286,7 @@ static address get_stack_commited_bottom(address bottom, size_t size) {
address ntop = bottom + size;
size_t page_sz = os::vm_page_size();
unsigned pages = size / page_sz;
unsigned pages = checked_cast<unsigned>(size / page_sz);
unsigned char vec[1];
unsigned imin = 1, imax = pages + 1, imid;
@ -3336,21 +3336,21 @@ bool os::committed_in_range(address start, size_t size, address& committed_start
vec[stripe] = 'X';
const size_t page_sz = os::vm_page_size();
size_t pages = size / page_sz;
uintx pages = size / page_sz;
assert(is_aligned(start, page_sz), "Start address must be page aligned");
assert(is_aligned(size, page_sz), "Size must be page aligned");
committed_start = nullptr;
int loops = (pages + stripe - 1) / stripe;
int loops = checked_cast<int>((pages + stripe - 1) / stripe);
int committed_pages = 0;
address loop_base = start;
bool found_range = false;
for (int index = 0; index < loops && !found_range; index ++) {
assert(pages > 0, "Nothing to do");
int pages_to_query = (pages >= stripe) ? stripe : pages;
uintx pages_to_query = (pages >= stripe) ? stripe : pages;
pages -= pages_to_query;
// Get stable read
@ -3366,7 +3366,7 @@ bool os::committed_in_range(address start, size_t size, address& committed_start
assert(vec[stripe] == 'X', "overflow guard");
assert(mincore_return_value == 0, "Range must be valid");
// Process this stripe
for (int vecIdx = 0; vecIdx < pages_to_query; vecIdx ++) {
for (uintx vecIdx = 0; vecIdx < pages_to_query; vecIdx ++) {
if ((vec[vecIdx] & 0x01) == 0) { // not committed
// End of current contiguous region
if (committed_start != nullptr) {
@ -4395,13 +4395,13 @@ static void check_pax(void) {
void os::init(void) {
char dummy; // used to get a guess on initial stack address
clock_tics_per_sec = sysconf(_SC_CLK_TCK);
int sys_pg_size = sysconf(_SC_PAGESIZE);
clock_tics_per_sec = checked_cast<int>(sysconf(_SC_CLK_TCK));
int sys_pg_size = checked_cast<int>(sysconf(_SC_PAGESIZE));
if (sys_pg_size < 0) {
fatal("os_linux.cpp: os::init: sysconf failed (%s)",
os::strerror(errno));
}
size_t page_size = (size_t) sys_pg_size;
size_t page_size = sys_pg_size;
OSInfo::set_vm_page_size(page_size);
OSInfo::set_vm_allocation_granularity(page_size);
if (os::vm_page_size() == 0) {
@ -4745,7 +4745,7 @@ static int get_active_processor_count() {
// Note: keep this function, with its CPU_xx macros, *outside* the os namespace (see JDK-8289477).
cpu_set_t cpus; // can represent at most 1024 (CPU_SETSIZE) processors
cpu_set_t* cpus_p = &cpus;
int cpus_size = sizeof(cpu_set_t);
size_t cpus_size = sizeof(cpu_set_t);
int configured_cpus = os::processor_count(); // upper bound on available cpus
int cpu_count = 0;
@ -4769,7 +4769,7 @@ static int get_active_processor_count() {
}
else {
// failed to allocate so fallback to online cpus
int online_cpus = ::sysconf(_SC_NPROCESSORS_ONLN);
int online_cpus = checked_cast<int>(::sysconf(_SC_NPROCESSORS_ONLN));
log_trace(os)("active_processor_count: "
"CPU_ALLOC failed (%s) - using "
"online processor count: %d",
@ -4801,7 +4801,7 @@ static int get_active_processor_count() {
log_trace(os)("active_processor_count: sched_getaffinity processor count: %d", cpu_count);
}
else {
cpu_count = ::sysconf(_SC_NPROCESSORS_ONLN);
cpu_count = checked_cast<int>(::sysconf(_SC_NPROCESSORS_ONLN));
warning("sched_getaffinity failed (%s)- using online processor count (%d) "
"which may exceed available processors", os::strerror(errno), cpu_count);
}
@ -5163,7 +5163,7 @@ static jlong slow_thread_cpu_time(Thread *thread, bool user_sys_cpu_time) {
pid_t tid = thread->osthread()->thread_id();
char *s;
char stat[2048];
int statlen;
size_t statlen;
char proc_name[64];
int count;
long sys_time, user_time;
@ -5309,7 +5309,7 @@ int os::get_core_path(char* buffer, size_t bufferSize) {
}
}
return strlen(buffer);
return checked_cast<int>(strlen(buffer));
}
bool os::start_debugging(char *buf, int buflen) {
@ -5444,9 +5444,9 @@ static inline struct timespec get_mtime(const char* filename) {
int os::compare_file_modified_times(const char* file1, const char* file2) {
struct timespec filetime1 = get_mtime(file1);
struct timespec filetime2 = get_mtime(file2);
int diff = filetime1.tv_sec - filetime2.tv_sec;
int diff = primitive_compare(filetime1.tv_sec, filetime2.tv_sec);
if (diff == 0) {
return filetime1.tv_nsec - filetime2.tv_nsec;
diff = primitive_compare(filetime1.tv_nsec, filetime2.tv_nsec);
}
return diff;
}

View File

@ -232,7 +232,7 @@ static double get_cpu_load(int which_logical_cpu, CPUPerfCounters* counters, dou
*/
static int SCANF_ARGS(2, 0) vread_statdata(const char* procfile, _SCANFMT_ const char* fmt, va_list args) {
FILE*f;
int n;
ssize_t n;
char buf[2048];
if ((f = os::fopen(procfile, "r")) == nullptr) {
@ -382,12 +382,12 @@ static double get_cpu_load(int which_logical_cpu, CPUPerfCounters* counters, dou
} else if (tdiff < (udiff + kdiff)) {
tdiff = udiff + kdiff;
}
*pkernelLoad = (kdiff / (double)tdiff);
*pkernelLoad = ((double)kdiff / (double)tdiff);
// BUG9044876, normalize return values to sane values
*pkernelLoad = MAX2<double>(*pkernelLoad, 0.0);
*pkernelLoad = MIN2<double>(*pkernelLoad, 1.0);
user_load = (udiff / (double)tdiff);
user_load = ((double)udiff / (double)tdiff);
user_load = MAX2<double>(user_load, 0.0);
user_load = MIN2<double>(user_load, 1.0);
@ -473,7 +473,7 @@ static int perf_context_switch_rate(double* rate) {
if (d == 0) {
*rate = lastRate;
} else if (get_noof_context_switches(&sw) == 0) {
*rate = ( (double)(sw - lastSwitches) / d ) * 1000;
*rate = ( (double)(sw - lastSwitches) / (double)d ) * 1000;
lastRate = *rate;
lastSwitches = sw;
if (bootTime != 0) {

View File

@ -56,12 +56,12 @@ enum membarrier_cmd {
MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED = (1 << 4),
};
static int membarrier(int cmd, unsigned int flags, int cpu_id) {
static long membarrier(int cmd, unsigned int flags, int cpu_id) {
return syscall(SYS_membarrier, cmd, flags, cpu_id); // cpu_id only on >= 5.10
}
bool LinuxSystemMemoryBarrier::initialize() {
int ret = membarrier(MEMBARRIER_CMD_QUERY, 0, 0);
long ret = membarrier(MEMBARRIER_CMD_QUERY, 0, 0);
if (ret < 0) {
log_info(os)("MEMBARRIER_CMD_QUERY unsupported");
return false;
@ -78,6 +78,6 @@ bool LinuxSystemMemoryBarrier::initialize() {
}
void LinuxSystemMemoryBarrier::emit() {
int s = membarrier(MEMBARRIER_CMD_PRIVATE_EXPEDITED, 0, 0);
long s = membarrier(MEMBARRIER_CMD_PRIVATE_EXPEDITED, 0, 0);
guarantee_with_errno(s >= 0, "MEMBARRIER_CMD_PRIVATE_EXPEDITED failed");
}

View File

@ -37,7 +37,7 @@
#endif
#endif
static int futex(volatile int *addr, int futex_op, int op_arg) {
static long futex(volatile int *addr, int futex_op, int op_arg) {
return syscall(SYS_futex, addr, futex_op, op_arg, nullptr, nullptr, 0);
}
@ -51,9 +51,9 @@ void LinuxWaitBarrier::arm(int barrier_tag) {
void LinuxWaitBarrier::disarm() {
assert(_futex_barrier != 0, "Should be armed/non-zero.");
_futex_barrier = 0;
int s = futex(&_futex_barrier,
FUTEX_WAKE_PRIVATE,
INT_MAX /* wake a max of this many threads */);
long s = futex(&_futex_barrier,
FUTEX_WAKE_PRIVATE,
INT_MAX /* wake a max of this many threads */);
guarantee_with_errno(s > -1, "futex FUTEX_WAKE failed");
}
@ -65,9 +65,9 @@ void LinuxWaitBarrier::wait(int barrier_tag) {
return;
}
do {
int s = futex(&_futex_barrier,
FUTEX_WAIT_PRIVATE,
barrier_tag /* should be this tag */);
long s = futex(&_futex_barrier,
FUTEX_WAIT_PRIVATE,
barrier_tag /* should be this tag */);
guarantee_with_errno((s == 0) ||
(s == -1 && errno == EAGAIN) ||
(s == -1 && errno == EINTR),

View File

@ -445,7 +445,7 @@ void os::Posix::print_load_average(outputStream* st) {
// for reboot at least on my test machines
void os::Posix::print_uptime_info(outputStream* st) {
int bootsec = -1;
int currsec = time(nullptr);
time_t currsec = time(nullptr);
struct utmpx* ent;
setutxent();
while ((ent = getutxent())) {
@ -456,7 +456,7 @@ void os::Posix::print_uptime_info(outputStream* st) {
}
if (bootsec != -1) {
os::print_dhm(st, "OS uptime:", (long) (currsec-bootsec));
os::print_dhm(st, "OS uptime:", currsec-bootsec);
}
}
@ -799,20 +799,20 @@ int os::socket_close(int fd) {
return ::close(fd);
}
int os::recv(int fd, char* buf, size_t nBytes, uint flags) {
RESTARTABLE_RETURN_INT(::recv(fd, buf, nBytes, flags));
ssize_t os::recv(int fd, char* buf, size_t nBytes, uint flags) {
RESTARTABLE_RETURN_SSIZE_T(::recv(fd, buf, nBytes, flags));
}
int os::send(int fd, char* buf, size_t nBytes, uint flags) {
RESTARTABLE_RETURN_INT(::send(fd, buf, nBytes, flags));
ssize_t os::send(int fd, char* buf, size_t nBytes, uint flags) {
RESTARTABLE_RETURN_SSIZE_T(::send(fd, buf, nBytes, flags));
}
int os::raw_send(int fd, char* buf, size_t nBytes, uint flags) {
ssize_t os::raw_send(int fd, char* buf, size_t nBytes, uint flags) {
return os::send(fd, buf, nBytes, flags);
}
int os::connect(int fd, struct sockaddr* him, socklen_t len) {
RESTARTABLE_RETURN_INT(::connect(fd, him, len));
ssize_t os::connect(int fd, struct sockaddr* him, socklen_t len) {
RESTARTABLE_RETURN_SSIZE_T(::connect(fd, him, len));
}
void os::exit(int num) {
@ -1208,7 +1208,7 @@ void os::Posix::init(void) {
#if defined(_ALLBSD_SOURCE)
clock_tics_per_sec = CLK_TCK;
#else
clock_tics_per_sec = sysconf(_SC_CLK_TCK);
clock_tics_per_sec = checked_cast<int>(sysconf(_SC_CLK_TCK));
#endif
// NOTE: no logging available when this is called. Put logging
// statements in init_2().
@ -1332,7 +1332,7 @@ static jlong millis_to_nanos_bounded(jlong millis) {
static void to_abstime(timespec* abstime, jlong timeout,
bool isAbsolute, bool isRealtime) {
DEBUG_ONLY(int max_secs = MAX_SECS;)
DEBUG_ONLY(time_t max_secs = MAX_SECS;)
if (timeout < 0) {
timeout = 0;
@ -1414,7 +1414,7 @@ void os::javaTimeNanos_info(jvmtiTimerInfo *info_ptr) {
// Time since start-up in seconds to a fine granularity.
double os::elapsedTime() {
return ((double)os::elapsed_counter()) / os::elapsed_frequency(); // nanosecond resolution
return ((double)os::elapsed_counter()) / (double)os::elapsed_frequency(); // nanosecond resolution
}
jlong os::elapsed_counter() {

View File

@ -44,8 +44,8 @@
_result = _cmd; \
} while(((int)_result == OS_ERR) && (errno == EINTR))
#define RESTARTABLE_RETURN_INT(_cmd) do { \
int _result; \
#define RESTARTABLE_RETURN_SSIZE_T(_cmd) do { \
ssize_t _result; \
RESTARTABLE(_cmd, _result); \
return _result; \
} while(false)

View File

@ -44,6 +44,7 @@
#include "suspendResume_posix.hpp"
#include "utilities/events.hpp"
#include "utilities/ostream.hpp"
#include "utilities/parseInteger.hpp"
#include "utilities/vmError.hpp"
#include <signal.h>
@ -681,7 +682,7 @@ static void UserHandler(int sig, siginfo_t* siginfo, void* context) {
static void print_signal_handler_name(outputStream* os, address handler, char* buf, size_t buflen) {
// We demangle, but omit arguments - signal handlers should have always the same prototype.
os::print_function_and_library_name(os, handler, buf, buflen,
os::print_function_and_library_name(os, handler, buf, checked_cast<int>(buflen),
true, // shorten_path
true, // demangle
true // omit arguments
@ -1726,8 +1727,9 @@ int SR_initialize() {
char *s;
// Get signal number to use for suspend/resume
if ((s = ::getenv("_JAVA_SR_SIGNUM")) != 0) {
int sig = ::strtol(s, 0, 10);
if (sig > MAX2(SIGSEGV, SIGBUS) && // See 4355769.
int sig;
bool result = parse_integer(s, &sig);
if (result && sig > MAX2(SIGSEGV, SIGBUS) && // See 4355769.
sig < NSIG) { // Must be legal signal and fit into sigflags[].
PosixSignals::SR_signum = sig;
} else {

View File

@ -1762,7 +1762,7 @@ static inline time_t get_mtime(const char* filename) {
int os::compare_file_modified_times(const char* file1, const char* file2) {
time_t t1 = get_mtime(file1);
time_t t2 = get_mtime(file2);
return t1 - t2;
return primitive_compare(t1, t2);
}
void os::print_os_info_brief(outputStream* st) {
@ -5608,19 +5608,19 @@ int os::socket_close(int fd) {
return ::closesocket(fd);
}
int os::connect(int fd, struct sockaddr* him, socklen_t len) {
ssize_t os::connect(int fd, struct sockaddr* him, socklen_t len) {
return ::connect(fd, him, len);
}
int os::recv(int fd, char* buf, size_t nBytes, uint flags) {
ssize_t os::recv(int fd, char* buf, size_t nBytes, uint flags) {
return ::recv(fd, buf, (int)nBytes, flags);
}
int os::send(int fd, char* buf, size_t nBytes, uint flags) {
ssize_t os::send(int fd, char* buf, size_t nBytes, uint flags) {
return ::send(fd, buf, (int)nBytes, flags);
}
int os::raw_send(int fd, char* buf, size_t nBytes, uint flags) {
ssize_t os::raw_send(int fd, char* buf, size_t nBytes, uint flags) {
return ::send(fd, buf, (int)nBytes, flags);
}

View File

@ -463,7 +463,7 @@ juint os::cpu_microcode_revision() {
fp = os::fopen("/proc/cpuinfo", "r");
if (fp) {
char data[2048] = {0}; // lines should fit in 2K buf
size_t len = sizeof(data);
int len = (int)sizeof(data);
while (!feof(fp)) {
if (fgets(data, len, fp)) {
if (strstr(data, "microcode") != nullptr) {

View File

@ -886,10 +886,10 @@ class os: AllStatic {
// SocketInterface (ex HPI SocketInterface )
static int socket_close(int fd);
static int recv(int fd, char* buf, size_t nBytes, uint flags);
static int send(int fd, char* buf, size_t nBytes, uint flags);
static int raw_send(int fd, char* buf, size_t nBytes, uint flags);
static int connect(int fd, struct sockaddr* him, socklen_t len);
static ssize_t recv(int fd, char* buf, size_t nBytes, uint flags);
static ssize_t send(int fd, char* buf, size_t nBytes, uint flags);
static ssize_t raw_send(int fd, char* buf, size_t nBytes, uint flags);
static ssize_t connect(int fd, struct sockaddr* him, socklen_t len);
// Support for signals
static void initialize_jdk_signal_support(TRAPS);

View File

@ -1096,15 +1096,15 @@ networkStream::networkStream() : bufferedStream(1024*10, 1024*10) {
}
}
int networkStream::read(char *buf, size_t len) {
return os::recv(_socket, buf, (int)len, 0);
ssize_t networkStream::read(char *buf, size_t len) {
return os::recv(_socket, buf, len, 0);
}
void networkStream::flush() {
if (size() != 0) {
int result = os::raw_send(_socket, (char *)base(), size(), 0);
ssize_t result = os::raw_send(_socket, (char *)base(), size(), 0);
assert(result != -1, "connection error");
assert(result == (int)size(), "didn't send enough data");
assert(result >= 0 && (size_t)result == size(), "didn't send enough data");
}
reset();
}
@ -1143,9 +1143,9 @@ bool networkStream::connect(const char *host, short port) {
return false;
}
ret = os::connect(_socket, addr_info->ai_addr, (socklen_t)addr_info->ai_addrlen);
ssize_t conn = os::connect(_socket, addr_info->ai_addr, (socklen_t)addr_info->ai_addrlen);
freeaddrinfo(addr_info);
return (ret >= 0);
return (conn >= 0);
}
#endif

View File

@ -321,7 +321,7 @@ class networkStream : public bufferedStream {
bool connect(const char *host, short port);
bool is_open() const { return _socket != -1; }
int read(char *buf, size_t len);
ssize_t read(char *buf, size_t len);
void close();
virtual void flush();
};