155 static sigset_t check_signal_done;
156 static bool check_signals = true;
157
158 // Signal number used to suspend/resume a thread
159
160 // do not use any signal number less than SIGSEGV, see 4355769
161 static int SR_signum = SIGUSR2;
162 sigset_t SR_sigset;
163
164 // utility functions
165
166 static int SR_initialize();
167
168 julong os::available_memory() {
169 return Linux::available_memory();
170 }
171
172 julong os::Linux::available_memory() {
173 // values in struct sysinfo are "unsigned long"
174 struct sysinfo si;
175 sysinfo(&si);
176
177 return (julong)si.freeram * si.mem_unit;
178 }
179
180 julong os::physical_memory() {
181 return Linux::physical_memory();
182 }
183
184 // Return true if user is running as root.
185
186 bool os::have_special_privileges() {
187 static bool init = false;
188 static bool privileges = false;
189 if (!init) {
190 privileges = (getuid() != geteuid()) || (getgid() != getegid());
191 init = true;
192 }
193 return privileges;
194 }
195
196
1934 void os::print_os_info(outputStream* st) {
1935 st->print("OS:");
1936
1937 os::Linux::print_distro_info(st);
1938
1939 os::Posix::print_uname_info(st);
1940
1941 // Print warning if unsafe chroot environment detected
1942 if (unsafe_chroot_detected) {
1943 st->print("WARNING!! ");
1944 st->print_cr("%s", unstable_chroot_error);
1945 }
1946
1947 os::Linux::print_libversion_info(st);
1948
1949 os::Posix::print_rlimit_info(st);
1950
1951 os::Posix::print_load_average(st);
1952
1953 os::Linux::print_full_memory_info(st);
1954 }
1955
1956 // Try to identify popular distros.
1957 // Most Linux distributions have a /etc/XXX-release file, which contains
1958 // the OS version string. Newer Linux distributions have a /etc/lsb-release
1959 // file that also contains the OS version string. Some have more than one
1960 // /etc/XXX-release file (e.g. Mandrake has both /etc/mandrake-release and
1961 // /etc/redhat-release.), so the order is important.
1962 // Any Linux that is based on Redhat (i.e. Oracle, Mandrake, Sun JDS...) have
1963 // their own specific XXX-release file as well as a redhat-release file.
1964 // Because of this the XXX-release file needs to be searched for before the
1965 // redhat-release file.
1966 // Since Red Hat and SuSE have an lsb-release file that is not very descriptive the
1967 // search for redhat-release / SuSE-release needs to be before lsb-release.
1968 // Since the lsb-release file is the new standard it needs to be searched
1969 // before the older style release files.
1970 // Searching system-release (Red Hat) and os-release (other Linuxes) are a
1971 // next to last resort. The os-release file is a new standard that contains
1972 // distribution information and the system-release file seems to be an old
1973 // standard that has been replaced by the lsb-release and os-release files.
2071 parse_os_info(&buf[7], buflen-7, "/etc/debian_version");
2072 } else {
2073 strncpy(buf, "Linux", buflen);
2074 }
2075 }
2076
2077 void os::Linux::print_libversion_info(outputStream* st) {
2078 // libc, pthread
2079 st->print("libc:");
2080 st->print("%s ", os::Linux::glibc_version());
2081 st->print("%s ", os::Linux::libpthread_version());
2082 st->cr();
2083 }
2084
2085 void os::Linux::print_full_memory_info(outputStream* st) {
2086 st->print("\n/proc/meminfo:\n");
2087 _print_ascii_file("/proc/meminfo", st);
2088 st->cr();
2089 }
2090
2091 void os::print_memory_info(outputStream* st) {
2092
2093 st->print("Memory:");
2094 st->print(" %dk page", os::vm_page_size()>>10);
2095
2096 // values in struct sysinfo are "unsigned long"
2097 struct sysinfo si;
2098 sysinfo(&si);
2099
2100 st->print(", physical " UINT64_FORMAT "k",
2101 os::physical_memory() >> 10);
2102 st->print("(" UINT64_FORMAT "k free)",
2103 os::available_memory() >> 10);
2104 st->print(", swap " UINT64_FORMAT "k",
2105 ((jlong)si.totalswap * si.mem_unit) >> 10);
2106 st->print("(" UINT64_FORMAT "k free)",
2107 ((jlong)si.freeswap * si.mem_unit) >> 10);
2108 st->cr();
2109 }
2110
4786
4787 Linux::clock_init();
4788 initial_time_count = javaTimeNanos();
4789
4790 // retrieve entry point for pthread_setname_np
4791 Linux::_pthread_setname_np =
4792 (int(*)(pthread_t, const char*))dlsym(RTLD_DEFAULT, "pthread_setname_np");
4793
4794 os::Posix::init();
4795 }
4796
4797 // To install functions for atexit system call
4798 extern "C" {
4799 static void perfMemory_exit_helper() {
4800 perfMemory_exit();
4801 }
4802 }
4803
4804 // this is called _after_ the global arguments have been parsed
4805 jint os::init_2(void) {
4806
4807 os::Posix::init_2();
4808
4809 Linux::fast_thread_clock_init();
4810
4811 // Allocate a single page and mark it as readable for safepoint polling
4812 address polling_page = (address) ::mmap(NULL, Linux::page_size(), PROT_READ, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
4813 guarantee(polling_page != MAP_FAILED, "os::init_2: failed to allocate polling page");
4814
4815 os::set_polling_page(polling_page);
4816 log_info(os)("SafePoint Polling address: " INTPTR_FORMAT, p2i(polling_page));
4817
4818 if (!UseMembar) {
4819 address mem_serialize_page = (address) ::mmap(NULL, Linux::page_size(), PROT_READ | PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
4820 guarantee(mem_serialize_page != MAP_FAILED, "mmap Failed for memory serialize page");
4821 os::set_memory_serialize_page(mem_serialize_page);
4822 log_info(os)("Memory Serialize Page address: " INTPTR_FORMAT, p2i(mem_serialize_page));
4823 }
4824
4825 // initialize suspend/resume support - must do this before signal_sets_init()
4826 if (SR_initialize() != 0) {
4951 }
4952 return count;
4953 }
4954
4955 #define CPU_COUNT(cpus) _cpu_count(cpus)
4956
4957 #endif // CPU_COUNT
4958
4959 // Get the current number of available processors for this process.
4960 // This value can change at any time during a process's lifetime.
4961 // sched_getaffinity gives an accurate answer as it accounts for cpusets.
4962 // If it appears there may be more than 1024 processors then we do a
4963 // dynamic check - see 6515172 for details.
4964 // If anything goes wrong we fallback to returning the number of online
4965 // processors - which can be greater than the number available to the process.
4966 int os::active_processor_count() {
4967 cpu_set_t cpus; // can represent at most 1024 (CPU_SETSIZE) processors
4968 cpu_set_t* cpus_p = &cpus;
4969 int cpus_size = sizeof(cpu_set_t);
4970
4971 int configured_cpus = processor_count(); // upper bound on available cpus
4972 int cpu_count = 0;
4973
4974 // old build platforms may not support dynamic cpu sets
4975 #ifdef CPU_ALLOC
4976
4977 // To enable easy testing of the dynamic path on different platforms we
4978 // introduce a diagnostic flag: UseCpuAllocPath
4979 if (configured_cpus >= CPU_SETSIZE || UseCpuAllocPath) {
4980 // kernel may use a mask bigger than cpu_set_t
4981 log_trace(os)("active_processor_count: using dynamic path %s"
4982 "- configured processors: %d",
4983 UseCpuAllocPath ? "(forced) " : "",
4984 configured_cpus);
4985 cpus_p = CPU_ALLOC(configured_cpus);
4986 if (cpus_p != NULL) {
4987 cpus_size = CPU_ALLOC_SIZE(configured_cpus);
4988 // zero it just to be safe
4989 CPU_ZERO_S(cpus_size, cpus_p);
4990 }
|
155 static sigset_t check_signal_done;
156 static bool check_signals = true;
157
158 // Signal number used to suspend/resume a thread
159
160 // do not use any signal number less than SIGSEGV, see 4355769
161 static int SR_signum = SIGUSR2;
162 sigset_t SR_sigset;
163
164 // utility functions
165
166 static int SR_initialize();
167
168 julong os::available_memory() {
169 return Linux::available_memory();
170 }
171
172 julong os::Linux::available_memory() {
173 // values in struct sysinfo are "unsigned long"
174 struct sysinfo si;
175
176 if (OSContainer::is_containerized()) {
177 julong avail_mem, mem_limit, mem_usage;
178 if ((mem_limit = OSContainer::memory_limit_in_bytes()) > 0) {
179 if ((mem_usage = OSContainer::memory_usage_in_bytes()) > 0) {
180 if (mem_limit > mem_usage) {
181 avail_mem = (julong)(mem_limit - mem_usage);
182 log_trace(os,container)("available container memory: %ld", avail_mem);
183 return avail_mem;
184 }
185 }
186 }
187 }
188
189 sysinfo(&si);
190 return (julong)si.freeram * si.mem_unit;
191 }
192
193 julong os::physical_memory() {
194 return Linux::physical_memory();
195 }
196
197 // Return true if user is running as root.
198
199 bool os::have_special_privileges() {
200 static bool init = false;
201 static bool privileges = false;
202 if (!init) {
203 privileges = (getuid() != geteuid()) || (getgid() != getegid());
204 init = true;
205 }
206 return privileges;
207 }
208
209
1947 void os::print_os_info(outputStream* st) {
1948 st->print("OS:");
1949
1950 os::Linux::print_distro_info(st);
1951
1952 os::Posix::print_uname_info(st);
1953
1954 // Print warning if unsafe chroot environment detected
1955 if (unsafe_chroot_detected) {
1956 st->print("WARNING!! ");
1957 st->print_cr("%s", unstable_chroot_error);
1958 }
1959
1960 os::Linux::print_libversion_info(st);
1961
1962 os::Posix::print_rlimit_info(st);
1963
1964 os::Posix::print_load_average(st);
1965
1966 os::Linux::print_full_memory_info(st);
1967
1968 os::Linux::print_container_info(st);
1969 }
1970
1971 // Try to identify popular distros.
1972 // Most Linux distributions have a /etc/XXX-release file, which contains
1973 // the OS version string. Newer Linux distributions have a /etc/lsb-release
1974 // file that also contains the OS version string. Some have more than one
1975 // /etc/XXX-release file (e.g. Mandrake has both /etc/mandrake-release and
1976 // /etc/redhat-release.), so the order is important.
1977 // Any Linux that is based on Redhat (i.e. Oracle, Mandrake, Sun JDS...) have
1978 // their own specific XXX-release file as well as a redhat-release file.
1979 // Because of this the XXX-release file needs to be searched for before the
1980 // redhat-release file.
1981 // Since Red Hat and SuSE have an lsb-release file that is not very descriptive the
1982 // search for redhat-release / SuSE-release needs to be before lsb-release.
1983 // Since the lsb-release file is the new standard it needs to be searched
1984 // before the older style release files.
1985 // Searching system-release (Red Hat) and os-release (other Linuxes) are a
1986 // next to last resort. The os-release file is a new standard that contains
1987 // distribution information and the system-release file seems to be an old
1988 // standard that has been replaced by the lsb-release and os-release files.
2086 parse_os_info(&buf[7], buflen-7, "/etc/debian_version");
2087 } else {
2088 strncpy(buf, "Linux", buflen);
2089 }
2090 }
2091
2092 void os::Linux::print_libversion_info(outputStream* st) {
2093 // libc, pthread
2094 st->print("libc:");
2095 st->print("%s ", os::Linux::glibc_version());
2096 st->print("%s ", os::Linux::libpthread_version());
2097 st->cr();
2098 }
2099
2100 void os::Linux::print_full_memory_info(outputStream* st) {
2101 st->print("\n/proc/meminfo:\n");
2102 _print_ascii_file("/proc/meminfo", st);
2103 st->cr();
2104 }
2105
2106 void os::Linux::print_container_info(outputStream* st) {
2107 st->print("container:");
2108 if (OSContainer::is_containerized()) {
2109 char *p;
2110 jlong j;
2111 int i;
2112 st->print("Running in a container: true");
2113 p = OSContainer::cpu_cpuset_cpus();
2114 if (p < 0) st->print("OSContainer::cpu_cpuset_cpus() failed");
2115 else {
2116 st->print("OSContainer::cpu_cpuset_cpus: %s", p);
2117 free(p);
2118 }
2119
2120 i = OSContainer::active_processor_count();
2121 if (i < 0) st->print("OSContainer::active_processor_count() failed");
2122 else
2123 st->print("OSContainer::active_processor_count: %d", i);
2124
2125 j = OSContainer::memory_limit_in_bytes();
2126 if (j < 0L) st->print("OSContainer::memory_limit_in_bytes() failed");
2127 else
2128 st->print("OSContainer::memory_limit_in_bytes: %ld", j);
2129
2130 j = OSContainer::OSContainer::memory_usage_in_bytes();
2131 if (j < 0L) st->print("OSContainer::memory_usage_in_bytes() failed");
2132 else
2133 st->print("OSContainer::memory_usage_in_bytes: %ld", j);
2134
2135 j = OSContainer::OSContainer::memory_max_usage_in_bytes();
2136 if (j < 0L) st->print("OSContainer::memory_max_usage_in_bytes() failed");
2137 else
2138 st->print("OSContainer::memory_max_usage_in_bytes: %ld", j);
2139 }
2140 else {
2141 st->print("Running in a container: false");
2142 }
2143 }
2144
2145 void os::print_memory_info(outputStream* st) {
2146
2147 st->print("Memory:");
2148 st->print(" %dk page", os::vm_page_size()>>10);
2149
2150 // values in struct sysinfo are "unsigned long"
2151 struct sysinfo si;
2152 sysinfo(&si);
2153
2154 st->print(", physical " UINT64_FORMAT "k",
2155 os::physical_memory() >> 10);
2156 st->print("(" UINT64_FORMAT "k free)",
2157 os::available_memory() >> 10);
2158 st->print(", swap " UINT64_FORMAT "k",
2159 ((jlong)si.totalswap * si.mem_unit) >> 10);
2160 st->print("(" UINT64_FORMAT "k free)",
2161 ((jlong)si.freeswap * si.mem_unit) >> 10);
2162 st->cr();
2163 }
2164
4840
4841 Linux::clock_init();
4842 initial_time_count = javaTimeNanos();
4843
4844 // retrieve entry point for pthread_setname_np
4845 Linux::_pthread_setname_np =
4846 (int(*)(pthread_t, const char*))dlsym(RTLD_DEFAULT, "pthread_setname_np");
4847
4848 os::Posix::init();
4849 }
4850
4851 // To install functions for atexit system call
4852 extern "C" {
4853 static void perfMemory_exit_helper() {
4854 perfMemory_exit();
4855 }
4856 }
4857
4858 // this is called _after_ the global arguments have been parsed
4859 jint os::init_2(void) {
4860 os::Posix::init_2();
4861
4862 Linux::fast_thread_clock_init();
4863
4864 // Allocate a single page and mark it as readable for safepoint polling
4865 address polling_page = (address) ::mmap(NULL, Linux::page_size(), PROT_READ, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
4866 guarantee(polling_page != MAP_FAILED, "os::init_2: failed to allocate polling page");
4867
4868 os::set_polling_page(polling_page);
4869 log_info(os)("SafePoint Polling address: " INTPTR_FORMAT, p2i(polling_page));
4870
4871 if (!UseMembar) {
4872 address mem_serialize_page = (address) ::mmap(NULL, Linux::page_size(), PROT_READ | PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
4873 guarantee(mem_serialize_page != MAP_FAILED, "mmap Failed for memory serialize page");
4874 os::set_memory_serialize_page(mem_serialize_page);
4875 log_info(os)("Memory Serialize Page address: " INTPTR_FORMAT, p2i(mem_serialize_page));
4876 }
4877
4878 // initialize suspend/resume support - must do this before signal_sets_init()
4879 if (SR_initialize() != 0) {
5004 }
5005 return count;
5006 }
5007
5008 #define CPU_COUNT(cpus) _cpu_count(cpus)
5009
5010 #endif // CPU_COUNT
5011
5012 // Get the current number of available processors for this process.
5013 // This value can change at any time during a process's lifetime.
5014 // sched_getaffinity gives an accurate answer as it accounts for cpusets.
5015 // If it appears there may be more than 1024 processors then we do a
5016 // dynamic check - see 6515172 for details.
5017 // If anything goes wrong we fallback to returning the number of online
5018 // processors - which can be greater than the number available to the process.
5019 int os::active_processor_count() {
5020 cpu_set_t cpus; // can represent at most 1024 (CPU_SETSIZE) processors
5021 cpu_set_t* cpus_p = &cpus;
5022 int cpus_size = sizeof(cpu_set_t);
5023
5024 // User has overridden the number of active processors
5025 if (!FLAG_IS_DEFAULT(ActiveProcessorCount)) {
5026 log_trace(os)("active_processor_count: "
5027 "active processor count set by user : %d",
5028 (int)ActiveProcessorCount);
5029 return ActiveProcessorCount;
5030 }
5031
5032 if (OSContainer::is_containerized()) {
5033 int active_cpus;
5034 if ((active_cpus = OSContainer::active_processor_count()) > 0) {
5035 log_trace(os,container)("active_processor_count: "
5036 "active processor count determined by OSContainer: %d",
5037 (int)active_cpus);
5038 return active_cpus;
5039 }
5040 }
5041
5042 int configured_cpus = processor_count(); // upper bound on available cpus
5043 int cpu_count = 0;
5044
5045 // old build platforms may not support dynamic cpu sets
5046 #ifdef CPU_ALLOC
5047
5048 // To enable easy testing of the dynamic path on different platforms we
5049 // introduce a diagnostic flag: UseCpuAllocPath
5050 if (configured_cpus >= CPU_SETSIZE || UseCpuAllocPath) {
5051 // kernel may use a mask bigger than cpu_set_t
5052 log_trace(os)("active_processor_count: using dynamic path %s"
5053 "- configured processors: %d",
5054 UseCpuAllocPath ? "(forced) " : "",
5055 configured_cpus);
5056 cpus_p = CPU_ALLOC(configured_cpus);
5057 if (cpus_p != NULL) {
5058 cpus_size = CPU_ALLOC_SIZE(configured_cpus);
5059 // zero it just to be safe
5060 CPU_ZERO_S(cpus_size, cpus_p);
5061 }
|