src/os/linux/vm/os_linux.cpp

Print this page




  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 // no precompiled headers
  26 #include "classfile/classLoader.hpp"
  27 #include "classfile/systemDictionary.hpp"
  28 #include "classfile/vmSymbols.hpp"
  29 #include "code/icBuffer.hpp"
  30 #include "code/vtableStubs.hpp"
  31 #include "compiler/compileBroker.hpp"
  32 #include "compiler/disassembler.hpp"
  33 #include "interpreter/interpreter.hpp"
  34 #include "jvm_linux.h"
  35 #include "memory/allocation.inline.hpp"
  36 #include "memory/filemap.hpp"
  37 #include "mutex_linux.inline.hpp"
  38 #include "oops/oop.inline.hpp"
  39 #include "os_share_linux.hpp"

  40 #include "prims/jniFastGetField.hpp"
  41 #include "prims/jvm.h"
  42 #include "prims/jvm_misc.hpp"
  43 #include "runtime/arguments.hpp"
  44 #include "runtime/extendedPC.hpp"
  45 #include "runtime/globals.hpp"
  46 #include "runtime/interfaceSupport.hpp"
  47 #include "runtime/init.hpp"
  48 #include "runtime/java.hpp"
  49 #include "runtime/javaCalls.hpp"
  50 #include "runtime/mutexLocker.hpp"
  51 #include "runtime/objectMonitor.hpp"
  52 #include "runtime/orderAccess.inline.hpp"
  53 #include "runtime/osThread.hpp"
  54 #include "runtime/perfMemory.hpp"
  55 #include "runtime/sharedRuntime.hpp"
  56 #include "runtime/statSampler.hpp"
  57 #include "runtime/stubRoutines.hpp"
  58 #include "runtime/thread.inline.hpp"
  59 #include "runtime/threadCritical.hpp"


 162 static int SR_signum = SIGUSR2;
 163 sigset_t SR_sigset;
 164 
 165 /* Used to protect dlsym() calls */
 166 static pthread_mutex_t dl_mutex;
 167 
 168 // Declarations
 169 static void unpackTime(timespec* absTime, bool isAbsolute, jlong time);
 170 
 171 // utility functions
 172 
 173 static int SR_initialize();
 174 
 175 julong os::available_memory() {
 176   return Linux::available_memory();
 177 }
 178 
 179 julong os::Linux::available_memory() {
 180   // values in struct sysinfo are "unsigned long"
 181   struct sysinfo si;
 182   sysinfo(&si);
 183 
 184   return (julong)si.freeram * si.mem_unit;





























 185 }
 186 
 187 julong os::physical_memory() {
 188   return Linux::physical_memory();




















 189 }
 190 
 191 ////////////////////////////////////////////////////////////////////////////////
 192 // environment support
 193 
 194 bool os::getenv(const char* name, char* buf, int len) {
 195   const char* val = ::getenv(name);
 196   if (val != NULL && strlen(val) < (size_t)len) {
 197     strcpy(buf, val);
 198     return true;
 199   }
 200   if (len > 0) buf[0] = 0;  // return a null string
 201   return false;
 202 }
 203 
 204 
 205 // Return true if user is running as root.
 206 
 207 bool os::have_special_privileges() {
 208   static bool init = false;


2103 void os::print_os_info(outputStream* st) {
2104   st->print("OS:");
2105 
2106   os::Linux::print_distro_info(st);
2107 
2108   os::Posix::print_uname_info(st);
2109 
2110   // Print warning if unsafe chroot environment detected
2111   if (unsafe_chroot_detected) {
2112     st->print("WARNING!! ");
2113     st->print_cr("%s", unstable_chroot_error);
2114   }
2115 
2116   os::Linux::print_libversion_info(st);
2117 
2118   os::Posix::print_rlimit_info(st);
2119 
2120   os::Posix::print_load_average(st);
2121 
2122   os::Linux::print_full_memory_info(st);


2123 }
2124 
2125 // Try to identify popular distros.
2126 // Most Linux distributions have a /etc/XXX-release file, which contains
2127 // the OS version string. Newer Linux distributions have a /etc/lsb-release
2128 // file that also contains the OS version string. Some have more than one
2129 // /etc/XXX-release file (e.g. Mandrake has both /etc/mandrake-release and
2130 // /etc/redhat-release.), so the order is important.
2131 // Any Linux that is based on Redhat (i.e. Oracle, Mandrake, Sun JDS...) have
2132 // their own specific XXX-release file as well as a redhat-release file.
2133 // Because of this the XXX-release file needs to be searched for before the
2134 // redhat-release file.
2135 // Since Red Hat has a lsb-release file that is not very descriptive the
2136 // search for redhat-release needs to be before lsb-release.
2137 // Since the lsb-release file is the new standard it needs to be searched
2138 // before the older style release files.
2139 // Searching system-release (Red Hat) and os-release (other Linuxes) are a
2140 // next to last resort.  The os-release file is a new standard that contains
2141 // distribution information and the system-release file seems to be an old
2142 // standard that has been replaced by the lsb-release and os-release files.


2168    st->cr();
2169 }
2170 
2171 void os::Linux::print_libversion_info(outputStream* st) {
2172   // libc, pthread
2173   st->print("libc:");
2174   st->print("%s ", os::Linux::glibc_version());
2175   st->print("%s ", os::Linux::libpthread_version());
2176   if (os::Linux::is_LinuxThreads()) {
2177      st->print("(%s stack)", os::Linux::is_floating_stack() ? "floating" : "fixed");
2178   }
2179   st->cr();
2180 }
2181 
2182 void os::Linux::print_full_memory_info(outputStream* st) {
2183    st->print("\n/proc/meminfo:\n");
2184    _print_ascii_file("/proc/meminfo", st);
2185    st->cr();
2186 }
2187 



















































