On Tue, 20 Jan 2026 16:56:11 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 one additional 
> commit since the last revision:
> 
>   relocate print out to SYSTEM section and remove AIX impl

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

> 2096: 
> 2097:   os::print_open_file_descriptors(st);
> 2098:   st->cr();

Remove?   I think the implementation uses print_cr and you didn't want to add a 
blank line between this and load average?  Also as not all OSs implement it, it 
will just put space between limits and load average.

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

> 5417:   closedir(dirp);
> 5418:   if (timed_out) {
> 5419:     st->print_cr("Open File Descriptors > %d", fds - 1); // minus the 
> opendir fd itself

Open File Descriptors: > %d
(with the colon like everywhere else?)

src/hotspot/os/windows/os_windows.cpp line 6262:

> 6260: 
> 6261: void os::print_open_file_descriptors(outputStream* st) {
> 6262:   // File descriptor counting not supported on Windows.

If you said "not implemented" here and in the other comment, it might be 
clearer that somebody could implement these if they build and test it.  Not 
supported sounds to me more like a reason we cannot do it.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/27971#discussion_r2709296759
PR Review Comment: https://git.openjdk.org/jdk/pull/27971#discussion_r2709300052
PR Review Comment: https://git.openjdk.org/jdk/pull/27971#discussion_r2709305132

Reply via email to