On Mon, 16 Mar 2026 14:46:32 GMT, Kieran Farrell <[email protected]> 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.
>
> Kieran Farrell has updated the pull request incrementally with two additional
> commits since the last revision:
>
> - update apple and linux impl
> - unlimited buffer for mac in non-signal handling context (vm.info)
src/hotspot/os/bsd/os_bsd.cpp line 2593:
> 2591: }
> 2592:
> 2593: void os::Bsd::print_open_file_descriptors(outputStream* st, char* buf,
> size_t buflen) {
To be consistent with the rest of this file, the if statements in this function
should only be indented by two spaces, not four.
src/hotspot/os/linux/os_linux.cpp line 5410:
> 5408: closedir(dirp);
> 5409: if (timed_out) {
> 5410: st->print_cr("Open File Descriptors: > %d", fds);
There is a space between "> %d" here but not in the BSD implementation in
os_bsd.cpp. I think we should choose one format and be consistent.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/27971#discussion_r2941068072
PR Review Comment: https://git.openjdk.org/jdk/pull/27971#discussion_r2941094247