hotspot/src/os/solaris/vm/os_solaris.cpp
changeset 26684 d1221849ea3d
parent 26683 a02753d5a0b2
child 26685 aa239a0dfbea
equal deleted inserted replaced
26683:a02753d5a0b2 26684:d1221849ea3d
   122 
   122 
   123 // Here are some liblgrp types from sys/lgrp_user.h to be able to
   123 // Here are some liblgrp types from sys/lgrp_user.h to be able to
   124 // compile on older systems without this header file.
   124 // compile on older systems without this header file.
   125 
   125 
   126 #ifndef MADV_ACCESS_LWP
   126 #ifndef MADV_ACCESS_LWP
   127 # define  MADV_ACCESS_LWP         7       /* next LWP to access heavily */
   127   #define  MADV_ACCESS_LWP   7       /* next LWP to access heavily */
   128 #endif
   128 #endif
   129 #ifndef MADV_ACCESS_MANY
   129 #ifndef MADV_ACCESS_MANY
   130 # define  MADV_ACCESS_MANY        8       /* many processes to access heavily */
   130   #define  MADV_ACCESS_MANY  8       /* many processes to access heavily */
   131 #endif
   131 #endif
   132 
   132 
   133 #ifndef LGRP_RSRC_CPU
   133 #ifndef LGRP_RSRC_CPU
   134 # define LGRP_RSRC_CPU           0       /* CPU resources */
   134   #define LGRP_RSRC_CPU      0       /* CPU resources */
   135 #endif
   135 #endif
   136 #ifndef LGRP_RSRC_MEM
   136 #ifndef LGRP_RSRC_MEM
   137 # define LGRP_RSRC_MEM           1       /* memory resources */
   137   #define LGRP_RSRC_MEM      1       /* memory resources */
   138 #endif
   138 #endif
   139 
   139 
   140 // see thr_setprio(3T) for the basis of these numbers
   140 // see thr_setprio(3T) for the basis of these numbers
   141 #define MinimumPriority 0
   141 #define MinimumPriority 0
   142 #define NormalPriority  64
   142 #define NormalPriority  64
   188 //
   188 //
   189 // Static member initialization for TLS
   189 // Static member initialization for TLS
   190 Thread* ThreadLocalStorage::_get_thread_cache[ThreadLocalStorage::_pd_cache_size] = {NULL};
   190 Thread* ThreadLocalStorage::_get_thread_cache[ThreadLocalStorage::_pd_cache_size] = {NULL};
   191 
   191 
   192 #ifndef PRODUCT
   192 #ifndef PRODUCT
   193 #define _PCT(n,d)       ((100.0*(double)(n))/(double)(d))
   193   #define _PCT(n,d)       ((100.0*(double)(n))/(double)(d))
   194 
   194 
   195 int ThreadLocalStorage::_tcacheHit = 0;
   195 int ThreadLocalStorage::_tcacheHit = 0;
   196 int ThreadLocalStorage::_tcacheMiss = 0;
   196 int ThreadLocalStorage::_tcacheMiss = 0;
   197 
   197 
   198 void ThreadLocalStorage::print_statistics() {
   198 void ThreadLocalStorage::print_statistics() {
   199   int total = _tcacheMiss+_tcacheHit;
   199   int total = _tcacheMiss+_tcacheHit;
   200   tty->print_cr("Thread cache hits %d misses %d total %d percent %f\n",
   200   tty->print_cr("Thread cache hits %d misses %d total %d percent %f\n",
   201                 _tcacheHit, _tcacheMiss, total, _PCT(_tcacheHit, total));
   201                 _tcacheHit, _tcacheMiss, total, _PCT(_tcacheHit, total));
   202 }
   202 }
   203 #undef _PCT
   203   #undef _PCT
   204 #endif // PRODUCT
   204 #endif // PRODUCT
   205 
   205 
   206 Thread* ThreadLocalStorage::get_thread_via_cache_slowly(uintptr_t raw_id,
   206 Thread* ThreadLocalStorage::get_thread_via_cache_slowly(uintptr_t raw_id,
   207                                                         int index) {
   207                                                         int index) {
   208   Thread *thread = get_thread_slow();
   208   Thread *thread = get_thread_slow();
   354 static volatile hrtime_t max_hrtime = 0;
   354 static volatile hrtime_t max_hrtime = 0;
   355 
   355 
   356 
   356 
   357 void os::Solaris::initialize_system_info() {
   357 void os::Solaris::initialize_system_info() {
   358   set_processor_count(sysconf(_SC_NPROCESSORS_CONF));
   358   set_processor_count(sysconf(_SC_NPROCESSORS_CONF));
   359   _processors_online = sysconf (_SC_NPROCESSORS_ONLN);
   359   _processors_online = sysconf(_SC_NPROCESSORS_ONLN);
   360   _physical_memory = (julong)sysconf(_SC_PHYS_PAGES) * (julong)sysconf(_SC_PAGESIZE);
   360   _physical_memory = (julong)sysconf(_SC_PHYS_PAGES) *
       
   361                                      (julong)sysconf(_SC_PAGESIZE);
   361 }
   362 }
   362 
   363 
   363 int os::active_processor_count() {
   364 int os::active_processor_count() {
   364   int online_cpus = sysconf(_SC_NPROCESSORS_ONLN);
   365   int online_cpus = sysconf(_SC_NPROCESSORS_ONLN);
   365   pid_t pid = getpid();
   366   pid_t pid = getpid();
   554   return (bind_result == 0);
   555   return (bind_result == 0);
   555 }
   556 }
   556 
   557 
   557 bool os::getenv(const char* name, char* buffer, int len) {
   558 bool os::getenv(const char* name, char* buffer, int len) {
   558   char* val = ::getenv(name);
   559   char* val = ::getenv(name);
   559   if (val == NULL
   560   if (val == NULL || strlen(val) + 1 > len) {
   560       ||   strlen(val) + 1  >  len ) {
   561     if (len > 0) buffer[0] = 0; // return a null string
   561     if (len > 0)  buffer[0] = 0; // return a null string
       
   562     return false;
   562     return false;
   563   }
   563   }
   564   strcpy(buffer, val);
   564   strcpy(buffer, val);
   565   return true;
   565   return true;
   566 }
   566 }
   778 
   778 
   779 void os::breakpoint() {
   779 void os::breakpoint() {
   780   BREAKPOINT;
   780   BREAKPOINT;
   781 }
   781 }
   782 
   782 
   783 bool os::obsolete_option(const JavaVMOption *option)
   783 bool os::obsolete_option(const JavaVMOption *option) {
   784 {
       
   785   if (!strncmp(option->optionString, "-Xt", 3)) {
   784   if (!strncmp(option->optionString, "-Xt", 3)) {
   786     return true;
   785     return true;
   787   } else if (!strncmp(option->optionString, "-Xtm", 4)) {
   786   } else if (!strncmp(option->optionString, "-Xtm", 4)) {
   788     return true;
   787     return true;
   789   } else if (!strncmp(option->optionString, "-Xverifyheap", 12)) {
   788   } else if (!strncmp(option->optionString, "-Xverifyheap", 12)) {
   904 
   903 
   905   return osthread;
   904   return osthread;
   906 }
   905 }
   907 
   906 
   908 void os::Solaris::hotspot_sigmask(Thread* thread) {
   907 void os::Solaris::hotspot_sigmask(Thread* thread) {
   909 
       
   910   //Save caller's signal mask
   908   //Save caller's signal mask
   911   sigset_t sigmask;
   909   sigset_t sigmask;
   912   thr_sigsetmask(SIG_SETMASK, NULL, &sigmask);
   910   thr_sigsetmask(SIG_SETMASK, NULL, &sigmask);
   913   OSThread *osthread = thread->osthread();
   911   OSThread *osthread = thread->osthread();
   914   osthread->set_caller_sigmask(sigmask);
   912   osthread->set_caller_sigmask(sigmask);
   968 
   966 
   969   return true;
   967   return true;
   970 }
   968 }
   971 
   969 
   972 
   970 
   973 bool os::create_thread(Thread* thread, ThreadType thr_type, size_t stack_size) {
   971 bool os::create_thread(Thread* thread, ThreadType thr_type,
       
   972                        size_t stack_size) {
   974   // Allocate the OSThread object
   973   // Allocate the OSThread object
   975   OSThread* osthread = new OSThread(NULL, NULL);
   974   OSThread* osthread = new OSThread(NULL, NULL);
   976   if (osthread == NULL) {
   975   if (osthread == NULL) {
   977     return false;
   976     return false;
   978   }
   977   }
  1086 
  1085 
  1087   // The thread is returned suspended (in state INITIALIZED), and is started higher up in the call chain
  1086   // The thread is returned suspended (in state INITIALIZED), and is started higher up in the call chain
  1088   return true;
  1087   return true;
  1089 }
  1088 }
  1090 
  1089 
  1091 /* defined for >= Solaris 10. This allows builds on earlier versions
  1090 // defined for >= Solaris 10. This allows builds on earlier versions
  1092  *  of Solaris to take advantage of the newly reserved Solaris JVM signals
  1091 // of Solaris to take advantage of the newly reserved Solaris JVM signals
  1093  *  With SIGJVM1, SIGJVM2, INTERRUPT_SIGNAL is SIGJVM1, ASYNC_SIGNAL is SIGJVM2
  1092 // With SIGJVM1, SIGJVM2, INTERRUPT_SIGNAL is SIGJVM1, ASYNC_SIGNAL is SIGJVM2
  1094  *  and -XX:+UseAltSigs does nothing since these should have no conflict
  1093 // and -XX:+UseAltSigs does nothing since these should have no conflict
  1095  */
  1094 //
  1096 #if !defined(SIGJVM1)
  1095 #if !defined(SIGJVM1)
  1097 #define SIGJVM1 39
  1096   #define SIGJVM1 39
  1098 #define SIGJVM2 40
  1097   #define SIGJVM2 40
  1099 #endif
  1098 #endif
  1100 
  1099 
  1101 debug_only(static bool signal_sets_initialized = false);
  1100 debug_only(static bool signal_sets_initialized = false);
  1102 static sigset_t unblocked_sigs, vm_sigs, allowdebug_blocked_sigs;
  1101 static sigset_t unblocked_sigs, vm_sigs, allowdebug_blocked_sigs;
  1103 int os::Solaris::_SIGinterrupt = INTERRUPT_SIGNAL;
  1102 int os::Solaris::_SIGinterrupt = INTERRUPT_SIGNAL;
  1106 bool os::Solaris::is_sig_ignored(int sig) {
  1105 bool os::Solaris::is_sig_ignored(int sig) {
  1107   struct sigaction oact;
  1106   struct sigaction oact;
  1108   sigaction(sig, (struct sigaction*)NULL, &oact);
  1107   sigaction(sig, (struct sigaction*)NULL, &oact);
  1109   void* ohlr = oact.sa_sigaction ? CAST_FROM_FN_PTR(void*,  oact.sa_sigaction)
  1108   void* ohlr = oact.sa_sigaction ? CAST_FROM_FN_PTR(void*,  oact.sa_sigaction)
  1110                                  : CAST_FROM_FN_PTR(void*,  oact.sa_handler);
  1109                                  : CAST_FROM_FN_PTR(void*,  oact.sa_handler);
  1111   if (ohlr == CAST_FROM_FN_PTR(void*, SIG_IGN))
  1110   if (ohlr == CAST_FROM_FN_PTR(void*, SIG_IGN)) {
  1112     return true;
  1111     return true;
  1113   else
  1112   } else {
  1114     return false;
  1113     return false;
       
  1114   }
  1115 }
  1115 }
  1116 
  1116 
  1117 // Note: SIGRTMIN is a macro that calls sysconf() so it will
  1117 // Note: SIGRTMIN is a macro that calls sysconf() so it will
  1118 // dynamically detect SIGRTMIN value for the system at runtime, not buildtime
  1118 // dynamically detect SIGRTMIN value for the system at runtime, not buildtime
  1119 static bool isJVM1available() {
  1119 static bool isJVM1available() {
  1171       sigaddset(&allowdebug_blocked_sigs, SHUTDOWN3_SIGNAL);
  1171       sigaddset(&allowdebug_blocked_sigs, SHUTDOWN3_SIGNAL);
  1172     }
  1172     }
  1173   }
  1173   }
  1174   // Fill in signals that are blocked by all but the VM thread.
  1174   // Fill in signals that are blocked by all but the VM thread.
  1175   sigemptyset(&vm_sigs);
  1175   sigemptyset(&vm_sigs);
  1176   if (!ReduceSignalUsage)
  1176   if (!ReduceSignalUsage) {
  1177     sigaddset(&vm_sigs, BREAK_SIGNAL);
  1177     sigaddset(&vm_sigs, BREAK_SIGNAL);
       
  1178   }
  1178   debug_only(signal_sets_initialized = true);
  1179   debug_only(signal_sets_initialized = true);
  1179 
  1180 
  1180   // For diagnostics only used in run_periodic_checks
  1181   // For diagnostics only used in run_periodic_checks
  1181   sigemptyset(&check_signal_done);
  1182   sigemptyset(&check_signal_done);
  1182 }
  1183 }
  1242     stack_size = (size_t)(base - bottom);
  1243     stack_size = (size_t)(base - bottom);
  1243 
  1244 
  1244     assert(stack_size > 0, "Stack size calculation problem");
  1245     assert(stack_size > 0, "Stack size calculation problem");
  1245 
  1246 
  1246     if (stack_size > jt->stack_size()) {
  1247     if (stack_size > jt->stack_size()) {
  1247       NOT_PRODUCT(
  1248 #ifndef PRODUCT
  1248                   struct rlimit limits;
  1249       struct rlimit limits;
  1249                   getrlimit(RLIMIT_STACK, &limits);
  1250       getrlimit(RLIMIT_STACK, &limits);
  1250                   size_t size = adjust_stack_size(base, (size_t)limits.rlim_cur);
  1251       size_t size = adjust_stack_size(base, (size_t)limits.rlim_cur);
  1251                   assert(size >= jt->stack_size(), "Stack size problem in main thread");
  1252       assert(size >= jt->stack_size(), "Stack size problem in main thread");
  1252                   )
  1253 #endif
  1253       tty->print_cr(
  1254       tty->print_cr("Stack size of %d Kb exceeds current limit of %d Kb.\n"
  1254                     "Stack size of %d Kb exceeds current limit of %d Kb.\n"
       
  1255                     "(Stack sizes are rounded up to a multiple of the system page size.)\n"
  1255                     "(Stack sizes are rounded up to a multiple of the system page size.)\n"
  1256                     "See limit(1) to increase the stack size limit.",
  1256                     "See limit(1) to increase the stack size limit.",
  1257                     stack_size / K, jt->stack_size() / K);
  1257                     stack_size / K, jt->stack_size() / K);
  1258       vm_exit(1);
  1258       vm_exit(1);
  1259     }
  1259     }
  1323   //           interface.  I think, however, that it will be faster to
  1323   //           interface.  I think, however, that it will be faster to
  1324   //           maintain the invariant that %g2 always contains the
  1324   //           maintain the invariant that %g2 always contains the
  1325   //           JavaThread in Java code, and have stubs simply
  1325   //           JavaThread in Java code, and have stubs simply
  1326   //           treat %g2 as a caller-save register, preserving it in a %lN.
  1326   //           treat %g2 as a caller-save register, preserving it in a %lN.
  1327   thread_key_t tk;
  1327   thread_key_t tk;
  1328   if (thr_keycreate( &tk, NULL))
  1328   if (thr_keycreate(&tk, NULL)) {
  1329     fatal(err_msg("os::allocate_thread_local_storage: thr_keycreate failed "
  1329     fatal(err_msg("os::allocate_thread_local_storage: thr_keycreate failed "
  1330                   "(%s)", strerror(errno)));
  1330                   "(%s)", strerror(errno)));
       
  1331   }
  1331   return int(tk);
  1332   return int(tk);
  1332 }
  1333 }
  1333 
  1334 
  1334 void os::free_thread_local_storage(int index) {
  1335 void os::free_thread_local_storage(int index) {
  1335   // %%% don't think we need anything here
  1336   // %%% don't think we need anything here
  1336   // if ( pthread_key_delete((pthread_key_t) tk) )
  1337   // if (pthread_key_delete((pthread_key_t) tk)) {
  1337   //   fatal("os::free_thread_local_storage: pthread_key_delete failed");
  1338   //   fatal("os::free_thread_local_storage: pthread_key_delete failed");
  1338 }
  1339   // }
  1339 
  1340 }
  1340 #define SMALLINT 32   // libthread allocate for tsd_common is a version specific
  1341 
       
  1342 // libthread allocate for tsd_common is a version specific
  1341 // small number - point is NO swap space available
  1343 // small number - point is NO swap space available
       
  1344 #define SMALLINT 32
  1342 void os::thread_local_storage_at_put(int index, void* value) {
  1345 void os::thread_local_storage_at_put(int index, void* value) {
  1343   // %%% this is used only in threadLocalStorage.cpp
  1346   // %%% this is used only in threadLocalStorage.cpp
  1344   if (thr_setspecific((thread_key_t)index, value)) {
  1347   if (thr_setspecific((thread_key_t)index, value)) {
  1345     if (errno == ENOMEM) {
  1348     if (errno == ENOMEM) {
  1346       vm_exit_out_of_memory(SMALLINT, OOM_MALLOC_ERROR,
  1349       vm_exit_out_of_memory(SMALLINT, OOM_MALLOC_ERROR,
  1429 
  1432 
  1430 bool os::supports_vtime() { return true; }
  1433 bool os::supports_vtime() { return true; }
  1431 
  1434 
  1432 bool os::enable_vtime() {
  1435 bool os::enable_vtime() {
  1433   int fd = ::open("/proc/self/ctl", O_WRONLY);
  1436   int fd = ::open("/proc/self/ctl", O_WRONLY);
  1434   if (fd == -1)
  1437   if (fd == -1) {
  1435     return false;
  1438     return false;
       
  1439   }
  1436 
  1440 
  1437   long cmd[] = { PCSET, PR_MSACCT };
  1441   long cmd[] = { PCSET, PR_MSACCT };
  1438   int res = ::write(fd, cmd, sizeof(long) * 2);
  1442   int res = ::write(fd, cmd, sizeof(long) * 2);
  1439   ::close(fd);
  1443   ::close(fd);
  1440   if (res != sizeof(long) * 2)
  1444   if (res != sizeof(long) * 2) {
  1441     return false;
  1445     return false;
  1442 
  1446   }
  1443   return true;
  1447   return true;
  1444 }
  1448 }
  1445 
  1449 
  1446 bool os::vtime_enabled() {
  1450 bool os::vtime_enabled() {
  1447   int fd = ::open("/proc/self/status", O_RDONLY);
  1451   int fd = ::open("/proc/self/status", O_RDONLY);
  1448   if (fd == -1)
  1452   if (fd == -1) {
  1449     return false;
  1453     return false;
       
  1454   }
  1450 
  1455 
  1451   pstatus_t status;
  1456   pstatus_t status;
  1452   int res = os::read(fd, (void*) &status, sizeof(pstatus_t));
  1457   int res = os::read(fd, (void*) &status, sizeof(pstatus_t));
  1453   ::close(fd);
  1458   ::close(fd);
  1454   if (res != sizeof(pstatus_t))
  1459   if (res != sizeof(pstatus_t)) {
  1455     return false;
  1460     return false;
  1456 
  1461   }
  1457   return status.pr_flags & PR_MSACCT;
  1462   return status.pr_flags & PR_MSACCT;
  1458 }
  1463 }
  1459 
  1464 
  1460 double os::elapsedVTime() {
  1465 double os::elapsedVTime() {
  1461   return (double)gethrvtime() / (double)hrtime_hz;
  1466   return (double)gethrvtime() / (double)hrtime_hz;
  1469 }
  1474 }
  1470 
  1475 
  1471 // Must return millis since Jan 1 1970 for JVM_CurrentTimeMillis
  1476 // Must return millis since Jan 1 1970 for JVM_CurrentTimeMillis
  1472 jlong os::javaTimeMillis() {
  1477 jlong os::javaTimeMillis() {
  1473   timeval t;
  1478   timeval t;
  1474   if (gettimeofday( &t, NULL) == -1)
  1479   if (gettimeofday(&t, NULL) == -1) {
  1475     fatal(err_msg("os::javaTimeMillis: gettimeofday (%s)", strerror(errno)));
  1480     fatal(err_msg("os::javaTimeMillis: gettimeofday (%s)", strerror(errno)));
       
  1481   }
  1476   return jlong(t.tv_sec) * 1000  +  jlong(t.tv_usec) / 1000;
  1482   return jlong(t.tv_sec) * 1000  +  jlong(t.tv_usec) / 1000;
  1477 }
  1483 }
  1478 
  1484 
  1479 jlong os::javaTimeNanos() {
  1485 jlong os::javaTimeNanos() {
  1480   return (jlong)getTimeNanos();
  1486   return (jlong)getTimeNanos();
  1623   }
  1629   }
  1624 
  1630 
  1625   return false;
  1631   return false;
  1626 }
  1632 }
  1627 
  1633 
  1628 typedef int (*dladdr1_func_type) (void *, Dl_info *, void **, int);
  1634 typedef int (*dladdr1_func_type)(void *, Dl_info *, void **, int);
  1629 static dladdr1_func_type dladdr1_func = NULL;
  1635 static dladdr1_func_type dladdr1_func = NULL;
  1630 
  1636 
  1631 bool os::dll_address_to_function_name(address addr, char *buf,
  1637 bool os::dll_address_to_function_name(address addr, char *buf,
  1632                                       int buflen, int * offset) {
  1638                                       int buflen, int * offset) {
  1633   // buf is not optional, but offset is optional
  1639   // buf is not optional, but offset is optional
  1641 
  1647 
  1642     // Support for dladdr1 is checked at runtime; it may be
  1648     // Support for dladdr1 is checked at runtime; it may be
  1643     // available even if the vm is built on a machine that does
  1649     // available even if the vm is built on a machine that does
  1644     // not have dladdr1 support.  Make sure there is a value for
  1650     // not have dladdr1 support.  Make sure there is a value for
  1645     // RTLD_DL_SYMENT.
  1651     // RTLD_DL_SYMENT.
  1646     #ifndef RTLD_DL_SYMENT
  1652 #ifndef RTLD_DL_SYMENT
  1647     #define RTLD_DL_SYMENT 1
  1653   #define RTLD_DL_SYMENT 1
  1648     #endif
  1654 #endif
  1649 #ifdef _LP64
  1655 #ifdef _LP64
  1650     Elf64_Sym * info;
  1656     Elf64_Sym * info;
  1651 #else
  1657 #else
  1652     Elf32_Sym * info;
  1658     Elf32_Sym * info;
  1653 #endif
  1659 #endif
  1761 
  1767 
  1762 // Loads .dll/.so and
  1768 // Loads .dll/.so and
  1763 // in case of error it checks if .dll/.so was built for the
  1769 // in case of error it checks if .dll/.so was built for the
  1764 // same architecture as Hotspot is running on
  1770 // same architecture as Hotspot is running on
  1765 
  1771 
  1766 void * os::dll_load(const char *filename, char *ebuf, int ebuflen)
  1772 void * os::dll_load(const char *filename, char *ebuf, int ebuflen) {
  1767 {
       
  1768   void * result= ::dlopen(filename, RTLD_LAZY);
  1773   void * result= ::dlopen(filename, RTLD_LAZY);
  1769   if (result != NULL) {
  1774   if (result != NULL) {
  1770     // Successful loading
  1775     // Successful loading
  1771     return result;
  1776     return result;
  1772   }
  1777   }
  1822     {EM_PPC,         EM_PPC,     ELFCLASS32, ELFDATA2MSB, (char*)"Power PC 32"},
  1827     {EM_PPC,         EM_PPC,     ELFCLASS32, ELFDATA2MSB, (char*)"Power PC 32"},
  1823     {EM_PPC64,       EM_PPC64,   ELFCLASS64, ELFDATA2MSB, (char*)"Power PC 64"},
  1828     {EM_PPC64,       EM_PPC64,   ELFCLASS64, ELFDATA2MSB, (char*)"Power PC 64"},
  1824     {EM_ARM,         EM_ARM,     ELFCLASS32, ELFDATA2LSB, (char*)"ARM 32"}
  1829     {EM_ARM,         EM_ARM,     ELFCLASS32, ELFDATA2LSB, (char*)"ARM 32"}
  1825   };
  1830   };
  1826 
  1831 
  1827   #if  (defined IA32)
  1832 #if  (defined IA32)
  1828   static  Elf32_Half running_arch_code=EM_386;
  1833   static  Elf32_Half running_arch_code=EM_386;
  1829   #elif   (defined AMD64)
  1834 #elif   (defined AMD64)
  1830   static  Elf32_Half running_arch_code=EM_X86_64;
  1835   static  Elf32_Half running_arch_code=EM_X86_64;
  1831   #elif  (defined IA64)
  1836 #elif  (defined IA64)
  1832   static  Elf32_Half running_arch_code=EM_IA_64;
  1837   static  Elf32_Half running_arch_code=EM_IA_64;
  1833   #elif  (defined __sparc) && (defined _LP64)
  1838 #elif  (defined __sparc) && (defined _LP64)
  1834   static  Elf32_Half running_arch_code=EM_SPARCV9;
  1839   static  Elf32_Half running_arch_code=EM_SPARCV9;
  1835   #elif  (defined __sparc) && (!defined _LP64)
  1840 #elif  (defined __sparc) && (!defined _LP64)
  1836   static  Elf32_Half running_arch_code=EM_SPARC;
  1841   static  Elf32_Half running_arch_code=EM_SPARC;
  1837   #elif  (defined __powerpc64__)
  1842 #elif  (defined __powerpc64__)
  1838   static  Elf32_Half running_arch_code=EM_PPC64;
  1843   static  Elf32_Half running_arch_code=EM_PPC64;
  1839   #elif  (defined __powerpc__)
  1844 #elif  (defined __powerpc__)
  1840   static  Elf32_Half running_arch_code=EM_PPC;
  1845   static  Elf32_Half running_arch_code=EM_PPC;
  1841   #elif (defined ARM)
  1846 #elif (defined ARM)
  1842   static  Elf32_Half running_arch_code=EM_ARM;
  1847   static  Elf32_Half running_arch_code=EM_ARM;
  1843   #else
  1848 #else
  1844     #error Method os::dll_load requires that one of following is defined:\
  1849   #error Method os::dll_load requires that one of following is defined:\
  1845          IA32, AMD64, IA64, __sparc, __powerpc__, ARM, ARM
  1850        IA32, AMD64, IA64, __sparc, __powerpc__, ARM, ARM
  1846   #endif
  1851 #endif
  1847 
  1852 
  1848   // Identify compatability class for VM's architecture and library's architecture
  1853   // Identify compatability class for VM's architecture and library's architecture
  1849   // Obtain string descriptions for architectures
  1854   // Obtain string descriptions for architectures
  1850 
  1855 
  1851   arch_t lib_arch={elf_head.e_machine,0,elf_head.e_ident[EI_CLASS], elf_head.e_ident[EI_DATA], NULL};
  1856   arch_t lib_arch={elf_head.e_machine,0,elf_head.e_ident[EI_CLASS], elf_head.e_ident[EI_DATA], NULL};
  2217 
  2222 
  2218 // This method is a copy of JDK's sysGetLastErrorString
  2223 // This method is a copy of JDK's sysGetLastErrorString
  2219 // from src/solaris/hpi/src/system_md.c
  2224 // from src/solaris/hpi/src/system_md.c
  2220 
  2225 
  2221 size_t os::lasterror(char *buf, size_t len) {
  2226 size_t os::lasterror(char *buf, size_t len) {
  2222 
       
  2223   if (errno == 0)  return 0;
  2227   if (errno == 0)  return 0;
  2224 
  2228 
  2225   const char *s = ::strerror(errno);
  2229   const char *s = ::strerror(errno);
  2226   size_t n = ::strlen(s);
  2230   size_t n = ::strlen(s);
  2227   if (n >= len) {
  2231   if (n >= len) {
  2312   struct sigaction sigAct, oldSigAct;
  2316   struct sigaction sigAct, oldSigAct;
  2313   sigfillset(&(sigAct.sa_mask));
  2317   sigfillset(&(sigAct.sa_mask));
  2314   sigAct.sa_flags = SA_RESTART & ~SA_RESETHAND;
  2318   sigAct.sa_flags = SA_RESTART & ~SA_RESETHAND;
  2315   sigAct.sa_handler = CAST_TO_FN_PTR(sa_handler_t, handler);
  2319   sigAct.sa_handler = CAST_TO_FN_PTR(sa_handler_t, handler);
  2316 
  2320 
  2317   if (sigaction(signal_number, &sigAct, &oldSigAct))
  2321   if (sigaction(signal_number, &sigAct, &oldSigAct)) {
  2318     // -1 means registration failed
  2322     // -1 means registration failed
  2319     return (void *)-1;
  2323     return (void *)-1;
       
  2324   }
  2320 
  2325 
  2321   return CAST_FROM_FN_PTR(void*, oldSigAct.sa_handler);
  2326   return CAST_FROM_FN_PTR(void*, oldSigAct.sa_handler);
  2322 }
  2327 }
  2323 
  2328 
  2324 void os::signal_raise(int signal_number) {
  2329 void os::signal_raise(int signal_number) {
  2325   raise(signal_number);
  2330   raise(signal_number);
  2326 }
  2331 }
  2327 
  2332 
  2328 /*
  2333 // The following code is moved from os.cpp for making this
  2329  * The following code is moved from os.cpp for making this
  2334 // code platform specific, which it is by its very nature.
  2330  * code platform specific, which it is by its very nature.
       
  2331  */
       
  2332 
  2335 
  2333 // a counter for each possible signal value
  2336 // a counter for each possible signal value
  2334 static int Sigexit = 0;
  2337 static int Sigexit = 0;
  2335 static int Maxlibjsigsigs;
  2338 static int Maxlibjsigsigs;
  2336 static jint *pending_signals = NULL;
  2339 static jint *pending_signals = NULL;
  2364                                                    * (Maxsignum + 1), mtInternal);
  2367                                                    * (Maxsignum + 1), mtInternal);
  2365     memset(chainedsigactions, 0, (sizeof(struct sigaction) * (Maxsignum + 1)));
  2368     memset(chainedsigactions, 0, (sizeof(struct sigaction) * (Maxsignum + 1)));
  2366     preinstalled_sigs = (int *)os::malloc(sizeof(int) * (Maxsignum + 1), mtInternal);
  2369     preinstalled_sigs = (int *)os::malloc(sizeof(int) * (Maxsignum + 1), mtInternal);
  2367     memset(preinstalled_sigs, 0, (sizeof(int) * (Maxsignum + 1)));
  2370     memset(preinstalled_sigs, 0, (sizeof(int) * (Maxsignum + 1)));
  2368   }
  2371   }
  2369   ourSigFlags = (int*)malloc(sizeof(int) * (Maxsignum + 1 ), mtInternal);
  2372   ourSigFlags = (int*)malloc(sizeof(int) * (Maxsignum + 1), mtInternal);
  2370   memset(ourSigFlags, 0, sizeof(int) * (Maxsignum + 1));
  2373   memset(ourSigFlags, 0, sizeof(int) * (Maxsignum + 1));
  2371 }
  2374 }
  2372 
  2375 
  2373 void os::signal_init_pd() {
  2376 void os::signal_init_pd() {
  2374   int ret;
  2377   int ret;
  2409       assert(ret == 0, "sema_wait() failed");
  2412       assert(ret == 0, "sema_wait() failed");
  2410 
  2413 
  2411       // were we externally suspended while we were waiting?
  2414       // were we externally suspended while we were waiting?
  2412       threadIsSuspended = thread->handle_special_suspend_equivalent_condition();
  2415       threadIsSuspended = thread->handle_special_suspend_equivalent_condition();
  2413       if (threadIsSuspended) {
  2416       if (threadIsSuspended) {
  2414         //
       
  2415         // The semaphore has been incremented, but while we were waiting
  2417         // The semaphore has been incremented, but while we were waiting
  2416         // another thread suspended us. We don't want to continue running
  2418         // another thread suspended us. We don't want to continue running
  2417         // while suspended because that would surprise the thread that
  2419         // while suspended because that would surprise the thread that
  2418         // suspended us.
  2420         // suspended us.
  2419         //
       
  2420         ret = ::sema_post(&sig_sem);
  2421         ret = ::sema_post(&sig_sem);
  2421         assert(ret == 0, "sema_post() failed");
  2422         assert(ret == 0, "sema_post() failed");
  2422 
  2423 
  2423         thread->java_suspend_self();
  2424         thread->java_suspend_self();
  2424       }
  2425       }
  2712   return false;
  2713   return false;
  2713 }
  2714 }
  2714 
  2715 
  2715 // Scan the pages from start to end until a page different than
  2716 // Scan the pages from start to end until a page different than
  2716 // the one described in the info parameter is encountered.
  2717 // the one described in the info parameter is encountered.
  2717 char *os::scan_pages(char *start, char* end, page_info* page_expected, page_info* page_found) {
  2718 char *os::scan_pages(char *start, char* end, page_info* page_expected,
       
  2719                      page_info* page_found) {
  2718   const uint_t info_types[] = { MEMINFO_VLGRP, MEMINFO_VPAGESIZE };
  2720   const uint_t info_types[] = { MEMINFO_VLGRP, MEMINFO_VPAGESIZE };
  2719   const size_t types = sizeof(info_types) / sizeof(info_types[0]);
  2721   const size_t types = sizeof(info_types) / sizeof(info_types[0]);
  2720   uint64_t addrs[MAX_MEMINFO_CNT], outdata[types * MAX_MEMINFO_CNT + 1];
  2722   uint64_t addrs[MAX_MEMINFO_CNT], outdata[types * MAX_MEMINFO_CNT + 1];
  2721   uint_t validity[MAX_MEMINFO_CNT];
  2723   uint_t validity[MAX_MEMINFO_CNT];
  2722 
  2724 
  2739       if ((validity[i] & 1) != 0) {
  2741       if ((validity[i] & 1) != 0) {
  2740         if ((validity[i] & 4) != 0) {
  2742         if ((validity[i] & 4) != 0) {
  2741           if (outdata[types * i + 1] != page_expected->size) {
  2743           if (outdata[types * i + 1] != page_expected->size) {
  2742             break;
  2744             break;
  2743           }
  2745           }
  2744         } else
  2746         } else if (page_expected->size != 0) {
  2745         if (page_expected->size != 0) {
       
  2746           break;
  2747           break;
  2747         }
  2748         }
  2748 
  2749 
  2749         if ((validity[i] & 2) != 0 && page_expected->lgrp_id > 0) {
  2750         if ((validity[i] & 2) != 0 && page_expected->lgrp_id > 0) {
  2750           if (outdata[types * i] != page_expected->lgrp_id) {
  2751           if (outdata[types * i] != page_expected->lgrp_id) {
  2793     return NULL;
  2794     return NULL;
  2794   }
  2795   }
  2795   return b;
  2796   return b;
  2796 }
  2797 }
  2797 
  2798 
  2798 char* os::Solaris::anon_mmap(char* requested_addr, size_t bytes, size_t alignment_hint, bool fixed) {
  2799 char* os::Solaris::anon_mmap(char* requested_addr, size_t bytes,
       
  2800                              size_t alignment_hint, bool fixed) {
  2799   char* addr = requested_addr;
  2801   char* addr = requested_addr;
  2800   int flags = MAP_PRIVATE | MAP_NORESERVE;
  2802   int flags = MAP_PRIVATE | MAP_NORESERVE;
  2801 
  2803 
  2802   assert(!(fixed && (alignment_hint > 0)), "alignment hint meaningless with fixed mmap");
  2804   assert(!(fixed && (alignment_hint > 0)),
       
  2805          "alignment hint meaningless with fixed mmap");
  2803 
  2806 
  2804   if (fixed) {
  2807   if (fixed) {
  2805     flags |= MAP_FIXED;
  2808     flags |= MAP_FIXED;
  2806   } else if (has_map_align && (alignment_hint > (size_t) vm_page_size())) {
  2809   } else if (has_map_align && (alignment_hint > (size_t) vm_page_size())) {
  2807     flags |= MAP_ALIGN;
  2810     flags |= MAP_ALIGN;
  2812   // uncommitted page. Otherwise, the read/write might succeed if we
  2815   // uncommitted page. Otherwise, the read/write might succeed if we
  2813   // have enough swap space to back the physical page.
  2816   // have enough swap space to back the physical page.
  2814   return mmap_chunk(addr, bytes, flags, PROT_NONE);
  2817   return mmap_chunk(addr, bytes, flags, PROT_NONE);
  2815 }
  2818 }
  2816 
  2819 
  2817 char* os::pd_reserve_memory(size_t bytes, char* requested_addr, size_t alignment_hint) {
  2820 char* os::pd_reserve_memory(size_t bytes, char* requested_addr,
  2818   char* addr = Solaris::anon_mmap(requested_addr, bytes, alignment_hint, (requested_addr != NULL));
  2821                             size_t alignment_hint) {
       
  2822   char* addr = Solaris::anon_mmap(requested_addr, bytes, alignment_hint,
       
  2823                                   (requested_addr != NULL));
  2819 
  2824 
  2820   guarantee(requested_addr == NULL || requested_addr == addr,
  2825   guarantee(requested_addr == NULL || requested_addr == addr,
  2821             "OS failed to return requested mmap address.");
  2826             "OS failed to return requested mmap address.");
  2822   return addr;
  2827   return addr;
  2823 }
  2828 }
  3078 
  3083 
  3079     UseLargePages = Solaris::mpss_sanity_check(warn_on_failure, &_large_page_size);
  3084     UseLargePages = Solaris::mpss_sanity_check(warn_on_failure, &_large_page_size);
  3080   }
  3085   }
  3081 }
  3086 }
  3082 
  3087 
  3083 bool os::Solaris::setup_large_pages(caddr_t start, size_t bytes, size_t align) {
  3088 bool os::Solaris::setup_large_pages(caddr_t start, size_t bytes,
       
  3089                                     size_t align) {
  3084   // Signal to OS that we want large pages for addresses
  3090   // Signal to OS that we want large pages for addresses
  3085   // from addr, addr + bytes
  3091   // from addr, addr + bytes
  3086   struct memcntl_mha mpss_struct;
  3092   struct memcntl_mha mpss_struct;
  3087   mpss_struct.mha_cmd = MHA_MAPSIZE_VA;
  3093   mpss_struct.mha_cmd = MHA_MAPSIZE_VA;
  3088   mpss_struct.mha_pagesize = align;
  3094   mpss_struct.mha_pagesize = align;
  3093     return false;
  3099     return false;
  3094   }
  3100   }
  3095   return true;
  3101   return true;
  3096 }
  3102 }
  3097 
  3103 
  3098 char* os::reserve_memory_special(size_t size, size_t alignment, char* addr, bool exec) {
  3104 char* os::reserve_memory_special(size_t size, size_t alignment, char* addr,
       
  3105                                  bool exec) {
  3099   fatal("os::reserve_memory_special should not be called on Solaris.");
  3106   fatal("os::reserve_memory_special should not be called on Solaris.");
  3100   return NULL;
  3107   return NULL;
  3101 }
  3108 }
  3102 
  3109 
  3103 bool os::release_memory_special(char* base, size_t bytes) {
  3110 bool os::release_memory_special(char* base, size_t bytes) {
  3158 bool os::dont_yield() {
  3165 bool os::dont_yield() {
  3159   if (DontYieldALot) {
  3166   if (DontYieldALot) {
  3160     static hrtime_t last_time = 0;
  3167     static hrtime_t last_time = 0;
  3161     hrtime_t diff = getTimeNanos() - last_time;
  3168     hrtime_t diff = getTimeNanos() - last_time;
  3162 
  3169 
  3163     if (diff < DontYieldALotInterval * 1000000)
  3170     if (diff < DontYieldALotInterval * 1000000) {
  3164       return true;
  3171       return true;
       
  3172     }
  3165 
  3173 
  3166     last_time += diff;
  3174     last_time += diff;
  3167 
  3175 
  3168     return false;
  3176     return false;
  3169   }
  3177   } else {
  3170   else {
       
  3171     return false;
  3178     return false;
  3172   }
  3179   }
  3173 }
  3180 }
  3174 
  3181 
  3175 // Note that yield semantics are defined by the scheduling class to which
  3182 // Note that yield semantics are defined by the scheduling class to which
  3360     myMin = fxLimits.minPrio;
  3367     myMin = fxLimits.minPrio;
  3361     myMax = fxLimits.maxPrio;
  3368     myMax = fxLimits.maxPrio;
  3362     myMax = MIN2(myMax, (int)fxInfo->fx_uprilim);       // clamp - restrict
  3369     myMax = MIN2(myMax, (int)fxInfo->fx_uprilim);       // clamp - restrict
  3363   } else {
  3370   } else {
  3364     // No clue - punt
  3371     // No clue - punt
  3365     if (ThreadPriorityVerbose)
  3372     if (ThreadPriorityVerbose) {
  3366       tty->print_cr("Unknown scheduling class: %s ... \n", ClassInfo.pc_clname);
  3373       tty->print_cr("Unknown scheduling class: %s ... \n",
       
  3374                     ClassInfo.pc_clname);
       
  3375     }
  3367     return EINVAL;      // no clue, punt
  3376     return EINVAL;      // no clue, punt
  3368   }
  3377   }
  3369 
  3378 
  3370   if (ThreadPriorityVerbose) {
  3379   if (ThreadPriorityVerbose) {
  3371     tty->print_cr("Thread priority Range: [%d..%d]\n", myMin, myMax);
  3380     tty->print_cr("Thread priority Range: [%d..%d]\n", myMin, myMax);
  3384 // scale_to_lwp_priority
  3393 // scale_to_lwp_priority
  3385 //
  3394 //
  3386 // Convert from the libthread "thr_setprio" scale to our current
  3395 // Convert from the libthread "thr_setprio" scale to our current
  3387 // lwp scheduling class scale.
  3396 // lwp scheduling class scale.
  3388 //
  3397 //
  3389 static
  3398 static int scale_to_lwp_priority(int rMin, int rMax, int x) {
  3390 int     scale_to_lwp_priority (int rMin, int rMax, int x)
       
  3391 {
       
  3392   int v;
  3399   int v;
  3393 
  3400 
  3394   if (x == 127) return rMax;            // avoid round-down
  3401   if (x == 127) return rMax;            // avoid round-down
  3395   v = (((x*(rMax-rMin)))/128)+rMin;
  3402   v = (((x*(rMax-rMin)))/128)+rMin;
  3396   return v;
  3403   return v;
  3413   // Cache "pcparms_t" in global ParmCache.
  3420   // Cache "pcparms_t" in global ParmCache.
  3414   // TODO: elide set-to-same-value
  3421   // TODO: elide set-to-same-value
  3415 
  3422 
  3416   // If something went wrong on init, don't change priorities.
  3423   // If something went wrong on init, don't change priorities.
  3417   if (!priocntl_enable) {
  3424   if (!priocntl_enable) {
  3418     if (ThreadPriorityVerbose)
  3425     if (ThreadPriorityVerbose) {
  3419       tty->print_cr("Trying to set priority but init failed, ignoring");
  3426       tty->print_cr("Trying to set priority but init failed, ignoring");
       
  3427     }
  3420     return EINVAL;
  3428     return EINVAL;
  3421   }
  3429   }
  3422 
  3430 
  3423   // If lwp hasn't started yet, just return
  3431   // If lwp hasn't started yet, just return
  3424   // the _start routine will call us again.
  3432   // the _start routine will call us again.
  3576 // This mode causes the priority table to get filled with
  3584 // This mode causes the priority table to get filled with
  3577 // linear values.  NormPriority get's mapped to 50% of the
  3585 // linear values.  NormPriority get's mapped to 50% of the
  3578 // Maximum priority an so on.  This will cause VM threads
  3586 // Maximum priority an so on.  This will cause VM threads
  3579 // to get unfair treatment against other Solaris processes
  3587 // to get unfair treatment against other Solaris processes
  3580 // which do not explicitly alter their thread priorities.
  3588 // which do not explicitly alter their thread priorities.
  3581 //
       
  3582 
  3589 
  3583 int os::java_to_os_priority[CriticalPriority + 1] = {
  3590 int os::java_to_os_priority[CriticalPriority + 1] = {
  3584   -99999,         // 0 Entry should never be used
  3591   -99999,         // 0 Entry should never be used
  3585 
  3592 
  3586   0,              // 1 MinPriority
  3593   0,              // 1 MinPriority
  3639   status |= lwp_status;
  3646   status |= lwp_status;
  3640   return (status == 0) ? OS_OK : OS_ERR;
  3647   return (status == 0) ? OS_OK : OS_ERR;
  3641 }
  3648 }
  3642 
  3649 
  3643 
  3650 
  3644 OSReturn os::get_native_priority(const Thread* const thread, int *priority_ptr) {
  3651 OSReturn os::get_native_priority(const Thread* const thread,
       
  3652                                  int *priority_ptr) {
  3645   int p;
  3653   int p;
  3646   if (!UseThreadPriorities) {
  3654   if (!UseThreadPriorities) {
  3647     *priority_ptr = NormalPriority;
  3655     *priority_ptr = NormalPriority;
  3648     return OS_OK;
  3656     return OS_OK;
  3649   }
  3657   }
  3868 }
  3876 }
  3869 
  3877 
  3870 
  3878 
  3871 // This does not do anything on Solaris. This is basically a hook for being
  3879 // This does not do anything on Solaris. This is basically a hook for being
  3872 // able to use structured exception handling (thread-local exception filters) on, e.g., Win32.
  3880 // able to use structured exception handling (thread-local exception filters) on, e.g., Win32.
  3873 void os::os_exception_wrapper(java_call_t f, JavaValue* value, methodHandle* method, JavaCallArguments* args, Thread* thread) {
  3881 void os::os_exception_wrapper(java_call_t f, JavaValue* value,
       
  3882                               methodHandle* method, JavaCallArguments* args,
       
  3883                               Thread* thread) {
  3874   f(value, method, args, thread);
  3884   f(value, method, args, thread);
  3875 }
  3885 }
  3876 
  3886 
  3877 // This routine may be used by user applications as a "hook" to catch signals.
  3887 // This routine may be used by user applications as a "hook" to catch signals.
  3878 // The user-defined signal handler must pass unrecognized signals to this
  3888 // The user-defined signal handler must pass unrecognized signals to this
  3899 // the sa_flags field passed to sigaction() includes SA_SIGINFO and SA_RESTART.
  3909 // the sa_flags field passed to sigaction() includes SA_SIGINFO and SA_RESTART.
  3900 //
  3910 //
  3901 // Note that the VM will print warnings if it detects conflicting signal
  3911 // Note that the VM will print warnings if it detects conflicting signal
  3902 // handlers, unless invoked with the option "-XX:+AllowUserSignalHandlers".
  3912 // handlers, unless invoked with the option "-XX:+AllowUserSignalHandlers".
  3903 //
  3913 //
  3904 extern "C" JNIEXPORT int
  3914 extern "C" JNIEXPORT int JVM_handle_solaris_signal(int signo,
  3905 JVM_handle_solaris_signal(int signo, siginfo_t* siginfo, void* ucontext,
  3915                                                    siginfo_t* siginfo,
  3906                           int abort_if_unrecognized);
  3916                                                    void* ucontext,
       
  3917                                                    int abort_if_unrecognized);
  3907 
  3918 
  3908 
  3919 
  3909 void signalHandler(int sig, siginfo_t* info, void* ucVoid) {
  3920 void signalHandler(int sig, siginfo_t* info, void* ucVoid) {
  3910   int orig_errno = errno;  // Preserve errno value over signal handler.
  3921   int orig_errno = errno;  // Preserve errno value over signal handler.
  3911   JVM_handle_solaris_signal(sig, info, ucVoid, true);
  3922   JVM_handle_solaris_signal(sig, info, ucVoid, true);
  3912   errno = orig_errno;
  3923   errno = orig_errno;
  3913 }
  3924 }
  3914 
  3925 
  3915 /* Do not delete - if guarantee is ever removed,  a signal handler (even empty)
  3926 // Do not delete - if guarantee is ever removed,  a signal handler (even empty)
  3916    is needed to provoke threads blocked on IO to return an EINTR
  3927 // is needed to provoke threads blocked on IO to return an EINTR
  3917    Note: this explicitly does NOT call JVM_handle_solaris_signal and
  3928 // Note: this explicitly does NOT call JVM_handle_solaris_signal and
  3918    does NOT participate in signal chaining due to requirement for
  3929 // does NOT participate in signal chaining due to requirement for
  3919    NOT setting SA_RESTART to make EINTR work. */
  3930 // NOT setting SA_RESTART to make EINTR work.
  3920 extern "C" void sigINTRHandler(int sig, siginfo_t* info, void* ucVoid) {
  3931 extern "C" void sigINTRHandler(int sig, siginfo_t* info, void* ucVoid) {
  3921   if (UseSignalChaining) {
  3932   if (UseSignalChaining) {
  3922     struct sigaction *actp = os::Solaris::get_chained_signal_action(sig);
  3933     struct sigaction *actp = os::Solaris::get_chained_signal_action(sig);
  3923     if (actp && actp->sa_handler) {
  3934     if (actp && actp->sa_handler) {
  3924       vm_exit_during_initialization("Signal chaining detected for VM interrupt signal, try -XX:+UseAltSigs");
  3935       vm_exit_during_initialization("Signal chaining detected for VM interrupt signal, try -XX:+UseAltSigs");
  4006   }
  4017   }
  4007   return chained;
  4018   return chained;
  4008 }
  4019 }
  4009 
  4020 
  4010 struct sigaction* os::Solaris::get_preinstalled_handler(int sig) {
  4021 struct sigaction* os::Solaris::get_preinstalled_handler(int sig) {
  4011   assert((chainedsigactions != (struct sigaction *)NULL) && (preinstalled_sigs != (int *)NULL) , "signals not yet initialized");
  4022   assert((chainedsigactions != (struct sigaction *)NULL) &&
       
  4023          (preinstalled_sigs != (int *)NULL), "signals not yet initialized");
  4012   if (preinstalled_sigs[sig] != 0) {
  4024   if (preinstalled_sigs[sig] != 0) {
  4013     return &chainedsigactions[sig];
  4025     return &chainedsigactions[sig];
  4014   }
  4026   }
  4015   return NULL;
  4027   return NULL;
  4016 }
  4028 }
  4017 
  4029 
  4018 void os::Solaris::save_preinstalled_handler(int sig, struct sigaction& oldAct) {
  4030 void os::Solaris::save_preinstalled_handler(int sig,
  4019 
  4031                                             struct sigaction& oldAct) {
  4020   assert(sig > 0 && sig <= Maxsignum, "vm signal out of expected range");
  4032   assert(sig > 0 && sig <= Maxsignum, "vm signal out of expected range");
  4021   assert((chainedsigactions != (struct sigaction *)NULL) && (preinstalled_sigs != (int *)NULL) , "signals not yet initialized");
  4033   assert((chainedsigactions != (struct sigaction *)NULL) &&
       
  4034          (preinstalled_sigs != (int *)NULL), "signals not yet initialized");
  4022   chainedsigactions[sig] = oldAct;
  4035   chainedsigactions[sig] = oldAct;
  4023   preinstalled_sigs[sig] = 1;
  4036   preinstalled_sigs[sig] = 1;
  4024 }
  4037 }
  4025 
  4038 
  4026 void os::Solaris::set_signal_handler(int sig, bool set_installed, bool oktochain) {
  4039 void os::Solaris::set_signal_handler(int sig, bool set_installed,
       
  4040                                      bool oktochain) {
  4027   // Check for overwrite.
  4041   // Check for overwrite.
  4028   struct sigaction oldAct;
  4042   struct sigaction oldAct;
  4029   sigaction(sig, (struct sigaction*)NULL, &oldAct);
  4043   sigaction(sig, (struct sigaction*)NULL, &oldAct);
  4030   void* oldhand = oldAct.sa_sigaction ? CAST_FROM_FN_PTR(void*,  oldAct.sa_sigaction)
  4044   void* oldhand =
  4031                                       : CAST_FROM_FN_PTR(void*,  oldAct.sa_handler);
  4045       oldAct.sa_sigaction ? CAST_FROM_FN_PTR(void*,  oldAct.sa_sigaction)
       
  4046                           : CAST_FROM_FN_PTR(void*,  oldAct.sa_handler);
  4032   if (oldhand != CAST_FROM_FN_PTR(void*, SIG_DFL) &&
  4047   if (oldhand != CAST_FROM_FN_PTR(void*, SIG_DFL) &&
  4033       oldhand != CAST_FROM_FN_PTR(void*, SIG_IGN) &&
  4048       oldhand != CAST_FROM_FN_PTR(void*, SIG_IGN) &&
  4034       oldhand != CAST_FROM_FN_PTR(void*, signalHandler)) {
  4049       oldhand != CAST_FROM_FN_PTR(void*, signalHandler)) {
  4035     if (AllowUserSignalHandlers || !set_installed) {
  4050     if (AllowUserSignalHandlers || !set_installed) {
  4036       // Do not overwrite; user takes responsibility to forward to us.
  4051       // Do not overwrite; user takes responsibility to forward to us.
  4057   sigAct.sa_sigaction = signalHandler;
  4072   sigAct.sa_sigaction = signalHandler;
  4058   // Handle SIGSEGV on alternate signal stack if
  4073   // Handle SIGSEGV on alternate signal stack if
  4059   // not using stack banging
  4074   // not using stack banging
  4060   if (!UseStackBanging && sig == SIGSEGV) {
  4075   if (!UseStackBanging && sig == SIGSEGV) {
  4061     sigAct.sa_flags = SA_SIGINFO | SA_RESTART | SA_ONSTACK;
  4076     sigAct.sa_flags = SA_SIGINFO | SA_RESTART | SA_ONSTACK;
       
  4077   } else if (sig == os::Solaris::SIGinterrupt()) {
  4062     // Interruptible i/o requires SA_RESTART cleared so EINTR
  4078     // Interruptible i/o requires SA_RESTART cleared so EINTR
  4063     // is returned instead of restarting system calls
  4079     // is returned instead of restarting system calls
  4064   } else if (sig == os::Solaris::SIGinterrupt()) {
       
  4065     sigemptyset(&sigAct.sa_mask);
  4080     sigemptyset(&sigAct.sa_mask);
  4066     sigAct.sa_handler = NULL;
  4081     sigAct.sa_handler = NULL;
  4067     sigAct.sa_flags = SA_SIGINFO;
  4082     sigAct.sa_flags = SA_SIGINFO;
  4068     sigAct.sa_sigaction = sigINTRHandler;
  4083     sigAct.sa_sigaction = sigINTRHandler;
  4069   } else {
  4084   } else {
  4077                                        : CAST_FROM_FN_PTR(void*, oldAct.sa_handler);
  4092                                        : CAST_FROM_FN_PTR(void*, oldAct.sa_handler);
  4078   assert(oldhand2 == oldhand, "no concurrent signal handler installation");
  4093   assert(oldhand2 == oldhand, "no concurrent signal handler installation");
  4079 }
  4094 }
  4080 
  4095 
  4081 
  4096 
  4082 #define DO_SIGNAL_CHECK(sig) \
  4097 #define DO_SIGNAL_CHECK(sig)                      \
  4083   if (!sigismember(&check_signal_done, sig)) \
  4098   do {                                            \
  4084     os::Solaris::check_signal_handler(sig)
  4099     if (!sigismember(&check_signal_done, sig)) {  \
       
  4100       os::Solaris::check_signal_handler(sig);     \
       
  4101     }                                             \
       
  4102   } while (0)
  4085 
  4103 
  4086 // This method is a periodic task to check for misbehaving JNI applications
  4104 // This method is a periodic task to check for misbehaving JNI applications
  4087 // under CheckJNI, we can add any periodic checks here
  4105 // under CheckJNI, we can add any periodic checks here
  4088 
  4106 
  4089 void os::run_periodic_checks() {
  4107 void os::run_periodic_checks() {
  4273     }
  4291     }
  4274   }
  4292   }
  4275 }
  4293 }
  4276 
  4294 
  4277 
  4295 
  4278 void report_error(const char* file_name, int line_no, const char* title, const char* format, ...);
  4296 void report_error(const char* file_name, int line_no, const char* title,
       
  4297                   const char* format, ...);
  4279 
  4298 
  4280 const char * signames[] = {
  4299 const char * signames[] = {
  4281   "SIG0",
  4300   "SIG0",
  4282   "SIGHUP", "SIGINT", "SIGQUIT", "SIGILL", "SIGTRAP",
  4301   "SIGHUP", "SIGINT", "SIGQUIT", "SIGILL", "SIGTRAP",
  4283   "SIGABRT", "SIGEMT", "SIGFPE", "SIGKILL", "SIGBUS",
  4302   "SIGABRT", "SIGEMT", "SIGFPE", "SIGKILL", "SIGBUS",
  4387     os::Solaris::set_cond_signal(CAST_TO_FN_PTR(int_fnP_cond_tP, resolve_symbol("_lwp_cond_signal")));
  4406     os::Solaris::set_cond_signal(CAST_TO_FN_PTR(int_fnP_cond_tP, resolve_symbol("_lwp_cond_signal")));
  4388     os::Solaris::set_cond_broadcast(CAST_TO_FN_PTR(int_fnP_cond_tP, resolve_symbol("_lwp_cond_broadcast")));
  4407     os::Solaris::set_cond_broadcast(CAST_TO_FN_PTR(int_fnP_cond_tP, resolve_symbol("_lwp_cond_broadcast")));
  4389     os::Solaris::set_cond_init(lwp_cond_init);
  4408     os::Solaris::set_cond_init(lwp_cond_init);
  4390     os::Solaris::set_cond_destroy(lwp_cond_destroy);
  4409     os::Solaris::set_cond_destroy(lwp_cond_destroy);
  4391     os::Solaris::set_cond_scope(USYNC_THREAD);
  4410     os::Solaris::set_cond_scope(USYNC_THREAD);
  4392   }
  4411   } else {
  4393   else {
       
  4394     os::Solaris::set_mutex_scope(USYNC_THREAD);
  4412     os::Solaris::set_mutex_scope(USYNC_THREAD);
  4395     os::Solaris::set_cond_scope(USYNC_THREAD);
  4413     os::Solaris::set_cond_scope(USYNC_THREAD);
  4396 
  4414 
  4397     if (UsePthreads) {
  4415     if (UsePthreads) {
  4398       os::Solaris::set_mutex_lock(CAST_TO_FN_PTR(int_fnP_mutex_tP, resolve_symbol("pthread_mutex_lock")));
  4416       os::Solaris::set_mutex_lock(CAST_TO_FN_PTR(int_fnP_mutex_tP, resolve_symbol("pthread_mutex_lock")));
  4405       os::Solaris::set_cond_wait(CAST_TO_FN_PTR(int_fnP_cond_tP_mutex_tP, resolve_symbol("pthread_cond_wait")));
  4423       os::Solaris::set_cond_wait(CAST_TO_FN_PTR(int_fnP_cond_tP_mutex_tP, resolve_symbol("pthread_cond_wait")));
  4406       os::Solaris::set_cond_signal(CAST_TO_FN_PTR(int_fnP_cond_tP, resolve_symbol("pthread_cond_signal")));
  4424       os::Solaris::set_cond_signal(CAST_TO_FN_PTR(int_fnP_cond_tP, resolve_symbol("pthread_cond_signal")));
  4407       os::Solaris::set_cond_broadcast(CAST_TO_FN_PTR(int_fnP_cond_tP, resolve_symbol("pthread_cond_broadcast")));
  4425       os::Solaris::set_cond_broadcast(CAST_TO_FN_PTR(int_fnP_cond_tP, resolve_symbol("pthread_cond_broadcast")));
  4408       os::Solaris::set_cond_init(pthread_cond_default_init);
  4426       os::Solaris::set_cond_init(pthread_cond_default_init);
  4409       os::Solaris::set_cond_destroy(CAST_TO_FN_PTR(int_fnP_cond_tP, resolve_symbol("pthread_cond_destroy")));
  4427       os::Solaris::set_cond_destroy(CAST_TO_FN_PTR(int_fnP_cond_tP, resolve_symbol("pthread_cond_destroy")));
  4410     }
  4428     } else {
  4411     else {
       
  4412       os::Solaris::set_mutex_lock(CAST_TO_FN_PTR(int_fnP_mutex_tP, resolve_symbol("mutex_lock")));
  4429       os::Solaris::set_mutex_lock(CAST_TO_FN_PTR(int_fnP_mutex_tP, resolve_symbol("mutex_lock")));
  4413       os::Solaris::set_mutex_trylock(CAST_TO_FN_PTR(int_fnP_mutex_tP, resolve_symbol("mutex_trylock")));
  4430       os::Solaris::set_mutex_trylock(CAST_TO_FN_PTR(int_fnP_mutex_tP, resolve_symbol("mutex_trylock")));
  4414       os::Solaris::set_mutex_unlock(CAST_TO_FN_PTR(int_fnP_mutex_tP, resolve_symbol("mutex_unlock")));
  4431       os::Solaris::set_mutex_unlock(CAST_TO_FN_PTR(int_fnP_mutex_tP, resolve_symbol("mutex_unlock")));
  4415       os::Solaris::set_mutex_init(::mutex_init);
  4432       os::Solaris::set_mutex_init(::mutex_init);
  4416       os::Solaris::set_mutex_destroy(::mutex_destroy);
  4433       os::Solaris::set_mutex_destroy(::mutex_destroy);
  4487   max_hrtime = first_hrtime = gethrtime();
  4504   max_hrtime = first_hrtime = gethrtime();
  4488 
  4505 
  4489   init_random(1234567);
  4506   init_random(1234567);
  4490 
  4507 
  4491   page_size = sysconf(_SC_PAGESIZE);
  4508   page_size = sysconf(_SC_PAGESIZE);
  4492   if (page_size == -1)
  4509   if (page_size == -1) {
  4493     fatal(err_msg("os_solaris.cpp: os::init: sysconf failed (%s)",
  4510     fatal(err_msg("os_solaris.cpp: os::init: sysconf failed (%s)",
  4494                   strerror(errno)));
  4511                   strerror(errno)));
       
  4512   }
  4495   init_page_sizes((size_t) page_size);
  4513   init_page_sizes((size_t) page_size);
  4496 
  4514 
  4497   Solaris::initialize_system_info();
  4515   Solaris::initialize_system_info();
  4498 
  4516 
  4499   // Initialize misc. symbols as soon as possible, so we can use them
  4517   // Initialize misc. symbols as soon as possible, so we can use them
  4515   // check if dladdr1() exists; dladdr1 can provide more information than
  4533   // check if dladdr1() exists; dladdr1 can provide more information than
  4516   // dladdr for os::dll_address_to_function_name. It comes with SunOS 5.9
  4534   // dladdr for os::dll_address_to_function_name. It comes with SunOS 5.9
  4517   // and is available on linker patches for 5.7 and 5.8.
  4535   // and is available on linker patches for 5.7 and 5.8.
  4518   // libdl.so must have been loaded, this call is just an entry lookup
  4536   // libdl.so must have been loaded, this call is just an entry lookup
  4519   void * hdl = dlopen("libdl.so", RTLD_NOW);
  4537   void * hdl = dlopen("libdl.so", RTLD_NOW);
  4520   if (hdl)
  4538   if (hdl) {
  4521     dladdr1_func = CAST_TO_FN_PTR(dladdr1_func_type, dlsym(hdl, "dladdr1"));
  4539     dladdr1_func = CAST_TO_FN_PTR(dladdr1_func_type, dlsym(hdl, "dladdr1"));
       
  4540   }
  4522 
  4541 
  4523   // (Solaris only) this switches to calls that actually do locking.
  4542   // (Solaris only) this switches to calls that actually do locking.
  4524   ThreadCritical::initialize();
  4543   ThreadCritical::initialize();
  4525 
  4544 
  4526   main_thread = thr_self();
  4545   main_thread = thr_self();
  4564   }
  4583   }
  4565 
  4584 
  4566   os::set_polling_page(polling_page);
  4585   os::set_polling_page(polling_page);
  4567 
  4586 
  4568 #ifndef PRODUCT
  4587 #ifndef PRODUCT
  4569   if (Verbose && PrintMiscellaneous)
  4588   if (Verbose && PrintMiscellaneous) {
  4570     tty->print("[SafePoint Polling address: " INTPTR_FORMAT "]\n", (intptr_t)polling_page);
  4589     tty->print("[SafePoint Polling address: " INTPTR_FORMAT "]\n",
       
  4590                (intptr_t)polling_page);
       
  4591   }
  4571 #endif
  4592 #endif
  4572 
  4593 
  4573   if (!UseMembar) {
  4594   if (!UseMembar) {
  4574     address mem_serialize_page = (address)Solaris::mmap_chunk(NULL, page_size, MAP_PRIVATE, PROT_READ | PROT_WRITE);
  4595     address mem_serialize_page = (address)Solaris::mmap_chunk(NULL, page_size, MAP_PRIVATE, PROT_READ | PROT_WRITE);
  4575     guarantee(mem_serialize_page != NULL, "mmap Failed for memory serialize page");
  4596     guarantee(mem_serialize_page != NULL, "mmap Failed for memory serialize page");
  4576     os::set_memory_serialize_page(mem_serialize_page);
  4597     os::set_memory_serialize_page(mem_serialize_page);
  4577 
  4598 
  4578 #ifndef PRODUCT
  4599 #ifndef PRODUCT
  4579     if (Verbose && PrintMiscellaneous)
  4600     if (Verbose && PrintMiscellaneous) {
  4580       tty->print("[Memory Serialize  Page address: " INTPTR_FORMAT "]\n", (intptr_t)mem_serialize_page);
  4601       tty->print("[Memory Serialize  Page address: " INTPTR_FORMAT "]\n",
       
  4602                  (intptr_t)mem_serialize_page);
       
  4603     }
  4581 #endif
  4604 #endif
  4582   }
  4605   }
  4583 
  4606 
  4584   // Check minimum allowable stack size for thread creation and to initialize
  4607   // Check minimum allowable stack size for thread creation and to initialize
  4585   // the java system classes, including StackOverflowError - depends on page
  4608   // the java system classes, including StackOverflowError - depends on page
  4654     // set the number of file descriptors to max. print out error
  4677     // set the number of file descriptors to max. print out error
  4655     // if getrlimit/setrlimit fails but continue regardless.
  4678     // if getrlimit/setrlimit fails but continue regardless.
  4656     struct rlimit nbr_files;
  4679     struct rlimit nbr_files;
  4657     int status = getrlimit(RLIMIT_NOFILE, &nbr_files);
  4680     int status = getrlimit(RLIMIT_NOFILE, &nbr_files);
  4658     if (status != 0) {
  4681     if (status != 0) {
  4659       if (PrintMiscellaneous && (Verbose || WizardMode))
  4682       if (PrintMiscellaneous && (Verbose || WizardMode)) {
  4660         perror("os::init_2 getrlimit failed");
  4683         perror("os::init_2 getrlimit failed");
       
  4684       }
  4661     } else {
  4685     } else {
  4662       nbr_files.rlim_cur = nbr_files.rlim_max;
  4686       nbr_files.rlim_cur = nbr_files.rlim_max;
  4663       status = setrlimit(RLIMIT_NOFILE, &nbr_files);
  4687       status = setrlimit(RLIMIT_NOFILE, &nbr_files);
  4664       if (status != 0) {
  4688       if (status != 0) {
  4665         if (PrintMiscellaneous && (Verbose || WizardMode))
  4689         if (PrintMiscellaneous && (Verbose || WizardMode)) {
  4666           perror("os::init_2 setrlimit failed");
  4690           perror("os::init_2 setrlimit failed");
       
  4691         }
  4667       }
  4692       }
  4668     }
  4693     }
  4669   }
  4694   }
  4670 
  4695 
  4671   // Calculate theoretical max. size of Threads to guard gainst
  4696   // Calculate theoretical max. size of Threads to guard gainst
  4713   return;
  4738   return;
  4714 }
  4739 }
  4715 
  4740 
  4716 // Mark the polling page as unreadable
  4741 // Mark the polling page as unreadable
  4717 void os::make_polling_page_unreadable(void) {
  4742 void os::make_polling_page_unreadable(void) {
  4718   if (mprotect((char *)_polling_page, page_size, PROT_NONE) != 0)
  4743   if (mprotect((char *)_polling_page, page_size, PROT_NONE) != 0) {
  4719     fatal("Could not disable polling page");
  4744     fatal("Could not disable polling page");
  4720 };
  4745   }
       
  4746 }
  4721 
  4747 
  4722 // Mark the polling page as readable
  4748 // Mark the polling page as readable
  4723 void os::make_polling_page_readable(void) {
  4749 void os::make_polling_page_readable(void) {
  4724   if (mprotect((char *)_polling_page, page_size, PROT_READ) != 0)
  4750   if (mprotect((char *)_polling_page, page_size, PROT_READ) != 0) {
  4725     fatal("Could not enable polling page");
  4751     fatal("Could not enable polling page");
  4726 };
  4752   }
       
  4753 }
  4727 
  4754 
  4728 // OS interface.
  4755 // OS interface.
  4729 
  4756 
  4730 bool os::check_heap(bool force) { return true; }
  4757 bool os::check_heap(bool force) { return true; }
  4731 
  4758 
  4734 
  4761 
  4735 int local_vsnprintf(char* buf, size_t count, const char* fmt, va_list argptr) {
  4762 int local_vsnprintf(char* buf, size_t count, const char* fmt, va_list argptr) {
  4736   if (!sol_vsnprintf) {
  4763   if (!sol_vsnprintf) {
  4737     //search  for the named symbol in the objects that were loaded after libjvm
  4764     //search  for the named symbol in the objects that were loaded after libjvm
  4738     void* where = RTLD_NEXT;
  4765     void* where = RTLD_NEXT;
  4739     if ((sol_vsnprintf = CAST_TO_FN_PTR(vsnprintf_t, dlsym(where, "__vsnprintf"))) == NULL)
  4766     if ((sol_vsnprintf = CAST_TO_FN_PTR(vsnprintf_t, dlsym(where, "__vsnprintf"))) == NULL) {
  4740       sol_vsnprintf = CAST_TO_FN_PTR(vsnprintf_t, dlsym(where, "vsnprintf"));
  4767       sol_vsnprintf = CAST_TO_FN_PTR(vsnprintf_t, dlsym(where, "vsnprintf"));
       
  4768     }
  4741     if (!sol_vsnprintf){
  4769     if (!sol_vsnprintf){
  4742       //search  for the named symbol in the objects that were loaded before libjvm
  4770       //search  for the named symbol in the objects that were loaded before libjvm
  4743       where = RTLD_DEFAULT;
  4771       where = RTLD_DEFAULT;
  4744       if ((sol_vsnprintf = CAST_TO_FN_PTR(vsnprintf_t, dlsym(where, "__vsnprintf"))) == NULL)
  4772       if ((sol_vsnprintf = CAST_TO_FN_PTR(vsnprintf_t, dlsym(where, "__vsnprintf"))) == NULL) {
  4745         sol_vsnprintf = CAST_TO_FN_PTR(vsnprintf_t, dlsym(where, "vsnprintf"));
  4773         sol_vsnprintf = CAST_TO_FN_PTR(vsnprintf_t, dlsym(where, "vsnprintf"));
       
  4774       }
  4746       assert(sol_vsnprintf != NULL, "vsnprintf not found");
  4775       assert(sol_vsnprintf != NULL, "vsnprintf not found");
  4747     }
  4776     }
  4748   }
  4777   }
  4749   return (*sol_vsnprintf)(buf, count, fmt, argptr);
  4778   return (*sol_vsnprintf)(buf, count, fmt, argptr);
  4750 }
  4779 }
  4756   struct dirent *ptr;
  4785   struct dirent *ptr;
  4757 
  4786 
  4758   dir = opendir(path);
  4787   dir = opendir(path);
  4759   if (dir == NULL) return true;
  4788   if (dir == NULL) return true;
  4760 
  4789 
  4761   /* Scan the directory */
  4790   // Scan the directory
  4762   bool result = true;
  4791   bool result = true;
  4763   char buf[sizeof(struct dirent) + MAX_PATH];
  4792   char buf[sizeof(struct dirent) + MAX_PATH];
  4764   struct dirent *dbuf = (struct dirent *) buf;
  4793   struct dirent *dbuf = (struct dirent *) buf;
  4765   while (result && (ptr = readdir(dir, dbuf)) != NULL) {
  4794   while (result && (ptr = readdir(dir, dbuf)) != NULL) {
  4766     if (strcmp(ptr->d_name, ".") != 0 && strcmp(ptr->d_name, "..") != 0) {
  4795     if (strcmp(ptr->d_name, ".") != 0 && strcmp(ptr->d_name, "..") != 0) {
  4773 
  4802 
  4774 // This code originates from JDK's sysOpen and open64_w
  4803 // This code originates from JDK's sysOpen and open64_w
  4775 // from src/solaris/hpi/src/system_md.c
  4804 // from src/solaris/hpi/src/system_md.c
  4776 
  4805 
  4777 #ifndef O_DELETE
  4806 #ifndef O_DELETE
  4778 #define O_DELETE 0x10000
  4807   #define O_DELETE 0x10000
  4779 #endif
  4808 #endif
  4780 
  4809 
  4781 // Open a file. Unlink the file immediately after open returns
  4810 // Open a file. Unlink the file immediately after open returns
  4782 // if the specified oflag has the O_DELETE flag set.
  4811 // if the specified oflag has the O_DELETE flag set.
  4783 // O_DELETE is used only in j2se/src/share/native/java/util/zip/ZipFile.c
  4812 // O_DELETE is used only in j2se/src/share/native/java/util/zip/ZipFile.c
  4792   oflag = oflag & ~O_DELETE;
  4821   oflag = oflag & ~O_DELETE;
  4793 
  4822 
  4794   fd = ::open64(path, oflag, mode);
  4823   fd = ::open64(path, oflag, mode);
  4795   if (fd == -1) return -1;
  4824   if (fd == -1) return -1;
  4796 
  4825 
  4797   //If the open succeeded, the file might still be a directory
  4826   // If the open succeeded, the file might still be a directory
  4798   {
  4827   {
  4799     struct stat64 buf64;
  4828     struct stat64 buf64;
  4800     int ret = ::fstat64(fd, &buf64);
  4829     int ret = ::fstat64(fd, &buf64);
  4801     int st_mode = buf64.st_mode;
  4830     int st_mode = buf64.st_mode;
  4802 
  4831 
  4809     } else {
  4838     } else {
  4810       ::close(fd);
  4839       ::close(fd);
  4811       return -1;
  4840       return -1;
  4812     }
  4841     }
  4813   }
  4842   }
  4814     /*
  4843 
  4815      * 32-bit Solaris systems suffer from:
  4844   // 32-bit Solaris systems suffer from:
  4816      *
  4845   //
  4817      * - an historical default soft limit of 256 per-process file
  4846   // - an historical default soft limit of 256 per-process file
  4818      *   descriptors that is too low for many Java programs.
  4847   //   descriptors that is too low for many Java programs.
  4819      *
  4848   //
  4820      * - a design flaw where file descriptors created using stdio
  4849   // - a design flaw where file descriptors created using stdio
  4821      *   fopen must be less than 256, _even_ when the first limit above
  4850   //   fopen must be less than 256, _even_ when the first limit above
  4822      *   has been raised.  This can cause calls to fopen (but not calls to
  4851   //   has been raised.  This can cause calls to fopen (but not calls to
  4823      *   open, for example) to fail mysteriously, perhaps in 3rd party
  4852   //   open, for example) to fail mysteriously, perhaps in 3rd party
  4824      *   native code (although the JDK itself uses fopen).  One can hardly
  4853   //   native code (although the JDK itself uses fopen).  One can hardly
  4825      *   criticize them for using this most standard of all functions.
  4854   //   criticize them for using this most standard of all functions.
  4826      *
  4855   //
  4827      * We attempt to make everything work anyways by:
  4856   // We attempt to make everything work anyways by:
  4828      *
  4857   //
  4829      * - raising the soft limit on per-process file descriptors beyond
  4858   // - raising the soft limit on per-process file descriptors beyond
  4830      *   256
  4859   //   256
  4831      *
  4860   //
  4832      * - As of Solaris 10u4, we can request that Solaris raise the 256
  4861   // - As of Solaris 10u4, we can request that Solaris raise the 256
  4833      *   stdio fopen limit by calling function enable_extended_FILE_stdio.
  4862   //   stdio fopen limit by calling function enable_extended_FILE_stdio.
  4834      *   This is done in init_2 and recorded in enabled_extended_FILE_stdio
  4863   //   This is done in init_2 and recorded in enabled_extended_FILE_stdio
  4835      *
  4864   //
  4836      * - If we are stuck on an old (pre 10u4) Solaris system, we can
  4865   // - If we are stuck on an old (pre 10u4) Solaris system, we can
  4837      *   workaround the bug by remapping non-stdio file descriptors below
  4866   //   workaround the bug by remapping non-stdio file descriptors below
  4838      *   256 to ones beyond 256, which is done below.
  4867   //   256 to ones beyond 256, which is done below.
  4839      *
  4868   //
  4840      * See:
  4869   // See:
  4841      * 1085341: 32-bit stdio routines should support file descriptors >255
  4870   // 1085341: 32-bit stdio routines should support file descriptors >255
  4842      * 6533291: Work around 32-bit Solaris stdio limit of 256 open files
  4871   // 6533291: Work around 32-bit Solaris stdio limit of 256 open files
  4843      * 6431278: Netbeans crash on 32 bit Solaris: need to call
  4872   // 6431278: Netbeans crash on 32 bit Solaris: need to call
  4844      *          enable_extended_FILE_stdio() in VM initialisation
  4873   //          enable_extended_FILE_stdio() in VM initialisation
  4845      * Giri Mandalika's blog
  4874   // Giri Mandalika's blog
  4846      * http://technopark02.blogspot.com/2005_05_01_archive.html
  4875   // http://technopark02.blogspot.com/2005_05_01_archive.html
  4847      */
  4876   //
  4848 #ifndef  _LP64
  4877 #ifndef  _LP64
  4849   if ((!enabled_extended_FILE_stdio) && fd < 256) {
  4878   if ((!enabled_extended_FILE_stdio) && fd < 256) {
  4850     int newfd = ::fcntl(fd, F_DUPFD, 256);
  4879     int newfd = ::fcntl(fd, F_DUPFD, 256);
  4851     if (newfd != -1) {
  4880     if (newfd != -1) {
  4852       ::close(fd);
  4881       ::close(fd);
  4853       fd = newfd;
  4882       fd = newfd;
  4854     }
  4883     }
  4855   }
  4884   }
  4856 #endif // 32-bit Solaris
  4885 #endif // 32-bit Solaris
  4857     /*
  4886 
  4858      * All file descriptors that are opened in the JVM and not
  4887   // All file descriptors that are opened in the JVM and not
  4859      * specifically destined for a subprocess should have the
  4888   // specifically destined for a subprocess should have the
  4860      * close-on-exec flag set.  If we don't set it, then careless 3rd
  4889   // close-on-exec flag set.  If we don't set it, then careless 3rd
  4861      * party native code might fork and exec without closing all
  4890   // party native code might fork and exec without closing all
  4862      * appropriate file descriptors (e.g. as we do in closeDescriptors in
  4891   // appropriate file descriptors (e.g. as we do in closeDescriptors in
  4863      * UNIXProcess.c), and this in turn might:
  4892   // UNIXProcess.c), and this in turn might:
  4864      *
  4893   //
  4865      * - cause end-of-file to fail to be detected on some file
  4894   // - cause end-of-file to fail to be detected on some file
  4866      *   descriptors, resulting in mysterious hangs, or
  4895   //   descriptors, resulting in mysterious hangs, or
  4867      *
  4896   //
  4868      * - might cause an fopen in the subprocess to fail on a system
  4897   // - might cause an fopen in the subprocess to fail on a system
  4869      *   suffering from bug 1085341.
  4898   //   suffering from bug 1085341.
  4870      *
  4899   //
  4871      * (Yes, the default setting of the close-on-exec flag is a Unix
  4900   // (Yes, the default setting of the close-on-exec flag is a Unix
  4872      * design flaw)
  4901   // design flaw)
  4873      *
  4902   //
  4874      * See:
  4903   // See:
  4875      * 1085341: 32-bit stdio routines should support file descriptors >255
  4904   // 1085341: 32-bit stdio routines should support file descriptors >255
  4876      * 4843136: (process) pipe file descriptor from Runtime.exec not being closed
  4905   // 4843136: (process) pipe file descriptor from Runtime.exec not being closed
  4877      * 6339493: (process) Runtime.exec does not close all file descriptors on Solaris 9
  4906   // 6339493: (process) Runtime.exec does not close all file descriptors on Solaris 9
  4878      */
  4907   //
  4879 #ifdef FD_CLOEXEC
  4908 #ifdef FD_CLOEXEC
  4880   {
  4909   {
  4881     int flags = ::fcntl(fd, F_GETFD);
  4910     int flags = ::fcntl(fd, F_GETFD);
  4882     if (flags != -1)
  4911     if (flags != -1) {
  4883       ::fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
  4912       ::fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
       
  4913     }
  4884   }
  4914   }
  4885 #endif
  4915 #endif
  4886 
  4916 
  4887   if (o_delete != 0) {
  4917   if (o_delete != 0) {
  4888     ::unlink(path);
  4918     ::unlink(path);
  5033 void record_synch(char* name, bool returning);  // defined below
  5063 void record_synch(char* name, bool returning);  // defined below
  5034 
  5064 
  5035 class RecordSynch {
  5065 class RecordSynch {
  5036   char* _name;
  5066   char* _name;
  5037  public:
  5067  public:
  5038   RecordSynch(char* name) :_name(name)
  5068   RecordSynch(char* name) :_name(name) { record_synch(_name, false); }
  5039                  { record_synch(_name, false); }
  5069   ~RecordSynch()                       { record_synch(_name, true); }
  5040   ~RecordSynch() { record_synch(_name,   true);  }
       
  5041 };
  5070 };
  5042 
  5071 
  5043 #define CHECK_SYNCH_OP(ret, name, params, args, inner)          \
  5072 #define CHECK_SYNCH_OP(ret, name, params, args, inner)          \
  5044 extern "C" ret name params {                                    \
  5073 extern "C" ret name params {                                    \
  5045   typedef ret name##_t params;                                  \
  5074   typedef ret name##_t params;                                  \
  5065   if (!CHECK_POINTER_OK(cv)) fatal("Condvar must be in C heap only.");
  5094   if (!CHECK_POINTER_OK(cv)) fatal("Condvar must be in C heap only.");
  5066 #define CHECK_P(p) \
  5095 #define CHECK_P(p) \
  5067   if (!CHECK_POINTER_OK(p))  fatal(false,  "Pointer must be in C heap only.");
  5096   if (!CHECK_POINTER_OK(p))  fatal(false,  "Pointer must be in C heap only.");
  5068 
  5097 
  5069 #define CHECK_MUTEX(mutex_op) \
  5098 #define CHECK_MUTEX(mutex_op) \
  5070 CHECK_SYNCH_OP(int, mutex_op, (mutex_t *mu), (mu), CHECK_MU);
  5099   CHECK_SYNCH_OP(int, mutex_op, (mutex_t *mu), (mu), CHECK_MU);
  5071 
  5100 
  5072 CHECK_MUTEX(   mutex_lock)
  5101 CHECK_MUTEX(   mutex_lock)
  5073 CHECK_MUTEX(  _mutex_lock)
  5102 CHECK_MUTEX(  _mutex_lock)
  5074 CHECK_MUTEX( mutex_unlock)
  5103 CHECK_MUTEX( mutex_unlock)
  5075 CHECK_MUTEX(_mutex_unlock)
  5104 CHECK_MUTEX(_mutex_unlock)
  5076 CHECK_MUTEX( mutex_trylock)
  5105 CHECK_MUTEX( mutex_trylock)
  5077 CHECK_MUTEX(_mutex_trylock)
  5106 CHECK_MUTEX(_mutex_trylock)
  5078 
  5107 
  5079 #define CHECK_COND(cond_op) \
  5108 #define CHECK_COND(cond_op) \
  5080 CHECK_SYNCH_OP(int, cond_op, (cond_t *cv, mutex_t *mu), (cv, mu), CHECK_MU;CHECK_CV);
  5109   CHECK_SYNCH_OP(int, cond_op, (cond_t *cv, mutex_t *mu), (cv, mu), CHECK_MU; CHECK_CV);
  5081 
  5110 
  5082 CHECK_COND( cond_wait);
  5111 CHECK_COND( cond_wait);
  5083 CHECK_COND(_cond_wait);
  5112 CHECK_COND(_cond_wait);
  5084 CHECK_COND(_cond_wait_cancel);
  5113 CHECK_COND(_cond_wait_cancel);
  5085 
  5114 
  5086 #define CHECK_COND2(cond_op) \
  5115 #define CHECK_COND2(cond_op) \
  5087 CHECK_SYNCH_OP(int, cond_op, (cond_t *cv, mutex_t *mu, timestruc_t* ts), (cv, mu, ts), CHECK_MU;CHECK_CV);
  5116   CHECK_SYNCH_OP(int, cond_op, (cond_t *cv, mutex_t *mu, timestruc_t* ts), (cv, mu, ts), CHECK_MU; CHECK_CV);
  5088 
  5117 
  5089 CHECK_COND2( cond_timedwait);
  5118 CHECK_COND2( cond_timedwait);
  5090 CHECK_COND2(_cond_timedwait);
  5119 CHECK_COND2(_cond_timedwait);
  5091 CHECK_COND2(_cond_timedwait_cancel);
  5120 CHECK_COND2(_cond_timedwait_cancel);
  5092 
  5121 
  5273   memset(&dlinfo, 0, sizeof(dlinfo));
  5302   memset(&dlinfo, 0, sizeof(dlinfo));
  5274   if (dladdr(addr, &dlinfo) != 0) {
  5303   if (dladdr(addr, &dlinfo) != 0) {
  5275     st->print(PTR_FORMAT ": ", addr);
  5304     st->print(PTR_FORMAT ": ", addr);
  5276     if (dlinfo.dli_sname != NULL && dlinfo.dli_saddr != NULL) {
  5305     if (dlinfo.dli_sname != NULL && dlinfo.dli_saddr != NULL) {
  5277       st->print("%s+%#lx", dlinfo.dli_sname, addr-(intptr_t)dlinfo.dli_saddr);
  5306       st->print("%s+%#lx", dlinfo.dli_sname, addr-(intptr_t)dlinfo.dli_saddr);
  5278     } else if (dlinfo.dli_fbase != NULL)
  5307     } else if (dlinfo.dli_fbase != NULL) {
  5279       st->print("<offset %#lx>", addr-(intptr_t)dlinfo.dli_fbase);
  5308       st->print("<offset %#lx>", addr-(intptr_t)dlinfo.dli_fbase);
  5280     else
  5309     } else {
  5281       st->print("<absolute address>");
  5310       st->print("<absolute address>");
       
  5311     }
  5282     if (dlinfo.dli_fname != NULL) {
  5312     if (dlinfo.dli_fname != NULL) {
  5283       st->print(" in %s", dlinfo.dli_fname);
  5313       st->print(" in %s", dlinfo.dli_fname);
  5284     }
  5314     }
  5285     if (dlinfo.dli_fbase != NULL) {
  5315     if (dlinfo.dli_fbase != NULL) {
  5286       st->print(" at " PTR_FORMAT, dlinfo.dli_fbase);
  5316       st->print(" at " PTR_FORMAT, dlinfo.dli_fbase);
  5294       address       lowest = (address) dlinfo.dli_sname;
  5324       address       lowest = (address) dlinfo.dli_sname;
  5295       if (!lowest)  lowest = (address) dlinfo.dli_fbase;
  5325       if (!lowest)  lowest = (address) dlinfo.dli_fbase;
  5296       if (begin < lowest)  begin = lowest;
  5326       if (begin < lowest)  begin = lowest;
  5297       Dl_info dlinfo2;
  5327       Dl_info dlinfo2;
  5298       if (dladdr(end, &dlinfo2) != 0 && dlinfo2.dli_saddr != dlinfo.dli_saddr
  5328       if (dladdr(end, &dlinfo2) != 0 && dlinfo2.dli_saddr != dlinfo.dli_saddr
  5299           && end > dlinfo2.dli_saddr && dlinfo2.dli_saddr > begin)
  5329           && end > dlinfo2.dli_saddr && dlinfo2.dli_saddr > begin) {
  5300         end = (address) dlinfo2.dli_saddr;
  5330         end = (address) dlinfo2.dli_saddr;
       
  5331       }
  5301       Disassembler::decode(begin, end, st);
  5332       Disassembler::decode(begin, end, st);
  5302     }
  5333     }
  5303     return true;
  5334     return true;
  5304   }
  5335   }
  5305   return false;
  5336   return false;
  5552 }
  5583 }
  5553 
  5584 
  5554 // JSR166
  5585 // JSR166
  5555 // -------------------------------------------------------
  5586 // -------------------------------------------------------
  5556 
  5587 
  5557 /*
  5588 // The solaris and linux implementations of park/unpark are fairly
  5558  * The solaris and linux implementations of park/unpark are fairly
  5589 // conservative for now, but can be improved. They currently use a
  5559  * conservative for now, but can be improved. They currently use a
  5590 // mutex/condvar pair, plus _counter.
  5560  * mutex/condvar pair, plus _counter.
  5591 // Park decrements _counter if > 0, else does a condvar wait.  Unpark
  5561  * Park decrements _counter if > 0, else does a condvar wait.  Unpark
  5592 // sets count to 1 and signals condvar.  Only one thread ever waits
  5562  * sets count to 1 and signals condvar.  Only one thread ever waits
  5593 // on the condvar. Contention seen when trying to park implies that someone
  5563  * on the condvar. Contention seen when trying to park implies that someone
  5594 // is unparking you, so don't wait. And spurious returns are fine, so there
  5564  * is unparking you, so don't wait. And spurious returns are fine, so there
  5595 // is no need to track notifications.
  5565  * is no need to track notifications.
       
  5566  */
       
  5567 
  5596 
  5568 #define MAX_SECS 100000000
  5597 #define MAX_SECS 100000000
  5569 /*
  5598 
  5570  * This code is common to linux and solaris and will be moved to a
  5599 // This code is common to linux and solaris and will be moved to a
  5571  * common place in dolphin.
  5600 // common place in dolphin.
  5572  *
  5601 //
  5573  * The passed in time value is either a relative time in nanoseconds
  5602 // The passed in time value is either a relative time in nanoseconds
  5574  * or an absolute time in milliseconds. Either way it has to be unpacked
  5603 // or an absolute time in milliseconds. Either way it has to be unpacked
  5575  * into suitable seconds and nanoseconds components and stored in the
  5604 // into suitable seconds and nanoseconds components and stored in the
  5576  * given timespec structure.
  5605 // given timespec structure.
  5577  * Given time is a 64-bit value and the time_t used in the timespec is only
  5606 // Given time is a 64-bit value and the time_t used in the timespec is only
  5578  * a signed-32-bit value (except on 64-bit Linux) we have to watch for
  5607 // a signed-32-bit value (except on 64-bit Linux) we have to watch for
  5579  * overflow if times way in the future are given. Further on Solaris versions
  5608 // overflow if times way in the future are given. Further on Solaris versions
  5580  * prior to 10 there is a restriction (see cond_timedwait) that the specified
  5609 // prior to 10 there is a restriction (see cond_timedwait) that the specified
  5581  * number of seconds, in abstime, is less than current_time  + 100,000,000.
  5610 // number of seconds, in abstime, is less than current_time  + 100,000,000.
  5582  * As it will be 28 years before "now + 100000000" will overflow we can
  5611 // As it will be 28 years before "now + 100000000" will overflow we can
  5583  * ignore overflow and just impose a hard-limit on seconds using the value
  5612 // ignore overflow and just impose a hard-limit on seconds using the value
  5584  * of "now + 100,000,000". This places a limit on the timeout of about 3.17
  5613 // of "now + 100,000,000". This places a limit on the timeout of about 3.17
  5585  * years from "now".
  5614 // years from "now".
  5586  */
  5615 //
  5587 static void unpackTime(timespec* absTime, bool isAbsolute, jlong time) {
  5616 static void unpackTime(timespec* absTime, bool isAbsolute, jlong time) {
  5588   assert(time > 0, "convertTime");
  5617   assert(time > 0, "convertTime");
  5589 
  5618 
  5590   struct timeval now;
  5619   struct timeval now;
  5591   int status = gettimeofday(&now, NULL);
  5620   int status = gettimeofday(&now, NULL);
  5595 
  5624 
  5596   if (isAbsolute) {
  5625   if (isAbsolute) {
  5597     jlong secs = time / 1000;
  5626     jlong secs = time / 1000;
  5598     if (secs > max_secs) {
  5627     if (secs > max_secs) {
  5599       absTime->tv_sec = max_secs;
  5628       absTime->tv_sec = max_secs;
  5600     }
  5629     } else {
  5601     else {
       
  5602       absTime->tv_sec = secs;
  5630       absTime->tv_sec = secs;
  5603     }
  5631     }
  5604     absTime->tv_nsec = (time % 1000) * NANOSECS_PER_MILLISEC;
  5632     absTime->tv_nsec = (time % 1000) * NANOSECS_PER_MILLISEC;
  5605   }
  5633   } else {
  5606   else {
       
  5607     jlong secs = time / NANOSECS_PER_SEC;
  5634     jlong secs = time / NANOSECS_PER_SEC;
  5608     if (secs >= MAX_SECS) {
  5635     if (secs >= MAX_SECS) {
  5609       absTime->tv_sec = max_secs;
  5636       absTime->tv_sec = max_secs;
  5610       absTime->tv_nsec = 0;
  5637       absTime->tv_nsec = 0;
  5611     }
  5638     } else {
  5612     else {
       
  5613       absTime->tv_sec = now.tv_sec + secs;
  5639       absTime->tv_sec = now.tv_sec + secs;
  5614       absTime->tv_nsec = (time % NANOSECS_PER_SEC) + now.tv_usec*1000;
  5640       absTime->tv_nsec = (time % NANOSECS_PER_SEC) + now.tv_usec*1000;
  5615       if (absTime->tv_nsec >= NANOSECS_PER_SEC) {
  5641       if (absTime->tv_nsec >= NANOSECS_PER_SEC) {
  5616         absTime->tv_nsec -= NANOSECS_PER_SEC;
  5642         absTime->tv_nsec -= NANOSECS_PER_SEC;
  5617         ++absTime->tv_sec; // note: this must be <= max_secs
  5643         ++absTime->tv_sec; // note: this must be <= max_secs
  5829   // Get path to libjvm.so
  5855   // Get path to libjvm.so
  5830   os::jvm_path(buf, sizeof(buf));
  5856   os::jvm_path(buf, sizeof(buf));
  5831 
  5857 
  5832   // Get rid of libjvm.so
  5858   // Get rid of libjvm.so
  5833   p = strrchr(buf, '/');
  5859   p = strrchr(buf, '/');
  5834   if (p == NULL) return false;
  5860   if (p == NULL) {
  5835   else *p = '\0';
  5861     return false;
       
  5862   } else {
       
  5863     *p = '\0';
       
  5864   }
  5836 
  5865 
  5837   // Get rid of client or server
  5866   // Get rid of client or server
  5838   p = strrchr(buf, '/');
  5867   p = strrchr(buf, '/');
  5839   if (p == NULL) return false;
  5868   if (p == NULL) {
  5840   else *p = '\0';
  5869     return false;
       
  5870   } else {
       
  5871     *p = '\0';
       
  5872   }
  5841 
  5873 
  5842   // check xawt/libmawt.so
  5874   // check xawt/libmawt.so
  5843   strcpy(libmawtpath, buf);
  5875   strcpy(libmawtpath, buf);
  5844   strcat(libmawtpath, xawtstr);
  5876   strcat(libmawtpath, xawtstr);
  5845   if (::stat(libmawtpath, &statbuf) == 0) return false;
  5877   if (::stat(libmawtpath, &statbuf) == 0) return false;
  5909     if (res == OS_ERR && errno == EINTR) {
  5941     if (res == OS_ERR && errno == EINTR) {
  5910       if (timeout != -1) {
  5942       if (timeout != -1) {
  5911         gettimeofday(&t, &aNull);
  5943         gettimeofday(&t, &aNull);
  5912         newtime = ((julong)t.tv_sec * 1000)  +  t.tv_usec /1000;
  5944         newtime = ((julong)t.tv_sec * 1000)  +  t.tv_usec /1000;
  5913         timeout -= newtime - prevtime;
  5945         timeout -= newtime - prevtime;
  5914         if (timeout <= 0)
  5946         if (timeout <= 0) {
  5915           return OS_OK;
  5947           return OS_OK;
       
  5948         }
  5916         prevtime = newtime;
  5949         prevtime = newtime;
  5917       }
  5950       }
  5918     } else return res;
  5951     } else return res;
  5919   }
  5952   }
  5920 }
  5953 }
  5941   //                      connection  attempt  has  not yet been com-
  5974   //                      connection  attempt  has  not yet been com-
  5942   //                      pleted.
  5975   //                      pleted.
  5943   //
  5976   //
  5944   //     EISCONN          The socket is already connected.
  5977   //     EISCONN          The socket is already connected.
  5945   if (_result == OS_ERR && errno == EINTR) {
  5978   if (_result == OS_ERR && errno == EINTR) {
  5946      /* restarting a connect() changes its errno semantics */
  5979     // restarting a connect() changes its errno semantics
  5947     RESTARTABLE(::connect(fd, him, len), _result);
  5980     RESTARTABLE(::connect(fd, him, len), _result);
  5948      /* undo these changes */
  5981     // undo these changes
  5949     if (_result == OS_ERR) {
  5982     if (_result == OS_ERR) {
  5950       if (errno == EALREADY) {
  5983       if (errno == EALREADY) {
  5951         errno = EINPROGRESS; /* fall through */
  5984         errno = EINPROGRESS; // fall through
  5952       } else if (errno == EISCONN) {
  5985       } else if (errno == EISCONN) {
  5953         errno = 0;
  5986         errno = 0;
  5954         return OS_OK;
  5987         return OS_OK;
  5955       }
  5988       }
  5956     }
  5989     }