Lines Matching defs:thread
184 /* Signal number used to suspend/resume a thread */
309 // Returns the kernel thread id of the currently running thread. Kernel
310 // thread id is used to access /proc.
312 // (Note that getpid() on BsdThreads returns kernel thread id too; but
670 // BREAK_SIGNAL which is unblocked only by the VM thread and blocked by all
675 // interference with shutdown hooks and BREAK_SIGNAL thread dumping.
701 // Fill in signals that are blocked by all but the VM thread.
709 // These are signals that are unblocked while a thread is running Java.
716 // These are the signals that are blocked while a (non-VM) thread is
717 // running Java. Only the VM thread handles these signals.
729 void os::Bsd::hotspot_sigmask(Thread* thread) {
735 OSThread* osthread = thread->osthread();
741 if (thread->is_VM_thread()) {
742 // Only the VM thread handles BREAK_SIGNAL ...
817 // thread stack
819 // Force Bsd kernel to expand current thread stack. If "bottom" is close
823 // A special mmap() flag that is used to implement thread stacks. It tells
826 // when creating a new thread. Bsd kernel will automatically expand thread
837 // This Bsd feature can cause SIGSEGV when VM bangs thread stack for
841 // not use this flag. However, the stack of initial thread is not created
843 // unlikely) that user code can create a thread with MAP_GROWSDOWN stack
844 // and then attach the thread to JVM.
847 // manually expand thread stack after receiving the SIGSEGV.
849 // There are two ways to expand thread stack to address "bottom", we used
918 // create new thread
922 // check if it's safe to start a new thread
923 static bool _thread_safety_check(Thread* thread) {
930 // allocated (MAP_FIXED) from high address space. Every thread stack
936 // many threads and/or very large heap, eventually thread stack will
955 // Unlike fixed stack BsdThreads, thread stacks are not MAP_FIXED. When
986 static void *java_start(Thread *thread) {
996 ThreadLocalStorage::set_thread(thread);
998 OSThread* osthread = thread->osthread();
1002 if (!_thread_safety_check(thread)) {
1003 // notify parent thread
1012 // thread_id is mach thread on macos
1020 // thread_id is kernel thread id (similar to Solaris LWP id)
1026 thread->set_lgrp_id(lgrp_id);
1030 // initialize signal mask for this thread
1031 os::Bsd::hotspot_sigmask(thread);
1037 // register thread with objc gc
1043 // handshaking with parent thread
1047 // notify parent thread
1058 thread->run();
1063 bool os::create_thread(Thread* thread, ThreadType thr_type, size_t stack_size) {
1064 assert(thread->osthread() == NULL, "caller responsible");
1072 // set the correct thread state
1078 thread->set_osthread(osthread);
1080 // init thread attributes
1129 // Serialize thread creation if we are running with fixed stack BsdThreads
1137 int ret = pthread_create(&tid, &attr, (void* (*)(void*)) java_start, thread);
1146 thread->set_osthread(NULL);
1157 // Wait until child thread is either initialized or aborted
1173 // Aborted due to thread limit being reached
1175 thread->set_osthread(NULL);
1180 // The thread is returned suspended (in state INITIALIZED),
1187 // attach existing thread
1189 // bootstrap the main thread
1190 bool os::create_main_thread(JavaThread* thread) {
1191 assert(os::Bsd::_main_thread == pthread_self(), "should be called inside main thread");
1192 return create_attached_thread(thread);
1195 bool os::create_attached_thread(JavaThread* thread) {
1197 thread->verify_not_published();
1223 // Initial thread state is RUNNABLE
1226 thread->set_osthread(osthread);
1232 thread->set_lgrp_id(lgrp_id);
1237 // If current thread is initial thread, its stack is mapped on demand,
1246 JavaThread *jt = (JavaThread *)thread;
1257 // initialize signal mask for this thread
1259 os::Bsd::hotspot_sigmask(thread);
1264 void os::pd_start_thread(Thread* thread) {
1265 OSThread * osthread = thread->osthread();
1286 // thread local storage
1291 assert(rslt == 0, "cannot allocate thread local storage");
1308 return ThreadLocalStorage::thread();
1312 // initial thread
1315 // Check if current thread is the initial thread, similar to Solaris thr_main.
1318 // If called before init complete, thread stack bottom will be null.
1323 "os::init did not locate initial thread's stack region");
1354 // Locate initial thread stack. This special handling of initial thread stack
1356 // bogus value for initial thread.
1373 // for initial thread if its stack size exceeds 6M. Cap it at 2M,
1438 // Figure what the primordial thread stack base is. Code is inspired
1502 // product mode - assume we are the initial thread, good luck in the
1504 warning("Can't detect initial thread stack location - bad conversion");
1511 warning("Can't detect initial thread stack location - no /proc/self/stat");
1527 // thread stack grows on demand, its real bottom is high - RLIMIT_STACK.)
1531 warning("Can't detect initial thread stack location - find_vma failed");
1669 // Switch to using fast clocks for thread cpu time if
1671 // Note, that some kernels may support the current thread
1792 out.print_raw("Current thread is ");
1806 // _exit() on BsdThreads only kills current thread
1840 // Under the old bsd thread library, bsd gives each thread
1841 // its own process id. Because of this each thread will return
1844 // of the launcher thread for the vm. This implementation
1845 // returns a unique pid, the pid of the launcher thread
1849 // launcher thread rather than a unique pid per thread.
1853 // returns a unique pid for the calling thread, then look at the
2612 // 4511530 - sem_post is serialized and handled by the manager thread. When
2613 // the program is interrupted by Ctrl-C, SIGINT is sent to every thread. We
2614 // don't want to flood the manager thread with sem_post requests.
2807 JavaThread *thread = JavaThread::current();
2808 ThreadBlockInVM tbivm(thread);
2812 thread->set_suspend_equivalent();
2817 threadIsSuspended = thread->handle_special_suspend_equivalent_condition();
2821 // another thread suspended us. We don't want to continue running
2822 // while suspended because that would surprise the thread that
2827 thread->java_suspend_self();
3601 int os::sleep(Thread* thread, jlong millis, bool interruptible) {
3602 assert(thread == Thread::current(), "thread consistency check");
3604 ParkEvent * const slp = thread->_SleepEvent ;
3612 if (os::is_interrupted(thread, true)) {
3633 assert(thread->is_Java_thread(), "sanity check");
3634 JavaThread *jt = (JavaThread *) thread;
3649 OSThreadWaitState osts(thread->osthread(), false /* not Object.wait() */);
3710 // thread priority support
3719 // The following code actually changes the niceness of kernel-thread/LWP. It
3720 // has an assumption that setpriority() only modifies one kernel-thread/LWP,
3791 // Only root can raise thread priority. Don't allow ThreadPriorityPolicy=1
3807 OSReturn os::set_native_priority(Thread* thread, int newpri) {
3814 int ret = pthread_setprio(thread->osthread()->pthread_id(), newpri);
3829 int ret = setpriority(PRIO_PROCESS, thread->osthread()->thread_id(), newpri);
3834 OSReturn os::get_native_priority(const Thread* const thread, int *priority_ptr) {
3842 *priority_ptr = pthread_getprio(thread->osthread()->pthread_id());
3850 *priority_ptr = getpriority(PRIO_PROCESS, thread->osthread()->thread_id());
3866 // that runs in the watcher thread.
3872 // - sends a signal to the target thread
3874 // - target thread signal handler (SR_handler) sets suspend state
3894 // Handler function invoked when a thread's execution is suspended or
3912 Thread* thread = Thread::current();
3913 OSThread* osthread = thread->osthread();
3914 assert(thread->is_VM_thread() || thread->is_Java_thread(), "Must be VMThread or JavaThread");
4010 // before bailing out on suspending a thread, also how often
4011 // we send a signal to a thread we want to resume
4018 assert(osthread->sr.is_running(), "thread should be running");
4057 assert(osthread->sr.is_suspended(), "thread should be suspended");
4084 void os::interrupt(Thread* thread) {
4085 assert(Thread::current() == thread || Threads_lock->owned_by_self(),
4088 OSThread* osthread = thread->osthread();
4092 // More than one thread can get here with the same value of osthread,
4096 ParkEvent * const slp = thread->_SleepEvent ;
4101 if (thread->is_Java_thread())
4102 ((JavaThread*)thread)->parker()->unpark();
4104 ParkEvent * ev = thread->_ParkEvent ;
4109 bool os::is_interrupted(Thread* thread, bool clear_interrupted) {
4110 assert(Thread::current() == thread || Threads_lock->owned_by_self(),
4113 OSThread* osthread = thread->osthread();
4119 // consider thread->_SleepEvent->reset() ... optional optimization
4307 // Needed for main thread as XNU (Mac OS X kernel) will only deliver SIGSEGV
4308 // (which starts as SIGBUS) on main thread with faulting address inside "stack+guard pages"
4408 // This is the fastest way to get thread cpu time on Bsd.
4409 // Returns cpu time (user+sys) for any thread, not only for current.
4634 // With BsdThreads the JavaMain thread pid (primordial thread)
4635 // is different than the pid of the java launcher thread.
4636 // So, on Bsd, the launcher thread pid is passed to the VM
4659 // main_thread points to the aboriginal thread
4723 // Check minimum allowable stack size for thread creation and to initialize
4725 // size. Add a page for compiler2 recursion in main thread.
4815 // Initialize lock used to serialize thread creation (see os::create_thread)
4838 // initialize thread priority policy
4913 PcFetcher(Thread* thread) : os::SuspendedThreadTask(thread) {}
4927 Thread* thread = context.thread();
4928 OSThread* osthread = thread->osthread();
4933 guarantee(thread->is_VM_thread(), "can only be called for VMThread");
4939 ExtendedPC os::get_thread_pc(Thread* thread) {
4942 assert(thread->is_VM_thread(), "Can only be called for VMThread");
4944 PcFetcher fetcher(thread);
5028 // able to use structured exception handling (thread-local exception filters)
5032 JavaCallArguments* args, Thread* thread) {
5033 f(value, method, args, thread);
5290 static jlong slow_thread_cpu_time(Thread *thread, bool user_sys_cpu_time);
5292 static clockid_t thread_cpu_clockid(Thread* thread) {
5293 pthread_t tid = thread->osthread()->pthread_id();
5296 // Get thread clockid
5305 // of a thread.
5323 jlong os::thread_cpu_time(Thread* thread) {
5327 return os::Bsd::fast_thread_cpu_time(thread_cpu_clockid(thread));
5329 return slow_thread_cpu_time(thread, true /* user + sys */);
5346 jlong os::thread_cpu_time(Thread *thread, bool user_sys_cpu_time) {
5353 mach_thread = thread->osthread()->thread_id();
5368 return os::Bsd::fast_thread_cpu_time(thread_cpu_clockid(thread));
5370 return slow_thread_cpu_time(thread, user_sys_cpu_time);
5380 static jlong slow_thread_cpu_time(Thread *thread, bool user_sys_cpu_time) {
5384 pid_t tid = thread->osthread()->thread_id();
5420 // The /proc/self/task/<tid>/stat still has the per-thread usage.
5537 // This is palliative and probabilistic, however. If the thread is preempted
5543 // 2. Modify park-unpark to use per-thread (per ParkEvent) pipe-pairs instead
5547 // thread.
5549 // 3. Embargo pthread_cond_timedwait() and implement a native "chron" thread
5551 // a timeout request to the chron thread and then blocking via pthread_cond_wait().
5616 // Invariant: Only the thread associated with the Event/PlatformEvent
5661 // We do this the hard way, by blocking the thread.
5675 // (c) thread.interrupt
5678 // That is, we treat thread.interrupt as a special case of notification.
5718 // -1 :=> either 0 or 1; must signal target thread
5726 // thread to block. This has the benefit of forcing a spurious return
5732 // Wait for the thread associated with the event to vacate
5750 // circumstances this can cause a thread to return prematurely from
5764 * sets count to 1 and signals condvar. Only one thread ever waits
5840 Thread* thread = Thread::current();
5841 assert(thread->is_Java_thread(), "Must be JavaThread");
5842 JavaThread *jt = (JavaThread *)thread;
5846 if (Thread::is_interrupted(thread, false)) {
5862 // The per-thread Parker:: mutex is a classic leaf-lock.
5863 // In particular a thread must never block on the Threads_lock while
5870 if (Thread::is_interrupted(thread, false) || pthread_mutex_trylock(_mutex) != 0) {
5887 // (This allows a debugger to break into the running thread.)
5893 OSThreadWaitState osts(thread->osthread(), false /* not Object.wait() */);
5982 // first to kill every thread on the thread list. Because this list is
5984 // every thread in the parent process. We know this is the only thread