Mercurial > hg > graal-jvmci-8
comparison src/os/linux/vm/os_linux.cpp @ 348:69fefd031e6c
Merge
author | ysr |
---|---|
date | Tue, 24 Jun 2008 13:20:34 -0700 |
parents | 37f87013dfd8 f139919897d2 |
children | 1ee8caae33af |
comparison
equal
deleted
inserted
replaced
347:60fb9c4db4e6 | 348:69fefd031e6c |
---|---|
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 { |
4641 // Run the specified command in a separate process. Return its exit value, | 4638 // Run the specified command in a separate process. Return its exit value, |
4642 // or -1 on failure (e.g. can't fork a new process). | 4639 // or -1 on failure (e.g. can't fork a new process). |
4643 // Unlike system(), this function can be called from signal handler. It | 4640 // Unlike system(), this function can be called from signal handler. It |
4644 // doesn't block SIGINT et al. | 4641 // doesn't block SIGINT et al. |
4645 int os::fork_and_exec(char* cmd) { | 4642 int os::fork_and_exec(char* cmd) { |
4646 char * argv[4]; | 4643 const char * argv[4] = {"sh", "-c", cmd, NULL}; |
4647 argv[0] = "sh"; | |
4648 argv[1] = "-c"; | |
4649 argv[2] = cmd; | |
4650 argv[3] = NULL; | |
4651 | 4644 |
4652 // fork() in LinuxThreads/NPTL is not async-safe. It needs to run | 4645 // fork() in LinuxThreads/NPTL is not async-safe. It needs to run |
4653 // pthread_atfork handlers and reset pthread library. All we need is a | 4646 // pthread_atfork handlers and reset pthread library. All we need is a |
4654 // separate process to execve. Make a direct syscall to fork process. | 4647 // separate process to execve. Make a direct syscall to fork process. |
4655 // On IA64 there's no fork syscall, we have to use fork() and hope for | 4648 // On IA64 there's no fork syscall, we have to use fork() and hope for |
4670 // every thread in the parent process. We know this is the only thread | 4663 // every thread in the parent process. We know this is the only thread |
4671 // in the new process, so make a system call directly. | 4664 // in the new process, so make a system call directly. |
4672 // IA64 should use normal execve() from glibc to match the glibc fork() | 4665 // IA64 should use normal execve() from glibc to match the glibc fork() |
4673 // above. | 4666 // above. |
4674 NOT_IA64(syscall(__NR_execve, "/bin/sh", argv, environ);) | 4667 NOT_IA64(syscall(__NR_execve, "/bin/sh", argv, environ);) |
4675 IA64_ONLY(execve("/bin/sh", argv, environ);) | 4668 IA64_ONLY(execve("/bin/sh", (char* const*)argv, environ);) |
4676 | 4669 |
4677 // execve failed | 4670 // execve failed |
4678 _exit(-1); | 4671 _exit(-1); |
4679 | 4672 |
4680 } else { | 4673 } else { |