RFR: 8359706: Add file descriptor count and maximum limit to VM.info

Joel Sikström jsikstro at openjdk.org
Mon Oct 27 11:14:20 UTC 2025


On Fri, 24 Oct 2025 08:25:21 GMT, Kieran Farrell <kfarrell at openjdk.org> wrote:

> Currently, it is only possible to read the number of open file descriptors of a Java process via the `UnixOperatingSystemMXBean` which is only accessible via JMX enabled tools. To improve servicability, it would be benifical to be able to view this information from jcmd VM.info output or hs_err_pid crash logs. This could help diagnose resource exhaustion and troubleshoot "too many open files" errors in Java processes on Unix platforms.
> 
> This PR adds reporting the current open file descriptor count to both jcmd VM.info output or hs_err_pid crash logs by refactoring the native JNI logic from `Java_com_sun_management_internal_OperatingSystemImpl_getOpenFileDescriptorCount0` of the `UnixOperatingSystemMXBean` into hotspot. Apple's API for retrieving open file descriptor count provides an array of the actual FDs to determine the count. To avoid using `malloc` to store this array in a potential signal handling context where stack space may be limited, the apple implementation instead allocates a fixed 32KB struct on the stack to store the open FDs and only reports the result if the struct is less than the max (1024 FDs). This should cover the majoirty of use cases.

I'm not 100% sure about the placement in the `VMError::print_vm_info`, but some comments so far.

src/hotspot/os/bsd/os_bsd.cpp line 2544:

> 2542:     st->print_cr("OpenFileDescriptorCount = unknown");
> 2543: }
> 2544: #endif

Is `defined(_ALLBSD_SOURCE)` needed? The return type for the non-apple variant is incorrect. Maybe we could do something like the following here instead:

void os::print_open_file_descriptors(outputStream* st) {
#ifdef __APPLE__
// do Apple stuff
#else
  st->print_cr("OpenFileDescriptorCount = unknown");
#endif
}

src/hotspot/os/linux/os_linux.cpp line 5464:

> 5462:     }
> 5463:     closedir(dirp);
> 5464:     st->print_cr("OpenFileDescriptorCount = %d", fds - 1);

Maybe a comment on why we do `-1` here, like you have for the AIX implementation.

src/hotspot/share/utilities/vmError.cpp line 1440:

> 1438:     st->cr();
> 1439:   #endif
> 1440: 

This is in `VMError::print_vm_info` which is only printed via the `VM.info` jcmd and the `-XX:+PrintVMInfoAtExit` flag. To also add it to hs_err files, you should also add the code to `VMError::report`.

-------------

PR Review: https://git.openjdk.org/jdk/pull/27971#pullrequestreview-3382937862
PR Review Comment: https://git.openjdk.org/jdk/pull/27971#discussion_r2465255020
PR Review Comment: https://git.openjdk.org/jdk/pull/27971#discussion_r2465261409
PR Review Comment: https://git.openjdk.org/jdk/pull/27971#discussion_r2465255149


More information about the hotspot-dev mailing list