8343285: java.lang.Process is unresponsive and CPU usage spikes to 100%

Reviewed-by: dholmes, rriggs, shade
This commit is contained in:
Gerard Ziemski 2024-11-13 15:33:00 +00:00
parent cc2acd14b1
commit c00e20c399

View File

@ -2148,13 +2148,12 @@ jint os::init_2(void) {
// On macOS according to setrlimit(2), OPEN_MAX must be used instead // On macOS according to setrlimit(2), OPEN_MAX must be used instead
// of RLIM_INFINITY, but testing on macOS >= 10.6, reveals that // of RLIM_INFINITY, but testing on macOS >= 10.6, reveals that
// we can, in fact, use even RLIM_INFINITY, so try the max value // we can, in fact, use even RLIM_INFINITY.
// that the system claims can be used first, same as other BSD OSes. // However, we need to limit the value to 0x100000 (which is the max value
// However, some terminals (ksh) will internally use "int" type // allowed on Linux) so that any existing code that iterates over all allowed
// to store this value and since RLIM_INFINITY overflows an "int" // file descriptors, finishes in a reasonable time, without appearing
// we might end up with a negative value, so cap the system limit max // to hang.
// at INT_MAX instead, just in case, for everyone. nbr_files.rlim_cur = MIN(0x100000, nbr_files.rlim_max);
nbr_files.rlim_cur = MIN(INT_MAX, nbr_files.rlim_max);
status = setrlimit(RLIMIT_NOFILE, &nbr_files); status = setrlimit(RLIMIT_NOFILE, &nbr_files);
if (status != 0) { if (status != 0) {