Tue, 22 May 2012 10:11:53 +0200
7161732: Improve handling of thread_id in OSThread
Reviewed-by: dholmes, kamg
duke@435 | 1 | /* |
rbackman@3709 | 2 | * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
stefank@2314 | 25 | #ifndef OS_LINUX_VM_OSTHREAD_LINUX_HPP |
stefank@2314 | 26 | #define OS_LINUX_VM_OSTHREAD_LINUX_HPP |
rbackman@3796 | 27 | public: |
rbackman@3796 | 28 | typedef pid_t thread_id_t; |
stefank@2314 | 29 | |
duke@435 | 30 | private: |
duke@435 | 31 | int _thread_type; |
duke@435 | 32 | |
duke@435 | 33 | public: |
duke@435 | 34 | |
duke@435 | 35 | int thread_type() const { |
duke@435 | 36 | return _thread_type; |
duke@435 | 37 | } |
duke@435 | 38 | void set_thread_type(int type) { |
duke@435 | 39 | _thread_type = type; |
duke@435 | 40 | } |
duke@435 | 41 | |
duke@435 | 42 | // _pthread_id is the pthread id, which is used by library calls |
duke@435 | 43 | // (e.g. pthread_kill). |
duke@435 | 44 | pthread_t _pthread_id; |
duke@435 | 45 | |
duke@435 | 46 | sigset_t _caller_sigmask; // Caller's signal mask |
duke@435 | 47 | |
duke@435 | 48 | public: |
duke@435 | 49 | |
duke@435 | 50 | // Methods to save/restore caller's signal mask |
duke@435 | 51 | sigset_t caller_sigmask() const { return _caller_sigmask; } |
duke@435 | 52 | void set_caller_sigmask(sigset_t sigmask) { _caller_sigmask = sigmask; } |
duke@435 | 53 | |
duke@435 | 54 | #ifndef PRODUCT |
duke@435 | 55 | // Used for debugging, return a unique integer for each thread. |
duke@435 | 56 | int thread_identifier() const { return _thread_id; } |
duke@435 | 57 | #endif |
duke@435 | 58 | #ifdef ASSERT |
duke@435 | 59 | // We expect no reposition failures so kill vm if we get one. |
duke@435 | 60 | // |
duke@435 | 61 | bool valid_reposition_failure() { |
duke@435 | 62 | return false; |
duke@435 | 63 | } |
duke@435 | 64 | #endif // ASSERT |
duke@435 | 65 | pthread_t pthread_id() const { |
duke@435 | 66 | return _pthread_id; |
duke@435 | 67 | } |
duke@435 | 68 | void set_pthread_id(pthread_t tid) { |
duke@435 | 69 | _pthread_id = tid; |
duke@435 | 70 | } |
duke@435 | 71 | |
duke@435 | 72 | // *************************************************************** |
duke@435 | 73 | // suspension support. |
duke@435 | 74 | // *************************************************************** |
duke@435 | 75 | |
duke@435 | 76 | public: |
duke@435 | 77 | // flags that support signal based suspend/resume on Linux are in a |
duke@435 | 78 | // separate class to avoid confusion with many flags in OSThread that |
duke@435 | 79 | // are used by VM level suspend/resume. |
duke@435 | 80 | os::Linux::SuspendResume sr; |
duke@435 | 81 | |
duke@435 | 82 | // _ucontext and _siginfo are used by SR_handler() to save thread context, |
duke@435 | 83 | // and they will later be used to walk the stack or reposition thread PC. |
duke@435 | 84 | // If the thread is not suspended in SR_handler() (e.g. self suspend), |
duke@435 | 85 | // the value in _ucontext is meaningless, so we must use the last Java |
duke@435 | 86 | // frame information as the frame. This will mean that for threads |
duke@435 | 87 | // that are parked on a mutex the profiler (and safepoint mechanism) |
duke@435 | 88 | // will see the thread as if it were still in the Java frame. This |
duke@435 | 89 | // not a problem for the profiler since the Java frame is a close |
duke@435 | 90 | // enough result. For the safepoint mechanism when the give it the |
duke@435 | 91 | // Java frame we are not at a point where the safepoint needs the |
duke@435 | 92 | // frame to that accurate (like for a compiled safepoint) since we |
duke@435 | 93 | // should be in a place where we are native and will block ourselves |
duke@435 | 94 | // if we transition. |
duke@435 | 95 | private: |
duke@435 | 96 | void* _siginfo; |
duke@435 | 97 | ucontext_t* _ucontext; |
duke@435 | 98 | int _expanding_stack; /* non zero if manually expanding stack */ |
duke@435 | 99 | address _alt_sig_stack; /* address of base of alternate signal stack */ |
duke@435 | 100 | |
duke@435 | 101 | public: |
duke@435 | 102 | void* siginfo() const { return _siginfo; } |
duke@435 | 103 | void set_siginfo(void* ptr) { _siginfo = ptr; } |
duke@435 | 104 | ucontext_t* ucontext() const { return _ucontext; } |
duke@435 | 105 | void set_ucontext(ucontext_t* ptr) { _ucontext = ptr; } |
duke@435 | 106 | void set_expanding_stack(void) { _expanding_stack = 1; } |
duke@435 | 107 | void clear_expanding_stack(void) { _expanding_stack = 0; } |
duke@435 | 108 | int expanding_stack(void) { return _expanding_stack; } |
duke@435 | 109 | |
duke@435 | 110 | void set_alt_sig_stack(address val) { _alt_sig_stack = val; } |
duke@435 | 111 | address alt_sig_stack(void) { return _alt_sig_stack; } |
duke@435 | 112 | |
duke@435 | 113 | private: |
duke@435 | 114 | Monitor* _startThread_lock; // sync parent and child in thread creation |
duke@435 | 115 | |
duke@435 | 116 | public: |
duke@435 | 117 | |
duke@435 | 118 | Monitor* startThread_lock() const { |
duke@435 | 119 | return _startThread_lock; |
duke@435 | 120 | } |
duke@435 | 121 | |
duke@435 | 122 | // *************************************************************** |
duke@435 | 123 | // Platform dependent initialization and cleanup |
duke@435 | 124 | // *************************************************************** |
duke@435 | 125 | |
duke@435 | 126 | private: |
duke@435 | 127 | |
duke@435 | 128 | void pd_initialize(); |
duke@435 | 129 | void pd_destroy(); |
duke@435 | 130 | |
duke@435 | 131 | // Reconciliation History |
duke@435 | 132 | // osThread_solaris.hpp 1.24 99/08/27 13:11:54 |
duke@435 | 133 | // End |
stefank@2314 | 134 | |
stefank@2314 | 135 | #endif // OS_LINUX_VM_OSTHREAD_LINUX_HPP |