hotspot/src/os/linux/vm/os_linux.cpp
changeset 37113 5a33bf5089ac
parent 37097 a4e966af48f6
child 37155 f00f299cb386
equal deleted inserted replaced
37111:98572401ab0a 37113:5a33bf5089ac
   758     if (ret == 0) {
   758     if (ret == 0) {
   759       log_info(os, thread)("Thread started (pthread id: " UINTX_FORMAT ", attributes: %s). ",
   759       log_info(os, thread)("Thread started (pthread id: " UINTX_FORMAT ", attributes: %s). ",
   760         (uintx) tid, os::Posix::describe_pthread_attr(buf, sizeof(buf), &attr));
   760         (uintx) tid, os::Posix::describe_pthread_attr(buf, sizeof(buf), &attr));
   761     } else {
   761     } else {
   762       log_warning(os, thread)("Failed to start thread - pthread_create failed (%s) for attributes: %s.",
   762       log_warning(os, thread)("Failed to start thread - pthread_create failed (%s) for attributes: %s.",
   763         strerror(ret), os::Posix::describe_pthread_attr(buf, sizeof(buf), &attr));
   763         os::errno_name(ret), os::Posix::describe_pthread_attr(buf, sizeof(buf), &attr));
   764     }
   764     }
   765 
   765 
   766     pthread_attr_destroy(&attr);
   766     pthread_attr_destroy(&attr);
   767 
   767 
   768     if (ret != 0) {
   768     if (ret != 0) {
  1391 // from src/solaris/hpi/src/system_md.c
  1391 // from src/solaris/hpi/src/system_md.c
  1392 
  1392 
  1393 size_t os::lasterror(char *buf, size_t len) {
  1393 size_t os::lasterror(char *buf, size_t len) {
  1394   if (errno == 0)  return 0;
  1394   if (errno == 0)  return 0;
  1395 
  1395 
  1396   const char *s = ::strerror(errno);
  1396   const char *s = os::strerror(errno);
  1397   size_t n = ::strlen(s);
  1397   size_t n = ::strlen(s);
  1398   if (n >= len) {
  1398   if (n >= len) {
  1399     n = len - 1;
  1399     n = len - 1;
  1400   }
  1400   }
  1401   ::strncpy(buf, s, n);
  1401   ::strncpy(buf, s, n);
  2597 
  2597 
  2598 static void warn_fail_commit_memory(char* addr, size_t size, bool exec,
  2598 static void warn_fail_commit_memory(char* addr, size_t size, bool exec,
  2599                                     int err) {
  2599                                     int err) {
  2600   warning("INFO: os::commit_memory(" PTR_FORMAT ", " SIZE_FORMAT
  2600   warning("INFO: os::commit_memory(" PTR_FORMAT ", " SIZE_FORMAT
  2601           ", %d) failed; error='%s' (errno=%d)", p2i(addr), size, exec,
  2601           ", %d) failed; error='%s' (errno=%d)", p2i(addr), size, exec,
  2602           strerror(err), err);
  2602           os::strerror(err), err);
  2603 }
  2603 }
  2604 
  2604 
  2605 static void warn_fail_commit_memory(char* addr, size_t size,
  2605 static void warn_fail_commit_memory(char* addr, size_t size,
  2606                                     size_t alignment_hint, bool exec,
  2606                                     size_t alignment_hint, bool exec,
  2607                                     int err) {
  2607                                     int err) {
  2608   warning("INFO: os::commit_memory(" PTR_FORMAT ", " SIZE_FORMAT
  2608   warning("INFO: os::commit_memory(" PTR_FORMAT ", " SIZE_FORMAT
  2609           ", " SIZE_FORMAT ", %d) failed; error='%s' (errno=%d)", p2i(addr), size,
  2609           ", " SIZE_FORMAT ", %d) failed; error='%s' (errno=%d)", p2i(addr), size,
  2610           alignment_hint, exec, strerror(err), err);
  2610           alignment_hint, exec, os::strerror(err), err);
  2611 }
  2611 }
  2612 
  2612 
  2613 // NOTE: Linux kernel does not really reserve the pages for us.
  2613 // NOTE: Linux kernel does not really reserve the pages for us.
  2614 //       All it does is to check if there are enough free pages
  2614 //       All it does is to check if there are enough free pages
  2615 //       left at the time of mmap(). This could be a potential
  2615 //       left at the time of mmap(). This could be a potential
  4571   ThreadCritical::initialize();
  4571   ThreadCritical::initialize();
  4572 
  4572 
  4573   Linux::set_page_size(sysconf(_SC_PAGESIZE));
  4573   Linux::set_page_size(sysconf(_SC_PAGESIZE));
  4574   if (Linux::page_size() == -1) {
  4574   if (Linux::page_size() == -1) {
  4575     fatal("os_linux.cpp: os::init: sysconf failed (%s)",
  4575     fatal("os_linux.cpp: os::init: sysconf failed (%s)",
  4576           strerror(errno));
  4576           os::strerror(errno));
  4577   }
  4577   }
  4578   init_page_sizes((size_t) Linux::page_size());
  4578   init_page_sizes((size_t) Linux::page_size());
  4579 
  4579 
  4580   Linux::initialize_system_info();
  4580   Linux::initialize_system_info();
  4581 
  4581 
  4587 
  4587 
  4588   // pthread_condattr initialization for monotonic clock
  4588   // pthread_condattr initialization for monotonic clock
  4589   int status;
  4589   int status;
  4590   pthread_condattr_t* _condattr = os::Linux::condAttr();
  4590   pthread_condattr_t* _condattr = os::Linux::condAttr();
  4591   if ((status = pthread_condattr_init(_condattr)) != 0) {
  4591   if ((status = pthread_condattr_init(_condattr)) != 0) {
  4592     fatal("pthread_condattr_init: %s", strerror(status));
  4592     fatal("pthread_condattr_init: %s", os::strerror(status));
  4593   }
  4593   }
  4594   // Only set the clock if CLOCK_MONOTONIC is available
  4594   // Only set the clock if CLOCK_MONOTONIC is available
  4595   if (os::supports_monotonic_clock()) {
  4595   if (os::supports_monotonic_clock()) {
  4596     if ((status = pthread_condattr_setclock(_condattr, CLOCK_MONOTONIC)) != 0) {
  4596     if ((status = pthread_condattr_setclock(_condattr, CLOCK_MONOTONIC)) != 0) {
  4597       if (status == EINVAL) {
  4597       if (status == EINVAL) {
  4598         warning("Unable to use monotonic clock with relative timed-waits" \
  4598         warning("Unable to use monotonic clock with relative timed-waits" \
  4599                 " - changes to the time-of-day clock may have adverse affects");
  4599                 " - changes to the time-of-day clock may have adverse affects");
  4600       } else {
  4600       } else {
  4601         fatal("pthread_condattr_setclock: %s", strerror(status));
  4601         fatal("pthread_condattr_setclock: %s", os::strerror(status));
  4602       }
  4602       }
  4603     }
  4603     }
  4604   }
  4604   }
  4605   // else it defaults to CLOCK_REALTIME
  4605   // else it defaults to CLOCK_REALTIME
  4606 
  4606 
  4842        // failed to allocate so fallback to online cpus
  4842        // failed to allocate so fallback to online cpus
  4843        int online_cpus = ::sysconf(_SC_NPROCESSORS_ONLN);
  4843        int online_cpus = ::sysconf(_SC_NPROCESSORS_ONLN);
  4844        log_trace(os)("active_processor_count: "
  4844        log_trace(os)("active_processor_count: "
  4845                      "CPU_ALLOC failed (%s) - using "
  4845                      "CPU_ALLOC failed (%s) - using "
  4846                      "online processor count: %d",
  4846                      "online processor count: %d",
  4847                      strerror(errno), online_cpus);
  4847                      os::strerror(errno), online_cpus);
  4848        return online_cpus;
  4848        return online_cpus;
  4849     }
  4849     }
  4850   }
  4850   }
  4851   else {
  4851   else {
  4852     log_trace(os)("active_processor_count: using static path - configured processors: %d",
  4852     log_trace(os)("active_processor_count: using static path - configured processors: %d",
  4872     log_trace(os)("active_processor_count: sched_getaffinity processor count: %d", cpu_count);
  4872     log_trace(os)("active_processor_count: sched_getaffinity processor count: %d", cpu_count);
  4873   }
  4873   }
  4874   else {
  4874   else {
  4875     cpu_count = ::sysconf(_SC_NPROCESSORS_ONLN);
  4875     cpu_count = ::sysconf(_SC_NPROCESSORS_ONLN);
  4876     warning("sched_getaffinity failed (%s)- using online processor count (%d) "
  4876     warning("sched_getaffinity failed (%s)- using online processor count (%d) "
  4877             "which may exceed available processors", strerror(errno), cpu_count);
  4877             "which may exceed available processors", os::strerror(errno), cpu_count);
  4878   }
  4878   }
  4879 
  4879 
  4880   if (cpus_p != &cpus) { // can only be true when CPU_ALLOC used
  4880   if (cpus_p != &cpus) { // can only be true when CPU_ALLOC used
  4881     CPU_FREE(cpus_p);
  4881     CPU_FREE(cpus_p);
  4882   }
  4882   }