annotate agent/src/share/classes/sun/jvm/hotspot/runtime/Thread.java @ 0:a61af66fc99e jdk7-b24

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children b9fba36710f2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 2000-2007 Sun Microsystems, Inc. All Rights Reserved.
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 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 package sun.jvm.hotspot.runtime;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import java.util.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import sun.jvm.hotspot.debugger.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import sun.jvm.hotspot.types.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30
a61af66fc99e Initial load
duke
parents:
diff changeset
31 public class Thread extends VMObject {
a61af66fc99e Initial load
duke
parents:
diff changeset
32 private static long tlabFieldOffset;
a61af66fc99e Initial load
duke
parents:
diff changeset
33
a61af66fc99e Initial load
duke
parents:
diff changeset
34 private static CIntegerField suspendFlagsField;
a61af66fc99e Initial load
duke
parents:
diff changeset
35 // Thread::SuspendFlags enum constants
a61af66fc99e Initial load
duke
parents:
diff changeset
36 private static int EXTERNAL_SUSPEND;
a61af66fc99e Initial load
duke
parents:
diff changeset
37 private static int EXT_SUSPENDED;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 private static int HAS_ASYNC_EXCEPTION;
a61af66fc99e Initial load
duke
parents:
diff changeset
39
a61af66fc99e Initial load
duke
parents:
diff changeset
40 private static AddressField activeHandlesField;
a61af66fc99e Initial load
duke
parents:
diff changeset
41 private static AddressField highestLockField;
a61af66fc99e Initial load
duke
parents:
diff changeset
42 private static AddressField currentPendingMonitorField;
a61af66fc99e Initial load
duke
parents:
diff changeset
43 private static AddressField currentWaitingMonitorField;
a61af66fc99e Initial load
duke
parents:
diff changeset
44
a61af66fc99e Initial load
duke
parents:
diff changeset
45 static {
a61af66fc99e Initial load
duke
parents:
diff changeset
46 VM.registerVMInitializedObserver(new Observer() {
a61af66fc99e Initial load
duke
parents:
diff changeset
47 public void update(Observable o, Object data) {
a61af66fc99e Initial load
duke
parents:
diff changeset
48 initialize(VM.getVM().getTypeDataBase());
a61af66fc99e Initial load
duke
parents:
diff changeset
49 }
a61af66fc99e Initial load
duke
parents:
diff changeset
50 });
a61af66fc99e Initial load
duke
parents:
diff changeset
51 }
a61af66fc99e Initial load
duke
parents:
diff changeset
52
a61af66fc99e Initial load
duke
parents:
diff changeset
53 private static synchronized void initialize(TypeDataBase db) {
a61af66fc99e Initial load
duke
parents:
diff changeset
54 Type type = db.lookupType("Thread");
a61af66fc99e Initial load
duke
parents:
diff changeset
55
a61af66fc99e Initial load
duke
parents:
diff changeset
56 suspendFlagsField = type.getCIntegerField("_suspend_flags");
a61af66fc99e Initial load
duke
parents:
diff changeset
57 EXTERNAL_SUSPEND = db.lookupIntConstant("Thread::_external_suspend").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
58 EXT_SUSPENDED = db.lookupIntConstant("Thread::_ext_suspended").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
59 HAS_ASYNC_EXCEPTION = db.lookupIntConstant("Thread::_has_async_exception").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
60
a61af66fc99e Initial load
duke
parents:
diff changeset
61 tlabFieldOffset = type.getField("_tlab").getOffset();
a61af66fc99e Initial load
duke
parents:
diff changeset
62 activeHandlesField = type.getAddressField("_active_handles");
a61af66fc99e Initial load
duke
parents:
diff changeset
63 highestLockField = type.getAddressField("_highest_lock");
a61af66fc99e Initial load
duke
parents:
diff changeset
64 currentPendingMonitorField = type.getAddressField("_current_pending_monitor");
a61af66fc99e Initial load
duke
parents:
diff changeset
65 currentWaitingMonitorField = type.getAddressField("_current_waiting_monitor");
a61af66fc99e Initial load
duke
parents:
diff changeset
66 }
a61af66fc99e Initial load
duke
parents:
diff changeset
67
a61af66fc99e Initial load
duke
parents:
diff changeset
68 public Thread(Address addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
69 super(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
70 }
a61af66fc99e Initial load
duke
parents:
diff changeset
71
a61af66fc99e Initial load
duke
parents:
diff changeset
72 public int suspendFlags() {
a61af66fc99e Initial load
duke
parents:
diff changeset
73 return (int) suspendFlagsField.getValue(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
74 }
a61af66fc99e Initial load
duke
parents:
diff changeset
75
a61af66fc99e Initial load
duke
parents:
diff changeset
76 public boolean isExternalSuspend() {
a61af66fc99e Initial load
duke
parents:
diff changeset
77 return (suspendFlags() & EXTERNAL_SUSPEND) != 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
78 }
a61af66fc99e Initial load
duke
parents:
diff changeset
79
a61af66fc99e Initial load
duke
parents:
diff changeset
80 public boolean isExtSuspended() {
a61af66fc99e Initial load
duke
parents:
diff changeset
81 return (suspendFlags() & EXT_SUSPENDED) != 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
82 }
a61af66fc99e Initial load
duke
parents:
diff changeset
83
a61af66fc99e Initial load
duke
parents:
diff changeset
84 public boolean isBeingExtSuspended() {
a61af66fc99e Initial load
duke
parents:
diff changeset
85 return isExtSuspended() || isExternalSuspend();
a61af66fc99e Initial load
duke
parents:
diff changeset
86 }
a61af66fc99e Initial load
duke
parents:
diff changeset
87
a61af66fc99e Initial load
duke
parents:
diff changeset
88 // historical usage: checked for VM or external suspension
a61af66fc99e Initial load
duke
parents:
diff changeset
89 public boolean isAnySuspended() {
a61af66fc99e Initial load
duke
parents:
diff changeset
90 return isExtSuspended();
a61af66fc99e Initial load
duke
parents:
diff changeset
91 }
a61af66fc99e Initial load
duke
parents:
diff changeset
92
a61af66fc99e Initial load
duke
parents:
diff changeset
93 public boolean hasAsyncException() {
a61af66fc99e Initial load
duke
parents:
diff changeset
94 return (suspendFlags() & HAS_ASYNC_EXCEPTION) != 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
95 }
a61af66fc99e Initial load
duke
parents:
diff changeset
96
a61af66fc99e Initial load
duke
parents:
diff changeset
97 public ThreadLocalAllocBuffer tlab() {
a61af66fc99e Initial load
duke
parents:
diff changeset
98 return new ThreadLocalAllocBuffer(addr.addOffsetTo(tlabFieldOffset));
a61af66fc99e Initial load
duke
parents:
diff changeset
99 }
a61af66fc99e Initial load
duke
parents:
diff changeset
100
a61af66fc99e Initial load
duke
parents:
diff changeset
101 public JNIHandleBlock activeHandles() {
a61af66fc99e Initial load
duke
parents:
diff changeset
102 Address a = activeHandlesField.getAddress(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
103 if (a == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
104 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
105 }
a61af66fc99e Initial load
duke
parents:
diff changeset
106 return new JNIHandleBlock(a);
a61af66fc99e Initial load
duke
parents:
diff changeset
107 }
a61af66fc99e Initial load
duke
parents:
diff changeset
108
a61af66fc99e Initial load
duke
parents:
diff changeset
109 public boolean isVMThread() { return false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
110 public boolean isJavaThread() { return false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
111 public boolean isCompilerThread() { return false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
112 public boolean isHiddenFromExternalView() { return false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
113 public boolean isJvmtiAgentThread() { return false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
114 public boolean isWatcherThread() { return false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
115 public boolean isConcurrentMarkSweepThread() { return false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
116 public boolean isLowMemoryDetectorThread() { return false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
117
a61af66fc99e Initial load
duke
parents:
diff changeset
118 /** Memory operations */
a61af66fc99e Initial load
duke
parents:
diff changeset
119 public void oopsDo(AddressVisitor oopVisitor) {
a61af66fc99e Initial load
duke
parents:
diff changeset
120 // FIXME: Empty for now; will later traverse JNI handles and
a61af66fc99e Initial load
duke
parents:
diff changeset
121 // pending exception
a61af66fc99e Initial load
duke
parents:
diff changeset
122 }
a61af66fc99e Initial load
duke
parents:
diff changeset
123
a61af66fc99e Initial load
duke
parents:
diff changeset
124 public Address highestLock() {
a61af66fc99e Initial load
duke
parents:
diff changeset
125 return highestLockField.getValue(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
126 }
a61af66fc99e Initial load
duke
parents:
diff changeset
127
a61af66fc99e Initial load
duke
parents:
diff changeset
128 public ObjectMonitor getCurrentPendingMonitor() {
a61af66fc99e Initial load
duke
parents:
diff changeset
129 Address monitorAddr = currentPendingMonitorField.getValue(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
130 if (monitorAddr == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
131 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
132 }
a61af66fc99e Initial load
duke
parents:
diff changeset
133 return new ObjectMonitor(monitorAddr);
a61af66fc99e Initial load
duke
parents:
diff changeset
134 }
a61af66fc99e Initial load
duke
parents:
diff changeset
135
a61af66fc99e Initial load
duke
parents:
diff changeset
136 public ObjectMonitor getCurrentWaitingMonitor() {
a61af66fc99e Initial load
duke
parents:
diff changeset
137 Address monitorAddr = currentWaitingMonitorField.getValue(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
138 if (monitorAddr == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
139 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
140 }
a61af66fc99e Initial load
duke
parents:
diff changeset
141 return new ObjectMonitor(monitorAddr);
a61af66fc99e Initial load
duke
parents:
diff changeset
142 }
a61af66fc99e Initial load
duke
parents:
diff changeset
143
a61af66fc99e Initial load
duke
parents:
diff changeset
144 public boolean isLockOwned(Address lock) {
a61af66fc99e Initial load
duke
parents:
diff changeset
145 if (isInStack(lock)) return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
146 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
147 }
a61af66fc99e Initial load
duke
parents:
diff changeset
148
a61af66fc99e Initial load
duke
parents:
diff changeset
149 public boolean isInStack(Address a) {
a61af66fc99e Initial load
duke
parents:
diff changeset
150 // In the Serviceability Agent we need access to the thread's
a61af66fc99e Initial load
duke
parents:
diff changeset
151 // stack pointer to be able to answer this question. Since it is
a61af66fc99e Initial load
duke
parents:
diff changeset
152 // only a debugging system at the moment we need access to the
a61af66fc99e Initial load
duke
parents:
diff changeset
153 // underlying thread, which is only present for Java threads; see
a61af66fc99e Initial load
duke
parents:
diff changeset
154 // JavaThread.java.
a61af66fc99e Initial load
duke
parents:
diff changeset
155 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
156 }
a61af66fc99e Initial load
duke
parents:
diff changeset
157
a61af66fc99e Initial load
duke
parents:
diff changeset
158 /** Assistance for ObjectMonitor implementation */
a61af66fc99e Initial load
duke
parents:
diff changeset
159 Address threadObjectAddress() { return addr; }
a61af66fc99e Initial load
duke
parents:
diff changeset
160 }