hotspot/src/os/bsd/vm/osThread_bsd.hpp
author dsamersoff
Thu, 03 Oct 2013 12:39:58 +0400
changeset 20377 393ee12eccc8
parent 18025 b7bcf7497f93
permissions -rw-r--r--
8022616: u4 should not be used as a type for thread_id Summary: Usage of u4 as a type for thread_id cause a compilation error on platform, where thread_id is a pointer Reviewed-by: sla, sspitsyn, minqi
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     1
/*
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 15593
diff changeset
     2
 * Copyright (c) 1999, 2013, 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
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
    42
#ifdef __APPLE__
12765
3e1b42265329 7161732: Improve handling of thread_id in OSThread
rbackman
parents: 12377
diff changeset
    43
  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
    44
#else
20377
393ee12eccc8 8022616: u4 should not be used as a type for thread_id
dsamersoff
parents: 18025
diff changeset
    45
  typedef pid_t thread_id_t;
12765
3e1b42265329 7161732: Improve handling of thread_id in OSThread
rbackman
parents: 12377
diff changeset
    46
#endif
3e1b42265329 7161732: Improve handling of thread_id in OSThread
rbackman
parents: 12377
diff changeset
    47
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
    48
  // _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
    49
  // (e.g. pthread_kill).
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    50
  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
    51
15593
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 14286
diff changeset
    52
  // This is the "thread_id" from struct thread_identifier_info. According to a
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 14286
diff changeset
    53
  // comment in thread_info.h, this is a "system-wide unique 64-bit thread id".
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 14286
diff changeset
    54
  // The value is used by SA to correlate threads.
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 14286
diff changeset
    55
  uint64_t _unique_thread_id;
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 14286
diff changeset
    56
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    57
  sigset_t _caller_sigmask; // Caller's signal mask
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    58
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    59
 public:
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    60
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    61
  // Methods to save/restore caller's signal mask
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    62
  sigset_t  caller_sigmask() const       { return _caller_sigmask; }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    63
  void    set_caller_sigmask(sigset_t sigmask)  { _caller_sigmask = sigmask; }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    64
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    65
#ifndef PRODUCT
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    66
  // Used for debugging, return a unique integer for each thread.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    67
  intptr_t thread_identifier() const   { return (intptr_t)_pthread_id; }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    68
#endif
12765
3e1b42265329 7161732: Improve handling of thread_id in OSThread
rbackman
parents: 12377
diff changeset
    69
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    70
#ifdef ASSERT
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    71
  // We expect no reposition failures so kill vm if we get one.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    72
  //
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    73
  bool valid_reposition_failure() {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    74
    return false;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    75
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    76
#endif // ASSERT
12765
3e1b42265329 7161732: Improve handling of thread_id in OSThread
rbackman
parents: 12377
diff changeset
    77
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    78
  pthread_t pthread_id() const {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    79
    return _pthread_id;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    80
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    81
  void set_pthread_id(pthread_t tid) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    82
    _pthread_id = tid;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    83
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    84
15593
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 14286
diff changeset
    85
  void set_unique_thread_id(uint64_t id) {
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 14286
diff changeset
    86
    _unique_thread_id = id;
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 14286
diff changeset
    87
  }
860cf6c70c06 8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
sla
parents: 14286
diff changeset
    88
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    89
  // ***************************************************************
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    90
  // suspension support.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    91
  // ***************************************************************
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    92
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    93
public:
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    94
  // flags that support signal based suspend/resume on Bsd are in a
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    95
  // separate class to avoid confusion with many flags in OSThread that
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    96
  // are used by VM level suspend/resume.
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 15593
diff changeset
    97
  os::SuspendResume sr;
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    98
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    99
  // _ucontext and _siginfo are used by SR_handler() to save thread context,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   100
  // and they will later be used to walk the stack or reposition thread PC.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   101
  // If the thread is not suspended in SR_handler() (e.g. self suspend),
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   102
  // the value in _ucontext is meaningless, so we must use the last Java
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   103
  // frame information as the frame. This will mean that for threads
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   104
  // that are parked on a mutex the profiler (and safepoint mechanism)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   105
  // will see the thread as if it were still in the Java frame. This
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   106
  // not a problem for the profiler since the Java frame is a close
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   107
  // enough result. For the safepoint mechanism when the give it the
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   108
  // Java frame we are not at a point where the safepoint needs the
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   109
  // frame to that accurate (like for a compiled safepoint) since we
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   110
  // should be in a place where we are native and will block ourselves
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   111
  // if we transition.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   112
private:
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   113
  void* _siginfo;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   114
  ucontext_t* _ucontext;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   115
  int _expanding_stack;                 /* non zero if manually expanding stack */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   116
  address _alt_sig_stack;               /* address of base of alternate signal stack */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   117
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   118
public:
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   119
  void* siginfo() const                   { return _siginfo;  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   120
  void set_siginfo(void* ptr)             { _siginfo = ptr;   }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   121
  ucontext_t* ucontext() const            { return _ucontext; }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   122
  void set_ucontext(ucontext_t* ptr)      { _ucontext = ptr;  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   123
  void set_expanding_stack(void)          { _expanding_stack = 1;  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   124
  void clear_expanding_stack(void)        { _expanding_stack = 0;  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   125
  int  expanding_stack(void)              { return _expanding_stack;  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   126
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   127
  void set_alt_sig_stack(address val)     { _alt_sig_stack = val; }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   128
  address alt_sig_stack(void)             { return _alt_sig_stack; }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   129
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   130
private:
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   131
  Monitor* _startThread_lock;     // sync parent and child in thread creation
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   132
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   133
public:
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   134
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   135
  Monitor* startThread_lock() const {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   136
    return _startThread_lock;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   137
  }
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
  // Platform dependent initialization and cleanup
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   141
  // ***************************************************************
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   142
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   143
private:
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   144
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   145
  void pd_initialize();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   146
  void pd_destroy();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   147
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   148
// Reconciliation History
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   149
// osThread_solaris.hpp 1.24 99/08/27 13:11:54
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   150
// End
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   151
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   152
#endif // OS_BSD_VM_OSTHREAD_BSD_HPP