author | mr |
Tue, 29 Oct 2019 13:52:04 -0700 | |
changeset 58850 | f4290bf1cc21 |
parent 58196 | cea6839598e8 |
child 58901 | 2700c409ff10 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
53149
259c36ef27df
8215731: Move forward class definitions out of globalDefinitions.hpp
coleenp
parents:
49392
diff
changeset
|
2 |
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. |
1 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
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 | 22 |
* |
23 |
*/ |
|
24 |
||
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
53149
diff
changeset
|
25 |
#ifndef SHARE_RUNTIME_OSTHREAD_HPP |
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
53149
diff
changeset
|
26 |
#define SHARE_RUNTIME_OSTHREAD_HPP |
7397 | 27 |
|
28 |
#include "runtime/frame.hpp" |
|
29 |
#include "runtime/handles.hpp" |
|
30 |
#include "runtime/javaFrameAnchor.hpp" |
|
31 |
#include "runtime/objectMonitor.hpp" |
|
40010 | 32 |
#include "utilities/macros.hpp" |
7397 | 33 |
|
1 | 34 |
// The OSThread class holds OS-specific thread information. It is equivalent |
35 |
// to the sys_thread_t structure of the classic JVM implementation. |
|
36 |
||
37 |
// The thread states represented by the ThreadState values are platform-specific |
|
38 |
// and are likely to be only approximate, because most OSes don't give you access |
|
39 |
// to precise thread state information. |
|
40 |
||
41 |
// Note: the ThreadState is legacy code and is not correctly implemented. |
|
42 |
// Uses of ThreadState need to be replaced by the state in the JavaThread. |
|
43 |
||
44 |
enum ThreadState { |
|
45 |
ALLOCATED, // Memory has been allocated but not initialized |
|
46 |
INITIALIZED, // The thread has been initialized but yet started |
|
47 |
RUNNABLE, // Has been started and is runnable, but not necessarily running |
|
48 |
MONITOR_WAIT, // Waiting on a contended monitor lock |
|
49 |
CONDVAR_WAIT, // Waiting on a condition variable |
|
50 |
OBJECT_WAIT, // Waiting on an Object.wait() call |
|
51 |
BREAKPOINTED, // Suspended at breakpoint |
|
52 |
SLEEPING, // Thread.sleep() |
|
53 |
ZOMBIE // All done, but not reclaimed yet |
|
54 |
}; |
|
55 |
||
53149
259c36ef27df
8215731: Move forward class definitions out of globalDefinitions.hpp
coleenp
parents:
49392
diff
changeset
|
56 |
typedef int (*OSThreadStartFunc)(void*); |
259c36ef27df
8215731: Move forward class definitions out of globalDefinitions.hpp
coleenp
parents:
49392
diff
changeset
|
57 |
|
13195 | 58 |
class OSThread: public CHeapObj<mtThread> { |
1 | 59 |
friend class VMStructs; |
35123
b0b89d83bcf5
8134994: use separate VMStructs databases for SA and JVMCI
twisti
parents:
22827
diff
changeset
|
60 |
friend class JVMCIVMStructs; |
1 | 61 |
private: |
62 |
OSThreadStartFunc _start_proc; // Thread start routine |
|
63 |
void* _start_parm; // Thread start routine parameter |
|
64 |
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
|
65 |
volatile jint _interrupted; // Thread.isInterrupted state |
1 | 66 |
|
67 |
// Note: _interrupted must be jint, so that Java intrinsics can access it. |
|
68 |
// The value stored there must be either 0 or 1. It must be possible |
|
69 |
// for Java to emulate Thread.currentThread().isInterrupted() by performing |
|
70 |
// the double indirection Thread::current()->_osthread->_interrupted. |
|
71 |
||
72 |
// Methods |
|
73 |
public: |
|
74 |
void set_state(ThreadState state) { _state = state; } |
|
75 |
ThreadState get_state() { return _state; } |
|
76 |
||
77 |
OSThread(OSThreadStartFunc start_proc, void* start_parm); |
|
78 |
~OSThread(); |
|
79 |
||
80 |
// Accessors |
|
81 |
OSThreadStartFunc start_proc() const { return _start_proc; } |
|
82 |
void set_start_proc(OSThreadStartFunc start_proc) { _start_proc = start_proc; } |
|
83 |
void* start_parm() const { return _start_parm; } |
|
84 |
void set_start_parm(void* start_parm) { _start_parm = start_parm; } |
|
58196
cea6839598e8
8230424: Use platform independent code for Thread.interrupt support
dholmes
parents:
54807
diff
changeset
|
85 |
// These are specialized on Windows. |
cea6839598e8
8230424: Use platform independent code for Thread.interrupt support
dholmes
parents:
54807
diff
changeset
|
86 |
#ifndef _WINDOWS |
8735
9829dda3b405
6535709: interrupt of wait()ing thread isn't triggerring InterruptedException - test intwait3
dholmes
parents:
7405
diff
changeset
|
87 |
volatile bool interrupted() const { return _interrupted != 0; } |
1 | 88 |
void set_interrupted(bool z) { _interrupted = z ? 1 : 0; } |
58196
cea6839598e8
8230424: Use platform independent code for Thread.interrupt support
dholmes
parents:
54807
diff
changeset
|
89 |
#endif |
1 | 90 |
// Printing |
91 |
void print_on(outputStream* st) const; |
|
54807 | 92 |
void print() const; |
1 | 93 |
|
94 |
// For java intrinsics: |
|
95 |
static ByteSize interrupted_offset() { return byte_offset_of(OSThread, _interrupted); } |
|
96 |
||
97 |
// Platform dependent stuff |
|
40010 | 98 |
#include OS_HEADER(osThread) |
7397 | 99 |
|
12765
3e1b42265329
7161732: Improve handling of thread_id in OSThread
rbackman
parents:
12377
diff
changeset
|
100 |
public: |
3e1b42265329
7161732: Improve handling of thread_id in OSThread
rbackman
parents:
12377
diff
changeset
|
101 |
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
|
102 |
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
|
103 |
|
3e1b42265329
7161732: Improve handling of thread_id in OSThread
rbackman
parents:
12377
diff
changeset
|
104 |
thread_id_t thread_id() const { return _thread_id; } |
3e1b42265329
7161732: Improve handling of thread_id in OSThread
rbackman
parents:
12377
diff
changeset
|
105 |
|
3e1b42265329
7161732: Improve handling of thread_id in OSThread
rbackman
parents:
12377
diff
changeset
|
106 |
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
|
107 |
|
3e1b42265329
7161732: Improve handling of thread_id in OSThread
rbackman
parents:
12377
diff
changeset
|
108 |
private: |
3e1b42265329
7161732: Improve handling of thread_id in OSThread
rbackman
parents:
12377
diff
changeset
|
109 |
// _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
|
110 |
// 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
|
111 |
// to access /proc. |
3e1b42265329
7161732: Improve handling of thread_id in OSThread
rbackman
parents:
12377
diff
changeset
|
112 |
thread_id_t _thread_id; |
1 | 113 |
}; |
114 |
||
115 |
||
116 |
// Utility class for use with condition variables: |
|
117 |
class OSThreadWaitState : public StackObj { |
|
118 |
OSThread* _osthread; |
|
119 |
ThreadState _old_state; |
|
120 |
public: |
|
121 |
OSThreadWaitState(OSThread* osthread, bool is_object_wait) { |
|
122 |
_osthread = osthread; |
|
123 |
_old_state = osthread->get_state(); |
|
124 |
if (is_object_wait) { |
|
125 |
osthread->set_state(OBJECT_WAIT); |
|
126 |
} else { |
|
127 |
osthread->set_state(CONDVAR_WAIT); |
|
128 |
} |
|
129 |
} |
|
130 |
~OSThreadWaitState() { |
|
131 |
_osthread->set_state(_old_state); |
|
132 |
} |
|
133 |
}; |
|
134 |
||
135 |
||
136 |
// Utility class for use with contended monitors: |
|
137 |
class OSThreadContendState : public StackObj { |
|
138 |
OSThread* _osthread; |
|
139 |
ThreadState _old_state; |
|
140 |
public: |
|
141 |
OSThreadContendState(OSThread* osthread) { |
|
142 |
_osthread = osthread; |
|
143 |
_old_state = osthread->get_state(); |
|
144 |
osthread->set_state(MONITOR_WAIT); |
|
145 |
} |
|
146 |
~OSThreadContendState() { |
|
147 |
_osthread->set_state(_old_state); |
|
148 |
} |
|
149 |
}; |
|
7397 | 150 |
|
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
53149
diff
changeset
|
151 |
#endif // SHARE_RUNTIME_OSTHREAD_HPP |