annotate src/share/vm/runtime/osThread.hpp @ 6972:bd7a7ce2e264

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