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(); |
1086 |
1085 |
1087 // The thread is returned suspended (in state INITIALIZED), and is started higher up in the call chain |
1086 // The thread is returned suspended (in state INITIALIZED), and is started higher up in the call chain |
1088 return true; |
1087 return true; |
1089 } |
1088 } |
1090 |
1089 |
1091 /* defined for >= Solaris 10. This allows builds on earlier versions |
1090 // defined for >= Solaris 10. This allows builds on earlier versions |
1092 * of Solaris to take advantage of the newly reserved Solaris JVM signals |
1091 // of Solaris to take advantage of the newly reserved Solaris JVM signals |
1093 * With SIGJVM1, SIGJVM2, INTERRUPT_SIGNAL is SIGJVM1, ASYNC_SIGNAL is SIGJVM2 |
1092 // With SIGJVM1, SIGJVM2, INTERRUPT_SIGNAL is SIGJVM1, ASYNC_SIGNAL is SIGJVM2 |
1094 * and -XX:+UseAltSigs does nothing since these should have no conflict |
1093 // and -XX:+UseAltSigs does nothing since these should have no conflict |
1095 */ |
1094 // |
1096 #if !defined(SIGJVM1) |
1095 #if !defined(SIGJVM1) |
1097 #define SIGJVM1 39 |
1096 #define SIGJVM1 39 |
1098 #define SIGJVM2 40 |
1097 #define SIGJVM2 40 |
1099 #endif |
1098 #endif |
1100 |
1099 |
1101 debug_only(static bool signal_sets_initialized = false); |
1100 debug_only(static bool signal_sets_initialized = false); |
1102 static sigset_t unblocked_sigs, vm_sigs, allowdebug_blocked_sigs; |
1101 static sigset_t unblocked_sigs, vm_sigs, allowdebug_blocked_sigs; |
1103 int os::Solaris::_SIGinterrupt = INTERRUPT_SIGNAL; |
1102 int os::Solaris::_SIGinterrupt = INTERRUPT_SIGNAL; |
1106 bool os::Solaris::is_sig_ignored(int sig) { |
1105 bool os::Solaris::is_sig_ignored(int sig) { |
1107 struct sigaction oact; |
1106 struct sigaction oact; |
1108 sigaction(sig, (struct sigaction*)NULL, &oact); |
1107 sigaction(sig, (struct sigaction*)NULL, &oact); |
1109 void* ohlr = oact.sa_sigaction ? CAST_FROM_FN_PTR(void*, oact.sa_sigaction) |
1108 void* ohlr = oact.sa_sigaction ? CAST_FROM_FN_PTR(void*, oact.sa_sigaction) |
1110 : CAST_FROM_FN_PTR(void*, oact.sa_handler); |
1109 : CAST_FROM_FN_PTR(void*, oact.sa_handler); |
1111 if (ohlr == CAST_FROM_FN_PTR(void*, SIG_IGN)) |
1110 if (ohlr == CAST_FROM_FN_PTR(void*, SIG_IGN)) { |
1112 return true; |
1111 return true; |
1113 else |
1112 } else { |
1114 return false; |
1113 return false; |
|
1114 } |
1115 } |
1115 } |
1116 |
1116 |
1117 // Note: SIGRTMIN is a macro that calls sysconf() so it will |
1117 // Note: SIGRTMIN is a macro that calls sysconf() so it will |
1118 // dynamically detect SIGRTMIN value for the system at runtime, not buildtime |
1118 // dynamically detect SIGRTMIN value for the system at runtime, not buildtime |
1119 static bool isJVM1available() { |
1119 static bool isJVM1available() { |
1242 stack_size = (size_t)(base - bottom); |
1243 stack_size = (size_t)(base - bottom); |
1243 |
1244 |
1244 assert(stack_size > 0, "Stack size calculation problem"); |
1245 assert(stack_size > 0, "Stack size calculation problem"); |
1245 |
1246 |
1246 if (stack_size > jt->stack_size()) { |
1247 if (stack_size > jt->stack_size()) { |
1247 NOT_PRODUCT( |
1248 #ifndef PRODUCT |
1248 struct rlimit limits; |
1249 struct rlimit limits; |
1249 getrlimit(RLIMIT_STACK, &limits); |
1250 getrlimit(RLIMIT_STACK, &limits); |
1250 size_t size = adjust_stack_size(base, (size_t)limits.rlim_cur); |
1251 size_t size = adjust_stack_size(base, (size_t)limits.rlim_cur); |
1251 assert(size >= jt->stack_size(), "Stack size problem in main thread"); |
1252 assert(size >= jt->stack_size(), "Stack size problem in main thread"); |
1252 ) |
1253 #endif |
1253 tty->print_cr( |
1254 tty->print_cr("Stack size of %d Kb exceeds current limit of %d Kb.\n" |
1254 "Stack size of %d Kb exceeds current limit of %d Kb.\n" |
|
1255 "(Stack sizes are rounded up to a multiple of the system page size.)\n" |
1255 "(Stack sizes are rounded up to a multiple of the system page size.)\n" |
1256 "See limit(1) to increase the stack size limit.", |
1256 "See limit(1) to increase the stack size limit.", |
1257 stack_size / K, jt->stack_size() / K); |
1257 stack_size / K, jt->stack_size() / K); |
1258 vm_exit(1); |
1258 vm_exit(1); |
1259 } |
1259 } |
1323 // interface. I think, however, that it will be faster to |
1323 // interface. I think, however, that it will be faster to |
1324 // maintain the invariant that %g2 always contains the |
1324 // maintain the invariant that %g2 always contains the |
1325 // JavaThread in Java code, and have stubs simply |
1325 // JavaThread in Java code, and have stubs simply |
1326 // treat %g2 as a caller-save register, preserving it in a %lN. |
1326 // treat %g2 as a caller-save register, preserving it in a %lN. |
1327 thread_key_t tk; |
1327 thread_key_t tk; |
1328 if (thr_keycreate( &tk, NULL)) |
1328 if (thr_keycreate(&tk, NULL)) { |
1329 fatal(err_msg("os::allocate_thread_local_storage: thr_keycreate failed " |
1329 fatal(err_msg("os::allocate_thread_local_storage: thr_keycreate failed " |
1330 "(%s)", strerror(errno))); |
1330 "(%s)", strerror(errno))); |
|
1331 } |
1331 return int(tk); |
1332 return int(tk); |
1332 } |
1333 } |
1333 |
1334 |
1334 void os::free_thread_local_storage(int index) { |
1335 void os::free_thread_local_storage(int index) { |
1335 // %%% don't think we need anything here |
1336 // %%% don't think we need anything here |
1336 // if ( pthread_key_delete((pthread_key_t) tk) ) |
1337 // if (pthread_key_delete((pthread_key_t) tk)) { |
1337 // fatal("os::free_thread_local_storage: pthread_key_delete failed"); |
1338 // fatal("os::free_thread_local_storage: pthread_key_delete failed"); |
1338 } |
1339 // } |
1339 |
1340 } |
1340 #define SMALLINT 32 // libthread allocate for tsd_common is a version specific |
1341 |
|
1342 // libthread allocate for tsd_common is a version specific |
1341 // small number - point is NO swap space available |
1343 // small number - point is NO swap space available |
|
1344 #define SMALLINT 32 |
1342 void os::thread_local_storage_at_put(int index, void* value) { |
1345 void os::thread_local_storage_at_put(int index, void* value) { |
1343 // %%% this is used only in threadLocalStorage.cpp |
1346 // %%% this is used only in threadLocalStorage.cpp |
1344 if (thr_setspecific((thread_key_t)index, value)) { |
1347 if (thr_setspecific((thread_key_t)index, value)) { |
1345 if (errno == ENOMEM) { |
1348 if (errno == ENOMEM) { |
1346 vm_exit_out_of_memory(SMALLINT, OOM_MALLOC_ERROR, |
1349 vm_exit_out_of_memory(SMALLINT, OOM_MALLOC_ERROR, |
1429 |
1432 |
1430 bool os::supports_vtime() { return true; } |
1433 bool os::supports_vtime() { return true; } |
1431 |
1434 |
1432 bool os::enable_vtime() { |
1435 bool os::enable_vtime() { |
1433 int fd = ::open("/proc/self/ctl", O_WRONLY); |
1436 int fd = ::open("/proc/self/ctl", O_WRONLY); |
1434 if (fd == -1) |
1437 if (fd == -1) { |
1435 return false; |
1438 return false; |
|
1439 } |
1436 |
1440 |
1437 long cmd[] = { PCSET, PR_MSACCT }; |
1441 long cmd[] = { PCSET, PR_MSACCT }; |
1438 int res = ::write(fd, cmd, sizeof(long) * 2); |
1442 int res = ::write(fd, cmd, sizeof(long) * 2); |
1439 ::close(fd); |
1443 ::close(fd); |
1440 if (res != sizeof(long) * 2) |
1444 if (res != sizeof(long) * 2) { |
1441 return false; |
1445 return false; |
1442 |
1446 } |
1443 return true; |
1447 return true; |
1444 } |
1448 } |
1445 |
1449 |
1446 bool os::vtime_enabled() { |
1450 bool os::vtime_enabled() { |
1447 int fd = ::open("/proc/self/status", O_RDONLY); |
1451 int fd = ::open("/proc/self/status", O_RDONLY); |
1448 if (fd == -1) |
1452 if (fd == -1) { |
1449 return false; |
1453 return false; |
|
1454 } |
1450 |
1455 |
1451 pstatus_t status; |
1456 pstatus_t status; |
1452 int res = os::read(fd, (void*) &status, sizeof(pstatus_t)); |
1457 int res = os::read(fd, (void*) &status, sizeof(pstatus_t)); |
1453 ::close(fd); |
1458 ::close(fd); |
1454 if (res != sizeof(pstatus_t)) |
1459 if (res != sizeof(pstatus_t)) { |
1455 return false; |
1460 return false; |
1456 |
1461 } |
1457 return status.pr_flags & PR_MSACCT; |
1462 return status.pr_flags & PR_MSACCT; |
1458 } |
1463 } |
1459 |
1464 |
1460 double os::elapsedVTime() { |
1465 double os::elapsedVTime() { |
1461 return (double)gethrvtime() / (double)hrtime_hz; |
1466 return (double)gethrvtime() / (double)hrtime_hz; |
1822 {EM_PPC, EM_PPC, ELFCLASS32, ELFDATA2MSB, (char*)"Power PC 32"}, |
1827 {EM_PPC, EM_PPC, ELFCLASS32, ELFDATA2MSB, (char*)"Power PC 32"}, |
1823 {EM_PPC64, EM_PPC64, ELFCLASS64, ELFDATA2MSB, (char*)"Power PC 64"}, |
1828 {EM_PPC64, EM_PPC64, ELFCLASS64, ELFDATA2MSB, (char*)"Power PC 64"}, |
1824 {EM_ARM, EM_ARM, ELFCLASS32, ELFDATA2LSB, (char*)"ARM 32"} |
1829 {EM_ARM, EM_ARM, ELFCLASS32, ELFDATA2LSB, (char*)"ARM 32"} |
1825 }; |
1830 }; |
1826 |
1831 |
1827 #if (defined IA32) |
1832 #if (defined IA32) |
1828 static Elf32_Half running_arch_code=EM_386; |
1833 static Elf32_Half running_arch_code=EM_386; |
1829 #elif (defined AMD64) |
1834 #elif (defined AMD64) |
1830 static Elf32_Half running_arch_code=EM_X86_64; |
1835 static Elf32_Half running_arch_code=EM_X86_64; |
1831 #elif (defined IA64) |
1836 #elif (defined IA64) |
1832 static Elf32_Half running_arch_code=EM_IA_64; |
1837 static Elf32_Half running_arch_code=EM_IA_64; |
1833 #elif (defined __sparc) && (defined _LP64) |
1838 #elif (defined __sparc) && (defined _LP64) |
1834 static Elf32_Half running_arch_code=EM_SPARCV9; |
1839 static Elf32_Half running_arch_code=EM_SPARCV9; |
1835 #elif (defined __sparc) && (!defined _LP64) |
1840 #elif (defined __sparc) && (!defined _LP64) |
1836 static Elf32_Half running_arch_code=EM_SPARC; |
1841 static Elf32_Half running_arch_code=EM_SPARC; |
1837 #elif (defined __powerpc64__) |
1842 #elif (defined __powerpc64__) |
1838 static Elf32_Half running_arch_code=EM_PPC64; |
1843 static Elf32_Half running_arch_code=EM_PPC64; |
1839 #elif (defined __powerpc__) |
1844 #elif (defined __powerpc__) |
1840 static Elf32_Half running_arch_code=EM_PPC; |
1845 static Elf32_Half running_arch_code=EM_PPC; |
1841 #elif (defined ARM) |
1846 #elif (defined ARM) |
1842 static Elf32_Half running_arch_code=EM_ARM; |
1847 static Elf32_Half running_arch_code=EM_ARM; |
1843 #else |
1848 #else |
1844 #error Method os::dll_load requires that one of following is defined:\ |
1849 #error Method os::dll_load requires that one of following is defined:\ |
1845 IA32, AMD64, IA64, __sparc, __powerpc__, ARM, ARM |
1850 IA32, AMD64, IA64, __sparc, __powerpc__, ARM, ARM |
1846 #endif |
1851 #endif |
1847 |
1852 |
1848 // Identify compatability class for VM's architecture and library's architecture |
1853 // Identify compatability class for VM's architecture and library's architecture |
1849 // Obtain string descriptions for architectures |
1854 // Obtain string descriptions for architectures |
1850 |
1855 |
1851 arch_t lib_arch={elf_head.e_machine,0,elf_head.e_ident[EI_CLASS], elf_head.e_ident[EI_DATA], NULL}; |
1856 arch_t lib_arch={elf_head.e_machine,0,elf_head.e_ident[EI_CLASS], elf_head.e_ident[EI_DATA], NULL}; |
2312 struct sigaction sigAct, oldSigAct; |
2316 struct sigaction sigAct, oldSigAct; |
2313 sigfillset(&(sigAct.sa_mask)); |
2317 sigfillset(&(sigAct.sa_mask)); |
2314 sigAct.sa_flags = SA_RESTART & ~SA_RESETHAND; |
2318 sigAct.sa_flags = SA_RESTART & ~SA_RESETHAND; |
2315 sigAct.sa_handler = CAST_TO_FN_PTR(sa_handler_t, handler); |
2319 sigAct.sa_handler = CAST_TO_FN_PTR(sa_handler_t, handler); |
2316 |
2320 |
2317 if (sigaction(signal_number, &sigAct, &oldSigAct)) |
2321 if (sigaction(signal_number, &sigAct, &oldSigAct)) { |
2318 // -1 means registration failed |
2322 // -1 means registration failed |
2319 return (void *)-1; |
2323 return (void *)-1; |
|
2324 } |
2320 |
2325 |
2321 return CAST_FROM_FN_PTR(void*, oldSigAct.sa_handler); |
2326 return CAST_FROM_FN_PTR(void*, oldSigAct.sa_handler); |
2322 } |
2327 } |
2323 |
2328 |
2324 void os::signal_raise(int signal_number) { |
2329 void os::signal_raise(int signal_number) { |
2325 raise(signal_number); |
2330 raise(signal_number); |
2326 } |
2331 } |
2327 |
2332 |
2328 /* |
2333 // The following code is moved from os.cpp for making this |
2329 * The following code is moved from os.cpp for making this |
2334 // code platform specific, which it is by its very nature. |
2330 * code platform specific, which it is by its very nature. |
|
2331 */ |
|
2332 |
2335 |
2333 // a counter for each possible signal value |
2336 // a counter for each possible signal value |
2334 static int Sigexit = 0; |
2337 static int Sigexit = 0; |
2335 static int Maxlibjsigsigs; |
2338 static int Maxlibjsigsigs; |
2336 static jint *pending_signals = NULL; |
2339 static jint *pending_signals = NULL; |
2364 * (Maxsignum + 1), mtInternal); |
2367 * (Maxsignum + 1), mtInternal); |
2365 memset(chainedsigactions, 0, (sizeof(struct sigaction) * (Maxsignum + 1))); |
2368 memset(chainedsigactions, 0, (sizeof(struct sigaction) * (Maxsignum + 1))); |
2366 preinstalled_sigs = (int *)os::malloc(sizeof(int) * (Maxsignum + 1), mtInternal); |
2369 preinstalled_sigs = (int *)os::malloc(sizeof(int) * (Maxsignum + 1), mtInternal); |
2367 memset(preinstalled_sigs, 0, (sizeof(int) * (Maxsignum + 1))); |
2370 memset(preinstalled_sigs, 0, (sizeof(int) * (Maxsignum + 1))); |
2368 } |
2371 } |
2369 ourSigFlags = (int*)malloc(sizeof(int) * (Maxsignum + 1 ), mtInternal); |
2372 ourSigFlags = (int*)malloc(sizeof(int) * (Maxsignum + 1), mtInternal); |
2370 memset(ourSigFlags, 0, sizeof(int) * (Maxsignum + 1)); |
2373 memset(ourSigFlags, 0, sizeof(int) * (Maxsignum + 1)); |
2371 } |
2374 } |
2372 |
2375 |
2373 void os::signal_init_pd() { |
2376 void os::signal_init_pd() { |
2374 int ret; |
2377 int ret; |
2409 assert(ret == 0, "sema_wait() failed"); |
2412 assert(ret == 0, "sema_wait() failed"); |
2410 |
2413 |
2411 // were we externally suspended while we were waiting? |
2414 // were we externally suspended while we were waiting? |
2412 threadIsSuspended = thread->handle_special_suspend_equivalent_condition(); |
2415 threadIsSuspended = thread->handle_special_suspend_equivalent_condition(); |
2413 if (threadIsSuspended) { |
2416 if (threadIsSuspended) { |
2414 // |
|
2415 // The semaphore has been incremented, but while we were waiting |
2417 // The semaphore has been incremented, but while we were waiting |
2416 // another thread suspended us. We don't want to continue running |
2418 // another thread suspended us. We don't want to continue running |
2417 // while suspended because that would surprise the thread that |
2419 // while suspended because that would surprise the thread that |
2418 // suspended us. |
2420 // suspended us. |
2419 // |
|
2420 ret = ::sema_post(&sig_sem); |
2421 ret = ::sema_post(&sig_sem); |
2421 assert(ret == 0, "sema_post() failed"); |
2422 assert(ret == 0, "sema_post() failed"); |
2422 |
2423 |
2423 thread->java_suspend_self(); |
2424 thread->java_suspend_self(); |
2424 } |
2425 } |
2812 // uncommitted page. Otherwise, the read/write might succeed if we |
2815 // uncommitted page. Otherwise, the read/write might succeed if we |
2813 // have enough swap space to back the physical page. |
2816 // have enough swap space to back the physical page. |
2814 return mmap_chunk(addr, bytes, flags, PROT_NONE); |
2817 return mmap_chunk(addr, bytes, flags, PROT_NONE); |
2815 } |
2818 } |
2816 |
2819 |
2817 char* os::pd_reserve_memory(size_t bytes, char* requested_addr, size_t alignment_hint) { |
2820 char* os::pd_reserve_memory(size_t bytes, char* requested_addr, |
2818 char* addr = Solaris::anon_mmap(requested_addr, bytes, alignment_hint, (requested_addr != NULL)); |
2821 size_t alignment_hint) { |
|
2822 char* addr = Solaris::anon_mmap(requested_addr, bytes, alignment_hint, |
|
2823 (requested_addr != NULL)); |
2819 |
2824 |
2820 guarantee(requested_addr == NULL || requested_addr == addr, |
2825 guarantee(requested_addr == NULL || requested_addr == addr, |
2821 "OS failed to return requested mmap address."); |
2826 "OS failed to return requested mmap address."); |
2822 return addr; |
2827 return addr; |
2823 } |
2828 } |
3868 } |
3876 } |
3869 |
3877 |
3870 |
3878 |
3871 // This does not do anything on Solaris. This is basically a hook for being |
3879 // This does not do anything on Solaris. This is basically a hook for being |
3872 // able to use structured exception handling (thread-local exception filters) on, e.g., Win32. |
3880 // able to use structured exception handling (thread-local exception filters) on, e.g., Win32. |
3873 void os::os_exception_wrapper(java_call_t f, JavaValue* value, methodHandle* method, JavaCallArguments* args, Thread* thread) { |
3881 void os::os_exception_wrapper(java_call_t f, JavaValue* value, |
|
3882 methodHandle* method, JavaCallArguments* args, |
|
3883 Thread* thread) { |
3874 f(value, method, args, thread); |
3884 f(value, method, args, thread); |
3875 } |
3885 } |
3876 |
3886 |
3877 // This routine may be used by user applications as a "hook" to catch signals. |
3887 // This routine may be used by user applications as a "hook" to catch signals. |
3878 // The user-defined signal handler must pass unrecognized signals to this |
3888 // The user-defined signal handler must pass unrecognized signals to this |
3899 // the sa_flags field passed to sigaction() includes SA_SIGINFO and SA_RESTART. |
3909 // the sa_flags field passed to sigaction() includes SA_SIGINFO and SA_RESTART. |
3900 // |
3910 // |
3901 // Note that the VM will print warnings if it detects conflicting signal |
3911 // Note that the VM will print warnings if it detects conflicting signal |
3902 // handlers, unless invoked with the option "-XX:+AllowUserSignalHandlers". |
3912 // handlers, unless invoked with the option "-XX:+AllowUserSignalHandlers". |
3903 // |
3913 // |
3904 extern "C" JNIEXPORT int |
3914 extern "C" JNIEXPORT int JVM_handle_solaris_signal(int signo, |
3905 JVM_handle_solaris_signal(int signo, siginfo_t* siginfo, void* ucontext, |
3915 siginfo_t* siginfo, |
3906 int abort_if_unrecognized); |
3916 void* ucontext, |
|
3917 int abort_if_unrecognized); |
3907 |
3918 |
3908 |
3919 |
3909 void signalHandler(int sig, siginfo_t* info, void* ucVoid) { |
3920 void signalHandler(int sig, siginfo_t* info, void* ucVoid) { |
3910 int orig_errno = errno; // Preserve errno value over signal handler. |
3921 int orig_errno = errno; // Preserve errno value over signal handler. |
3911 JVM_handle_solaris_signal(sig, info, ucVoid, true); |
3922 JVM_handle_solaris_signal(sig, info, ucVoid, true); |
3912 errno = orig_errno; |
3923 errno = orig_errno; |
3913 } |
3924 } |
3914 |
3925 |
3915 /* Do not delete - if guarantee is ever removed, a signal handler (even empty) |
3926 // Do not delete - if guarantee is ever removed, a signal handler (even empty) |
3916 is needed to provoke threads blocked on IO to return an EINTR |
3927 // is needed to provoke threads blocked on IO to return an EINTR |
3917 Note: this explicitly does NOT call JVM_handle_solaris_signal and |
3928 // Note: this explicitly does NOT call JVM_handle_solaris_signal and |
3918 does NOT participate in signal chaining due to requirement for |
3929 // does NOT participate in signal chaining due to requirement for |
3919 NOT setting SA_RESTART to make EINTR work. */ |
3930 // NOT setting SA_RESTART to make EINTR work. |
3920 extern "C" void sigINTRHandler(int sig, siginfo_t* info, void* ucVoid) { |
3931 extern "C" void sigINTRHandler(int sig, siginfo_t* info, void* ucVoid) { |
3921 if (UseSignalChaining) { |
3932 if (UseSignalChaining) { |
3922 struct sigaction *actp = os::Solaris::get_chained_signal_action(sig); |
3933 struct sigaction *actp = os::Solaris::get_chained_signal_action(sig); |
3923 if (actp && actp->sa_handler) { |
3934 if (actp && actp->sa_handler) { |
3924 vm_exit_during_initialization("Signal chaining detected for VM interrupt signal, try -XX:+UseAltSigs"); |
3935 vm_exit_during_initialization("Signal chaining detected for VM interrupt signal, try -XX:+UseAltSigs"); |
4006 } |
4017 } |
4007 return chained; |
4018 return chained; |
4008 } |
4019 } |
4009 |
4020 |
4010 struct sigaction* os::Solaris::get_preinstalled_handler(int sig) { |
4021 struct sigaction* os::Solaris::get_preinstalled_handler(int sig) { |
4011 assert((chainedsigactions != (struct sigaction *)NULL) && (preinstalled_sigs != (int *)NULL) , "signals not yet initialized"); |
4022 assert((chainedsigactions != (struct sigaction *)NULL) && |
|
4023 (preinstalled_sigs != (int *)NULL), "signals not yet initialized"); |
4012 if (preinstalled_sigs[sig] != 0) { |
4024 if (preinstalled_sigs[sig] != 0) { |
4013 return &chainedsigactions[sig]; |
4025 return &chainedsigactions[sig]; |
4014 } |
4026 } |
4015 return NULL; |
4027 return NULL; |
4016 } |
4028 } |
4017 |
4029 |
4018 void os::Solaris::save_preinstalled_handler(int sig, struct sigaction& oldAct) { |
4030 void os::Solaris::save_preinstalled_handler(int sig, |
4019 |
4031 struct sigaction& oldAct) { |
4020 assert(sig > 0 && sig <= Maxsignum, "vm signal out of expected range"); |
4032 assert(sig > 0 && sig <= Maxsignum, "vm signal out of expected range"); |
4021 assert((chainedsigactions != (struct sigaction *)NULL) && (preinstalled_sigs != (int *)NULL) , "signals not yet initialized"); |
4033 assert((chainedsigactions != (struct sigaction *)NULL) && |
|
4034 (preinstalled_sigs != (int *)NULL), "signals not yet initialized"); |
4022 chainedsigactions[sig] = oldAct; |
4035 chainedsigactions[sig] = oldAct; |
4023 preinstalled_sigs[sig] = 1; |
4036 preinstalled_sigs[sig] = 1; |
4024 } |
4037 } |
4025 |
4038 |
4026 void os::Solaris::set_signal_handler(int sig, bool set_installed, bool oktochain) { |
4039 void os::Solaris::set_signal_handler(int sig, bool set_installed, |
|
4040 bool oktochain) { |
4027 // Check for overwrite. |
4041 // Check for overwrite. |
4028 struct sigaction oldAct; |
4042 struct sigaction oldAct; |
4029 sigaction(sig, (struct sigaction*)NULL, &oldAct); |
4043 sigaction(sig, (struct sigaction*)NULL, &oldAct); |
4030 void* oldhand = oldAct.sa_sigaction ? CAST_FROM_FN_PTR(void*, oldAct.sa_sigaction) |
4044 void* oldhand = |
4031 : CAST_FROM_FN_PTR(void*, oldAct.sa_handler); |
4045 oldAct.sa_sigaction ? CAST_FROM_FN_PTR(void*, oldAct.sa_sigaction) |
|
4046 : CAST_FROM_FN_PTR(void*, oldAct.sa_handler); |
4032 if (oldhand != CAST_FROM_FN_PTR(void*, SIG_DFL) && |
4047 if (oldhand != CAST_FROM_FN_PTR(void*, SIG_DFL) && |
4033 oldhand != CAST_FROM_FN_PTR(void*, SIG_IGN) && |
4048 oldhand != CAST_FROM_FN_PTR(void*, SIG_IGN) && |
4034 oldhand != CAST_FROM_FN_PTR(void*, signalHandler)) { |
4049 oldhand != CAST_FROM_FN_PTR(void*, signalHandler)) { |
4035 if (AllowUserSignalHandlers || !set_installed) { |
4050 if (AllowUserSignalHandlers || !set_installed) { |
4036 // Do not overwrite; user takes responsibility to forward to us. |
4051 // Do not overwrite; user takes responsibility to forward to us. |
4057 sigAct.sa_sigaction = signalHandler; |
4072 sigAct.sa_sigaction = signalHandler; |
4058 // Handle SIGSEGV on alternate signal stack if |
4073 // Handle SIGSEGV on alternate signal stack if |
4059 // not using stack banging |
4074 // not using stack banging |
4060 if (!UseStackBanging && sig == SIGSEGV) { |
4075 if (!UseStackBanging && sig == SIGSEGV) { |
4061 sigAct.sa_flags = SA_SIGINFO | SA_RESTART | SA_ONSTACK; |
4076 sigAct.sa_flags = SA_SIGINFO | SA_RESTART | SA_ONSTACK; |
|
4077 } else if (sig == os::Solaris::SIGinterrupt()) { |
4062 // Interruptible i/o requires SA_RESTART cleared so EINTR |
4078 // Interruptible i/o requires SA_RESTART cleared so EINTR |
4063 // is returned instead of restarting system calls |
4079 // is returned instead of restarting system calls |
4064 } else if (sig == os::Solaris::SIGinterrupt()) { |
|
4065 sigemptyset(&sigAct.sa_mask); |
4080 sigemptyset(&sigAct.sa_mask); |
4066 sigAct.sa_handler = NULL; |
4081 sigAct.sa_handler = NULL; |
4067 sigAct.sa_flags = SA_SIGINFO; |
4082 sigAct.sa_flags = SA_SIGINFO; |
4068 sigAct.sa_sigaction = sigINTRHandler; |
4083 sigAct.sa_sigaction = sigINTRHandler; |
4069 } else { |
4084 } else { |
4405 os::Solaris::set_cond_wait(CAST_TO_FN_PTR(int_fnP_cond_tP_mutex_tP, resolve_symbol("pthread_cond_wait"))); |
4423 os::Solaris::set_cond_wait(CAST_TO_FN_PTR(int_fnP_cond_tP_mutex_tP, resolve_symbol("pthread_cond_wait"))); |
4406 os::Solaris::set_cond_signal(CAST_TO_FN_PTR(int_fnP_cond_tP, resolve_symbol("pthread_cond_signal"))); |
4424 os::Solaris::set_cond_signal(CAST_TO_FN_PTR(int_fnP_cond_tP, resolve_symbol("pthread_cond_signal"))); |
4407 os::Solaris::set_cond_broadcast(CAST_TO_FN_PTR(int_fnP_cond_tP, resolve_symbol("pthread_cond_broadcast"))); |
4425 os::Solaris::set_cond_broadcast(CAST_TO_FN_PTR(int_fnP_cond_tP, resolve_symbol("pthread_cond_broadcast"))); |
4408 os::Solaris::set_cond_init(pthread_cond_default_init); |
4426 os::Solaris::set_cond_init(pthread_cond_default_init); |
4409 os::Solaris::set_cond_destroy(CAST_TO_FN_PTR(int_fnP_cond_tP, resolve_symbol("pthread_cond_destroy"))); |
4427 os::Solaris::set_cond_destroy(CAST_TO_FN_PTR(int_fnP_cond_tP, resolve_symbol("pthread_cond_destroy"))); |
4410 } |
4428 } else { |
4411 else { |
|
4412 os::Solaris::set_mutex_lock(CAST_TO_FN_PTR(int_fnP_mutex_tP, resolve_symbol("mutex_lock"))); |
4429 os::Solaris::set_mutex_lock(CAST_TO_FN_PTR(int_fnP_mutex_tP, resolve_symbol("mutex_lock"))); |
4413 os::Solaris::set_mutex_trylock(CAST_TO_FN_PTR(int_fnP_mutex_tP, resolve_symbol("mutex_trylock"))); |
4430 os::Solaris::set_mutex_trylock(CAST_TO_FN_PTR(int_fnP_mutex_tP, resolve_symbol("mutex_trylock"))); |
4414 os::Solaris::set_mutex_unlock(CAST_TO_FN_PTR(int_fnP_mutex_tP, resolve_symbol("mutex_unlock"))); |
4431 os::Solaris::set_mutex_unlock(CAST_TO_FN_PTR(int_fnP_mutex_tP, resolve_symbol("mutex_unlock"))); |
4415 os::Solaris::set_mutex_init(::mutex_init); |
4432 os::Solaris::set_mutex_init(::mutex_init); |
4416 os::Solaris::set_mutex_destroy(::mutex_destroy); |
4433 os::Solaris::set_mutex_destroy(::mutex_destroy); |
4515 // check if dladdr1() exists; dladdr1 can provide more information than |
4533 // check if dladdr1() exists; dladdr1 can provide more information than |
4516 // dladdr for os::dll_address_to_function_name. It comes with SunOS 5.9 |
4534 // dladdr for os::dll_address_to_function_name. It comes with SunOS 5.9 |
4517 // and is available on linker patches for 5.7 and 5.8. |
4535 // and is available on linker patches for 5.7 and 5.8. |
4518 // libdl.so must have been loaded, this call is just an entry lookup |
4536 // libdl.so must have been loaded, this call is just an entry lookup |
4519 void * hdl = dlopen("libdl.so", RTLD_NOW); |
4537 void * hdl = dlopen("libdl.so", RTLD_NOW); |
4520 if (hdl) |
4538 if (hdl) { |
4521 dladdr1_func = CAST_TO_FN_PTR(dladdr1_func_type, dlsym(hdl, "dladdr1")); |
4539 dladdr1_func = CAST_TO_FN_PTR(dladdr1_func_type, dlsym(hdl, "dladdr1")); |
|
4540 } |
4522 |
4541 |
4523 // (Solaris only) this switches to calls that actually do locking. |
4542 // (Solaris only) this switches to calls that actually do locking. |
4524 ThreadCritical::initialize(); |
4543 ThreadCritical::initialize(); |
4525 |
4544 |
4526 main_thread = thr_self(); |
4545 main_thread = thr_self(); |
4564 } |
4583 } |
4565 |
4584 |
4566 os::set_polling_page(polling_page); |
4585 os::set_polling_page(polling_page); |
4567 |
4586 |
4568 #ifndef PRODUCT |
4587 #ifndef PRODUCT |
4569 if (Verbose && PrintMiscellaneous) |
4588 if (Verbose && PrintMiscellaneous) { |
4570 tty->print("[SafePoint Polling address: " INTPTR_FORMAT "]\n", (intptr_t)polling_page); |
4589 tty->print("[SafePoint Polling address: " INTPTR_FORMAT "]\n", |
|
4590 (intptr_t)polling_page); |
|
4591 } |
4571 #endif |
4592 #endif |
4572 |
4593 |
4573 if (!UseMembar) { |
4594 if (!UseMembar) { |
4574 address mem_serialize_page = (address)Solaris::mmap_chunk(NULL, page_size, MAP_PRIVATE, PROT_READ | PROT_WRITE); |
4595 address mem_serialize_page = (address)Solaris::mmap_chunk(NULL, page_size, MAP_PRIVATE, PROT_READ | PROT_WRITE); |
4575 guarantee(mem_serialize_page != NULL, "mmap Failed for memory serialize page"); |
4596 guarantee(mem_serialize_page != NULL, "mmap Failed for memory serialize page"); |
4576 os::set_memory_serialize_page(mem_serialize_page); |
4597 os::set_memory_serialize_page(mem_serialize_page); |
4577 |
4598 |
4578 #ifndef PRODUCT |
4599 #ifndef PRODUCT |
4579 if (Verbose && PrintMiscellaneous) |
4600 if (Verbose && PrintMiscellaneous) { |
4580 tty->print("[Memory Serialize Page address: " INTPTR_FORMAT "]\n", (intptr_t)mem_serialize_page); |
4601 tty->print("[Memory Serialize Page address: " INTPTR_FORMAT "]\n", |
|
4602 (intptr_t)mem_serialize_page); |
|
4603 } |
4581 #endif |
4604 #endif |
4582 } |
4605 } |
4583 |
4606 |
4584 // Check minimum allowable stack size for thread creation and to initialize |
4607 // Check minimum allowable stack size for thread creation and to initialize |
4585 // the java system classes, including StackOverflowError - depends on page |
4608 // the java system classes, including StackOverflowError - depends on page |
4654 // set the number of file descriptors to max. print out error |
4677 // set the number of file descriptors to max. print out error |
4655 // if getrlimit/setrlimit fails but continue regardless. |
4678 // if getrlimit/setrlimit fails but continue regardless. |
4656 struct rlimit nbr_files; |
4679 struct rlimit nbr_files; |
4657 int status = getrlimit(RLIMIT_NOFILE, &nbr_files); |
4680 int status = getrlimit(RLIMIT_NOFILE, &nbr_files); |
4658 if (status != 0) { |
4681 if (status != 0) { |
4659 if (PrintMiscellaneous && (Verbose || WizardMode)) |
4682 if (PrintMiscellaneous && (Verbose || WizardMode)) { |
4660 perror("os::init_2 getrlimit failed"); |
4683 perror("os::init_2 getrlimit failed"); |
|
4684 } |
4661 } else { |
4685 } else { |
4662 nbr_files.rlim_cur = nbr_files.rlim_max; |
4686 nbr_files.rlim_cur = nbr_files.rlim_max; |
4663 status = setrlimit(RLIMIT_NOFILE, &nbr_files); |
4687 status = setrlimit(RLIMIT_NOFILE, &nbr_files); |
4664 if (status != 0) { |
4688 if (status != 0) { |
4665 if (PrintMiscellaneous && (Verbose || WizardMode)) |
4689 if (PrintMiscellaneous && (Verbose || WizardMode)) { |
4666 perror("os::init_2 setrlimit failed"); |
4690 perror("os::init_2 setrlimit failed"); |
|
4691 } |
4667 } |
4692 } |
4668 } |
4693 } |
4669 } |
4694 } |
4670 |
4695 |
4671 // Calculate theoretical max. size of Threads to guard gainst |
4696 // Calculate theoretical max. size of Threads to guard gainst |
4734 |
4761 |
4735 int local_vsnprintf(char* buf, size_t count, const char* fmt, va_list argptr) { |
4762 int local_vsnprintf(char* buf, size_t count, const char* fmt, va_list argptr) { |
4736 if (!sol_vsnprintf) { |
4763 if (!sol_vsnprintf) { |
4737 //search for the named symbol in the objects that were loaded after libjvm |
4764 //search for the named symbol in the objects that were loaded after libjvm |
4738 void* where = RTLD_NEXT; |
4765 void* where = RTLD_NEXT; |
4739 if ((sol_vsnprintf = CAST_TO_FN_PTR(vsnprintf_t, dlsym(where, "__vsnprintf"))) == NULL) |
4766 if ((sol_vsnprintf = CAST_TO_FN_PTR(vsnprintf_t, dlsym(where, "__vsnprintf"))) == NULL) { |
4740 sol_vsnprintf = CAST_TO_FN_PTR(vsnprintf_t, dlsym(where, "vsnprintf")); |
4767 sol_vsnprintf = CAST_TO_FN_PTR(vsnprintf_t, dlsym(where, "vsnprintf")); |
|
4768 } |
4741 if (!sol_vsnprintf){ |
4769 if (!sol_vsnprintf){ |
4742 //search for the named symbol in the objects that were loaded before libjvm |
4770 //search for the named symbol in the objects that were loaded before libjvm |
4743 where = RTLD_DEFAULT; |
4771 where = RTLD_DEFAULT; |
4744 if ((sol_vsnprintf = CAST_TO_FN_PTR(vsnprintf_t, dlsym(where, "__vsnprintf"))) == NULL) |
4772 if ((sol_vsnprintf = CAST_TO_FN_PTR(vsnprintf_t, dlsym(where, "__vsnprintf"))) == NULL) { |
4745 sol_vsnprintf = CAST_TO_FN_PTR(vsnprintf_t, dlsym(where, "vsnprintf")); |
4773 sol_vsnprintf = CAST_TO_FN_PTR(vsnprintf_t, dlsym(where, "vsnprintf")); |
|
4774 } |
4746 assert(sol_vsnprintf != NULL, "vsnprintf not found"); |
4775 assert(sol_vsnprintf != NULL, "vsnprintf not found"); |
4747 } |
4776 } |
4748 } |
4777 } |
4749 return (*sol_vsnprintf)(buf, count, fmt, argptr); |
4778 return (*sol_vsnprintf)(buf, count, fmt, argptr); |
4750 } |
4779 } |
4809 } else { |
4838 } else { |
4810 ::close(fd); |
4839 ::close(fd); |
4811 return -1; |
4840 return -1; |
4812 } |
4841 } |
4813 } |
4842 } |
4814 /* |
4843 |
4815 * 32-bit Solaris systems suffer from: |
4844 // 32-bit Solaris systems suffer from: |
4816 * |
4845 // |
4817 * - an historical default soft limit of 256 per-process file |
4846 // - an historical default soft limit of 256 per-process file |
4818 * descriptors that is too low for many Java programs. |
4847 // descriptors that is too low for many Java programs. |
4819 * |
4848 // |
4820 * - a design flaw where file descriptors created using stdio |
4849 // - a design flaw where file descriptors created using stdio |
4821 * fopen must be less than 256, _even_ when the first limit above |
4850 // fopen must be less than 256, _even_ when the first limit above |
4822 * has been raised. This can cause calls to fopen (but not calls to |
4851 // has been raised. This can cause calls to fopen (but not calls to |
4823 * open, for example) to fail mysteriously, perhaps in 3rd party |
4852 // open, for example) to fail mysteriously, perhaps in 3rd party |
4824 * native code (although the JDK itself uses fopen). One can hardly |
4853 // native code (although the JDK itself uses fopen). One can hardly |
4825 * criticize them for using this most standard of all functions. |
4854 // criticize them for using this most standard of all functions. |
4826 * |
4855 // |
4827 * We attempt to make everything work anyways by: |
4856 // We attempt to make everything work anyways by: |
4828 * |
4857 // |
4829 * - raising the soft limit on per-process file descriptors beyond |
4858 // - raising the soft limit on per-process file descriptors beyond |
4830 * 256 |
4859 // 256 |
4831 * |
4860 // |
4832 * - As of Solaris 10u4, we can request that Solaris raise the 256 |
4861 // - As of Solaris 10u4, we can request that Solaris raise the 256 |
4833 * stdio fopen limit by calling function enable_extended_FILE_stdio. |
4862 // stdio fopen limit by calling function enable_extended_FILE_stdio. |
4834 * This is done in init_2 and recorded in enabled_extended_FILE_stdio |
4863 // This is done in init_2 and recorded in enabled_extended_FILE_stdio |
4835 * |
4864 // |
4836 * - If we are stuck on an old (pre 10u4) Solaris system, we can |
4865 // - If we are stuck on an old (pre 10u4) Solaris system, we can |
4837 * workaround the bug by remapping non-stdio file descriptors below |
4866 // workaround the bug by remapping non-stdio file descriptors below |
4838 * 256 to ones beyond 256, which is done below. |
4867 // 256 to ones beyond 256, which is done below. |
4839 * |
4868 // |
4840 * See: |
4869 // See: |
4841 * 1085341: 32-bit stdio routines should support file descriptors >255 |
4870 // 1085341: 32-bit stdio routines should support file descriptors >255 |
4842 * 6533291: Work around 32-bit Solaris stdio limit of 256 open files |
4871 // 6533291: Work around 32-bit Solaris stdio limit of 256 open files |
4843 * 6431278: Netbeans crash on 32 bit Solaris: need to call |
4872 // 6431278: Netbeans crash on 32 bit Solaris: need to call |
4844 * enable_extended_FILE_stdio() in VM initialisation |
4873 // enable_extended_FILE_stdio() in VM initialisation |
4845 * Giri Mandalika's blog |
4874 // Giri Mandalika's blog |
4846 * http://technopark02.blogspot.com/2005_05_01_archive.html |
4875 // http://technopark02.blogspot.com/2005_05_01_archive.html |
4847 */ |
4876 // |
4848 #ifndef _LP64 |
4877 #ifndef _LP64 |
4849 if ((!enabled_extended_FILE_stdio) && fd < 256) { |
4878 if ((!enabled_extended_FILE_stdio) && fd < 256) { |
4850 int newfd = ::fcntl(fd, F_DUPFD, 256); |
4879 int newfd = ::fcntl(fd, F_DUPFD, 256); |
4851 if (newfd != -1) { |
4880 if (newfd != -1) { |
4852 ::close(fd); |
4881 ::close(fd); |
4853 fd = newfd; |
4882 fd = newfd; |
4854 } |
4883 } |
4855 } |
4884 } |
4856 #endif // 32-bit Solaris |
4885 #endif // 32-bit Solaris |
4857 /* |
4886 |
4858 * All file descriptors that are opened in the JVM and not |
4887 // All file descriptors that are opened in the JVM and not |
4859 * specifically destined for a subprocess should have the |
4888 // specifically destined for a subprocess should have the |
4860 * close-on-exec flag set. If we don't set it, then careless 3rd |
4889 // close-on-exec flag set. If we don't set it, then careless 3rd |
4861 * party native code might fork and exec without closing all |
4890 // party native code might fork and exec without closing all |
4862 * appropriate file descriptors (e.g. as we do in closeDescriptors in |
4891 // appropriate file descriptors (e.g. as we do in closeDescriptors in |
4863 * UNIXProcess.c), and this in turn might: |
4892 // UNIXProcess.c), and this in turn might: |
4864 * |
4893 // |
4865 * - cause end-of-file to fail to be detected on some file |
4894 // - cause end-of-file to fail to be detected on some file |
4866 * descriptors, resulting in mysterious hangs, or |
4895 // descriptors, resulting in mysterious hangs, or |
4867 * |
4896 // |
4868 * - might cause an fopen in the subprocess to fail on a system |
4897 // - might cause an fopen in the subprocess to fail on a system |
4869 * suffering from bug 1085341. |
4898 // suffering from bug 1085341. |
4870 * |
4899 // |
4871 * (Yes, the default setting of the close-on-exec flag is a Unix |
4900 // (Yes, the default setting of the close-on-exec flag is a Unix |
4872 * design flaw) |
4901 // design flaw) |
4873 * |
4902 // |
4874 * See: |
4903 // See: |
4875 * 1085341: 32-bit stdio routines should support file descriptors >255 |
4904 // 1085341: 32-bit stdio routines should support file descriptors >255 |
4876 * 4843136: (process) pipe file descriptor from Runtime.exec not being closed |
4905 // 4843136: (process) pipe file descriptor from Runtime.exec not being closed |
4877 * 6339493: (process) Runtime.exec does not close all file descriptors on Solaris 9 |
4906 // 6339493: (process) Runtime.exec does not close all file descriptors on Solaris 9 |
4878 */ |
4907 // |
4879 #ifdef FD_CLOEXEC |
4908 #ifdef FD_CLOEXEC |
4880 { |
4909 { |
4881 int flags = ::fcntl(fd, F_GETFD); |
4910 int flags = ::fcntl(fd, F_GETFD); |
4882 if (flags != -1) |
4911 if (flags != -1) { |
4883 ::fcntl(fd, F_SETFD, flags | FD_CLOEXEC); |
4912 ::fcntl(fd, F_SETFD, flags | FD_CLOEXEC); |
|
4913 } |
4884 } |
4914 } |
4885 #endif |
4915 #endif |
4886 |
4916 |
4887 if (o_delete != 0) { |
4917 if (o_delete != 0) { |
4888 ::unlink(path); |
4918 ::unlink(path); |
5065 if (!CHECK_POINTER_OK(cv)) fatal("Condvar must be in C heap only."); |
5094 if (!CHECK_POINTER_OK(cv)) fatal("Condvar must be in C heap only."); |
5066 #define CHECK_P(p) \ |
5095 #define CHECK_P(p) \ |
5067 if (!CHECK_POINTER_OK(p)) fatal(false, "Pointer must be in C heap only."); |
5096 if (!CHECK_POINTER_OK(p)) fatal(false, "Pointer must be in C heap only."); |
5068 |
5097 |
5069 #define CHECK_MUTEX(mutex_op) \ |
5098 #define CHECK_MUTEX(mutex_op) \ |
5070 CHECK_SYNCH_OP(int, mutex_op, (mutex_t *mu), (mu), CHECK_MU); |
5099 CHECK_SYNCH_OP(int, mutex_op, (mutex_t *mu), (mu), CHECK_MU); |
5071 |
5100 |
5072 CHECK_MUTEX( mutex_lock) |
5101 CHECK_MUTEX( mutex_lock) |
5073 CHECK_MUTEX( _mutex_lock) |
5102 CHECK_MUTEX( _mutex_lock) |
5074 CHECK_MUTEX( mutex_unlock) |
5103 CHECK_MUTEX( mutex_unlock) |
5075 CHECK_MUTEX(_mutex_unlock) |
5104 CHECK_MUTEX(_mutex_unlock) |
5076 CHECK_MUTEX( mutex_trylock) |
5105 CHECK_MUTEX( mutex_trylock) |
5077 CHECK_MUTEX(_mutex_trylock) |
5106 CHECK_MUTEX(_mutex_trylock) |
5078 |
5107 |
5079 #define CHECK_COND(cond_op) \ |
5108 #define CHECK_COND(cond_op) \ |
5080 CHECK_SYNCH_OP(int, cond_op, (cond_t *cv, mutex_t *mu), (cv, mu), CHECK_MU;CHECK_CV); |
5109 CHECK_SYNCH_OP(int, cond_op, (cond_t *cv, mutex_t *mu), (cv, mu), CHECK_MU; CHECK_CV); |
5081 |
5110 |
5082 CHECK_COND( cond_wait); |
5111 CHECK_COND( cond_wait); |
5083 CHECK_COND(_cond_wait); |
5112 CHECK_COND(_cond_wait); |
5084 CHECK_COND(_cond_wait_cancel); |
5113 CHECK_COND(_cond_wait_cancel); |
5085 |
5114 |
5086 #define CHECK_COND2(cond_op) \ |
5115 #define CHECK_COND2(cond_op) \ |
5087 CHECK_SYNCH_OP(int, cond_op, (cond_t *cv, mutex_t *mu, timestruc_t* ts), (cv, mu, ts), CHECK_MU;CHECK_CV); |
5116 CHECK_SYNCH_OP(int, cond_op, (cond_t *cv, mutex_t *mu, timestruc_t* ts), (cv, mu, ts), CHECK_MU; CHECK_CV); |
5088 |
5117 |
5089 CHECK_COND2( cond_timedwait); |
5118 CHECK_COND2( cond_timedwait); |
5090 CHECK_COND2(_cond_timedwait); |
5119 CHECK_COND2(_cond_timedwait); |
5091 CHECK_COND2(_cond_timedwait_cancel); |
5120 CHECK_COND2(_cond_timedwait_cancel); |
5092 |
5121 |
5273 memset(&dlinfo, 0, sizeof(dlinfo)); |
5302 memset(&dlinfo, 0, sizeof(dlinfo)); |
5274 if (dladdr(addr, &dlinfo) != 0) { |
5303 if (dladdr(addr, &dlinfo) != 0) { |
5275 st->print(PTR_FORMAT ": ", addr); |
5304 st->print(PTR_FORMAT ": ", addr); |
5276 if (dlinfo.dli_sname != NULL && dlinfo.dli_saddr != NULL) { |
5305 if (dlinfo.dli_sname != NULL && dlinfo.dli_saddr != NULL) { |
5277 st->print("%s+%#lx", dlinfo.dli_sname, addr-(intptr_t)dlinfo.dli_saddr); |
5306 st->print("%s+%#lx", dlinfo.dli_sname, addr-(intptr_t)dlinfo.dli_saddr); |
5278 } else if (dlinfo.dli_fbase != NULL) |
5307 } else if (dlinfo.dli_fbase != NULL) { |
5279 st->print("<offset %#lx>", addr-(intptr_t)dlinfo.dli_fbase); |
5308 st->print("<offset %#lx>", addr-(intptr_t)dlinfo.dli_fbase); |
5280 else |
5309 } else { |
5281 st->print("<absolute address>"); |
5310 st->print("<absolute address>"); |
|
5311 } |
5282 if (dlinfo.dli_fname != NULL) { |
5312 if (dlinfo.dli_fname != NULL) { |
5283 st->print(" in %s", dlinfo.dli_fname); |
5313 st->print(" in %s", dlinfo.dli_fname); |
5284 } |
5314 } |
5285 if (dlinfo.dli_fbase != NULL) { |
5315 if (dlinfo.dli_fbase != NULL) { |
5286 st->print(" at " PTR_FORMAT, dlinfo.dli_fbase); |
5316 st->print(" at " PTR_FORMAT, dlinfo.dli_fbase); |
5552 } |
5583 } |
5553 |
5584 |
5554 // JSR166 |
5585 // JSR166 |
5555 // ------------------------------------------------------- |
5586 // ------------------------------------------------------- |
5556 |
5587 |
5557 /* |
5588 // The solaris and linux implementations of park/unpark are fairly |
5558 * The solaris and linux implementations of park/unpark are fairly |
5589 // conservative for now, but can be improved. They currently use a |
5559 * conservative for now, but can be improved. They currently use a |
5590 // mutex/condvar pair, plus _counter. |
5560 * mutex/condvar pair, plus _counter. |
5591 // Park decrements _counter if > 0, else does a condvar wait. Unpark |
5561 * Park decrements _counter if > 0, else does a condvar wait. Unpark |
5592 // sets count to 1 and signals condvar. Only one thread ever waits |
5562 * sets count to 1 and signals condvar. Only one thread ever waits |
5593 // on the condvar. Contention seen when trying to park implies that someone |
5563 * on the condvar. Contention seen when trying to park implies that someone |
5594 // is unparking you, so don't wait. And spurious returns are fine, so there |
5564 * is unparking you, so don't wait. And spurious returns are fine, so there |
5595 // is no need to track notifications. |
5565 * is no need to track notifications. |
|
5566 */ |
|
5567 |
5596 |
5568 #define MAX_SECS 100000000 |
5597 #define MAX_SECS 100000000 |
5569 /* |
5598 |
5570 * This code is common to linux and solaris and will be moved to a |
5599 // This code is common to linux and solaris and will be moved to a |
5571 * common place in dolphin. |
5600 // common place in dolphin. |
5572 * |
5601 // |
5573 * The passed in time value is either a relative time in nanoseconds |
5602 // The passed in time value is either a relative time in nanoseconds |
5574 * or an absolute time in milliseconds. Either way it has to be unpacked |
5603 // or an absolute time in milliseconds. Either way it has to be unpacked |
5575 * into suitable seconds and nanoseconds components and stored in the |
5604 // into suitable seconds and nanoseconds components and stored in the |
5576 * given timespec structure. |
5605 // given timespec structure. |
5577 * Given time is a 64-bit value and the time_t used in the timespec is only |
5606 // Given time is a 64-bit value and the time_t used in the timespec is only |
5578 * a signed-32-bit value (except on 64-bit Linux) we have to watch for |
5607 // a signed-32-bit value (except on 64-bit Linux) we have to watch for |
5579 * overflow if times way in the future are given. Further on Solaris versions |
5608 // overflow if times way in the future are given. Further on Solaris versions |
5580 * prior to 10 there is a restriction (see cond_timedwait) that the specified |
5609 // prior to 10 there is a restriction (see cond_timedwait) that the specified |
5581 * number of seconds, in abstime, is less than current_time + 100,000,000. |
5610 // number of seconds, in abstime, is less than current_time + 100,000,000. |
5582 * As it will be 28 years before "now + 100000000" will overflow we can |
5611 // As it will be 28 years before "now + 100000000" will overflow we can |
5583 * ignore overflow and just impose a hard-limit on seconds using the value |
5612 // ignore overflow and just impose a hard-limit on seconds using the value |
5584 * of "now + 100,000,000". This places a limit on the timeout of about 3.17 |
5613 // of "now + 100,000,000". This places a limit on the timeout of about 3.17 |
5585 * years from "now". |
5614 // years from "now". |
5586 */ |
5615 // |
5587 static void unpackTime(timespec* absTime, bool isAbsolute, jlong time) { |
5616 static void unpackTime(timespec* absTime, bool isAbsolute, jlong time) { |
5588 assert(time > 0, "convertTime"); |
5617 assert(time > 0, "convertTime"); |
5589 |
5618 |
5590 struct timeval now; |
5619 struct timeval now; |
5591 int status = gettimeofday(&now, NULL); |
5620 int status = gettimeofday(&now, NULL); |
5595 |
5624 |
5596 if (isAbsolute) { |
5625 if (isAbsolute) { |
5597 jlong secs = time / 1000; |
5626 jlong secs = time / 1000; |
5598 if (secs > max_secs) { |
5627 if (secs > max_secs) { |
5599 absTime->tv_sec = max_secs; |
5628 absTime->tv_sec = max_secs; |
5600 } |
5629 } else { |
5601 else { |
|
5602 absTime->tv_sec = secs; |
5630 absTime->tv_sec = secs; |
5603 } |
5631 } |
5604 absTime->tv_nsec = (time % 1000) * NANOSECS_PER_MILLISEC; |
5632 absTime->tv_nsec = (time % 1000) * NANOSECS_PER_MILLISEC; |
5605 } |
5633 } else { |
5606 else { |
|
5607 jlong secs = time / NANOSECS_PER_SEC; |
5634 jlong secs = time / NANOSECS_PER_SEC; |
5608 if (secs >= MAX_SECS) { |
5635 if (secs >= MAX_SECS) { |
5609 absTime->tv_sec = max_secs; |
5636 absTime->tv_sec = max_secs; |
5610 absTime->tv_nsec = 0; |
5637 absTime->tv_nsec = 0; |
5611 } |
5638 } else { |
5612 else { |
|
5613 absTime->tv_sec = now.tv_sec + secs; |
5639 absTime->tv_sec = now.tv_sec + secs; |
5614 absTime->tv_nsec = (time % NANOSECS_PER_SEC) + now.tv_usec*1000; |
5640 absTime->tv_nsec = (time % NANOSECS_PER_SEC) + now.tv_usec*1000; |
5615 if (absTime->tv_nsec >= NANOSECS_PER_SEC) { |
5641 if (absTime->tv_nsec >= NANOSECS_PER_SEC) { |
5616 absTime->tv_nsec -= NANOSECS_PER_SEC; |
5642 absTime->tv_nsec -= NANOSECS_PER_SEC; |
5617 ++absTime->tv_sec; // note: this must be <= max_secs |
5643 ++absTime->tv_sec; // note: this must be <= max_secs |
5829 // Get path to libjvm.so |
5855 // Get path to libjvm.so |
5830 os::jvm_path(buf, sizeof(buf)); |
5856 os::jvm_path(buf, sizeof(buf)); |
5831 |
5857 |
5832 // Get rid of libjvm.so |
5858 // Get rid of libjvm.so |
5833 p = strrchr(buf, '/'); |
5859 p = strrchr(buf, '/'); |
5834 if (p == NULL) return false; |
5860 if (p == NULL) { |
5835 else *p = '\0'; |
5861 return false; |
|
5862 } else { |
|
5863 *p = '\0'; |
|
5864 } |
5836 |
5865 |
5837 // Get rid of client or server |
5866 // Get rid of client or server |
5838 p = strrchr(buf, '/'); |
5867 p = strrchr(buf, '/'); |
5839 if (p == NULL) return false; |
5868 if (p == NULL) { |
5840 else *p = '\0'; |
5869 return false; |
|
5870 } else { |
|
5871 *p = '\0'; |
|
5872 } |
5841 |
5873 |
5842 // check xawt/libmawt.so |
5874 // check xawt/libmawt.so |
5843 strcpy(libmawtpath, buf); |
5875 strcpy(libmawtpath, buf); |
5844 strcat(libmawtpath, xawtstr); |
5876 strcat(libmawtpath, xawtstr); |
5845 if (::stat(libmawtpath, &statbuf) == 0) return false; |
5877 if (::stat(libmawtpath, &statbuf) == 0) return false; |
5941 // connection attempt has not yet been com- |
5974 // connection attempt has not yet been com- |
5942 // pleted. |
5975 // pleted. |
5943 // |
5976 // |
5944 // EISCONN The socket is already connected. |
5977 // EISCONN The socket is already connected. |
5945 if (_result == OS_ERR && errno == EINTR) { |
5978 if (_result == OS_ERR && errno == EINTR) { |
5946 /* restarting a connect() changes its errno semantics */ |
5979 // restarting a connect() changes its errno semantics |
5947 RESTARTABLE(::connect(fd, him, len), _result); |
5980 RESTARTABLE(::connect(fd, him, len), _result); |
5948 /* undo these changes */ |
5981 // undo these changes |
5949 if (_result == OS_ERR) { |
5982 if (_result == OS_ERR) { |
5950 if (errno == EALREADY) { |
5983 if (errno == EALREADY) { |
5951 errno = EINPROGRESS; /* fall through */ |
5984 errno = EINPROGRESS; // fall through |
5952 } else if (errno == EISCONN) { |
5985 } else if (errno == EISCONN) { |
5953 errno = 0; |
5986 errno = 0; |
5954 return OS_OK; |
5987 return OS_OK; |
5955 } |
5988 } |
5956 } |
5989 } |