Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 18 commits into from
Closed
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/hotspot/os/aix/attachListener_aix.cpp
Original file line number Diff line number Diff line change
@@ -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();
};
@@ -285,8 +285,8 @@ 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;
ssize_t off = 0;
ssize_t left = max_len;

do {
int n;
@@ -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 {
4 changes: 2 additions & 2 deletions src/hotspot/os/aix/os_aix.cpp
Original file line number Diff line number Diff line change
@@ -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 checked_cast<int>(t1 - t2);
}

bool os::supports_map_sync() {
2 changes: 1 addition & 1 deletion src/hotspot/os/aix/os_perf_aix.cpp
Original file line number Diff line number Diff line change
@@ -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");
14 changes: 7 additions & 7 deletions src/hotspot/os/bsd/attachListener_bsd.cpp
Original file line number Diff line number Diff line change
@@ -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();
};
@@ -266,11 +266,11 @@ 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;
ssize_t off = 0;
ssize_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!");
buf[max_len - 1] = '\0';
@@ -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 {
6 changes: 3 additions & 3 deletions src/hotspot/os/bsd/os_bsd.cpp
Original file line number Diff line number Diff line change
@@ -2208,11 +2208,11 @@ 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;
time_t diff = filetime1.tv_sec - filetime2.tv_sec;
if (diff == 0) {
return filetime1.tv_nsec - filetime2.tv_nsec;
diff = filetime1.tv_nsec - filetime2.tv_nsec;
}
return diff;
return checked_cast<int>(diff);
}

// This code originates from JDK's sysOpen and open64_w
12 changes: 6 additions & 6 deletions src/hotspot/os/linux/attachListener_linux.cpp
Original file line number Diff line number Diff line change
@@ -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();
};
@@ -266,11 +266,11 @@ 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;
ssize_t off = 0;
ssize_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!");
buf[max_len - 1] = '\0';
@@ -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) {
2 changes: 1 addition & 1 deletion src/hotspot/os/linux/cgroupSubsystem_linux.cpp
Original file line number Diff line number Diff line change
@@ -494,7 +494,7 @@ int CgroupSubsystem::active_processor_count() {
int period = cpu_period();

if (quota > -1 && period > 0) {
quota_count = ceilf((float)quota / (float)period);
quota_count = (int)ceilf((float)quota / (float)period);
log_trace(os, container)("CPU Quota count based on quota/period: %d", quota_count);
}

Loading