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