Mercurial > hg > graal-jvmci-8
comparison src/os/linux/vm/os_linux.cpp @ 235:9c2ecc2ffb12 jdk7-b31
Merge
author | trims |
---|---|
date | Fri, 11 Jul 2008 01:14:44 -0700 |
parents | d1605aabd0a1 f139919897d2 |
children | 1fdb98a17101 |
comparison
equal
deleted
inserted
replaced
197:de141433919f | 235:9c2ecc2ffb12 |
---|---|
73 pthread_t os::Linux::_main_thread; | 73 pthread_t os::Linux::_main_thread; |
74 int os::Linux::_page_size = -1; | 74 int os::Linux::_page_size = -1; |
75 bool os::Linux::_is_floating_stack = false; | 75 bool os::Linux::_is_floating_stack = false; |
76 bool os::Linux::_is_NPTL = false; | 76 bool os::Linux::_is_NPTL = false; |
77 bool os::Linux::_supports_fast_thread_cpu_time = false; | 77 bool os::Linux::_supports_fast_thread_cpu_time = false; |
78 char * os::Linux::_glibc_version = NULL; | 78 const char * os::Linux::_glibc_version = NULL; |
79 char * os::Linux::_libpthread_version = NULL; | 79 const char * os::Linux::_libpthread_version = NULL; |
80 | 80 |
81 static jlong initial_time_count=0; | 81 static jlong initial_time_count=0; |
82 | 82 |
83 static int clock_tics_per_sec = 100; | 83 static int clock_tics_per_sec = 100; |
84 | 84 |
211 // Most versions of linux have a bug where the number of processors are | 211 // Most versions of linux have a bug where the number of processors are |
212 // determined by looking at the /proc file system. In a chroot environment, | 212 // determined by looking at the /proc file system. In a chroot environment, |
213 // the system call returns 1. This causes the VM to act as if it is | 213 // the system call returns 1. This causes the VM to act as if it is |
214 // a single processor and elide locking (see is_MP() call). | 214 // a single processor and elide locking (see is_MP() call). |
215 static bool unsafe_chroot_detected = false; | 215 static bool unsafe_chroot_detected = false; |
216 static char *unstable_chroot_error = "/proc file system not found.\n" | 216 static const char *unstable_chroot_error = "/proc file system not found.\n" |
217 "Java may be unstable running multithreaded in a chroot " | 217 "Java may be unstable running multithreaded in a chroot " |
218 "environment on Linux when /proc filesystem is not mounted."; | 218 "environment on Linux when /proc filesystem is not mounted."; |
219 | 219 |
220 void os::Linux::initialize_system_info() { | 220 void os::Linux::initialize_system_info() { |
221 _processor_count = sysconf(_SC_NPROCESSORS_CONF); | 221 _processor_count = sysconf(_SC_NPROCESSORS_CONF); |
222 if (_processor_count == 1) { | 222 if (_processor_count == 1) { |
223 pid_t pid = os::Linux::gettid(); | 223 pid_t pid = os::Linux::gettid(); |
542 | 542 |
543 n = confstr(_CS_GNU_LIBPTHREAD_VERSION, NULL, 0); | 543 n = confstr(_CS_GNU_LIBPTHREAD_VERSION, NULL, 0); |
544 if (n > 0) { | 544 if (n > 0) { |
545 char *str = (char *)malloc(n); | 545 char *str = (char *)malloc(n); |
546 confstr(_CS_GNU_LIBPTHREAD_VERSION, str, n); | 546 confstr(_CS_GNU_LIBPTHREAD_VERSION, str, n); |
547 | |
548 // Vanilla RH-9 (glibc 2.3.2) has a bug that confstr() always tells | 547 // Vanilla RH-9 (glibc 2.3.2) has a bug that confstr() always tells |
549 // us "NPTL-0.29" even we are running with LinuxThreads. Check if this | 548 // us "NPTL-0.29" even we are running with LinuxThreads. Check if this |
550 // is the case: | 549 // is the case. LinuxThreads has a hard limit on max number of threads. |
550 // So sysconf(_SC_THREAD_THREADS_MAX) will return a positive value. | |
551 // On the other hand, NPTL does not have such a limit, sysconf() | |
552 // will return -1 and errno is not changed. Check if it is really NPTL. | |
551 if (strcmp(os::Linux::glibc_version(), "glibc 2.3.2") == 0 && | 553 if (strcmp(os::Linux::glibc_version(), "glibc 2.3.2") == 0 && |
552 strstr(str, "NPTL")) { | 554 strstr(str, "NPTL") && |
553 // LinuxThreads has a hard limit on max number of threads. So | 555 sysconf(_SC_THREAD_THREADS_MAX) > 0) { |
554 // sysconf(_SC_THREAD_THREADS_MAX) will return a positive value. | 556 free(str); |
555 // On the other hand, NPTL does not have such a limit, sysconf() | 557 os::Linux::set_libpthread_version("linuxthreads"); |
556 // will return -1 and errno is not changed. Check if it is really | 558 } else { |
557 // NPTL: | 559 os::Linux::set_libpthread_version(str); |
558 if (sysconf(_SC_THREAD_THREADS_MAX) > 0) { | |
559 free(str); | |
560 str = "linuxthreads"; | |
561 } | |
562 } | 560 } |
563 os::Linux::set_libpthread_version(str); | |
564 } else { | 561 } else { |
565 // glibc before 2.3.2 only has LinuxThreads. | 562 // glibc before 2.3.2 only has LinuxThreads. |
566 os::Linux::set_libpthread_version("linuxthreads"); | 563 os::Linux::set_libpthread_version("linuxthreads"); |
567 } | 564 } |
568 | 565 |
569 if (strstr(libpthread_version(), "NPTL")) { | 566 if (strstr(libpthread_version(), "NPTL")) { |
570 os::Linux::set_is_NPTL(); | 567 os::Linux::set_is_NPTL(); |
571 } else { | 568 } else { |
4630 // Run the specified command in a separate process. Return its exit value, | 4627 // Run the specified command in a separate process. Return its exit value, |
4631 // or -1 on failure (e.g. can't fork a new process). | 4628 // or -1 on failure (e.g. can't fork a new process). |
4632 // Unlike system(), this function can be called from signal handler. It | 4629 // Unlike system(), this function can be called from signal handler. It |
4633 // doesn't block SIGINT et al. | 4630 // doesn't block SIGINT et al. |
4634 int os::fork_and_exec(char* cmd) { | 4631 int os::fork_and_exec(char* cmd) { |
4635 char * argv[4]; | 4632 const char * argv[4] = {"sh", "-c", cmd, NULL}; |
4636 argv[0] = "sh"; | |
4637 argv[1] = "-c"; | |
4638 argv[2] = cmd; | |
4639 argv[3] = NULL; | |
4640 | 4633 |
4641 // fork() in LinuxThreads/NPTL is not async-safe. It needs to run | 4634 // fork() in LinuxThreads/NPTL is not async-safe. It needs to run |
4642 // pthread_atfork handlers and reset pthread library. All we need is a | 4635 // pthread_atfork handlers and reset pthread library. All we need is a |
4643 // separate process to execve. Make a direct syscall to fork process. | 4636 // separate process to execve. Make a direct syscall to fork process. |
4644 // On IA64 there's no fork syscall, we have to use fork() and hope for | 4637 // On IA64 there's no fork syscall, we have to use fork() and hope for |
4659 // every thread in the parent process. We know this is the only thread | 4652 // every thread in the parent process. We know this is the only thread |
4660 // in the new process, so make a system call directly. | 4653 // in the new process, so make a system call directly. |
4661 // IA64 should use normal execve() from glibc to match the glibc fork() | 4654 // IA64 should use normal execve() from glibc to match the glibc fork() |
4662 // above. | 4655 // above. |
4663 NOT_IA64(syscall(__NR_execve, "/bin/sh", argv, environ);) | 4656 NOT_IA64(syscall(__NR_execve, "/bin/sh", argv, environ);) |
4664 IA64_ONLY(execve("/bin/sh", argv, environ);) | 4657 IA64_ONLY(execve("/bin/sh", (char* const*)argv, environ);) |
4665 | 4658 |
4666 // execve failed | 4659 // execve failed |
4667 _exit(-1); | 4660 _exit(-1); |
4668 | 4661 |
4669 } else { | 4662 } else { |