author | poonam |
Tue, 24 Jun 2014 02:19:59 -0700 | |
changeset 25335 | 2557b9b45520 |
parent 8110 | c992c8d52344 |
child 27475 | 1f22a5d5be00 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
8110
c992c8d52344
6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents:
5547
diff
changeset
|
2 |
* Copyright (c) 2000, 2011, 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:
3261
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
3261
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:
3261
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
25 |
package sun.jvm.hotspot.runtime; |
|
26 |
||
27 |
import java.util.*; |
|
28 |
import sun.jvm.hotspot.debugger.*; |
|
29 |
import sun.jvm.hotspot.types.*; |
|
30 |
||
31 |
public class Thread extends VMObject { |
|
32 |
private static long tlabFieldOffset; |
|
33 |
||
34 |
private static CIntegerField suspendFlagsField; |
|
35 |
// Thread::SuspendFlags enum constants |
|
36 |
private static int EXTERNAL_SUSPEND; |
|
37 |
private static int EXT_SUSPENDED; |
|
38 |
private static int HAS_ASYNC_EXCEPTION; |
|
39 |
||
40 |
private static AddressField activeHandlesField; |
|
41 |
private static AddressField currentPendingMonitorField; |
|
42 |
private static AddressField currentWaitingMonitorField; |
|
43 |
||
25335 | 44 |
private static JLongField allocatedBytesField; |
45 |
||
1 | 46 |
static { |
47 |
VM.registerVMInitializedObserver(new Observer() { |
|
48 |
public void update(Observable o, Object data) { |
|
49 |
initialize(VM.getVM().getTypeDataBase()); |
|
50 |
} |
|
51 |
}); |
|
52 |
} |
|
53 |
||
54 |
private static synchronized void initialize(TypeDataBase db) { |
|
55 |
Type type = db.lookupType("Thread"); |
|
56 |
||
57 |
suspendFlagsField = type.getCIntegerField("_suspend_flags"); |
|
58 |
EXTERNAL_SUSPEND = db.lookupIntConstant("Thread::_external_suspend").intValue(); |
|
59 |
EXT_SUSPENDED = db.lookupIntConstant("Thread::_ext_suspended").intValue(); |
|
60 |
HAS_ASYNC_EXCEPTION = db.lookupIntConstant("Thread::_has_async_exception").intValue(); |
|
61 |
||
62 |
tlabFieldOffset = type.getField("_tlab").getOffset(); |
|
63 |
activeHandlesField = type.getAddressField("_active_handles"); |
|
64 |
currentPendingMonitorField = type.getAddressField("_current_pending_monitor"); |
|
65 |
currentWaitingMonitorField = type.getAddressField("_current_waiting_monitor"); |
|
25335 | 66 |
allocatedBytesField = type.getJLongField("_allocated_bytes"); |
1 | 67 |
} |
68 |
||
69 |
public Thread(Address addr) { |
|
70 |
super(addr); |
|
71 |
} |
|
72 |
||
73 |
public int suspendFlags() { |
|
74 |
return (int) suspendFlagsField.getValue(addr); |
|
75 |
} |
|
76 |
||
77 |
public boolean isExternalSuspend() { |
|
78 |
return (suspendFlags() & EXTERNAL_SUSPEND) != 0; |
|
79 |
} |
|
80 |
||
81 |
public boolean isExtSuspended() { |
|
82 |
return (suspendFlags() & EXT_SUSPENDED) != 0; |
|
83 |
} |
|
84 |
||
85 |
public boolean isBeingExtSuspended() { |
|
86 |
return isExtSuspended() || isExternalSuspend(); |
|
87 |
} |
|
88 |
||
89 |
// historical usage: checked for VM or external suspension |
|
90 |
public boolean isAnySuspended() { |
|
91 |
return isExtSuspended(); |
|
92 |
} |
|
93 |
||
94 |
public boolean hasAsyncException() { |
|
95 |
return (suspendFlags() & HAS_ASYNC_EXCEPTION) != 0; |
|
96 |
} |
|
97 |
||
98 |
public ThreadLocalAllocBuffer tlab() { |
|
99 |
return new ThreadLocalAllocBuffer(addr.addOffsetTo(tlabFieldOffset)); |
|
100 |
} |
|
101 |
||
102 |
public JNIHandleBlock activeHandles() { |
|
103 |
Address a = activeHandlesField.getAddress(addr); |
|
104 |
if (a == null) { |
|
105 |
return null; |
|
106 |
} |
|
107 |
return new JNIHandleBlock(a); |
|
108 |
} |
|
109 |
||
25335 | 110 |
public long allocatedBytes() { |
111 |
return allocatedBytesField.getValue(addr); |
|
112 |
} |
|
113 |
||
1 | 114 |
public boolean isVMThread() { return false; } |
115 |
public boolean isJavaThread() { return false; } |
|
116 |
public boolean isCompilerThread() { return false; } |
|
117 |
public boolean isHiddenFromExternalView() { return false; } |
|
118 |
public boolean isJvmtiAgentThread() { return false; } |
|
119 |
public boolean isWatcherThread() { return false; } |
|
120 |
public boolean isConcurrentMarkSweepThread() { return false; } |
|
8110
c992c8d52344
6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents:
5547
diff
changeset
|
121 |
public boolean isServiceThread() { return false; } |
1 | 122 |
|
123 |
/** Memory operations */ |
|
124 |
public void oopsDo(AddressVisitor oopVisitor) { |
|
125 |
// FIXME: Empty for now; will later traverse JNI handles and |
|
126 |
// pending exception |
|
127 |
} |
|
128 |
||
129 |
public ObjectMonitor getCurrentPendingMonitor() { |
|
130 |
Address monitorAddr = currentPendingMonitorField.getValue(addr); |
|
131 |
if (monitorAddr == null) { |
|
132 |
return null; |
|
133 |
} |
|
134 |
return new ObjectMonitor(monitorAddr); |
|
135 |
} |
|
136 |
||
137 |
public ObjectMonitor getCurrentWaitingMonitor() { |
|
138 |
Address monitorAddr = currentWaitingMonitorField.getValue(addr); |
|
139 |
if (monitorAddr == null) { |
|
140 |
return null; |
|
141 |
} |
|
142 |
return new ObjectMonitor(monitorAddr); |
|
143 |
} |
|
144 |
||
145 |
public boolean isLockOwned(Address lock) { |
|
146 |
if (isInStack(lock)) return true; |
|
147 |
return false; |
|
148 |
} |
|
149 |
||
150 |
public boolean isInStack(Address a) { |
|
151 |
// In the Serviceability Agent we need access to the thread's |
|
152 |
// stack pointer to be able to answer this question. Since it is |
|
153 |
// only a debugging system at the moment we need access to the |
|
154 |
// underlying thread, which is only present for Java threads; see |
|
155 |
// JavaThread.java. |
|
156 |
return false; |
|
157 |
} |
|
158 |
||
159 |
/** Assistance for ObjectMonitor implementation */ |
|
160 |
Address threadObjectAddress() { return addr; } |
|
161 |
} |