hotspot/src/os/solaris/vm/os_solaris.cpp
changeset 26685 aa239a0dfbea
parent 26557 e399effe36f9
parent 26684 d1221849ea3d
child 26823 e4d9c51281a1
child 26704 36bff23b2c2e
equal deleted inserted replaced
26682:f339669ba825 26685:aa239a0dfbea
   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();
   209   if (thread != NULL) {
   209   if (thread != NULL) {
   210     address sp = os::current_stack_pointer();
   210     address sp = os::current_stack_pointer();
   211     guarantee(thread->_stack_base == NULL ||
   211     guarantee(thread->_stack_base == NULL ||
   212               (sp <= thread->_stack_base &&
   212               (sp <= thread->_stack_base &&
   213                  sp >= thread->_stack_base - thread->_stack_size) ||
   213               sp >= thread->_stack_base - thread->_stack_size) ||
   214                is_error_reported(),
   214               is_error_reported(),
   215               "sp must be inside of selected thread stack");
   215               "sp must be inside of selected thread stack");
   216 
   216 
   217     thread->set_self_raw_id(raw_id);  // mark for quick retrieval
   217     thread->set_self_raw_id(raw_id);  // mark for quick retrieval
   218     _get_thread_cache[index] = thread;
   218     _get_thread_cache[index] = thread;
   219   }
   219   }
   330   }
   330   }
   331 }
   331 }
   332 
   332 
   333 static int _processors_online = 0;
   333 static int _processors_online = 0;
   334 
   334 
   335          jint os::Solaris::_os_thread_limit = 0;
   335 jint os::Solaris::_os_thread_limit = 0;
   336 volatile jint os::Solaris::_os_thread_count = 0;
   336 volatile jint os::Solaris::_os_thread_count = 0;
   337 
   337 
   338 julong os::available_memory() {
   338 julong os::available_memory() {
   339   return Solaris::available_memory();
   339   return Solaris::available_memory();
   340 }
   340 }
   344 }
   344 }
   345 
   345 
   346 julong os::Solaris::_physical_memory = 0;
   346 julong os::Solaris::_physical_memory = 0;
   347 
   347 
   348 julong os::physical_memory() {
   348 julong os::physical_memory() {
   349    return Solaris::physical_memory();
   349   return Solaris::physical_memory();
   350 }
   350 }
   351 
   351 
   352 static hrtime_t first_hrtime = 0;
   352 static hrtime_t first_hrtime = 0;
   353 static const hrtime_t hrtime_hz = 1000*1000*1000;
   353 static const hrtime_t hrtime_hz = 1000*1000*1000;
   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();
   430       }
   431       }
   431     }
   432     }
   432     next += 1;
   433     next += 1;
   433   }
   434   }
   434   if (found < *id_length) {
   435   if (found < *id_length) {
   435       // The loop above didn't identify the expected number of processors.
   436     // The loop above didn't identify the expected number of processors.
   436       // We could always retry the operation, calling sysconf(_SC_NPROCESSORS_ONLN)
   437     // We could always retry the operation, calling sysconf(_SC_NPROCESSORS_ONLN)
   437       // and re-running the loop, above, but there's no guarantee of progress
   438     // and re-running the loop, above, but there's no guarantee of progress
   438       // if the system configuration is in flux.  Instead, we just return what
   439     // if the system configuration is in flux.  Instead, we just return what
   439       // we've got.  Note that in the worst case find_processors_online() could
   440     // we've got.  Note that in the worst case find_processors_online() could
   440       // return an empty set.  (As a fall-back in the case of the empty set we
   441     // return an empty set.  (As a fall-back in the case of the empty set we
   441       // could just return the ID of the current processor).
   442     // could just return the ID of the current processor).
   442       *id_length = found;
   443     *id_length = found;
   443   }
   444   }
   444 
   445 
   445   return true;
   446   return true;
   446 }
   447 }
   447 
   448 
   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);
   930 #ifdef ASSERT
   928 #ifdef ASSERT
   931   thread->verify_not_published();
   929   thread->verify_not_published();
   932 #endif
   930 #endif
   933   OSThread* osthread = create_os_thread(thread, thr_self());
   931   OSThread* osthread = create_os_thread(thread, thr_self());
   934   if (osthread == NULL) {
   932   if (osthread == NULL) {
   935      return false;
   933     return false;
   936   }
   934   }
   937 
   935 
   938   // Initial thread state is RUNNABLE
   936   // Initial thread state is RUNNABLE
   939   osthread->set_state(RUNNABLE);
   937   osthread->set_state(RUNNABLE);
   940   thread->set_osthread(osthread);
   938   thread->set_osthread(osthread);
   950 #ifdef ASSERT
   948 #ifdef ASSERT
   951   thread->verify_not_published();
   949   thread->verify_not_published();
   952 #endif
   950 #endif
   953   if (_starting_thread == NULL) {
   951   if (_starting_thread == NULL) {
   954     _starting_thread = create_os_thread(thread, main_thread);
   952     _starting_thread = create_os_thread(thread, main_thread);
   955      if (_starting_thread == NULL) {
   953     if (_starting_thread == NULL) {
   956         return false;
   954       return false;
   957      }
   955     }
   958   }
   956   }
   959 
   957 
   960   // The primodial thread is runnable from the start
   958   // The primodial thread is runnable from the start
   961   _starting_thread->set_state(RUNNABLE);
   959   _starting_thread->set_state(RUNNABLE);
   962 
   960 
   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   }
   979 
   978 
   980   if (ThreadPriorityVerbose) {
   979   if (ThreadPriorityVerbose) {
   981     char *thrtyp;
   980     char *thrtyp;
   982     switch (thr_type) {
   981     switch (thr_type) {
   983       case vm_thread:
   982     case vm_thread:
   984         thrtyp = (char *)"vm";
   983       thrtyp = (char *)"vm";
   985         break;
   984       break;
   986       case cgc_thread:
   985     case cgc_thread:
   987         thrtyp = (char *)"cgc";
   986       thrtyp = (char *)"cgc";
   988         break;
   987       break;
   989       case pgc_thread:
   988     case pgc_thread:
   990         thrtyp = (char *)"pgc";
   989       thrtyp = (char *)"pgc";
   991         break;
   990       break;
   992       case java_thread:
   991     case java_thread:
   993         thrtyp = (char *)"java";
   992       thrtyp = (char *)"java";
   994         break;
   993       break;
   995       case compiler_thread:
   994     case compiler_thread:
   996         thrtyp = (char *)"compiler";
   995       thrtyp = (char *)"compiler";
   997         break;
   996       break;
   998       case watcher_thread:
   997     case watcher_thread:
   999         thrtyp = (char *)"watcher";
   998       thrtyp = (char *)"watcher";
  1000         break;
   999       break;
  1001       default:
  1000     default:
  1002         thrtyp = (char *)"unknown";
  1001       thrtyp = (char *)"unknown";
  1003         break;
  1002       break;
  1004     }
  1003     }
  1005     tty->print_cr("In create_thread, creating a %s thread\n", thrtyp);
  1004     tty->print_cr("In create_thread, creating a %s thread\n", thrtyp);
  1006   }
  1005   }
  1007 
  1006 
  1008   // Calculate stack size if it's not specified by caller.
  1007   // Calculate stack size if it's not specified by caller.
  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;
  1104 int os::Solaris::_SIGasync = ASYNC_SIGNAL;
  1103 int os::Solaris::_SIGasync = ASYNC_SIGNAL;
  1105 
  1104 
  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() {
  1156 
  1156 
  1157   sigaddset(&unblocked_sigs, os::Solaris::SIGinterrupt());
  1157   sigaddset(&unblocked_sigs, os::Solaris::SIGinterrupt());
  1158   sigaddset(&unblocked_sigs, os::Solaris::SIGasync());
  1158   sigaddset(&unblocked_sigs, os::Solaris::SIGasync());
  1159 
  1159 
  1160   if (!ReduceSignalUsage) {
  1160   if (!ReduceSignalUsage) {
  1161    if (!os::Solaris::is_sig_ignored(SHUTDOWN1_SIGNAL)) {
  1161     if (!os::Solaris::is_sig_ignored(SHUTDOWN1_SIGNAL)) {
  1162       sigaddset(&unblocked_sigs, SHUTDOWN1_SIGNAL);
  1162       sigaddset(&unblocked_sigs, SHUTDOWN1_SIGNAL);
  1163       sigaddset(&allowdebug_blocked_sigs, SHUTDOWN1_SIGNAL);
  1163       sigaddset(&allowdebug_blocked_sigs, SHUTDOWN1_SIGNAL);
  1164    }
  1164     }
  1165    if (!os::Solaris::is_sig_ignored(SHUTDOWN2_SIGNAL)) {
  1165     if (!os::Solaris::is_sig_ignored(SHUTDOWN2_SIGNAL)) {
  1166       sigaddset(&unblocked_sigs, SHUTDOWN2_SIGNAL);
  1166       sigaddset(&unblocked_sigs, SHUTDOWN2_SIGNAL);
  1167       sigaddset(&allowdebug_blocked_sigs, SHUTDOWN2_SIGNAL);
  1167       sigaddset(&allowdebug_blocked_sigs, SHUTDOWN2_SIGNAL);
  1168    }
  1168     }
  1169    if (!os::Solaris::is_sig_ignored(SHUTDOWN3_SIGNAL)) {
  1169     if (!os::Solaris::is_sig_ignored(SHUTDOWN3_SIGNAL)) {
  1170       sigaddset(&unblocked_sigs, SHUTDOWN3_SIGNAL);
  1170       sigaddset(&unblocked_sigs, SHUTDOWN3_SIGNAL);
  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     }
  1260     assert(jt->stack_size() >= stack_size,
  1260     assert(jt->stack_size() >= stack_size,
  1261           "Attempt to map more stack than was allocated");
  1261            "Attempt to map more stack than was allocated");
  1262     jt->set_stack_size(stack_size);
  1262     jt->set_stack_size(stack_size);
  1263   }
  1263   }
  1264 
  1264 
  1265   // With the T2 libthread (T1 is no longer supported) threads are always bound
  1265   // With the T2 libthread (T1 is no longer supported) threads are always bound
  1266   // and we use stackbanging in all cases.
  1266   // and we use stackbanging in all cases.
  1279   // We are told to free resources of the argument thread,
  1279   // We are told to free resources of the argument thread,
  1280   // but we can only really operate on the current thread.
  1280   // but we can only really operate on the current thread.
  1281   // The main thread must take the VMThread down synchronously
  1281   // The main thread must take the VMThread down synchronously
  1282   // before the main thread exits and frees up CodeHeap
  1282   // before the main thread exits and frees up CodeHeap
  1283   guarantee((Thread::current()->osthread() == osthread
  1283   guarantee((Thread::current()->osthread() == osthread
  1284      || (osthread == VMThread::vm_thread()->osthread())), "os::free_thread but not current thread");
  1284              || (osthread == VMThread::vm_thread()->osthread())), "os::free_thread but not current thread");
  1285   if (Thread::current()->osthread() == osthread) {
  1285   if (Thread::current()->osthread() == osthread) {
  1286     // Restore caller's signal mask
  1286     // Restore caller's signal mask
  1287     sigset_t sigmask = osthread->caller_sigmask();
  1287     sigset_t sigmask = osthread->caller_sigmask();
  1288     thr_sigsetmask(SIG_SETMASK, &sigmask, NULL);
  1288     thr_sigsetmask(SIG_SETMASK, &sigmask, NULL);
  1289   }
  1289   }
  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 
  1341                       // small number - point is NO swap space available
  1342 // libthread allocate for tsd_common is a version specific
       
  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,
  1347                              "thr_setspecific: out of swap space");
  1350                             "thr_setspecific: out of swap space");
  1348     } else {
  1351     } else {
  1349       fatal(err_msg("os::thread_local_storage_at_put: thr_setspecific failed "
  1352       fatal(err_msg("os::thread_local_storage_at_put: thr_setspecific failed "
  1350                     "(%s)", strerror(errno)));
  1353                     "(%s)", strerror(errno)));
  1351     }
  1354     }
  1352   } else {
  1355   } else {
  1353       ThreadLocalStorage::set_thread_in_slot((Thread *) value);
  1356     ThreadLocalStorage::set_thread_in_slot((Thread *) value);
  1354   }
  1357   }
  1355 }
  1358 }
  1356 
  1359 
  1357 // This function could be called before TLS is initialized, for example, when
  1360 // This function could be called before TLS is initialized, for example, when
  1358 // VM receives an async signal or when VM causes a fatal error during
  1361 // VM receives an async signal or when VM causes a fatal error during
  1400 jlong os::elapsed_counter() {
  1403 jlong os::elapsed_counter() {
  1401   return (jlong)(getTimeNanos() - first_hrtime);
  1404   return (jlong)(getTimeNanos() - first_hrtime);
  1402 }
  1405 }
  1403 
  1406 
  1404 jlong os::elapsed_frequency() {
  1407 jlong os::elapsed_frequency() {
  1405    return hrtime_hz;
  1408   return hrtime_hz;
  1406 }
  1409 }
  1407 
  1410 
  1408 // Return the real, user, and system times in seconds from an
  1411 // Return the real, user, and system times in seconds from an
  1409 // arbitrary fixed point in the past.
  1412 // arbitrary fixed point in the past.
  1410 bool os::getTimesSecs(double* process_real_time,
  1413 bool os::getTimesSecs(double* process_real_time,
  1411                   double* process_user_time,
  1414                       double* process_user_time,
  1412                   double* process_system_time) {
  1415                       double* process_system_time) {
  1413   struct tms ticks;
  1416   struct tms ticks;
  1414   clock_t real_ticks = times(&ticks);
  1417   clock_t real_ticks = times(&ticks);
  1415 
  1418 
  1416   if (real_ticks == (clock_t) (-1)) {
  1419   if (real_ticks == (clock_t) (-1)) {
  1417     return false;
  1420     return false;
  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
  1770   if (get_loaded_modules_info(_print_dll_info_cb, (void *)st)) {
  1776   if (get_loaded_modules_info(_print_dll_info_cb, (void *)st)) {
  1771     st->print_cr("Error: Cannot print dynamic libraries.");
  1777     st->print_cr("Error: Cannot print dynamic libraries.");
  1772   }
  1778   }
  1773 }
  1779 }
  1774 
  1780 
  1775   // Loads .dll/.so and
  1781 // Loads .dll/.so and
  1776   // in case of error it checks if .dll/.so was built for the
  1782 // in case of error it checks if .dll/.so was built for the
  1777   // same architecture as Hotspot is running on
  1783 // same architecture as Hotspot is running on
  1778 
  1784 
  1779 void * os::dll_load(const char *filename, char *ebuf, int ebuflen)
  1785 void * os::dll_load(const char *filename, char *ebuf, int ebuflen) {
  1780 {
       
  1781   void * result= ::dlopen(filename, RTLD_LAZY);
  1786   void * result= ::dlopen(filename, RTLD_LAZY);
  1782   if (result != NULL) {
  1787   if (result != NULL) {
  1783     // Successful loading
  1788     // Successful loading
  1784     return result;
  1789     return result;
  1785   }
  1790   }
  1806     return NULL;
  1811     return NULL;
  1807   }
  1812   }
  1808 
  1813 
  1809   bool failed_to_read_elf_head=
  1814   bool failed_to_read_elf_head=
  1810     (sizeof(elf_head)!=
  1815     (sizeof(elf_head)!=
  1811         (::read(file_descriptor, &elf_head,sizeof(elf_head))));
  1816      (::read(file_descriptor, &elf_head,sizeof(elf_head))));
  1812 
  1817 
  1813   ::close(file_descriptor);
  1818   ::close(file_descriptor);
  1814   if (failed_to_read_elf_head) {
  1819   if (failed_to_read_elf_head) {
  1815     // file i/o error - report dlerror() msg
  1820     // file i/o error - report dlerror() msg
  1816     return NULL;
  1821     return NULL;
  1835     {EM_PPC,         EM_PPC,     ELFCLASS32, ELFDATA2MSB, (char*)"Power PC 32"},
  1840     {EM_PPC,         EM_PPC,     ELFCLASS32, ELFDATA2MSB, (char*)"Power PC 32"},
  1836     {EM_PPC64,       EM_PPC64,   ELFCLASS64, ELFDATA2MSB, (char*)"Power PC 64"},
  1841     {EM_PPC64,       EM_PPC64,   ELFCLASS64, ELFDATA2MSB, (char*)"Power PC 64"},
  1837     {EM_ARM,         EM_ARM,     ELFCLASS32, ELFDATA2LSB, (char*)"ARM 32"}
  1842     {EM_ARM,         EM_ARM,     ELFCLASS32, ELFDATA2LSB, (char*)"ARM 32"}
  1838   };
  1843   };
  1839 
  1844 
  1840   #if  (defined IA32)
  1845 #if  (defined IA32)
  1841     static  Elf32_Half running_arch_code=EM_386;
  1846   static  Elf32_Half running_arch_code=EM_386;
  1842   #elif   (defined AMD64)
  1847 #elif   (defined AMD64)
  1843     static  Elf32_Half running_arch_code=EM_X86_64;
  1848   static  Elf32_Half running_arch_code=EM_X86_64;
  1844   #elif  (defined IA64)
  1849 #elif  (defined IA64)
  1845     static  Elf32_Half running_arch_code=EM_IA_64;
  1850   static  Elf32_Half running_arch_code=EM_IA_64;
  1846   #elif  (defined __sparc) && (defined _LP64)
  1851 #elif  (defined __sparc) && (defined _LP64)
  1847     static  Elf32_Half running_arch_code=EM_SPARCV9;
  1852   static  Elf32_Half running_arch_code=EM_SPARCV9;
  1848   #elif  (defined __sparc) && (!defined _LP64)
  1853 #elif  (defined __sparc) && (!defined _LP64)
  1849     static  Elf32_Half running_arch_code=EM_SPARC;
  1854   static  Elf32_Half running_arch_code=EM_SPARC;
  1850   #elif  (defined __powerpc64__)
  1855 #elif  (defined __powerpc64__)
  1851     static  Elf32_Half running_arch_code=EM_PPC64;
  1856   static  Elf32_Half running_arch_code=EM_PPC64;
  1852   #elif  (defined __powerpc__)
  1857 #elif  (defined __powerpc__)
  1853     static  Elf32_Half running_arch_code=EM_PPC;
  1858   static  Elf32_Half running_arch_code=EM_PPC;
  1854   #elif (defined ARM)
  1859 #elif (defined ARM)
  1855     static  Elf32_Half running_arch_code=EM_ARM;
  1860   static  Elf32_Half running_arch_code=EM_ARM;
  1856   #else
  1861 #else
  1857     #error Method os::dll_load requires that one of following is defined:\
  1862   #error Method os::dll_load requires that one of following is defined:\
  1858          IA32, AMD64, IA64, __sparc, __powerpc__, ARM, ARM
  1863        IA32, AMD64, IA64, __sparc, __powerpc__, ARM, ARM
  1859   #endif
  1864 #endif
  1860 
  1865 
  1861   // Identify compatability class for VM's architecture and library's architecture
  1866   // Identify compatability class for VM's architecture and library's architecture
  1862   // Obtain string descriptions for architectures
  1867   // Obtain string descriptions for architectures
  1863 
  1868 
  1864   arch_t lib_arch={elf_head.e_machine,0,elf_head.e_ident[EI_CLASS], elf_head.e_ident[EI_DATA], NULL};
  1869   arch_t lib_arch={elf_head.e_machine,0,elf_head.e_ident[EI_CLASS], elf_head.e_ident[EI_DATA], NULL};
  1873       lib_arch.name         = arch_array[i].name;
  1878       lib_arch.name         = arch_array[i].name;
  1874     }
  1879     }
  1875   }
  1880   }
  1876 
  1881 
  1877   assert(running_arch_index != -1,
  1882   assert(running_arch_index != -1,
  1878     "Didn't find running architecture code (running_arch_code) in arch_array");
  1883          "Didn't find running architecture code (running_arch_code) in arch_array");
  1879   if (running_arch_index == -1) {
  1884   if (running_arch_index == -1) {
  1880     // Even though running architecture detection failed
  1885     // Even though running architecture detection failed
  1881     // we may still continue with reporting dlerror() message
  1886     // we may still continue with reporting dlerror() message
  1882     return NULL;
  1887     return NULL;
  1883   }
  1888   }
  1893   }
  1898   }
  1894 
  1899 
  1895   if (lib_arch.compat_class != arch_array[running_arch_index].compat_class) {
  1900   if (lib_arch.compat_class != arch_array[running_arch_index].compat_class) {
  1896     if (lib_arch.name!=NULL) {
  1901     if (lib_arch.name!=NULL) {
  1897       ::snprintf(diag_msg_buf, diag_msg_max_length-1,
  1902       ::snprintf(diag_msg_buf, diag_msg_max_length-1,
  1898         " (Possible cause: can't load %s-bit .so on a %s-bit platform)",
  1903                  " (Possible cause: can't load %s-bit .so on a %s-bit platform)",
  1899         lib_arch.name, arch_array[running_arch_index].name);
  1904                  lib_arch.name, arch_array[running_arch_index].name);
  1900     } else {
  1905     } else {
  1901       ::snprintf(diag_msg_buf, diag_msg_max_length-1,
  1906       ::snprintf(diag_msg_buf, diag_msg_max_length-1,
  1902       " (Possible cause: can't load this .so (machine code=0x%x) on a %s-bit platform)",
  1907                  " (Possible cause: can't load this .so (machine code=0x%x) on a %s-bit platform)",
  1903         lib_arch.code,
  1908                  lib_arch.code,
  1904         arch_array[running_arch_index].name);
  1909                  arch_array[running_arch_index].name);
  1905     }
  1910     }
  1906   }
  1911   }
  1907 
  1912 
  1908   return NULL;
  1913   return NULL;
  1909 }
  1914 }
  1927 }
  1932 }
  1928 
  1933 
  1929 static bool _print_ascii_file(const char* filename, outputStream* st) {
  1934 static bool _print_ascii_file(const char* filename, outputStream* st) {
  1930   int fd = ::open(filename, O_RDONLY);
  1935   int fd = ::open(filename, O_RDONLY);
  1931   if (fd == -1) {
  1936   if (fd == -1) {
  1932      return false;
  1937     return false;
  1933   }
  1938   }
  1934 
  1939 
  1935   char buf[32];
  1940   char buf[32];
  1936   int bytes;
  1941   int bytes;
  1937   while ((bytes = ::read(fd, buf, sizeof(buf))) > 0) {
  1942   while ((bytes = ::read(fd, buf, sizeof(buf))) > 0) {
  1965   os::Posix::print_load_average(st);
  1970   os::Posix::print_load_average(st);
  1966 }
  1971 }
  1967 
  1972 
  1968 void os::Solaris::print_distro_info(outputStream* st) {
  1973 void os::Solaris::print_distro_info(outputStream* st) {
  1969   if (!_print_ascii_file("/etc/release", st)) {
  1974   if (!_print_ascii_file("/etc/release", st)) {
  1970       st->print("Solaris");
  1975     st->print("Solaris");
  1971     }
  1976   }
  1972     st->cr();
  1977   st->cr();
  1973 }
  1978 }
  1974 
  1979 
  1975 void os::Solaris::print_libversion_info(outputStream* st) {
  1980 void os::Solaris::print_libversion_info(outputStream* st) {
  1976   st->print("  (T2 libthread)");
  1981   st->print("  (T2 libthread)");
  1977   st->cr();
  1982   st->cr();
  2066   }
  2071   }
  2067   return buf;
  2072   return buf;
  2068 }
  2073 }
  2069 
  2074 
  2070 static void print_signal_handler(outputStream* st, int sig,
  2075 static void print_signal_handler(outputStream* st, int sig,
  2071                                   char* buf, size_t buflen) {
  2076                                  char* buf, size_t buflen) {
  2072   struct sigaction sa;
  2077   struct sigaction sa;
  2073 
  2078 
  2074   sigaction(sig, NULL, &sa);
  2079   sigaction(sig, NULL, &sa);
  2075 
  2080 
  2076   st->print("%s: ", os::exception_name(sig, buf, buflen));
  2081   st->print("%s: ", os::exception_name(sig, buf, buflen));
  2100   st->print(", sa_flags=");
  2105   st->print(", sa_flags=");
  2101   os::Posix::print_sa_flags(st, sa.sa_flags);
  2106   os::Posix::print_sa_flags(st, sa.sa_flags);
  2102 
  2107 
  2103   // Check: is it our handler?
  2108   // Check: is it our handler?
  2104   if (handler == CAST_FROM_FN_PTR(address, signalHandler) ||
  2109   if (handler == CAST_FROM_FN_PTR(address, signalHandler) ||
  2105      handler == CAST_FROM_FN_PTR(address, sigINTRHandler)) {
  2110       handler == CAST_FROM_FN_PTR(address, sigINTRHandler)) {
  2106     // It is our signal handler
  2111     // It is our signal handler
  2107     // check for flags
  2112     // check for flags
  2108     if (sa.sa_flags != os::Solaris::get_our_sigflags(sig)) {
  2113     if (sa.sa_flags != os::Solaris::get_our_sigflags(sig)) {
  2109       st->print(
  2114       st->print(
  2110         ", flags was changed from " PTR32_FORMAT ", consider using jsig library",
  2115                 ", flags was changed from " PTR32_FORMAT ", consider using jsig library",
  2111         os::Solaris::get_our_sigflags(sig));
  2116                 os::Solaris::get_our_sigflags(sig));
  2112     }
  2117     }
  2113   }
  2118   }
  2114   st->cr();
  2119   st->cr();
  2115 }
  2120 }
  2116 
  2121 
  2230 
  2235 
  2231 // This method is a copy of JDK's sysGetLastErrorString
  2236 // This method is a copy of JDK's sysGetLastErrorString
  2232 // from src/solaris/hpi/src/system_md.c
  2237 // from src/solaris/hpi/src/system_md.c
  2233 
  2238 
  2234 size_t os::lasterror(char *buf, size_t len) {
  2239 size_t os::lasterror(char *buf, size_t len) {
  2235 
       
  2236   if (errno == 0)  return 0;
  2240   if (errno == 0)  return 0;
  2237 
  2241 
  2238   const char *s = ::strerror(errno);
  2242   const char *s = ::strerror(errno);
  2239   size_t n = ::strlen(s);
  2243   size_t n = ::strlen(s);
  2240   if (n >= len) {
  2244   if (n >= len) {
  2251 extern "C" {
  2255 extern "C" {
  2252   static void UserHandler(int sig, void *siginfo, void *context) {
  2256   static void UserHandler(int sig, void *siginfo, void *context) {
  2253     // Ctrl-C is pressed during error reporting, likely because the error
  2257     // Ctrl-C is pressed during error reporting, likely because the error
  2254     // handler fails to abort. Let VM die immediately.
  2258     // handler fails to abort. Let VM die immediately.
  2255     if (sig == SIGINT && is_error_reported()) {
  2259     if (sig == SIGINT && is_error_reported()) {
  2256        os::die();
  2260       os::die();
  2257     }
  2261     }
  2258 
  2262 
  2259     os::signal_notify(sig);
  2263     os::signal_notify(sig);
  2260     // We do not need to reinstate the signal handler each time...
  2264     // We do not need to reinstate the signal handler each time...
  2261   }
  2265   }
  2264 void* os::user_handler() {
  2268 void* os::user_handler() {
  2265   return CAST_FROM_FN_PTR(void*, UserHandler);
  2269   return CAST_FROM_FN_PTR(void*, UserHandler);
  2266 }
  2270 }
  2267 
  2271 
  2268 class Semaphore : public StackObj {
  2272 class Semaphore : public StackObj {
  2269   public:
  2273  public:
  2270     Semaphore();
  2274   Semaphore();
  2271     ~Semaphore();
  2275   ~Semaphore();
  2272     void signal();
  2276   void signal();
  2273     void wait();
  2277   void wait();
  2274     bool trywait();
  2278   bool trywait();
  2275     bool timedwait(unsigned int sec, int nsec);
  2279   bool timedwait(unsigned int sec, int nsec);
  2276   private:
  2280  private:
  2277     sema_t _semaphore;
  2281   sema_t _semaphore;
  2278 };
  2282 };
  2279 
  2283 
  2280 
  2284 
  2281 Semaphore::Semaphore() {
  2285 Semaphore::Semaphore() {
  2282   sema_init(&_semaphore, 0, NULL, NULL);
  2286   sema_init(&_semaphore, 0, NULL, NULL);
  2325   struct sigaction sigAct, oldSigAct;
  2329   struct sigaction sigAct, oldSigAct;
  2326   sigfillset(&(sigAct.sa_mask));
  2330   sigfillset(&(sigAct.sa_mask));
  2327   sigAct.sa_flags = SA_RESTART & ~SA_RESETHAND;
  2331   sigAct.sa_flags = SA_RESTART & ~SA_RESETHAND;
  2328   sigAct.sa_handler = CAST_TO_FN_PTR(sa_handler_t, handler);
  2332   sigAct.sa_handler = CAST_TO_FN_PTR(sa_handler_t, handler);
  2329 
  2333 
  2330   if (sigaction(signal_number, &sigAct, &oldSigAct))
  2334   if (sigaction(signal_number, &sigAct, &oldSigAct)) {
  2331     // -1 means registration failed
  2335     // -1 means registration failed
  2332     return (void *)-1;
  2336     return (void *)-1;
       
  2337   }
  2333 
  2338 
  2334   return CAST_FROM_FN_PTR(void*, oldSigAct.sa_handler);
  2339   return CAST_FROM_FN_PTR(void*, oldSigAct.sa_handler);
  2335 }
  2340 }
  2336 
  2341 
  2337 void os::signal_raise(int signal_number) {
  2342 void os::signal_raise(int signal_number) {
  2338   raise(signal_number);
  2343   raise(signal_number);
  2339 }
  2344 }
  2340 
  2345 
  2341 /*
  2346 // The following code is moved from os.cpp for making this
  2342  * The following code is moved from os.cpp for making this
  2347 // code platform specific, which it is by its very nature.
  2343  * code platform specific, which it is by its very nature.
       
  2344  */
       
  2345 
  2348 
  2346 // a counter for each possible signal value
  2349 // a counter for each possible signal value
  2347 static int Sigexit = 0;
  2350 static int Sigexit = 0;
  2348 static int Maxlibjsigsigs;
  2351 static int Maxlibjsigsigs;
  2349 static jint *pending_signals = NULL;
  2352 static jint *pending_signals = NULL;
  2371   // The additional signal is for SIGEXIT - exit signal to signal_thread
  2374   // The additional signal is for SIGEXIT - exit signal to signal_thread
  2372   pending_signals = (jint *)os::malloc(sizeof(jint) * (Sigexit+1), mtInternal);
  2375   pending_signals = (jint *)os::malloc(sizeof(jint) * (Sigexit+1), mtInternal);
  2373   memset(pending_signals, 0, (sizeof(jint) * (Sigexit+1)));
  2376   memset(pending_signals, 0, (sizeof(jint) * (Sigexit+1)));
  2374 
  2377 
  2375   if (UseSignalChaining) {
  2378   if (UseSignalChaining) {
  2376      chainedsigactions = (struct sigaction *)malloc(sizeof(struct sigaction)
  2379     chainedsigactions = (struct sigaction *)malloc(sizeof(struct sigaction)
  2377        * (Maxsignum + 1), mtInternal);
  2380                                                    * (Maxsignum + 1), mtInternal);
  2378      memset(chainedsigactions, 0, (sizeof(struct sigaction) * (Maxsignum + 1)));
  2381     memset(chainedsigactions, 0, (sizeof(struct sigaction) * (Maxsignum + 1)));
  2379      preinstalled_sigs = (int *)os::malloc(sizeof(int) * (Maxsignum + 1), mtInternal);
  2382     preinstalled_sigs = (int *)os::malloc(sizeof(int) * (Maxsignum + 1), mtInternal);
  2380      memset(preinstalled_sigs, 0, (sizeof(int) * (Maxsignum + 1)));
  2383     memset(preinstalled_sigs, 0, (sizeof(int) * (Maxsignum + 1)));
  2381   }
  2384   }
  2382   ourSigFlags = (int*)malloc(sizeof(int) * (Maxsignum + 1 ), mtInternal);
  2385   ourSigFlags = (int*)malloc(sizeof(int) * (Maxsignum + 1), mtInternal);
  2383   memset(ourSigFlags, 0, sizeof(int) * (Maxsignum + 1));
  2386   memset(ourSigFlags, 0, sizeof(int) * (Maxsignum + 1));
  2384 }
  2387 }
  2385 
  2388 
  2386 void os::signal_init_pd() {
  2389 void os::signal_init_pd() {
  2387   int ret;
  2390   int ret;
  2416     bool threadIsSuspended;
  2419     bool threadIsSuspended;
  2417     do {
  2420     do {
  2418       thread->set_suspend_equivalent();
  2421       thread->set_suspend_equivalent();
  2419       // cleared by handle_special_suspend_equivalent_condition() or java_suspend_self()
  2422       // cleared by handle_special_suspend_equivalent_condition() or java_suspend_self()
  2420       while ((ret = ::sema_wait(&sig_sem)) == EINTR)
  2423       while ((ret = ::sema_wait(&sig_sem)) == EINTR)
  2421           ;
  2424         ;
  2422       assert(ret == 0, "sema_wait() failed");
  2425       assert(ret == 0, "sema_wait() failed");
  2423 
  2426 
  2424       // were we externally suspended while we were waiting?
  2427       // were we externally suspended while we were waiting?
  2425       threadIsSuspended = thread->handle_special_suspend_equivalent_condition();
  2428       threadIsSuspended = thread->handle_special_suspend_equivalent_condition();
  2426       if (threadIsSuspended) {
  2429       if (threadIsSuspended) {
  2427         //
       
  2428         // The semaphore has been incremented, but while we were waiting
  2430         // The semaphore has been incremented, but while we were waiting
  2429         // another thread suspended us. We don't want to continue running
  2431         // another thread suspended us. We don't want to continue running
  2430         // while suspended because that would surprise the thread that
  2432         // while suspended because that would surprise the thread that
  2431         // suspended us.
  2433         // suspended us.
  2432         //
       
  2433         ret = ::sema_post(&sig_sem);
  2434         ret = ::sema_post(&sig_sem);
  2434         assert(ret == 0, "sema_post() failed");
  2435         assert(ret == 0, "sema_post() failed");
  2435 
  2436 
  2436         thread->java_suspend_self();
  2437         thread->java_suspend_self();
  2437       }
  2438       }
  2633 
  2634 
  2634 // Get a list of leaf locality groups. A leaf lgroup is group that
  2635 // Get a list of leaf locality groups. A leaf lgroup is group that
  2635 // doesn't have any children. Typical leaf group is a CPU or a CPU/memory
  2636 // doesn't have any children. Typical leaf group is a CPU or a CPU/memory
  2636 // board. An LWP is assigned to one of these groups upon creation.
  2637 // board. An LWP is assigned to one of these groups upon creation.
  2637 size_t os::numa_get_leaf_groups(int *ids, size_t size) {
  2638 size_t os::numa_get_leaf_groups(int *ids, size_t size) {
  2638    if ((ids[0] = Solaris::lgrp_root(Solaris::lgrp_cookie())) == -1) {
  2639   if ((ids[0] = Solaris::lgrp_root(Solaris::lgrp_cookie())) == -1) {
  2639      ids[0] = 0;
  2640     ids[0] = 0;
  2640      return 1;
  2641     return 1;
  2641    }
  2642   }
  2642    int result_size = 0, top = 1, bottom = 0, cur = 0;
  2643   int result_size = 0, top = 1, bottom = 0, cur = 0;
  2643    for (int k = 0; k < size; k++) {
  2644   for (int k = 0; k < size; k++) {
  2644      int r = Solaris::lgrp_children(Solaris::lgrp_cookie(), ids[cur],
  2645     int r = Solaris::lgrp_children(Solaris::lgrp_cookie(), ids[cur],
  2645                                     (Solaris::lgrp_id_t*)&ids[top], size - top);
  2646                                    (Solaris::lgrp_id_t*)&ids[top], size - top);
  2646      if (r == -1) {
  2647     if (r == -1) {
  2647        ids[0] = 0;
  2648       ids[0] = 0;
  2648        return 1;
  2649       return 1;
  2649      }
  2650     }
  2650      if (!r) {
  2651     if (!r) {
  2651        // That's a leaf node.
  2652       // That's a leaf node.
  2652        assert(bottom <= cur, "Sanity check");
  2653       assert(bottom <= cur, "Sanity check");
  2653        // Check if the node has memory
  2654       // Check if the node has memory
  2654        if (Solaris::lgrp_resources(Solaris::lgrp_cookie(), ids[cur],
  2655       if (Solaris::lgrp_resources(Solaris::lgrp_cookie(), ids[cur],
  2655                                    NULL, 0, LGRP_RSRC_MEM) > 0) {
  2656                                   NULL, 0, LGRP_RSRC_MEM) > 0) {
  2656          ids[bottom++] = ids[cur];
  2657         ids[bottom++] = ids[cur];
  2657        }
  2658       }
  2658      }
  2659     }
  2659      top += r;
  2660     top += r;
  2660      cur++;
  2661     cur++;
  2661    }
  2662   }
  2662    if (bottom == 0) {
  2663   if (bottom == 0) {
  2663      // Handle a situation, when the OS reports no memory available.
  2664     // Handle a situation, when the OS reports no memory available.
  2664      // Assume UMA architecture.
  2665     // Assume UMA architecture.
  2665      ids[0] = 0;
  2666     ids[0] = 0;
  2666      return 1;
  2667     return 1;
  2667    }
  2668   }
  2668    return bottom;
  2669   return bottom;
  2669 }
  2670 }
  2670 
  2671 
  2671 // Detect the topology change. Typically happens during CPU plugging-unplugging.
  2672 // Detect the topology change. Typically happens during CPU plugging-unplugging.
  2672 bool os::numa_topology_changed() {
  2673 bool os::numa_topology_changed() {
  2673   int is_stale = Solaris::lgrp_cookie_stale(Solaris::lgrp_cookie());
  2674   int is_stale = Solaris::lgrp_cookie_stale(Solaris::lgrp_cookie());
  2725   return false;
  2726   return false;
  2726 }
  2727 }
  2727 
  2728 
  2728 // Scan the pages from start to end until a page different than
  2729 // Scan the pages from start to end until a page different than
  2729 // the one described in the info parameter is encountered.
  2730 // the one described in the info parameter is encountered.
  2730 char *os::scan_pages(char *start, char* end, page_info* page_expected, page_info* page_found) {
  2731 char *os::scan_pages(char *start, char* end, page_info* page_expected,
       
  2732                      page_info* page_found) {
  2731   const uint_t info_types[] = { MEMINFO_VLGRP, MEMINFO_VPAGESIZE };
  2733   const uint_t info_types[] = { MEMINFO_VLGRP, MEMINFO_VPAGESIZE };
  2732   const size_t types = sizeof(info_types) / sizeof(info_types[0]);
  2734   const size_t types = sizeof(info_types) / sizeof(info_types[0]);
  2733   uint64_t addrs[MAX_MEMINFO_CNT], outdata[types * MAX_MEMINFO_CNT + 1];
  2735   uint64_t addrs[MAX_MEMINFO_CNT], outdata[types * MAX_MEMINFO_CNT + 1];
  2734   uint_t validity[MAX_MEMINFO_CNT];
  2736   uint_t validity[MAX_MEMINFO_CNT];
  2735 
  2737 
  2752       if ((validity[i] & 1) != 0) {
  2754       if ((validity[i] & 1) != 0) {
  2753         if ((validity[i] & 4) != 0) {
  2755         if ((validity[i] & 4) != 0) {
  2754           if (outdata[types * i + 1] != page_expected->size) {
  2756           if (outdata[types * i + 1] != page_expected->size) {
  2755             break;
  2757             break;
  2756           }
  2758           }
  2757         } else
  2759         } else if (page_expected->size != 0) {
  2758           if (page_expected->size != 0) {
  2760           break;
  2759             break;
  2761         }
  2760           }
       
  2761 
  2762 
  2762         if ((validity[i] & 2) != 0 && page_expected->lgrp_id > 0) {
  2763         if ((validity[i] & 2) != 0 && page_expected->lgrp_id > 0) {
  2763           if (outdata[types * i] != page_expected->lgrp_id) {
  2764           if (outdata[types * i] != page_expected->lgrp_id) {
  2764             break;
  2765             break;
  2765           }
  2766           }
  2806     return NULL;
  2807     return NULL;
  2807   }
  2808   }
  2808   return b;
  2809   return b;
  2809 }
  2810 }
  2810 
  2811 
  2811 char* os::Solaris::anon_mmap(char* requested_addr, size_t bytes, size_t alignment_hint, bool fixed) {
  2812 char* os::Solaris::anon_mmap(char* requested_addr, size_t bytes,
       
  2813                              size_t alignment_hint, bool fixed) {
  2812   char* addr = requested_addr;
  2814   char* addr = requested_addr;
  2813   int flags = MAP_PRIVATE | MAP_NORESERVE;
  2815   int flags = MAP_PRIVATE | MAP_NORESERVE;
  2814 
  2816 
  2815   assert(!(fixed && (alignment_hint > 0)), "alignment hint meaningless with fixed mmap");
  2817   assert(!(fixed && (alignment_hint > 0)),
       
  2818          "alignment hint meaningless with fixed mmap");
  2816 
  2819 
  2817   if (fixed) {
  2820   if (fixed) {
  2818     flags |= MAP_FIXED;
  2821     flags |= MAP_FIXED;
  2819   } else if (has_map_align && (alignment_hint > (size_t) vm_page_size())) {
  2822   } else if (has_map_align && (alignment_hint > (size_t) vm_page_size())) {
  2820     flags |= MAP_ALIGN;
  2823     flags |= MAP_ALIGN;
  2825   // uncommitted page. Otherwise, the read/write might succeed if we
  2828   // uncommitted page. Otherwise, the read/write might succeed if we
  2826   // have enough swap space to back the physical page.
  2829   // have enough swap space to back the physical page.
  2827   return mmap_chunk(addr, bytes, flags, PROT_NONE);
  2830   return mmap_chunk(addr, bytes, flags, PROT_NONE);
  2828 }
  2831 }
  2829 
  2832 
  2830 char* os::pd_reserve_memory(size_t bytes, char* requested_addr, size_t alignment_hint) {
  2833 char* os::pd_reserve_memory(size_t bytes, char* requested_addr,
  2831   char* addr = Solaris::anon_mmap(requested_addr, bytes, alignment_hint, (requested_addr != NULL));
  2834                             size_t alignment_hint) {
       
  2835   char* addr = Solaris::anon_mmap(requested_addr, bytes, alignment_hint,
       
  2836                                   (requested_addr != NULL));
  2832 
  2837 
  2833   guarantee(requested_addr == NULL || requested_addr == addr,
  2838   guarantee(requested_addr == NULL || requested_addr == addr,
  2834             "OS failed to return requested mmap address.");
  2839             "OS failed to return requested mmap address.");
  2835   return addr;
  2840   return addr;
  2836 }
  2841 }
  3091 
  3096 
  3092     UseLargePages = Solaris::mpss_sanity_check(warn_on_failure, &_large_page_size);
  3097     UseLargePages = Solaris::mpss_sanity_check(warn_on_failure, &_large_page_size);
  3093   }
  3098   }
  3094 }
  3099 }
  3095 
  3100 
  3096 bool os::Solaris::setup_large_pages(caddr_t start, size_t bytes, size_t align) {
  3101 bool os::Solaris::setup_large_pages(caddr_t start, size_t bytes,
       
  3102                                     size_t align) {
  3097   // Signal to OS that we want large pages for addresses
  3103   // Signal to OS that we want large pages for addresses
  3098   // from addr, addr + bytes
  3104   // from addr, addr + bytes
  3099   struct memcntl_mha mpss_struct;
  3105   struct memcntl_mha mpss_struct;
  3100   mpss_struct.mha_cmd = MHA_MAPSIZE_VA;
  3106   mpss_struct.mha_cmd = MHA_MAPSIZE_VA;
  3101   mpss_struct.mha_pagesize = align;
  3107   mpss_struct.mha_pagesize = align;
  3106     return false;
  3112     return false;
  3107   }
  3113   }
  3108   return true;
  3114   return true;
  3109 }
  3115 }
  3110 
  3116 
  3111 char* os::reserve_memory_special(size_t size, size_t alignment, char* addr, bool exec) {
  3117 char* os::reserve_memory_special(size_t size, size_t alignment, char* addr,
       
  3118                                  bool exec) {
  3112   fatal("os::reserve_memory_special should not be called on Solaris.");
  3119   fatal("os::reserve_memory_special should not be called on Solaris.");
  3113   return NULL;
  3120   return NULL;
  3114 }
  3121 }
  3115 
  3122 
  3116 bool os::release_memory_special(char* base, size_t bytes) {
  3123 bool os::release_memory_special(char* base, size_t bytes) {
  3143 }
  3150 }
  3144 
  3151 
  3145 size_t os::restartable_read(int fd, void *buf, unsigned int nBytes) {
  3152 size_t os::restartable_read(int fd, void *buf, unsigned int nBytes) {
  3146   size_t res;
  3153   size_t res;
  3147   assert(((JavaThread*)Thread::current())->thread_state() == _thread_in_native,
  3154   assert(((JavaThread*)Thread::current())->thread_state() == _thread_in_native,
  3148           "Assumed _thread_in_native");
  3155          "Assumed _thread_in_native");
  3149   RESTARTABLE(::read(fd, buf, (size_t) nBytes), res);
  3156   RESTARTABLE(::read(fd, buf, (size_t) nBytes), res);
  3150   return res;
  3157   return res;
  3151 }
  3158 }
  3152 
  3159 
  3153 void os::naked_short_sleep(jlong ms) {
  3160 void os::naked_short_sleep(jlong ms) {
  3171 bool os::dont_yield() {
  3178 bool os::dont_yield() {
  3172   if (DontYieldALot) {
  3179   if (DontYieldALot) {
  3173     static hrtime_t last_time = 0;
  3180     static hrtime_t last_time = 0;
  3174     hrtime_t diff = getTimeNanos() - last_time;
  3181     hrtime_t diff = getTimeNanos() - last_time;
  3175 
  3182 
  3176     if (diff < DontYieldALotInterval * 1000000)
  3183     if (diff < DontYieldALotInterval * 1000000) {
  3177       return true;
  3184       return true;
       
  3185     }
  3178 
  3186 
  3179     last_time += diff;
  3187     last_time += diff;
  3180 
  3188 
  3181     return false;
  3189     return false;
  3182   }
  3190   } else {
  3183   else {
       
  3184     return false;
  3191     return false;
  3185   }
  3192   }
  3186 }
  3193 }
  3187 
  3194 
  3188 // Note that yield semantics are defined by the scheduling class to which
  3195 // Note that yield semantics are defined by the scheduling class to which
  3238 //              Given a priority, compute appropriate timeslice.
  3245 //              Given a priority, compute appropriate timeslice.
  3239 // +    Higher numerical values have higher priority.
  3246 // +    Higher numerical values have higher priority.
  3240 
  3247 
  3241 // sched class attributes
  3248 // sched class attributes
  3242 typedef struct {
  3249 typedef struct {
  3243         int   schedPolicy;              // classID
  3250   int   schedPolicy;              // classID
  3244         int   maxPrio;
  3251   int   maxPrio;
  3245         int   minPrio;
  3252   int   minPrio;
  3246 } SchedInfo;
  3253 } SchedInfo;
  3247 
  3254 
  3248 
  3255 
  3249 static SchedInfo tsLimits, iaLimits, rtLimits, fxLimits;
  3256 static SchedInfo tsLimits, iaLimits, rtLimits, fxLimits;
  3250 
  3257 
  3373     myMin = fxLimits.minPrio;
  3380     myMin = fxLimits.minPrio;
  3374     myMax = fxLimits.maxPrio;
  3381     myMax = fxLimits.maxPrio;
  3375     myMax = MIN2(myMax, (int)fxInfo->fx_uprilim);       // clamp - restrict
  3382     myMax = MIN2(myMax, (int)fxInfo->fx_uprilim);       // clamp - restrict
  3376   } else {
  3383   } else {
  3377     // No clue - punt
  3384     // No clue - punt
  3378     if (ThreadPriorityVerbose)
  3385     if (ThreadPriorityVerbose) {
  3379       tty->print_cr("Unknown scheduling class: %s ... \n", ClassInfo.pc_clname);
  3386       tty->print_cr("Unknown scheduling class: %s ... \n",
       
  3387                     ClassInfo.pc_clname);
       
  3388     }
  3380     return EINVAL;      // no clue, punt
  3389     return EINVAL;      // no clue, punt
  3381   }
  3390   }
  3382 
  3391 
  3383   if (ThreadPriorityVerbose) {
  3392   if (ThreadPriorityVerbose) {
  3384     tty->print_cr("Thread priority Range: [%d..%d]\n", myMin, myMax);
  3393     tty->print_cr("Thread priority Range: [%d..%d]\n", myMin, myMax);
  3397 // scale_to_lwp_priority
  3406 // scale_to_lwp_priority
  3398 //
  3407 //
  3399 // Convert from the libthread "thr_setprio" scale to our current
  3408 // Convert from the libthread "thr_setprio" scale to our current
  3400 // lwp scheduling class scale.
  3409 // lwp scheduling class scale.
  3401 //
  3410 //
  3402 static
  3411 static int scale_to_lwp_priority(int rMin, int rMax, int x) {
  3403 int     scale_to_lwp_priority (int rMin, int rMax, int x)
       
  3404 {
       
  3405   int v;
  3412   int v;
  3406 
  3413 
  3407   if (x == 127) return rMax;            // avoid round-down
  3414   if (x == 127) return rMax;            // avoid round-down
  3408     v = (((x*(rMax-rMin)))/128)+rMin;
  3415   v = (((x*(rMax-rMin)))/128)+rMin;
  3409   return v;
  3416   return v;
  3410 }
  3417 }
  3411 
  3418 
  3412 
  3419 
  3413 // set_lwp_class_and_priority
  3420 // set_lwp_class_and_priority
  3426   // Cache "pcparms_t" in global ParmCache.
  3433   // Cache "pcparms_t" in global ParmCache.
  3427   // TODO: elide set-to-same-value
  3434   // TODO: elide set-to-same-value
  3428 
  3435 
  3429   // If something went wrong on init, don't change priorities.
  3436   // If something went wrong on init, don't change priorities.
  3430   if (!priocntl_enable) {
  3437   if (!priocntl_enable) {
  3431     if (ThreadPriorityVerbose)
  3438     if (ThreadPriorityVerbose) {
  3432       tty->print_cr("Trying to set priority but init failed, ignoring");
  3439       tty->print_cr("Trying to set priority but init failed, ignoring");
       
  3440     }
  3433     return EINVAL;
  3441     return EINVAL;
  3434   }
  3442   }
  3435 
  3443 
  3436   // If lwp hasn't started yet, just return
  3444   // If lwp hasn't started yet, just return
  3437   // the _start routine will call us again.
  3445   // the _start routine will call us again.
  3438   if (lwpid <= 0) {
  3446   if (lwpid <= 0) {
  3439     if (ThreadPriorityVerbose) {
  3447     if (ThreadPriorityVerbose) {
  3440       tty->print_cr("deferring the set_lwp_class_and_priority of thread "
  3448       tty->print_cr("deferring the set_lwp_class_and_priority of thread "
  3441                      INTPTR_FORMAT " to %d, lwpid not set",
  3449                     INTPTR_FORMAT " to %d, lwpid not set",
  3442                      ThreadID, newPrio);
  3450                     ThreadID, newPrio);
  3443     }
  3451     }
  3444     return 0;
  3452     return 0;
  3445   }
  3453   }
  3446 
  3454 
  3447   if (ThreadPriorityVerbose) {
  3455   if (ThreadPriorityVerbose) {
  3470     }
  3478     }
  3471   } else if (new_class == iaLimits.schedPolicy) {
  3479   } else if (new_class == iaLimits.schedPolicy) {
  3472     iaparms_t* iaInfo  = (iaparms_t*)ParmInfo.pc_clparms;
  3480     iaparms_t* iaInfo  = (iaparms_t*)ParmInfo.pc_clparms;
  3473     int maxClamped     = MIN2(iaLimits.maxPrio,
  3481     int maxClamped     = MIN2(iaLimits.maxPrio,
  3474                               cur_class == new_class
  3482                               cur_class == new_class
  3475                                 ? (int)iaInfo->ia_uprilim : iaLimits.maxPrio);
  3483                               ? (int)iaInfo->ia_uprilim : iaLimits.maxPrio);
  3476     iaInfo->ia_upri    = scale ? scale_to_lwp_priority(iaLimits.minPrio,
  3484     iaInfo->ia_upri    = scale ? scale_to_lwp_priority(iaLimits.minPrio,
  3477                                                        maxClamped, newPrio)
  3485                                                        maxClamped, newPrio)
  3478                                : newPrio;
  3486                                : newPrio;
  3479     iaInfo->ia_uprilim = cur_class == new_class
  3487     iaInfo->ia_uprilim = cur_class == new_class
  3480                            ? IA_NOCHANGE : (pri_t)iaLimits.maxPrio;
  3488                            ? IA_NOCHANGE : (pri_t)iaLimits.maxPrio;
  3485     }
  3493     }
  3486   } else if (new_class == tsLimits.schedPolicy) {
  3494   } else if (new_class == tsLimits.schedPolicy) {
  3487     tsparms_t* tsInfo  = (tsparms_t*)ParmInfo.pc_clparms;
  3495     tsparms_t* tsInfo  = (tsparms_t*)ParmInfo.pc_clparms;
  3488     int maxClamped     = MIN2(tsLimits.maxPrio,
  3496     int maxClamped     = MIN2(tsLimits.maxPrio,
  3489                               cur_class == new_class
  3497                               cur_class == new_class
  3490                                 ? (int)tsInfo->ts_uprilim : tsLimits.maxPrio);
  3498                               ? (int)tsInfo->ts_uprilim : tsLimits.maxPrio);
  3491     tsInfo->ts_upri    = scale ? scale_to_lwp_priority(tsLimits.minPrio,
  3499     tsInfo->ts_upri    = scale ? scale_to_lwp_priority(tsLimits.minPrio,
  3492                                                        maxClamped, newPrio)
  3500                                                        maxClamped, newPrio)
  3493                                : newPrio;
  3501                                : newPrio;
  3494     tsInfo->ts_uprilim = cur_class == new_class
  3502     tsInfo->ts_uprilim = cur_class == new_class
  3495                            ? TS_NOCHANGE : (pri_t)tsLimits.maxPrio;
  3503                            ? TS_NOCHANGE : (pri_t)tsLimits.maxPrio;
  3499     }
  3507     }
  3500   } else if (new_class == fxLimits.schedPolicy) {
  3508   } else if (new_class == fxLimits.schedPolicy) {
  3501     fxparms_t* fxInfo  = (fxparms_t*)ParmInfo.pc_clparms;
  3509     fxparms_t* fxInfo  = (fxparms_t*)ParmInfo.pc_clparms;
  3502     int maxClamped     = MIN2(fxLimits.maxPrio,
  3510     int maxClamped     = MIN2(fxLimits.maxPrio,
  3503                               cur_class == new_class
  3511                               cur_class == new_class
  3504                                 ? (int)fxInfo->fx_uprilim : fxLimits.maxPrio);
  3512                               ? (int)fxInfo->fx_uprilim : fxLimits.maxPrio);
  3505     fxInfo->fx_upri    = scale ? scale_to_lwp_priority(fxLimits.minPrio,
  3513     fxInfo->fx_upri    = scale ? scale_to_lwp_priority(fxLimits.minPrio,
  3506                                                        maxClamped, newPrio)
  3514                                                        maxClamped, newPrio)
  3507                                : newPrio;
  3515                                : newPrio;
  3508     fxInfo->fx_uprilim = cur_class == new_class
  3516     fxInfo->fx_uprilim = cur_class == new_class
  3509                            ? FX_NOCHANGE : (pri_t)fxLimits.maxPrio;
  3517                            ? FX_NOCHANGE : (pri_t)fxLimits.maxPrio;
  3589 // This mode causes the priority table to get filled with
  3597 // This mode causes the priority table to get filled with
  3590 // linear values.  NormPriority get's mapped to 50% of the
  3598 // linear values.  NormPriority get's mapped to 50% of the
  3591 // Maximum priority an so on.  This will cause VM threads
  3599 // Maximum priority an so on.  This will cause VM threads
  3592 // to get unfair treatment against other Solaris processes
  3600 // to get unfair treatment against other Solaris processes
  3593 // which do not explicitly alter their thread priorities.
  3601 // which do not explicitly alter their thread priorities.
  3594 //
       
  3595 
  3602 
  3596 int os::java_to_os_priority[CriticalPriority + 1] = {
  3603 int os::java_to_os_priority[CriticalPriority + 1] = {
  3597   -99999,         // 0 Entry should never be used
  3604   -99999,         // 0 Entry should never be used
  3598 
  3605 
  3599   0,              // 1 MinPriority
  3606   0,              // 1 MinPriority
  3636     status = thr_setprio(thread->osthread()->thread_id(), newpri);
  3643     status = thr_setprio(thread->osthread()->thread_id(), newpri);
  3637   }
  3644   }
  3638 
  3645 
  3639   int lwp_status =
  3646   int lwp_status =
  3640           set_lwp_class_and_priority(osthread->thread_id(),
  3647           set_lwp_class_and_priority(osthread->thread_id(),
  3641           osthread->lwp_id(),
  3648                                      osthread->lwp_id(),
  3642           newpri,
  3649                                      newpri,
  3643           fxcritical ? fxLimits.schedPolicy : myClass,
  3650                                      fxcritical ? fxLimits.schedPolicy : myClass,
  3644           !fxcritical);
  3651                                      !fxcritical);
  3645   if (lwp_status != 0 && fxcritical) {
  3652   if (lwp_status != 0 && fxcritical) {
  3646     // Try again, this time without changing the scheduling class
  3653     // Try again, this time without changing the scheduling class
  3647     newpri = java_MaxPriority_to_os_priority;
  3654     newpri = java_MaxPriority_to_os_priority;
  3648     lwp_status = set_lwp_class_and_priority(osthread->thread_id(),
  3655     lwp_status = set_lwp_class_and_priority(osthread->thread_id(),
  3649             osthread->lwp_id(),
  3656                                             osthread->lwp_id(),
  3650             newpri, myClass, false);
  3657                                             newpri, myClass, false);
  3651   }
  3658   }
  3652   status |= lwp_status;
  3659   status |= lwp_status;
  3653   return (status == 0) ? OS_OK : OS_ERR;
  3660   return (status == 0) ? OS_OK : OS_ERR;
  3654 }
  3661 }
  3655 
  3662 
  3656 
  3663 
  3657 OSReturn os::get_native_priority(const Thread* const thread, int *priority_ptr) {
  3664 OSReturn os::get_native_priority(const Thread* const thread,
       
  3665                                  int *priority_ptr) {
  3658   int p;
  3666   int p;
  3659   if (!UseThreadPriorities) {
  3667   if (!UseThreadPriorities) {
  3660     *priority_ptr = NormalPriority;
  3668     *priority_ptr = NormalPriority;
  3661     return OS_OK;
  3669     return OS_OK;
  3662   }
  3670   }
  3841     do_resume(_thread->osthread());
  3849     do_resume(_thread->osthread());
  3842   }
  3850   }
  3843 }
  3851 }
  3844 
  3852 
  3845 class PcFetcher : public os::SuspendedThreadTask {
  3853 class PcFetcher : public os::SuspendedThreadTask {
  3846 public:
  3854  public:
  3847   PcFetcher(Thread* thread) : os::SuspendedThreadTask(thread) {}
  3855   PcFetcher(Thread* thread) : os::SuspendedThreadTask(thread) {}
  3848   ExtendedPC result();
  3856   ExtendedPC result();
  3849 protected:
  3857  protected:
  3850   void do_task(const os::SuspendedThreadTaskContext& context);
  3858   void do_task(const os::SuspendedThreadTaskContext& context);
  3851 private:
  3859  private:
  3852   ExtendedPC _epc;
  3860   ExtendedPC _epc;
  3853 };
  3861 };
  3854 
  3862 
  3855 ExtendedPC PcFetcher::result() {
  3863 ExtendedPC PcFetcher::result() {
  3856   guarantee(is_done(), "task is not done yet.");
  3864   guarantee(is_done(), "task is not done yet.");
  3881 }
  3889 }
  3882 
  3890 
  3883 
  3891 
  3884 // This does not do anything on Solaris. This is basically a hook for being
  3892 // This does not do anything on Solaris. This is basically a hook for being
  3885 // able to use structured exception handling (thread-local exception filters) on, e.g., Win32.
  3893 // able to use structured exception handling (thread-local exception filters) on, e.g., Win32.
  3886 void os::os_exception_wrapper(java_call_t f, JavaValue* value, methodHandle* method, JavaCallArguments* args, Thread* thread) {
  3894 void os::os_exception_wrapper(java_call_t f, JavaValue* value,
       
  3895                               methodHandle* method, JavaCallArguments* args,
       
  3896                               Thread* thread) {
  3887   f(value, method, args, thread);
  3897   f(value, method, args, thread);
  3888 }
  3898 }
  3889 
  3899 
  3890 // This routine may be used by user applications as a "hook" to catch signals.
  3900 // This routine may be used by user applications as a "hook" to catch signals.
  3891 // The user-defined signal handler must pass unrecognized signals to this
  3901 // The user-defined signal handler must pass unrecognized signals to this
  3912 // the sa_flags field passed to sigaction() includes SA_SIGINFO and SA_RESTART.
  3922 // the sa_flags field passed to sigaction() includes SA_SIGINFO and SA_RESTART.
  3913 //
  3923 //
  3914 // Note that the VM will print warnings if it detects conflicting signal
  3924 // Note that the VM will print warnings if it detects conflicting signal
  3915 // handlers, unless invoked with the option "-XX:+AllowUserSignalHandlers".
  3925 // handlers, unless invoked with the option "-XX:+AllowUserSignalHandlers".
  3916 //
  3926 //
  3917 extern "C" JNIEXPORT int
  3927 extern "C" JNIEXPORT int JVM_handle_solaris_signal(int signo,
  3918 JVM_handle_solaris_signal(int signo, siginfo_t* siginfo, void* ucontext,
  3928                                                    siginfo_t* siginfo,
  3919                           int abort_if_unrecognized);
  3929                                                    void* ucontext,
       
  3930                                                    int abort_if_unrecognized);
  3920 
  3931 
  3921 
  3932 
  3922 void signalHandler(int sig, siginfo_t* info, void* ucVoid) {
  3933 void signalHandler(int sig, siginfo_t* info, void* ucVoid) {
  3923   int orig_errno = errno;  // Preserve errno value over signal handler.
  3934   int orig_errno = errno;  // Preserve errno value over signal handler.
  3924   JVM_handle_solaris_signal(sig, info, ucVoid, true);
  3935   JVM_handle_solaris_signal(sig, info, ucVoid, true);
  3925   errno = orig_errno;
  3936   errno = orig_errno;
  3926 }
  3937 }
  3927 
  3938 
  3928 /* Do not delete - if guarantee is ever removed,  a signal handler (even empty)
  3939 // Do not delete - if guarantee is ever removed,  a signal handler (even empty)
  3929    is needed to provoke threads blocked on IO to return an EINTR
  3940 // is needed to provoke threads blocked on IO to return an EINTR
  3930    Note: this explicitly does NOT call JVM_handle_solaris_signal and
  3941 // Note: this explicitly does NOT call JVM_handle_solaris_signal and
  3931    does NOT participate in signal chaining due to requirement for
  3942 // does NOT participate in signal chaining due to requirement for
  3932    NOT setting SA_RESTART to make EINTR work. */
  3943 // NOT setting SA_RESTART to make EINTR work.
  3933 extern "C" void sigINTRHandler(int sig, siginfo_t* info, void* ucVoid) {
  3944 extern "C" void sigINTRHandler(int sig, siginfo_t* info, void* ucVoid) {
  3934    if (UseSignalChaining) {
  3945   if (UseSignalChaining) {
  3935       struct sigaction *actp = os::Solaris::get_chained_signal_action(sig);
  3946     struct sigaction *actp = os::Solaris::get_chained_signal_action(sig);
  3936       if (actp && actp->sa_handler) {
  3947     if (actp && actp->sa_handler) {
  3937         vm_exit_during_initialization("Signal chaining detected for VM interrupt signal, try -XX:+UseAltSigs");
  3948       vm_exit_during_initialization("Signal chaining detected for VM interrupt signal, try -XX:+UseAltSigs");
  3938       }
  3949     }
  3939    }
  3950   }
  3940 }
  3951 }
  3941 
  3952 
  3942 // This boolean allows users to forward their own non-matching signals
  3953 // This boolean allows users to forward their own non-matching signals
  3943 // to JVM_handle_solaris_signal, harmlessly.
  3954 // to JVM_handle_solaris_signal, harmlessly.
  3944 bool os::Solaris::signal_handlers_are_installed = false;
  3955 bool os::Solaris::signal_handlers_are_installed = false;
  4019   }
  4030   }
  4020   return chained;
  4031   return chained;
  4021 }
  4032 }
  4022 
  4033 
  4023 struct sigaction* os::Solaris::get_preinstalled_handler(int sig) {
  4034 struct sigaction* os::Solaris::get_preinstalled_handler(int sig) {
  4024   assert((chainedsigactions != (struct sigaction *)NULL) && (preinstalled_sigs != (int *)NULL) , "signals not yet initialized");
  4035   assert((chainedsigactions != (struct sigaction *)NULL) &&
       
  4036          (preinstalled_sigs != (int *)NULL), "signals not yet initialized");
  4025   if (preinstalled_sigs[sig] != 0) {
  4037   if (preinstalled_sigs[sig] != 0) {
  4026     return &chainedsigactions[sig];
  4038     return &chainedsigactions[sig];
  4027   }
  4039   }
  4028   return NULL;
  4040   return NULL;
  4029 }
  4041 }
  4030 
  4042 
  4031 void os::Solaris::save_preinstalled_handler(int sig, struct sigaction& oldAct) {
  4043 void os::Solaris::save_preinstalled_handler(int sig,
  4032 
  4044                                             struct sigaction& oldAct) {
  4033   assert(sig > 0 && sig <= Maxsignum, "vm signal out of expected range");
  4045   assert(sig > 0 && sig <= Maxsignum, "vm signal out of expected range");
  4034   assert((chainedsigactions != (struct sigaction *)NULL) && (preinstalled_sigs != (int *)NULL) , "signals not yet initialized");
  4046   assert((chainedsigactions != (struct sigaction *)NULL) &&
       
  4047          (preinstalled_sigs != (int *)NULL), "signals not yet initialized");
  4035   chainedsigactions[sig] = oldAct;
  4048   chainedsigactions[sig] = oldAct;
  4036   preinstalled_sigs[sig] = 1;
  4049   preinstalled_sigs[sig] = 1;
  4037 }
  4050 }
  4038 
  4051 
  4039 void os::Solaris::set_signal_handler(int sig, bool set_installed, bool oktochain) {
  4052 void os::Solaris::set_signal_handler(int sig, bool set_installed,
       
  4053                                      bool oktochain) {
  4040   // Check for overwrite.
  4054   // Check for overwrite.
  4041   struct sigaction oldAct;
  4055   struct sigaction oldAct;
  4042   sigaction(sig, (struct sigaction*)NULL, &oldAct);
  4056   sigaction(sig, (struct sigaction*)NULL, &oldAct);
  4043   void* oldhand = oldAct.sa_sigaction ? CAST_FROM_FN_PTR(void*,  oldAct.sa_sigaction)
  4057   void* oldhand =
  4044                                       : CAST_FROM_FN_PTR(void*,  oldAct.sa_handler);
  4058       oldAct.sa_sigaction ? CAST_FROM_FN_PTR(void*,  oldAct.sa_sigaction)
       
  4059                           : CAST_FROM_FN_PTR(void*,  oldAct.sa_handler);
  4045   if (oldhand != CAST_FROM_FN_PTR(void*, SIG_DFL) &&
  4060   if (oldhand != CAST_FROM_FN_PTR(void*, SIG_DFL) &&
  4046       oldhand != CAST_FROM_FN_PTR(void*, SIG_IGN) &&
  4061       oldhand != CAST_FROM_FN_PTR(void*, SIG_IGN) &&
  4047       oldhand != CAST_FROM_FN_PTR(void*, signalHandler)) {
  4062       oldhand != CAST_FROM_FN_PTR(void*, signalHandler)) {
  4048     if (AllowUserSignalHandlers || !set_installed) {
  4063     if (AllowUserSignalHandlers || !set_installed) {
  4049       // Do not overwrite; user takes responsibility to forward to us.
  4064       // Do not overwrite; user takes responsibility to forward to us.
  4070   sigAct.sa_sigaction = signalHandler;
  4085   sigAct.sa_sigaction = signalHandler;
  4071   // Handle SIGSEGV on alternate signal stack if
  4086   // Handle SIGSEGV on alternate signal stack if
  4072   // not using stack banging
  4087   // not using stack banging
  4073   if (!UseStackBanging && sig == SIGSEGV) {
  4088   if (!UseStackBanging && sig == SIGSEGV) {
  4074     sigAct.sa_flags = SA_SIGINFO | SA_RESTART | SA_ONSTACK;
  4089     sigAct.sa_flags = SA_SIGINFO | SA_RESTART | SA_ONSTACK;
  4075   // Interruptible i/o requires SA_RESTART cleared so EINTR
       
  4076   // is returned instead of restarting system calls
       
  4077   } else if (sig == os::Solaris::SIGinterrupt()) {
  4090   } else if (sig == os::Solaris::SIGinterrupt()) {
       
  4091     // Interruptible i/o requires SA_RESTART cleared so EINTR
       
  4092     // is returned instead of restarting system calls
  4078     sigemptyset(&sigAct.sa_mask);
  4093     sigemptyset(&sigAct.sa_mask);
  4079     sigAct.sa_handler = NULL;
  4094     sigAct.sa_handler = NULL;
  4080     sigAct.sa_flags = SA_SIGINFO;
  4095     sigAct.sa_flags = SA_SIGINFO;
  4081     sigAct.sa_sigaction = sigINTRHandler;
  4096     sigAct.sa_sigaction = sigINTRHandler;
  4082   } else {
  4097   } else {
  4090                                        : CAST_FROM_FN_PTR(void*, oldAct.sa_handler);
  4105                                        : CAST_FROM_FN_PTR(void*, oldAct.sa_handler);
  4091   assert(oldhand2 == oldhand, "no concurrent signal handler installation");
  4106   assert(oldhand2 == oldhand, "no concurrent signal handler installation");
  4092 }
  4107 }
  4093 
  4108 
  4094 
  4109 
  4095 #define DO_SIGNAL_CHECK(sig) \
  4110 #define DO_SIGNAL_CHECK(sig)                      \
  4096   if (!sigismember(&check_signal_done, sig)) \
  4111   do {                                            \
  4097     os::Solaris::check_signal_handler(sig)
  4112     if (!sigismember(&check_signal_done, sig)) {  \
       
  4113       os::Solaris::check_signal_handler(sig);     \
       
  4114     }                                             \
       
  4115   } while (0)
  4098 
  4116 
  4099 // This method is a periodic task to check for misbehaving JNI applications
  4117 // This method is a periodic task to check for misbehaving JNI applications
  4100 // under CheckJNI, we can add any periodic checks here
  4118 // under CheckJNI, we can add any periodic checks here
  4101 
  4119 
  4102 void os::run_periodic_checks() {
  4120 void os::run_periodic_checks() {
  4153     ? CAST_FROM_FN_PTR(address, act.sa_sigaction)
  4171     ? CAST_FROM_FN_PTR(address, act.sa_sigaction)
  4154     : CAST_FROM_FN_PTR(address, act.sa_handler);
  4172     : CAST_FROM_FN_PTR(address, act.sa_handler);
  4155 
  4173 
  4156 
  4174 
  4157   switch (sig) {
  4175   switch (sig) {
  4158     case SIGSEGV:
  4176   case SIGSEGV:
  4159     case SIGBUS:
  4177   case SIGBUS:
  4160     case SIGFPE:
  4178   case SIGFPE:
  4161     case SIGPIPE:
  4179   case SIGPIPE:
  4162     case SIGXFSZ:
  4180   case SIGXFSZ:
  4163     case SIGILL:
  4181   case SIGILL:
       
  4182     jvmHandler = CAST_FROM_FN_PTR(address, signalHandler);
       
  4183     break;
       
  4184 
       
  4185   case SHUTDOWN1_SIGNAL:
       
  4186   case SHUTDOWN2_SIGNAL:
       
  4187   case SHUTDOWN3_SIGNAL:
       
  4188   case BREAK_SIGNAL:
       
  4189     jvmHandler = (address)user_handler();
       
  4190     break;
       
  4191 
       
  4192   default:
       
  4193     int intrsig = os::Solaris::SIGinterrupt();
       
  4194     int asynsig = os::Solaris::SIGasync();
       
  4195 
       
  4196     if (sig == intrsig) {
       
  4197       jvmHandler = CAST_FROM_FN_PTR(address, sigINTRHandler);
       
  4198     } else if (sig == asynsig) {
  4164       jvmHandler = CAST_FROM_FN_PTR(address, signalHandler);
  4199       jvmHandler = CAST_FROM_FN_PTR(address, signalHandler);
  4165       break;
  4200     } else {
  4166 
  4201       return;
  4167     case SHUTDOWN1_SIGNAL:
  4202     }
  4168     case SHUTDOWN2_SIGNAL:
  4203     break;
  4169     case SHUTDOWN3_SIGNAL:
       
  4170     case BREAK_SIGNAL:
       
  4171       jvmHandler = (address)user_handler();
       
  4172       break;
       
  4173 
       
  4174     default:
       
  4175       int intrsig = os::Solaris::SIGinterrupt();
       
  4176       int asynsig = os::Solaris::SIGasync();
       
  4177 
       
  4178       if (sig == intrsig) {
       
  4179         jvmHandler = CAST_FROM_FN_PTR(address, sigINTRHandler);
       
  4180       } else if (sig == asynsig) {
       
  4181         jvmHandler = CAST_FROM_FN_PTR(address, signalHandler);
       
  4182       } else {
       
  4183         return;
       
  4184       }
       
  4185       break;
       
  4186   }
  4204   }
  4187 
  4205 
  4188 
  4206 
  4189   if (thisHandler != jvmHandler) {
  4207   if (thisHandler != jvmHandler) {
  4190     tty->print("Warning: %s handler ", exception_name(sig, buf, O_BUFLEN));
  4208     tty->print("Warning: %s handler ", exception_name(sig, buf, O_BUFLEN));
  4251   if (os::Solaris::SIGinterrupt() > OLDMAXSIGNUM || os::Solaris::SIGasync() > OLDMAXSIGNUM) {
  4269   if (os::Solaris::SIGinterrupt() > OLDMAXSIGNUM || os::Solaris::SIGasync() > OLDMAXSIGNUM) {
  4252 
  4270 
  4253     // Pre-1.4.1 Libjsig limited to signal chaining signals <= 32 so
  4271     // Pre-1.4.1 Libjsig limited to signal chaining signals <= 32 so
  4254     // can not register overridable signals which might be > 32
  4272     // can not register overridable signals which might be > 32
  4255     if (libjsig_is_loaded && libjsigversion <= JSIG_VERSION_1_4_1) {
  4273     if (libjsig_is_loaded && libjsigversion <= JSIG_VERSION_1_4_1) {
  4256     // Tell libjsig jvm has finished setting signal handlers
  4274       // Tell libjsig jvm has finished setting signal handlers
  4257       (*end_signal_setting)();
  4275       (*end_signal_setting)();
  4258       libjsigdone = true;
  4276       libjsigdone = true;
  4259     }
  4277     }
  4260   }
  4278   }
  4261 
  4279 
  4286     }
  4304     }
  4287   }
  4305   }
  4288 }
  4306 }
  4289 
  4307 
  4290 
  4308 
  4291 void report_error(const char* file_name, int line_no, const char* title, const char* format, ...);
  4309 void report_error(const char* file_name, int line_no, const char* title,
       
  4310                   const char* format, ...);
  4292 
  4311 
  4293 const char * signames[] = {
  4312 const char * signames[] = {
  4294   "SIG0",
  4313   "SIG0",
  4295   "SIGHUP", "SIGINT", "SIGQUIT", "SIGILL", "SIGTRAP",
  4314   "SIGHUP", "SIGINT", "SIGQUIT", "SIGILL", "SIGTRAP",
  4296   "SIGABRT", "SIGEMT", "SIGFPE", "SIGKILL", "SIGBUS",
  4315   "SIGABRT", "SIGEMT", "SIGFPE", "SIGKILL", "SIGBUS",
  4304 
  4323 
  4305 const char* os::exception_name(int exception_code, char* buf, size_t size) {
  4324 const char* os::exception_name(int exception_code, char* buf, size_t size) {
  4306   if (0 < exception_code && exception_code <= SIGRTMAX) {
  4325   if (0 < exception_code && exception_code <= SIGRTMAX) {
  4307     // signal
  4326     // signal
  4308     if (exception_code < sizeof(signames)/sizeof(const char*)) {
  4327     if (exception_code < sizeof(signames)/sizeof(const char*)) {
  4309        jio_snprintf(buf, size, "%s", signames[exception_code]);
  4328       jio_snprintf(buf, size, "%s", signames[exception_code]);
  4310     } else {
  4329     } else {
  4311        jio_snprintf(buf, size, "SIG%d", exception_code);
  4330       jio_snprintf(buf, size, "SIG%d", exception_code);
  4312     }
  4331     }
  4313     return buf;
  4332     return buf;
  4314   } else {
  4333   } else {
  4315     return NULL;
  4334     return NULL;
  4316   }
  4335   }
  4400     os::Solaris::set_cond_signal(CAST_TO_FN_PTR(int_fnP_cond_tP, resolve_symbol("_lwp_cond_signal")));
  4419     os::Solaris::set_cond_signal(CAST_TO_FN_PTR(int_fnP_cond_tP, resolve_symbol("_lwp_cond_signal")));
  4401     os::Solaris::set_cond_broadcast(CAST_TO_FN_PTR(int_fnP_cond_tP, resolve_symbol("_lwp_cond_broadcast")));
  4420     os::Solaris::set_cond_broadcast(CAST_TO_FN_PTR(int_fnP_cond_tP, resolve_symbol("_lwp_cond_broadcast")));
  4402     os::Solaris::set_cond_init(lwp_cond_init);
  4421     os::Solaris::set_cond_init(lwp_cond_init);
  4403     os::Solaris::set_cond_destroy(lwp_cond_destroy);
  4422     os::Solaris::set_cond_destroy(lwp_cond_destroy);
  4404     os::Solaris::set_cond_scope(USYNC_THREAD);
  4423     os::Solaris::set_cond_scope(USYNC_THREAD);
  4405   }
  4424   } else {
  4406   else {
       
  4407     os::Solaris::set_mutex_scope(USYNC_THREAD);
  4425     os::Solaris::set_mutex_scope(USYNC_THREAD);
  4408     os::Solaris::set_cond_scope(USYNC_THREAD);
  4426     os::Solaris::set_cond_scope(USYNC_THREAD);
  4409 
  4427 
  4410     if (UsePthreads) {
  4428     if (UsePthreads) {
  4411       os::Solaris::set_mutex_lock(CAST_TO_FN_PTR(int_fnP_mutex_tP, resolve_symbol("pthread_mutex_lock")));
  4429       os::Solaris::set_mutex_lock(CAST_TO_FN_PTR(int_fnP_mutex_tP, resolve_symbol("pthread_mutex_lock")));
  4418       os::Solaris::set_cond_wait(CAST_TO_FN_PTR(int_fnP_cond_tP_mutex_tP, resolve_symbol("pthread_cond_wait")));
  4436       os::Solaris::set_cond_wait(CAST_TO_FN_PTR(int_fnP_cond_tP_mutex_tP, resolve_symbol("pthread_cond_wait")));
  4419       os::Solaris::set_cond_signal(CAST_TO_FN_PTR(int_fnP_cond_tP, resolve_symbol("pthread_cond_signal")));
  4437       os::Solaris::set_cond_signal(CAST_TO_FN_PTR(int_fnP_cond_tP, resolve_symbol("pthread_cond_signal")));
  4420       os::Solaris::set_cond_broadcast(CAST_TO_FN_PTR(int_fnP_cond_tP, resolve_symbol("pthread_cond_broadcast")));
  4438       os::Solaris::set_cond_broadcast(CAST_TO_FN_PTR(int_fnP_cond_tP, resolve_symbol("pthread_cond_broadcast")));
  4421       os::Solaris::set_cond_init(pthread_cond_default_init);
  4439       os::Solaris::set_cond_init(pthread_cond_default_init);
  4422       os::Solaris::set_cond_destroy(CAST_TO_FN_PTR(int_fnP_cond_tP, resolve_symbol("pthread_cond_destroy")));
  4440       os::Solaris::set_cond_destroy(CAST_TO_FN_PTR(int_fnP_cond_tP, resolve_symbol("pthread_cond_destroy")));
  4423     }
  4441     } else {
  4424     else {
       
  4425       os::Solaris::set_mutex_lock(CAST_TO_FN_PTR(int_fnP_mutex_tP, resolve_symbol("mutex_lock")));
  4442       os::Solaris::set_mutex_lock(CAST_TO_FN_PTR(int_fnP_mutex_tP, resolve_symbol("mutex_lock")));
  4426       os::Solaris::set_mutex_trylock(CAST_TO_FN_PTR(int_fnP_mutex_tP, resolve_symbol("mutex_trylock")));
  4443       os::Solaris::set_mutex_trylock(CAST_TO_FN_PTR(int_fnP_mutex_tP, resolve_symbol("mutex_trylock")));
  4427       os::Solaris::set_mutex_unlock(CAST_TO_FN_PTR(int_fnP_mutex_tP, resolve_symbol("mutex_unlock")));
  4444       os::Solaris::set_mutex_unlock(CAST_TO_FN_PTR(int_fnP_mutex_tP, resolve_symbol("mutex_unlock")));
  4428       os::Solaris::set_mutex_init(::mutex_init);
  4445       os::Solaris::set_mutex_init(::mutex_init);
  4429       os::Solaris::set_mutex_destroy(::mutex_destroy);
  4446       os::Solaris::set_mutex_destroy(::mutex_destroy);
  4447     os::Solaris::set_lgrp_root(CAST_TO_FN_PTR(lgrp_root_func_t, dlsym(handle, "lgrp_root")));
  4464     os::Solaris::set_lgrp_root(CAST_TO_FN_PTR(lgrp_root_func_t, dlsym(handle, "lgrp_root")));
  4448     os::Solaris::set_lgrp_children(CAST_TO_FN_PTR(lgrp_children_func_t, dlsym(handle, "lgrp_children")));
  4465     os::Solaris::set_lgrp_children(CAST_TO_FN_PTR(lgrp_children_func_t, dlsym(handle, "lgrp_children")));
  4449     os::Solaris::set_lgrp_resources(CAST_TO_FN_PTR(lgrp_resources_func_t, dlsym(handle, "lgrp_resources")));
  4466     os::Solaris::set_lgrp_resources(CAST_TO_FN_PTR(lgrp_resources_func_t, dlsym(handle, "lgrp_resources")));
  4450     os::Solaris::set_lgrp_nlgrps(CAST_TO_FN_PTR(lgrp_nlgrps_func_t, dlsym(handle, "lgrp_nlgrps")));
  4467     os::Solaris::set_lgrp_nlgrps(CAST_TO_FN_PTR(lgrp_nlgrps_func_t, dlsym(handle, "lgrp_nlgrps")));
  4451     os::Solaris::set_lgrp_cookie_stale(CAST_TO_FN_PTR(lgrp_cookie_stale_func_t,
  4468     os::Solaris::set_lgrp_cookie_stale(CAST_TO_FN_PTR(lgrp_cookie_stale_func_t,
  4452                                        dlsym(handle, "lgrp_cookie_stale")));
  4469                                                       dlsym(handle, "lgrp_cookie_stale")));
  4453 
  4470 
  4454     lgrp_cookie_t c = lgrp_init(LGRP_VIEW_CALLER);
  4471     lgrp_cookie_t c = lgrp_init(LGRP_VIEW_CALLER);
  4455     set_lgrp_cookie(c);
  4472     set_lgrp_cookie(c);
  4456     return true;
  4473     return true;
  4457   }
  4474   }
  4500   max_hrtime = first_hrtime = gethrtime();
  4517   max_hrtime = first_hrtime = gethrtime();
  4501 
  4518 
  4502   init_random(1234567);
  4519   init_random(1234567);
  4503 
  4520 
  4504   page_size = sysconf(_SC_PAGESIZE);
  4521   page_size = sysconf(_SC_PAGESIZE);
  4505   if (page_size == -1)
  4522   if (page_size == -1) {
  4506     fatal(err_msg("os_solaris.cpp: os::init: sysconf failed (%s)",
  4523     fatal(err_msg("os_solaris.cpp: os::init: sysconf failed (%s)",
  4507                   strerror(errno)));
  4524                   strerror(errno)));
       
  4525   }
  4508   init_page_sizes((size_t) page_size);
  4526   init_page_sizes((size_t) page_size);
  4509 
  4527 
  4510   Solaris::initialize_system_info();
  4528   Solaris::initialize_system_info();
  4511 
  4529 
  4512   // Initialize misc. symbols as soon as possible, so we can use them
  4530   // Initialize misc. symbols as soon as possible, so we can use them
  4528   // check if dladdr1() exists; dladdr1 can provide more information than
  4546   // check if dladdr1() exists; dladdr1 can provide more information than
  4529   // dladdr for os::dll_address_to_function_name. It comes with SunOS 5.9
  4547   // dladdr for os::dll_address_to_function_name. It comes with SunOS 5.9
  4530   // and is available on linker patches for 5.7 and 5.8.
  4548   // and is available on linker patches for 5.7 and 5.8.
  4531   // libdl.so must have been loaded, this call is just an entry lookup
  4549   // libdl.so must have been loaded, this call is just an entry lookup
  4532   void * hdl = dlopen("libdl.so", RTLD_NOW);
  4550   void * hdl = dlopen("libdl.so", RTLD_NOW);
  4533   if (hdl)
  4551   if (hdl) {
  4534     dladdr1_func = CAST_TO_FN_PTR(dladdr1_func_type, dlsym(hdl, "dladdr1"));
  4552     dladdr1_func = CAST_TO_FN_PTR(dladdr1_func_type, dlsym(hdl, "dladdr1"));
       
  4553   }
  4535 
  4554 
  4536   // (Solaris only) this switches to calls that actually do locking.
  4555   // (Solaris only) this switches to calls that actually do locking.
  4537   ThreadCritical::initialize();
  4556   ThreadCritical::initialize();
  4538 
  4557 
  4539   main_thread = thr_self();
  4558   main_thread = thr_self();
  4577   }
  4596   }
  4578 
  4597 
  4579   os::set_polling_page(polling_page);
  4598   os::set_polling_page(polling_page);
  4580 
  4599 
  4581 #ifndef PRODUCT
  4600 #ifndef PRODUCT
  4582   if (Verbose && PrintMiscellaneous)
  4601   if (Verbose && PrintMiscellaneous) {
  4583     tty->print("[SafePoint Polling address: " INTPTR_FORMAT "]\n", (intptr_t)polling_page);
  4602     tty->print("[SafePoint Polling address: " INTPTR_FORMAT "]\n",
       
  4603                (intptr_t)polling_page);
       
  4604   }
  4584 #endif
  4605 #endif
  4585 
  4606 
  4586   if (!UseMembar) {
  4607   if (!UseMembar) {
  4587     address mem_serialize_page = (address)Solaris::mmap_chunk(NULL, page_size, MAP_PRIVATE, PROT_READ | PROT_WRITE);
  4608     address mem_serialize_page = (address)Solaris::mmap_chunk(NULL, page_size, MAP_PRIVATE, PROT_READ | PROT_WRITE);
  4588     guarantee(mem_serialize_page != NULL, "mmap Failed for memory serialize page");
  4609     guarantee(mem_serialize_page != NULL, "mmap Failed for memory serialize page");
  4589     os::set_memory_serialize_page(mem_serialize_page);
  4610     os::set_memory_serialize_page(mem_serialize_page);
  4590 
  4611 
  4591 #ifndef PRODUCT
  4612 #ifndef PRODUCT
  4592     if (Verbose && PrintMiscellaneous)
  4613     if (Verbose && PrintMiscellaneous) {
  4593       tty->print("[Memory Serialize  Page address: " INTPTR_FORMAT "]\n", (intptr_t)mem_serialize_page);
  4614       tty->print("[Memory Serialize  Page address: " INTPTR_FORMAT "]\n",
       
  4615                  (intptr_t)mem_serialize_page);
       
  4616     }
  4594 #endif
  4617 #endif
  4595   }
  4618   }
  4596 
  4619 
  4597   // Check minimum allowable stack size for thread creation and to initialize
  4620   // Check minimum allowable stack size for thread creation and to initialize
  4598   // the java system classes, including StackOverflowError - depends on page
  4621   // the java system classes, including StackOverflowError - depends on page
  4599   // size.  Add a page for compiler2 recursion in main thread.
  4622   // size.  Add a page for compiler2 recursion in main thread.
  4600   // Add in 2*BytesPerWord times page size to account for VM stack during
  4623   // Add in 2*BytesPerWord times page size to account for VM stack during
  4601   // class initialization depending on 32 or 64 bit VM.
  4624   // class initialization depending on 32 or 64 bit VM.
  4602   os::Solaris::min_stack_allowed = MAX2(os::Solaris::min_stack_allowed,
  4625   os::Solaris::min_stack_allowed = MAX2(os::Solaris::min_stack_allowed,
  4603             (size_t)(StackYellowPages+StackRedPages+StackShadowPages+
  4626                                         (size_t)(StackYellowPages+StackRedPages+StackShadowPages+
  4604                     2*BytesPerWord COMPILER2_PRESENT(+1)) * page_size);
  4627                                         2*BytesPerWord COMPILER2_PRESENT(+1)) * page_size);
  4605 
  4628 
  4606   size_t threadStackSizeInBytes = ThreadStackSize * K;
  4629   size_t threadStackSizeInBytes = ThreadStackSize * K;
  4607   if (threadStackSizeInBytes != 0 &&
  4630   if (threadStackSizeInBytes != 0 &&
  4608     threadStackSizeInBytes < os::Solaris::min_stack_allowed) {
  4631       threadStackSizeInBytes < os::Solaris::min_stack_allowed) {
  4609     tty->print_cr("\nThe stack size specified is too small, Specify at least %dk",
  4632     tty->print_cr("\nThe stack size specified is too small, Specify at least %dk",
  4610                   os::Solaris::min_stack_allowed/K);
  4633                   os::Solaris::min_stack_allowed/K);
  4611     return JNI_ERR;
  4634     return JNI_ERR;
  4612   }
  4635   }
  4613 
  4636 
  4617   // virtual memory fragmentation (since we're not creating the
  4640   // virtual memory fragmentation (since we're not creating the
  4618   // stack on a power of 2 boundary.  The real fix for this
  4641   // stack on a power of 2 boundary.  The real fix for this
  4619   // should be to fix the guard page mechanism.
  4642   // should be to fix the guard page mechanism.
  4620 
  4643 
  4621   if (vm_page_size() > 8*K) {
  4644   if (vm_page_size() > 8*K) {
  4622       threadStackSizeInBytes = (threadStackSizeInBytes != 0)
  4645     threadStackSizeInBytes = (threadStackSizeInBytes != 0)
  4623          ? threadStackSizeInBytes +
  4646        ? threadStackSizeInBytes +
  4624            ((StackYellowPages + StackRedPages) * vm_page_size())
  4647          ((StackYellowPages + StackRedPages) * vm_page_size())
  4625          : 0;
  4648        : 0;
  4626       ThreadStackSize = threadStackSizeInBytes/K;
  4649     ThreadStackSize = threadStackSizeInBytes/K;
  4627   }
  4650   }
  4628 
  4651 
  4629   // Make the stack size a multiple of the page size so that
  4652   // Make the stack size a multiple of the page size so that
  4630   // the yellow/red zones can be guarded.
  4653   // the yellow/red zones can be guarded.
  4631   JavaThread::set_stack_size_at_create(round_to(threadStackSizeInBytes,
  4654   JavaThread::set_stack_size_at_create(round_to(threadStackSizeInBytes,
  4632         vm_page_size()));
  4655                                                 vm_page_size()));
  4633 
  4656 
  4634   Solaris::libthread_init();
  4657   Solaris::libthread_init();
  4635 
  4658 
  4636   if (UseNUMA) {
  4659   if (UseNUMA) {
  4637     if (!Solaris::liblgrp_init()) {
  4660     if (!Solaris::liblgrp_init()) {
  4667     // set the number of file descriptors to max. print out error
  4690     // set the number of file descriptors to max. print out error
  4668     // if getrlimit/setrlimit fails but continue regardless.
  4691     // if getrlimit/setrlimit fails but continue regardless.
  4669     struct rlimit nbr_files;
  4692     struct rlimit nbr_files;
  4670     int status = getrlimit(RLIMIT_NOFILE, &nbr_files);
  4693     int status = getrlimit(RLIMIT_NOFILE, &nbr_files);
  4671     if (status != 0) {
  4694     if (status != 0) {
  4672       if (PrintMiscellaneous && (Verbose || WizardMode))
  4695       if (PrintMiscellaneous && (Verbose || WizardMode)) {
  4673         perror("os::init_2 getrlimit failed");
  4696         perror("os::init_2 getrlimit failed");
       
  4697       }
  4674     } else {
  4698     } else {
  4675       nbr_files.rlim_cur = nbr_files.rlim_max;
  4699       nbr_files.rlim_cur = nbr_files.rlim_max;
  4676       status = setrlimit(RLIMIT_NOFILE, &nbr_files);
  4700       status = setrlimit(RLIMIT_NOFILE, &nbr_files);
  4677       if (status != 0) {
  4701       if (status != 0) {
  4678         if (PrintMiscellaneous && (Verbose || WizardMode))
  4702         if (PrintMiscellaneous && (Verbose || WizardMode)) {
  4679           perror("os::init_2 setrlimit failed");
  4703           perror("os::init_2 setrlimit failed");
       
  4704         }
  4680       }
  4705       }
  4681     }
  4706     }
  4682   }
  4707   }
  4683 
  4708 
  4684   // Calculate theoretical max. size of Threads to guard gainst
  4709   // Calculate theoretical max. size of Threads to guard gainst
  4726   return;
  4751   return;
  4727 }
  4752 }
  4728 
  4753 
  4729 // Mark the polling page as unreadable
  4754 // Mark the polling page as unreadable
  4730 void os::make_polling_page_unreadable(void) {
  4755 void os::make_polling_page_unreadable(void) {
  4731   if (mprotect((char *)_polling_page, page_size, PROT_NONE) != 0)
  4756   if (mprotect((char *)_polling_page, page_size, PROT_NONE) != 0) {
  4732     fatal("Could not disable polling page");
  4757     fatal("Could not disable polling page");
  4733 };
  4758   }
       
  4759 }
  4734 
  4760 
  4735 // Mark the polling page as readable
  4761 // Mark the polling page as readable
  4736 void os::make_polling_page_readable(void) {
  4762 void os::make_polling_page_readable(void) {
  4737   if (mprotect((char *)_polling_page, page_size, PROT_READ) != 0)
  4763   if (mprotect((char *)_polling_page, page_size, PROT_READ) != 0) {
  4738     fatal("Could not enable polling page");
  4764     fatal("Could not enable polling page");
  4739 };
  4765   }
       
  4766 }
  4740 
  4767 
  4741 // OS interface.
  4768 // OS interface.
  4742 
  4769 
  4743 bool os::check_heap(bool force) { return true; }
  4770 bool os::check_heap(bool force) { return true; }
  4744 
  4771 
  4747 
  4774 
  4748 int local_vsnprintf(char* buf, size_t count, const char* fmt, va_list argptr) {
  4775 int local_vsnprintf(char* buf, size_t count, const char* fmt, va_list argptr) {
  4749   if (!sol_vsnprintf) {
  4776   if (!sol_vsnprintf) {
  4750     //search  for the named symbol in the objects that were loaded after libjvm
  4777     //search  for the named symbol in the objects that were loaded after libjvm
  4751     void* where = RTLD_NEXT;
  4778     void* where = RTLD_NEXT;
  4752     if ((sol_vsnprintf = CAST_TO_FN_PTR(vsnprintf_t, dlsym(where, "__vsnprintf"))) == NULL)
  4779     if ((sol_vsnprintf = CAST_TO_FN_PTR(vsnprintf_t, dlsym(where, "__vsnprintf"))) == NULL) {
  4753         sol_vsnprintf = CAST_TO_FN_PTR(vsnprintf_t, dlsym(where, "vsnprintf"));
  4780       sol_vsnprintf = CAST_TO_FN_PTR(vsnprintf_t, dlsym(where, "vsnprintf"));
       
  4781     }
  4754     if (!sol_vsnprintf){
  4782     if (!sol_vsnprintf){
  4755       //search  for the named symbol in the objects that were loaded before libjvm
  4783       //search  for the named symbol in the objects that were loaded before libjvm
  4756       where = RTLD_DEFAULT;
  4784       where = RTLD_DEFAULT;
  4757       if ((sol_vsnprintf = CAST_TO_FN_PTR(vsnprintf_t, dlsym(where, "__vsnprintf"))) == NULL)
  4785       if ((sol_vsnprintf = CAST_TO_FN_PTR(vsnprintf_t, dlsym(where, "__vsnprintf"))) == NULL) {
  4758         sol_vsnprintf = CAST_TO_FN_PTR(vsnprintf_t, dlsym(where, "vsnprintf"));
  4786         sol_vsnprintf = CAST_TO_FN_PTR(vsnprintf_t, dlsym(where, "vsnprintf"));
       
  4787       }
  4759       assert(sol_vsnprintf != NULL, "vsnprintf not found");
  4788       assert(sol_vsnprintf != NULL, "vsnprintf not found");
  4760     }
  4789     }
  4761   }
  4790   }
  4762   return (*sol_vsnprintf)(buf, count, fmt, argptr);
  4791   return (*sol_vsnprintf)(buf, count, fmt, argptr);
  4763 }
  4792 }
  4769   struct dirent *ptr;
  4798   struct dirent *ptr;
  4770 
  4799 
  4771   dir = opendir(path);
  4800   dir = opendir(path);
  4772   if (dir == NULL) return true;
  4801   if (dir == NULL) return true;
  4773 
  4802 
  4774   /* Scan the directory */
  4803   // Scan the directory
  4775   bool result = true;
  4804   bool result = true;
  4776   char buf[sizeof(struct dirent) + MAX_PATH];
  4805   char buf[sizeof(struct dirent) + MAX_PATH];
  4777   struct dirent *dbuf = (struct dirent *) buf;
  4806   struct dirent *dbuf = (struct dirent *) buf;
  4778   while (result && (ptr = readdir(dir, dbuf)) != NULL) {
  4807   while (result && (ptr = readdir(dir, dbuf)) != NULL) {
  4779     if (strcmp(ptr->d_name, ".") != 0 && strcmp(ptr->d_name, "..") != 0) {
  4808     if (strcmp(ptr->d_name, ".") != 0 && strcmp(ptr->d_name, "..") != 0) {
  4786 
  4815 
  4787 // This code originates from JDK's sysOpen and open64_w
  4816 // This code originates from JDK's sysOpen and open64_w
  4788 // from src/solaris/hpi/src/system_md.c
  4817 // from src/solaris/hpi/src/system_md.c
  4789 
  4818 
  4790 #ifndef O_DELETE
  4819 #ifndef O_DELETE
  4791 #define O_DELETE 0x10000
  4820   #define O_DELETE 0x10000
  4792 #endif
  4821 #endif
  4793 
  4822 
  4794 // Open a file. Unlink the file immediately after open returns
  4823 // Open a file. Unlink the file immediately after open returns
  4795 // if the specified oflag has the O_DELETE flag set.
  4824 // if the specified oflag has the O_DELETE flag set.
  4796 // O_DELETE is used only in j2se/src/share/native/java/util/zip/ZipFile.c
  4825 // O_DELETE is used only in j2se/src/share/native/java/util/zip/ZipFile.c
  4805   oflag = oflag & ~O_DELETE;
  4834   oflag = oflag & ~O_DELETE;
  4806 
  4835 
  4807   fd = ::open64(path, oflag, mode);
  4836   fd = ::open64(path, oflag, mode);
  4808   if (fd == -1) return -1;
  4837   if (fd == -1) return -1;
  4809 
  4838 
  4810   //If the open succeeded, the file might still be a directory
  4839   // If the open succeeded, the file might still be a directory
  4811   {
  4840   {
  4812     struct stat64 buf64;
  4841     struct stat64 buf64;
  4813     int ret = ::fstat64(fd, &buf64);
  4842     int ret = ::fstat64(fd, &buf64);
  4814     int st_mode = buf64.st_mode;
  4843     int st_mode = buf64.st_mode;
  4815 
  4844 
  4822     } else {
  4851     } else {
  4823       ::close(fd);
  4852       ::close(fd);
  4824       return -1;
  4853       return -1;
  4825     }
  4854     }
  4826   }
  4855   }
  4827     /*
  4856 
  4828      * 32-bit Solaris systems suffer from:
  4857   // 32-bit Solaris systems suffer from:
  4829      *
  4858   //
  4830      * - an historical default soft limit of 256 per-process file
  4859   // - an historical default soft limit of 256 per-process file
  4831      *   descriptors that is too low for many Java programs.
  4860   //   descriptors that is too low for many Java programs.
  4832      *
  4861   //
  4833      * - a design flaw where file descriptors created using stdio
  4862   // - a design flaw where file descriptors created using stdio
  4834      *   fopen must be less than 256, _even_ when the first limit above
  4863   //   fopen must be less than 256, _even_ when the first limit above
  4835      *   has been raised.  This can cause calls to fopen (but not calls to
  4864   //   has been raised.  This can cause calls to fopen (but not calls to
  4836      *   open, for example) to fail mysteriously, perhaps in 3rd party
  4865   //   open, for example) to fail mysteriously, perhaps in 3rd party
  4837      *   native code (although the JDK itself uses fopen).  One can hardly
  4866   //   native code (although the JDK itself uses fopen).  One can hardly
  4838      *   criticize them for using this most standard of all functions.
  4867   //   criticize them for using this most standard of all functions.
  4839      *
  4868   //
  4840      * We attempt to make everything work anyways by:
  4869   // We attempt to make everything work anyways by:
  4841      *
  4870   //
  4842      * - raising the soft limit on per-process file descriptors beyond
  4871   // - raising the soft limit on per-process file descriptors beyond
  4843      *   256
  4872   //   256
  4844      *
  4873   //
  4845      * - As of Solaris 10u4, we can request that Solaris raise the 256
  4874   // - As of Solaris 10u4, we can request that Solaris raise the 256
  4846      *   stdio fopen limit by calling function enable_extended_FILE_stdio.
  4875   //   stdio fopen limit by calling function enable_extended_FILE_stdio.
  4847      *   This is done in init_2 and recorded in enabled_extended_FILE_stdio
  4876   //   This is done in init_2 and recorded in enabled_extended_FILE_stdio
  4848      *
  4877   //
  4849      * - If we are stuck on an old (pre 10u4) Solaris system, we can
  4878   // - If we are stuck on an old (pre 10u4) Solaris system, we can
  4850      *   workaround the bug by remapping non-stdio file descriptors below
  4879   //   workaround the bug by remapping non-stdio file descriptors below
  4851      *   256 to ones beyond 256, which is done below.
  4880   //   256 to ones beyond 256, which is done below.
  4852      *
  4881   //
  4853      * See:
  4882   // See:
  4854      * 1085341: 32-bit stdio routines should support file descriptors >255
  4883   // 1085341: 32-bit stdio routines should support file descriptors >255
  4855      * 6533291: Work around 32-bit Solaris stdio limit of 256 open files
  4884   // 6533291: Work around 32-bit Solaris stdio limit of 256 open files
  4856      * 6431278: Netbeans crash on 32 bit Solaris: need to call
  4885   // 6431278: Netbeans crash on 32 bit Solaris: need to call
  4857      *          enable_extended_FILE_stdio() in VM initialisation
  4886   //          enable_extended_FILE_stdio() in VM initialisation
  4858      * Giri Mandalika's blog
  4887   // Giri Mandalika's blog
  4859      * http://technopark02.blogspot.com/2005_05_01_archive.html
  4888   // http://technopark02.blogspot.com/2005_05_01_archive.html
  4860      */
  4889   //
  4861 #ifndef  _LP64
  4890 #ifndef  _LP64
  4862      if ((!enabled_extended_FILE_stdio) && fd < 256) {
  4891   if ((!enabled_extended_FILE_stdio) && fd < 256) {
  4863          int newfd = ::fcntl(fd, F_DUPFD, 256);
  4892     int newfd = ::fcntl(fd, F_DUPFD, 256);
  4864          if (newfd != -1) {
  4893     if (newfd != -1) {
  4865              ::close(fd);
  4894       ::close(fd);
  4866              fd = newfd;
  4895       fd = newfd;
  4867          }
  4896     }
  4868      }
  4897   }
  4869 #endif // 32-bit Solaris
  4898 #endif // 32-bit Solaris
  4870     /*
  4899 
  4871      * All file descriptors that are opened in the JVM and not
  4900   // All file descriptors that are opened in the JVM and not
  4872      * specifically destined for a subprocess should have the
  4901   // specifically destined for a subprocess should have the
  4873      * close-on-exec flag set.  If we don't set it, then careless 3rd
  4902   // close-on-exec flag set.  If we don't set it, then careless 3rd
  4874      * party native code might fork and exec without closing all
  4903   // party native code might fork and exec without closing all
  4875      * appropriate file descriptors (e.g. as we do in closeDescriptors in
  4904   // appropriate file descriptors (e.g. as we do in closeDescriptors in
  4876      * UNIXProcess.c), and this in turn might:
  4905   // UNIXProcess.c), and this in turn might:
  4877      *
  4906   //
  4878      * - cause end-of-file to fail to be detected on some file
  4907   // - cause end-of-file to fail to be detected on some file
  4879      *   descriptors, resulting in mysterious hangs, or
  4908   //   descriptors, resulting in mysterious hangs, or
  4880      *
  4909   //
  4881      * - might cause an fopen in the subprocess to fail on a system
  4910   // - might cause an fopen in the subprocess to fail on a system
  4882      *   suffering from bug 1085341.
  4911   //   suffering from bug 1085341.
  4883      *
  4912   //
  4884      * (Yes, the default setting of the close-on-exec flag is a Unix
  4913   // (Yes, the default setting of the close-on-exec flag is a Unix
  4885      * design flaw)
  4914   // design flaw)
  4886      *
  4915   //
  4887      * See:
  4916   // See:
  4888      * 1085341: 32-bit stdio routines should support file descriptors >255
  4917   // 1085341: 32-bit stdio routines should support file descriptors >255
  4889      * 4843136: (process) pipe file descriptor from Runtime.exec not being closed
  4918   // 4843136: (process) pipe file descriptor from Runtime.exec not being closed
  4890      * 6339493: (process) Runtime.exec does not close all file descriptors on Solaris 9
  4919   // 6339493: (process) Runtime.exec does not close all file descriptors on Solaris 9
  4891      */
  4920   //
  4892 #ifdef FD_CLOEXEC
  4921 #ifdef FD_CLOEXEC
  4893     {
  4922   {
  4894         int flags = ::fcntl(fd, F_GETFD);
  4923     int flags = ::fcntl(fd, F_GETFD);
  4895         if (flags != -1)
  4924     if (flags != -1) {
  4896             ::fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
  4925       ::fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
  4897     }
  4926     }
       
  4927   }
  4898 #endif
  4928 #endif
  4899 
  4929 
  4900   if (o_delete != 0) {
  4930   if (o_delete != 0) {
  4901     ::unlink(path);
  4931     ::unlink(path);
  4902   }
  4932   }
  4938   RESTARTABLE_RETURN_INT(::fsync(fd));
  4968   RESTARTABLE_RETURN_INT(::fsync(fd));
  4939 }
  4969 }
  4940 
  4970 
  4941 int os::available(int fd, jlong *bytes) {
  4971 int os::available(int fd, jlong *bytes) {
  4942   assert(((JavaThread*)Thread::current())->thread_state() == _thread_in_native,
  4972   assert(((JavaThread*)Thread::current())->thread_state() == _thread_in_native,
  4943           "Assumed _thread_in_native");
  4973          "Assumed _thread_in_native");
  4944   jlong cur, end;
  4974   jlong cur, end;
  4945   int mode;
  4975   int mode;
  4946   struct stat64 buf64;
  4976   struct stat64 buf64;
  4947 
  4977 
  4948   if (::fstat64(fd, &buf64) >= 0) {
  4978   if (::fstat64(fd, &buf64) >= 0) {
  4950     if (S_ISCHR(mode) || S_ISFIFO(mode) || S_ISSOCK(mode)) {
  4980     if (S_ISCHR(mode) || S_ISFIFO(mode) || S_ISSOCK(mode)) {
  4951       int n,ioctl_return;
  4981       int n,ioctl_return;
  4952 
  4982 
  4953       RESTARTABLE(::ioctl(fd, FIONREAD, &n), ioctl_return);
  4983       RESTARTABLE(::ioctl(fd, FIONREAD, &n), ioctl_return);
  4954       if (ioctl_return>= 0) {
  4984       if (ioctl_return>= 0) {
  4955           *bytes = n;
  4985         *bytes = n;
  4956         return 1;
  4986         return 1;
  4957       }
  4987       }
  4958     }
  4988     }
  4959   }
  4989   }
  4960   if ((cur = ::lseek64(fd, 0L, SEEK_CUR)) == -1) {
  4990   if ((cur = ::lseek64(fd, 0L, SEEK_CUR)) == -1) {
  4968   return 1;
  4998   return 1;
  4969 }
  4999 }
  4970 
  5000 
  4971 // Map a block of memory.
  5001 // Map a block of memory.
  4972 char* os::pd_map_memory(int fd, const char* file_name, size_t file_offset,
  5002 char* os::pd_map_memory(int fd, const char* file_name, size_t file_offset,
  4973                      char *addr, size_t bytes, bool read_only,
  5003                         char *addr, size_t bytes, bool read_only,
  4974                      bool allow_exec) {
  5004                         bool allow_exec) {
  4975   int prot;
  5005   int prot;
  4976   int flags;
  5006   int flags;
  4977 
  5007 
  4978   if (read_only) {
  5008   if (read_only) {
  4979     prot = PROT_READ;
  5009     prot = PROT_READ;
  5000 }
  5030 }
  5001 
  5031 
  5002 
  5032 
  5003 // Remap a block of memory.
  5033 // Remap a block of memory.
  5004 char* os::pd_remap_memory(int fd, const char* file_name, size_t file_offset,
  5034 char* os::pd_remap_memory(int fd, const char* file_name, size_t file_offset,
  5005                        char *addr, size_t bytes, bool read_only,
  5035                           char *addr, size_t bytes, bool read_only,
  5006                        bool allow_exec) {
  5036                           bool allow_exec) {
  5007   // same as map_memory() on this OS
  5037   // same as map_memory() on this OS
  5008   return os::map_memory(fd, file_name, file_offset, addr, bytes, read_only,
  5038   return os::map_memory(fd, file_name, file_offset, addr, bytes, read_only,
  5009                         allow_exec);
  5039                         allow_exec);
  5010 }
  5040 }
  5011 
  5041 
  5030     while (::stat(filename, &buf) == 0) {
  5060     while (::stat(filename, &buf) == 0) {
  5031       (void)::poll(NULL, 0, 100);
  5061       (void)::poll(NULL, 0, 100);
  5032     }
  5062     }
  5033   } else {
  5063   } else {
  5034     jio_fprintf(stderr,
  5064     jio_fprintf(stderr,
  5035       "Could not open pause file '%s', continuing immediately.\n", filename);
  5065                 "Could not open pause file '%s', continuing immediately.\n", filename);
  5036   }
  5066   }
  5037 }
  5067 }
  5038 
  5068 
  5039 #ifndef PRODUCT
  5069 #ifndef PRODUCT
  5040 #ifdef INTERPOSE_ON_SYSTEM_SYNCH_FUNCTIONS
  5070 #ifdef INTERPOSE_ON_SYSTEM_SYNCH_FUNCTIONS
  5046 void record_synch(char* name, bool returning);  // defined below
  5076 void record_synch(char* name, bool returning);  // defined below
  5047 
  5077 
  5048 class RecordSynch {
  5078 class RecordSynch {
  5049   char* _name;
  5079   char* _name;
  5050  public:
  5080  public:
  5051   RecordSynch(char* name) :_name(name)
  5081   RecordSynch(char* name) :_name(name) { record_synch(_name, false); }
  5052                  { record_synch(_name, false); }
  5082   ~RecordSynch()                       { record_synch(_name, true); }
  5053   ~RecordSynch() { record_synch(_name,   true);  }
       
  5054 };
  5083 };
  5055 
  5084 
  5056 #define CHECK_SYNCH_OP(ret, name, params, args, inner)          \
  5085 #define CHECK_SYNCH_OP(ret, name, params, args, inner)          \
  5057 extern "C" ret name params {                                    \
  5086 extern "C" ret name params {                                    \
  5058   typedef ret name##_t params;                                  \
  5087   typedef ret name##_t params;                                  \
  5078   if (!CHECK_POINTER_OK(cv)) fatal("Condvar must be in C heap only.");
  5107   if (!CHECK_POINTER_OK(cv)) fatal("Condvar must be in C heap only.");
  5079 #define CHECK_P(p) \
  5108 #define CHECK_P(p) \
  5080   if (!CHECK_POINTER_OK(p))  fatal(false,  "Pointer must be in C heap only.");
  5109   if (!CHECK_POINTER_OK(p))  fatal(false,  "Pointer must be in C heap only.");
  5081 
  5110 
  5082 #define CHECK_MUTEX(mutex_op) \
  5111 #define CHECK_MUTEX(mutex_op) \
  5083 CHECK_SYNCH_OP(int, mutex_op, (mutex_t *mu), (mu), CHECK_MU);
  5112   CHECK_SYNCH_OP(int, mutex_op, (mutex_t *mu), (mu), CHECK_MU);
  5084 
  5113 
  5085 CHECK_MUTEX(   mutex_lock)
  5114 CHECK_MUTEX(   mutex_lock)
  5086 CHECK_MUTEX(  _mutex_lock)
  5115 CHECK_MUTEX(  _mutex_lock)
  5087 CHECK_MUTEX( mutex_unlock)
  5116 CHECK_MUTEX( mutex_unlock)
  5088 CHECK_MUTEX(_mutex_unlock)
  5117 CHECK_MUTEX(_mutex_unlock)
  5089 CHECK_MUTEX( mutex_trylock)
  5118 CHECK_MUTEX( mutex_trylock)
  5090 CHECK_MUTEX(_mutex_trylock)
  5119 CHECK_MUTEX(_mutex_trylock)
  5091 
  5120 
  5092 #define CHECK_COND(cond_op) \
  5121 #define CHECK_COND(cond_op) \
  5093 CHECK_SYNCH_OP(int, cond_op, (cond_t *cv, mutex_t *mu), (cv, mu), CHECK_MU;CHECK_CV);
  5122   CHECK_SYNCH_OP(int, cond_op, (cond_t *cv, mutex_t *mu), (cv, mu), CHECK_MU; CHECK_CV);
  5094 
  5123 
  5095 CHECK_COND( cond_wait);
  5124 CHECK_COND( cond_wait);
  5096 CHECK_COND(_cond_wait);
  5125 CHECK_COND(_cond_wait);
  5097 CHECK_COND(_cond_wait_cancel);
  5126 CHECK_COND(_cond_wait_cancel);
  5098 
  5127 
  5099 #define CHECK_COND2(cond_op) \
  5128 #define CHECK_COND2(cond_op) \
  5100 CHECK_SYNCH_OP(int, cond_op, (cond_t *cv, mutex_t *mu, timestruc_t* ts), (cv, mu, ts), CHECK_MU;CHECK_CV);
  5129   CHECK_SYNCH_OP(int, cond_op, (cond_t *cv, mutex_t *mu, timestruc_t* ts), (cv, mu, ts), CHECK_MU; CHECK_CV);
  5101 
  5130 
  5102 CHECK_COND2( cond_timedwait);
  5131 CHECK_COND2( cond_timedwait);
  5103 CHECK_COND2(_cond_timedwait);
  5132 CHECK_COND2(_cond_timedwait);
  5104 CHECK_COND2(_cond_timedwait_cancel);
  5133 CHECK_COND2(_cond_timedwait_cancel);
  5105 
  5134 
  5219   prusage_t prusage;
  5248   prusage_t prusage;
  5220   jlong lwp_time;
  5249   jlong lwp_time;
  5221   int fd;
  5250   int fd;
  5222 
  5251 
  5223   sprintf(proc_name, "/proc/%d/lwp/%d/lwpusage",
  5252   sprintf(proc_name, "/proc/%d/lwp/%d/lwpusage",
  5224                      getpid(),
  5253           getpid(),
  5225                      thread->osthread()->lwp_id());
  5254           thread->osthread()->lwp_id());
  5226   fd = ::open(proc_name, O_RDONLY);
  5255   fd = ::open(proc_name, O_RDONLY);
  5227   if (fd == -1) return -1;
  5256   if (fd == -1) return -1;
  5228 
  5257 
  5229   do {
  5258   do {
  5230     count = ::pread(fd,
  5259     count = ::pread(fd,
  5231                   (void *)&prusage.pr_utime,
  5260                     (void *)&prusage.pr_utime,
  5232                   thr_time_size,
  5261                     thr_time_size,
  5233                   thr_time_off);
  5262                     thr_time_off);
  5234   } while (count < 0 && errno == EINTR);
  5263   } while (count < 0 && errno == EINTR);
  5235   ::close(fd);
  5264   ::close(fd);
  5236   if (count < 0) return -1;
  5265   if (count < 0) return -1;
  5237 
  5266 
  5238   if (user_sys_cpu_time) {
  5267   if (user_sys_cpu_time) {
  5286   memset(&dlinfo, 0, sizeof(dlinfo));
  5315   memset(&dlinfo, 0, sizeof(dlinfo));
  5287   if (dladdr(addr, &dlinfo) != 0) {
  5316   if (dladdr(addr, &dlinfo) != 0) {
  5288     st->print(PTR_FORMAT ": ", addr);
  5317     st->print(PTR_FORMAT ": ", addr);
  5289     if (dlinfo.dli_sname != NULL && dlinfo.dli_saddr != NULL) {
  5318     if (dlinfo.dli_sname != NULL && dlinfo.dli_saddr != NULL) {
  5290       st->print("%s+%#lx", dlinfo.dli_sname, addr-(intptr_t)dlinfo.dli_saddr);
  5319       st->print("%s+%#lx", dlinfo.dli_sname, addr-(intptr_t)dlinfo.dli_saddr);
  5291     } else if (dlinfo.dli_fbase != NULL)
  5320     } else if (dlinfo.dli_fbase != NULL) {
  5292       st->print("<offset %#lx>", addr-(intptr_t)dlinfo.dli_fbase);
  5321       st->print("<offset %#lx>", addr-(intptr_t)dlinfo.dli_fbase);
  5293     else
  5322     } else {
  5294       st->print("<absolute address>");
  5323       st->print("<absolute address>");
       
  5324     }
  5295     if (dlinfo.dli_fname != NULL) {
  5325     if (dlinfo.dli_fname != NULL) {
  5296       st->print(" in %s", dlinfo.dli_fname);
  5326       st->print(" in %s", dlinfo.dli_fname);
  5297     }
  5327     }
  5298     if (dlinfo.dli_fbase != NULL) {
  5328     if (dlinfo.dli_fbase != NULL) {
  5299       st->print(" at " PTR_FORMAT, dlinfo.dli_fbase);
  5329       st->print(" at " PTR_FORMAT, dlinfo.dli_fbase);
  5307       address       lowest = (address) dlinfo.dli_sname;
  5337       address       lowest = (address) dlinfo.dli_sname;
  5308       if (!lowest)  lowest = (address) dlinfo.dli_fbase;
  5338       if (!lowest)  lowest = (address) dlinfo.dli_fbase;
  5309       if (begin < lowest)  begin = lowest;
  5339       if (begin < lowest)  begin = lowest;
  5310       Dl_info dlinfo2;
  5340       Dl_info dlinfo2;
  5311       if (dladdr(end, &dlinfo2) != 0 && dlinfo2.dli_saddr != dlinfo.dli_saddr
  5341       if (dladdr(end, &dlinfo2) != 0 && dlinfo2.dli_saddr != dlinfo.dli_saddr
  5312           && end > dlinfo2.dli_saddr && dlinfo2.dli_saddr > begin)
  5342           && end > dlinfo2.dli_saddr && dlinfo2.dli_saddr > begin) {
  5313         end = (address) dlinfo2.dli_saddr;
  5343         end = (address) dlinfo2.dli_saddr;
       
  5344       }
  5314       Disassembler::decode(begin, end, st);
  5345       Disassembler::decode(begin, end, st);
  5315     }
  5346     }
  5316     return true;
  5347     return true;
  5317   }
  5348   }
  5318   return false;
  5349   return false;
  5424     // since we can not accurately identify the patch level and
  5455     // since we can not accurately identify the patch level and
  5425     // this has already been fixed in Solaris 9 and 8 we will
  5456     // this has already been fixed in Solaris 9 and 8 we will
  5426     // leave it alone rather than always rounding down.
  5457     // leave it alone rather than always rounding down.
  5427 
  5458 
  5428     if (millis > 0 && millis < ROUNDINGFIX) millis = ROUNDINGFIX;
  5459     if (millis > 0 && millis < ROUNDINGFIX) millis = ROUNDINGFIX;
  5429        // It appears that when we go directly through Solaris _lwp_cond_timedwait()
  5460     // It appears that when we go directly through Solaris _lwp_cond_timedwait()
  5430            // the acceptable max time threshold is smaller than for libthread on 2.5.1 and 2.6
  5461     // the acceptable max time threshold is smaller than for libthread on 2.5.1 and 2.6
  5431            max_wait_period = 21000000;
  5462     max_wait_period = 21000000;
  5432   } else {
  5463   } else {
  5433     max_wait_period = 50000000;
  5464     max_wait_period = 50000000;
  5434   }
  5465   }
  5435   millis %= 1000;
  5466   millis %= 1000;
  5436   if (seconds > max_wait_period) {      // see man cond_timedwait(3T)
  5467   if (seconds > max_wait_period) {      // see man cond_timedwait(3T)
  5437      seconds = max_wait_period;
  5468     seconds = max_wait_period;
  5438   }
  5469   }
  5439   abstime->tv_sec = now.tv_sec  + seconds;
  5470   abstime->tv_sec = now.tv_sec  + seconds;
  5440   long       usec = now.tv_usec + millis * 1000;
  5471   long       usec = now.tv_usec + millis * 1000;
  5441   if (usec >= 1000000) {
  5472   if (usec >= 1000000) {
  5442     abstime->tv_sec += 1;
  5473     abstime->tv_sec += 1;
  5451   // may call park().
  5482   // may call park().
  5452   assert(_nParked == 0, "invariant");
  5483   assert(_nParked == 0, "invariant");
  5453 
  5484 
  5454   int v;
  5485   int v;
  5455   for (;;) {
  5486   for (;;) {
  5456       v = _Event;
  5487     v = _Event;
  5457       if (Atomic::cmpxchg(v-1, &_Event, v) == v) break;
  5488     if (Atomic::cmpxchg(v-1, &_Event, v) == v) break;
  5458   }
  5489   }
  5459   guarantee(v >= 0, "invariant");
  5490   guarantee(v >= 0, "invariant");
  5460   if (v == 0) {
  5491   if (v == 0) {
  5461      // Do this the hard way by blocking ...
  5492     // Do this the hard way by blocking ...
  5462      // See http://monaco.sfbay/detail.jsf?cr=5094058.
  5493     // See http://monaco.sfbay/detail.jsf?cr=5094058.
  5463      // TODO-FIXME: for Solaris SPARC set fprs.FEF=0 prior to parking.
  5494     // TODO-FIXME: for Solaris SPARC set fprs.FEF=0 prior to parking.
  5464      // Only for SPARC >= V8PlusA
  5495     // Only for SPARC >= V8PlusA
  5465 #if defined(__sparc) && defined(COMPILER2)
  5496 #if defined(__sparc) && defined(COMPILER2)
  5466      if (ClearFPUAtPark) { _mark_fpu_nosave(); }
  5497     if (ClearFPUAtPark) { _mark_fpu_nosave(); }
  5467 #endif
  5498 #endif
  5468      int status = os::Solaris::mutex_lock(_mutex);
  5499     int status = os::Solaris::mutex_lock(_mutex);
  5469      assert_status(status == 0, status, "mutex_lock");
  5500     assert_status(status == 0, status, "mutex_lock");
  5470      guarantee(_nParked == 0, "invariant");
  5501     guarantee(_nParked == 0, "invariant");
  5471      ++_nParked;
  5502     ++_nParked;
  5472      while (_Event < 0) {
  5503     while (_Event < 0) {
  5473         // for some reason, under 2.7 lwp_cond_wait() may return ETIME ...
  5504       // for some reason, under 2.7 lwp_cond_wait() may return ETIME ...
  5474         // Treat this the same as if the wait was interrupted
  5505       // Treat this the same as if the wait was interrupted
  5475         // With usr/lib/lwp going to kernel, always handle ETIME
  5506       // With usr/lib/lwp going to kernel, always handle ETIME
  5476         status = os::Solaris::cond_wait(_cond, _mutex);
  5507       status = os::Solaris::cond_wait(_cond, _mutex);
  5477         if (status == ETIME) status = EINTR;
  5508       if (status == ETIME) status = EINTR;
  5478         assert_status(status == 0 || status == EINTR, status, "cond_wait");
  5509       assert_status(status == 0 || status == EINTR, status, "cond_wait");
  5479      }
  5510     }
  5480      --_nParked;
  5511     --_nParked;
  5481      _Event = 0;
  5512     _Event = 0;
  5482      status = os::Solaris::mutex_unlock(_mutex);
  5513     status = os::Solaris::mutex_unlock(_mutex);
  5483      assert_status(status == 0, status, "mutex_unlock");
  5514     assert_status(status == 0, status, "mutex_unlock");
  5484     // Paranoia to ensure our locked and lock-free paths interact
  5515     // Paranoia to ensure our locked and lock-free paths interact
  5485     // correctly with each other.
  5516     // correctly with each other.
  5486     OrderAccess::fence();
  5517     OrderAccess::fence();
  5487   }
  5518   }
  5488 }
  5519 }
  5489 
  5520 
  5490 int os::PlatformEvent::park(jlong millis) {
  5521 int os::PlatformEvent::park(jlong millis) {
  5491   guarantee(_nParked == 0, "invariant");
  5522   guarantee(_nParked == 0, "invariant");
  5492   int v;
  5523   int v;
  5493   for (;;) {
  5524   for (;;) {
  5494       v = _Event;
  5525     v = _Event;
  5495       if (Atomic::cmpxchg(v-1, &_Event, v) == v) break;
  5526     if (Atomic::cmpxchg(v-1, &_Event, v) == v) break;
  5496   }
  5527   }
  5497   guarantee(v >= 0, "invariant");
  5528   guarantee(v >= 0, "invariant");
  5498   if (v != 0) return OS_OK;
  5529   if (v != 0) return OS_OK;
  5499 
  5530 
  5500   int ret = OS_TIMEOUT;
  5531   int ret = OS_TIMEOUT;
  5503 
  5534 
  5504   // See http://monaco.sfbay/detail.jsf?cr=5094058.
  5535   // See http://monaco.sfbay/detail.jsf?cr=5094058.
  5505   // For Solaris SPARC set fprs.FEF=0 prior to parking.
  5536   // For Solaris SPARC set fprs.FEF=0 prior to parking.
  5506   // Only for SPARC >= V8PlusA
  5537   // Only for SPARC >= V8PlusA
  5507 #if defined(__sparc) && defined(COMPILER2)
  5538 #if defined(__sparc) && defined(COMPILER2)
  5508  if (ClearFPUAtPark) { _mark_fpu_nosave(); }
  5539   if (ClearFPUAtPark) { _mark_fpu_nosave(); }
  5509 #endif
  5540 #endif
  5510   int status = os::Solaris::mutex_lock(_mutex);
  5541   int status = os::Solaris::mutex_lock(_mutex);
  5511   assert_status(status == 0, status, "mutex_lock");
  5542   assert_status(status == 0, status, "mutex_lock");
  5512   guarantee(_nParked == 0, "invariant");
  5543   guarantee(_nParked == 0, "invariant");
  5513   ++_nParked;
  5544   ++_nParked;
  5514   while (_Event < 0) {
  5545   while (_Event < 0) {
  5515      int status = os::Solaris::cond_timedwait(_cond, _mutex, &abst);
  5546     int status = os::Solaris::cond_timedwait(_cond, _mutex, &abst);
  5516      assert_status(status == 0 || status == EINTR ||
  5547     assert_status(status == 0 || status == EINTR ||
  5517                    status == ETIME || status == ETIMEDOUT,
  5548                   status == ETIME || status == ETIMEDOUT,
  5518                    status, "cond_timedwait");
  5549                   status, "cond_timedwait");
  5519      if (!FilterSpuriousWakeups) break;                // previous semantics
  5550     if (!FilterSpuriousWakeups) break;                // previous semantics
  5520      if (status == ETIME || status == ETIMEDOUT) break;
  5551     if (status == ETIME || status == ETIMEDOUT) break;
  5521      // We consume and ignore EINTR and spurious wakeups.
  5552     // We consume and ignore EINTR and spurious wakeups.
  5522   }
  5553   }
  5523   --_nParked;
  5554   --_nParked;
  5524   if (_Event >= 0) ret = OS_OK;
  5555   if (_Event >= 0) ret = OS_OK;
  5525   _Event = 0;
  5556   _Event = 0;
  5526   status = os::Solaris::mutex_unlock(_mutex);
  5557   status = os::Solaris::mutex_unlock(_mutex);
  5565 }
  5596 }
  5566 
  5597 
  5567 // JSR166
  5598 // JSR166
  5568 // -------------------------------------------------------
  5599 // -------------------------------------------------------
  5569 
  5600 
  5570 /*
  5601 // The solaris and linux implementations of park/unpark are fairly
  5571  * The solaris and linux implementations of park/unpark are fairly
  5602 // conservative for now, but can be improved. They currently use a
  5572  * conservative for now, but can be improved. They currently use a
  5603 // mutex/condvar pair, plus _counter.
  5573  * mutex/condvar pair, plus _counter.
  5604 // Park decrements _counter if > 0, else does a condvar wait.  Unpark
  5574  * Park decrements _counter if > 0, else does a condvar wait.  Unpark
  5605 // sets count to 1 and signals condvar.  Only one thread ever waits
  5575  * sets count to 1 and signals condvar.  Only one thread ever waits
  5606 // on the condvar. Contention seen when trying to park implies that someone
  5576  * on the condvar. Contention seen when trying to park implies that someone
  5607 // is unparking you, so don't wait. And spurious returns are fine, so there
  5577  * is unparking you, so don't wait. And spurious returns are fine, so there
  5608 // is no need to track notifications.
  5578  * is no need to track notifications.
       
  5579  */
       
  5580 
  5609 
  5581 #define MAX_SECS 100000000
  5610 #define MAX_SECS 100000000
  5582 /*
  5611 
  5583  * This code is common to linux and solaris and will be moved to a
  5612 // This code is common to linux and solaris and will be moved to a
  5584  * common place in dolphin.
  5613 // common place in dolphin.
  5585  *
  5614 //
  5586  * The passed in time value is either a relative time in nanoseconds
  5615 // The passed in time value is either a relative time in nanoseconds
  5587  * or an absolute time in milliseconds. Either way it has to be unpacked
  5616 // or an absolute time in milliseconds. Either way it has to be unpacked
  5588  * into suitable seconds and nanoseconds components and stored in the
  5617 // into suitable seconds and nanoseconds components and stored in the
  5589  * given timespec structure.
  5618 // given timespec structure.
  5590  * Given time is a 64-bit value and the time_t used in the timespec is only
  5619 // Given time is a 64-bit value and the time_t used in the timespec is only
  5591  * a signed-32-bit value (except on 64-bit Linux) we have to watch for
  5620 // a signed-32-bit value (except on 64-bit Linux) we have to watch for
  5592  * overflow if times way in the future are given. Further on Solaris versions
  5621 // overflow if times way in the future are given. Further on Solaris versions
  5593  * prior to 10 there is a restriction (see cond_timedwait) that the specified
  5622 // prior to 10 there is a restriction (see cond_timedwait) that the specified
  5594  * number of seconds, in abstime, is less than current_time  + 100,000,000.
  5623 // number of seconds, in abstime, is less than current_time  + 100,000,000.
  5595  * As it will be 28 years before "now + 100000000" will overflow we can
  5624 // As it will be 28 years before "now + 100000000" will overflow we can
  5596  * ignore overflow and just impose a hard-limit on seconds using the value
  5625 // ignore overflow and just impose a hard-limit on seconds using the value
  5597  * of "now + 100,000,000". This places a limit on the timeout of about 3.17
  5626 // of "now + 100,000,000". This places a limit on the timeout of about 3.17
  5598  * years from "now".
  5627 // years from "now".
  5599  */
  5628 //
  5600 static void unpackTime(timespec* absTime, bool isAbsolute, jlong time) {
  5629 static void unpackTime(timespec* absTime, bool isAbsolute, jlong time) {
  5601   assert(time > 0, "convertTime");
  5630   assert(time > 0, "convertTime");
  5602 
  5631 
  5603   struct timeval now;
  5632   struct timeval now;
  5604   int status = gettimeofday(&now, NULL);
  5633   int status = gettimeofday(&now, NULL);
  5608 
  5637 
  5609   if (isAbsolute) {
  5638   if (isAbsolute) {
  5610     jlong secs = time / 1000;
  5639     jlong secs = time / 1000;
  5611     if (secs > max_secs) {
  5640     if (secs > max_secs) {
  5612       absTime->tv_sec = max_secs;
  5641       absTime->tv_sec = max_secs;
  5613     }
  5642     } else {
  5614     else {
       
  5615       absTime->tv_sec = secs;
  5643       absTime->tv_sec = secs;
  5616     }
  5644     }
  5617     absTime->tv_nsec = (time % 1000) * NANOSECS_PER_MILLISEC;
  5645     absTime->tv_nsec = (time % 1000) * NANOSECS_PER_MILLISEC;
  5618   }
  5646   } else {
  5619   else {
       
  5620     jlong secs = time / NANOSECS_PER_SEC;
  5647     jlong secs = time / NANOSECS_PER_SEC;
  5621     if (secs >= MAX_SECS) {
  5648     if (secs >= MAX_SECS) {
  5622       absTime->tv_sec = max_secs;
  5649       absTime->tv_sec = max_secs;
  5623       absTime->tv_nsec = 0;
  5650       absTime->tv_nsec = 0;
  5624     }
  5651     } else {
  5625     else {
       
  5626       absTime->tv_sec = now.tv_sec + secs;
  5652       absTime->tv_sec = now.tv_sec + secs;
  5627       absTime->tv_nsec = (time % NANOSECS_PER_SEC) + now.tv_usec*1000;
  5653       absTime->tv_nsec = (time % NANOSECS_PER_SEC) + now.tv_usec*1000;
  5628       if (absTime->tv_nsec >= NANOSECS_PER_SEC) {
  5654       if (absTime->tv_nsec >= NANOSECS_PER_SEC) {
  5629         absTime->tv_nsec -= NANOSECS_PER_SEC;
  5655         absTime->tv_nsec -= NANOSECS_PER_SEC;
  5630         ++absTime->tv_sec; // note: this must be <= max_secs
  5656         ++absTime->tv_sec; // note: this must be <= max_secs
  5797     int status;
  5823     int status;
  5798 
  5824 
  5799     // Wait for the child process to exit.  This returns immediately if
  5825     // Wait for the child process to exit.  This returns immediately if
  5800     // the child has already exited. */
  5826     // the child has already exited. */
  5801     while (waitpid(pid, &status, 0) < 0) {
  5827     while (waitpid(pid, &status, 0) < 0) {
  5802         switch (errno) {
  5828       switch (errno) {
  5803         case ECHILD: return 0;
  5829       case ECHILD: return 0;
  5804         case EINTR: break;
  5830       case EINTR: break;
  5805         default: return -1;
  5831       default: return -1;
  5806         }
  5832       }
  5807     }
  5833     }
  5808 
  5834 
  5809     if (WIFEXITED(status)) {
  5835     if (WIFEXITED(status)) {
  5810        // The child exited normally; get its exit code.
  5836       // The child exited normally; get its exit code.
  5811        return WEXITSTATUS(status);
  5837       return WEXITSTATUS(status);
  5812     } else if (WIFSIGNALED(status)) {
  5838     } else if (WIFSIGNALED(status)) {
  5813        // The child exited because of a signal
  5839       // The child exited because of a signal
  5814        // The best value to return is 0x80 + signal number,
  5840       // The best value to return is 0x80 + signal number,
  5815        // because that is what all Unix shells do, and because
  5841       // because that is what all Unix shells do, and because
  5816        // it allows callers to distinguish between process exit and
  5842       // it allows callers to distinguish between process exit and
  5817        // process death by signal.
  5843       // process death by signal.
  5818        return 0x80 + WTERMSIG(status);
  5844       return 0x80 + WTERMSIG(status);
  5819     } else {
  5845     } else {
  5820        // Unknown exit code; pass it through
  5846       // Unknown exit code; pass it through
  5821        return status;
  5847       return status;
  5822     }
  5848     }
  5823   }
  5849   }
  5824 }
  5850 }
  5825 
  5851 
  5826 // is_headless_jre()
  5852 // is_headless_jre()
  5830 //
  5856 //
  5831 // Since JDK8 xawt/libmawt.so was moved into the same directory
  5857 // Since JDK8 xawt/libmawt.so was moved into the same directory
  5832 // as libawt.so, and renamed libawt_xawt.so
  5858 // as libawt.so, and renamed libawt_xawt.so
  5833 //
  5859 //
  5834 bool os::is_headless_jre() {
  5860 bool os::is_headless_jre() {
  5835     struct stat statbuf;
  5861   struct stat statbuf;
  5836     char buf[MAXPATHLEN];
  5862   char buf[MAXPATHLEN];
  5837     char libmawtpath[MAXPATHLEN];
  5863   char libmawtpath[MAXPATHLEN];
  5838     const char *xawtstr  = "/xawt/libmawt.so";
  5864   const char *xawtstr  = "/xawt/libmawt.so";
  5839     const char *new_xawtstr = "/libawt_xawt.so";
  5865   const char *new_xawtstr = "/libawt_xawt.so";
  5840     char *p;
  5866   char *p;
  5841 
  5867 
  5842     // Get path to libjvm.so
  5868   // Get path to libjvm.so
  5843     os::jvm_path(buf, sizeof(buf));
  5869   os::jvm_path(buf, sizeof(buf));
  5844 
  5870 
  5845     // Get rid of libjvm.so
  5871   // Get rid of libjvm.so
  5846     p = strrchr(buf, '/');
  5872   p = strrchr(buf, '/');
  5847     if (p == NULL) return false;
  5873   if (p == NULL) {
  5848     else *p = '\0';
  5874     return false;
  5849 
  5875   } else {
  5850     // Get rid of client or server
  5876     *p = '\0';
  5851     p = strrchr(buf, '/');
  5877   }
  5852     if (p == NULL) return false;
  5878 
  5853     else *p = '\0';
  5879   // Get rid of client or server
  5854 
  5880   p = strrchr(buf, '/');
  5855     // check xawt/libmawt.so
  5881   if (p == NULL) {
  5856     strcpy(libmawtpath, buf);
  5882     return false;
  5857     strcat(libmawtpath, xawtstr);
  5883   } else {
  5858     if (::stat(libmawtpath, &statbuf) == 0) return false;
  5884     *p = '\0';
  5859 
  5885   }
  5860     // check libawt_xawt.so
  5886 
  5861     strcpy(libmawtpath, buf);
  5887   // check xawt/libmawt.so
  5862     strcat(libmawtpath, new_xawtstr);
  5888   strcpy(libmawtpath, buf);
  5863     if (::stat(libmawtpath, &statbuf) == 0) return false;
  5889   strcat(libmawtpath, xawtstr);
  5864 
  5890   if (::stat(libmawtpath, &statbuf) == 0) return false;
  5865     return true;
  5891 
       
  5892   // check libawt_xawt.so
       
  5893   strcpy(libmawtpath, buf);
       
  5894   strcat(libmawtpath, new_xawtstr);
       
  5895   if (::stat(libmawtpath, &statbuf) == 0) return false;
       
  5896 
       
  5897   return true;
  5866 }
  5898 }
  5867 
  5899 
  5868 size_t os::write(int fd, const void *buf, unsigned int nBytes) {
  5900 size_t os::write(int fd, const void *buf, unsigned int nBytes) {
  5869   size_t res;
  5901   size_t res;
  5870   assert(((JavaThread*)Thread::current())->thread_state() == _thread_in_native,
  5902   assert(((JavaThread*)Thread::current())->thread_state() == _thread_in_native,
  5871           "Assumed _thread_in_native");
  5903          "Assumed _thread_in_native");
  5872   RESTARTABLE((size_t) ::write(fd, buf, (size_t) nBytes), res);
  5904   RESTARTABLE((size_t) ::write(fd, buf, (size_t) nBytes), res);
  5873   return res;
  5905   return res;
  5874 }
  5906 }
  5875 
  5907 
  5876 int os::close(int fd) {
  5908 int os::close(int fd) {
  5881   return ::close(fd);
  5913   return ::close(fd);
  5882 }
  5914 }
  5883 
  5915 
  5884 int os::recv(int fd, char* buf, size_t nBytes, uint flags) {
  5916 int os::recv(int fd, char* buf, size_t nBytes, uint flags) {
  5885   assert(((JavaThread*)Thread::current())->thread_state() == _thread_in_native,
  5917   assert(((JavaThread*)Thread::current())->thread_state() == _thread_in_native,
  5886           "Assumed _thread_in_native");
  5918          "Assumed _thread_in_native");
  5887   RESTARTABLE_RETURN_INT((int)::recv(fd, buf, nBytes, flags));
  5919   RESTARTABLE_RETURN_INT((int)::recv(fd, buf, nBytes, flags));
  5888 }
  5920 }
  5889 
  5921 
  5890 int os::send(int fd, char* buf, size_t nBytes, uint flags) {
  5922 int os::send(int fd, char* buf, size_t nBytes, uint flags) {
  5891   assert(((JavaThread*)Thread::current())->thread_state() == _thread_in_native,
  5923   assert(((JavaThread*)Thread::current())->thread_state() == _thread_in_native,
  5892           "Assumed _thread_in_native");
  5924          "Assumed _thread_in_native");
  5893   RESTARTABLE_RETURN_INT((int)::send(fd, buf, nBytes, flags));
  5925   RESTARTABLE_RETURN_INT((int)::send(fd, buf, nBytes, flags));
  5894 }
  5926 }
  5895 
  5927 
  5896 int os::raw_send(int fd, char* buf, size_t nBytes, uint flags) {
  5928 int os::raw_send(int fd, char* buf, size_t nBytes, uint flags) {
  5897   RESTARTABLE_RETURN_INT((int)::send(fd, buf, nBytes, flags));
  5929   RESTARTABLE_RETURN_INT((int)::send(fd, buf, nBytes, flags));
  5910   struct pollfd pfd;
  5942   struct pollfd pfd;
  5911   pfd.fd = fd;
  5943   pfd.fd = fd;
  5912   pfd.events = POLLIN;
  5944   pfd.events = POLLIN;
  5913 
  5945 
  5914   assert(((JavaThread*)Thread::current())->thread_state() == _thread_in_native,
  5946   assert(((JavaThread*)Thread::current())->thread_state() == _thread_in_native,
  5915           "Assumed _thread_in_native");
  5947          "Assumed _thread_in_native");
  5916 
  5948 
  5917   gettimeofday(&t, &aNull);
  5949   gettimeofday(&t, &aNull);
  5918   prevtime = ((julong)t.tv_sec * 1000)  +  t.tv_usec / 1000;
  5950   prevtime = ((julong)t.tv_sec * 1000)  +  t.tv_usec / 1000;
  5919 
  5951 
  5920   for (;;) {
  5952   for (;;) {
  5921     res = ::poll(&pfd, 1, timeout);
  5953     res = ::poll(&pfd, 1, timeout);
  5922     if (res == OS_ERR && errno == EINTR) {
  5954     if (res == OS_ERR && errno == EINTR) {
  5923         if (timeout != -1) {
  5955       if (timeout != -1) {
  5924           gettimeofday(&t, &aNull);
  5956         gettimeofday(&t, &aNull);
  5925           newtime = ((julong)t.tv_sec * 1000)  +  t.tv_usec /1000;
  5957         newtime = ((julong)t.tv_sec * 1000)  +  t.tv_usec /1000;
  5926           timeout -= newtime - prevtime;
  5958         timeout -= newtime - prevtime;
  5927           if (timeout <= 0)
  5959         if (timeout <= 0) {
  5928             return OS_OK;
  5960           return OS_OK;
  5929           prevtime = newtime;
       
  5930         }
  5961         }
       
  5962         prevtime = newtime;
       
  5963       }
  5931     } else return res;
  5964     } else return res;
  5932   }
  5965   }
  5933 }
  5966 }
  5934 
  5967 
  5935 int os::connect(int fd, struct sockaddr *him, socklen_t len) {
  5968 int os::connect(int fd, struct sockaddr *him, socklen_t len) {
  5954   //                      connection  attempt  has  not yet been com-
  5987   //                      connection  attempt  has  not yet been com-
  5955   //                      pleted.
  5988   //                      pleted.
  5956   //
  5989   //
  5957   //     EISCONN          The socket is already connected.
  5990   //     EISCONN          The socket is already connected.
  5958   if (_result == OS_ERR && errno == EINTR) {
  5991   if (_result == OS_ERR && errno == EINTR) {
  5959      /* restarting a connect() changes its errno semantics */
  5992     // restarting a connect() changes its errno semantics
  5960      RESTARTABLE(::connect(fd, him, len), _result);
  5993     RESTARTABLE(::connect(fd, him, len), _result);
  5961      /* undo these changes */
  5994     // undo these changes
  5962      if (_result == OS_ERR) {
  5995     if (_result == OS_ERR) {
  5963        if (errno == EALREADY) {
  5996       if (errno == EALREADY) {
  5964          errno = EINPROGRESS; /* fall through */
  5997         errno = EINPROGRESS; // fall through
  5965        } else if (errno == EISCONN) {
  5998       } else if (errno == EISCONN) {
  5966          errno = 0;
  5999         errno = 0;
  5967          return OS_OK;
  6000         return OS_OK;
  5968        }
  6001       }
  5969      }
  6002     }
  5970    }
  6003   }
  5971    return _result;
  6004   return _result;
  5972  }
  6005 }
  5973 
  6006 
  5974 int os::accept(int fd, struct sockaddr* him, socklen_t* len) {
  6007 int os::accept(int fd, struct sockaddr* him, socklen_t* len) {
  5975   if (fd < 0) {
  6008   if (fd < 0) {
  5976     return OS_ERR;
  6009     return OS_ERR;
  5977   }
  6010   }
  5978   assert(((JavaThread*)Thread::current())->thread_state() == _thread_in_native,
  6011   assert(((JavaThread*)Thread::current())->thread_state() == _thread_in_native,
  5979           "Assumed _thread_in_native");
  6012          "Assumed _thread_in_native");
  5980   RESTARTABLE_RETURN_INT((int)::accept(fd, him, len));
  6013   RESTARTABLE_RETURN_INT((int)::accept(fd, him, len));
  5981 }
  6014 }
  5982 
  6015 
  5983 int os::recvfrom(int fd, char* buf, size_t nBytes, uint flags,
  6016 int os::recvfrom(int fd, char* buf, size_t nBytes, uint flags,
  5984                  sockaddr* from, socklen_t* fromlen) {
  6017                  sockaddr* from, socklen_t* fromlen) {
  5985   assert(((JavaThread*)Thread::current())->thread_state() == _thread_in_native,
  6018   assert(((JavaThread*)Thread::current())->thread_state() == _thread_in_native,
  5986           "Assumed _thread_in_native");
  6019          "Assumed _thread_in_native");
  5987   RESTARTABLE_RETURN_INT((int)::recvfrom(fd, buf, nBytes, flags, from, fromlen));
  6020   RESTARTABLE_RETURN_INT((int)::recvfrom(fd, buf, nBytes, flags, from, fromlen));
  5988 }
  6021 }
  5989 
  6022 
  5990 int os::sendto(int fd, char* buf, size_t len, uint flags,
  6023 int os::sendto(int fd, char* buf, size_t len, uint flags,
  5991                struct sockaddr* to, socklen_t tolen) {
  6024                struct sockaddr* to, socklen_t tolen) {
  5992   assert(((JavaThread*)Thread::current())->thread_state() == _thread_in_native,
  6025   assert(((JavaThread*)Thread::current())->thread_state() == _thread_in_native,
  5993           "Assumed _thread_in_native");
  6026          "Assumed _thread_in_native");
  5994   RESTARTABLE_RETURN_INT((int)::sendto(fd, buf, len, flags, to, tolen));
  6027   RESTARTABLE_RETURN_INT((int)::sendto(fd, buf, len, flags, to, tolen));
  5995 }
  6028 }
  5996 
  6029 
  5997 int os::socket_available(int fd, jint *pbytes) {
  6030 int os::socket_available(int fd, jint *pbytes) {
  5998   if (fd < 0) {
  6031   if (fd < 0) {
  6005   return (ret == OS_ERR) ? 0 : 1;
  6038   return (ret == OS_ERR) ? 0 : 1;
  6006 }
  6039 }
  6007 
  6040 
  6008 int os::bind(int fd, struct sockaddr* him, socklen_t len) {
  6041 int os::bind(int fd, struct sockaddr* him, socklen_t len) {
  6009   assert(((JavaThread*)Thread::current())->thread_state() == _thread_in_native,
  6042   assert(((JavaThread*)Thread::current())->thread_state() == _thread_in_native,
  6010           "Assumed _thread_in_native");
  6043          "Assumed _thread_in_native");
  6011    return ::bind(fd, him, len);
  6044   return ::bind(fd, him, len);
  6012 }
  6045 }
  6013 
  6046 
  6014 // Get the default path to the core file
  6047 // Get the default path to the core file
  6015 // Returns the length of the string
  6048 // Returns the length of the string
  6016 int os::get_core_path(char* buffer, size_t bufferSize) {
  6049 int os::get_core_path(char* buffer, size_t bufferSize) {