Skip to content

Commit 6d2f640

Browse files
author
David Holmes
committedJan 24, 2024
8324578: [BACKOUT] [IMPROVE] OPEN_MAX is no longer the max limit on macOS >= 10.6 for RLIMIT_NOFILE
Reviewed-by: darcy, kvn
1 parent c17059d commit 6d2f640

File tree

1 file changed

+20
-29
lines changed

1 file changed

+20
-29
lines changed
 

‎src/hotspot/os/bsd/os_bsd.cpp

+20-29
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -2008,15 +2008,15 @@ void os::init(void) {
20082008

20092009
Bsd::initialize_system_info();
20102010

2011-
// _main_thread points to the thread that created/loaded the JVM
2011+
// _main_thread points to the thread that created/loaded the JVM.
20122012
Bsd::_main_thread = pthread_self();
20132013

20142014
Bsd::clock_init();
20152015

20162016
os::Posix::init();
20172017
}
20182018

2019-
// to install functions for atexit system call
2019+
// To install functions for atexit system call
20202020
extern "C" {
20212021
static void perfMemory_exit_helper() {
20222022
perfMemory_exit();
@@ -2036,60 +2036,51 @@ jint os::init_2(void) {
20362036
return JNI_ERR;
20372037
}
20382038

2039-
// check and sets minimum stack sizes against command line options
2039+
// Check and sets minimum stack sizes against command line options
20402040
if (set_minimum_stack_sizes() == JNI_ERR) {
20412041
return JNI_ERR;
20422042
}
20432043

2044-
// not supported
2044+
// Not supported.
20452045
FLAG_SET_ERGO(UseNUMA, false);
20462046
FLAG_SET_ERGO(UseNUMAInterleaving, false);
20472047

20482048
if (MaxFDLimit) {
2049-
// Set the number of file descriptors to max. Print out error
2049+
// set the number of file descriptors to max. print out error
20502050
// if getrlimit/setrlimit fails but continue regardless.
20512051
struct rlimit nbr_files;
20522052
int status = getrlimit(RLIMIT_NOFILE, &nbr_files);
20532053
if (status != 0) {
20542054
log_info(os)("os::init_2 getrlimit failed: %s", os::strerror(errno));
20552055
} else {
2056-
rlim_t rlim_original = nbr_files.rlim_cur;
2057-
2058-
// On macOS according to setrlimit(2), OPEN_MAX must be used instead
2059-
// of RLIM_INFINITY, but testing on macOS >= 10.6, reveals that
2060-
// we can, in fact, use even RLIM_INFINITY, so try the max value
2061-
// that the system claims can be used first, same as other BSD OSes.
2062-
// However, some terminals (ksh) will internally use "int" type
2063-
// to store this value and since RLIM_INFINITY overflows an "int"
2064-
// we might end up with a negative value, so cap the system limit max
2065-
// at INT_MAX instead, just in case, for everyone.
2066-
nbr_files.rlim_cur = MIN(INT_MAX, nbr_files.rlim_max);
2056+
nbr_files.rlim_cur = nbr_files.rlim_max;
2057+
2058+
#ifdef __APPLE__
2059+
// Darwin returns RLIM_INFINITY for rlim_max, but fails with EINVAL if
2060+
// you attempt to use RLIM_INFINITY. As per setrlimit(2), OPEN_MAX must
2061+
// be used instead
2062+
nbr_files.rlim_cur = MIN(OPEN_MAX, nbr_files.rlim_cur);
2063+
#endif
20672064

20682065
status = setrlimit(RLIMIT_NOFILE, &nbr_files);
2069-
if (status != 0) {
2070-
// If that fails then try lowering the limit to either OPEN_MAX
2071-
// (which is safe) or the original limit, whichever was greater.
2072-
nbr_files.rlim_cur = MAX(OPEN_MAX, rlim_original);
2073-
status = setrlimit(RLIMIT_NOFILE, &nbr_files);
2074-
}
20752066
if (status != 0) {
20762067
log_info(os)("os::init_2 setrlimit failed: %s", os::strerror(errno));
20772068
}
20782069
}
20792070
}
20802071

2081-
// At-exit methods are called in the reverse order of their registration.
2072+
// at-exit methods are called in the reverse order of their registration.
20822073
// atexit functions are called on return from main or as a result of a
20832074
// call to exit(3C). There can be only 32 of these functions registered
20842075
// and atexit() does not set errno.
20852076

20862077
if (PerfAllowAtExitRegistration) {
2087-
// Only register atexit functions if PerfAllowAtExitRegistration is set.
2078+
// only register atexit functions if PerfAllowAtExitRegistration is set.
20882079
// atexit functions can be delayed until process exit time, which
20892080
// can be problematic for embedded VM situations. Embedded VMs should
20902081
// call DestroyJavaVM() to assure that VM resources are released.
20912082

2092-
// Note: perfMemory_exit_helper atexit function may be removed in
2083+
// note: perfMemory_exit_helper atexit function may be removed in
20932084
// the future if the appropriate cleanup code can be added to the
20942085
// VM_Exit VMOperation's doit method.
20952086
if (atexit(perfMemory_exit_helper) != 0) {
@@ -2112,7 +2103,7 @@ jint os::init_2(void) {
21122103
}
21132104

21142105
int os::active_processor_count() {
2115-
// user has overridden the number of active processors
2106+
// User has overridden the number of active processors
21162107
if (ActiveProcessorCount > 0) {
21172108
log_trace(os)("active_processor_count: "
21182109
"active processor count set by user : %d",
@@ -2165,9 +2156,9 @@ uint os::processor_id() {
21652156

21662157
void os::set_native_thread_name(const char *name) {
21672158
#if defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
2168-
// this is only supported in Snow Leopard and beyond
2159+
// This is only supported in Snow Leopard and beyond
21692160
if (name != nullptr) {
2170-
// add a "Java: " prefix to the name
2161+
// Add a "Java: " prefix to the name
21712162
char buf[MAXTHREADNAMESIZE];
21722163
snprintf(buf, sizeof(buf), "Java: %s", name);
21732164
pthread_setname_np(buf);

0 commit comments

Comments
 (0)
Please sign in to comment.