hotspot/src/share/vm/runtime/osThread.hpp
author twisti
Mon, 14 Dec 2015 17:02:02 -1000
changeset 35123 b0b89d83bcf5
parent 22827 07d991d45a51
child 37466 287c4ebd11b0
permissions -rw-r--r--
8134994: use separate VMStructs databases for SA and JVMCI Reviewed-by: kbarrett
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
12377
ae6def2813e0 7160570: Intrinsification support for tracing framework
rbackman
parents: 10565
diff changeset
     2
 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#ifndef SHARE_VM_RUNTIME_OSTHREAD_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#define SHARE_VM_RUNTIME_OSTHREAD_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "runtime/frame.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "runtime/handles.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "runtime/javaFrameAnchor.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "runtime/objectMonitor.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
#include "utilities/top.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    33
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// The OSThread class holds OS-specific thread information.  It is equivalent
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// to the sys_thread_t structure of the classic JVM implementation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// The thread states represented by the ThreadState values are platform-specific
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
// and are likely to be only approximate, because most OSes don't give you access
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
// to precise thread state information.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
// Note: the ThreadState is legacy code and is not correctly implemented.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
// Uses of ThreadState need to be replaced by the state in the JavaThread.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
enum ThreadState {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  ALLOCATED,                    // Memory has been allocated but not initialized
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  INITIALIZED,                  // The thread has been initialized but yet started
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  RUNNABLE,                     // Has been started and is runnable, but not necessarily running
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  MONITOR_WAIT,                 // Waiting on a contended monitor lock
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  CONDVAR_WAIT,                 // Waiting on a condition variable
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  OBJECT_WAIT,                  // Waiting on an Object.wait() call
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  BREAKPOINTED,                 // Suspended at breakpoint
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  SLEEPING,                     // Thread.sleep()
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  ZOMBIE                        // All done, but not reclaimed yet
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
// I'd make OSThread a ValueObj embedded in Thread to avoid an indirection, but
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
// the assembler test in java.cpp expects that it can install the OSThread of
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
// the main thread into its own Thread at will.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12765
diff changeset
    61
class OSThread: public CHeapObj<mtThread> {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  friend class VMStructs;
35123
b0b89d83bcf5 8134994: use separate VMStructs databases for SA and JVMCI
twisti
parents: 22827
diff changeset
    63
  friend class JVMCIVMStructs;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  OSThreadStartFunc _start_proc;  // Thread start routine
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  void* _start_parm;              // Thread start routine parameter
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  volatile ThreadState _state;    // Thread state *hint*
8735
9829dda3b405 6535709: interrupt of wait()ing thread isn't triggerring InterruptedException - test intwait3
dholmes
parents: 7405
diff changeset
    68
  volatile jint _interrupted;     // Thread.isInterrupted state
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  // Note:  _interrupted must be jint, so that Java intrinsics can access it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  // The value stored there must be either 0 or 1.  It must be possible
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  // for Java to emulate Thread.currentThread().isInterrupted() by performing
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  // the double indirection Thread::current()->_osthread->_interrupted.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  // Methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  void set_state(ThreadState state)                { _state = state; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  ThreadState get_state()                          { return _state; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  OSThread(OSThreadStartFunc start_proc, void* start_parm);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  ~OSThread();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  // Accessors
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  OSThreadStartFunc start_proc() const              { return _start_proc; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  void set_start_proc(OSThreadStartFunc start_proc) { _start_proc = start_proc; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  void* start_parm() const                          { return _start_parm; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  void set_start_parm(void* start_parm)             { _start_parm = start_parm; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
8735
9829dda3b405 6535709: interrupt of wait()ing thread isn't triggerring InterruptedException - test intwait3
dholmes
parents: 7405
diff changeset
    89
  volatile bool interrupted() const                 { return _interrupted != 0; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  void set_interrupted(bool z)                      { _interrupted = z ? 1 : 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  // Printing
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  void print_on(outputStream* st) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  void print() const                                { print_on(tty); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  // For java intrinsics:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  static ByteSize interrupted_offset()            { return byte_offset_of(OSThread, _interrupted); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  // Platform dependent stuff
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   100
#ifdef TARGET_OS_FAMILY_linux
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   101
# include "osThread_linux.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   102
#endif
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   103
#ifdef TARGET_OS_FAMILY_solaris
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   104
# include "osThread_solaris.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   105
#endif
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   106
#ifdef TARGET_OS_FAMILY_windows
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   107
# include "osThread_windows.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   108
#endif
22827
07d991d45a51 8023033: PPC64 (part 13): basic changes for AIX
goetz
parents: 13195
diff changeset
   109
#ifdef TARGET_OS_FAMILY_aix
07d991d45a51 8023033: PPC64 (part 13): basic changes for AIX
goetz
parents: 13195
diff changeset
   110
# include "osThread_aix.hpp"
07d991d45a51 8023033: PPC64 (part 13): basic changes for AIX
goetz
parents: 13195
diff changeset
   111
#endif
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents: 8735
diff changeset
   112
#ifdef TARGET_OS_FAMILY_bsd
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents: 8735
diff changeset
   113
# include "osThread_bsd.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents: 8735
diff changeset
   114
#endif
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   115
12765
3e1b42265329 7161732: Improve handling of thread_id in OSThread
rbackman
parents: 12377
diff changeset
   116
 public:
3e1b42265329 7161732: Improve handling of thread_id in OSThread
rbackman
parents: 12377
diff changeset
   117
  static ByteSize thread_id_offset()              { return byte_offset_of(OSThread, _thread_id); }
3e1b42265329 7161732: Improve handling of thread_id in OSThread
rbackman
parents: 12377
diff changeset
   118
  static size_t thread_id_size()                  { return sizeof(thread_id_t); }
3e1b42265329 7161732: Improve handling of thread_id in OSThread
rbackman
parents: 12377
diff changeset
   119
3e1b42265329 7161732: Improve handling of thread_id in OSThread
rbackman
parents: 12377
diff changeset
   120
  thread_id_t thread_id() const                   { return _thread_id; }
3e1b42265329 7161732: Improve handling of thread_id in OSThread
rbackman
parents: 12377
diff changeset
   121
3e1b42265329 7161732: Improve handling of thread_id in OSThread
rbackman
parents: 12377
diff changeset
   122
  void set_thread_id(thread_id_t id)              { _thread_id = id; }
3e1b42265329 7161732: Improve handling of thread_id in OSThread
rbackman
parents: 12377
diff changeset
   123
3e1b42265329 7161732: Improve handling of thread_id in OSThread
rbackman
parents: 12377
diff changeset
   124
 private:
3e1b42265329 7161732: Improve handling of thread_id in OSThread
rbackman
parents: 12377
diff changeset
   125
  // _thread_id is kernel thread id (similar to LWP id on Solaris). Each
3e1b42265329 7161732: Improve handling of thread_id in OSThread
rbackman
parents: 12377
diff changeset
   126
  // thread has a unique thread_id (BsdThreads or NPTL). It can be used
3e1b42265329 7161732: Improve handling of thread_id in OSThread
rbackman
parents: 12377
diff changeset
   127
  // to access /proc.
3e1b42265329 7161732: Improve handling of thread_id in OSThread
rbackman
parents: 12377
diff changeset
   128
  thread_id_t _thread_id;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
// Utility class for use with condition variables:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
class OSThreadWaitState : public StackObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  OSThread*   _osthread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  ThreadState _old_state;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  OSThreadWaitState(OSThread* osthread, bool is_object_wait) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
    _osthread  = osthread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
    _old_state = osthread->get_state();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
    if (is_object_wait) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
      osthread->set_state(OBJECT_WAIT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
      osthread->set_state(CONDVAR_WAIT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  ~OSThreadWaitState() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
    _osthread->set_state(_old_state);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
// Utility class for use with contended monitors:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
class OSThreadContendState : public StackObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  OSThread*   _osthread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  ThreadState _old_state;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  OSThreadContendState(OSThread* osthread) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
    _osthread  = osthread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
    _old_state = osthread->get_state();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
    osthread->set_state(MONITOR_WAIT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  ~OSThreadContendState() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
    _osthread->set_state(_old_state);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   166
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   167
#endif // SHARE_VM_RUNTIME_OSTHREAD_HPP