From 2d574f7cebd0e03bdb590a4a1be933dde05f64a1 Mon Sep 17 00:00:00 2001 From: MBaesken Date: Fri, 14 Nov 2025 10:25:07 +0100 Subject: [PATCH 1/4] JDK-8333871 --- src/hotspot/os/linux/os_linux.cpp | 22 ++++++++++++++----- .../unix/native/libjava/java_props_md.c | 9 ++++++-- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/hotspot/os/linux/os_linux.cpp b/src/hotspot/os/linux/os_linux.cpp index 69ef8ce7c337c..118ce786f30a2 100644 --- a/src/hotspot/os/linux/os_linux.cpp +++ b/src/hotspot/os/linux/os_linux.cpp @@ -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); } @@ -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."); } } @@ -2570,7 +2576,7 @@ 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); @@ -2578,10 +2584,14 @@ void os::print_memory_info(outputStream* st) { (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); diff --git a/src/java.base/unix/native/libjava/java_props_md.c b/src/java.base/unix/native/libjava/java_props_md.c index 000eb4b953e2c..ae0ecc5837a11 100644 --- a/src/java.base/unix/native/libjava/java_props_md.c +++ b/src/java.base/unix/native/libjava/java_props_md.c @@ -388,8 +388,13 @@ 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); + list[sizeof(list) - 1] = '\0'; + } else { + sprops.cpu_isalist = NULL; + } } #else sprops.cpu_isalist = NULL; From e9d2b1b49c074c43ec71d0160c57f423bf60eb7a Mon Sep 17 00:00:00 2001 From: MBaesken Date: Fri, 14 Nov 2025 12:02:38 +0100 Subject: [PATCH 2/4] 0 - terminate not needed --- src/java.base/unix/native/libjava/java_props_md.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/java.base/unix/native/libjava/java_props_md.c b/src/java.base/unix/native/libjava/java_props_md.c index ae0ecc5837a11..30d0ca67652b8 100644 --- a/src/java.base/unix/native/libjava/java_props_md.c +++ b/src/java.base/unix/native/libjava/java_props_md.c @@ -391,7 +391,6 @@ GetJavaProperties(JNIEnv *env) int ret = sysinfo(SI_ISALIST, list, sizeof(list)); if (ret == 0) { sprops.cpu_isalist = strdup(list); - list[sizeof(list) - 1] = '\0'; } else { sprops.cpu_isalist = NULL; } From 6284ef291e8623f295a56a7308c53f6b3bc87d89 Mon Sep 17 00:00:00 2001 From: MBaesken Date: Wed, 19 Nov 2025 11:10:53 +0100 Subject: [PATCH 3/4] use more asserts --- src/hotspot/os/linux/os_linux.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/hotspot/os/linux/os_linux.cpp b/src/hotspot/os/linux/os_linux.cpp index 118ce786f30a2..701263f317441 100644 --- a/src/hotspot/os/linux/os_linux.cpp +++ b/src/hotspot/os/linux/os_linux.cpp @@ -2451,9 +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."); } + assert(ret == 0, "sysinfo must return 0"); } bool os::Linux::print_container_info(outputStream* st) { @@ -2577,6 +2576,7 @@ void os::print_memory_info(outputStream* st) { // values in struct sysinfo are "unsigned long" struct sysinfo si; int ret = sysinfo(&si); + assert(ret == 0, "sysinfo must return 0"); physical_memory_size_type phys_mem = physical_memory(); st->print(", physical " PHYS_MEM_TYPE_FORMAT "k", phys_mem >> 10); @@ -2589,8 +2589,6 @@ void os::print_memory_info(outputStream* st) { ((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: "); From 22a2f6aa2beba9c3727b18010927cda393515c0d Mon Sep 17 00:00:00 2001 From: MBaesken Date: Thu, 20 Nov 2025 09:20:48 +0100 Subject: [PATCH 4/4] Better assert messages --- src/hotspot/os/linux/os_linux.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hotspot/os/linux/os_linux.cpp b/src/hotspot/os/linux/os_linux.cpp index 7e99e20f3a044..b9f8307673cb3 100644 --- a/src/hotspot/os/linux/os_linux.cpp +++ b/src/hotspot/os/linux/os_linux.cpp @@ -2433,7 +2433,7 @@ void os::Linux::print_uptime_info(outputStream* st) { if (ret == 0) { os::print_dhm(st, "OS uptime:", (long) sinfo.uptime); } - assert(ret == 0, "sysinfo must return 0"); + assert(ret == 0, "sysinfo failed: %s", os::strerror(errno)); } bool os::Linux::print_container_info(outputStream* st) { @@ -2599,7 +2599,7 @@ void os::print_memory_info(outputStream* st) { // values in struct sysinfo are "unsigned long" struct sysinfo si; int ret = sysinfo(&si); - assert(ret == 0, "sysinfo must return 0"); + assert(ret == 0, "sysinfo failed: %s", os::strerror(errno)); physical_memory_size_type phys_mem = physical_memory(); st->print(", physical " PHYS_MEM_TYPE_FORMAT "k", phys_mem >> 10);