148 static sigset_t check_signal_done; |
148 static sigset_t check_signal_done; |
149 static bool check_signals = true; |
149 static bool check_signals = true; |
150 |
150 |
151 static pid_t _initial_pid = 0; |
151 static pid_t _initial_pid = 0; |
152 |
152 |
153 /* Signal number used to suspend/resume a thread */ |
153 // Signal number used to suspend/resume a thread |
154 |
154 |
155 /* do not use any signal number less than SIGSEGV, see 4355769 */ |
155 // do not use any signal number less than SIGSEGV, see 4355769 |
156 static int SR_signum = SIGUSR2; |
156 static int SR_signum = SIGUSR2; |
157 sigset_t SR_sigset; |
157 sigset_t SR_sigset; |
158 |
158 |
159 /* Used to protect dlsym() calls */ |
159 // Used to protect dlsym() calls |
160 static pthread_mutex_t dl_mutex; |
160 static pthread_mutex_t dl_mutex; |
161 |
161 |
162 // Declarations |
162 // Declarations |
163 static void unpackTime(timespec* absTime, bool isAbsolute, jlong time); |
163 static void unpackTime(timespec* absTime, bool isAbsolute, jlong time); |
164 |
164 |
348 // Otherwise exit. |
348 // Otherwise exit. |
349 // |
349 // |
350 // Important note: if the location of libjvm.so changes this |
350 // Important note: if the location of libjvm.so changes this |
351 // code needs to be changed accordingly. |
351 // code needs to be changed accordingly. |
352 |
352 |
353 // See ld(1): |
353 // See ld(1): |
354 // The linker uses the following search paths to locate required |
354 // The linker uses the following search paths to locate required |
355 // shared libraries: |
355 // shared libraries: |
356 // 1: ... |
356 // 1: ... |
357 // ... |
357 // ... |
358 // 7: The default directories, normally /lib and /usr/lib. |
358 // 7: The default directories, normally /lib and /usr/lib. |
359 #if defined(AMD64) || defined(_LP64) && (defined(SPARC) || defined(PPC) || defined(S390)) |
359 #if defined(AMD64) || defined(_LP64) && (defined(SPARC) || defined(PPC) || defined(S390)) |
360 #define DEFAULT_LIBPATH "/usr/lib64:/lib64:/lib:/usr/lib" |
360 #define DEFAULT_LIBPATH "/usr/lib64:/lib64:/lib:/usr/lib" |
361 #else |
361 #else |
362 #define DEFAULT_LIBPATH "/lib:/usr/lib" |
362 #define DEFAULT_LIBPATH "/lib:/usr/lib" |
363 #endif |
363 #endif |
364 |
364 |
365 // Base path of extensions installed on the system. |
365 // Base path of extensions installed on the system. |
366 #define SYS_EXT_DIR "/usr/java/packages" |
366 #define SYS_EXT_DIR "/usr/java/packages" |
367 #define EXTENSIONS_DIR "/lib/ext" |
367 #define EXTENSIONS_DIR "/lib/ext" |
467 bool os::Linux::is_sig_ignored(int sig) { |
467 bool os::Linux::is_sig_ignored(int sig) { |
468 struct sigaction oact; |
468 struct sigaction oact; |
469 sigaction(sig, (struct sigaction*)NULL, &oact); |
469 sigaction(sig, (struct sigaction*)NULL, &oact); |
470 void* ohlr = oact.sa_sigaction ? CAST_FROM_FN_PTR(void*, oact.sa_sigaction) |
470 void* ohlr = oact.sa_sigaction ? CAST_FROM_FN_PTR(void*, oact.sa_sigaction) |
471 : CAST_FROM_FN_PTR(void*, oact.sa_handler); |
471 : CAST_FROM_FN_PTR(void*, oact.sa_handler); |
472 if (ohlr == CAST_FROM_FN_PTR(void*, SIG_IGN)) |
472 if (ohlr == CAST_FROM_FN_PTR(void*, SIG_IGN)) { |
473 return true; |
473 return true; |
474 else |
474 } else { |
475 return false; |
475 return false; |
|
476 } |
476 } |
477 } |
477 |
478 |
478 void os::Linux::signal_sets_init() { |
479 void os::Linux::signal_sets_init() { |
479 // Should also have an assertion stating we are still single-threaded. |
480 // Should also have an assertion stating we are still single-threaded. |
480 assert(!signal_sets_initialized, "Already initialized"); |
481 assert(!signal_sets_initialized, "Already initialized"); |
572 void os::Linux::libpthread_init() { |
574 void os::Linux::libpthread_init() { |
573 // Save glibc and pthread version strings. Note that _CS_GNU_LIBC_VERSION |
575 // Save glibc and pthread version strings. Note that _CS_GNU_LIBC_VERSION |
574 // and _CS_GNU_LIBPTHREAD_VERSION are supported in glibc >= 2.3.2. Use a |
576 // and _CS_GNU_LIBPTHREAD_VERSION are supported in glibc >= 2.3.2. Use a |
575 // generic name for earlier versions. |
577 // generic name for earlier versions. |
576 // Define macros here so we can build HotSpot on old systems. |
578 // Define macros here so we can build HotSpot on old systems. |
577 # ifndef _CS_GNU_LIBC_VERSION |
579 #ifndef _CS_GNU_LIBC_VERSION |
578 # define _CS_GNU_LIBC_VERSION 2 |
580 #define _CS_GNU_LIBC_VERSION 2 |
579 # endif |
581 #endif |
580 # ifndef _CS_GNU_LIBPTHREAD_VERSION |
582 #ifndef _CS_GNU_LIBPTHREAD_VERSION |
581 # define _CS_GNU_LIBPTHREAD_VERSION 3 |
583 #define _CS_GNU_LIBPTHREAD_VERSION 3 |
582 # endif |
584 #endif |
583 |
585 |
584 size_t n = confstr(_CS_GNU_LIBC_VERSION, NULL, 0); |
586 size_t n = confstr(_CS_GNU_LIBC_VERSION, NULL, 0); |
585 if (n > 0) { |
587 if (n > 0) { |
586 char *str = (char *)malloc(n, mtInternal); |
588 char *str = (char *)malloc(n, mtInternal); |
587 confstr(_CS_GNU_LIBC_VERSION, str, n); |
589 confstr(_CS_GNU_LIBC_VERSION, str, n); |
1082 if (initial_thread_stack_bottom() == NULL) return false; |
1085 if (initial_thread_stack_bottom() == NULL) return false; |
1083 assert(initial_thread_stack_bottom() != NULL && |
1086 assert(initial_thread_stack_bottom() != NULL && |
1084 initial_thread_stack_size() != 0, |
1087 initial_thread_stack_size() != 0, |
1085 "os::init did not locate initial thread's stack region"); |
1088 "os::init did not locate initial thread's stack region"); |
1086 if ((address)&dummy >= initial_thread_stack_bottom() && |
1089 if ((address)&dummy >= initial_thread_stack_bottom() && |
1087 (address)&dummy < initial_thread_stack_bottom() + initial_thread_stack_size()) |
1090 (address)&dummy < initial_thread_stack_bottom() + initial_thread_stack_size()) { |
1088 return true; |
1091 return true; |
1089 else return false; |
1092 } else { |
|
1093 return false; |
|
1094 } |
1090 } |
1095 } |
1091 |
1096 |
1092 // Find the virtual memory area that contains addr |
1097 // Find the virtual memory area that contains addr |
1093 static bool find_vma(address addr, address* vma_low, address* vma_high) { |
1098 static bool find_vma(address addr, address* vma_low, address* vma_high) { |
1094 FILE *fp = fopen("/proc/self/maps", "r"); |
1099 FILE *fp = fopen("/proc/self/maps", "r"); |
1134 // SuSE 7.2, Debian) can not handle alternate signal stack correctly |
1139 // SuSE 7.2, Debian) can not handle alternate signal stack correctly |
1135 // for initial thread if its stack size exceeds 6M. Cap it at 2M, |
1140 // for initial thread if its stack size exceeds 6M. Cap it at 2M, |
1136 // in case other parts in glibc still assumes 2M max stack size. |
1141 // in case other parts in glibc still assumes 2M max stack size. |
1137 // FIXME: alt signal stack is gone, maybe we can relax this constraint? |
1142 // FIXME: alt signal stack is gone, maybe we can relax this constraint? |
1138 // Problem still exists RH7.2 (IA64 anyway) but 2MB is a little small |
1143 // Problem still exists RH7.2 (IA64 anyway) but 2MB is a little small |
1139 if (stack_size > 2 * K * K IA64_ONLY(*2)) |
1144 if (stack_size > 2 * K * K IA64_ONLY(*2)) { |
1140 stack_size = 2 * K * K IA64_ONLY(*2); |
1145 stack_size = 2 * K * K IA64_ONLY(*2); |
|
1146 } |
1141 // Try to figure out where the stack base (top) is. This is harder. |
1147 // Try to figure out where the stack base (top) is. This is harder. |
1142 // |
1148 // |
1143 // When an application is started, glibc saves the initial stack pointer in |
1149 // When an application is started, glibc saves the initial stack pointer in |
1144 // a global variable "__libc_stack_end", which is then used by system |
1150 // a global variable "__libc_stack_end", which is then used by system |
1145 // libraries. __libc_stack_end should be pretty close to stack top. The |
1151 // libraries. __libc_stack_end should be pretty close to stack top. The |
1219 do s++; while (isspace(*s)); |
1225 do s++; while (isspace(*s)); |
1220 |
1226 |
1221 #define _UFM UINTX_FORMAT |
1227 #define _UFM UINTX_FORMAT |
1222 #define _DFM INTX_FORMAT |
1228 #define _DFM INTX_FORMAT |
1223 |
1229 |
1224 /* 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 */ |
1230 // 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 |
1225 /* 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 */ |
1231 // 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 |
1226 i = sscanf(s, "%c %d %d %d %d %d %lu %lu %lu %lu %lu %lu %lu %ld %ld %ld %ld %ld %ld " _UFM _UFM _DFM _UFM _UFM _UFM _UFM, |
1232 i = sscanf(s, "%c %d %d %d %d %d %lu %lu %lu %lu %lu %lu %lu %ld %ld %ld %ld %ld %ld " _UFM _UFM _DFM _UFM _UFM _UFM _UFM, |
1227 &state, /* 3 %c */ |
1233 &state, // 3 %c |
1228 &ppid, /* 4 %d */ |
1234 &ppid, // 4 %d |
1229 &pgrp, /* 5 %d */ |
1235 &pgrp, // 5 %d |
1230 &session, /* 6 %d */ |
1236 &session, // 6 %d |
1231 &nr, /* 7 %d */ |
1237 &nr, // 7 %d |
1232 &tpgrp, /* 8 %d */ |
1238 &tpgrp, // 8 %d |
1233 &flags, /* 9 %lu */ |
1239 &flags, // 9 %lu |
1234 &minflt, /* 10 %lu */ |
1240 &minflt, // 10 %lu |
1235 &cminflt, /* 11 %lu */ |
1241 &cminflt, // 11 %lu |
1236 &majflt, /* 12 %lu */ |
1242 &majflt, // 12 %lu |
1237 &cmajflt, /* 13 %lu */ |
1243 &cmajflt, // 13 %lu |
1238 &utime, /* 14 %lu */ |
1244 &utime, // 14 %lu |
1239 &stime, /* 15 %lu */ |
1245 &stime, // 15 %lu |
1240 &cutime, /* 16 %ld */ |
1246 &cutime, // 16 %ld |
1241 &cstime, /* 17 %ld */ |
1247 &cstime, // 17 %ld |
1242 &prio, /* 18 %ld */ |
1248 &prio, // 18 %ld |
1243 &nice, /* 19 %ld */ |
1249 &nice, // 19 %ld |
1244 &junk, /* 20 %ld */ |
1250 &junk, // 20 %ld |
1245 &it_real, /* 21 %ld */ |
1251 &it_real, // 21 %ld |
1246 &start, /* 22 UINTX_FORMAT */ |
1252 &start, // 22 UINTX_FORMAT |
1247 &vsize, /* 23 UINTX_FORMAT */ |
1253 &vsize, // 23 UINTX_FORMAT |
1248 &rss, /* 24 INTX_FORMAT */ |
1254 &rss, // 24 INTX_FORMAT |
1249 &rsslim, /* 25 UINTX_FORMAT */ |
1255 &rsslim, // 25 UINTX_FORMAT |
1250 &scodes, /* 26 UINTX_FORMAT */ |
1256 &scodes, // 26 UINTX_FORMAT |
1251 &ecode, /* 27 UINTX_FORMAT */ |
1257 &ecode, // 27 UINTX_FORMAT |
1252 &stack_start); /* 28 UINTX_FORMAT */ |
1258 &stack_start); // 28 UINTX_FORMAT |
1253 } |
1259 } |
1254 |
1260 |
1255 #undef _UFM |
1261 #undef _UFM |
1256 #undef _DFM |
1262 #undef _DFM |
1257 |
1263 |
1389 warning("No monotonic clock was available - timed services may " \ |
1395 warning("No monotonic clock was available - timed services may " \ |
1390 "be adversely affected if the time-of-day clock changes"); |
1396 "be adversely affected if the time-of-day clock changes"); |
1391 } |
1397 } |
1392 |
1398 |
1393 #ifndef SYS_clock_getres |
1399 #ifndef SYS_clock_getres |
1394 |
1400 #if defined(IA32) || defined(AMD64) |
1395 #if defined(IA32) || defined(AMD64) |
1401 #define SYS_clock_getres IA32_ONLY(266) AMD64_ONLY(229) |
1396 #define SYS_clock_getres IA32_ONLY(266) AMD64_ONLY(229) |
1402 #define sys_clock_getres(x,y) ::syscall(SYS_clock_getres, x, y) |
1397 #define sys_clock_getres(x,y) ::syscall(SYS_clock_getres, x, y) |
1403 #else |
|
1404 #warning "SYS_clock_getres not defined for this platform, disabling fast_thread_cpu_time" |
|
1405 #define sys_clock_getres(x,y) -1 |
|
1406 #endif |
1398 #else |
1407 #else |
1399 #warning "SYS_clock_getres not defined for this platform, disabling fast_thread_cpu_time" |
1408 #define sys_clock_getres(x,y) ::syscall(SYS_clock_getres, x, y) |
1400 #define sys_clock_getres(x,y) -1 |
|
1401 #endif |
|
1402 |
|
1403 #else |
|
1404 #define sys_clock_getres(x,y) ::syscall(SYS_clock_getres, x, y) |
|
1405 #endif |
1409 #endif |
1406 |
1410 |
1407 void os::Linux::fast_thread_clock_init() { |
1411 void os::Linux::fast_thread_clock_init() { |
1408 if (!UseLinuxPosixThreadCPUClocks) { |
1412 if (!UseLinuxPosixThreadCPUClocks) { |
1409 return; |
1413 return; |
1919 char elf_class; // 32 or 64 bit |
1920 char elf_class; // 32 or 64 bit |
1920 char endianess; // MSB or LSB |
1921 char endianess; // MSB or LSB |
1921 char* name; // String representation |
1922 char* name; // String representation |
1922 } arch_t; |
1923 } arch_t; |
1923 |
1924 |
1924 #ifndef EM_486 |
1925 #ifndef EM_486 |
1925 #define EM_486 6 /* Intel 80486 */ |
1926 #define EM_486 6 /* Intel 80486 */ |
1926 #endif |
1927 #endif |
1927 |
1928 |
1928 static const arch_t arch_array[]={ |
1929 static const arch_t arch_array[]={ |
1929 {EM_386, EM_386, ELFCLASS32, ELFDATA2LSB, (char*)"IA 32"}, |
1930 {EM_386, EM_386, ELFCLASS32, ELFDATA2LSB, (char*)"IA 32"}, |
1930 {EM_486, EM_386, ELFCLASS32, ELFDATA2LSB, (char*)"IA 32"}, |
1931 {EM_486, EM_386, ELFCLASS32, ELFDATA2LSB, (char*)"IA 32"}, |
1931 {EM_IA_64, EM_IA_64, ELFCLASS64, ELFDATA2LSB, (char*)"IA 64"}, |
1932 {EM_IA_64, EM_IA_64, ELFCLASS64, ELFDATA2LSB, (char*)"IA 64"}, |
1946 {EM_MIPS, EM_MIPS, ELFCLASS32, ELFDATA2MSB, (char*)"MIPS"}, |
1947 {EM_MIPS, EM_MIPS, ELFCLASS32, ELFDATA2MSB, (char*)"MIPS"}, |
1947 {EM_PARISC, EM_PARISC, ELFCLASS32, ELFDATA2MSB, (char*)"PARISC"}, |
1948 {EM_PARISC, EM_PARISC, ELFCLASS32, ELFDATA2MSB, (char*)"PARISC"}, |
1948 {EM_68K, EM_68K, ELFCLASS32, ELFDATA2MSB, (char*)"M68k"} |
1949 {EM_68K, EM_68K, ELFCLASS32, ELFDATA2MSB, (char*)"M68k"} |
1949 }; |
1950 }; |
1950 |
1951 |
1951 #if (defined IA32) |
1952 #if (defined IA32) |
1952 static Elf32_Half running_arch_code=EM_386; |
1953 static Elf32_Half running_arch_code=EM_386; |
1953 #elif (defined AMD64) |
1954 #elif (defined AMD64) |
1954 static Elf32_Half running_arch_code=EM_X86_64; |
1955 static Elf32_Half running_arch_code=EM_X86_64; |
1955 #elif (defined IA64) |
1956 #elif (defined IA64) |
1956 static Elf32_Half running_arch_code=EM_IA_64; |
1957 static Elf32_Half running_arch_code=EM_IA_64; |
1957 #elif (defined __sparc) && (defined _LP64) |
1958 #elif (defined __sparc) && (defined _LP64) |
1958 static Elf32_Half running_arch_code=EM_SPARCV9; |
1959 static Elf32_Half running_arch_code=EM_SPARCV9; |
1959 #elif (defined __sparc) && (!defined _LP64) |
1960 #elif (defined __sparc) && (!defined _LP64) |
1960 static Elf32_Half running_arch_code=EM_SPARC; |
1961 static Elf32_Half running_arch_code=EM_SPARC; |
1961 #elif (defined __powerpc64__) |
1962 #elif (defined __powerpc64__) |
1962 static Elf32_Half running_arch_code=EM_PPC64; |
1963 static Elf32_Half running_arch_code=EM_PPC64; |
1963 #elif (defined __powerpc__) |
1964 #elif (defined __powerpc__) |
1964 static Elf32_Half running_arch_code=EM_PPC; |
1965 static Elf32_Half running_arch_code=EM_PPC; |
1965 #elif (defined ARM) |
1966 #elif (defined ARM) |
1966 static Elf32_Half running_arch_code=EM_ARM; |
1967 static Elf32_Half running_arch_code=EM_ARM; |
1967 #elif (defined S390) |
1968 #elif (defined S390) |
1968 static Elf32_Half running_arch_code=EM_S390; |
1969 static Elf32_Half running_arch_code=EM_S390; |
1969 #elif (defined ALPHA) |
1970 #elif (defined ALPHA) |
1970 static Elf32_Half running_arch_code=EM_ALPHA; |
1971 static Elf32_Half running_arch_code=EM_ALPHA; |
1971 #elif (defined MIPSEL) |
1972 #elif (defined MIPSEL) |
1972 static Elf32_Half running_arch_code=EM_MIPS_RS3_LE; |
1973 static Elf32_Half running_arch_code=EM_MIPS_RS3_LE; |
1973 #elif (defined PARISC) |
1974 #elif (defined PARISC) |
1974 static Elf32_Half running_arch_code=EM_PARISC; |
1975 static Elf32_Half running_arch_code=EM_PARISC; |
1975 #elif (defined MIPS) |
1976 #elif (defined MIPS) |
1976 static Elf32_Half running_arch_code=EM_MIPS; |
1977 static Elf32_Half running_arch_code=EM_MIPS; |
1977 #elif (defined M68K) |
1978 #elif (defined M68K) |
1978 static Elf32_Half running_arch_code=EM_68K; |
1979 static Elf32_Half running_arch_code=EM_68K; |
1979 #else |
1980 #else |
1980 #error Method os::dll_load requires that one of following is defined:\ |
1981 #error Method os::dll_load requires that one of following is defined:\ |
1981 IA32, AMD64, IA64, __sparc, __powerpc__, ARM, S390, ALPHA, MIPS, MIPSEL, PARISC, M68K |
1982 IA32, AMD64, IA64, __sparc, __powerpc__, ARM, S390, ALPHA, MIPS, MIPSEL, PARISC, M68K |
1982 #endif |
1983 #endif |
1983 |
1984 |
1984 // Identify compatability class for VM's architecture and library's architecture |
1985 // Identify compatability class for VM's architecture and library's architecture |
1985 // Obtain string descriptions for architectures |
1986 // Obtain string descriptions for architectures |
1986 |
1987 |
1987 arch_t lib_arch={elf_head.e_machine,0,elf_head.e_ident[EI_CLASS], elf_head.e_ident[EI_DATA], NULL}; |
1988 arch_t lib_arch={elf_head.e_machine,0,elf_head.e_ident[EI_CLASS], elf_head.e_ident[EI_DATA], NULL}; |
2031 } |
2032 } |
2032 |
2033 |
2033 return NULL; |
2034 return NULL; |
2034 } |
2035 } |
2035 |
2036 |
2036 void * os::Linux::dlopen_helper(const char *filename, char *ebuf, int ebuflen) { |
2037 void * os::Linux::dlopen_helper(const char *filename, char *ebuf, |
|
2038 int ebuflen) { |
2037 void * result = ::dlopen(filename, RTLD_LAZY); |
2039 void * result = ::dlopen(filename, RTLD_LAZY); |
2038 if (result == NULL) { |
2040 if (result == NULL) { |
2039 ::strncpy(ebuf, ::dlerror(), ebuflen - 1); |
2041 ::strncpy(ebuf, ::dlerror(), ebuflen - 1); |
2040 ebuf[ebuflen-1] = '\0'; |
2042 ebuf[ebuflen-1] = '\0'; |
2041 } |
2043 } |
2042 return result; |
2044 return result; |
2043 } |
2045 } |
2044 |
2046 |
2045 void * os::Linux::dll_load_in_vmthread(const char *filename, char *ebuf, int ebuflen) { |
2047 void * os::Linux::dll_load_in_vmthread(const char *filename, char *ebuf, |
|
2048 int ebuflen) { |
2046 void * result = NULL; |
2049 void * result = NULL; |
2047 if (LoadExecStackDllInVMThread) { |
2050 if (LoadExecStackDllInVMThread) { |
2048 result = dlopen_helper(filename, ebuf, ebuflen); |
2051 result = dlopen_helper(filename, ebuf, ebuflen); |
2049 } |
2052 } |
2050 |
2053 |
2378 //////////////////////////////////////////////////////////////////////////////// |
2383 //////////////////////////////////////////////////////////////////////////////// |
2379 // sun.misc.Signal support |
2384 // sun.misc.Signal support |
2380 |
2385 |
2381 static volatile jint sigint_count = 0; |
2386 static volatile jint sigint_count = 0; |
2382 |
2387 |
2383 static void |
2388 static void UserHandler(int sig, void *siginfo, void *context) { |
2384 UserHandler(int sig, void *siginfo, void *context) { |
|
2385 // 4511530 - sem_post is serialized and handled by the manager thread. When |
2389 // 4511530 - sem_post is serialized and handled by the manager thread. When |
2386 // the program is interrupted by Ctrl-C, SIGINT is sent to every thread. We |
2390 // the program is interrupted by Ctrl-C, SIGINT is sent to every thread. We |
2387 // don't want to flood the manager thread with sem_post requests. |
2391 // don't want to flood the manager thread with sem_post requests. |
2388 if (sig == SIGINT && Atomic::add(1, &sigint_count) > 1) |
2392 if (sig == SIGINT && Atomic::add(1, &sigint_count) > 1) { |
2389 return; |
2393 return; |
|
2394 } |
2390 |
2395 |
2391 // Ctrl-C is pressed during error reporting, likely because the error |
2396 // Ctrl-C is pressed during error reporting, likely because the error |
2392 // handler fails to abort. Let VM die immediately. |
2397 // handler fails to abort. Let VM die immediately. |
2393 if (sig == SIGINT && is_error_reported()) { |
2398 if (sig == SIGINT && is_error_reported()) { |
2394 os::die(); |
2399 os::die(); |
2541 ::sem_wait(&sig_sem); |
2544 ::sem_wait(&sig_sem); |
2542 |
2545 |
2543 // were we externally suspended while we were waiting? |
2546 // were we externally suspended while we were waiting? |
2544 threadIsSuspended = thread->handle_special_suspend_equivalent_condition(); |
2547 threadIsSuspended = thread->handle_special_suspend_equivalent_condition(); |
2545 if (threadIsSuspended) { |
2548 if (threadIsSuspended) { |
2546 // |
|
2547 // The semaphore has been incremented, but while we were waiting |
2549 // The semaphore has been incremented, but while we were waiting |
2548 // another thread suspended us. We don't want to continue running |
2550 // another thread suspended us. We don't want to continue running |
2549 // while suspended because that would surprise the thread that |
2551 // while suspended because that would surprise the thread that |
2550 // suspended us. |
2552 // suspended us. |
2551 // |
|
2552 ::sem_post(&sig_sem); |
2553 ::sem_post(&sig_sem); |
2553 |
2554 |
2554 thread->java_suspend_self(); |
2555 thread->java_suspend_self(); |
2555 } |
2556 } |
2556 } while (threadIsSuspended); |
2557 } while (threadIsSuspended); |
2694 } |
2695 } |
2695 } |
2696 } |
2696 |
2697 |
2697 // Define MAP_HUGETLB here so we can build HotSpot on old systems. |
2698 // Define MAP_HUGETLB here so we can build HotSpot on old systems. |
2698 #ifndef MAP_HUGETLB |
2699 #ifndef MAP_HUGETLB |
2699 #define MAP_HUGETLB 0x40000 |
2700 #define MAP_HUGETLB 0x40000 |
2700 #endif |
2701 #endif |
2701 |
2702 |
2702 // Define MADV_HUGEPAGE here so we can build HotSpot on old systems. |
2703 // Define MADV_HUGEPAGE here so we can build HotSpot on old systems. |
2703 #ifndef MADV_HUGEPAGE |
2704 #ifndef MADV_HUGEPAGE |
2704 #define MADV_HUGEPAGE 14 |
2705 #define MADV_HUGEPAGE 14 |
2705 #endif |
2706 #endif |
2706 |
2707 |
2707 int os::Linux::commit_memory_impl(char* addr, size_t size, |
2708 int os::Linux::commit_memory_impl(char* addr, size_t size, |
2708 size_t alignment_hint, bool exec) { |
2709 size_t alignment_hint, bool exec) { |
2709 int err = os::Linux::commit_memory_impl(addr, size, exec); |
2710 int err = os::Linux::commit_memory_impl(addr, size, exec); |
2796 |
2797 |
2797 bool os::get_page_info(char *start, page_info* info) { |
2798 bool os::get_page_info(char *start, page_info* info) { |
2798 return false; |
2799 return false; |
2799 } |
2800 } |
2800 |
2801 |
2801 char *os::scan_pages(char *start, char* end, page_info* page_expected, page_info* page_found) { |
2802 char *os::scan_pages(char *start, char* end, page_info* page_expected, |
|
2803 page_info* page_found) { |
2802 return end; |
2804 return end; |
2803 } |
2805 } |
2804 |
2806 |
2805 |
2807 |
2806 int os::Linux::sched_getcpu_syscall(void) { |
2808 int os::Linux::sched_getcpu_syscall(void) { |
2807 unsigned int cpu; |
2809 unsigned int cpu; |
2808 int retval = -1; |
2810 int retval = -1; |
2809 |
2811 |
2810 #if defined(IA32) |
2812 #if defined(IA32) |
2811 # ifndef SYS_getcpu |
2813 #ifndef SYS_getcpu |
2812 # define SYS_getcpu 318 |
2814 #define SYS_getcpu 318 |
2813 # endif |
2815 #endif |
2814 retval = syscall(SYS_getcpu, &cpu, NULL, NULL); |
2816 retval = syscall(SYS_getcpu, &cpu, NULL, NULL); |
2815 #elif defined(AMD64) |
2817 #elif defined(AMD64) |
2816 // Unfortunately we have to bring all these macros here from vsyscall.h |
2818 // Unfortunately we have to bring all these macros here from vsyscall.h |
2817 // to be able to compile on old linuxes. |
2819 // to be able to compile on old linuxes. |
2818 # define __NR_vgetcpu 2 |
2820 #define __NR_vgetcpu 2 |
2819 # define VSYSCALL_START (-10UL << 20) |
2821 #define VSYSCALL_START (-10UL << 20) |
2820 # define VSYSCALL_SIZE 1024 |
2822 #define VSYSCALL_SIZE 1024 |
2821 # define VSYSCALL_ADDR(vsyscall_nr) (VSYSCALL_START+VSYSCALL_SIZE*(vsyscall_nr)) |
2823 #define VSYSCALL_ADDR(vsyscall_nr) (VSYSCALL_START+VSYSCALL_SIZE*(vsyscall_nr)) |
2822 typedef long (*vgetcpu_t)(unsigned int *cpu, unsigned int *node, unsigned long *tcache); |
2824 typedef long (*vgetcpu_t)(unsigned int *cpu, unsigned int *node, unsigned long *tcache); |
2823 vgetcpu_t vgetcpu = (vgetcpu_t)VSYSCALL_ADDR(__NR_vgetcpu); |
2825 vgetcpu_t vgetcpu = (vgetcpu_t)VSYSCALL_ADDR(__NR_vgetcpu); |
2824 retval = vgetcpu(&cpu, NULL, NULL); |
2826 retval = vgetcpu(&cpu, NULL, NULL); |
2825 #endif |
2827 #endif |
2826 |
2828 |
2849 // sched_getcpu() should be in libc. |
2851 // sched_getcpu() should be in libc. |
2850 set_sched_getcpu(CAST_TO_FN_PTR(sched_getcpu_func_t, |
2852 set_sched_getcpu(CAST_TO_FN_PTR(sched_getcpu_func_t, |
2851 dlsym(RTLD_DEFAULT, "sched_getcpu"))); |
2853 dlsym(RTLD_DEFAULT, "sched_getcpu"))); |
2852 |
2854 |
2853 // If it's not, try a direct syscall. |
2855 // If it's not, try a direct syscall. |
2854 if (sched_getcpu() == -1) |
2856 if (sched_getcpu() == -1) { |
2855 set_sched_getcpu(CAST_TO_FN_PTR(sched_getcpu_func_t, (void*)&sched_getcpu_syscall)); |
2857 set_sched_getcpu(CAST_TO_FN_PTR(sched_getcpu_func_t, |
|
2858 (void*)&sched_getcpu_syscall)); |
|
2859 } |
2856 |
2860 |
2857 if (sched_getcpu() != -1) { // Does it work? |
2861 if (sched_getcpu() != -1) { // Does it work? |
2858 void *handle = dlopen("libnuma.so.1", RTLD_LAZY); |
2862 void *handle = dlopen("libnuma.so.1", RTLD_LAZY); |
2859 if (handle != NULL) { |
2863 if (handle != NULL) { |
2860 set_numa_node_to_cpus(CAST_TO_FN_PTR(numa_node_to_cpus_func_t, |
2864 set_numa_node_to_cpus(CAST_TO_FN_PTR(numa_node_to_cpus_func_t, |
2942 uintptr_t res = (uintptr_t) ::mmap(addr, size, PROT_NONE, |
2946 uintptr_t res = (uintptr_t) ::mmap(addr, size, PROT_NONE, |
2943 MAP_PRIVATE|MAP_FIXED|MAP_NORESERVE|MAP_ANONYMOUS, -1, 0); |
2947 MAP_PRIVATE|MAP_FIXED|MAP_NORESERVE|MAP_ANONYMOUS, -1, 0); |
2944 return res != (uintptr_t) MAP_FAILED; |
2948 return res != (uintptr_t) MAP_FAILED; |
2945 } |
2949 } |
2946 |
2950 |
2947 static |
2951 static address get_stack_commited_bottom(address bottom, size_t size) { |
2948 address get_stack_commited_bottom(address bottom, size_t size) { |
|
2949 address nbot = bottom; |
2952 address nbot = bottom; |
2950 address ntop = bottom + size; |
2953 address ntop = bottom + size; |
2951 |
2954 |
2952 size_t page_sz = os::vm_page_size(); |
2955 size_t page_sz = os::vm_page_size(); |
2953 unsigned pages = size / page_sz; |
2956 unsigned pages = size / page_sz; |
3017 // that point by munmap()ping it. This ensures that when we later |
3020 // that point by munmap()ping it. This ensures that when we later |
3018 // munmap() the guard pages we don't leave a hole in the stack |
3021 // munmap() the guard pages we don't leave a hole in the stack |
3019 // mapping. This only affects the main/initial thread |
3022 // mapping. This only affects the main/initial thread |
3020 |
3023 |
3021 bool os::pd_create_stack_guard_pages(char* addr, size_t size) { |
3024 bool os::pd_create_stack_guard_pages(char* addr, size_t size) { |
3022 |
|
3023 if (os::Linux::is_initial_thread()) { |
3025 if (os::Linux::is_initial_thread()) { |
3024 // As we manually grow stack up to bottom inside create_attached_thread(), |
3026 // As we manually grow stack up to bottom inside create_attached_thread(), |
3025 // it's likely that os::Linux::initial_thread_stack_bottom is mapped and |
3027 // it's likely that os::Linux::initial_thread_stack_bottom is mapped and |
3026 // we don't need to do anything special. |
3028 // we don't need to do anything special. |
3027 // Check it first, before calling heavy function. |
3029 // Check it first, before calling heavy function. |
3154 |
3156 |
3155 bool os::unguard_memory(char* addr, size_t size) { |
3157 bool os::unguard_memory(char* addr, size_t size) { |
3156 return linux_mprotect(addr, size, PROT_READ|PROT_WRITE); |
3158 return linux_mprotect(addr, size, PROT_READ|PROT_WRITE); |
3157 } |
3159 } |
3158 |
3160 |
3159 bool os::Linux::transparent_huge_pages_sanity_check(bool warn, size_t page_size) { |
3161 bool os::Linux::transparent_huge_pages_sanity_check(bool warn, |
|
3162 size_t page_size) { |
3160 bool result = false; |
3163 bool result = false; |
3161 void *p = mmap(NULL, page_size * 2, PROT_READ|PROT_WRITE, |
3164 void *p = mmap(NULL, page_size * 2, PROT_READ|PROT_WRITE, |
3162 MAP_ANONYMOUS|MAP_PRIVATE, |
3165 MAP_ANONYMOUS|MAP_PRIVATE, |
3163 -1, 0); |
3166 -1, 0); |
3164 if (p != MAP_FAILED) { |
3167 if (p != MAP_FAILED) { |
3209 } |
3212 } |
3210 |
3213 |
3211 return result; |
3214 return result; |
3212 } |
3215 } |
3213 |
3216 |
3214 /* |
3217 // Set the coredump_filter bits to include largepages in core dump (bit 6) |
3215 * Set the coredump_filter bits to include largepages in core dump (bit 6) |
3218 // |
3216 * |
3219 // From the coredump_filter documentation: |
3217 * From the coredump_filter documentation: |
3220 // |
3218 * |
3221 // - (bit 0) anonymous private memory |
3219 * - (bit 0) anonymous private memory |
3222 // - (bit 1) anonymous shared memory |
3220 * - (bit 1) anonymous shared memory |
3223 // - (bit 2) file-backed private memory |
3221 * - (bit 2) file-backed private memory |
3224 // - (bit 3) file-backed shared memory |
3222 * - (bit 3) file-backed shared memory |
3225 // - (bit 4) ELF header pages in file-backed private memory areas (it is |
3223 * - (bit 4) ELF header pages in file-backed private memory areas (it is |
3226 // effective only if the bit 2 is cleared) |
3224 * effective only if the bit 2 is cleared) |
3227 // - (bit 5) hugetlb private memory |
3225 * - (bit 5) hugetlb private memory |
3228 // - (bit 6) hugetlb shared memory |
3226 * - (bit 6) hugetlb shared memory |
3229 // |
3227 */ |
|
3228 static void set_coredump_filter(void) { |
3230 static void set_coredump_filter(void) { |
3229 FILE *f; |
3231 FILE *f; |
3230 long cdm; |
3232 long cdm; |
3231 |
3233 |
3232 if ((f = fopen("/proc/self/coredump_filter", "r+")) == NULL) { |
3234 if ((f = fopen("/proc/self/coredump_filter", "r+")) == NULL) { |
3375 |
3377 |
3376 set_coredump_filter(); |
3378 set_coredump_filter(); |
3377 } |
3379 } |
3378 |
3380 |
3379 #ifndef SHM_HUGETLB |
3381 #ifndef SHM_HUGETLB |
3380 #define SHM_HUGETLB 04000 |
3382 #define SHM_HUGETLB 04000 |
3381 #endif |
3383 #endif |
3382 |
3384 |
3383 char* os::Linux::reserve_memory_special_shm(size_t bytes, size_t alignment, char* req_addr, bool exec) { |
3385 char* os::Linux::reserve_memory_special_shm(size_t bytes, size_t alignment, |
|
3386 char* req_addr, bool exec) { |
3384 // "exec" is passed in but not used. Creating the shared image for |
3387 // "exec" is passed in but not used. Creating the shared image for |
3385 // the code cache doesn't have an SHM_X executable permission to check. |
3388 // the code cache doesn't have an SHM_X executable permission to check. |
3386 assert(UseLargePages && UseSHM, "only for SHM large pages"); |
3389 assert(UseLargePages && UseSHM, "only for SHM large pages"); |
3387 assert(is_ptr_aligned(req_addr, os::large_page_size()), "Unaligned address"); |
3390 assert(is_ptr_aligned(req_addr, os::large_page_size()), "Unaligned address"); |
3388 |
3391 |
3460 PTR_FORMAT " bytes: " SIZE_FORMAT " (errno = %d).", req_addr, bytes, error); |
3463 PTR_FORMAT " bytes: " SIZE_FORMAT " (errno = %d).", req_addr, bytes, error); |
3461 warning("%s", msg); |
3464 warning("%s", msg); |
3462 } |
3465 } |
3463 } |
3466 } |
3464 |
3467 |
3465 char* os::Linux::reserve_memory_special_huge_tlbfs_only(size_t bytes, char* req_addr, bool exec) { |
3468 char* os::Linux::reserve_memory_special_huge_tlbfs_only(size_t bytes, |
|
3469 char* req_addr, |
|
3470 bool exec) { |
3466 assert(UseLargePages && UseHugeTLBFS, "only for Huge TLBFS large pages"); |
3471 assert(UseLargePages && UseHugeTLBFS, "only for Huge TLBFS large pages"); |
3467 assert(is_size_aligned(bytes, os::large_page_size()), "Unaligned size"); |
3472 assert(is_size_aligned(bytes, os::large_page_size()), "Unaligned size"); |
3468 assert(is_ptr_aligned(req_addr, os::large_page_size()), "Unaligned address"); |
3473 assert(is_ptr_aligned(req_addr, os::large_page_size()), "Unaligned address"); |
3469 |
3474 |
3470 int prot = exec ? PROT_READ|PROT_WRITE|PROT_EXEC : PROT_READ|PROT_WRITE; |
3475 int prot = exec ? PROT_READ|PROT_WRITE|PROT_EXEC : PROT_READ|PROT_WRITE; |
3572 } |
3580 } |
3573 |
3581 |
3574 return start; |
3582 return start; |
3575 } |
3583 } |
3576 |
3584 |
3577 char* os::Linux::reserve_memory_special_huge_tlbfs(size_t bytes, size_t alignment, char* req_addr, bool exec) { |
3585 char* os::Linux::reserve_memory_special_huge_tlbfs(size_t bytes, |
|
3586 size_t alignment, |
|
3587 char* req_addr, |
|
3588 bool exec) { |
3578 assert(UseLargePages && UseHugeTLBFS, "only for Huge TLBFS large pages"); |
3589 assert(UseLargePages && UseHugeTLBFS, "only for Huge TLBFS large pages"); |
3579 assert(is_ptr_aligned(req_addr, alignment), "Must be"); |
3590 assert(is_ptr_aligned(req_addr, alignment), "Must be"); |
3580 assert(is_power_of_2(alignment), "Must be"); |
3591 assert(is_power_of_2(alignment), "Must be"); |
3581 assert(is_power_of_2(os::large_page_size()), "Must be"); |
3592 assert(is_power_of_2(os::large_page_size()), "Must be"); |
3582 assert(bytes >= os::large_page_size(), "Shouldn't allocate large pages for small sizes"); |
3593 assert(bytes >= os::large_page_size(), "Shouldn't allocate large pages for small sizes"); |
3900 // - resume: |
3911 // - resume: |
3901 // - sets target osthread state to continue |
3912 // - sets target osthread state to continue |
3902 // - sends signal to end the sigsuspend loop in the SR_handler |
3913 // - sends signal to end the sigsuspend loop in the SR_handler |
3903 // |
3914 // |
3904 // Note that the SR_lock plays no role in this suspend/resume protocol. |
3915 // Note that the SR_lock plays no role in this suspend/resume protocol. |
3905 // |
|
3906 |
3916 |
3907 static void resume_clear_context(OSThread *osthread) { |
3917 static void resume_clear_context(OSThread *osthread) { |
3908 osthread->set_ucontext(NULL); |
3918 osthread->set_ucontext(NULL); |
3909 osthread->set_siginfo(NULL); |
3919 osthread->set_siginfo(NULL); |
3910 } |
3920 } |
3911 |
3921 |
3912 static void suspend_save_context(OSThread *osthread, siginfo_t* siginfo, ucontext_t* context) { |
3922 static void suspend_save_context(OSThread *osthread, siginfo_t* siginfo, |
|
3923 ucontext_t* context) { |
3913 osthread->set_ucontext(context); |
3924 osthread->set_ucontext(context); |
3914 osthread->set_siginfo(siginfo); |
3925 osthread->set_siginfo(siginfo); |
3915 } |
3926 } |
3916 |
3927 |
3917 // |
|
3918 // Handler function invoked when a thread's execution is suspended or |
3928 // Handler function invoked when a thread's execution is suspended or |
3919 // resumed. We have to be careful that only async-safe functions are |
3929 // resumed. We have to be careful that only async-safe functions are |
3920 // called here (Note: most pthread functions are not async safe and |
3930 // called here (Note: most pthread functions are not async safe and |
3921 // should be avoided.) |
3931 // should be avoided.) |
3922 // |
3932 // |
4122 // the sa_flags field passed to sigaction() includes SA_SIGINFO and SA_RESTART. |
4132 // the sa_flags field passed to sigaction() includes SA_SIGINFO and SA_RESTART. |
4123 // |
4133 // |
4124 // Note that the VM will print warnings if it detects conflicting signal |
4134 // Note that the VM will print warnings if it detects conflicting signal |
4125 // handlers, unless invoked with the option "-XX:+AllowUserSignalHandlers". |
4135 // handlers, unless invoked with the option "-XX:+AllowUserSignalHandlers". |
4126 // |
4136 // |
4127 extern "C" JNIEXPORT int |
4137 extern "C" JNIEXPORT int JVM_handle_linux_signal(int signo, |
4128 JVM_handle_linux_signal(int signo, siginfo_t* siginfo, |
4138 siginfo_t* siginfo, |
4129 void* ucontext, int abort_if_unrecognized); |
4139 void* ucontext, |
|
4140 int abort_if_unrecognized); |
4130 |
4141 |
4131 void signalHandler(int sig, siginfo_t* info, void* uc) { |
4142 void signalHandler(int sig, siginfo_t* info, void* uc) { |
4132 assert(info != NULL && uc != NULL, "it must be old kernel"); |
4143 assert(info != NULL && uc != NULL, "it must be old kernel"); |
4133 int orig_errno = errno; // Preserve errno value over signal handler. |
4144 int orig_errno = errno; // Preserve errno value over signal handler. |
4134 JVM_handle_linux_signal(sig, info, uc, true); |
4145 JVM_handle_linux_signal(sig, info, uc, true); |
4373 // to indicate, that some special sort of signal |
4384 // to indicate, that some special sort of signal |
4374 // trampoline is used. |
4385 // trampoline is used. |
4375 // We will never set this flag, and we should |
4386 // We will never set this flag, and we should |
4376 // ignore this flag in our diagnostic |
4387 // ignore this flag in our diagnostic |
4377 #ifdef SIGNIFICANT_SIGNAL_MASK |
4388 #ifdef SIGNIFICANT_SIGNAL_MASK |
4378 #undef SIGNIFICANT_SIGNAL_MASK |
4389 #undef SIGNIFICANT_SIGNAL_MASK |
4379 #endif |
4390 #endif |
4380 #define SIGNIFICANT_SIGNAL_MASK (~0x04000000) |
4391 #define SIGNIFICANT_SIGNAL_MASK (~0x04000000) |
4381 |
4392 |
4382 static const char* get_signal_handler_name(address handler, |
4393 static const char* get_signal_handler_name(address handler, |
4383 char* buf, int buflen) { |
4394 char* buf, int buflen) { |
4445 } |
4456 } |
4446 st->cr(); |
4457 st->cr(); |
4447 } |
4458 } |
4448 |
4459 |
4449 |
4460 |
4450 #define DO_SIGNAL_CHECK(sig) \ |
4461 #define DO_SIGNAL_CHECK(sig) \ |
4451 if (!sigismember(&check_signal_done, sig)) \ |
4462 do { \ |
4452 os::Linux::check_signal_handler(sig) |
4463 if (!sigismember(&check_signal_done, sig)) { \ |
|
4464 os::Linux::check_signal_handler(sig); \ |
|
4465 } \ |
|
4466 } while (0) |
4453 |
4467 |
4454 // This method is a periodic task to check for misbehaving JNI applications |
4468 // This method is a periodic task to check for misbehaving JNI applications |
4455 // under CheckJNI, we can add any periodic checks here |
4469 // under CheckJNI, we can add any periodic checks here |
4456 |
4470 |
4457 void os::run_periodic_checks() { |
4471 void os::run_periodic_checks() { |
4458 |
|
4459 if (check_signals == false) return; |
4472 if (check_signals == false) return; |
4460 |
4473 |
4461 // SEGV and BUS if overridden could potentially prevent |
4474 // SEGV and BUS if overridden could potentially prevent |
4462 // generation of hs*.log in the event of a crash, debugging |
4475 // generation of hs*.log in the event of a crash, debugging |
4463 // such a case can be very challenging, so we absolutely |
4476 // such a case can be very challenging, so we absolutely |
4564 if (sigismember(&check_signal_done, sig)) { |
4577 if (sigismember(&check_signal_done, sig)) { |
4565 print_signal_handlers(tty, buf, O_BUFLEN); |
4578 print_signal_handlers(tty, buf, O_BUFLEN); |
4566 } |
4579 } |
4567 } |
4580 } |
4568 |
4581 |
4569 extern void report_error(char* file_name, int line_no, char* title, char* format, ...); |
4582 extern void report_error(char* file_name, int line_no, char* title, |
|
4583 char* format, ...); |
4570 |
4584 |
4571 extern bool signal_name(int signo, char* buf, size_t len); |
4585 extern bool signal_name(int signo, char* buf, size_t len); |
4572 |
4586 |
4573 const char* os::exception_name(int exception_code, char* buf, size_t size) { |
4587 const char* os::exception_name(int exception_code, char* buf, size_t size) { |
4574 if (0 < exception_code && exception_code <= SIGRTMAX) { |
4588 if (0 < exception_code && exception_code <= SIGRTMAX) { |
4655 perfMemory_exit(); |
4669 perfMemory_exit(); |
4656 } |
4670 } |
4657 } |
4671 } |
4658 |
4672 |
4659 // this is called _after_ the global arguments have been parsed |
4673 // this is called _after_ the global arguments have been parsed |
4660 jint os::init_2(void) |
4674 jint os::init_2(void) { |
4661 { |
|
4662 Linux::fast_thread_clock_init(); |
4675 Linux::fast_thread_clock_init(); |
4663 |
4676 |
4664 // Allocate a single page and mark it as readable for safepoint polling |
4677 // Allocate a single page and mark it as readable for safepoint polling |
4665 address polling_page = (address) ::mmap(NULL, Linux::page_size(), PROT_READ, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); |
4678 address polling_page = (address) ::mmap(NULL, Linux::page_size(), PROT_READ, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); |
4666 guarantee(polling_page != MAP_FAILED, "os::init_2: failed to allocate polling page"); |
4679 guarantee(polling_page != MAP_FAILED, "os::init_2: failed to allocate polling page"); |
4667 |
4680 |
4668 os::set_polling_page(polling_page); |
4681 os::set_polling_page(polling_page); |
4669 |
4682 |
4670 #ifndef PRODUCT |
4683 #ifndef PRODUCT |
4671 if (Verbose && PrintMiscellaneous) |
4684 if (Verbose && PrintMiscellaneous) { |
4672 tty->print("[SafePoint Polling address: " INTPTR_FORMAT "]\n", (intptr_t)polling_page); |
4685 tty->print("[SafePoint Polling address: " INTPTR_FORMAT "]\n", |
|
4686 (intptr_t)polling_page); |
|
4687 } |
4673 #endif |
4688 #endif |
4674 |
4689 |
4675 if (!UseMembar) { |
4690 if (!UseMembar) { |
4676 address mem_serialize_page = (address) ::mmap(NULL, Linux::page_size(), PROT_READ | PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); |
4691 address mem_serialize_page = (address) ::mmap(NULL, Linux::page_size(), PROT_READ | PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); |
4677 guarantee(mem_serialize_page != MAP_FAILED, "mmap Failed for memory serialize page"); |
4692 guarantee(mem_serialize_page != MAP_FAILED, "mmap Failed for memory serialize page"); |
4678 os::set_memory_serialize_page(mem_serialize_page); |
4693 os::set_memory_serialize_page(mem_serialize_page); |
4679 |
4694 |
4680 #ifndef PRODUCT |
4695 #ifndef PRODUCT |
4681 if (Verbose && PrintMiscellaneous) |
4696 if (Verbose && PrintMiscellaneous) { |
4682 tty->print("[Memory Serialize Page address: " INTPTR_FORMAT "]\n", (intptr_t)mem_serialize_page); |
4697 tty->print("[Memory Serialize Page address: " INTPTR_FORMAT "]\n", |
|
4698 (intptr_t)mem_serialize_page); |
|
4699 } |
4683 #endif |
4700 #endif |
4684 } |
4701 } |
4685 |
4702 |
4686 // initialize suspend/resume support - must do this before signal_sets_init() |
4703 // initialize suspend/resume support - must do this before signal_sets_init() |
4687 if (SR_initialize() != 0) { |
4704 if (SR_initialize() != 0) { |
4765 // set the number of file descriptors to max. print out error |
4782 // set the number of file descriptors to max. print out error |
4766 // if getrlimit/setrlimit fails but continue regardless. |
4783 // if getrlimit/setrlimit fails but continue regardless. |
4767 struct rlimit nbr_files; |
4784 struct rlimit nbr_files; |
4768 int status = getrlimit(RLIMIT_NOFILE, &nbr_files); |
4785 int status = getrlimit(RLIMIT_NOFILE, &nbr_files); |
4769 if (status != 0) { |
4786 if (status != 0) { |
4770 if (PrintMiscellaneous && (Verbose || WizardMode)) |
4787 if (PrintMiscellaneous && (Verbose || WizardMode)) { |
4771 perror("os::init_2 getrlimit failed"); |
4788 perror("os::init_2 getrlimit failed"); |
|
4789 } |
4772 } else { |
4790 } else { |
4773 nbr_files.rlim_cur = nbr_files.rlim_max; |
4791 nbr_files.rlim_cur = nbr_files.rlim_max; |
4774 status = setrlimit(RLIMIT_NOFILE, &nbr_files); |
4792 status = setrlimit(RLIMIT_NOFILE, &nbr_files); |
4775 if (status != 0) { |
4793 if (status != 0) { |
4776 if (PrintMiscellaneous && (Verbose || WizardMode)) |
4794 if (PrintMiscellaneous && (Verbose || WizardMode)) { |
4777 perror("os::init_2 setrlimit failed"); |
4795 perror("os::init_2 setrlimit failed"); |
|
4796 } |
4778 } |
4797 } |
4779 } |
4798 } |
4780 } |
4799 } |
4781 |
4800 |
4782 // Initialize lock used to serialize thread creation (see os::create_thread) |
4801 // Initialize lock used to serialize thread creation (see os::create_thread) |
4818 #endif |
4837 #endif |
4819 } |
4838 } |
4820 |
4839 |
4821 // Mark the polling page as unreadable |
4840 // Mark the polling page as unreadable |
4822 void os::make_polling_page_unreadable(void) { |
4841 void os::make_polling_page_unreadable(void) { |
4823 if (!guard_memory((char*)_polling_page, Linux::page_size())) |
4842 if (!guard_memory((char*)_polling_page, Linux::page_size())) { |
4824 fatal("Could not disable polling page"); |
4843 fatal("Could not disable polling page"); |
4825 }; |
4844 } |
|
4845 } |
4826 |
4846 |
4827 // Mark the polling page as readable |
4847 // Mark the polling page as readable |
4828 void os::make_polling_page_readable(void) { |
4848 void os::make_polling_page_readable(void) { |
4829 if (!linux_mprotect((char *)_polling_page, Linux::page_size(), PROT_READ)) { |
4849 if (!linux_mprotect((char *)_polling_page, Linux::page_size(), PROT_READ)) { |
4830 fatal("Could not enable polling page"); |
4850 fatal("Could not enable polling page"); |
4831 } |
4851 } |
4832 }; |
4852 } |
4833 |
4853 |
4834 int os::active_processor_count() { |
4854 int os::active_processor_count() { |
4835 // Linux doesn't yet have a (official) notion of processor sets, |
4855 // Linux doesn't yet have a (official) notion of processor sets, |
4836 // so just return the number of online processors. |
4856 // so just return the number of online processors. |
4837 int online_cpus = ::sysconf(_SC_NPROCESSORS_ONLN); |
4857 int online_cpus = ::sysconf(_SC_NPROCESSORS_ONLN); |
5033 |
5056 |
5034 // This code originates from JDK's sysOpen and open64_w |
5057 // This code originates from JDK's sysOpen and open64_w |
5035 // from src/solaris/hpi/src/system_md.c |
5058 // from src/solaris/hpi/src/system_md.c |
5036 |
5059 |
5037 #ifndef O_DELETE |
5060 #ifndef O_DELETE |
5038 #define O_DELETE 0x10000 |
5061 #define O_DELETE 0x10000 |
5039 #endif |
5062 #endif |
5040 |
5063 |
5041 // Open a file. Unlink the file immediately after open returns |
5064 // Open a file. Unlink the file immediately after open returns |
5042 // if the specified oflag has the O_DELETE flag set. |
5065 // if the specified oflag has the O_DELETE flag set. |
5043 // O_DELETE is used only in j2se/src/share/native/java/util/zip/ZipFile.c |
5066 // O_DELETE is used only in j2se/src/share/native/java/util/zip/ZipFile.c |
5044 |
5067 |
5045 int os::open(const char *path, int oflag, int mode) { |
5068 int os::open(const char *path, int oflag, int mode) { |
5046 |
|
5047 if (strlen(path) > MAX_PATH - 1) { |
5069 if (strlen(path) > MAX_PATH - 1) { |
5048 errno = ENAMETOOLONG; |
5070 errno = ENAMETOOLONG; |
5049 return -1; |
5071 return -1; |
5050 } |
5072 } |
5051 int fd; |
5073 int fd; |
5071 ::close(fd); |
5093 ::close(fd); |
5072 return -1; |
5094 return -1; |
5073 } |
5095 } |
5074 } |
5096 } |
5075 |
5097 |
5076 /* |
5098 // All file descriptors that are opened in the JVM and not |
5077 * All file descriptors that are opened in the JVM and not |
5099 // specifically destined for a subprocess should have the |
5078 * specifically destined for a subprocess should have the |
5100 // close-on-exec flag set. If we don't set it, then careless 3rd |
5079 * close-on-exec flag set. If we don't set it, then careless 3rd |
5101 // party native code might fork and exec without closing all |
5080 * party native code might fork and exec without closing all |
5102 // appropriate file descriptors (e.g. as we do in closeDescriptors in |
5081 * appropriate file descriptors (e.g. as we do in closeDescriptors in |
5103 // UNIXProcess.c), and this in turn might: |
5082 * UNIXProcess.c), and this in turn might: |
5104 // |
5083 * |
5105 // - cause end-of-file to fail to be detected on some file |
5084 * - cause end-of-file to fail to be detected on some file |
5106 // descriptors, resulting in mysterious hangs, or |
5085 * descriptors, resulting in mysterious hangs, or |
5107 // |
5086 * |
5108 // - might cause an fopen in the subprocess to fail on a system |
5087 * - might cause an fopen in the subprocess to fail on a system |
5109 // suffering from bug 1085341. |
5088 * suffering from bug 1085341. |
5110 // |
5089 * |
5111 // (Yes, the default setting of the close-on-exec flag is a Unix |
5090 * (Yes, the default setting of the close-on-exec flag is a Unix |
5112 // design flaw) |
5091 * design flaw) |
5113 // |
5092 * |
5114 // See: |
5093 * See: |
5115 // 1085341: 32-bit stdio routines should support file descriptors >255 |
5094 * 1085341: 32-bit stdio routines should support file descriptors >255 |
5116 // 4843136: (process) pipe file descriptor from Runtime.exec not being closed |
5095 * 4843136: (process) pipe file descriptor from Runtime.exec not being closed |
5117 // 6339493: (process) Runtime.exec does not close all file descriptors on Solaris 9 |
5096 * 6339493: (process) Runtime.exec does not close all file descriptors on Solaris 9 |
5118 // |
5097 */ |
|
5098 #ifdef FD_CLOEXEC |
5119 #ifdef FD_CLOEXEC |
5099 { |
5120 { |
5100 int flags = ::fcntl(fd, F_GETFD); |
5121 int flags = ::fcntl(fd, F_GETFD); |
5101 if (flags != -1) |
5122 if (flags != -1) { |
5102 ::fcntl(fd, F_SETFD, flags | FD_CLOEXEC); |
5123 ::fcntl(fd, F_SETFD, flags | FD_CLOEXEC); |
|
5124 } |
5103 } |
5125 } |
5104 #endif |
5126 #endif |
5105 |
5127 |
5106 if (o_delete != 0) { |
5128 if (o_delete != 0) { |
5107 ::unlink(path); |
5129 ::unlink(path); |
5138 struct stat64 buf64; |
5160 struct stat64 buf64; |
5139 |
5161 |
5140 if (::fstat64(fd, &buf64) >= 0) { |
5162 if (::fstat64(fd, &buf64) >= 0) { |
5141 mode = buf64.st_mode; |
5163 mode = buf64.st_mode; |
5142 if (S_ISCHR(mode) || S_ISFIFO(mode) || S_ISSOCK(mode)) { |
5164 if (S_ISCHR(mode) || S_ISFIFO(mode) || S_ISSOCK(mode)) { |
5143 /* |
5165 // XXX: is the following call interruptible? If so, this might |
5144 * XXX: is the following call interruptible? If so, this might |
5166 // need to go through the INTERRUPT_IO() wrapper as for other |
5145 * need to go through the INTERRUPT_IO() wrapper as for other |
5167 // blocking, interruptible calls in this file. |
5146 * blocking, interruptible calls in this file. |
|
5147 */ |
|
5148 int n; |
5168 int n; |
5149 if (::ioctl(fd, FIONREAD, &n) >= 0) { |
5169 if (::ioctl(fd, FIONREAD, &n) >= 0) { |
5150 *bytes = n; |
5170 *bytes = n; |
5151 return 1; |
5171 return 1; |
5152 } |
5172 } |
5604 |
5621 |
5605 |
5622 |
5606 // JSR166 |
5623 // JSR166 |
5607 // ------------------------------------------------------- |
5624 // ------------------------------------------------------- |
5608 |
5625 |
5609 /* |
5626 // The solaris and linux implementations of park/unpark are fairly |
5610 * The solaris and linux implementations of park/unpark are fairly |
5627 // conservative for now, but can be improved. They currently use a |
5611 * conservative for now, but can be improved. They currently use a |
5628 // mutex/condvar pair, plus a a count. |
5612 * mutex/condvar pair, plus a a count. |
5629 // Park decrements count if > 0, else does a condvar wait. Unpark |
5613 * Park decrements count if > 0, else does a condvar wait. Unpark |
5630 // sets count to 1 and signals condvar. Only one thread ever waits |
5614 * sets count to 1 and signals condvar. Only one thread ever waits |
5631 // on the condvar. Contention seen when trying to park implies that someone |
5615 * on the condvar. Contention seen when trying to park implies that someone |
5632 // is unparking you, so don't wait. And spurious returns are fine, so there |
5616 * is unparking you, so don't wait. And spurious returns are fine, so there |
5633 // is no need to track notifications. |
5617 * is no need to track notifications. |
5634 |
5618 */ |
5635 // This code is common to linux and solaris and will be moved to a |
5619 |
5636 // common place in dolphin. |
5620 /* |
5637 // |
5621 * This code is common to linux and solaris and will be moved to a |
5638 // The passed in time value is either a relative time in nanoseconds |
5622 * common place in dolphin. |
5639 // or an absolute time in milliseconds. Either way it has to be unpacked |
5623 * |
5640 // into suitable seconds and nanoseconds components and stored in the |
5624 * The passed in time value is either a relative time in nanoseconds |
5641 // given timespec structure. |
5625 * or an absolute time in milliseconds. Either way it has to be unpacked |
5642 // Given time is a 64-bit value and the time_t used in the timespec is only |
5626 * into suitable seconds and nanoseconds components and stored in the |
5643 // a signed-32-bit value (except on 64-bit Linux) we have to watch for |
5627 * given timespec structure. |
5644 // overflow if times way in the future are given. Further on Solaris versions |
5628 * Given time is a 64-bit value and the time_t used in the timespec is only |
5645 // prior to 10 there is a restriction (see cond_timedwait) that the specified |
5629 * a signed-32-bit value (except on 64-bit Linux) we have to watch for |
5646 // number of seconds, in abstime, is less than current_time + 100,000,000. |
5630 * overflow if times way in the future are given. Further on Solaris versions |
5647 // As it will be 28 years before "now + 100000000" will overflow we can |
5631 * prior to 10 there is a restriction (see cond_timedwait) that the specified |
5648 // ignore overflow and just impose a hard-limit on seconds using the value |
5632 * number of seconds, in abstime, is less than current_time + 100,000,000. |
5649 // of "now + 100,000,000". This places a limit on the timeout of about 3.17 |
5633 * As it will be 28 years before "now + 100000000" will overflow we can |
5650 // years from "now". |
5634 * ignore overflow and just impose a hard-limit on seconds using the value |
|
5635 * of "now + 100,000,000". This places a limit on the timeout of about 3.17 |
|
5636 * years from "now". |
|
5637 */ |
|
5638 |
5651 |
5639 static void unpackTime(timespec* absTime, bool isAbsolute, jlong time) { |
5652 static void unpackTime(timespec* absTime, bool isAbsolute, jlong time) { |
5640 assert(time > 0, "convertTime"); |
5653 assert(time > 0, "convertTime"); |
5641 time_t max_secs = 0; |
5654 time_t max_secs = 0; |
5642 |
5655 |
5803 if (s < 1) { |
5816 if (s < 1) { |
5804 // thread might be parked |
5817 // thread might be parked |
5805 if (_cur_index != -1) { |
5818 if (_cur_index != -1) { |
5806 // thread is definitely parked |
5819 // thread is definitely parked |
5807 if (WorkAroundNPTLTimedWaitHang) { |
5820 if (WorkAroundNPTLTimedWaitHang) { |
5808 status = pthread_cond_signal (&_cond[_cur_index]); |
5821 status = pthread_cond_signal(&_cond[_cur_index]); |
5809 assert(status == 0, "invariant"); |
5822 assert(status == 0, "invariant"); |
5810 status = pthread_mutex_unlock(_mutex); |
5823 status = pthread_mutex_unlock(_mutex); |
5811 assert(status == 0, "invariant"); |
5824 assert(status == 0, "invariant"); |
5812 } else { |
5825 } else { |
5813 status = pthread_mutex_unlock(_mutex); |
5826 status = pthread_mutex_unlock(_mutex); |
5814 assert(status == 0, "invariant"); |
5827 assert(status == 0, "invariant"); |
5815 status = pthread_cond_signal (&_cond[_cur_index]); |
5828 status = pthread_cond_signal(&_cond[_cur_index]); |
5816 assert(status == 0, "invariant"); |
5829 assert(status == 0, "invariant"); |
5817 } |
5830 } |
5818 } else { |
5831 } else { |
5819 pthread_mutex_unlock(_mutex); |
5832 pthread_mutex_unlock(_mutex); |
5820 assert(status == 0, "invariant"); |
5833 assert(status == 0, "invariant"); |
5923 // Get path to libjvm.so |
5936 // Get path to libjvm.so |
5924 os::jvm_path(buf, sizeof(buf)); |
5937 os::jvm_path(buf, sizeof(buf)); |
5925 |
5938 |
5926 // Get rid of libjvm.so |
5939 // Get rid of libjvm.so |
5927 p = strrchr(buf, '/'); |
5940 p = strrchr(buf, '/'); |
5928 if (p == NULL) return false; |
5941 if (p == NULL) { |
5929 else *p = '\0'; |
5942 return false; |
|
5943 } else { |
|
5944 *p = '\0'; |
|
5945 } |
5930 |
5946 |
5931 // Get rid of client or server |
5947 // Get rid of client or server |
5932 p = strrchr(buf, '/'); |
5948 p = strrchr(buf, '/'); |
5933 if (p == NULL) return false; |
5949 if (p == NULL) { |
5934 else *p = '\0'; |
5950 return false; |
|
5951 } else { |
|
5952 *p = '\0'; |
|
5953 } |
5935 |
5954 |
5936 // check xawt/libmawt.so |
5955 // check xawt/libmawt.so |
5937 strcpy(libmawtpath, buf); |
5956 strcpy(libmawtpath, buf); |
5938 strcat(libmawtpath, xawtstr); |
5957 strcat(libmawtpath, xawtstr); |
5939 if (::stat(libmawtpath, &statbuf) == 0) return false; |
5958 if (::stat(libmawtpath, &statbuf) == 0) return false; |