1 /*
2 * Copyright (c) 1997, 2005, Oracle and/or its affiliates. All rights reserved.
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 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 // The OSThread class holds OS-specific thread information. It is equivalent
26 // to the sys_thread_t structure of the classic JVM implementation.
27
28 // The thread states represented by the ThreadState values are platform-specific
29 // and are likely to be only approximate, because most OSes don't give you access
30 // to precise thread state information.
31
32 // Note: the ThreadState is legacy code and is not correctly implemented.
33 // Uses of ThreadState need to be replaced by the state in the JavaThread.
34
35 enum ThreadState {
36 ALLOCATED, // Memory has been allocated but not initialized
37 INITIALIZED, // The thread has been initialized but yet started
38 RUNNABLE, // Has been started and is runnable, but not necessarily running
39 MONITOR_WAIT, // Waiting on a contended monitor lock
40 CONDVAR_WAIT, // Waiting on a condition variable
41 OBJECT_WAIT, // Waiting on an Object.wait() call
42 BREAKPOINTED, // Suspended at breakpoint
43 SLEEPING, // Thread.sleep()
44 ZOMBIE // All done, but not reclaimed yet
74 // Destructor
75 ~OSThread();
76
77 // Accessors
78 OSThreadStartFunc start_proc() const { return _start_proc; }
79 void set_start_proc(OSThreadStartFunc start_proc) { _start_proc = start_proc; }
80 void* start_parm() const { return _start_parm; }
81 void set_start_parm(void* start_parm) { _start_parm = start_parm; }
82
83 bool interrupted() const { return _interrupted != 0; }
84 void set_interrupted(bool z) { _interrupted = z ? 1 : 0; }
85
86 // Printing
87 void print_on(outputStream* st) const;
88 void print() const { print_on(tty); }
89
90 // For java intrinsics:
91 static ByteSize interrupted_offset() { return byte_offset_of(OSThread, _interrupted); }
92
93 // Platform dependent stuff
94 #include "incls/_osThread_pd.hpp.incl"
95 };
96
97
98 // Utility class for use with condition variables:
99 class OSThreadWaitState : public StackObj {
100 OSThread* _osthread;
101 ThreadState _old_state;
102 public:
103 OSThreadWaitState(OSThread* osthread, bool is_object_wait) {
104 _osthread = osthread;
105 _old_state = osthread->get_state();
106 if (is_object_wait) {
107 osthread->set_state(OBJECT_WAIT);
108 } else {
109 osthread->set_state(CONDVAR_WAIT);
110 }
111 }
112 ~OSThreadWaitState() {
113 _osthread->set_state(_old_state);
114 }
115 };
116
117
118 // Utility class for use with contended monitors:
119 class OSThreadContendState : public StackObj {
120 OSThread* _osthread;
121 ThreadState _old_state;
122 public:
123 OSThreadContendState(OSThread* osthread) {
124 _osthread = osthread;
125 _old_state = osthread->get_state();
126 osthread->set_state(MONITOR_WAIT);
127 }
128 ~OSThreadContendState() {
129 _osthread->set_state(_old_state);
130 }
131 };
|
1 /*
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
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 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_VM_RUNTIME_OSTHREAD_HPP
26 #define SHARE_VM_RUNTIME_OSTHREAD_HPP
27
28 #include "runtime/frame.hpp"
29 #include "runtime/handles.hpp"
30 #include "runtime/hpi.hpp"
31 #include "runtime/javaFrameAnchor.hpp"
32 #include "runtime/objectMonitor.hpp"
33 #include "utilities/top.hpp"
34
35 // The OSThread class holds OS-specific thread information. It is equivalent
36 // to the sys_thread_t structure of the classic JVM implementation.
37
38 // The thread states represented by the ThreadState values are platform-specific
39 // and are likely to be only approximate, because most OSes don't give you access
40 // to precise thread state information.
41
42 // Note: the ThreadState is legacy code and is not correctly implemented.
43 // Uses of ThreadState need to be replaced by the state in the JavaThread.
44
45 enum ThreadState {
46 ALLOCATED, // Memory has been allocated but not initialized
47 INITIALIZED, // The thread has been initialized but yet started
48 RUNNABLE, // Has been started and is runnable, but not necessarily running
49 MONITOR_WAIT, // Waiting on a contended monitor lock
50 CONDVAR_WAIT, // Waiting on a condition variable
51 OBJECT_WAIT, // Waiting on an Object.wait() call
52 BREAKPOINTED, // Suspended at breakpoint
53 SLEEPING, // Thread.sleep()
54 ZOMBIE // All done, but not reclaimed yet
84 // Destructor
85 ~OSThread();
86
87 // Accessors
88 OSThreadStartFunc start_proc() const { return _start_proc; }
89 void set_start_proc(OSThreadStartFunc start_proc) { _start_proc = start_proc; }
90 void* start_parm() const { return _start_parm; }
91 void set_start_parm(void* start_parm) { _start_parm = start_parm; }
92
93 bool interrupted() const { return _interrupted != 0; }
94 void set_interrupted(bool z) { _interrupted = z ? 1 : 0; }
95
96 // Printing
97 void print_on(outputStream* st) const;
98 void print() const { print_on(tty); }
99
100 // For java intrinsics:
101 static ByteSize interrupted_offset() { return byte_offset_of(OSThread, _interrupted); }
102
103 // Platform dependent stuff
104 #ifdef TARGET_OS_FAMILY_linux
105 # include "osThread_linux.hpp"
106 #endif
107 #ifdef TARGET_OS_FAMILY_solaris
108 # include "osThread_solaris.hpp"
109 #endif
110 #ifdef TARGET_OS_FAMILY_windows
111 # include "osThread_windows.hpp"
112 #endif
113
114 };
115
116
117 // Utility class for use with condition variables:
118 class OSThreadWaitState : public StackObj {
119 OSThread* _osthread;
120 ThreadState _old_state;
121 public:
122 OSThreadWaitState(OSThread* osthread, bool is_object_wait) {
123 _osthread = osthread;
124 _old_state = osthread->get_state();
125 if (is_object_wait) {
126 osthread->set_state(OBJECT_WAIT);
127 } else {
128 osthread->set_state(CONDVAR_WAIT);
129 }
130 }
131 ~OSThreadWaitState() {
132 _osthread->set_state(_old_state);
133 }
134 };
135
136
137 // Utility class for use with contended monitors:
138 class OSThreadContendState : public StackObj {
139 OSThread* _osthread;
140 ThreadState _old_state;
141 public:
142 OSThreadContendState(OSThread* osthread) {
143 _osthread = osthread;
144 _old_state = osthread->get_state();
145 osthread->set_state(MONITOR_WAIT);
146 }
147 ~OSThreadContendState() {
148 _osthread->set_state(_old_state);
149 }
150 };
151
152 #endif // SHARE_VM_RUNTIME_OSTHREAD_HPP
|