Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
22 changes: 16 additions & 6 deletions src/hotspot/os/linux/os_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,11 @@ pid_t os::Linux::gettid() {
// This can change at any time.
julong os::Linux::host_swap() {
struct sysinfo si;
sysinfo(&si);
int ret = sysinfo(&si);
if (ret != 0) {
assert(false, "sysinfo failed in host_swap(): %s", os::strerror(errno));
return 0;
}
return (julong)(si.totalswap * si.mem_unit);
}

Expand Down Expand Up @@ -2447,6 +2451,8 @@ void os::Linux::print_uptime_info(outputStream* st) {
int ret = sysinfo(&sinfo);
if (ret == 0) {
os::print_dhm(st, "OS uptime:", (long) sinfo.uptime);
} else {
st->print_cr("OS uptime could not be retrieved.");
}
}

Expand Down Expand Up @@ -2570,18 +2576,22 @@ void os::print_memory_info(outputStream* st) {

// values in struct sysinfo are "unsigned long"
struct sysinfo si;
sysinfo(&si);
int ret = sysinfo(&si);
physical_memory_size_type phys_mem = physical_memory();
st->print(", physical " PHYS_MEM_TYPE_FORMAT "k",
phys_mem >> 10);
physical_memory_size_type avail_mem = 0;
(void)os::available_memory(avail_mem);
st->print("(" PHYS_MEM_TYPE_FORMAT "k free)",
avail_mem >> 10);
st->print(", swap " UINT64_FORMAT "k",
((jlong)si.totalswap * si.mem_unit) >> 10);
st->print("(" UINT64_FORMAT "k free)",
((jlong)si.freeswap * si.mem_unit) >> 10);
if (ret == 0) {
st->print(", swap " UINT64_FORMAT "k",
((jlong)si.totalswap * si.mem_unit) >> 10);
st->print("(" UINT64_FORMAT "k free)",
((jlong)si.freeswap * si.mem_unit) >> 10);
} else {
st->print(", swap could not be determined");
}
st->cr();
st->print("Page Sizes: ");
_page_sizes.print_on(st);
Expand Down
8 changes: 6 additions & 2 deletions src/java.base/unix/native/libjava/java_props_md.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,12 @@ GetJavaProperties(JNIEnv *env)
/* supported instruction sets */
{
char list[258];
sysinfo(SI_ISALIST, list, sizeof(list));
sprops.cpu_isalist = strdup(list);
int ret = sysinfo(SI_ISALIST, list, sizeof(list));
if (ret == 0) {
sprops.cpu_isalist = strdup(list);
} else {
sprops.cpu_isalist = NULL;
Copy link
Contributor

Choose a reason for hiding this comment

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

Would you mind checking the code that puts this in a system property can tolerate NULL? I don't suppose sysinfo will fail here (unless you found a case?) but it would be good to confirm that it won't blow up somewhere else.

Copy link
Member Author

Choose a reason for hiding this comment

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

We do PUTPROP here

PUTPROP(propArray, _sun_cpu_isalist_NDX, sprops->cpu_isalist);

with 3rd parameter == NULL in this case.
PUTPROP checks for this so I do not see issues with this
#define PUTPROP(array, prop_index, val) \

}
}
#else
sprops.cpu_isalist = NULL;
Expand Down