hotspot/src/os/linux/vm/os_linux.cpp
changeset 26684 d1221849ea3d
parent 26683 a02753d5a0b2
child 26685 aa239a0dfbea
equal deleted inserted replaced
26683:a02753d5a0b2 26684:d1221849ea3d
   107 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
   107 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
   108 
   108 
   109 // if RUSAGE_THREAD for getrusage() has not been defined, do it here. The code calling
   109 // if RUSAGE_THREAD for getrusage() has not been defined, do it here. The code calling
   110 // getrusage() is prepared to handle the associated failure.
   110 // getrusage() is prepared to handle the associated failure.
   111 #ifndef RUSAGE_THREAD
   111 #ifndef RUSAGE_THREAD
   112 #define RUSAGE_THREAD   (1)               /* only the calling thread */
   112   #define RUSAGE_THREAD   (1)               /* only the calling thread */
   113 #endif
   113 #endif
   114 
   114 
   115 #define MAX_PATH    (2 * K)
   115 #define MAX_PATH    (2 * K)
   116 
   116 
   117 #define MAX_SECS 100000000
   117 #define MAX_SECS 100000000
   148 static sigset_t check_signal_done;
   148 static sigset_t check_signal_done;
   149 static bool check_signals = true;
   149 static bool check_signals = true;
   150 
   150 
   151 static pid_t _initial_pid = 0;
   151 static pid_t _initial_pid = 0;
   152 
   152 
   153 /* Signal number used to suspend/resume a thread */
   153 // Signal number used to suspend/resume a thread
   154 
   154 
   155 /* do not use any signal number less than SIGSEGV, see 4355769 */
   155 // do not use any signal number less than SIGSEGV, see 4355769
   156 static int SR_signum = SIGUSR2;
   156 static int SR_signum = SIGUSR2;
   157 sigset_t SR_sigset;
   157 sigset_t SR_sigset;
   158 
   158 
   159 /* Used to protect dlsym() calls */
   159 // Used to protect dlsym() calls
   160 static pthread_mutex_t dl_mutex;
   160 static pthread_mutex_t dl_mutex;
   161 
   161 
   162 // Declarations
   162 // Declarations
   163 static void unpackTime(timespec* absTime, bool isAbsolute, jlong time);
   163 static void unpackTime(timespec* absTime, bool isAbsolute, jlong time);
   164 
   164 
   238 }
   238 }
   239 
   239 
   240 
   240 
   241 #ifndef SYS_gettid
   241 #ifndef SYS_gettid
   242 // i386: 224, ia64: 1105, amd64: 186, sparc 143
   242 // i386: 224, ia64: 1105, amd64: 186, sparc 143
   243 #ifdef __ia64__
   243   #ifdef __ia64__
   244 #define SYS_gettid 1105
   244     #define SYS_gettid 1105
   245 #elif __i386__
   245   #elif __i386__
   246 #define SYS_gettid 224
   246     #define SYS_gettid 224
   247 #elif __amd64__
   247   #elif __amd64__
   248 #define SYS_gettid 186
   248     #define SYS_gettid 186
   249 #elif __sparc__
   249   #elif __sparc__
   250 #define SYS_gettid 143
   250     #define SYS_gettid 143
   251 #else
   251   #else
   252 #error define gettid for the arch
   252     #error define gettid for the arch
   253 #endif
   253   #endif
   254 #endif
   254 #endif
   255 
   255 
   256 // Cpu architecture string
   256 // Cpu architecture string
   257 #if   defined(ZERO)
   257 #if   defined(ZERO)
   258 static char cpu_arch[] = ZERO_LIBARCH;
   258 static char cpu_arch[] = ZERO_LIBARCH;
   267 #elif defined(PPC32)
   267 #elif defined(PPC32)
   268 static char cpu_arch[] = "ppc";
   268 static char cpu_arch[] = "ppc";
   269 #elif defined(PPC64)
   269 #elif defined(PPC64)
   270 static char cpu_arch[] = "ppc64";
   270 static char cpu_arch[] = "ppc64";
   271 #elif defined(SPARC)
   271 #elif defined(SPARC)
   272 #  ifdef _LP64
   272   #ifdef _LP64
   273 static char cpu_arch[] = "sparcv9";
   273 static char cpu_arch[] = "sparcv9";
   274 #  else
   274   #else
   275 static char cpu_arch[] = "sparc";
   275 static char cpu_arch[] = "sparc";
   276 #  endif
   276   #endif
   277 #else
   277 #else
   278 #error Add appropriate cpu_arch setting
   278   #error Add appropriate cpu_arch setting
   279 #endif
   279 #endif
   280 
   280 
   281 
   281 
   282 // pid_t gettid()
   282 // pid_t gettid()
   283 //
   283 //
   348   // Otherwise exit.
   348   // Otherwise exit.
   349   //
   349   //
   350   // Important note: if the location of libjvm.so changes this
   350   // Important note: if the location of libjvm.so changes this
   351   // code needs to be changed accordingly.
   351   // code needs to be changed accordingly.
   352 
   352 
   353 // See ld(1):
   353   // See ld(1):
   354 //      The linker uses the following search paths to locate required
   354   //      The linker uses the following search paths to locate required
   355 //      shared libraries:
   355   //      shared libraries:
   356 //        1: ...
   356   //        1: ...
   357 //        ...
   357   //        ...
   358 //        7: The default directories, normally /lib and /usr/lib.
   358   //        7: The default directories, normally /lib and /usr/lib.
   359 #if defined(AMD64) || defined(_LP64) && (defined(SPARC) || defined(PPC) || defined(S390))
   359 #if defined(AMD64) || defined(_LP64) && (defined(SPARC) || defined(PPC) || defined(S390))
   360 #define DEFAULT_LIBPATH "/usr/lib64:/lib64:/lib:/usr/lib"
   360   #define DEFAULT_LIBPATH "/usr/lib64:/lib64:/lib:/usr/lib"
   361 #else
   361 #else
   362 #define DEFAULT_LIBPATH "/lib:/usr/lib"
   362   #define DEFAULT_LIBPATH "/lib:/usr/lib"
   363 #endif
   363 #endif
   364 
   364 
   365 // Base path of extensions installed on the system.
   365 // Base path of extensions installed on the system.
   366 #define SYS_EXT_DIR     "/usr/java/packages"
   366 #define SYS_EXT_DIR     "/usr/java/packages"
   367 #define EXTENSIONS_DIR  "/lib/ext"
   367 #define EXTENSIONS_DIR  "/lib/ext"
   467 bool os::Linux::is_sig_ignored(int sig) {
   467 bool os::Linux::is_sig_ignored(int sig) {
   468   struct sigaction oact;
   468   struct sigaction oact;
   469   sigaction(sig, (struct sigaction*)NULL, &oact);
   469   sigaction(sig, (struct sigaction*)NULL, &oact);
   470   void* ohlr = oact.sa_sigaction ? CAST_FROM_FN_PTR(void*,  oact.sa_sigaction)
   470   void* ohlr = oact.sa_sigaction ? CAST_FROM_FN_PTR(void*,  oact.sa_sigaction)
   471                                  : CAST_FROM_FN_PTR(void*,  oact.sa_handler);
   471                                  : CAST_FROM_FN_PTR(void*,  oact.sa_handler);
   472   if (ohlr == CAST_FROM_FN_PTR(void*, SIG_IGN))
   472   if (ohlr == CAST_FROM_FN_PTR(void*, SIG_IGN)) {
   473     return true;
   473     return true;
   474   else
   474   } else {
   475     return false;
   475     return false;
       
   476   }
   476 }
   477 }
   477 
   478 
   478 void os::Linux::signal_sets_init() {
   479 void os::Linux::signal_sets_init() {
   479   // Should also have an assertion stating we are still single-threaded.
   480   // Should also have an assertion stating we are still single-threaded.
   480   assert(!signal_sets_initialized, "Already initialized");
   481   assert(!signal_sets_initialized, "Already initialized");
   516       sigaddset(&allowdebug_blocked_sigs, SHUTDOWN3_SIGNAL);
   517       sigaddset(&allowdebug_blocked_sigs, SHUTDOWN3_SIGNAL);
   517     }
   518     }
   518   }
   519   }
   519   // Fill in signals that are blocked by all but the VM thread.
   520   // Fill in signals that are blocked by all but the VM thread.
   520   sigemptyset(&vm_sigs);
   521   sigemptyset(&vm_sigs);
   521   if (!ReduceSignalUsage)
   522   if (!ReduceSignalUsage) {
   522     sigaddset(&vm_sigs, BREAK_SIGNAL);
   523     sigaddset(&vm_sigs, BREAK_SIGNAL);
       
   524   }
   523   debug_only(signal_sets_initialized = true);
   525   debug_only(signal_sets_initialized = true);
   524 
   526 
   525 }
   527 }
   526 
   528 
   527 // These are signals that are unblocked while a thread is running Java.
   529 // These are signals that are unblocked while a thread is running Java.
   572 void os::Linux::libpthread_init() {
   574 void os::Linux::libpthread_init() {
   573   // Save glibc and pthread version strings. Note that _CS_GNU_LIBC_VERSION
   575   // Save glibc and pthread version strings. Note that _CS_GNU_LIBC_VERSION
   574   // and _CS_GNU_LIBPTHREAD_VERSION are supported in glibc >= 2.3.2. Use a
   576   // and _CS_GNU_LIBPTHREAD_VERSION are supported in glibc >= 2.3.2. Use a
   575   // generic name for earlier versions.
   577   // generic name for earlier versions.
   576   // Define macros here so we can build HotSpot on old systems.
   578   // Define macros here so we can build HotSpot on old systems.
   577 # ifndef _CS_GNU_LIBC_VERSION
   579 #ifndef _CS_GNU_LIBC_VERSION
   578 # define _CS_GNU_LIBC_VERSION 2
   580   #define _CS_GNU_LIBC_VERSION 2
   579 # endif
   581 #endif
   580 # ifndef _CS_GNU_LIBPTHREAD_VERSION
   582 #ifndef _CS_GNU_LIBPTHREAD_VERSION
   581 # define _CS_GNU_LIBPTHREAD_VERSION 3
   583   #define _CS_GNU_LIBPTHREAD_VERSION 3
   582 # endif
   584 #endif
   583 
   585 
   584   size_t n = confstr(_CS_GNU_LIBC_VERSION, NULL, 0);
   586   size_t n = confstr(_CS_GNU_LIBC_VERSION, NULL, 0);
   585   if (n > 0) {
   587   if (n > 0) {
   586     char *str = (char *)malloc(n, mtInternal);
   588     char *str = (char *)malloc(n, mtInternal);
   587     confstr(_CS_GNU_LIBC_VERSION, str, n);
   589     confstr(_CS_GNU_LIBC_VERSION, str, n);
   681 //
   683 //
   682 // _expand_stack_to() assumes its frame size is less than page size, which
   684 // _expand_stack_to() assumes its frame size is less than page size, which
   683 // should always be true if the function is not inlined.
   685 // should always be true if the function is not inlined.
   684 
   686 
   685 #if __GNUC__ < 3    // gcc 2.x does not support noinline attribute
   687 #if __GNUC__ < 3    // gcc 2.x does not support noinline attribute
   686 #define NOINLINE
   688   #define NOINLINE
   687 #else
   689 #else
   688 #define NOINLINE __attribute__ ((noinline))
   690   #define NOINLINE __attribute__ ((noinline))
   689 #endif
   691 #endif
   690 
   692 
   691 static void _expand_stack_to(address bottom) NOINLINE;
   693 static void _expand_stack_to(address bottom) NOINLINE;
   692 
   694 
   693 static void _expand_stack_to(address bottom) {
   695 static void _expand_stack_to(address bottom) {
   830   thread->run();
   832   thread->run();
   831 
   833 
   832   return 0;
   834   return 0;
   833 }
   835 }
   834 
   836 
   835 bool os::create_thread(Thread* thread, ThreadType thr_type, size_t stack_size) {
   837 bool os::create_thread(Thread* thread, ThreadType thr_type,
       
   838                        size_t stack_size) {
   836   assert(thread->osthread() == NULL, "caller responsible");
   839   assert(thread->osthread() == NULL, "caller responsible");
   837 
   840 
   838   // Allocate the OSThread object
   841   // Allocate the OSThread object
   839   OSThread* osthread = new OSThread(NULL, NULL);
   842   OSThread* osthread = new OSThread(NULL, NULL);
   840   if (osthread == NULL) {
   843   if (osthread == NULL) {
  1082   if (initial_thread_stack_bottom() == NULL) return false;
  1085   if (initial_thread_stack_bottom() == NULL) return false;
  1083   assert(initial_thread_stack_bottom() != NULL &&
  1086   assert(initial_thread_stack_bottom() != NULL &&
  1084          initial_thread_stack_size()   != 0,
  1087          initial_thread_stack_size()   != 0,
  1085          "os::init did not locate initial thread's stack region");
  1088          "os::init did not locate initial thread's stack region");
  1086   if ((address)&dummy >= initial_thread_stack_bottom() &&
  1089   if ((address)&dummy >= initial_thread_stack_bottom() &&
  1087       (address)&dummy < initial_thread_stack_bottom() + initial_thread_stack_size())
  1090       (address)&dummy < initial_thread_stack_bottom() + initial_thread_stack_size()) {
  1088     return true;
  1091     return true;
  1089   else return false;
  1092   } else {
       
  1093     return false;
       
  1094   }
  1090 }
  1095 }
  1091 
  1096 
  1092 // Find the virtual memory area that contains addr
  1097 // Find the virtual memory area that contains addr
  1093 static bool find_vma(address addr, address* vma_low, address* vma_high) {
  1098 static bool find_vma(address addr, address* vma_low, address* vma_high) {
  1094   FILE *fp = fopen("/proc/self/maps", "r");
  1099   FILE *fp = fopen("/proc/self/maps", "r");
  1134   //   SuSE 7.2, Debian) can not handle alternate signal stack correctly
  1139   //   SuSE 7.2, Debian) can not handle alternate signal stack correctly
  1135   //   for initial thread if its stack size exceeds 6M. Cap it at 2M,
  1140   //   for initial thread if its stack size exceeds 6M. Cap it at 2M,
  1136   //   in case other parts in glibc still assumes 2M max stack size.
  1141   //   in case other parts in glibc still assumes 2M max stack size.
  1137   // FIXME: alt signal stack is gone, maybe we can relax this constraint?
  1142   // FIXME: alt signal stack is gone, maybe we can relax this constraint?
  1138   // Problem still exists RH7.2 (IA64 anyway) but 2MB is a little small
  1143   // Problem still exists RH7.2 (IA64 anyway) but 2MB is a little small
  1139   if (stack_size > 2 * K * K IA64_ONLY(*2))
  1144   if (stack_size > 2 * K * K IA64_ONLY(*2)) {
  1140     stack_size = 2 * K * K IA64_ONLY(*2);
  1145     stack_size = 2 * K * K IA64_ONLY(*2);
       
  1146   }
  1141   // Try to figure out where the stack base (top) is. This is harder.
  1147   // Try to figure out where the stack base (top) is. This is harder.
  1142   //
  1148   //
  1143   // When an application is started, glibc saves the initial stack pointer in
  1149   // When an application is started, glibc saves the initial stack pointer in
  1144   // a global variable "__libc_stack_end", which is then used by system
  1150   // a global variable "__libc_stack_end", which is then used by system
  1145   // libraries. __libc_stack_end should be pretty close to stack top. The
  1151   // libraries. __libc_stack_end should be pretty close to stack top. The
  1219         do s++; while (isspace(*s));
  1225         do s++; while (isspace(*s));
  1220 
  1226 
  1221 #define _UFM UINTX_FORMAT
  1227 #define _UFM UINTX_FORMAT
  1222 #define _DFM INTX_FORMAT
  1228 #define _DFM INTX_FORMAT
  1223 
  1229 
  1224         /*                                     1   1   1   1   1   1   1   1   1   1   2   2    2    2    2    2    2    2    2 */
  1230         //                                     1   1   1   1   1   1   1   1   1   1   2   2    2    2    2    2    2    2    2
  1225         /*              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 */
  1231         //              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
  1226         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,
  1232         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,
  1227                    &state,          /* 3  %c  */
  1233                    &state,          // 3  %c
  1228                    &ppid,           /* 4  %d  */
  1234                    &ppid,           // 4  %d
  1229                    &pgrp,           /* 5  %d  */
  1235                    &pgrp,           // 5  %d
  1230                    &session,        /* 6  %d  */
  1236                    &session,        // 6  %d
  1231                    &nr,             /* 7  %d  */
  1237                    &nr,             // 7  %d
  1232                    &tpgrp,          /* 8  %d  */
  1238                    &tpgrp,          // 8  %d
  1233                    &flags,          /* 9  %lu  */
  1239                    &flags,          // 9  %lu
  1234                    &minflt,         /* 10 %lu  */
  1240                    &minflt,         // 10 %lu
  1235                    &cminflt,        /* 11 %lu  */
  1241                    &cminflt,        // 11 %lu
  1236                    &majflt,         /* 12 %lu  */
  1242                    &majflt,         // 12 %lu
  1237                    &cmajflt,        /* 13 %lu  */
  1243                    &cmajflt,        // 13 %lu
  1238                    &utime,          /* 14 %lu  */
  1244                    &utime,          // 14 %lu
  1239                    &stime,          /* 15 %lu  */
  1245                    &stime,          // 15 %lu
  1240                    &cutime,         /* 16 %ld  */
  1246                    &cutime,         // 16 %ld
  1241                    &cstime,         /* 17 %ld  */
  1247                    &cstime,         // 17 %ld
  1242                    &prio,           /* 18 %ld  */
  1248                    &prio,           // 18 %ld
  1243                    &nice,           /* 19 %ld  */
  1249                    &nice,           // 19 %ld
  1244                    &junk,           /* 20 %ld  */
  1250                    &junk,           // 20 %ld
  1245                    &it_real,        /* 21 %ld  */
  1251                    &it_real,        // 21 %ld
  1246                    &start,          /* 22 UINTX_FORMAT */
  1252                    &start,          // 22 UINTX_FORMAT
  1247                    &vsize,          /* 23 UINTX_FORMAT */
  1253                    &vsize,          // 23 UINTX_FORMAT
  1248                    &rss,            /* 24 INTX_FORMAT  */
  1254                    &rss,            // 24 INTX_FORMAT
  1249                    &rsslim,         /* 25 UINTX_FORMAT */
  1255                    &rsslim,         // 25 UINTX_FORMAT
  1250                    &scodes,         /* 26 UINTX_FORMAT */
  1256                    &scodes,         // 26 UINTX_FORMAT
  1251                    &ecode,          /* 27 UINTX_FORMAT */
  1257                    &ecode,          // 27 UINTX_FORMAT
  1252                    &stack_start);   /* 28 UINTX_FORMAT */
  1258                    &stack_start);   // 28 UINTX_FORMAT
  1253       }
  1259       }
  1254 
  1260 
  1255 #undef _UFM
  1261 #undef _UFM
  1256 #undef _DFM
  1262 #undef _DFM
  1257 
  1263 
  1346   assert(status != -1, "linux error");
  1352   assert(status != -1, "linux error");
  1347   return jlong(time.tv_sec) * 1000  +  jlong(time.tv_usec / 1000);
  1353   return jlong(time.tv_sec) * 1000  +  jlong(time.tv_usec / 1000);
  1348 }
  1354 }
  1349 
  1355 
  1350 #ifndef CLOCK_MONOTONIC
  1356 #ifndef CLOCK_MONOTONIC
  1351 #define CLOCK_MONOTONIC (1)
  1357   #define CLOCK_MONOTONIC (1)
  1352 #endif
  1358 #endif
  1353 
  1359 
  1354 void os::Linux::clock_init() {
  1360 void os::Linux::clock_init() {
  1355   // we do dlopen's in this particular order due to bug in linux
  1361   // we do dlopen's in this particular order due to bug in linux
  1356   // dynamical loader (see 6348968) leading to crash on exit
  1362   // dynamical loader (see 6348968) leading to crash on exit
  1389   warning("No monotonic clock was available - timed services may " \
  1395   warning("No monotonic clock was available - timed services may " \
  1390           "be adversely affected if the time-of-day clock changes");
  1396           "be adversely affected if the time-of-day clock changes");
  1391 }
  1397 }
  1392 
  1398 
  1393 #ifndef SYS_clock_getres
  1399 #ifndef SYS_clock_getres
  1394 
  1400   #if defined(IA32) || defined(AMD64)
  1395 #if defined(IA32) || defined(AMD64)
  1401     #define SYS_clock_getres IA32_ONLY(266)  AMD64_ONLY(229)
  1396 #define SYS_clock_getres IA32_ONLY(266)  AMD64_ONLY(229)
  1402     #define sys_clock_getres(x,y)  ::syscall(SYS_clock_getres, x, y)
  1397 #define sys_clock_getres(x,y)  ::syscall(SYS_clock_getres, x, y)
  1403   #else
       
  1404     #warning "SYS_clock_getres not defined for this platform, disabling fast_thread_cpu_time"
       
  1405     #define sys_clock_getres(x,y)  -1
       
  1406   #endif
  1398 #else
  1407 #else
  1399 #warning "SYS_clock_getres not defined for this platform, disabling fast_thread_cpu_time"
  1408   #define sys_clock_getres(x,y)  ::syscall(SYS_clock_getres, x, y)
  1400 #define sys_clock_getres(x,y)  -1
       
  1401 #endif
       
  1402 
       
  1403 #else
       
  1404 #define sys_clock_getres(x,y)  ::syscall(SYS_clock_getres, x, y)
       
  1405 #endif
  1409 #endif
  1406 
  1410 
  1407 void os::Linux::fast_thread_clock_init() {
  1411 void os::Linux::fast_thread_clock_init() {
  1408   if (!UseLinuxPosixThreadCPUClocks) {
  1412   if (!UseLinuxPosixThreadCPUClocks) {
  1409     return;
  1413     return;
  1423   // better than 1 sec. This is extra check for reliability.
  1427   // better than 1 sec. This is extra check for reliability.
  1424 
  1428 
  1425   if (pthread_getcpuclockid_func &&
  1429   if (pthread_getcpuclockid_func &&
  1426       pthread_getcpuclockid_func(_main_thread, &clockid) == 0 &&
  1430       pthread_getcpuclockid_func(_main_thread, &clockid) == 0 &&
  1427       sys_clock_getres(clockid, &tp) == 0 && tp.tv_sec == 0) {
  1431       sys_clock_getres(clockid, &tp) == 0 && tp.tv_sec == 0) {
  1428 
       
  1429     _supports_fast_thread_cpu_time = true;
  1432     _supports_fast_thread_cpu_time = true;
  1430     _pthread_getcpuclockid = pthread_getcpuclockid_func;
  1433     _pthread_getcpuclockid = pthread_getcpuclockid_func;
  1431   }
  1434   }
  1432 }
  1435 }
  1433 
  1436 
  1556 
  1559 
  1557 // This method is a copy of JDK's sysGetLastErrorString
  1560 // This method is a copy of JDK's sysGetLastErrorString
  1558 // from src/solaris/hpi/src/system_md.c
  1561 // from src/solaris/hpi/src/system_md.c
  1559 
  1562 
  1560 size_t os::lasterror(char *buf, size_t len) {
  1563 size_t os::lasterror(char *buf, size_t len) {
  1561 
       
  1562   if (errno == 0)  return 0;
  1564   if (errno == 0)  return 0;
  1563 
  1565 
  1564   const char *s = ::strerror(errno);
  1566   const char *s = ::strerror(errno);
  1565   size_t n = ::strlen(s);
  1567   size_t n = ::strlen(s);
  1566   if (n >= len) {
  1568   if (n >= len) {
  1816     os::Linux::_stack_is_executable = true;
  1818     os::Linux::_stack_is_executable = true;
  1817   }
  1819   }
  1818   void* loaded_library() { return _lib; }
  1820   void* loaded_library() { return _lib; }
  1819 };
  1821 };
  1820 
  1822 
  1821 void * os::dll_load(const char *filename, char *ebuf, int ebuflen)
  1823 void * os::dll_load(const char *filename, char *ebuf, int ebuflen) {
  1822 {
       
  1823   void * result = NULL;
  1824   void * result = NULL;
  1824   bool load_attempted = false;
  1825   bool load_attempted = false;
  1825 
  1826 
  1826   // Check whether the library to load might change execution rights
  1827   // Check whether the library to load might change execution rights
  1827   // of the stack. If they are changed, the protection of the stack
  1828   // of the stack. If they are changed, the protection of the stack
  1919     char        elf_class;    // 32 or 64 bit
  1920     char        elf_class;    // 32 or 64 bit
  1920     char        endianess;    // MSB or LSB
  1921     char        endianess;    // MSB or LSB
  1921     char*       name;         // String representation
  1922     char*       name;         // String representation
  1922   } arch_t;
  1923   } arch_t;
  1923 
  1924 
  1924   #ifndef EM_486
  1925 #ifndef EM_486
  1925   #define EM_486          6               /* Intel 80486 */
  1926   #define EM_486          6               /* Intel 80486 */
  1926   #endif
  1927 #endif
  1927 
  1928 
  1928   static const arch_t arch_array[]={
  1929   static const arch_t arch_array[]={
  1929     {EM_386,         EM_386,     ELFCLASS32, ELFDATA2LSB, (char*)"IA 32"},
  1930     {EM_386,         EM_386,     ELFCLASS32, ELFDATA2LSB, (char*)"IA 32"},
  1930     {EM_486,         EM_386,     ELFCLASS32, ELFDATA2LSB, (char*)"IA 32"},
  1931     {EM_486,         EM_386,     ELFCLASS32, ELFDATA2LSB, (char*)"IA 32"},
  1931     {EM_IA_64,       EM_IA_64,   ELFCLASS64, ELFDATA2LSB, (char*)"IA 64"},
  1932     {EM_IA_64,       EM_IA_64,   ELFCLASS64, ELFDATA2LSB, (char*)"IA 64"},
  1946     {EM_MIPS,        EM_MIPS,    ELFCLASS32, ELFDATA2MSB, (char*)"MIPS"},
  1947     {EM_MIPS,        EM_MIPS,    ELFCLASS32, ELFDATA2MSB, (char*)"MIPS"},
  1947     {EM_PARISC,      EM_PARISC,  ELFCLASS32, ELFDATA2MSB, (char*)"PARISC"},
  1948     {EM_PARISC,      EM_PARISC,  ELFCLASS32, ELFDATA2MSB, (char*)"PARISC"},
  1948     {EM_68K,         EM_68K,     ELFCLASS32, ELFDATA2MSB, (char*)"M68k"}
  1949     {EM_68K,         EM_68K,     ELFCLASS32, ELFDATA2MSB, (char*)"M68k"}
  1949   };
  1950   };
  1950 
  1951 
  1951   #if  (defined IA32)
  1952 #if  (defined IA32)
  1952   static  Elf32_Half running_arch_code=EM_386;
  1953   static  Elf32_Half running_arch_code=EM_386;
  1953   #elif   (defined AMD64)
  1954 #elif   (defined AMD64)
  1954   static  Elf32_Half running_arch_code=EM_X86_64;
  1955   static  Elf32_Half running_arch_code=EM_X86_64;
  1955   #elif  (defined IA64)
  1956 #elif  (defined IA64)
  1956   static  Elf32_Half running_arch_code=EM_IA_64;
  1957   static  Elf32_Half running_arch_code=EM_IA_64;
  1957   #elif  (defined __sparc) && (defined _LP64)
  1958 #elif  (defined __sparc) && (defined _LP64)
  1958   static  Elf32_Half running_arch_code=EM_SPARCV9;
  1959   static  Elf32_Half running_arch_code=EM_SPARCV9;
  1959   #elif  (defined __sparc) && (!defined _LP64)
  1960 #elif  (defined __sparc) && (!defined _LP64)
  1960   static  Elf32_Half running_arch_code=EM_SPARC;
  1961   static  Elf32_Half running_arch_code=EM_SPARC;
  1961   #elif  (defined __powerpc64__)
  1962 #elif  (defined __powerpc64__)
  1962   static  Elf32_Half running_arch_code=EM_PPC64;
  1963   static  Elf32_Half running_arch_code=EM_PPC64;
  1963   #elif  (defined __powerpc__)
  1964 #elif  (defined __powerpc__)
  1964   static  Elf32_Half running_arch_code=EM_PPC;
  1965   static  Elf32_Half running_arch_code=EM_PPC;
  1965   #elif  (defined ARM)
  1966 #elif  (defined ARM)
  1966   static  Elf32_Half running_arch_code=EM_ARM;
  1967   static  Elf32_Half running_arch_code=EM_ARM;
  1967   #elif  (defined S390)
  1968 #elif  (defined S390)
  1968   static  Elf32_Half running_arch_code=EM_S390;
  1969   static  Elf32_Half running_arch_code=EM_S390;
  1969   #elif  (defined ALPHA)
  1970 #elif  (defined ALPHA)
  1970   static  Elf32_Half running_arch_code=EM_ALPHA;
  1971   static  Elf32_Half running_arch_code=EM_ALPHA;
  1971   #elif  (defined MIPSEL)
  1972 #elif  (defined MIPSEL)
  1972   static  Elf32_Half running_arch_code=EM_MIPS_RS3_LE;
  1973   static  Elf32_Half running_arch_code=EM_MIPS_RS3_LE;
  1973   #elif  (defined PARISC)
  1974 #elif  (defined PARISC)
  1974   static  Elf32_Half running_arch_code=EM_PARISC;
  1975   static  Elf32_Half running_arch_code=EM_PARISC;
  1975   #elif  (defined MIPS)
  1976 #elif  (defined MIPS)
  1976   static  Elf32_Half running_arch_code=EM_MIPS;
  1977   static  Elf32_Half running_arch_code=EM_MIPS;
  1977   #elif  (defined M68K)
  1978 #elif  (defined M68K)
  1978   static  Elf32_Half running_arch_code=EM_68K;
  1979   static  Elf32_Half running_arch_code=EM_68K;
  1979   #else
  1980 #else
  1980     #error Method os::dll_load requires that one of following is defined:\
  1981     #error Method os::dll_load requires that one of following is defined:\
  1981          IA32, AMD64, IA64, __sparc, __powerpc__, ARM, S390, ALPHA, MIPS, MIPSEL, PARISC, M68K
  1982          IA32, AMD64, IA64, __sparc, __powerpc__, ARM, S390, ALPHA, MIPS, MIPSEL, PARISC, M68K
  1982   #endif
  1983 #endif
  1983 
  1984 
  1984   // Identify compatability class for VM's architecture and library's architecture
  1985   // Identify compatability class for VM's architecture and library's architecture
  1985   // Obtain string descriptions for architectures
  1986   // Obtain string descriptions for architectures
  1986 
  1987 
  1987   arch_t lib_arch={elf_head.e_machine,0,elf_head.e_ident[EI_CLASS], elf_head.e_ident[EI_DATA], NULL};
  1988   arch_t lib_arch={elf_head.e_machine,0,elf_head.e_ident[EI_CLASS], elf_head.e_ident[EI_DATA], NULL};
  2031   }
  2032   }
  2032 
  2033 
  2033   return NULL;
  2034   return NULL;
  2034 }
  2035 }
  2035 
  2036 
  2036 void * os::Linux::dlopen_helper(const char *filename, char *ebuf, int ebuflen) {
  2037 void * os::Linux::dlopen_helper(const char *filename, char *ebuf,
       
  2038                                 int ebuflen) {
  2037   void * result = ::dlopen(filename, RTLD_LAZY);
  2039   void * result = ::dlopen(filename, RTLD_LAZY);
  2038   if (result == NULL) {
  2040   if (result == NULL) {
  2039     ::strncpy(ebuf, ::dlerror(), ebuflen - 1);
  2041     ::strncpy(ebuf, ::dlerror(), ebuflen - 1);
  2040     ebuf[ebuflen-1] = '\0';
  2042     ebuf[ebuflen-1] = '\0';
  2041   }
  2043   }
  2042   return result;
  2044   return result;
  2043 }
  2045 }
  2044 
  2046 
  2045 void * os::Linux::dll_load_in_vmthread(const char *filename, char *ebuf, int ebuflen) {
  2047 void * os::Linux::dll_load_in_vmthread(const char *filename, char *ebuf,
       
  2048                                        int ebuflen) {
  2046   void * result = NULL;
  2049   void * result = NULL;
  2047   if (LoadExecStackDllInVMThread) {
  2050   if (LoadExecStackDllInVMThread) {
  2048     result = dlopen_helper(filename, ebuf, ebuflen);
  2051     result = dlopen_helper(filename, ebuf, ebuflen);
  2049   }
  2052   }
  2050 
  2053 
  2072   }
  2075   }
  2073 
  2076 
  2074   return result;
  2077   return result;
  2075 }
  2078 }
  2076 
  2079 
  2077 /*
  2080 // glibc-2.0 libdl is not MT safe.  If you are building with any glibc,
  2078  * glibc-2.0 libdl is not MT safe.  If you are building with any glibc,
  2081 // chances are you might want to run the generated bits against glibc-2.0
  2079  * chances are you might want to run the generated bits against glibc-2.0
  2082 // libdl.so, so always use locking for any version of glibc.
  2080  * libdl.so, so always use locking for any version of glibc.
  2083 //
  2081  */
       
  2082 void* os::dll_lookup(void* handle, const char* name) {
  2084 void* os::dll_lookup(void* handle, const char* name) {
  2083   pthread_mutex_lock(&dl_mutex);
  2085   pthread_mutex_lock(&dl_mutex);
  2084   void* res = dlsym(handle, name);
  2086   void* res = dlsym(handle, name);
  2085   pthread_mutex_unlock(&dl_mutex);
  2087   pthread_mutex_unlock(&dl_mutex);
  2086   return res;
  2088   return res;
  2306   assert(ret, "cannot locate libjvm");
  2308   assert(ret, "cannot locate libjvm");
  2307   char *rp = NULL;
  2309   char *rp = NULL;
  2308   if (ret && dli_fname[0] != '\0') {
  2310   if (ret && dli_fname[0] != '\0') {
  2309     rp = realpath(dli_fname, buf);
  2311     rp = realpath(dli_fname, buf);
  2310   }
  2312   }
  2311   if (rp == NULL)
  2313   if (rp == NULL) {
  2312     return;
  2314     return;
       
  2315   }
  2313 
  2316 
  2314   if (Arguments::sun_java_launcher_is_altjvm()) {
  2317   if (Arguments::sun_java_launcher_is_altjvm()) {
  2315     // Support for the java launcher's '-XXaltjvm=<path>' option. Typical
  2318     // Support for the java launcher's '-XXaltjvm=<path>' option. Typical
  2316     // value for buf is "<JAVA_HOME>/jre/lib/<arch>/<vmtype>/libjvm.so".
  2319     // value for buf is "<JAVA_HOME>/jre/lib/<arch>/<vmtype>/libjvm.so".
  2317     // If "/jre/lib/" appears at the right place in the string, then
  2320     // If "/jre/lib/" appears at the right place in the string, then
  2335         // Check the current module name "libjvm.so".
  2338         // Check the current module name "libjvm.so".
  2336         p = strrchr(buf, '/');
  2339         p = strrchr(buf, '/');
  2337         assert(strstr(p, "/libjvm") == p, "invalid library name");
  2340         assert(strstr(p, "/libjvm") == p, "invalid library name");
  2338 
  2341 
  2339         rp = realpath(java_home_var, buf);
  2342         rp = realpath(java_home_var, buf);
  2340         if (rp == NULL)
  2343         if (rp == NULL) {
  2341           return;
  2344           return;
       
  2345         }
  2342 
  2346 
  2343         // determine if this is a legacy image or modules image
  2347         // determine if this is a legacy image or modules image
  2344         // modules image doesn't have "jre" subdirectory
  2348         // modules image doesn't have "jre" subdirectory
  2345         len = strlen(buf);
  2349         len = strlen(buf);
  2346         assert(len < buflen, "Ran out of buffer room");
  2350         assert(len < buflen, "Ran out of buffer room");
  2355           len = strlen(buf);
  2359           len = strlen(buf);
  2356           snprintf(buf + len, buflen-len, "/hotspot/libjvm.so");
  2360           snprintf(buf + len, buflen-len, "/hotspot/libjvm.so");
  2357         } else {
  2361         } else {
  2358           // Go back to path of .so
  2362           // Go back to path of .so
  2359           rp = realpath(dli_fname, buf);
  2363           rp = realpath(dli_fname, buf);
  2360           if (rp == NULL)
  2364           if (rp == NULL) {
  2361             return;
  2365             return;
       
  2366           }
  2362         }
  2367         }
  2363       }
  2368       }
  2364     }
  2369     }
  2365   }
  2370   }
  2366 
  2371 
  2378 ////////////////////////////////////////////////////////////////////////////////
  2383 ////////////////////////////////////////////////////////////////////////////////
  2379 // sun.misc.Signal support
  2384 // sun.misc.Signal support
  2380 
  2385 
  2381 static volatile jint sigint_count = 0;
  2386 static volatile jint sigint_count = 0;
  2382 
  2387 
  2383 static void
  2388 static void UserHandler(int sig, void *siginfo, void *context) {
  2384 UserHandler(int sig, void *siginfo, void *context) {
       
  2385   // 4511530 - sem_post is serialized and handled by the manager thread. When
  2389   // 4511530 - sem_post is serialized and handled by the manager thread. When
  2386   // the program is interrupted by Ctrl-C, SIGINT is sent to every thread. We
  2390   // the program is interrupted by Ctrl-C, SIGINT is sent to every thread. We
  2387   // don't want to flood the manager thread with sem_post requests.
  2391   // don't want to flood the manager thread with sem_post requests.
  2388   if (sig == SIGINT && Atomic::add(1, &sigint_count) > 1)
  2392   if (sig == SIGINT && Atomic::add(1, &sigint_count) > 1) {
  2389     return;
  2393     return;
       
  2394   }
  2390 
  2395 
  2391   // Ctrl-C is pressed during error reporting, likely because the error
  2396   // Ctrl-C is pressed during error reporting, likely because the error
  2392   // handler fails to abort. Let VM die immediately.
  2397   // handler fails to abort. Let VM die immediately.
  2393   if (sig == SIGINT && is_error_reported()) {
  2398   if (sig == SIGINT && is_error_reported()) {
  2394     os::die();
  2399     os::die();
  2487 
  2492 
  2488 void os::signal_raise(int signal_number) {
  2493 void os::signal_raise(int signal_number) {
  2489   ::raise(signal_number);
  2494   ::raise(signal_number);
  2490 }
  2495 }
  2491 
  2496 
  2492 /*
  2497 // The following code is moved from os.cpp for making this
  2493  * The following code is moved from os.cpp for making this
  2498 // code platform specific, which it is by its very nature.
  2494  * code platform specific, which it is by its very nature.
       
  2495  */
       
  2496 
  2499 
  2497 // Will be modified when max signal is changed to be dynamic
  2500 // Will be modified when max signal is changed to be dynamic
  2498 int os::sigexitnum_pd() {
  2501 int os::sigexitnum_pd() {
  2499   return NSIG;
  2502   return NSIG;
  2500 }
  2503 }
  2541       ::sem_wait(&sig_sem);
  2544       ::sem_wait(&sig_sem);
  2542 
  2545 
  2543       // were we externally suspended while we were waiting?
  2546       // were we externally suspended while we were waiting?
  2544       threadIsSuspended = thread->handle_special_suspend_equivalent_condition();
  2547       threadIsSuspended = thread->handle_special_suspend_equivalent_condition();
  2545       if (threadIsSuspended) {
  2548       if (threadIsSuspended) {
  2546         //
       
  2547         // The semaphore has been incremented, but while we were waiting
  2549         // The semaphore has been incremented, but while we were waiting
  2548         // another thread suspended us. We don't want to continue running
  2550         // another thread suspended us. We don't want to continue running
  2549         // while suspended because that would surprise the thread that
  2551         // while suspended because that would surprise the thread that
  2550         // suspended us.
  2552         // suspended us.
  2551         //
       
  2552         ::sem_post(&sig_sem);
  2553         ::sem_post(&sig_sem);
  2553 
  2554 
  2554         thread->java_suspend_self();
  2555         thread->java_suspend_self();
  2555       }
  2556       }
  2556     } while (threadIsSuspended);
  2557     } while (threadIsSuspended);
  2694   }
  2695   }
  2695 }
  2696 }
  2696 
  2697 
  2697 // Define MAP_HUGETLB here so we can build HotSpot on old systems.
  2698 // Define MAP_HUGETLB here so we can build HotSpot on old systems.
  2698 #ifndef MAP_HUGETLB
  2699 #ifndef MAP_HUGETLB
  2699 #define MAP_HUGETLB 0x40000
  2700   #define MAP_HUGETLB 0x40000
  2700 #endif
  2701 #endif
  2701 
  2702 
  2702 // Define MADV_HUGEPAGE here so we can build HotSpot on old systems.
  2703 // Define MADV_HUGEPAGE here so we can build HotSpot on old systems.
  2703 #ifndef MADV_HUGEPAGE
  2704 #ifndef MADV_HUGEPAGE
  2704 #define MADV_HUGEPAGE 14
  2705   #define MADV_HUGEPAGE 14
  2705 #endif
  2706 #endif
  2706 
  2707 
  2707 int os::Linux::commit_memory_impl(char* addr, size_t size,
  2708 int os::Linux::commit_memory_impl(char* addr, size_t size,
  2708                                   size_t alignment_hint, bool exec) {
  2709                                   size_t alignment_hint, bool exec) {
  2709   int err = os::Linux::commit_memory_impl(addr, size, exec);
  2710   int err = os::Linux::commit_memory_impl(addr, size, exec);
  2767   // free large pages.
  2768   // free large pages.
  2768   Linux::numa_set_bind_policy(USE_MPOL_PREFERRED);
  2769   Linux::numa_set_bind_policy(USE_MPOL_PREFERRED);
  2769   Linux::numa_tonode_memory(addr, bytes, lgrp_hint);
  2770   Linux::numa_tonode_memory(addr, bytes, lgrp_hint);
  2770 }
  2771 }
  2771 
  2772 
  2772 bool os::numa_topology_changed()   { return false; }
  2773 bool os::numa_topology_changed() { return false; }
  2773 
  2774 
  2774 size_t os::numa_get_groups_num() {
  2775 size_t os::numa_get_groups_num() {
  2775   int max_node = Linux::numa_max_node();
  2776   int max_node = Linux::numa_max_node();
  2776   return max_node > 0 ? max_node + 1 : 1;
  2777   return max_node > 0 ? max_node + 1 : 1;
  2777 }
  2778 }
  2796 
  2797 
  2797 bool os::get_page_info(char *start, page_info* info) {
  2798 bool os::get_page_info(char *start, page_info* info) {
  2798   return false;
  2799   return false;
  2799 }
  2800 }
  2800 
  2801 
  2801 char *os::scan_pages(char *start, char* end, page_info* page_expected, page_info* page_found) {
  2802 char *os::scan_pages(char *start, char* end, page_info* page_expected,
       
  2803                      page_info* page_found) {
  2802   return end;
  2804   return end;
  2803 }
  2805 }
  2804 
  2806 
  2805 
  2807 
  2806 int os::Linux::sched_getcpu_syscall(void) {
  2808 int os::Linux::sched_getcpu_syscall(void) {
  2807   unsigned int cpu;
  2809   unsigned int cpu;
  2808   int retval = -1;
  2810   int retval = -1;
  2809 
  2811 
  2810 #if defined(IA32)
  2812 #if defined(IA32)
  2811 # ifndef SYS_getcpu
  2813   #ifndef SYS_getcpu
  2812 # define SYS_getcpu 318
  2814     #define SYS_getcpu 318
  2813 # endif
  2815   #endif
  2814   retval = syscall(SYS_getcpu, &cpu, NULL, NULL);
  2816   retval = syscall(SYS_getcpu, &cpu, NULL, NULL);
  2815 #elif defined(AMD64)
  2817 #elif defined(AMD64)
  2816 // Unfortunately we have to bring all these macros here from vsyscall.h
  2818 // Unfortunately we have to bring all these macros here from vsyscall.h
  2817 // to be able to compile on old linuxes.
  2819 // to be able to compile on old linuxes.
  2818 # define __NR_vgetcpu 2
  2820   #define __NR_vgetcpu 2
  2819 # define VSYSCALL_START (-10UL << 20)
  2821   #define VSYSCALL_START (-10UL << 20)
  2820 # define VSYSCALL_SIZE 1024
  2822   #define VSYSCALL_SIZE 1024
  2821 # define VSYSCALL_ADDR(vsyscall_nr) (VSYSCALL_START+VSYSCALL_SIZE*(vsyscall_nr))
  2823   #define VSYSCALL_ADDR(vsyscall_nr) (VSYSCALL_START+VSYSCALL_SIZE*(vsyscall_nr))
  2822   typedef long (*vgetcpu_t)(unsigned int *cpu, unsigned int *node, unsigned long *tcache);
  2824   typedef long (*vgetcpu_t)(unsigned int *cpu, unsigned int *node, unsigned long *tcache);
  2823   vgetcpu_t vgetcpu = (vgetcpu_t)VSYSCALL_ADDR(__NR_vgetcpu);
  2825   vgetcpu_t vgetcpu = (vgetcpu_t)VSYSCALL_ADDR(__NR_vgetcpu);
  2824   retval = vgetcpu(&cpu, NULL, NULL);
  2826   retval = vgetcpu(&cpu, NULL, NULL);
  2825 #endif
  2827 #endif
  2826 
  2828 
  2849   // sched_getcpu() should be in libc.
  2851   // sched_getcpu() should be in libc.
  2850   set_sched_getcpu(CAST_TO_FN_PTR(sched_getcpu_func_t,
  2852   set_sched_getcpu(CAST_TO_FN_PTR(sched_getcpu_func_t,
  2851                                   dlsym(RTLD_DEFAULT, "sched_getcpu")));
  2853                                   dlsym(RTLD_DEFAULT, "sched_getcpu")));
  2852 
  2854 
  2853   // If it's not, try a direct syscall.
  2855   // If it's not, try a direct syscall.
  2854   if (sched_getcpu() == -1)
  2856   if (sched_getcpu() == -1) {
  2855     set_sched_getcpu(CAST_TO_FN_PTR(sched_getcpu_func_t, (void*)&sched_getcpu_syscall));
  2857     set_sched_getcpu(CAST_TO_FN_PTR(sched_getcpu_func_t,
       
  2858                                     (void*)&sched_getcpu_syscall));
       
  2859   }
  2856 
  2860 
  2857   if (sched_getcpu() != -1) { // Does it work?
  2861   if (sched_getcpu() != -1) { // Does it work?
  2858     void *handle = dlopen("libnuma.so.1", RTLD_LAZY);
  2862     void *handle = dlopen("libnuma.so.1", RTLD_LAZY);
  2859     if (handle != NULL) {
  2863     if (handle != NULL) {
  2860       set_numa_node_to_cpus(CAST_TO_FN_PTR(numa_node_to_cpus_func_t,
  2864       set_numa_node_to_cpus(CAST_TO_FN_PTR(numa_node_to_cpus_func_t,
  2942   uintptr_t res = (uintptr_t) ::mmap(addr, size, PROT_NONE,
  2946   uintptr_t res = (uintptr_t) ::mmap(addr, size, PROT_NONE,
  2943                                      MAP_PRIVATE|MAP_FIXED|MAP_NORESERVE|MAP_ANONYMOUS, -1, 0);
  2947                                      MAP_PRIVATE|MAP_FIXED|MAP_NORESERVE|MAP_ANONYMOUS, -1, 0);
  2944   return res  != (uintptr_t) MAP_FAILED;
  2948   return res  != (uintptr_t) MAP_FAILED;
  2945 }
  2949 }
  2946 
  2950 
  2947 static
  2951 static address get_stack_commited_bottom(address bottom, size_t size) {
  2948 address get_stack_commited_bottom(address bottom, size_t size) {
       
  2949   address nbot = bottom;
  2952   address nbot = bottom;
  2950   address ntop = bottom + size;
  2953   address ntop = bottom + size;
  2951 
  2954 
  2952   size_t page_sz = os::vm_page_size();
  2955   size_t page_sz = os::vm_page_size();
  2953   unsigned pages = size / page_sz;
  2956   unsigned pages = size / page_sz;
  3017 // that point by munmap()ping it.  This ensures that when we later
  3020 // that point by munmap()ping it.  This ensures that when we later
  3018 // munmap() the guard pages we don't leave a hole in the stack
  3021 // munmap() the guard pages we don't leave a hole in the stack
  3019 // mapping. This only affects the main/initial thread
  3022 // mapping. This only affects the main/initial thread
  3020 
  3023 
  3021 bool os::pd_create_stack_guard_pages(char* addr, size_t size) {
  3024 bool os::pd_create_stack_guard_pages(char* addr, size_t size) {
  3022 
       
  3023   if (os::Linux::is_initial_thread()) {
  3025   if (os::Linux::is_initial_thread()) {
  3024     // As we manually grow stack up to bottom inside create_attached_thread(),
  3026     // As we manually grow stack up to bottom inside create_attached_thread(),
  3025     // it's likely that os::Linux::initial_thread_stack_bottom is mapped and
  3027     // it's likely that os::Linux::initial_thread_stack_bottom is mapped and
  3026     // we don't need to do anything special.
  3028     // we don't need to do anything special.
  3027     // Check it first, before calling heavy function.
  3029     // Check it first, before calling heavy function.
  3154 
  3156 
  3155 bool os::unguard_memory(char* addr, size_t size) {
  3157 bool os::unguard_memory(char* addr, size_t size) {
  3156   return linux_mprotect(addr, size, PROT_READ|PROT_WRITE);
  3158   return linux_mprotect(addr, size, PROT_READ|PROT_WRITE);
  3157 }
  3159 }
  3158 
  3160 
  3159 bool os::Linux::transparent_huge_pages_sanity_check(bool warn, size_t page_size) {
  3161 bool os::Linux::transparent_huge_pages_sanity_check(bool warn,
       
  3162                                                     size_t page_size) {
  3160   bool result = false;
  3163   bool result = false;
  3161   void *p = mmap(NULL, page_size * 2, PROT_READ|PROT_WRITE,
  3164   void *p = mmap(NULL, page_size * 2, PROT_READ|PROT_WRITE,
  3162                  MAP_ANONYMOUS|MAP_PRIVATE,
  3165                  MAP_ANONYMOUS|MAP_PRIVATE,
  3163                  -1, 0);
  3166                  -1, 0);
  3164   if (p != MAP_FAILED) {
  3167   if (p != MAP_FAILED) {
  3209   }
  3212   }
  3210 
  3213 
  3211   return result;
  3214   return result;
  3212 }
  3215 }
  3213 
  3216 
  3214 /*
  3217 // Set the coredump_filter bits to include largepages in core dump (bit 6)
  3215 * Set the coredump_filter bits to include largepages in core dump (bit 6)
  3218 //
  3216 *
  3219 // From the coredump_filter documentation:
  3217 * From the coredump_filter documentation:
  3220 //
  3218 *
  3221 // - (bit 0) anonymous private memory
  3219 * - (bit 0) anonymous private memory
  3222 // - (bit 1) anonymous shared memory
  3220 * - (bit 1) anonymous shared memory
  3223 // - (bit 2) file-backed private memory
  3221 * - (bit 2) file-backed private memory
  3224 // - (bit 3) file-backed shared memory
  3222 * - (bit 3) file-backed shared memory
  3225 // - (bit 4) ELF header pages in file-backed private memory areas (it is
  3223 * - (bit 4) ELF header pages in file-backed private memory areas (it is
  3226 //           effective only if the bit 2 is cleared)
  3224 *           effective only if the bit 2 is cleared)
  3227 // - (bit 5) hugetlb private memory
  3225 * - (bit 5) hugetlb private memory
  3228 // - (bit 6) hugetlb shared memory
  3226 * - (bit 6) hugetlb shared memory
  3229 //
  3227 */
       
  3228 static void set_coredump_filter(void) {
  3230 static void set_coredump_filter(void) {
  3229   FILE *f;
  3231   FILE *f;
  3230   long cdm;
  3232   long cdm;
  3231 
  3233 
  3232   if ((f = fopen("/proc/self/coredump_filter", "r+")) == NULL) {
  3234   if ((f = fopen("/proc/self/coredump_filter", "r+")) == NULL) {
  3375 
  3377 
  3376   set_coredump_filter();
  3378   set_coredump_filter();
  3377 }
  3379 }
  3378 
  3380 
  3379 #ifndef SHM_HUGETLB
  3381 #ifndef SHM_HUGETLB
  3380 #define SHM_HUGETLB 04000
  3382   #define SHM_HUGETLB 04000
  3381 #endif
  3383 #endif
  3382 
  3384 
  3383 char* os::Linux::reserve_memory_special_shm(size_t bytes, size_t alignment, char* req_addr, bool exec) {
  3385 char* os::Linux::reserve_memory_special_shm(size_t bytes, size_t alignment,
       
  3386                                             char* req_addr, bool exec) {
  3384   // "exec" is passed in but not used.  Creating the shared image for
  3387   // "exec" is passed in but not used.  Creating the shared image for
  3385   // the code cache doesn't have an SHM_X executable permission to check.
  3388   // the code cache doesn't have an SHM_X executable permission to check.
  3386   assert(UseLargePages && UseSHM, "only for SHM large pages");
  3389   assert(UseLargePages && UseSHM, "only for SHM large pages");
  3387   assert(is_ptr_aligned(req_addr, os::large_page_size()), "Unaligned address");
  3390   assert(is_ptr_aligned(req_addr, os::large_page_size()), "Unaligned address");
  3388 
  3391 
  3394   char *addr;
  3397   char *addr;
  3395 
  3398 
  3396   bool warn_on_failure = UseLargePages &&
  3399   bool warn_on_failure = UseLargePages &&
  3397                         (!FLAG_IS_DEFAULT(UseLargePages) ||
  3400                         (!FLAG_IS_DEFAULT(UseLargePages) ||
  3398                          !FLAG_IS_DEFAULT(UseSHM) ||
  3401                          !FLAG_IS_DEFAULT(UseSHM) ||
  3399                          !FLAG_IS_DEFAULT(LargePageSizeInBytes)
  3402                          !FLAG_IS_DEFAULT(LargePageSizeInBytes));
  3400                         );
       
  3401   char msg[128];
  3403   char msg[128];
  3402 
  3404 
  3403   // Create a large shared memory region to attach to based on size.
  3405   // Create a large shared memory region to attach to based on size.
  3404   // Currently, size is the total size of the heap
  3406   // Currently, size is the total size of the heap
  3405   int shmid = shmget(key, bytes, SHM_HUGETLB|IPC_CREAT|SHM_R|SHM_W);
  3407   int shmid = shmget(key, bytes, SHM_HUGETLB|IPC_CREAT|SHM_R|SHM_W);
  3444   }
  3446   }
  3445 
  3447 
  3446   return addr;
  3448   return addr;
  3447 }
  3449 }
  3448 
  3450 
  3449 static void warn_on_large_pages_failure(char* req_addr, size_t bytes, int error) {
  3451 static void warn_on_large_pages_failure(char* req_addr, size_t bytes,
       
  3452                                         int error) {
  3450   assert(error == ENOMEM, "Only expect to fail if no memory is available");
  3453   assert(error == ENOMEM, "Only expect to fail if no memory is available");
  3451 
  3454 
  3452   bool warn_on_failure = UseLargePages &&
  3455   bool warn_on_failure = UseLargePages &&
  3453       (!FLAG_IS_DEFAULT(UseLargePages) ||
  3456       (!FLAG_IS_DEFAULT(UseLargePages) ||
  3454        !FLAG_IS_DEFAULT(UseHugeTLBFS) ||
  3457        !FLAG_IS_DEFAULT(UseHugeTLBFS) ||
  3460                  PTR_FORMAT " bytes: " SIZE_FORMAT " (errno = %d).", req_addr, bytes, error);
  3463                  PTR_FORMAT " bytes: " SIZE_FORMAT " (errno = %d).", req_addr, bytes, error);
  3461     warning("%s", msg);
  3464     warning("%s", msg);
  3462   }
  3465   }
  3463 }
  3466 }
  3464 
  3467 
  3465 char* os::Linux::reserve_memory_special_huge_tlbfs_only(size_t bytes, char* req_addr, bool exec) {
  3468 char* os::Linux::reserve_memory_special_huge_tlbfs_only(size_t bytes,
       
  3469                                                         char* req_addr,
       
  3470                                                         bool exec) {
  3466   assert(UseLargePages && UseHugeTLBFS, "only for Huge TLBFS large pages");
  3471   assert(UseLargePages && UseHugeTLBFS, "only for Huge TLBFS large pages");
  3467   assert(is_size_aligned(bytes, os::large_page_size()), "Unaligned size");
  3472   assert(is_size_aligned(bytes, os::large_page_size()), "Unaligned size");
  3468   assert(is_ptr_aligned(req_addr, os::large_page_size()), "Unaligned address");
  3473   assert(is_ptr_aligned(req_addr, os::large_page_size()), "Unaligned address");
  3469 
  3474 
  3470   int prot = exec ? PROT_READ|PROT_WRITE|PROT_EXEC : PROT_READ|PROT_WRITE;
  3475   int prot = exec ? PROT_READ|PROT_WRITE|PROT_EXEC : PROT_READ|PROT_WRITE;
  3480   assert(is_ptr_aligned(addr, os::large_page_size()), "Must be");
  3485   assert(is_ptr_aligned(addr, os::large_page_size()), "Must be");
  3481 
  3486 
  3482   return addr;
  3487   return addr;
  3483 }
  3488 }
  3484 
  3489 
  3485 char* os::Linux::reserve_memory_special_huge_tlbfs_mixed(size_t bytes, size_t alignment, char* req_addr, bool exec) {
  3490 char* os::Linux::reserve_memory_special_huge_tlbfs_mixed(size_t bytes,
       
  3491                                                          size_t alignment,
       
  3492                                                          char* req_addr,
       
  3493                                                          bool exec) {
  3486   size_t large_page_size = os::large_page_size();
  3494   size_t large_page_size = os::large_page_size();
  3487 
  3495 
  3488   assert(bytes >= large_page_size, "Shouldn't allocate large pages for small sizes");
  3496   assert(bytes >= large_page_size, "Shouldn't allocate large pages for small sizes");
  3489 
  3497 
  3490   // Allocate small pages.
  3498   // Allocate small pages.
  3572   }
  3580   }
  3573 
  3581 
  3574   return start;
  3582   return start;
  3575 }
  3583 }
  3576 
  3584 
  3577 char* os::Linux::reserve_memory_special_huge_tlbfs(size_t bytes, size_t alignment, char* req_addr, bool exec) {
  3585 char* os::Linux::reserve_memory_special_huge_tlbfs(size_t bytes,
       
  3586                                                    size_t alignment,
       
  3587                                                    char* req_addr,
       
  3588                                                    bool exec) {
  3578   assert(UseLargePages && UseHugeTLBFS, "only for Huge TLBFS large pages");
  3589   assert(UseLargePages && UseHugeTLBFS, "only for Huge TLBFS large pages");
  3579   assert(is_ptr_aligned(req_addr, alignment), "Must be");
  3590   assert(is_ptr_aligned(req_addr, alignment), "Must be");
  3580   assert(is_power_of_2(alignment), "Must be");
  3591   assert(is_power_of_2(alignment), "Must be");
  3581   assert(is_power_of_2(os::large_page_size()), "Must be");
  3592   assert(is_power_of_2(os::large_page_size()), "Must be");
  3582   assert(bytes >= os::large_page_size(), "Shouldn't allocate large pages for small sizes");
  3593   assert(bytes >= os::large_page_size(), "Shouldn't allocate large pages for small sizes");
  3586   } else {
  3597   } else {
  3587     return reserve_memory_special_huge_tlbfs_mixed(bytes, alignment, req_addr, exec);
  3598     return reserve_memory_special_huge_tlbfs_mixed(bytes, alignment, req_addr, exec);
  3588   }
  3599   }
  3589 }
  3600 }
  3590 
  3601 
  3591 char* os::reserve_memory_special(size_t bytes, size_t alignment, char* req_addr, bool exec) {
  3602 char* os::reserve_memory_special(size_t bytes, size_t alignment,
       
  3603                                  char* req_addr, bool exec) {
  3592   assert(UseLargePages, "only for large pages");
  3604   assert(UseLargePages, "only for large pages");
  3593 
  3605 
  3594   char* addr;
  3606   char* addr;
  3595   if (UseSHM) {
  3607   if (UseSHM) {
  3596     addr = os::Linux::reserve_memory_special_shm(bytes, alignment, req_addr, exec);
  3608     addr = os::Linux::reserve_memory_special_shm(bytes, alignment, req_addr, exec);
  3756 
  3768 
  3757 size_t os::read(int fd, void *buf, unsigned int nBytes) {
  3769 size_t os::read(int fd, void *buf, unsigned int nBytes) {
  3758   return ::read(fd, buf, nBytes);
  3770   return ::read(fd, buf, nBytes);
  3759 }
  3771 }
  3760 
  3772 
  3761 //
       
  3762 // Short sleep, direct OS call.
  3773 // Short sleep, direct OS call.
  3763 //
  3774 //
  3764 // Note: certain versions of Linux CFS scheduler (since 2.6.23) do not guarantee
  3775 // Note: certain versions of Linux CFS scheduler (since 2.6.23) do not guarantee
  3765 // sched_yield(2) will actually give up the CPU:
  3776 // sched_yield(2) will actually give up the CPU:
  3766 //
  3777 //
  3775 
  3786 
  3776   assert(ms < 1000, "Un-interruptable sleep, short time use only");
  3787   assert(ms < 1000, "Un-interruptable sleep, short time use only");
  3777   req.tv_sec = 0;
  3788   req.tv_sec = 0;
  3778   if (ms > 0) {
  3789   if (ms > 0) {
  3779     req.tv_nsec = (ms % 1000) * 1000000;
  3790     req.tv_nsec = (ms % 1000) * 1000000;
  3780   }
  3791   } else {
  3781   else {
       
  3782     req.tv_nsec = 1;
  3792     req.tv_nsec = 1;
  3783   }
  3793   }
  3784 
  3794 
  3785   nanosleep(&req, NULL);
  3795   nanosleep(&req, NULL);
  3786 
  3796 
  3863 
  3873 
  3864   int ret = setpriority(PRIO_PROCESS, thread->osthread()->thread_id(), newpri);
  3874   int ret = setpriority(PRIO_PROCESS, thread->osthread()->thread_id(), newpri);
  3865   return (ret == 0) ? OS_OK : OS_ERR;
  3875   return (ret == 0) ? OS_OK : OS_ERR;
  3866 }
  3876 }
  3867 
  3877 
  3868 OSReturn os::get_native_priority(const Thread* const thread, int *priority_ptr) {
  3878 OSReturn os::get_native_priority(const Thread* const thread,
       
  3879                                  int *priority_ptr) {
  3869   if (!UseThreadPriorities || ThreadPriorityPolicy == 0) {
  3880   if (!UseThreadPriorities || ThreadPriorityPolicy == 0) {
  3870     *priority_ptr = java_to_os_priority[NormPriority];
  3881     *priority_ptr = java_to_os_priority[NormPriority];
  3871     return OS_OK;
  3882     return OS_OK;
  3872   }
  3883   }
  3873 
  3884 
  3900 //  - resume:
  3911 //  - resume:
  3901 //      - sets target osthread state to continue
  3912 //      - sets target osthread state to continue
  3902 //      - sends signal to end the sigsuspend loop in the SR_handler
  3913 //      - sends signal to end the sigsuspend loop in the SR_handler
  3903 //
  3914 //
  3904 //  Note that the SR_lock plays no role in this suspend/resume protocol.
  3915 //  Note that the SR_lock plays no role in this suspend/resume protocol.
  3905 //
       
  3906 
  3916 
  3907 static void resume_clear_context(OSThread *osthread) {
  3917 static void resume_clear_context(OSThread *osthread) {
  3908   osthread->set_ucontext(NULL);
  3918   osthread->set_ucontext(NULL);
  3909   osthread->set_siginfo(NULL);
  3919   osthread->set_siginfo(NULL);
  3910 }
  3920 }
  3911 
  3921 
  3912 static void suspend_save_context(OSThread *osthread, siginfo_t* siginfo, ucontext_t* context) {
  3922 static void suspend_save_context(OSThread *osthread, siginfo_t* siginfo,
       
  3923                                  ucontext_t* context) {
  3913   osthread->set_ucontext(context);
  3924   osthread->set_ucontext(context);
  3914   osthread->set_siginfo(siginfo);
  3925   osthread->set_siginfo(siginfo);
  3915 }
  3926 }
  3916 
  3927 
  3917 //
       
  3918 // Handler function invoked when a thread's execution is suspended or
  3928 // Handler function invoked when a thread's execution is suspended or
  3919 // resumed. We have to be careful that only async-safe functions are
  3929 // resumed. We have to be careful that only async-safe functions are
  3920 // called here (Note: most pthread functions are not async safe and
  3930 // called here (Note: most pthread functions are not async safe and
  3921 // should be avoided.)
  3931 // should be avoided.)
  3922 //
  3932 //
  3982 
  3992 
  3983 
  3993 
  3984 static int SR_initialize() {
  3994 static int SR_initialize() {
  3985   struct sigaction act;
  3995   struct sigaction act;
  3986   char *s;
  3996   char *s;
  3987   /* Get signal number to use for suspend/resume */
  3997   // Get signal number to use for suspend/resume
  3988   if ((s = ::getenv("_JAVA_SR_SIGNUM")) != 0) {
  3998   if ((s = ::getenv("_JAVA_SR_SIGNUM")) != 0) {
  3989     int sig = ::strtol(s, 0, 10);
  3999     int sig = ::strtol(s, 0, 10);
  3990     if (sig > 0 || sig < _NSIG) {
  4000     if (sig > 0 || sig < _NSIG) {
  3991       SR_signum = sig;
  4001       SR_signum = sig;
  3992     }
  4002     }
  3996          "SR_signum must be greater than max(SIGSEGV, SIGBUS), see 4355769");
  4006          "SR_signum must be greater than max(SIGSEGV, SIGBUS), see 4355769");
  3997 
  4007 
  3998   sigemptyset(&SR_sigset);
  4008   sigemptyset(&SR_sigset);
  3999   sigaddset(&SR_sigset, SR_signum);
  4009   sigaddset(&SR_sigset, SR_signum);
  4000 
  4010 
  4001   /* Set up signal handler for suspend/resume */
  4011   // Set up signal handler for suspend/resume
  4002   act.sa_flags = SA_RESTART|SA_SIGINFO;
  4012   act.sa_flags = SA_RESTART|SA_SIGINFO;
  4003   act.sa_handler = (void (*)(int)) SR_handler;
  4013   act.sa_handler = (void (*)(int)) SR_handler;
  4004 
  4014 
  4005   // SR_signum is blocked by default.
  4015   // SR_signum is blocked by default.
  4006   // 4528190 - We also need to block pthread restart signal (32 on all
  4016   // 4528190 - We also need to block pthread restart signal (32 on all
  4122 // the sa_flags field passed to sigaction() includes SA_SIGINFO and SA_RESTART.
  4132 // the sa_flags field passed to sigaction() includes SA_SIGINFO and SA_RESTART.
  4123 //
  4133 //
  4124 // Note that the VM will print warnings if it detects conflicting signal
  4134 // Note that the VM will print warnings if it detects conflicting signal
  4125 // handlers, unless invoked with the option "-XX:+AllowUserSignalHandlers".
  4135 // handlers, unless invoked with the option "-XX:+AllowUserSignalHandlers".
  4126 //
  4136 //
  4127 extern "C" JNIEXPORT int
  4137 extern "C" JNIEXPORT int JVM_handle_linux_signal(int signo,
  4128 JVM_handle_linux_signal(int signo, siginfo_t* siginfo,
  4138                                                  siginfo_t* siginfo,
  4129                         void* ucontext, int abort_if_unrecognized);
  4139                                                  void* ucontext,
       
  4140                                                  int abort_if_unrecognized);
  4130 
  4141 
  4131 void signalHandler(int sig, siginfo_t* info, void* uc) {
  4142 void signalHandler(int sig, siginfo_t* info, void* uc) {
  4132   assert(info != NULL && uc != NULL, "it must be old kernel");
  4143   assert(info != NULL && uc != NULL, "it must be old kernel");
  4133   int orig_errno = errno;  // Preserve errno value over signal handler.
  4144   int orig_errno = errno;  // Preserve errno value over signal handler.
  4134   JVM_handle_linux_signal(sig, info, uc, true);
  4145   JVM_handle_linux_signal(sig, info, uc, true);
  4373 // to indicate, that some special sort of signal
  4384 // to indicate, that some special sort of signal
  4374 // trampoline is used.
  4385 // trampoline is used.
  4375 // We will never set this flag, and we should
  4386 // We will never set this flag, and we should
  4376 // ignore this flag in our diagnostic
  4387 // ignore this flag in our diagnostic
  4377 #ifdef SIGNIFICANT_SIGNAL_MASK
  4388 #ifdef SIGNIFICANT_SIGNAL_MASK
  4378 #undef SIGNIFICANT_SIGNAL_MASK
  4389   #undef SIGNIFICANT_SIGNAL_MASK
  4379 #endif
  4390 #endif
  4380 #define SIGNIFICANT_SIGNAL_MASK (~0x04000000)
  4391 #define SIGNIFICANT_SIGNAL_MASK (~0x04000000)
  4381 
  4392 
  4382 static const char* get_signal_handler_name(address handler,
  4393 static const char* get_signal_handler_name(address handler,
  4383                                            char* buf, int buflen) {
  4394                                            char* buf, int buflen) {
  4445   }
  4456   }
  4446   st->cr();
  4457   st->cr();
  4447 }
  4458 }
  4448 
  4459 
  4449 
  4460 
  4450 #define DO_SIGNAL_CHECK(sig) \
  4461 #define DO_SIGNAL_CHECK(sig)                      \
  4451   if (!sigismember(&check_signal_done, sig)) \
  4462   do {                                            \
  4452     os::Linux::check_signal_handler(sig)
  4463     if (!sigismember(&check_signal_done, sig)) {  \
       
  4464       os::Linux::check_signal_handler(sig);       \
       
  4465     }                                             \
       
  4466   } while (0)
  4453 
  4467 
  4454 // This method is a periodic task to check for misbehaving JNI applications
  4468 // This method is a periodic task to check for misbehaving JNI applications
  4455 // under CheckJNI, we can add any periodic checks here
  4469 // under CheckJNI, we can add any periodic checks here
  4456 
  4470 
  4457 void os::run_periodic_checks() {
  4471 void os::run_periodic_checks() {
  4458 
       
  4459   if (check_signals == false) return;
  4472   if (check_signals == false) return;
  4460 
  4473 
  4461   // SEGV and BUS if overridden could potentially prevent
  4474   // SEGV and BUS if overridden could potentially prevent
  4462   // generation of hs*.log in the event of a crash, debugging
  4475   // generation of hs*.log in the event of a crash, debugging
  4463   // such a case can be very challenging, so we absolutely
  4476   // such a case can be very challenging, so we absolutely
  4564   if (sigismember(&check_signal_done, sig)) {
  4577   if (sigismember(&check_signal_done, sig)) {
  4565     print_signal_handlers(tty, buf, O_BUFLEN);
  4578     print_signal_handlers(tty, buf, O_BUFLEN);
  4566   }
  4579   }
  4567 }
  4580 }
  4568 
  4581 
  4569 extern void report_error(char* file_name, int line_no, char* title, char* format, ...);
  4582 extern void report_error(char* file_name, int line_no, char* title,
       
  4583                          char* format, ...);
  4570 
  4584 
  4571 extern bool signal_name(int signo, char* buf, size_t len);
  4585 extern bool signal_name(int signo, char* buf, size_t len);
  4572 
  4586 
  4573 const char* os::exception_name(int exception_code, char* buf, size_t size) {
  4587 const char* os::exception_name(int exception_code, char* buf, size_t size) {
  4574   if (0 < exception_code && exception_code <= SIGRTMAX) {
  4588   if (0 < exception_code && exception_code <= SIGRTMAX) {
  4582   }
  4596   }
  4583 }
  4597 }
  4584 
  4598 
  4585 // this is called _before_ the most of global arguments have been parsed
  4599 // this is called _before_ the most of global arguments have been parsed
  4586 void os::init(void) {
  4600 void os::init(void) {
  4587   char dummy;   /* used to get a guess on initial stack address */
  4601   char dummy;   // used to get a guess on initial stack address
  4588 //  first_hrtime = gethrtime();
  4602 //  first_hrtime = gethrtime();
  4589 
  4603 
  4590   // With LinuxThreads the JavaMain thread pid (primordial thread)
  4604   // With LinuxThreads the JavaMain thread pid (primordial thread)
  4591   // is different than the pid of the java launcher thread.
  4605   // is different than the pid of the java launcher thread.
  4592   // So, on Linux, the launcher thread pid is passed to the VM
  4606   // So, on Linux, the launcher thread pid is passed to the VM
  4655     perfMemory_exit();
  4669     perfMemory_exit();
  4656   }
  4670   }
  4657 }
  4671 }
  4658 
  4672 
  4659 // this is called _after_ the global arguments have been parsed
  4673 // this is called _after_ the global arguments have been parsed
  4660 jint os::init_2(void)
  4674 jint os::init_2(void) {
  4661 {
       
  4662   Linux::fast_thread_clock_init();
  4675   Linux::fast_thread_clock_init();
  4663 
  4676 
  4664   // Allocate a single page and mark it as readable for safepoint polling
  4677   // Allocate a single page and mark it as readable for safepoint polling
  4665   address polling_page = (address) ::mmap(NULL, Linux::page_size(), PROT_READ, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
  4678   address polling_page = (address) ::mmap(NULL, Linux::page_size(), PROT_READ, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
  4666   guarantee(polling_page != MAP_FAILED, "os::init_2: failed to allocate polling page");
  4679   guarantee(polling_page != MAP_FAILED, "os::init_2: failed to allocate polling page");
  4667 
  4680 
  4668   os::set_polling_page(polling_page);
  4681   os::set_polling_page(polling_page);
  4669 
  4682 
  4670 #ifndef PRODUCT
  4683 #ifndef PRODUCT
  4671   if (Verbose && PrintMiscellaneous)
  4684   if (Verbose && PrintMiscellaneous) {
  4672     tty->print("[SafePoint Polling address: " INTPTR_FORMAT "]\n", (intptr_t)polling_page);
  4685     tty->print("[SafePoint Polling address: " INTPTR_FORMAT "]\n",
       
  4686                (intptr_t)polling_page);
       
  4687   }
  4673 #endif
  4688 #endif
  4674 
  4689 
  4675   if (!UseMembar) {
  4690   if (!UseMembar) {
  4676     address mem_serialize_page = (address) ::mmap(NULL, Linux::page_size(), PROT_READ | PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
  4691     address mem_serialize_page = (address) ::mmap(NULL, Linux::page_size(), PROT_READ | PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
  4677     guarantee(mem_serialize_page != MAP_FAILED, "mmap Failed for memory serialize page");
  4692     guarantee(mem_serialize_page != MAP_FAILED, "mmap Failed for memory serialize page");
  4678     os::set_memory_serialize_page(mem_serialize_page);
  4693     os::set_memory_serialize_page(mem_serialize_page);
  4679 
  4694 
  4680 #ifndef PRODUCT
  4695 #ifndef PRODUCT
  4681     if (Verbose && PrintMiscellaneous)
  4696     if (Verbose && PrintMiscellaneous) {
  4682       tty->print("[Memory Serialize  Page address: " INTPTR_FORMAT "]\n", (intptr_t)mem_serialize_page);
  4697       tty->print("[Memory Serialize  Page address: " INTPTR_FORMAT "]\n",
       
  4698                  (intptr_t)mem_serialize_page);
       
  4699     }
  4683 #endif
  4700 #endif
  4684   }
  4701   }
  4685 
  4702 
  4686   // initialize suspend/resume support - must do this before signal_sets_init()
  4703   // initialize suspend/resume support - must do this before signal_sets_init()
  4687   if (SR_initialize() != 0) {
  4704   if (SR_initialize() != 0) {
  4765     // set the number of file descriptors to max. print out error
  4782     // set the number of file descriptors to max. print out error
  4766     // if getrlimit/setrlimit fails but continue regardless.
  4783     // if getrlimit/setrlimit fails but continue regardless.
  4767     struct rlimit nbr_files;
  4784     struct rlimit nbr_files;
  4768     int status = getrlimit(RLIMIT_NOFILE, &nbr_files);
  4785     int status = getrlimit(RLIMIT_NOFILE, &nbr_files);
  4769     if (status != 0) {
  4786     if (status != 0) {
  4770       if (PrintMiscellaneous && (Verbose || WizardMode))
  4787       if (PrintMiscellaneous && (Verbose || WizardMode)) {
  4771         perror("os::init_2 getrlimit failed");
  4788         perror("os::init_2 getrlimit failed");
       
  4789       }
  4772     } else {
  4790     } else {
  4773       nbr_files.rlim_cur = nbr_files.rlim_max;
  4791       nbr_files.rlim_cur = nbr_files.rlim_max;
  4774       status = setrlimit(RLIMIT_NOFILE, &nbr_files);
  4792       status = setrlimit(RLIMIT_NOFILE, &nbr_files);
  4775       if (status != 0) {
  4793       if (status != 0) {
  4776         if (PrintMiscellaneous && (Verbose || WizardMode))
  4794         if (PrintMiscellaneous && (Verbose || WizardMode)) {
  4777           perror("os::init_2 setrlimit failed");
  4795           perror("os::init_2 setrlimit failed");
       
  4796         }
  4778       }
  4797       }
  4779     }
  4798     }
  4780   }
  4799   }
  4781 
  4800 
  4782   // Initialize lock used to serialize thread creation (see os::create_thread)
  4801   // Initialize lock used to serialize thread creation (see os::create_thread)
  4818 #endif
  4837 #endif
  4819 }
  4838 }
  4820 
  4839 
  4821 // Mark the polling page as unreadable
  4840 // Mark the polling page as unreadable
  4822 void os::make_polling_page_unreadable(void) {
  4841 void os::make_polling_page_unreadable(void) {
  4823   if (!guard_memory((char*)_polling_page, Linux::page_size()))
  4842   if (!guard_memory((char*)_polling_page, Linux::page_size())) {
  4824     fatal("Could not disable polling page");
  4843     fatal("Could not disable polling page");
  4825 };
  4844   }
       
  4845 }
  4826 
  4846 
  4827 // Mark the polling page as readable
  4847 // Mark the polling page as readable
  4828 void os::make_polling_page_readable(void) {
  4848 void os::make_polling_page_readable(void) {
  4829   if (!linux_mprotect((char *)_polling_page, Linux::page_size(), PROT_READ)) {
  4849   if (!linux_mprotect((char *)_polling_page, Linux::page_size(), PROT_READ)) {
  4830     fatal("Could not enable polling page");
  4850     fatal("Could not enable polling page");
  4831   }
  4851   }
  4832 };
  4852 }
  4833 
  4853 
  4834 int os::active_processor_count() {
  4854 int os::active_processor_count() {
  4835   // Linux doesn't yet have a (official) notion of processor sets,
  4855   // Linux doesn't yet have a (official) notion of processor sets,
  4836   // so just return the number of online processors.
  4856   // so just return the number of online processors.
  4837   int online_cpus = ::sysconf(_SC_NPROCESSORS_ONLN);
  4857   int online_cpus = ::sysconf(_SC_NPROCESSORS_ONLN);
  4900   PcFetcher fetcher(thread);
  4920   PcFetcher fetcher(thread);
  4901   fetcher.run();
  4921   fetcher.run();
  4902   return fetcher.result();
  4922   return fetcher.result();
  4903 }
  4923 }
  4904 
  4924 
  4905 int os::Linux::safe_cond_timedwait(pthread_cond_t *_cond, pthread_mutex_t *_mutex, const struct timespec *_abstime)
  4925 int os::Linux::safe_cond_timedwait(pthread_cond_t *_cond,
  4906 {
  4926                                    pthread_mutex_t *_mutex,
       
  4927                                    const struct timespec *_abstime) {
  4907   if (is_NPTL()) {
  4928   if (is_NPTL()) {
  4908     return pthread_cond_timedwait(_cond, _mutex, _abstime);
  4929     return pthread_cond_timedwait(_cond, _mutex, _abstime);
  4909   } else {
  4930   } else {
  4910     // 6292965: LinuxThreads pthread_cond_timedwait() resets FPU control
  4931     // 6292965: LinuxThreads pthread_cond_timedwait() resets FPU control
  4911     // word back to default 64bit precision if condvar is signaled. Java
  4932     // word back to default 64bit precision if condvar is signaled. Java
  4948       address       lowest = (address) dlinfo.dli_sname;
  4969       address       lowest = (address) dlinfo.dli_sname;
  4949       if (!lowest)  lowest = (address) dlinfo.dli_fbase;
  4970       if (!lowest)  lowest = (address) dlinfo.dli_fbase;
  4950       if (begin < lowest)  begin = lowest;
  4971       if (begin < lowest)  begin = lowest;
  4951       Dl_info dlinfo2;
  4972       Dl_info dlinfo2;
  4952       if (dladdr(end, &dlinfo2) != 0 && dlinfo2.dli_saddr != dlinfo.dli_saddr
  4973       if (dladdr(end, &dlinfo2) != 0 && dlinfo2.dli_saddr != dlinfo.dli_saddr
  4953           && end > dlinfo2.dli_saddr && dlinfo2.dli_saddr > begin)
  4974           && end > dlinfo2.dli_saddr && dlinfo2.dli_saddr > begin) {
  4954         end = (address) dlinfo2.dli_saddr;
  4975         end = (address) dlinfo2.dli_saddr;
       
  4976       }
  4955       Disassembler::decode(begin, end, st);
  4977       Disassembler::decode(begin, end, st);
  4956     }
  4978     }
  4957     return true;
  4979     return true;
  4958   }
  4980   }
  4959   return false;
  4981   return false;
  5005 
  5027 
  5006 bool os::check_heap(bool force) {
  5028 bool os::check_heap(bool force) {
  5007   return true;
  5029   return true;
  5008 }
  5030 }
  5009 
  5031 
  5010 int local_vsnprintf(char* buf, size_t count, const char* format, va_list args) {
  5032 int local_vsnprintf(char* buf, size_t count, const char* format,
       
  5033                     va_list args) {
  5011   return ::vsnprintf(buf, count, format, args);
  5034   return ::vsnprintf(buf, count, format, args);
  5012 }
  5035 }
  5013 
  5036 
  5014 // Is a (classpath) directory empty?
  5037 // Is a (classpath) directory empty?
  5015 bool os::dir_is_empty(const char* path) {
  5038 bool os::dir_is_empty(const char* path) {
  5017   struct dirent *ptr;
  5040   struct dirent *ptr;
  5018 
  5041 
  5019   dir = opendir(path);
  5042   dir = opendir(path);
  5020   if (dir == NULL) return true;
  5043   if (dir == NULL) return true;
  5021 
  5044 
  5022   /* Scan the directory */
  5045   // Scan the directory
  5023   bool result = true;
  5046   bool result = true;
  5024   char buf[sizeof(struct dirent) + MAX_PATH];
  5047   char buf[sizeof(struct dirent) + MAX_PATH];
  5025   while (result && (ptr = ::readdir(dir)) != NULL) {
  5048   while (result && (ptr = ::readdir(dir)) != NULL) {
  5026     if (strcmp(ptr->d_name, ".") != 0 && strcmp(ptr->d_name, "..") != 0) {
  5049     if (strcmp(ptr->d_name, ".") != 0 && strcmp(ptr->d_name, "..") != 0) {
  5027       result = false;
  5050       result = false;
  5033 
  5056 
  5034 // This code originates from JDK's sysOpen and open64_w
  5057 // This code originates from JDK's sysOpen and open64_w
  5035 // from src/solaris/hpi/src/system_md.c
  5058 // from src/solaris/hpi/src/system_md.c
  5036 
  5059 
  5037 #ifndef O_DELETE
  5060 #ifndef O_DELETE
  5038 #define O_DELETE 0x10000
  5061   #define O_DELETE 0x10000
  5039 #endif
  5062 #endif
  5040 
  5063 
  5041 // Open a file. Unlink the file immediately after open returns
  5064 // Open a file. Unlink the file immediately after open returns
  5042 // if the specified oflag has the O_DELETE flag set.
  5065 // if the specified oflag has the O_DELETE flag set.
  5043 // O_DELETE is used only in j2se/src/share/native/java/util/zip/ZipFile.c
  5066 // O_DELETE is used only in j2se/src/share/native/java/util/zip/ZipFile.c
  5044 
  5067 
  5045 int os::open(const char *path, int oflag, int mode) {
  5068 int os::open(const char *path, int oflag, int mode) {
  5046 
       
  5047   if (strlen(path) > MAX_PATH - 1) {
  5069   if (strlen(path) > MAX_PATH - 1) {
  5048     errno = ENAMETOOLONG;
  5070     errno = ENAMETOOLONG;
  5049     return -1;
  5071     return -1;
  5050   }
  5072   }
  5051   int fd;
  5073   int fd;
  5071       ::close(fd);
  5093       ::close(fd);
  5072       return -1;
  5094       return -1;
  5073     }
  5095     }
  5074   }
  5096   }
  5075 
  5097 
  5076     /*
  5098   // All file descriptors that are opened in the JVM and not
  5077      * All file descriptors that are opened in the JVM and not
  5099   // specifically destined for a subprocess should have the
  5078      * specifically destined for a subprocess should have the
  5100   // close-on-exec flag set.  If we don't set it, then careless 3rd
  5079      * close-on-exec flag set.  If we don't set it, then careless 3rd
  5101   // party native code might fork and exec without closing all
  5080      * party native code might fork and exec without closing all
  5102   // appropriate file descriptors (e.g. as we do in closeDescriptors in
  5081      * appropriate file descriptors (e.g. as we do in closeDescriptors in
  5103   // UNIXProcess.c), and this in turn might:
  5082      * UNIXProcess.c), and this in turn might:
  5104   //
  5083      *
  5105   // - cause end-of-file to fail to be detected on some file
  5084      * - cause end-of-file to fail to be detected on some file
  5106   //   descriptors, resulting in mysterious hangs, or
  5085      *   descriptors, resulting in mysterious hangs, or
  5107   //
  5086      *
  5108   // - might cause an fopen in the subprocess to fail on a system
  5087      * - might cause an fopen in the subprocess to fail on a system
  5109   //   suffering from bug 1085341.
  5088      *   suffering from bug 1085341.
  5110   //
  5089      *
  5111   // (Yes, the default setting of the close-on-exec flag is a Unix
  5090      * (Yes, the default setting of the close-on-exec flag is a Unix
  5112   // design flaw)
  5091      * design flaw)
  5113   //
  5092      *
  5114   // See:
  5093      * See:
  5115   // 1085341: 32-bit stdio routines should support file descriptors >255
  5094      * 1085341: 32-bit stdio routines should support file descriptors >255
  5116   // 4843136: (process) pipe file descriptor from Runtime.exec not being closed
  5095      * 4843136: (process) pipe file descriptor from Runtime.exec not being closed
  5117   // 6339493: (process) Runtime.exec does not close all file descriptors on Solaris 9
  5096      * 6339493: (process) Runtime.exec does not close all file descriptors on Solaris 9
  5118   //
  5097      */
       
  5098 #ifdef FD_CLOEXEC
  5119 #ifdef FD_CLOEXEC
  5099   {
  5120   {
  5100     int flags = ::fcntl(fd, F_GETFD);
  5121     int flags = ::fcntl(fd, F_GETFD);
  5101     if (flags != -1)
  5122     if (flags != -1) {
  5102       ::fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
  5123       ::fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
       
  5124     }
  5103   }
  5125   }
  5104 #endif
  5126 #endif
  5105 
  5127 
  5106   if (o_delete != 0) {
  5128   if (o_delete != 0) {
  5107     ::unlink(path);
  5129     ::unlink(path);
  5138   struct stat64 buf64;
  5160   struct stat64 buf64;
  5139 
  5161 
  5140   if (::fstat64(fd, &buf64) >= 0) {
  5162   if (::fstat64(fd, &buf64) >= 0) {
  5141     mode = buf64.st_mode;
  5163     mode = buf64.st_mode;
  5142     if (S_ISCHR(mode) || S_ISFIFO(mode) || S_ISSOCK(mode)) {
  5164     if (S_ISCHR(mode) || S_ISFIFO(mode) || S_ISSOCK(mode)) {
  5143       /*
  5165       // XXX: is the following call interruptible? If so, this might
  5144       * XXX: is the following call interruptible? If so, this might
  5166       // need to go through the INTERRUPT_IO() wrapper as for other
  5145       * need to go through the INTERRUPT_IO() wrapper as for other
  5167       // blocking, interruptible calls in this file.
  5146       * blocking, interruptible calls in this file.
       
  5147       */
       
  5148       int n;
  5168       int n;
  5149       if (::ioctl(fd, FIONREAD, &n) >= 0) {
  5169       if (::ioctl(fd, FIONREAD, &n) >= 0) {
  5150         *bytes = n;
  5170         *bytes = n;
  5151         return 1;
  5171         return 1;
  5152       }
  5172       }
  5268   } else {
  5288   } else {
  5269     return slow_thread_cpu_time(thread, user_sys_cpu_time);
  5289     return slow_thread_cpu_time(thread, user_sys_cpu_time);
  5270   }
  5290   }
  5271 }
  5291 }
  5272 
  5292 
  5273 //
       
  5274 //  -1 on error.
  5293 //  -1 on error.
  5275 //
       
  5276 
       
  5277 static jlong slow_thread_cpu_time(Thread *thread, bool user_sys_cpu_time) {
  5294 static jlong slow_thread_cpu_time(Thread *thread, bool user_sys_cpu_time) {
  5278   pid_t  tid = thread->osthread()->thread_id();
  5295   pid_t  tid = thread->osthread()->thread_id();
  5279   char *s;
  5296   char *s;
  5280   char stat[2048];
  5297   char stat[2048];
  5281   int statlen;
  5298   int statlen;
  5604 
  5621 
  5605 
  5622 
  5606 // JSR166
  5623 // JSR166
  5607 // -------------------------------------------------------
  5624 // -------------------------------------------------------
  5608 
  5625 
  5609 /*
  5626 // The solaris and linux implementations of park/unpark are fairly
  5610  * The solaris and linux implementations of park/unpark are fairly
  5627 // conservative for now, but can be improved. They currently use a
  5611  * conservative for now, but can be improved. They currently use a
  5628 // mutex/condvar pair, plus a a count.
  5612  * mutex/condvar pair, plus a a count.
  5629 // Park decrements count if > 0, else does a condvar wait.  Unpark
  5613  * Park decrements count if > 0, else does a condvar wait.  Unpark
  5630 // sets count to 1 and signals condvar.  Only one thread ever waits
  5614  * sets count to 1 and signals condvar.  Only one thread ever waits
  5631 // on the condvar. Contention seen when trying to park implies that someone
  5615  * on the condvar. Contention seen when trying to park implies that someone
  5632 // is unparking you, so don't wait. And spurious returns are fine, so there
  5616  * is unparking you, so don't wait. And spurious returns are fine, so there
  5633 // is no need to track notifications.
  5617  * is no need to track notifications.
  5634 
  5618  */
  5635 // This code is common to linux and solaris and will be moved to a
  5619 
  5636 // common place in dolphin.
  5620 /*
  5637 //
  5621  * This code is common to linux and solaris and will be moved to a
  5638 // The passed in time value is either a relative time in nanoseconds
  5622  * common place in dolphin.
  5639 // or an absolute time in milliseconds. Either way it has to be unpacked
  5623  *
  5640 // into suitable seconds and nanoseconds components and stored in the
  5624  * The passed in time value is either a relative time in nanoseconds
  5641 // given timespec structure.
  5625  * or an absolute time in milliseconds. Either way it has to be unpacked
  5642 // Given time is a 64-bit value and the time_t used in the timespec is only
  5626  * into suitable seconds and nanoseconds components and stored in the
  5643 // a signed-32-bit value (except on 64-bit Linux) we have to watch for
  5627  * given timespec structure.
  5644 // overflow if times way in the future are given. Further on Solaris versions
  5628  * Given time is a 64-bit value and the time_t used in the timespec is only
  5645 // prior to 10 there is a restriction (see cond_timedwait) that the specified
  5629  * a signed-32-bit value (except on 64-bit Linux) we have to watch for
  5646 // number of seconds, in abstime, is less than current_time  + 100,000,000.
  5630  * overflow if times way in the future are given. Further on Solaris versions
  5647 // As it will be 28 years before "now + 100000000" will overflow we can
  5631  * prior to 10 there is a restriction (see cond_timedwait) that the specified
  5648 // ignore overflow and just impose a hard-limit on seconds using the value
  5632  * number of seconds, in abstime, is less than current_time  + 100,000,000.
  5649 // of "now + 100,000,000". This places a limit on the timeout of about 3.17
  5633  * As it will be 28 years before "now + 100000000" will overflow we can
  5650 // years from "now".
  5634  * ignore overflow and just impose a hard-limit on seconds using the value
       
  5635  * of "now + 100,000,000". This places a limit on the timeout of about 3.17
       
  5636  * years from "now".
       
  5637  */
       
  5638 
  5651 
  5639 static void unpackTime(timespec* absTime, bool isAbsolute, jlong time) {
  5652 static void unpackTime(timespec* absTime, bool isAbsolute, jlong time) {
  5640   assert(time > 0, "convertTime");
  5653   assert(time > 0, "convertTime");
  5641   time_t max_secs = 0;
  5654   time_t max_secs = 0;
  5642 
  5655 
  5803   if (s < 1) {
  5816   if (s < 1) {
  5804     // thread might be parked
  5817     // thread might be parked
  5805     if (_cur_index != -1) {
  5818     if (_cur_index != -1) {
  5806       // thread is definitely parked
  5819       // thread is definitely parked
  5807       if (WorkAroundNPTLTimedWaitHang) {
  5820       if (WorkAroundNPTLTimedWaitHang) {
  5808         status = pthread_cond_signal (&_cond[_cur_index]);
  5821         status = pthread_cond_signal(&_cond[_cur_index]);
  5809         assert(status == 0, "invariant");
  5822         assert(status == 0, "invariant");
  5810         status = pthread_mutex_unlock(_mutex);
  5823         status = pthread_mutex_unlock(_mutex);
  5811         assert(status == 0, "invariant");
  5824         assert(status == 0, "invariant");
  5812       } else {
  5825       } else {
  5813         status = pthread_mutex_unlock(_mutex);
  5826         status = pthread_mutex_unlock(_mutex);
  5814         assert(status == 0, "invariant");
  5827         assert(status == 0, "invariant");
  5815         status = pthread_cond_signal (&_cond[_cur_index]);
  5828         status = pthread_cond_signal(&_cond[_cur_index]);
  5816         assert(status == 0, "invariant");
  5829         assert(status == 0, "invariant");
  5817       }
  5830       }
  5818     } else {
  5831     } else {
  5819       pthread_mutex_unlock(_mutex);
  5832       pthread_mutex_unlock(_mutex);
  5820       assert(status == 0, "invariant");
  5833       assert(status == 0, "invariant");
  5827 
  5840 
  5828 
  5841 
  5829 extern char** environ;
  5842 extern char** environ;
  5830 
  5843 
  5831 #ifndef __NR_fork
  5844 #ifndef __NR_fork
  5832 #define __NR_fork IA32_ONLY(2) IA64_ONLY(not defined) AMD64_ONLY(57)
  5845   #define __NR_fork IA32_ONLY(2) IA64_ONLY(not defined) AMD64_ONLY(57)
  5833 #endif
  5846 #endif
  5834 
  5847 
  5835 #ifndef __NR_execve
  5848 #ifndef __NR_execve
  5836 #define __NR_execve IA32_ONLY(11) IA64_ONLY(1033) AMD64_ONLY(59)
  5849   #define __NR_execve IA32_ONLY(11) IA64_ONLY(1033) AMD64_ONLY(59)
  5837 #endif
  5850 #endif
  5838 
  5851 
  5839 // Run the specified command in a separate process. Return its exit value,
  5852 // Run the specified command in a separate process. Return its exit value,
  5840 // or -1 on failure (e.g. can't fork a new process).
  5853 // or -1 on failure (e.g. can't fork a new process).
  5841 // Unlike system(), this function can be called from signal handler. It
  5854 // Unlike system(), this function can be called from signal handler. It
  5923   // Get path to libjvm.so
  5936   // Get path to libjvm.so
  5924   os::jvm_path(buf, sizeof(buf));
  5937   os::jvm_path(buf, sizeof(buf));
  5925 
  5938 
  5926   // Get rid of libjvm.so
  5939   // Get rid of libjvm.so
  5927   p = strrchr(buf, '/');
  5940   p = strrchr(buf, '/');
  5928   if (p == NULL) return false;
  5941   if (p == NULL) {
  5929   else *p = '\0';
  5942     return false;
       
  5943   } else {
       
  5944     *p = '\0';
       
  5945   }
  5930 
  5946 
  5931   // Get rid of client or server
  5947   // Get rid of client or server
  5932   p = strrchr(buf, '/');
  5948   p = strrchr(buf, '/');
  5933   if (p == NULL) return false;
  5949   if (p == NULL) {
  5934   else *p = '\0';
  5950     return false;
       
  5951   } else {
       
  5952     *p = '\0';
       
  5953   }
  5935 
  5954 
  5936   // check xawt/libmawt.so
  5955   // check xawt/libmawt.so
  5937   strcpy(libmawtpath, buf);
  5956   strcpy(libmawtpath, buf);
  5938   strcat(libmawtpath, xawtstr);
  5957   strcat(libmawtpath, xawtstr);
  5939   if (::stat(libmawtpath, &statbuf) == 0) return false;
  5958   if (::stat(libmawtpath, &statbuf) == 0) return false;
  6016       // Universe::heap()->size_policy()->set_gc_time_limit_exceeded(true);
  6035       // Universe::heap()->size_policy()->set_gc_time_limit_exceeded(true);
  6017     }
  6036     }
  6018   }
  6037   }
  6019 }
  6038 }
  6020 
  6039 
  6021 //
       
  6022 // See if the /dev/mem_notify device exists, and if so, start a thread to monitor it.
  6040 // See if the /dev/mem_notify device exists, and if so, start a thread to monitor it.
  6023 //
  6041 //
  6024 void MemNotifyThread::start() {
  6042 void MemNotifyThread::start() {
  6025   int    fd;
  6043   int fd;
  6026   fd = open ("/dev/mem_notify", O_RDONLY, 0);
  6044   fd = open("/dev/mem_notify", O_RDONLY, 0);
  6027   if (fd < 0) {
  6045   if (fd < 0) {
  6028     return;
  6046     return;
  6029   }
  6047   }
  6030 
  6048 
  6031   if (memnotify_thread() == NULL) {
  6049   if (memnotify_thread() == NULL) {
  6038 
  6056 
  6039 /////////////// Unit tests ///////////////
  6057 /////////////// Unit tests ///////////////
  6040 
  6058 
  6041 #ifndef PRODUCT
  6059 #ifndef PRODUCT
  6042 
  6060 
  6043 #define test_log(...) \
  6061 #define test_log(...)              \
  6044   do {\
  6062   do {                             \
  6045     if (VerboseInternalVMTests) { \
  6063     if (VerboseInternalVMTests) {  \
  6046       tty->print_cr(__VA_ARGS__); \
  6064       tty->print_cr(__VA_ARGS__);  \
  6047       tty->flush(); \
  6065       tty->flush();                \
  6048     }\
  6066     }                              \
  6049   } while (false)
  6067   } while (false)
  6050 
  6068 
  6051 class TestReserveMemorySpecial : AllStatic {
  6069 class TestReserveMemorySpecial : AllStatic {
  6052  public:
  6070  public:
  6053   static void small_page_write(void* addr, size_t size) {
  6071   static void small_page_write(void* addr, size_t size) {