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 } |
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 |
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; |
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 } |
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}; |
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 } |
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 |
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()); |
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 } |
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) { |
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 } |
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 { |
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)); |
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 } |
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 |
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 } |
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 } |
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 |
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); |
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) { |