src/os/bsd/vm/os_bsd.cpp

changeset 4229
0af5da0c9d9d
parent 4136
bf2edd3c9b0f
child 4261
6cb0d32b828b
     1.1 --- a/src/os/bsd/vm/os_bsd.cpp	Thu Oct 25 16:33:40 2012 -0400
     1.2 +++ b/src/os/bsd/vm/os_bsd.cpp	Mon Oct 29 21:04:17 2012 +0100
     1.3 @@ -108,14 +108,8 @@
     1.4  # include <semaphore.h>
     1.5  # include <fcntl.h>
     1.6  # include <string.h>
     1.7 -#ifdef _ALLBSD_SOURCE
     1.8  # include <sys/param.h>
     1.9  # include <sys/sysctl.h>
    1.10 -#else
    1.11 -# include <syscall.h>
    1.12 -# include <sys/sysinfo.h>
    1.13 -# include <gnu/libc-version.h>
    1.14 -#endif
    1.15  # include <sys/ipc.h>
    1.16  # include <sys/shm.h>
    1.17  #ifndef __APPLE__
    1.18 @@ -150,25 +144,10 @@
    1.19  // global variables
    1.20  julong os::Bsd::_physical_memory = 0;
    1.21  
    1.22 -#ifndef _ALLBSD_SOURCE
    1.23 -address   os::Bsd::_initial_thread_stack_bottom = NULL;
    1.24 -uintptr_t os::Bsd::_initial_thread_stack_size   = 0;
    1.25 -#endif
    1.26  
    1.27  int (*os::Bsd::_clock_gettime)(clockid_t, struct timespec *) = NULL;
    1.28 -#ifndef _ALLBSD_SOURCE
    1.29 -int (*os::Bsd::_pthread_getcpuclockid)(pthread_t, clockid_t *) = NULL;
    1.30 -Mutex* os::Bsd::_createThread_lock = NULL;
    1.31 -#endif
    1.32  pthread_t os::Bsd::_main_thread;
    1.33  int os::Bsd::_page_size = -1;
    1.34 -#ifndef _ALLBSD_SOURCE
    1.35 -bool os::Bsd::_is_floating_stack = false;
    1.36 -bool os::Bsd::_is_NPTL = false;
    1.37 -bool os::Bsd::_supports_fast_thread_cpu_time = false;
    1.38 -const char * os::Bsd::_glibc_version = NULL;
    1.39 -const char * os::Bsd::_libpthread_version = NULL;
    1.40 -#endif
    1.41  
    1.42  static jlong initial_time_count=0;
    1.43  
    1.44 @@ -176,7 +155,7 @@
    1.45  
    1.46  // For diagnostics to print a message once. see run_periodic_checks
    1.47  static sigset_t check_signal_done;
    1.48 -static bool check_signals = true;;
    1.49 +static bool check_signals = true;
    1.50  
    1.51  static pid_t _initial_pid = 0;
    1.52  
    1.53 @@ -198,16 +177,8 @@
    1.54  }
    1.55  
    1.56  julong os::Bsd::available_memory() {
    1.57 -#ifdef _ALLBSD_SOURCE
    1.58    // XXXBSD: this is just a stopgap implementation
    1.59    return physical_memory() >> 2;
    1.60 -#else
    1.61 -  // values in struct sysinfo are "unsigned long"
    1.62 -  struct sysinfo si;
    1.63 -  sysinfo(&si);
    1.64 -
    1.65 -  return (julong)si.freeram * si.mem_unit;
    1.66 -#endif
    1.67  }
    1.68  
    1.69  julong os::physical_memory() {
    1.70 @@ -255,22 +226,6 @@
    1.71  }
    1.72  
    1.73  
    1.74 -#ifndef _ALLBSD_SOURCE
    1.75 -#ifndef SYS_gettid
    1.76 -// i386: 224, ia64: 1105, amd64: 186, sparc 143
    1.77 -#ifdef __ia64__
    1.78 -#define SYS_gettid 1105
    1.79 -#elif __i386__
    1.80 -#define SYS_gettid 224
    1.81 -#elif __amd64__
    1.82 -#define SYS_gettid 186
    1.83 -#elif __sparc__
    1.84 -#define SYS_gettid 143
    1.85 -#else
    1.86 -#error define gettid for the arch
    1.87 -#endif
    1.88 -#endif
    1.89 -#endif
    1.90  
    1.91  // Cpu architecture string
    1.92  #if   defined(ZERO)
    1.93 @@ -302,36 +257,7 @@
    1.94  #define COMPILER_VARIANT "client"
    1.95  #endif
    1.96  
    1.97 -#ifndef _ALLBSD_SOURCE
    1.98 -// pid_t gettid()
    1.99 -//
   1.100 -// Returns the kernel thread id of the currently running thread. Kernel
   1.101 -// thread id is used to access /proc.
   1.102 -//
   1.103 -// (Note that getpid() on BsdThreads returns kernel thread id too; but
   1.104 -// on NPTL, it returns the same pid for all threads, as required by POSIX.)
   1.105 -//
   1.106 -pid_t os::Bsd::gettid() {
   1.107 -  int rslt = syscall(SYS_gettid);
   1.108 -  if (rslt == -1) {
   1.109 -     // old kernel, no NPTL support
   1.110 -     return getpid();
   1.111 -  } else {
   1.112 -     return (pid_t)rslt;
   1.113 -  }
   1.114 -}
   1.115 -
   1.116 -// Most versions of bsd have a bug where the number of processors are
   1.117 -// determined by looking at the /proc file system.  In a chroot environment,
   1.118 -// the system call returns 1.  This causes the VM to act as if it is
   1.119 -// a single processor and elide locking (see is_MP() call).
   1.120 -static bool unsafe_chroot_detected = false;
   1.121 -static const char *unstable_chroot_error = "/proc file system not found.\n"
   1.122 -                     "Java may be unstable running multithreaded in a chroot "
   1.123 -                     "environment on Bsd when /proc filesystem is not mounted.";
   1.124 -#endif
   1.125 -
   1.126 -#ifdef _ALLBSD_SOURCE
   1.127 +
   1.128  void os::Bsd::initialize_system_info() {
   1.129    int mib[2];
   1.130    size_t len;
   1.131 @@ -370,24 +296,6 @@
   1.132    }
   1.133  #endif
   1.134  }
   1.135 -#else
   1.136 -void os::Bsd::initialize_system_info() {
   1.137 -  set_processor_count(sysconf(_SC_NPROCESSORS_CONF));
   1.138 -  if (processor_count() == 1) {
   1.139 -    pid_t pid = os::Bsd::gettid();
   1.140 -    char fname[32];
   1.141 -    jio_snprintf(fname, sizeof(fname), "/proc/%d", pid);
   1.142 -    FILE *fp = fopen(fname, "r");
   1.143 -    if (fp == NULL) {
   1.144 -      unsafe_chroot_detected = true;
   1.145 -    } else {
   1.146 -      fclose(fp);
   1.147 -    }
   1.148 -  }
   1.149 -  _physical_memory = (julong)sysconf(_SC_PHYS_PAGES) * (julong)sysconf(_SC_PAGESIZE);
   1.150 -  assert(processor_count() > 0, "bsd error");
   1.151 -}
   1.152 -#endif
   1.153  
   1.154  #ifdef __APPLE__
   1.155  static const char *get_home() {
   1.156 @@ -744,171 +652,6 @@
   1.157    }
   1.158  }
   1.159  
   1.160 -#ifndef _ALLBSD_SOURCE
   1.161 -//////////////////////////////////////////////////////////////////////////////
   1.162 -// detecting pthread library
   1.163 -
   1.164 -void os::Bsd::libpthread_init() {
   1.165 -  // Save glibc and pthread version strings. Note that _CS_GNU_LIBC_VERSION
   1.166 -  // and _CS_GNU_LIBPTHREAD_VERSION are supported in glibc >= 2.3.2. Use a
   1.167 -  // generic name for earlier versions.
   1.168 -  // Define macros here so we can build HotSpot on old systems.
   1.169 -# ifndef _CS_GNU_LIBC_VERSION
   1.170 -# define _CS_GNU_LIBC_VERSION 2
   1.171 -# endif
   1.172 -# ifndef _CS_GNU_LIBPTHREAD_VERSION
   1.173 -# define _CS_GNU_LIBPTHREAD_VERSION 3
   1.174 -# endif
   1.175 -
   1.176 -  size_t n = confstr(_CS_GNU_LIBC_VERSION, NULL, 0);
   1.177 -  if (n > 0) {
   1.178 -     char *str = (char *)malloc(n);
   1.179 -     confstr(_CS_GNU_LIBC_VERSION, str, n);
   1.180 -     os::Bsd::set_glibc_version(str);
   1.181 -  } else {
   1.182 -     // _CS_GNU_LIBC_VERSION is not supported, try gnu_get_libc_version()
   1.183 -     static char _gnu_libc_version[32];
   1.184 -     jio_snprintf(_gnu_libc_version, sizeof(_gnu_libc_version),
   1.185 -              "glibc %s %s", gnu_get_libc_version(), gnu_get_libc_release());
   1.186 -     os::Bsd::set_glibc_version(_gnu_libc_version);
   1.187 -  }
   1.188 -
   1.189 -  n = confstr(_CS_GNU_LIBPTHREAD_VERSION, NULL, 0);
   1.190 -  if (n > 0) {
   1.191 -     char *str = (char *)malloc(n);
   1.192 -     confstr(_CS_GNU_LIBPTHREAD_VERSION, str, n);
   1.193 -     // Vanilla RH-9 (glibc 2.3.2) has a bug that confstr() always tells
   1.194 -     // us "NPTL-0.29" even we are running with BsdThreads. Check if this
   1.195 -     // is the case. BsdThreads has a hard limit on max number of threads.
   1.196 -     // So sysconf(_SC_THREAD_THREADS_MAX) will return a positive value.
   1.197 -     // On the other hand, NPTL does not have such a limit, sysconf()
   1.198 -     // will return -1 and errno is not changed. Check if it is really NPTL.
   1.199 -     if (strcmp(os::Bsd::glibc_version(), "glibc 2.3.2") == 0 &&
   1.200 -         strstr(str, "NPTL") &&
   1.201 -         sysconf(_SC_THREAD_THREADS_MAX) > 0) {
   1.202 -       free(str);
   1.203 -       os::Bsd::set_libpthread_version("bsdthreads");
   1.204 -     } else {
   1.205 -       os::Bsd::set_libpthread_version(str);
   1.206 -     }
   1.207 -  } else {
   1.208 -    // glibc before 2.3.2 only has BsdThreads.
   1.209 -    os::Bsd::set_libpthread_version("bsdthreads");
   1.210 -  }
   1.211 -
   1.212 -  if (strstr(libpthread_version(), "NPTL")) {
   1.213 -     os::Bsd::set_is_NPTL();
   1.214 -  } else {
   1.215 -     os::Bsd::set_is_BsdThreads();
   1.216 -  }
   1.217 -
   1.218 -  // BsdThreads have two flavors: floating-stack mode, which allows variable
   1.219 -  // stack size; and fixed-stack mode. NPTL is always floating-stack.
   1.220 -  if (os::Bsd::is_NPTL() || os::Bsd::supports_variable_stack_size()) {
   1.221 -     os::Bsd::set_is_floating_stack();
   1.222 -  }
   1.223 -}
   1.224 -
   1.225 -/////////////////////////////////////////////////////////////////////////////
   1.226 -// thread stack
   1.227 -
   1.228 -// Force Bsd kernel to expand current thread stack. If "bottom" is close
   1.229 -// to the stack guard, caller should block all signals.
   1.230 -//
   1.231 -// MAP_GROWSDOWN:
   1.232 -//   A special mmap() flag that is used to implement thread stacks. It tells
   1.233 -//   kernel that the memory region should extend downwards when needed. This
   1.234 -//   allows early versions of BsdThreads to only mmap the first few pages
   1.235 -//   when creating a new thread. Bsd kernel will automatically expand thread
   1.236 -//   stack as needed (on page faults).
   1.237 -//
   1.238 -//   However, because the memory region of a MAP_GROWSDOWN stack can grow on
   1.239 -//   demand, if a page fault happens outside an already mapped MAP_GROWSDOWN
   1.240 -//   region, it's hard to tell if the fault is due to a legitimate stack
   1.241 -//   access or because of reading/writing non-exist memory (e.g. buffer
   1.242 -//   overrun). As a rule, if the fault happens below current stack pointer,
   1.243 -//   Bsd kernel does not expand stack, instead a SIGSEGV is sent to the
   1.244 -//   application (see Bsd kernel fault.c).
   1.245 -//
   1.246 -//   This Bsd feature can cause SIGSEGV when VM bangs thread stack for
   1.247 -//   stack overflow detection.
   1.248 -//
   1.249 -//   Newer version of BsdThreads (since glibc-2.2, or, RH-7.x) and NPTL do
   1.250 -//   not use this flag. However, the stack of initial thread is not created
   1.251 -//   by pthread, it is still MAP_GROWSDOWN. Also it's possible (though
   1.252 -//   unlikely) that user code can create a thread with MAP_GROWSDOWN stack
   1.253 -//   and then attach the thread to JVM.
   1.254 -//
   1.255 -// To get around the problem and allow stack banging on Bsd, we need to
   1.256 -// manually expand thread stack after receiving the SIGSEGV.
   1.257 -//
   1.258 -// There are two ways to expand thread stack to address "bottom", we used
   1.259 -// both of them in JVM before 1.5:
   1.260 -//   1. adjust stack pointer first so that it is below "bottom", and then
   1.261 -//      touch "bottom"
   1.262 -//   2. mmap() the page in question
   1.263 -//
   1.264 -// Now alternate signal stack is gone, it's harder to use 2. For instance,
   1.265 -// if current sp is already near the lower end of page 101, and we need to
   1.266 -// call mmap() to map page 100, it is possible that part of the mmap() frame
   1.267 -// will be placed in page 100. When page 100 is mapped, it is zero-filled.
   1.268 -// That will destroy the mmap() frame and cause VM to crash.
   1.269 -//
   1.270 -// The following code works by adjusting sp first, then accessing the "bottom"
   1.271 -// page to force a page fault. Bsd kernel will then automatically expand the
   1.272 -// stack mapping.
   1.273 -//
   1.274 -// _expand_stack_to() assumes its frame size is less than page size, which
   1.275 -// should always be true if the function is not inlined.
   1.276 -
   1.277 -#if __GNUC__ < 3    // gcc 2.x does not support noinline attribute
   1.278 -#define NOINLINE
   1.279 -#else
   1.280 -#define NOINLINE __attribute__ ((noinline))
   1.281 -#endif
   1.282 -
   1.283 -static void _expand_stack_to(address bottom) NOINLINE;
   1.284 -
   1.285 -static void _expand_stack_to(address bottom) {
   1.286 -  address sp;
   1.287 -  size_t size;
   1.288 -  volatile char *p;
   1.289 -
   1.290 -  // Adjust bottom to point to the largest address within the same page, it
   1.291 -  // gives us a one-page buffer if alloca() allocates slightly more memory.
   1.292 -  bottom = (address)align_size_down((uintptr_t)bottom, os::Bsd::page_size());
   1.293 -  bottom += os::Bsd::page_size() - 1;
   1.294 -
   1.295 -  // sp might be slightly above current stack pointer; if that's the case, we
   1.296 -  // will alloca() a little more space than necessary, which is OK. Don't use
   1.297 -  // os::current_stack_pointer(), as its result can be slightly below current
   1.298 -  // stack pointer, causing us to not alloca enough to reach "bottom".
   1.299 -  sp = (address)&sp;
   1.300 -
   1.301 -  if (sp > bottom) {
   1.302 -    size = sp - bottom;
   1.303 -    p = (volatile char *)alloca(size);
   1.304 -    assert(p != NULL && p <= (volatile char *)bottom, "alloca problem?");
   1.305 -    p[0] = '\0';
   1.306 -  }
   1.307 -}
   1.308 -
   1.309 -bool os::Bsd::manually_expand_stack(JavaThread * t, address addr) {
   1.310 -  assert(t!=NULL, "just checking");
   1.311 -  assert(t->osthread()->expanding_stack(), "expand should be set");
   1.312 -  assert(t->stack_base() != NULL, "stack_base was not initialized");
   1.313 -
   1.314 -  if (addr <  t->stack_base() && addr >= t->stack_yellow_zone_base()) {
   1.315 -    sigset_t mask_all, old_sigset;
   1.316 -    sigfillset(&mask_all);
   1.317 -    pthread_sigmask(SIG_SETMASK, &mask_all, &old_sigset);
   1.318 -    _expand_stack_to(addr);
   1.319 -    pthread_sigmask(SIG_SETMASK, &old_sigset, NULL);
   1.320 -    return true;
   1.321 -  }
   1.322 -  return false;
   1.323 -}
   1.324 -#endif
   1.325  
   1.326  //////////////////////////////////////////////////////////////////////////////
   1.327  // create new thread
   1.328 @@ -917,43 +660,7 @@
   1.329  
   1.330  // check if it's safe to start a new thread
   1.331  static bool _thread_safety_check(Thread* thread) {
   1.332 -#ifdef _ALLBSD_SOURCE
   1.333 -    return true;
   1.334 -#else
   1.335 -  if (os::Bsd::is_BsdThreads() && !os::Bsd::is_floating_stack()) {
   1.336 -    // Fixed stack BsdThreads (SuSE Bsd/x86, and some versions of Redhat)
   1.337 -    //   Heap is mmap'ed at lower end of memory space. Thread stacks are
   1.338 -    //   allocated (MAP_FIXED) from high address space. Every thread stack
   1.339 -    //   occupies a fixed size slot (usually 2Mbytes, but user can change
   1.340 -    //   it to other values if they rebuild BsdThreads).
   1.341 -    //
   1.342 -    // Problem with MAP_FIXED is that mmap() can still succeed even part of
   1.343 -    // the memory region has already been mmap'ed. That means if we have too
   1.344 -    // many threads and/or very large heap, eventually thread stack will
   1.345 -    // collide with heap.
   1.346 -    //
   1.347 -    // Here we try to prevent heap/stack collision by comparing current
   1.348 -    // stack bottom with the highest address that has been mmap'ed by JVM
   1.349 -    // plus a safety margin for memory maps created by native code.
   1.350 -    //
   1.351 -    // This feature can be disabled by setting ThreadSafetyMargin to 0
   1.352 -    //
   1.353 -    if (ThreadSafetyMargin > 0) {
   1.354 -      address stack_bottom = os::current_stack_base() - os::current_stack_size();
   1.355 -
   1.356 -      // not safe if our stack extends below the safety margin
   1.357 -      return stack_bottom - ThreadSafetyMargin >= highest_vm_reserved_address();
   1.358 -    } else {
   1.359 -      return true;
   1.360 -    }
   1.361 -  } else {
   1.362 -    // Floating stack BsdThreads or NPTL:
   1.363 -    //   Unlike fixed stack BsdThreads, thread stacks are not MAP_FIXED. When
   1.364 -    //   there's not enough space left, pthread_create() will fail. If we come
   1.365 -    //   here, that means enough space has been reserved for stack.
   1.366 -    return true;
   1.367 -  }
   1.368 -#endif
   1.369 +  return true;
   1.370  }
   1.371  
   1.372  #ifdef __APPLE__
   1.373 @@ -991,7 +698,6 @@
   1.374      return NULL;
   1.375    }
   1.376  
   1.377 -#ifdef _ALLBSD_SOURCE
   1.378  #ifdef __APPLE__
   1.379    // thread_id is mach thread on macos
   1.380    osthread->set_thread_id(::mach_thread_self());
   1.381 @@ -999,17 +705,6 @@
   1.382    // thread_id is pthread_id on BSD
   1.383    osthread->set_thread_id(::pthread_self());
   1.384  #endif
   1.385 -#else
   1.386 -  // thread_id is kernel thread id (similar to Solaris LWP id)
   1.387 -  osthread->set_thread_id(os::Bsd::gettid());
   1.388 -
   1.389 -  if (UseNUMA) {
   1.390 -    int lgrp_id = os::numa_get_group_id();
   1.391 -    if (lgrp_id != -1) {
   1.392 -      thread->set_lgrp_id(lgrp_id);
   1.393 -    }
   1.394 -  }
   1.395 -#endif
   1.396    // initialize signal mask for this thread
   1.397    os::Bsd::hotspot_sigmask(thread);
   1.398  
   1.399 @@ -1099,23 +794,9 @@
   1.400      // let pthread_create() pick the default value.
   1.401    }
   1.402  
   1.403 -#ifndef _ALLBSD_SOURCE
   1.404 -  // glibc guard page
   1.405 -  pthread_attr_setguardsize(&attr, os::Bsd::default_guard_size(thr_type));
   1.406 -#endif
   1.407 -
   1.408    ThreadState state;
   1.409  
   1.410    {
   1.411 -
   1.412 -#ifndef _ALLBSD_SOURCE
   1.413 -    // Serialize thread creation if we are running with fixed stack BsdThreads
   1.414 -    bool lock = os::Bsd::is_BsdThreads() && !os::Bsd::is_floating_stack();
   1.415 -    if (lock) {
   1.416 -      os::Bsd::createThread_lock()->lock_without_safepoint_check();
   1.417 -    }
   1.418 -#endif
   1.419 -
   1.420      pthread_t tid;
   1.421      int ret = pthread_create(&tid, &attr, (void* (*)(void*)) java_start, thread);
   1.422  
   1.423 @@ -1128,9 +809,6 @@
   1.424        // Need to clean up stuff we've allocated so far
   1.425        thread->set_osthread(NULL);
   1.426        delete osthread;
   1.427 -#ifndef _ALLBSD_SOURCE
   1.428 -      if (lock) os::Bsd::createThread_lock()->unlock();
   1.429 -#endif
   1.430        return false;
   1.431      }
   1.432  
   1.433 @@ -1146,11 +824,6 @@
   1.434        }
   1.435      }
   1.436  
   1.437 -#ifndef _ALLBSD_SOURCE
   1.438 -    if (lock) {
   1.439 -      os::Bsd::createThread_lock()->unlock();
   1.440 -    }
   1.441 -#endif
   1.442    }
   1.443  
   1.444    // Aborted due to thread limit being reached
   1.445 @@ -1188,15 +861,11 @@
   1.446    }
   1.447  
   1.448    // Store pthread info into the OSThread
   1.449 -#ifdef _ALLBSD_SOURCE
   1.450  #ifdef __APPLE__
   1.451    osthread->set_thread_id(::mach_thread_self());
   1.452  #else
   1.453    osthread->set_thread_id(::pthread_self());
   1.454  #endif
   1.455 -#else
   1.456 -  osthread->set_thread_id(os::Bsd::gettid());
   1.457 -#endif
   1.458    osthread->set_pthread_id(::pthread_self());
   1.459  
   1.460    // initialize floating point control register
   1.461 @@ -1207,35 +876,6 @@
   1.462  
   1.463    thread->set_osthread(osthread);
   1.464  
   1.465 -#ifndef _ALLBSD_SOURCE
   1.466 -  if (UseNUMA) {
   1.467 -    int lgrp_id = os::numa_get_group_id();
   1.468 -    if (lgrp_id != -1) {
   1.469 -      thread->set_lgrp_id(lgrp_id);
   1.470 -    }
   1.471 -  }
   1.472 -
   1.473 -  if (os::Bsd::is_initial_thread()) {
   1.474 -    // If current thread is initial thread, its stack is mapped on demand,
   1.475 -    // see notes about MAP_GROWSDOWN. Here we try to force kernel to map
   1.476 -    // the entire stack region to avoid SEGV in stack banging.
   1.477 -    // It is also useful to get around the heap-stack-gap problem on SuSE
   1.478 -    // kernel (see 4821821 for details). We first expand stack to the top
   1.479 -    // of yellow zone, then enable stack yellow zone (order is significant,
   1.480 -    // enabling yellow zone first will crash JVM on SuSE Bsd), so there
   1.481 -    // is no gap between the last two virtual memory regions.
   1.482 -
   1.483 -    JavaThread *jt = (JavaThread *)thread;
   1.484 -    address addr = jt->stack_yellow_zone_base();
   1.485 -    assert(addr != NULL, "initialization problem?");
   1.486 -    assert(jt->stack_available(addr) > 0, "stack guard should not be enabled");
   1.487 -
   1.488 -    osthread->set_expanding_stack();
   1.489 -    os::Bsd::manually_expand_stack(jt, addr);
   1.490 -    osthread->clear_expanding_stack();
   1.491 -  }
   1.492 -#endif
   1.493 -
   1.494    // initialize signal mask for this thread
   1.495    // and save the caller's signal mask
   1.496    os::Bsd::hotspot_sigmask(thread);
   1.497 @@ -1290,247 +930,6 @@
   1.498    return ThreadLocalStorage::thread();
   1.499  }
   1.500  
   1.501 -//////////////////////////////////////////////////////////////////////////////
   1.502 -// initial thread
   1.503 -
   1.504 -#ifndef _ALLBSD_SOURCE
   1.505 -// Check if current thread is the initial thread, similar to Solaris thr_main.
   1.506 -bool os::Bsd::is_initial_thread(void) {
   1.507 -  char dummy;
   1.508 -  // If called before init complete, thread stack bottom will be null.
   1.509 -  // Can be called if fatal error occurs before initialization.
   1.510 -  if (initial_thread_stack_bottom() == NULL) return false;
   1.511 -  assert(initial_thread_stack_bottom() != NULL &&
   1.512 -         initial_thread_stack_size()   != 0,
   1.513 -         "os::init did not locate initial thread's stack region");
   1.514 -  if ((address)&dummy >= initial_thread_stack_bottom() &&
   1.515 -      (address)&dummy < initial_thread_stack_bottom() + initial_thread_stack_size())
   1.516 -       return true;
   1.517 -  else return false;
   1.518 -}
   1.519 -
   1.520 -// Find the virtual memory area that contains addr
   1.521 -static bool find_vma(address addr, address* vma_low, address* vma_high) {
   1.522 -  FILE *fp = fopen("/proc/self/maps", "r");
   1.523 -  if (fp) {
   1.524 -    address low, high;
   1.525 -    while (!feof(fp)) {
   1.526 -      if (fscanf(fp, "%p-%p", &low, &high) == 2) {
   1.527 -        if (low <= addr && addr < high) {
   1.528 -           if (vma_low)  *vma_low  = low;
   1.529 -           if (vma_high) *vma_high = high;
   1.530 -           fclose (fp);
   1.531 -           return true;
   1.532 -        }
   1.533 -      }
   1.534 -      for (;;) {
   1.535 -        int ch = fgetc(fp);
   1.536 -        if (ch == EOF || ch == (int)'\n') break;
   1.537 -      }
   1.538 -    }
   1.539 -    fclose(fp);
   1.540 -  }
   1.541 -  return false;
   1.542 -}
   1.543 -
   1.544 -// Locate initial thread stack. This special handling of initial thread stack
   1.545 -// is needed because pthread_getattr_np() on most (all?) Bsd distros returns
   1.546 -// bogus value for initial thread.
   1.547 -void os::Bsd::capture_initial_stack(size_t max_size) {
   1.548 -  // stack size is the easy part, get it from RLIMIT_STACK
   1.549 -  size_t stack_size;
   1.550 -  struct rlimit rlim;
   1.551 -  getrlimit(RLIMIT_STACK, &rlim);
   1.552 -  stack_size = rlim.rlim_cur;
   1.553 -
   1.554 -  // 6308388: a bug in ld.so will relocate its own .data section to the
   1.555 -  //   lower end of primordial stack; reduce ulimit -s value a little bit
   1.556 -  //   so we won't install guard page on ld.so's data section.
   1.557 -  stack_size -= 2 * page_size();
   1.558 -
   1.559 -  // 4441425: avoid crash with "unlimited" stack size on SuSE 7.1 or Redhat
   1.560 -  //   7.1, in both cases we will get 2G in return value.
   1.561 -  // 4466587: glibc 2.2.x compiled w/o "--enable-kernel=2.4.0" (RH 7.0,
   1.562 -  //   SuSE 7.2, Debian) can not handle alternate signal stack correctly
   1.563 -  //   for initial thread if its stack size exceeds 6M. Cap it at 2M,
   1.564 -  //   in case other parts in glibc still assumes 2M max stack size.
   1.565 -  // FIXME: alt signal stack is gone, maybe we can relax this constraint?
   1.566 -#ifndef IA64
   1.567 -  if (stack_size > 2 * K * K) stack_size = 2 * K * K;
   1.568 -#else
   1.569 -  // Problem still exists RH7.2 (IA64 anyway) but 2MB is a little small
   1.570 -  if (stack_size > 4 * K * K) stack_size = 4 * K * K;
   1.571 -#endif
   1.572 -
   1.573 -  // Try to figure out where the stack base (top) is. This is harder.
   1.574 -  //
   1.575 -  // When an application is started, glibc saves the initial stack pointer in
   1.576 -  // a global variable "__libc_stack_end", which is then used by system
   1.577 -  // libraries. __libc_stack_end should be pretty close to stack top. The
   1.578 -  // variable is available since the very early days. However, because it is
   1.579 -  // a private interface, it could disappear in the future.
   1.580 -  //
   1.581 -  // Bsd kernel saves start_stack information in /proc/<pid>/stat. Similar
   1.582 -  // to __libc_stack_end, it is very close to stack top, but isn't the real
   1.583 -  // stack top. Note that /proc may not exist if VM is running as a chroot
   1.584 -  // program, so reading /proc/<pid>/stat could fail. Also the contents of
   1.585 -  // /proc/<pid>/stat could change in the future (though unlikely).
   1.586 -  //
   1.587 -  // We try __libc_stack_end first. If that doesn't work, look for
   1.588 -  // /proc/<pid>/stat. If neither of them works, we use current stack pointer
   1.589 -  // as a hint, which should work well in most cases.
   1.590 -
   1.591 -  uintptr_t stack_start;
   1.592 -
   1.593 -  // try __libc_stack_end first
   1.594 -  uintptr_t *p = (uintptr_t *)dlsym(RTLD_DEFAULT, "__libc_stack_end");
   1.595 -  if (p && *p) {
   1.596 -    stack_start = *p;
   1.597 -  } else {
   1.598 -    // see if we can get the start_stack field from /proc/self/stat
   1.599 -    FILE *fp;
   1.600 -    int pid;
   1.601 -    char state;
   1.602 -    int ppid;
   1.603 -    int pgrp;
   1.604 -    int session;
   1.605 -    int nr;
   1.606 -    int tpgrp;
   1.607 -    unsigned long flags;
   1.608 -    unsigned long minflt;
   1.609 -    unsigned long cminflt;
   1.610 -    unsigned long majflt;
   1.611 -    unsigned long cmajflt;
   1.612 -    unsigned long utime;
   1.613 -    unsigned long stime;
   1.614 -    long cutime;
   1.615 -    long cstime;
   1.616 -    long prio;
   1.617 -    long nice;
   1.618 -    long junk;
   1.619 -    long it_real;
   1.620 -    uintptr_t start;
   1.621 -    uintptr_t vsize;
   1.622 -    intptr_t rss;
   1.623 -    uintptr_t rsslim;
   1.624 -    uintptr_t scodes;
   1.625 -    uintptr_t ecode;
   1.626 -    int i;
   1.627 -
   1.628 -    // Figure what the primordial thread stack base is. Code is inspired
   1.629 -    // by email from Hans Boehm. /proc/self/stat begins with current pid,
   1.630 -    // followed by command name surrounded by parentheses, state, etc.
   1.631 -    char stat[2048];
   1.632 -    int statlen;
   1.633 -
   1.634 -    fp = fopen("/proc/self/stat", "r");
   1.635 -    if (fp) {
   1.636 -      statlen = fread(stat, 1, 2047, fp);
   1.637 -      stat[statlen] = '\0';
   1.638 -      fclose(fp);
   1.639 -
   1.640 -      // Skip pid and the command string. Note that we could be dealing with
   1.641 -      // weird command names, e.g. user could decide to rename java launcher
   1.642 -      // to "java 1.4.2 :)", then the stat file would look like
   1.643 -      //                1234 (java 1.4.2 :)) R ... ...
   1.644 -      // We don't really need to know the command string, just find the last
   1.645 -      // occurrence of ")" and then start parsing from there. See bug 4726580.
   1.646 -      char * s = strrchr(stat, ')');
   1.647 -
   1.648 -      i = 0;
   1.649 -      if (s) {
   1.650 -        // Skip blank chars
   1.651 -        do s++; while (isspace(*s));
   1.652 -
   1.653 -#define _UFM UINTX_FORMAT
   1.654 -#define _DFM INTX_FORMAT
   1.655 -
   1.656 -        /*                                     1   1   1   1   1   1   1   1   1   1   2   2    2    2    2    2    2    2    2 */
   1.657 -        /*              3  4  5  6  7  8   9   0   1   2   3   4   5   6   7   8   9   0   1    2    3    4    5    6    7    8 */
   1.658 -        i = sscanf(s, "%c %d %d %d %d %d %lu %lu %lu %lu %lu %lu %lu %ld %ld %ld %ld %ld %ld " _UFM _UFM _DFM _UFM _UFM _UFM _UFM,
   1.659 -             &state,          /* 3  %c  */
   1.660 -             &ppid,           /* 4  %d  */
   1.661 -             &pgrp,           /* 5  %d  */
   1.662 -             &session,        /* 6  %d  */
   1.663 -             &nr,             /* 7  %d  */
   1.664 -             &tpgrp,          /* 8  %d  */
   1.665 -             &flags,          /* 9  %lu  */
   1.666 -             &minflt,         /* 10 %lu  */
   1.667 -             &cminflt,        /* 11 %lu  */
   1.668 -             &majflt,         /* 12 %lu  */
   1.669 -             &cmajflt,        /* 13 %lu  */
   1.670 -             &utime,          /* 14 %lu  */
   1.671 -             &stime,          /* 15 %lu  */
   1.672 -             &cutime,         /* 16 %ld  */
   1.673 -             &cstime,         /* 17 %ld  */
   1.674 -             &prio,           /* 18 %ld  */
   1.675 -             &nice,           /* 19 %ld  */
   1.676 -             &junk,           /* 20 %ld  */
   1.677 -             &it_real,        /* 21 %ld  */
   1.678 -             &start,          /* 22 UINTX_FORMAT */
   1.679 -             &vsize,          /* 23 UINTX_FORMAT */
   1.680 -             &rss,            /* 24 INTX_FORMAT  */
   1.681 -             &rsslim,         /* 25 UINTX_FORMAT */
   1.682 -             &scodes,         /* 26 UINTX_FORMAT */
   1.683 -             &ecode,          /* 27 UINTX_FORMAT */
   1.684 -             &stack_start);   /* 28 UINTX_FORMAT */
   1.685 -      }
   1.686 -
   1.687 -#undef _UFM
   1.688 -#undef _DFM
   1.689 -
   1.690 -      if (i != 28 - 2) {
   1.691 -         assert(false, "Bad conversion from /proc/self/stat");
   1.692 -         // product mode - assume we are the initial thread, good luck in the
   1.693 -         // embedded case.
   1.694 -         warning("Can't detect initial thread stack location - bad conversion");
   1.695 -         stack_start = (uintptr_t) &rlim;
   1.696 -      }
   1.697 -    } else {
   1.698 -      // For some reason we can't open /proc/self/stat (for example, running on
   1.699 -      // FreeBSD with a Bsd emulator, or inside chroot), this should work for
   1.700 -      // most cases, so don't abort:
   1.701 -      warning("Can't detect initial thread stack location - no /proc/self/stat");
   1.702 -      stack_start = (uintptr_t) &rlim;
   1.703 -    }
   1.704 -  }
   1.705 -
   1.706 -  // Now we have a pointer (stack_start) very close to the stack top, the
   1.707 -  // next thing to do is to figure out the exact location of stack top. We
   1.708 -  // can find out the virtual memory area that contains stack_start by
   1.709 -  // reading /proc/self/maps, it should be the last vma in /proc/self/maps,
   1.710 -  // and its upper limit is the real stack top. (again, this would fail if
   1.711 -  // running inside chroot, because /proc may not exist.)
   1.712 -
   1.713 -  uintptr_t stack_top;
   1.714 -  address low, high;
   1.715 -  if (find_vma((address)stack_start, &low, &high)) {
   1.716 -    // success, "high" is the true stack top. (ignore "low", because initial
   1.717 -    // thread stack grows on demand, its real bottom is high - RLIMIT_STACK.)
   1.718 -    stack_top = (uintptr_t)high;
   1.719 -  } else {
   1.720 -    // failed, likely because /proc/self/maps does not exist
   1.721 -    warning("Can't detect initial thread stack location - find_vma failed");
   1.722 -    // best effort: stack_start is normally within a few pages below the real
   1.723 -    // stack top, use it as stack top, and reduce stack size so we won't put
   1.724 -    // guard page outside stack.
   1.725 -    stack_top = stack_start;
   1.726 -    stack_size -= 16 * page_size();
   1.727 -  }
   1.728 -
   1.729 -  // stack_top could be partially down the page so align it
   1.730 -  stack_top = align_size_up(stack_top, page_size());
   1.731 -
   1.732 -  if (max_size && stack_size > max_size) {
   1.733 -     _initial_thread_stack_size = max_size;
   1.734 -  } else {
   1.735 -     _initial_thread_stack_size = stack_size;
   1.736 -  }
   1.737 -
   1.738 -  _initial_thread_stack_size = align_size_down(_initial_thread_stack_size, page_size());
   1.739 -  _initial_thread_stack_bottom = (address)stack_top - _initial_thread_stack_size;
   1.740 -}
   1.741 -#endif
   1.742  
   1.743  ////////////////////////////////////////////////////////////////////////////////
   1.744  // time support
   1.745 @@ -1576,7 +975,7 @@
   1.746  void os::Bsd::clock_init() {
   1.747          // XXXDARWIN: Investigate replacement monotonic clock
   1.748  }
   1.749 -#elif defined(_ALLBSD_SOURCE)
   1.750 +#else
   1.751  void os::Bsd::clock_init() {
   1.752    struct timespec res;
   1.753    struct timespec tp;
   1.754 @@ -1586,86 +985,8 @@
   1.755      _clock_gettime = ::clock_gettime;
   1.756    }
   1.757  }
   1.758 -#else
   1.759 -void os::Bsd::clock_init() {
   1.760 -  // we do dlopen's in this particular order due to bug in bsd
   1.761 -  // dynamical loader (see 6348968) leading to crash on exit
   1.762 -  void* handle = dlopen("librt.so.1", RTLD_LAZY);
   1.763 -  if (handle == NULL) {
   1.764 -    handle = dlopen("librt.so", RTLD_LAZY);
   1.765 -  }
   1.766 -
   1.767 -  if (handle) {
   1.768 -    int (*clock_getres_func)(clockid_t, struct timespec*) =
   1.769 -           (int(*)(clockid_t, struct timespec*))dlsym(handle, "clock_getres");
   1.770 -    int (*clock_gettime_func)(clockid_t, struct timespec*) =
   1.771 -           (int(*)(clockid_t, struct timespec*))dlsym(handle, "clock_gettime");
   1.772 -    if (clock_getres_func && clock_gettime_func) {
   1.773 -      // See if monotonic clock is supported by the kernel. Note that some
   1.774 -      // early implementations simply return kernel jiffies (updated every
   1.775 -      // 1/100 or 1/1000 second). It would be bad to use such a low res clock
   1.776 -      // for nano time (though the monotonic property is still nice to have).
   1.777 -      // It's fixed in newer kernels, however clock_getres() still returns
   1.778 -      // 1/HZ. We check if clock_getres() works, but will ignore its reported
   1.779 -      // resolution for now. Hopefully as people move to new kernels, this
   1.780 -      // won't be a problem.
   1.781 -      struct timespec res;
   1.782 -      struct timespec tp;
   1.783 -      if (clock_getres_func (CLOCK_MONOTONIC, &res) == 0 &&
   1.784 -          clock_gettime_func(CLOCK_MONOTONIC, &tp)  == 0) {
   1.785 -        // yes, monotonic clock is supported
   1.786 -        _clock_gettime = clock_gettime_func;
   1.787 -      } else {
   1.788 -        // close librt if there is no monotonic clock
   1.789 -        dlclose(handle);
   1.790 -      }
   1.791 -    }
   1.792 -  }
   1.793 -}
   1.794  #endif
   1.795  
   1.796 -#ifndef _ALLBSD_SOURCE
   1.797 -#ifndef SYS_clock_getres
   1.798 -
   1.799 -#if defined(IA32) || defined(AMD64)
   1.800 -#define SYS_clock_getres IA32_ONLY(266)  AMD64_ONLY(229)
   1.801 -#define sys_clock_getres(x,y)  ::syscall(SYS_clock_getres, x, y)
   1.802 -#else
   1.803 -#warning "SYS_clock_getres not defined for this platform, disabling fast_thread_cpu_time"
   1.804 -#define sys_clock_getres(x,y)  -1
   1.805 -#endif
   1.806 -
   1.807 -#else
   1.808 -#define sys_clock_getres(x,y)  ::syscall(SYS_clock_getres, x, y)
   1.809 -#endif
   1.810 -
   1.811 -void os::Bsd::fast_thread_clock_init() {
   1.812 -  if (!UseBsdPosixThreadCPUClocks) {
   1.813 -    return;
   1.814 -  }
   1.815 -  clockid_t clockid;
   1.816 -  struct timespec tp;
   1.817 -  int (*pthread_getcpuclockid_func)(pthread_t, clockid_t *) =
   1.818 -      (int(*)(pthread_t, clockid_t *)) dlsym(RTLD_DEFAULT, "pthread_getcpuclockid");
   1.819 -
   1.820 -  // Switch to using fast clocks for thread cpu time if
   1.821 -  // the sys_clock_getres() returns 0 error code.
   1.822 -  // Note, that some kernels may support the current thread
   1.823 -  // clock (CLOCK_THREAD_CPUTIME_ID) but not the clocks
   1.824 -  // returned by the pthread_getcpuclockid().
   1.825 -  // If the fast Posix clocks are supported then the sys_clock_getres()
   1.826 -  // must return at least tp.tv_sec == 0 which means a resolution
   1.827 -  // better than 1 sec. This is extra check for reliability.
   1.828 -
   1.829 -  if(pthread_getcpuclockid_func &&
   1.830 -     pthread_getcpuclockid_func(_main_thread, &clockid) == 0 &&
   1.831 -     sys_clock_getres(clockid, &tp) == 0 && tp.tv_sec == 0) {
   1.832 -
   1.833 -    _supports_fast_thread_cpu_time = true;
   1.834 -    _pthread_getcpuclockid = pthread_getcpuclockid_func;
   1.835 -  }
   1.836 -}
   1.837 -#endif
   1.838  
   1.839  jlong os::javaTimeNanos() {
   1.840    if (Bsd::supports_monotonic_clock()) {
   1.841 @@ -1978,7 +1299,6 @@
   1.842    return false;
   1.843  }
   1.844  
   1.845 -#ifdef _ALLBSD_SOURCE
   1.846  // ported from solaris version
   1.847  bool os::dll_address_to_library_name(address addr, char* buf,
   1.848                                       int buflen, int* offset) {
   1.849 @@ -1994,86 +1314,10 @@
   1.850       return false;
   1.851    }
   1.852  }
   1.853 -#else
   1.854 -struct _address_to_library_name {
   1.855 -  address addr;          // input : memory address
   1.856 -  size_t  buflen;        //         size of fname
   1.857 -  char*   fname;         // output: library name
   1.858 -  address base;          //         library base addr
   1.859 -};
   1.860 -
   1.861 -static int address_to_library_name_callback(struct dl_phdr_info *info,
   1.862 -                                            size_t size, void *data) {
   1.863 -  int i;
   1.864 -  bool found = false;
   1.865 -  address libbase = NULL;
   1.866 -  struct _address_to_library_name * d = (struct _address_to_library_name *)data;
   1.867 -
   1.868 -  // iterate through all loadable segments
   1.869 -  for (i = 0; i < info->dlpi_phnum; i++) {
   1.870 -    address segbase = (address)(info->dlpi_addr + info->dlpi_phdr[i].p_vaddr);
   1.871 -    if (info->dlpi_phdr[i].p_type == PT_LOAD) {
   1.872 -      // base address of a library is the lowest address of its loaded
   1.873 -      // segments.
   1.874 -      if (libbase == NULL || libbase > segbase) {
   1.875 -        libbase = segbase;
   1.876 -      }
   1.877 -      // see if 'addr' is within current segment
   1.878 -      if (segbase <= d->addr &&
   1.879 -          d->addr < segbase + info->dlpi_phdr[i].p_memsz) {
   1.880 -        found = true;
   1.881 -      }
   1.882 -    }
   1.883 -  }
   1.884 -
   1.885 -  // dlpi_name is NULL or empty if the ELF file is executable, return 0
   1.886 -  // so dll_address_to_library_name() can fall through to use dladdr() which
   1.887 -  // can figure out executable name from argv[0].
   1.888 -  if (found && info->dlpi_name && info->dlpi_name[0]) {
   1.889 -    d->base = libbase;
   1.890 -    if (d->fname) {
   1.891 -      jio_snprintf(d->fname, d->buflen, "%s", info->dlpi_name);
   1.892 -    }
   1.893 -    return 1;
   1.894 -  }
   1.895 -  return 0;
   1.896 -}
   1.897 -
   1.898 -bool os::dll_address_to_library_name(address addr, char* buf,
   1.899 -                                     int buflen, int* offset) {
   1.900 -  Dl_info dlinfo;
   1.901 -  struct _address_to_library_name data;
   1.902 -
   1.903 -  // There is a bug in old glibc dladdr() implementation that it could resolve
   1.904 -  // to wrong library name if the .so file has a base address != NULL. Here
   1.905 -  // we iterate through the program headers of all loaded libraries to find
   1.906 -  // out which library 'addr' really belongs to. This workaround can be
   1.907 -  // removed once the minimum requirement for glibc is moved to 2.3.x.
   1.908 -  data.addr = addr;
   1.909 -  data.fname = buf;
   1.910 -  data.buflen = buflen;
   1.911 -  data.base = NULL;
   1.912 -  int rslt = dl_iterate_phdr(address_to_library_name_callback, (void *)&data);
   1.913 -
   1.914 -  if (rslt) {
   1.915 -     // buf already contains library name
   1.916 -     if (offset) *offset = addr - data.base;
   1.917 -     return true;
   1.918 -  } else if (dladdr((void*)addr, &dlinfo)){
   1.919 -     if (buf) jio_snprintf(buf, buflen, "%s", dlinfo.dli_fname);
   1.920 -     if (offset) *offset = addr - (address)dlinfo.dli_fbase;
   1.921 -     return true;
   1.922 -  } else {
   1.923 -     if (buf) buf[0] = '\0';
   1.924 -     if (offset) *offset = -1;
   1.925 -     return false;
   1.926 -  }
   1.927 -}
   1.928 -#endif
   1.929 -
   1.930 -  // Loads .dll/.so and
   1.931 -  // in case of error it checks if .dll/.so was built for the
   1.932 -  // same architecture as Hotspot is running on
   1.933 +
   1.934 +// Loads .dll/.so and
   1.935 +// in case of error it checks if .dll/.so was built for the
   1.936 +// same architecture as Hotspot is running on
   1.937  
   1.938  #ifdef __APPLE__
   1.939  void * os::dll_load(const char *filename, char *ebuf, int ebuflen) {
   1.940 @@ -2292,7 +1536,6 @@
   1.941  
   1.942  void os::print_dll_info(outputStream *st) {
   1.943     st->print_cr("Dynamic libraries:");
   1.944 -#ifdef _ALLBSD_SOURCE
   1.945  #ifdef RTLD_DI_LINKMAP
   1.946      Dl_info dli;
   1.947      void *handle;
   1.948 @@ -2336,16 +1579,6 @@
   1.949  #else
   1.950     st->print_cr("Error: Cannot print dynamic libraries.");
   1.951  #endif
   1.952 -#else
   1.953 -   char fname[32];
   1.954 -   pid_t pid = os::Bsd::gettid();
   1.955 -
   1.956 -   jio_snprintf(fname, sizeof(fname), "/proc/%d/maps", pid);
   1.957 -
   1.958 -   if (!_print_ascii_file(fname, st)) {
   1.959 -     st->print("Can not get library information for pid = %d\n", pid);
   1.960 -   }
   1.961 -#endif
   1.962  }
   1.963  
   1.964  void os::print_os_info_brief(outputStream* st) {
   1.965 @@ -2374,22 +1607,10 @@
   1.966    st->print("Memory:");
   1.967    st->print(" %dk page", os::vm_page_size()>>10);
   1.968  
   1.969 -#ifndef _ALLBSD_SOURCE
   1.970 -  // values in struct sysinfo are "unsigned long"
   1.971 -  struct sysinfo si;
   1.972 -  sysinfo(&si);
   1.973 -#endif
   1.974 -
   1.975    st->print(", physical " UINT64_FORMAT "k",
   1.976              os::physical_memory() >> 10);
   1.977    st->print("(" UINT64_FORMAT "k free)",
   1.978              os::available_memory() >> 10);
   1.979 -#ifndef _ALLBSD_SOURCE
   1.980 -  st->print(", swap " UINT64_FORMAT "k",
   1.981 -            ((jlong)si.totalswap * si.mem_unit) >> 10);
   1.982 -  st->print("(" UINT64_FORMAT "k free)",
   1.983 -            ((jlong)si.freeswap * si.mem_unit) >> 10);
   1.984 -#endif
   1.985    st->cr();
   1.986  
   1.987    // meminfo
   1.988 @@ -2786,42 +2007,13 @@
   1.989  #endif
   1.990  }
   1.991  
   1.992 -#ifndef _ALLBSD_SOURCE
   1.993 -// Define MAP_HUGETLB here so we can build HotSpot on old systems.
   1.994 -#ifndef MAP_HUGETLB
   1.995 -#define MAP_HUGETLB 0x40000
   1.996 -#endif
   1.997 -
   1.998 -// Define MADV_HUGEPAGE here so we can build HotSpot on old systems.
   1.999 -#ifndef MADV_HUGEPAGE
  1.1000 -#define MADV_HUGEPAGE 14
  1.1001 -#endif
  1.1002 -#endif
  1.1003  
  1.1004  bool os::pd_commit_memory(char* addr, size_t size, size_t alignment_hint,
  1.1005                         bool exec) {
  1.1006 -#ifndef _ALLBSD_SOURCE
  1.1007 -  if (UseHugeTLBFS && alignment_hint > (size_t)vm_page_size()) {
  1.1008 -    int prot = exec ? PROT_READ|PROT_WRITE|PROT_EXEC : PROT_READ|PROT_WRITE;
  1.1009 -    uintptr_t res =
  1.1010 -      (uintptr_t) ::mmap(addr, size, prot,
  1.1011 -                         MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS|MAP_HUGETLB,
  1.1012 -                         -1, 0);
  1.1013 -    return res != (uintptr_t) MAP_FAILED;
  1.1014 -  }
  1.1015 -#endif
  1.1016 -
  1.1017    return commit_memory(addr, size, exec);
  1.1018  }
  1.1019  
  1.1020  void os::pd_realign_memory(char *addr, size_t bytes, size_t alignment_hint) {
  1.1021 -#ifndef _ALLBSD_SOURCE
  1.1022 -  if (UseHugeTLBFS && alignment_hint > (size_t)vm_page_size()) {
  1.1023 -    // We don't check the return value: madvise(MADV_HUGEPAGE) may not
  1.1024 -    // be supported or the memory may already be backed by huge pages.
  1.1025 -    ::madvise(addr, bytes, MADV_HUGEPAGE);
  1.1026 -  }
  1.1027 -#endif
  1.1028  }
  1.1029  
  1.1030  void os::pd_free_memory(char *addr, size_t bytes, size_t alignment_hint) {
  1.1031 @@ -2860,111 +2052,6 @@
  1.1032    return end;
  1.1033  }
  1.1034  
  1.1035 -#ifndef _ALLBSD_SOURCE
  1.1036 -// Something to do with the numa-aware allocator needs these symbols
  1.1037 -extern "C" JNIEXPORT void numa_warn(int number, char *where, ...) { }
  1.1038 -extern "C" JNIEXPORT void numa_error(char *where) { }
  1.1039 -extern "C" JNIEXPORT int fork1() { return fork(); }
  1.1040 -
  1.1041 -
  1.1042 -// If we are running with libnuma version > 2, then we should
  1.1043 -// be trying to use symbols with versions 1.1
  1.1044 -// If we are running with earlier version, which did not have symbol versions,
  1.1045 -// we should use the base version.
  1.1046 -void* os::Bsd::libnuma_dlsym(void* handle, const char *name) {
  1.1047 -  void *f = dlvsym(handle, name, "libnuma_1.1");
  1.1048 -  if (f == NULL) {
  1.1049 -    f = dlsym(handle, name);
  1.1050 -  }
  1.1051 -  return f;
  1.1052 -}
  1.1053 -
  1.1054 -bool os::Bsd::libnuma_init() {
  1.1055 -  // sched_getcpu() should be in libc.
  1.1056 -  set_sched_getcpu(CAST_TO_FN_PTR(sched_getcpu_func_t,
  1.1057 -                                  dlsym(RTLD_DEFAULT, "sched_getcpu")));
  1.1058 -
  1.1059 -  if (sched_getcpu() != -1) { // Does it work?
  1.1060 -    void *handle = dlopen("libnuma.so.1", RTLD_LAZY);
  1.1061 -    if (handle != NULL) {
  1.1062 -      set_numa_node_to_cpus(CAST_TO_FN_PTR(numa_node_to_cpus_func_t,
  1.1063 -                                           libnuma_dlsym(handle, "numa_node_to_cpus")));
  1.1064 -      set_numa_max_node(CAST_TO_FN_PTR(numa_max_node_func_t,
  1.1065 -                                       libnuma_dlsym(handle, "numa_max_node")));
  1.1066 -      set_numa_available(CAST_TO_FN_PTR(numa_available_func_t,
  1.1067 -                                        libnuma_dlsym(handle, "numa_available")));
  1.1068 -      set_numa_tonode_memory(CAST_TO_FN_PTR(numa_tonode_memory_func_t,
  1.1069 -                                            libnuma_dlsym(handle, "numa_tonode_memory")));
  1.1070 -      set_numa_interleave_memory(CAST_TO_FN_PTR(numa_interleave_memory_func_t,
  1.1071 -                                            libnuma_dlsym(handle, "numa_interleave_memory")));
  1.1072 -
  1.1073 -
  1.1074 -      if (numa_available() != -1) {
  1.1075 -        set_numa_all_nodes((unsigned long*)libnuma_dlsym(handle, "numa_all_nodes"));
  1.1076 -        // Create a cpu -> node mapping
  1.1077 -        _cpu_to_node = new (ResourceObj::C_HEAP) GrowableArray<int>(0, true);
  1.1078 -        rebuild_cpu_to_node_map();
  1.1079 -        return true;
  1.1080 -      }
  1.1081 -    }
  1.1082 -  }
  1.1083 -  return false;
  1.1084 -}
  1.1085 -
  1.1086 -// rebuild_cpu_to_node_map() constructs a table mapping cpud id to node id.
  1.1087 -// The table is later used in get_node_by_cpu().
  1.1088 -void os::Bsd::rebuild_cpu_to_node_map() {
  1.1089 -  const size_t NCPUS = 32768; // Since the buffer size computation is very obscure
  1.1090 -                              // in libnuma (possible values are starting from 16,
  1.1091 -                              // and continuing up with every other power of 2, but less
  1.1092 -                              // than the maximum number of CPUs supported by kernel), and
  1.1093 -                              // is a subject to change (in libnuma version 2 the requirements
  1.1094 -                              // are more reasonable) we'll just hardcode the number they use
  1.1095 -                              // in the library.
  1.1096 -  const size_t BitsPerCLong = sizeof(long) * CHAR_BIT;
  1.1097 -
  1.1098 -  size_t cpu_num = os::active_processor_count();
  1.1099 -  size_t cpu_map_size = NCPUS / BitsPerCLong;
  1.1100 -  size_t cpu_map_valid_size =
  1.1101 -    MIN2((cpu_num + BitsPerCLong - 1) / BitsPerCLong, cpu_map_size);
  1.1102 -
  1.1103 -  cpu_to_node()->clear();
  1.1104 -  cpu_to_node()->at_grow(cpu_num - 1);
  1.1105 -  size_t node_num = numa_get_groups_num();
  1.1106 -
  1.1107 -  unsigned long *cpu_map = NEW_C_HEAP_ARRAY(unsigned long, cpu_map_size);
  1.1108 -  for (size_t i = 0; i < node_num; i++) {
  1.1109 -    if (numa_node_to_cpus(i, cpu_map, cpu_map_size * sizeof(unsigned long)) != -1) {
  1.1110 -      for (size_t j = 0; j < cpu_map_valid_size; j++) {
  1.1111 -        if (cpu_map[j] != 0) {
  1.1112 -          for (size_t k = 0; k < BitsPerCLong; k++) {
  1.1113 -            if (cpu_map[j] & (1UL << k)) {
  1.1114 -              cpu_to_node()->at_put(j * BitsPerCLong + k, i);
  1.1115 -            }
  1.1116 -          }
  1.1117 -        }
  1.1118 -      }
  1.1119 -    }
  1.1120 -  }
  1.1121 -  FREE_C_HEAP_ARRAY(unsigned long, cpu_map);
  1.1122 -}
  1.1123 -
  1.1124 -int os::Bsd::get_node_by_cpu(int cpu_id) {
  1.1125 -  if (cpu_to_node() != NULL && cpu_id >= 0 && cpu_id < cpu_to_node()->length()) {
  1.1126 -    return cpu_to_node()->at(cpu_id);
  1.1127 -  }
  1.1128 -  return -1;
  1.1129 -}
  1.1130 -
  1.1131 -GrowableArray<int>* os::Bsd::_cpu_to_node;
  1.1132 -os::Bsd::sched_getcpu_func_t os::Bsd::_sched_getcpu;
  1.1133 -os::Bsd::numa_node_to_cpus_func_t os::Bsd::_numa_node_to_cpus;
  1.1134 -os::Bsd::numa_max_node_func_t os::Bsd::_numa_max_node;
  1.1135 -os::Bsd::numa_available_func_t os::Bsd::_numa_available;
  1.1136 -os::Bsd::numa_tonode_memory_func_t os::Bsd::_numa_tonode_memory;
  1.1137 -os::Bsd::numa_interleave_memory_func_t os::Bsd::_numa_interleave_memory;
  1.1138 -unsigned long* os::Bsd::_numa_all_nodes;
  1.1139 -#endif
  1.1140  
  1.1141  bool os::pd_uncommit_memory(char* addr, size_t size) {
  1.1142  #ifdef __OpenBSD__
  1.1143 @@ -3084,42 +2171,7 @@
  1.1144  }
  1.1145  
  1.1146  bool os::Bsd::hugetlbfs_sanity_check(bool warn, size_t page_size) {
  1.1147 -  bool result = false;
  1.1148 -#ifndef _ALLBSD_SOURCE
  1.1149 -  void *p = mmap (NULL, page_size, PROT_READ|PROT_WRITE,
  1.1150 -                  MAP_ANONYMOUS|MAP_PRIVATE|MAP_HUGETLB,
  1.1151 -                  -1, 0);
  1.1152 -
  1.1153 -  if (p != (void *) -1) {
  1.1154 -    // We don't know if this really is a huge page or not.
  1.1155 -    FILE *fp = fopen("/proc/self/maps", "r");
  1.1156 -    if (fp) {
  1.1157 -      while (!feof(fp)) {
  1.1158 -        char chars[257];
  1.1159 -        long x = 0;
  1.1160 -        if (fgets(chars, sizeof(chars), fp)) {
  1.1161 -          if (sscanf(chars, "%lx-%*x", &x) == 1
  1.1162 -              && x == (long)p) {
  1.1163 -            if (strstr (chars, "hugepage")) {
  1.1164 -              result = true;
  1.1165 -              break;
  1.1166 -            }
  1.1167 -          }
  1.1168 -        }
  1.1169 -      }
  1.1170 -      fclose(fp);
  1.1171 -    }
  1.1172 -    munmap (p, page_size);
  1.1173 -    if (result)
  1.1174 -      return true;
  1.1175 -  }
  1.1176 -
  1.1177 -  if (warn) {
  1.1178 -    warning("HugeTLBFS is not supported by the operating system.");
  1.1179 -  }
  1.1180 -#endif
  1.1181 -
  1.1182 -  return result;
  1.1183 +  return false;
  1.1184  }
  1.1185  
  1.1186  /*
  1.1187 @@ -3164,92 +2216,8 @@
  1.1188  static size_t _large_page_size = 0;
  1.1189  
  1.1190  void os::large_page_init() {
  1.1191 -#ifndef _ALLBSD_SOURCE
  1.1192 -  if (!UseLargePages) {
  1.1193 -    UseHugeTLBFS = false;
  1.1194 -    UseSHM = false;
  1.1195 -    return;
  1.1196 -  }
  1.1197 -
  1.1198 -  if (FLAG_IS_DEFAULT(UseHugeTLBFS) && FLAG_IS_DEFAULT(UseSHM)) {
  1.1199 -    // If UseLargePages is specified on the command line try both methods,
  1.1200 -    // if it's default, then try only HugeTLBFS.
  1.1201 -    if (FLAG_IS_DEFAULT(UseLargePages)) {
  1.1202 -      UseHugeTLBFS = true;
  1.1203 -    } else {
  1.1204 -      UseHugeTLBFS = UseSHM = true;
  1.1205 -    }
  1.1206 -  }
  1.1207 -
  1.1208 -  if (LargePageSizeInBytes) {
  1.1209 -    _large_page_size = LargePageSizeInBytes;
  1.1210 -  } else {
  1.1211 -    // large_page_size on Bsd is used to round up heap size. x86 uses either
  1.1212 -    // 2M or 4M page, depending on whether PAE (Physical Address Extensions)
  1.1213 -    // mode is enabled. AMD64/EM64T uses 2M page in 64bit mode. IA64 can use
  1.1214 -    // page as large as 256M.
  1.1215 -    //
  1.1216 -    // Here we try to figure out page size by parsing /proc/meminfo and looking
  1.1217 -    // for a line with the following format:
  1.1218 -    //    Hugepagesize:     2048 kB
  1.1219 -    //
  1.1220 -    // If we can't determine the value (e.g. /proc is not mounted, or the text
  1.1221 -    // format has been changed), we'll use the largest page size supported by
  1.1222 -    // the processor.
  1.1223 -
  1.1224 -#ifndef ZERO
  1.1225 -    _large_page_size = IA32_ONLY(4 * M) AMD64_ONLY(2 * M) IA64_ONLY(256 * M) SPARC_ONLY(4 * M)
  1.1226 -                       ARM_ONLY(2 * M) PPC_ONLY(4 * M);
  1.1227 -#endif // ZERO
  1.1228 -
  1.1229 -    FILE *fp = fopen("/proc/meminfo", "r");
  1.1230 -    if (fp) {
  1.1231 -      while (!feof(fp)) {
  1.1232 -        int x = 0;
  1.1233 -        char buf[16];
  1.1234 -        if (fscanf(fp, "Hugepagesize: %d", &x) == 1) {
  1.1235 -          if (x && fgets(buf, sizeof(buf), fp) && strcmp(buf, " kB\n") == 0) {
  1.1236 -            _large_page_size = x * K;
  1.1237 -            break;
  1.1238 -          }
  1.1239 -        } else {
  1.1240 -          // skip to next line
  1.1241 -          for (;;) {
  1.1242 -            int ch = fgetc(fp);
  1.1243 -            if (ch == EOF || ch == (int)'\n') break;
  1.1244 -          }
  1.1245 -        }
  1.1246 -      }
  1.1247 -      fclose(fp);
  1.1248 -    }
  1.1249 -  }
  1.1250 -
  1.1251 -  // print a warning if any large page related flag is specified on command line
  1.1252 -  bool warn_on_failure = !FLAG_IS_DEFAULT(UseHugeTLBFS);
  1.1253 -
  1.1254 -  const size_t default_page_size = (size_t)Bsd::page_size();
  1.1255 -  if (_large_page_size > default_page_size) {
  1.1256 -    _page_sizes[0] = _large_page_size;
  1.1257 -    _page_sizes[1] = default_page_size;
  1.1258 -    _page_sizes[2] = 0;
  1.1259 -  }
  1.1260 -  UseHugeTLBFS = UseHugeTLBFS &&
  1.1261 -                 Bsd::hugetlbfs_sanity_check(warn_on_failure, _large_page_size);
  1.1262 -
  1.1263 -  if (UseHugeTLBFS)
  1.1264 -    UseSHM = false;
  1.1265 -
  1.1266 -  UseLargePages = UseHugeTLBFS || UseSHM;
  1.1267 -
  1.1268 -  set_coredump_filter();
  1.1269 -#endif
  1.1270  }
  1.1271  
  1.1272 -#ifndef _ALLBSD_SOURCE
  1.1273 -#ifndef SHM_HUGETLB
  1.1274 -#define SHM_HUGETLB 04000
  1.1275 -#endif
  1.1276 -#endif
  1.1277  
  1.1278  char* os::reserve_memory_special(size_t bytes, char* req_addr, bool exec) {
  1.1279    // "exec" is passed in but not used.  Creating the shared image for
  1.1280 @@ -3267,11 +2235,7 @@
  1.1281  
  1.1282    // Create a large shared memory region to attach to based on size.
  1.1283    // Currently, size is the total size of the heap
  1.1284 -#ifndef _ALLBSD_SOURCE
  1.1285 -  int shmid = shmget(key, bytes, SHM_HUGETLB|IPC_CREAT|SHM_R|SHM_W);
  1.1286 -#else
  1.1287    int shmid = shmget(key, bytes, IPC_CREAT|SHM_R|SHM_W);
  1.1288 -#endif
  1.1289    if (shmid == -1) {
  1.1290       // Possible reasons for shmget failure:
  1.1291       // 1. shmmax is too small for Java heap.
  1.1292 @@ -3558,7 +2522,7 @@
  1.1293  // this reason, the code should not be used as default (ThreadPriorityPolicy=0).
  1.1294  // It is only used when ThreadPriorityPolicy=1 and requires root privilege.
  1.1295  
  1.1296 -#if defined(_ALLBSD_SOURCE) && !defined(__APPLE__)
  1.1297 +#if !defined(__APPLE__)
  1.1298  int os::java_to_os_priority[CriticalPriority + 1] = {
  1.1299    19,              // 0 Entry should never be used
  1.1300  
  1.1301 @@ -3578,7 +2542,7 @@
  1.1302  
  1.1303    31               // 11 CriticalPriority
  1.1304  };
  1.1305 -#elif defined(__APPLE__)
  1.1306 +#else
  1.1307  /* Using Mach high-level priority assignments */
  1.1308  int os::java_to_os_priority[CriticalPriority + 1] = {
  1.1309     0,              // 0 Entry should never be used (MINPRI_USER)
  1.1310 @@ -3599,26 +2563,6 @@
  1.1311  
  1.1312    36               // 11 CriticalPriority
  1.1313  };
  1.1314 -#else
  1.1315 -int os::java_to_os_priority[CriticalPriority + 1] = {
  1.1316 -  19,              // 0 Entry should never be used
  1.1317 -
  1.1318 -   4,              // 1 MinPriority
  1.1319 -   3,              // 2
  1.1320 -   2,              // 3
  1.1321 -
  1.1322 -   1,              // 4
  1.1323 -   0,              // 5 NormPriority
  1.1324 -  -1,              // 6
  1.1325 -
  1.1326 -  -2,              // 7
  1.1327 -  -3,              // 8
  1.1328 -  -4,              // 9 NearMaxPriority
  1.1329 -
  1.1330 -  -5,              // 10 MaxPriority
  1.1331 -
  1.1332 -  -5               // 11 CriticalPriority
  1.1333 -};
  1.1334  #endif
  1.1335  
  1.1336  static int prio_init() {
  1.1337 @@ -4179,22 +3123,6 @@
  1.1338    }
  1.1339  }
  1.1340  
  1.1341 -#ifndef _ALLBSD_SOURCE
  1.1342 -// This is the fastest way to get thread cpu time on Bsd.
  1.1343 -// Returns cpu time (user+sys) for any thread, not only for current.
  1.1344 -// POSIX compliant clocks are implemented in the kernels 2.6.16+.
  1.1345 -// It might work on 2.6.10+ with a special kernel/glibc patch.
  1.1346 -// For reference, please, see IEEE Std 1003.1-2004:
  1.1347 -//   http://www.unix.org/single_unix_specification
  1.1348 -
  1.1349 -jlong os::Bsd::fast_thread_cpu_time(clockid_t clockid) {
  1.1350 -  struct timespec tp;
  1.1351 -  int rc = os::Bsd::clock_gettime(clockid, &tp);
  1.1352 -  assert(rc == 0, "clock_gettime is expected to return 0 code");
  1.1353 -
  1.1354 -  return (tp.tv_sec * NANOSECS_PER_SEC) + tp.tv_nsec;
  1.1355 -}
  1.1356 -#endif
  1.1357  
  1.1358  /////
  1.1359  // glibc on Bsd platform uses non-documented flag
  1.1360 @@ -4458,10 +3386,6 @@
  1.1361  // this is called _after_ the global arguments have been parsed
  1.1362  jint os::init_2(void)
  1.1363  {
  1.1364 -#ifndef _ALLBSD_SOURCE
  1.1365 -  Bsd::fast_thread_clock_init();
  1.1366 -#endif
  1.1367 -
  1.1368    // Allocate a single page and mark it as readable for safepoint polling
  1.1369    address polling_page = (address) ::mmap(NULL, Bsd::page_size(), PROT_READ, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
  1.1370    guarantee( polling_page != MAP_FAILED, "os::init_2: failed to allocate polling page" );
  1.1371 @@ -4518,48 +3442,6 @@
  1.1372    JavaThread::set_stack_size_at_create(round_to(threadStackSizeInBytes,
  1.1373          vm_page_size()));
  1.1374  
  1.1375 -#ifndef _ALLBSD_SOURCE
  1.1376 -  Bsd::capture_initial_stack(JavaThread::stack_size_at_create());
  1.1377 -
  1.1378 -  Bsd::libpthread_init();
  1.1379 -  if (PrintMiscellaneous && (Verbose || WizardMode)) {
  1.1380 -     tty->print_cr("[HotSpot is running with %s, %s(%s)]\n",
  1.1381 -          Bsd::glibc_version(), Bsd::libpthread_version(),
  1.1382 -          Bsd::is_floating_stack() ? "floating stack" : "fixed stack");
  1.1383 -  }
  1.1384 -
  1.1385 -  if (UseNUMA) {
  1.1386 -    if (!Bsd::libnuma_init()) {
  1.1387 -      UseNUMA = false;
  1.1388 -    } else {
  1.1389 -      if ((Bsd::numa_max_node() < 1)) {
  1.1390 -        // There's only one node(they start from 0), disable NUMA.
  1.1391 -        UseNUMA = false;
  1.1392 -      }
  1.1393 -    }
  1.1394 -    // With SHM large pages we cannot uncommit a page, so there's not way
  1.1395 -    // we can make the adaptive lgrp chunk resizing work. If the user specified
  1.1396 -    // both UseNUMA and UseLargePages (or UseSHM) on the command line - warn and
  1.1397 -    // disable adaptive resizing.
  1.1398 -    if (UseNUMA && UseLargePages && UseSHM) {
  1.1399 -      if (!FLAG_IS_DEFAULT(UseNUMA)) {
  1.1400 -        if (FLAG_IS_DEFAULT(UseLargePages) && FLAG_IS_DEFAULT(UseSHM)) {
  1.1401 -          UseLargePages = false;
  1.1402 -        } else {
  1.1403 -          warning("UseNUMA is not fully compatible with SHM large pages, disabling adaptive resizing");
  1.1404 -          UseAdaptiveSizePolicy = false;
  1.1405 -          UseAdaptiveNUMAChunkSizing = false;
  1.1406 -        }
  1.1407 -      } else {
  1.1408 -        UseNUMA = false;
  1.1409 -      }
  1.1410 -    }
  1.1411 -    if (!UseNUMA && ForceNUMA) {
  1.1412 -      UseNUMA = true;
  1.1413 -    }
  1.1414 -  }
  1.1415 -#endif
  1.1416 -
  1.1417    if (MaxFDLimit) {
  1.1418      // set the number of file descriptors to max. print out error
  1.1419      // if getrlimit/setrlimit fails but continue regardless.
  1.1420 @@ -4586,11 +3468,6 @@
  1.1421      }
  1.1422    }
  1.1423  
  1.1424 -#ifndef _ALLBSD_SOURCE
  1.1425 -  // Initialize lock used to serialize thread creation (see os::create_thread)
  1.1426 -  Bsd::set_createThread_lock(new Mutex(Mutex::leaf, "createThread_lock", false));
  1.1427 -#endif
  1.1428 -
  1.1429    // at-exit methods are called in the reverse order of their registration.
  1.1430    // atexit functions are called on return from main or as a result of a
  1.1431    // call to exit(3C). There can be only 32 of these functions registered
  1.1432 @@ -4641,15 +3518,7 @@
  1.1433  };
  1.1434  
  1.1435  int os::active_processor_count() {
  1.1436 -#ifdef _ALLBSD_SOURCE
  1.1437    return _processor_count;
  1.1438 -#else
  1.1439 -  // Bsd doesn't yet have a (official) notion of processor sets,
  1.1440 -  // so just return the number of online processors.
  1.1441 -  int online_cpus = ::sysconf(_SC_NPROCESSORS_ONLN);
  1.1442 -  assert(online_cpus > 0 && online_cpus <= processor_count(), "sanity check");
  1.1443 -  return online_cpus;
  1.1444 -#endif
  1.1445  }
  1.1446  
  1.1447  void os::set_native_thread_name(const char *name) {
  1.1448 @@ -4703,25 +3572,7 @@
  1.1449  
  1.1450  int os::Bsd::safe_cond_timedwait(pthread_cond_t *_cond, pthread_mutex_t *_mutex, const struct timespec *_abstime)
  1.1451  {
  1.1452 -#ifdef _ALLBSD_SOURCE
  1.1453    return pthread_cond_timedwait(_cond, _mutex, _abstime);
  1.1454 -#else
  1.1455 -   if (is_NPTL()) {
  1.1456 -      return pthread_cond_timedwait(_cond, _mutex, _abstime);
  1.1457 -   } else {
  1.1458 -#ifndef IA64
  1.1459 -      // 6292965: BsdThreads pthread_cond_timedwait() resets FPU control
  1.1460 -      // word back to default 64bit precision if condvar is signaled. Java
  1.1461 -      // wants 53bit precision.  Save and restore current value.
  1.1462 -      int fpu = get_fpu_control_word();
  1.1463 -#endif // IA64
  1.1464 -      int status = pthread_cond_timedwait(_cond, _mutex, _abstime);
  1.1465 -#ifndef IA64
  1.1466 -      set_fpu_control_word(fpu);
  1.1467 -#endif // IA64
  1.1468 -      return status;
  1.1469 -   }
  1.1470 -#endif
  1.1471  }
  1.1472  
  1.1473  ////////////////////////////////////////////////////////////////////////////////
  1.1474 @@ -5041,20 +3892,6 @@
  1.1475    return munmap(addr, bytes) == 0;
  1.1476  }
  1.1477  
  1.1478 -#ifndef _ALLBSD_SOURCE
  1.1479 -static jlong slow_thread_cpu_time(Thread *thread, bool user_sys_cpu_time);
  1.1480 -
  1.1481 -static clockid_t thread_cpu_clockid(Thread* thread) {
  1.1482 -  pthread_t tid = thread->osthread()->pthread_id();
  1.1483 -  clockid_t clockid;
  1.1484 -
  1.1485 -  // Get thread clockid
  1.1486 -  int rc = os::Bsd::pthread_getcpuclockid(tid, &clockid);
  1.1487 -  assert(rc == 0, "pthread_getcpuclockid is expected to return 0 code");
  1.1488 -  return clockid;
  1.1489 -}
  1.1490 -#endif
  1.1491 -
  1.1492  // current_thread_cpu_time(bool) and thread_cpu_time(Thread*, bool)
  1.1493  // are used by JVM M&M and JVMTI to get user+sys or user CPU time
  1.1494  // of a thread.
  1.1495 @@ -5065,36 +3902,15 @@
  1.1496  jlong os::current_thread_cpu_time() {
  1.1497  #ifdef __APPLE__
  1.1498    return os::thread_cpu_time(Thread::current(), true /* user + sys */);
  1.1499 -#elif !defined(_ALLBSD_SOURCE)
  1.1500 -  if (os::Bsd::supports_fast_thread_cpu_time()) {
  1.1501 -    return os::Bsd::fast_thread_cpu_time(CLOCK_THREAD_CPUTIME_ID);
  1.1502 -  } else {
  1.1503 -    // return user + sys since the cost is the same
  1.1504 -    return slow_thread_cpu_time(Thread::current(), true /* user + sys */);
  1.1505 -  }
  1.1506  #endif
  1.1507  }
  1.1508  
  1.1509  jlong os::thread_cpu_time(Thread* thread) {
  1.1510 -#ifndef _ALLBSD_SOURCE
  1.1511 -  // consistent with what current_thread_cpu_time() returns
  1.1512 -  if (os::Bsd::supports_fast_thread_cpu_time()) {
  1.1513 -    return os::Bsd::fast_thread_cpu_time(thread_cpu_clockid(thread));
  1.1514 -  } else {
  1.1515 -    return slow_thread_cpu_time(thread, true /* user + sys */);
  1.1516 -  }
  1.1517 -#endif
  1.1518  }
  1.1519  
  1.1520  jlong os::current_thread_cpu_time(bool user_sys_cpu_time) {
  1.1521  #ifdef __APPLE__
  1.1522    return os::thread_cpu_time(Thread::current(), user_sys_cpu_time);
  1.1523 -#elif !defined(_ALLBSD_SOURCE)
  1.1524 -  if (user_sys_cpu_time && os::Bsd::supports_fast_thread_cpu_time()) {
  1.1525 -    return os::Bsd::fast_thread_cpu_time(CLOCK_THREAD_CPUTIME_ID);
  1.1526 -  } else {
  1.1527 -    return slow_thread_cpu_time(Thread::current(), user_sys_cpu_time);
  1.1528 -  }
  1.1529  #endif
  1.1530  }
  1.1531  
  1.1532 @@ -5118,106 +3934,9 @@
  1.1533    } else {
  1.1534      return ((jlong)tinfo.user_time.seconds * 1000000000) + ((jlong)tinfo.user_time.microseconds * (jlong)1000);
  1.1535    }
  1.1536 -#elif !defined(_ALLBSD_SOURCE)
  1.1537 -  if (user_sys_cpu_time && os::Bsd::supports_fast_thread_cpu_time()) {
  1.1538 -    return os::Bsd::fast_thread_cpu_time(thread_cpu_clockid(thread));
  1.1539 -  } else {
  1.1540 -    return slow_thread_cpu_time(thread, user_sys_cpu_time);
  1.1541 -  }
  1.1542  #endif
  1.1543  }
  1.1544  
  1.1545 -#ifndef _ALLBSD_SOURCE
  1.1546 -//
  1.1547 -//  -1 on error.
  1.1548 -//
  1.1549 -
  1.1550 -static jlong slow_thread_cpu_time(Thread *thread, bool user_sys_cpu_time) {
  1.1551 -  static bool proc_pid_cpu_avail = true;
  1.1552 -  static bool proc_task_unchecked = true;
  1.1553 -  static const char *proc_stat_path = "/proc/%d/stat";
  1.1554 -  pid_t  tid = thread->osthread()->thread_id();
  1.1555 -  int i;
  1.1556 -  char *s;
  1.1557 -  char stat[2048];
  1.1558 -  int statlen;
  1.1559 -  char proc_name[64];
  1.1560 -  int count;
  1.1561 -  long sys_time, user_time;
  1.1562 -  char string[64];
  1.1563 -  char cdummy;
  1.1564 -  int idummy;
  1.1565 -  long ldummy;
  1.1566 -  FILE *fp;
  1.1567 -
  1.1568 -  // We first try accessing /proc/<pid>/cpu since this is faster to
  1.1569 -  // process.  If this file is not present (bsd kernels 2.5 and above)
  1.1570 -  // then we open /proc/<pid>/stat.
  1.1571 -  if ( proc_pid_cpu_avail ) {
  1.1572 -    sprintf(proc_name, "/proc/%d/cpu", tid);
  1.1573 -    fp =  fopen(proc_name, "r");
  1.1574 -    if ( fp != NULL ) {
  1.1575 -      count = fscanf( fp, "%s %lu %lu\n", string, &user_time, &sys_time);
  1.1576 -      fclose(fp);
  1.1577 -      if ( count != 3 ) return -1;
  1.1578 -
  1.1579 -      if (user_sys_cpu_time) {
  1.1580 -        return ((jlong)sys_time + (jlong)user_time) * (1000000000 / clock_tics_per_sec);
  1.1581 -      } else {
  1.1582 -        return (jlong)user_time * (1000000000 / clock_tics_per_sec);
  1.1583 -      }
  1.1584 -    }
  1.1585 -    else proc_pid_cpu_avail = false;
  1.1586 -  }
  1.1587 -
  1.1588 -  // The /proc/<tid>/stat aggregates per-process usage on
  1.1589 -  // new Bsd kernels 2.6+ where NPTL is supported.
  1.1590 -  // The /proc/self/task/<tid>/stat still has the per-thread usage.
  1.1591 -  // See bug 6328462.
  1.1592 -  // There can be no directory /proc/self/task on kernels 2.4 with NPTL
  1.1593 -  // and possibly in some other cases, so we check its availability.
  1.1594 -  if (proc_task_unchecked && os::Bsd::is_NPTL()) {
  1.1595 -    // This is executed only once
  1.1596 -    proc_task_unchecked = false;
  1.1597 -    fp = fopen("/proc/self/task", "r");
  1.1598 -    if (fp != NULL) {
  1.1599 -      proc_stat_path = "/proc/self/task/%d/stat";
  1.1600 -      fclose(fp);
  1.1601 -    }
  1.1602 -  }
  1.1603 -
  1.1604 -  sprintf(proc_name, proc_stat_path, tid);
  1.1605 -  fp = fopen(proc_name, "r");
  1.1606 -  if ( fp == NULL ) return -1;
  1.1607 -  statlen = fread(stat, 1, 2047, fp);
  1.1608 -  stat[statlen] = '\0';
  1.1609 -  fclose(fp);
  1.1610 -
  1.1611 -  // Skip pid and the command string. Note that we could be dealing with
  1.1612 -  // weird command names, e.g. user could decide to rename java launcher
  1.1613 -  // to "java 1.4.2 :)", then the stat file would look like
  1.1614 -  //                1234 (java 1.4.2 :)) R ... ...
  1.1615 -  // We don't really need to know the command string, just find the last
  1.1616 -  // occurrence of ")" and then start parsing from there. See bug 4726580.
  1.1617 -  s = strrchr(stat, ')');
  1.1618 -  i = 0;
  1.1619 -  if (s == NULL ) return -1;
  1.1620 -
  1.1621 -  // Skip blank chars
  1.1622 -  do s++; while (isspace(*s));
  1.1623 -
  1.1624 -  count = sscanf(s,"%c %d %d %d %d %d %lu %lu %lu %lu %lu %lu %lu",
  1.1625 -                 &cdummy, &idummy, &idummy, &idummy, &idummy, &idummy,
  1.1626 -                 &ldummy, &ldummy, &ldummy, &ldummy, &ldummy,
  1.1627 -                 &user_time, &sys_time);
  1.1628 -  if ( count != 13 ) return -1;
  1.1629 -  if (user_sys_cpu_time) {
  1.1630 -    return ((jlong)sys_time + (jlong)user_time) * (1000000000 / clock_tics_per_sec);
  1.1631 -  } else {
  1.1632 -    return (jlong)user_time * (1000000000 / clock_tics_per_sec);
  1.1633 -  }
  1.1634 -}
  1.1635 -#endif
  1.1636  
  1.1637  void os::current_thread_cpu_time_info(jvmtiTimerInfo *info_ptr) {
  1.1638    info_ptr->max_value = ALL_64_BITS;       // will not wrap in less than 64 bits
  1.1639 @@ -5236,10 +3955,8 @@
  1.1640  bool os::is_thread_cpu_time_supported() {
  1.1641  #ifdef __APPLE__
  1.1642    return true;
  1.1643 -#elif defined(_ALLBSD_SOURCE)
  1.1644 +#else
  1.1645    return false;
  1.1646 -#else
  1.1647 -  return true;
  1.1648  #endif
  1.1649  }
  1.1650  

mercurial