1
1
/*
2
- * Copyright (c) 1999, 2023 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 1999, 2024 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
@@ -2008,15 +2008,15 @@ void os::init(void) {
2008
2008
2009
2009
Bsd::initialize_system_info ();
2010
2010
2011
- // _main_thread points to the thread that created/loaded the JVM.
2011
+ // _main_thread points to the thread that created/loaded the JVM
2012
2012
Bsd::_main_thread = pthread_self ();
2013
2013
2014
2014
Bsd::clock_init ();
2015
2015
2016
2016
os::Posix::init ();
2017
2017
}
2018
2018
2019
- // To install functions for atexit system call
2019
+ // to install functions for atexit system call
2020
2020
extern " C" {
2021
2021
static void perfMemory_exit_helper () {
2022
2022
perfMemory_exit ();
@@ -2036,51 +2036,60 @@ jint os::init_2(void) {
2036
2036
return JNI_ERR;
2037
2037
}
2038
2038
2039
- // Check and sets minimum stack sizes against command line options
2039
+ // check and sets minimum stack sizes against command line options
2040
2040
if (set_minimum_stack_sizes () == JNI_ERR) {
2041
2041
return JNI_ERR;
2042
2042
}
2043
2043
2044
- // Not supported.
2044
+ // not supported
2045
2045
FLAG_SET_ERGO (UseNUMA, false );
2046
2046
FLAG_SET_ERGO (UseNUMAInterleaving, false );
2047
2047
2048
2048
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
2050
2050
// if getrlimit/setrlimit fails but continue regardless.
2051
2051
struct rlimit nbr_files;
2052
2052
int status = getrlimit (RLIMIT_NOFILE, &nbr_files);
2053
2053
if (status != 0 ) {
2054
2054
log_info (os)(" os::init_2 getrlimit failed: %s" , os::strerror (errno));
2055
2055
} else {
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
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 );
2064
2067
2065
2068
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
+ }
2066
2075
if (status != 0 ) {
2067
2076
log_info (os)(" os::init_2 setrlimit failed: %s" , os::strerror (errno));
2068
2077
}
2069
2078
}
2070
2079
}
2071
2080
2072
- // at -exit methods are called in the reverse order of their registration.
2081
+ // At -exit methods are called in the reverse order of their registration.
2073
2082
// atexit functions are called on return from main or as a result of a
2074
2083
// call to exit(3C). There can be only 32 of these functions registered
2075
2084
// and atexit() does not set errno.
2076
2085
2077
2086
if (PerfAllowAtExitRegistration) {
2078
- // only register atexit functions if PerfAllowAtExitRegistration is set.
2087
+ // Only register atexit functions if PerfAllowAtExitRegistration is set.
2079
2088
// atexit functions can be delayed until process exit time, which
2080
2089
// can be problematic for embedded VM situations. Embedded VMs should
2081
2090
// call DestroyJavaVM() to assure that VM resources are released.
2082
2091
2083
- // note : perfMemory_exit_helper atexit function may be removed in
2092
+ // Note : perfMemory_exit_helper atexit function may be removed in
2084
2093
// the future if the appropriate cleanup code can be added to the
2085
2094
// VM_Exit VMOperation's doit method.
2086
2095
if (atexit (perfMemory_exit_helper) != 0 ) {
@@ -2103,7 +2112,7 @@ jint os::init_2(void) {
2103
2112
}
2104
2113
2105
2114
int os::active_processor_count () {
2106
- // User has overridden the number of active processors
2115
+ // user has overridden the number of active processors
2107
2116
if (ActiveProcessorCount > 0 ) {
2108
2117
log_trace (os)(" active_processor_count: "
2109
2118
" active processor count set by user : %d" ,
@@ -2156,9 +2165,9 @@ uint os::processor_id() {
2156
2165
2157
2166
void os::set_native_thread_name (const char *name) {
2158
2167
#if defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
2159
- // This is only supported in Snow Leopard and beyond
2168
+ // this is only supported in Snow Leopard and beyond
2160
2169
if (name != nullptr ) {
2161
- // Add a "Java: " prefix to the name
2170
+ // add a "Java: " prefix to the name
2162
2171
char buf[MAXTHREADNAMESIZE];
2163
2172
snprintf (buf, sizeof (buf), " Java: %s" , name);
2164
2173
pthread_setname_np (buf);
0 commit comments