duke@435: /* trims@1907: * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: duke@435: // This is embedded via include into the class OSThread duke@435: duke@435: private: duke@435: duke@435: thread_t _thread_id; // Solaris thread id duke@435: unsigned int _lwp_id; // lwp ID, only used with bound threads duke@435: sigset_t _caller_sigmask; // Caller's signal mask duke@435: bool _vm_created_thread; // true if the VM create this thread duke@435: // false if primary thread or attached thread duke@435: public: duke@435: duke@435: thread_t thread_id() const { return _thread_id; } duke@435: duke@435: unsigned int lwp_id() const { return _lwp_id; } duke@435: duke@435: // Set and get state of _vm_created_thread flag duke@435: void set_vm_created() { _vm_created_thread = true; } duke@435: bool is_vm_created() { return _vm_created_thread; } duke@435: duke@435: // Methods to save/restore caller's signal mask duke@435: sigset_t caller_sigmask() const { return _caller_sigmask; } duke@435: void set_caller_sigmask(sigset_t sigmask) { _caller_sigmask = sigmask; } duke@435: duke@435: #ifndef PRODUCT duke@435: // Used for debugging, return a unique integer for each thread. duke@435: int thread_identifier() const { return _thread_id; } duke@435: #endif duke@435: #ifdef ASSERT duke@435: // On solaris reposition can fail in two ways: duke@435: // 1: a mismatched pc, because signal is delivered too late, target thread duke@435: // is resumed. duke@435: // 2: on a timeout where signal is lost, target thread is resumed. duke@435: bool valid_reposition_failure() { duke@435: // only 1 and 2 can happen and we can handle both of them duke@435: return true; duke@435: } duke@435: #endif duke@435: void set_thread_id(thread_t id) { _thread_id = id; } duke@435: void set_lwp_id(unsigned int id){ _lwp_id = id; } duke@435: duke@435: // *************************************************************** duke@435: // interrupt support. interrupts (using signals) are used to get duke@435: // the thread context (get_thread_pc), to set the thread context duke@435: // (set_thread_pc), and to implement java.lang.Thread.interrupt. duke@435: // *************************************************************** duke@435: duke@435: public: duke@435: duke@435: class InterruptArguments : StackObj { duke@435: private: duke@435: Thread* _thread; // the thread to signal was dispatched to duke@435: ucontext_t* _ucontext; // the machine context at the time of the signal duke@435: duke@435: public: duke@435: InterruptArguments(Thread* thread, ucontext_t* ucontext) { duke@435: _thread = thread; duke@435: _ucontext = ucontext; duke@435: } duke@435: duke@435: Thread* thread() const { return _thread; } duke@435: ucontext_t* ucontext() const { return _ucontext; } duke@435: }; duke@435: duke@435: // There are currently no asynchronous callbacks - and we'd better not duke@435: // support them in the future either, as they need to be deallocated from duke@435: // the interrupt handler, which is not safe; they also require locks to duke@435: // protect the callback queue. duke@435: duke@435: class Sync_Interrupt_Callback : private StackObj { duke@435: protected: duke@435: volatile bool _is_done; duke@435: Monitor* _sync; duke@435: Thread* _target; duke@435: public: duke@435: Sync_Interrupt_Callback(Monitor * sync) { duke@435: _is_done = false; _target = NULL; _sync = sync; duke@435: } duke@435: duke@435: bool is_done() const { return _is_done; } duke@435: Thread* target() const { return _target; } duke@435: duke@435: int interrupt(Thread * target, int timeout); duke@435: duke@435: // override to implement the callback. duke@435: virtual void execute(InterruptArguments *args) = 0; duke@435: duke@435: void leave_callback(); duke@435: }; duke@435: duke@435: private: duke@435: duke@435: Sync_Interrupt_Callback * volatile _current_callback; duke@435: enum { duke@435: callback_in_progress = 1 duke@435: }; duke@435: Mutex * _current_callback_lock; // only used on v8 duke@435: duke@435: public: duke@435: duke@435: int set_interrupt_callback (Sync_Interrupt_Callback * cb); duke@435: void remove_interrupt_callback(Sync_Interrupt_Callback * cb); zgu@1979: void do_interrupt_callbacks_at_interrupt(InterruptArguments *args); duke@435: duke@435: // *************************************************************** duke@435: // java.lang.Thread.interrupt state. duke@435: // *************************************************************** duke@435: duke@435: private: duke@435: duke@435: JavaThreadState _saved_interrupt_thread_state; // the thread state before a system call -- restored afterward duke@435: duke@435: public: duke@435: duke@435: duke@435: JavaThreadState saved_interrupt_thread_state() { return _saved_interrupt_thread_state; } duke@435: void set_saved_interrupt_thread_state(JavaThreadState state) { _saved_interrupt_thread_state = state; } duke@435: duke@435: static void handle_spinlock_contention(int tries); // Used for thread local eden locking duke@435: duke@435: // *************************************************************** duke@435: // Platform dependent initialization and cleanup duke@435: // *************************************************************** duke@435: duke@435: private: duke@435: duke@435: void pd_initialize(); duke@435: void pd_destroy();