2188 void os::print_memory_info(outputStream* st) {
2189 
2190   st->print("Memory:");
2191   st->print(" %dk page", os::vm_page_size()>>10);
2192 
2193   // values in struct sysinfo are "unsigned long"
2194   struct sysinfo si;
2195   sysinfo(&si);
2196 
2197   st->print(", physical " UINT64_FORMAT "k",
2198             os::physical_memory() >> 10);
2199   st->print("(" UINT64_FORMAT "k free)",
2200             os::available_memory() >> 10);
2201   st->print(", swap " UINT64_FORMAT "k",
2202             ((jlong)si.totalswap * si.mem_unit) >> 10);
2203   st->print("(" UINT64_FORMAT "k free)",
2204             ((jlong)si.freeswap * si.mem_unit) >> 10);
2205   st->cr();
2206 }
2207 


4939 
4940   pthread_mutex_init(&dl_mutex, NULL);
4941 
4942   // If the pagesize of the VM is greater than 8K determine the appropriate
4943   // number of initial guard pages.  The user can change this with the
4944   // command line arguments, if needed.
4945   if (vm_page_size() > (int)Linux::vm_default_page_size()) {
4946     StackYellowPages = 1;
4947     StackRedPages = 1;
4948     StackShadowPages = round_to((StackShadowPages*Linux::vm_default_page_size()), vm_page_size()) / vm_page_size();
4949   }
4950 }
4951 
4952 // To install functions for atexit system call
4953 extern "C" {
4954   static void perfMemory_exit_helper() {
4955     perfMemory_exit();
4956   }
4957 }
4958 




4959 // this is called _after_ the global arguments have been parsed
4960 jint os::init_2(void)
4961 {
4962   Linux::fast_thread_clock_init();
4963 
4964   // Allocate a single page and mark it as readable for safepoint polling
4965   address polling_page = (address) ::mmap(NULL, Linux::page_size(), PROT_READ, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
4966   guarantee( polling_page != MAP_FAILED, "os::init_2: failed to allocate polling page" );
4967 
4968   os::set_polling_page( polling_page );
4969 
4970 #ifndef PRODUCT
4971   if(Verbose && PrintMiscellaneous)
4972     tty->print("[SafePoint Polling address: " INTPTR_FORMAT "]\n", (intptr_t)polling_page);
4973 #endif
4974 
4975   if (!UseMembar) {
4976     address mem_serialize_page = (address) ::mmap(NULL, Linux::page_size(), PROT_READ | PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
4977     guarantee( mem_serialize_page != MAP_FAILED, "mmap Failed for memory serialize page");
4978     os::set_memory_serialize_page( mem_serialize_page );


5119     fatal("Could not enable polling page");
5120   }
5121 };
5122 
5123 static int os_cpu_count(const cpu_set_t* cpus) {
5124   int count = 0;
5125   // only look up to the number of configured processors
5126   for (int i = 0; i < os::processor_count(); i++) {
5127     if (CPU_ISSET(i, cpus)) {
5128       count++;
5129     }
5130   }
5131   return count;
5132 }
5133 
5134 // Get the current number of available processors for this process.
5135 // This value can change at any time during a process's lifetime.
5136 // sched_getaffinity gives an accurate answer as it accounts for cpusets.
5137 // If anything goes wrong we fallback to returning the number of online
5138 // processors - which can be greater than the number available to the process.
5139 int os::active_processor_count() {
5140   cpu_set_t cpus;  // can represent at most 1024 (CPU_SETSIZE) processors
5141   int cpus_size = sizeof(cpu_set_t);
5142   int cpu_count = 0;
5143 
5144   // pid 0 means the current thread - which we have to assume represents the process
5145   if (sched_getaffinity(0, cpus_size, &cpus) == 0) {
5146     cpu_count = os_cpu_count(&cpus);
5147     if (PrintActiveCpus) {
5148       tty->print_cr("active_processor_count: sched_getaffinity processor count: %d", cpu_count);
5149     }
5150   }
5151   else {
5152     cpu_count = ::sysconf(_SC_NPROCESSORS_ONLN);
5153     warning("sched_getaffinity failed (%s)- using online processor count (%d) "
5154             "which may exceed available processors", strerror(errno), cpu_count);
5155   }
5156 
5157   assert(cpu_count > 0 && cpu_count <= processor_count(), "sanity check");
5158   return cpu_count;
5159 }
5160 






































5161 void os::set_native_thread_name(const char *name) {
5162   // Not yet implemented.
5163   return;
5164 }
5165 
5166 bool os::distribute_processes(uint length, uint* distribution) {
5167   // Not yet implemented.
5168   return false;
5169 }
5170 
5171 bool os::bind_to_processor(uint processor_id) {
5172   // Not yet implemented.
5173   return false;
5174 }
5175 
5176 ///
5177 
5178 void os::SuspendedThreadTask::internal_do_task() {
5179   if (do_suspend(_thread->osthread())) {
5180     SuspendedThreadTaskContext context(_thread, _thread->osthread()->ucontext());




  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 // no precompiled headers
  26 #include "classfile/classLoader.hpp"
  27 #include "classfile/systemDictionary.hpp"
  28 #include "classfile/vmSymbols.hpp"
  29 #include "code/icBuffer.hpp"
  30 #include "code/vtableStubs.hpp"
  31 #include "compiler/compileBroker.hpp"
  32 #include "compiler/disassembler.hpp"
  33 #include "interpreter/interpreter.hpp"
  34 #include "jvm_linux.h"
  35 #include "memory/allocation.inline.hpp"
  36 #include "memory/filemap.hpp"
  37 #include "mutex_linux.inline.hpp"
  38 #include "oops/oop.inline.hpp"
  39 #include "os_share_linux.hpp"
  40 #include "osContainer_linux.hpp"
  41 #include "prims/jniFastGetField.hpp"
  42 #include "prims/jvm.h"
  43 #include "prims/jvm_misc.hpp"
  44 #include "runtime/arguments.hpp"
  45 #include "runtime/extendedPC.hpp"
  46 #include "runtime/globals.hpp"
  47 #include "runtime/interfaceSupport.hpp"
  48 #include "runtime/init.hpp"
  49 #include "runtime/java.hpp"
  50 #include "runtime/javaCalls.hpp"
  51 #include "runtime/mutexLocker.hpp"
  52 #include "runtime/objectMonitor.hpp"
  53 #include "runtime/orderAccess.inline.hpp"
  54 #include "runtime/osThread.hpp"
  55 #include "runtime/perfMemory.hpp"
  56 #include "runtime/sharedRuntime.hpp"
  57 #include "runtime/statSampler.hpp"
  58 #include "runtime/stubRoutines.hpp"
  59 #include "runtime/thread.inline.hpp"
  60 #include "runtime/threadCritical.hpp"


 163 static int SR_signum = SIGUSR2;
 164 sigset_t SR_sigset;
 165 
 166 /* Used to protect dlsym() calls */
 167 static pthread_mutex_t dl_mutex;
 168 
 169 // Declarations
 170 static void unpackTime(timespec* absTime, bool isAbsolute, jlong time);
 171 
 172 // utility functions
 173 
 174 static int SR_initialize();
 175 
 176 julong os::available_memory() {
 177   return Linux::available_memory();
 178 }
 179 
 180 julong os::Linux::available_memory() {
 181   // values in struct sysinfo are "unsigned long"
 182   struct sysinfo si;
 183   julong avail_mem;
 184 
 185   if (OSContainer::is_containerized()) {
 186     jlong mem_limit, mem_usage;
 187     if ((mem_limit = OSContainer::memory_limit_in_bytes()) < 1) {
 188       if (PrintContainerInfo) {
 189         tty->print_cr("container memory limit %s: " JLONG_FORMAT ", using host value",
 190                        mem_limit == OSCONTAINER_ERROR ? "failed" : "unlimited", mem_limit);
 191       }
 192     }
 193 
 194     if (mem_limit > 0 && (mem_usage = OSContainer::memory_usage_in_bytes()) < 1) {
 195       if (PrintContainerInfo) {
 196         tty->print_cr("container memory usage failed: " JLONG_FORMAT ", using host value", mem_usage);
 197       }
 198     }
 199 
 200     if (mem_limit > 0 && mem_usage > 0 ) {
 201       avail_mem = mem_limit > mem_usage ? (julong)mem_limit - (julong)mem_usage : 0;
 202       if (PrintContainerInfo) {
 203         tty->print_cr("available container memory: " JULONG_FORMAT, avail_mem);
 204       }
 205       return avail_mem;
 206     }
 207   }
 208 
 209   sysinfo(&si);
 210   avail_mem = (julong)si.freeram * si.mem_unit;
 211   if (Verbose) {
 212     tty->print_cr("available memory: " JULONG_FORMAT, avail_mem);
 213   }
 214   return avail_mem;
 215 }
 216 
 217 julong os::physical_memory() {
 218   jlong phys_mem = 0;
 219   if (OSContainer::is_containerized()) {
 220     jlong mem_limit;
 221     if ((mem_limit = OSContainer::memory_limit_in_bytes()) > 0) {
 222       if (PrintContainerInfo) {
 223         tty->print_cr("total container memory: " JLONG_FORMAT, mem_limit);
 224       }
 225       return mem_limit;
 226     }
 227 
 228     if (PrintContainerInfo) {
 229       tty->print_cr("container memory limit %s: " JLONG_FORMAT ", using host value",
 230                      mem_limit == OSCONTAINER_ERROR ? "failed" : "unlimited", mem_limit);
 231     }
 232   }
 233 
 234   phys_mem = Linux::physical_memory();
 235   if (Verbose) {
 236     tty->print_cr("total system memory: " JLONG_FORMAT, phys_mem);
 237   }
 238   return phys_mem;
 239 }
 240 
 241 ////////////////////////////////////////////////////////////////////////////////
 242 // environment support
 243 
 244 bool os::getenv(const char* name, char* buf, int len) {
 245   const char* val = ::getenv(name);
 246   if (val != NULL && strlen(val) < (size_t)len) {
 247     strcpy(buf, val);
 248     return true;
 249   }
 250   if (len > 0) buf[0] = 0;  // return a null string
 251   return false;
 252 }
 253 
 254 
 255 // Return true if user is running as root.
 256 
 257 bool os::have_special_privileges() {
 258   static bool init = false;


2153 void os::print_os_info(outputStream* st) {
2154   st->print("OS:");
2155 
2156   os::Linux::print_distro_info(st);
2157 
2158   os::Posix::print_uname_info(st);
2159 
2160   // Print warning if unsafe chroot environment detected
2161   if (unsafe_chroot_detected) {
2162     st->print("WARNING!! ");
2163     st->print_cr("%s", unstable_chroot_error);
2164   }
2165 
2166   os::Linux::print_libversion_info(st);
2167 
2168   os::Posix::print_rlimit_info(st);
2169 
2170   os::Posix::print_load_average(st);
2171 
2172   os::Linux::print_full_memory_info(st);
2173 
2174   os::Linux::print_container_info(st);
2175 }
2176 
2177 // Try to identify popular distros.
2178 // Most Linux distributions have a /etc/XXX-release file, which contains
2179 // the OS version string. Newer Linux distributions have a /etc/lsb-release
2180 // file that also contains the OS version string. Some have more than one
2181 // /etc/XXX-release file (e.g. Mandrake has both /etc/mandrake-release and
2182 // /etc/redhat-release.), so the order is important.
2183 // Any Linux that is based on Redhat (i.e. Oracle, Mandrake, Sun JDS...) have
2184 // their own specific XXX-release file as well as a redhat-release file.
2185 // Because of this the XXX-release file needs to be searched for before the
2186 // redhat-release file.
2187 // Since Red Hat has a lsb-release file that is not very descriptive the
2188 // search for redhat-release needs to be before lsb-release.
2189 // Since the lsb-release file is the new standard it needs to be searched
2190 // before the older style release files.
2191 // Searching system-release (Red Hat) and os-release (other Linuxes) are a
2192 // next to last resort.  The os-release file is a new standard that contains
2193 // distribution information and the system-release file seems to be an old
2194 // standard that has been replaced by the lsb-release and os-release files.


2220    st->cr();
2221 }
2222 
2223 void os::Linux::print_libversion_info(outputStream* st) {
2224   // libc, pthread
2225   st->print("libc:");
2226   st->print("%s ", os::Linux::glibc_version());
2227   st->print("%s ", os::Linux::libpthread_version());
2228   if (os::Linux::is_LinuxThreads()) {
2229      st->print("(%s stack)", os::Linux::is_floating_stack() ? "floating" : "fixed");
2230   }
2231   st->cr();
2232 }
2233 
2234 void os::Linux::print_full_memory_info(outputStream* st) {
2235    st->print("\n/proc/meminfo:\n");
2236    _print_ascii_file("/proc/meminfo", st);
2237    st->cr();
2238 }
2239 
2240 void os::Linux::print_container_info(outputStream* st) {
2241 if (!OSContainer::is_containerized()) {
2242     return;
2243   }
2244 
2245   st->print("container (cgroup) information:\n");
2246 
2247   const char *p_ct = OSContainer::container_type();
2248   st->print("container_type: %s\n", p_ct != NULL ? p_ct : "failed");
2249 
2250   char *p = OSContainer::cpu_cpuset_cpus();
2251   st->print("cpu_cpuset_cpus: %s\n", p != NULL ? p : "failed");
2252   free(p);
2253 
2254   p = OSContainer::cpu_cpuset_memory_nodes();
2255   st->print("cpu_memory_nodes: %s\n", p != NULL ? p : "failed");
2256   free(p);
2257 
2258   int i = OSContainer::active_processor_count();
2259   if (i > 0) {
2260     st->print("active_processor_count: %d\n", i);
2261   } else {
2262     st->print("active_processor_count: failed\n");
2263   }
2264 
2265   i = OSContainer::cpu_quota();
2266   st->print("cpu_quota: %d\n", i);
2267 
2268   i = OSContainer::cpu_period();
2269   st->print("cpu_period: %d\n", i);
2270 
2271   i = OSContainer::cpu_shares();
2272   st->print("cpu_shares: %d\n", i);
2273 
2274   jlong j = OSContainer::memory_limit_in_bytes();
2275   st->print("memory_limit_in_bytes: " JLONG_FORMAT "\n", j);
2276 
2277   j = OSContainer::memory_and_swap_limit_in_bytes();
2278   st->print("memory_and_swap_limit_in_bytes: " JLONG_FORMAT "\n", j);
2279 
2280   j = OSContainer::memory_soft_limit_in_bytes();
2281   st->print("memory_soft_limit_in_bytes: " JLONG_FORMAT "\n", j);
2282 
2283   j = OSContainer::OSContainer::memory_usage_in_bytes();
2284   st->print("memory_usage_in_bytes: " JLONG_FORMAT "\n", j);
2285 
2286   j = OSContainer::OSContainer::memory_max_usage_in_bytes();
2287   st->print("memory_max_usage_in_bytes: " JLONG_FORMAT "\n", j);
2288   st->cr();  
2289 }
2290 
2291 void os::print_memory_info(outputStream* st) {
2292 
2293   st->print("Memory:");
2294   st->print(" %dk page", os::vm_page_size()>>10);
2295 
2296   // values in struct sysinfo are "unsigned long"
2297   struct sysinfo si;
2298   sysinfo(&si);
2299 
2300   st->print(", physical " UINT64_FORMAT "k",
2301             os::physical_memory() >> 10);
2302   st->print("(" UINT64_FORMAT "k free)",
2303             os::available_memory() >> 10);
2304   st->print(", swap " UINT64_FORMAT "k",
2305             ((jlong)si.totalswap * si.mem_unit) >> 10);
2306   st->print("(" UINT64_FORMAT "k free)",
2307             ((jlong)si.freeswap * si.mem_unit) >> 10);
2308   st->cr();
2309 }
2310 


5042 
5043   pthread_mutex_init(&dl_mutex, NULL);
5044 
5045   // If the pagesize of the VM is greater than 8K determine the appropriate
5046   // number of initial guard pages.  The user can change this with the
5047   // command line arguments, if needed.
5048   if (vm_page_size() > (int)Linux::vm_default_page_size()) {
5049     StackYellowPages = 1;
5050     StackRedPages = 1;
5051     StackShadowPages = round_to((StackShadowPages*Linux::vm_default_page_size()), vm_page_size()) / vm_page_size();
5052   }
5053 }
5054 
5055 // To install functions for atexit system call
5056 extern "C" {
5057   static void perfMemory_exit_helper() {
5058     perfMemory_exit();
5059   }
5060 }
5061 
5062 void os::pd_init_container_support() {
5063   OSContainer::init();
5064 }
5065 
5066 // this is called _after_ the global arguments have been parsed
5067 jint os::init_2(void)
5068 {
5069   Linux::fast_thread_clock_init();
5070 
5071   // Allocate a single page and mark it as readable for safepoint polling
5072   address polling_page = (address) ::mmap(NULL, Linux::page_size(), PROT_READ, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
5073   guarantee( polling_page != MAP_FAILED, "os::init_2: failed to allocate polling page" );
5074 
5075   os::set_polling_page( polling_page );
5076 
5077 #ifndef PRODUCT
5078   if(Verbose && PrintMiscellaneous)
5079     tty->print("[SafePoint Polling address: " INTPTR_FORMAT "]\n", (intptr_t)polling_page);
5080 #endif
5081 
5082   if (!UseMembar) {
5083     address mem_serialize_page = (address) ::mmap(NULL, Linux::page_size(), PROT_READ | PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
5084     guarantee( mem_serialize_page != MAP_FAILED, "mmap Failed for memory serialize page");
5085     os::set_memory_serialize_page( mem_serialize_page );


5226     fatal("Could not enable polling page");
5227   }
5228 };
5229 
5230 static int os_cpu_count(const cpu_set_t* cpus) {
5231   int count = 0;
5232   // only look up to the number of configured processors
5233   for (int i = 0; i < os::processor_count(); i++) {
5234     if (CPU_ISSET(i, cpus)) {
5235       count++;
5236     }
5237   }
5238   return count;
5239 }
5240 
5241 // Get the current number of available processors for this process.
5242 // This value can change at any time during a process's lifetime.
5243 // sched_getaffinity gives an accurate answer as it accounts for cpusets.
5244 // If anything goes wrong we fallback to returning the number of online
5245 // processors - which can be greater than the number available to the process.
5246 int os::Linux::active_processor_count() {
5247   cpu_set_t cpus;  // can represent at most 1024 (CPU_SETSIZE) processors
5248   int cpus_size = sizeof(cpu_set_t);
5249   int cpu_count = 0;
5250 
5251   // pid 0 means the current thread - which we have to assume represents the process
5252   if (sched_getaffinity(0, cpus_size, &cpus) == 0) {
5253     cpu_count = os_cpu_count(&cpus);
5254     if (PrintActiveCpus) {
5255       tty->print_cr("active_processor_count: sched_getaffinity processor count: %d", cpu_count);
5256     }
5257   }
5258   else {
5259     cpu_count = ::sysconf(_SC_NPROCESSORS_ONLN);
5260     warning("sched_getaffinity failed (%s)- using online processor count (%d) "
5261             "which may exceed available processors", strerror(errno), cpu_count);
5262   }
5263 
5264   assert(cpu_count > 0 && cpu_count <= os::processor_count(), "sanity check");
5265   return cpu_count;
5266 }
5267 
5268 // Determine the active processor count from one of
5269 // three different sources:
5270 //
5271 // 1. User option -XX:ActiveProcessorCount
5272 // 2. kernel os calls (sched_getaffinity or sysconf(_SC_NPROCESSORS_ONLN)
5273 // 3. extracted from cgroup cpu subsystem (shares and quotas)
5274 //
5275 // Option 1, if specified, will always override.
5276 // If the cgroup subsystem is active and configured, we
5277 // will return the min of the cgroup and option 2 results.
5278 // This is required since tools, such as numactl, that
5279 // alter cpu affinity do not update cgroup subsystem
5280 // cpuset configuration files.
5281 int os::active_processor_count() {
5282   // User has overridden the number of active processors
5283   if (ActiveProcessorCount > 0) {
5284     if (PrintActiveCpus) { 
5285       tty->print_cr("active_processor_count: "
5286                     "active processor count set by user : %d",
5287                     ActiveProcessorCount);
5288     }
5289     return ActiveProcessorCount;
5290   }
5291 
5292   int active_cpus;
5293   if (OSContainer::is_containerized()) {
5294     active_cpus = OSContainer::active_processor_count();
5295     if (PrintActiveCpus) {
5296       tty->print_cr("active_processor_count: determined by OSContainer: %d",
5297                      active_cpus);
5298     }
5299   } else {
5300     active_cpus = os::Linux::active_processor_count();
5301   }
5302 
5303   return active_cpus;
5304 }
5305 
5306 void os::set_native_thread_name(const char *name) {
5307   // Not yet implemented.
5308   return;
5309 }
5310 
5311 bool os::distribute_processes(uint length, uint* distribution) {
5312   // Not yet implemented.
5313   return false;
5314 }
5315 
5316 bool os::bind_to_processor(uint processor_id) {
5317   // Not yet implemented.
5318   return false;
5319 }
5320 
5321 ///
5322 
5323 void os::SuspendedThreadTask::internal_do_task() {
5324   if (do_suspend(_thread->osthread())) {
5325     SuspendedThreadTaskContext context(_thread, _thread->osthread()->ucontext());