annotate agent/src/share/classes/sun/jvm/hotspot/jdi/ThreadReferenceImpl.java @ 818:b109e761e927

6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14 Summary: Disable escape analysis when jvmti/debugger is used. Add support for EA ibto SA. Reviewed-by: never
author kvn
date Tue, 09 Jun 2009 16:19:10 -0700
parents a61af66fc99e
children bd02caa94611
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 2002-2005 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.jdi;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import sun.jvm.hotspot.debugger.OopHandle;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import sun.jvm.hotspot.runtime.VMObject;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import sun.jvm.hotspot.runtime.JavaThread;
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import sun.jvm.hotspot.runtime.OSThread;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 //import sun.jvm.hotspot.runtime.StackFrameStream;
a61af66fc99e Initial load
duke
parents:
diff changeset
32 import sun.jvm.hotspot.runtime.JavaVFrame;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 import sun.jvm.hotspot.runtime.JavaThreadState;
a61af66fc99e Initial load
duke
parents:
diff changeset
34 import sun.jvm.hotspot.runtime.MonitorInfo;
a61af66fc99e Initial load
duke
parents:
diff changeset
35 import sun.jvm.hotspot.runtime.ObjectMonitor;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 import sun.jvm.hotspot.oops.Oop;
a61af66fc99e Initial load
duke
parents:
diff changeset
37 import sun.jvm.hotspot.oops.ObjectHeap;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 import sun.jvm.hotspot.oops.Instance;
a61af66fc99e Initial load
duke
parents:
diff changeset
39 import sun.jvm.hotspot.oops.OopUtilities;
a61af66fc99e Initial load
duke
parents:
diff changeset
40 import sun.jvm.hotspot.oops.Klass;
a61af66fc99e Initial load
duke
parents:
diff changeset
41 import sun.jvm.hotspot.utilities.Assert;
a61af66fc99e Initial load
duke
parents:
diff changeset
42 import com.sun.jdi.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
43 import java.util.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
44
a61af66fc99e Initial load
duke
parents:
diff changeset
45 public class ThreadReferenceImpl extends ObjectReferenceImpl
a61af66fc99e Initial load
duke
parents:
diff changeset
46 implements ThreadReference, /* imports */ JVMTIThreadState {
a61af66fc99e Initial load
duke
parents:
diff changeset
47
a61af66fc99e Initial load
duke
parents:
diff changeset
48 private JavaThread myJavaThread;
a61af66fc99e Initial load
duke
parents:
diff changeset
49 private ArrayList frames; // StackFrames
a61af66fc99e Initial load
duke
parents:
diff changeset
50 private List ownedMonitors; // List<ObjectReferenceImpl>
a61af66fc99e Initial load
duke
parents:
diff changeset
51 private List ownedMonitorsInfo; // List<MonitorInfo>
a61af66fc99e Initial load
duke
parents:
diff changeset
52 private ObjectReferenceImpl currentContendingMonitor;
a61af66fc99e Initial load
duke
parents:
diff changeset
53
a61af66fc99e Initial load
duke
parents:
diff changeset
54 ThreadReferenceImpl(VirtualMachine aVm, sun.jvm.hotspot.runtime.JavaThread aRef) {
a61af66fc99e Initial load
duke
parents:
diff changeset
55 // We are given a JavaThread and save it in our myJavaThread field.
a61af66fc99e Initial load
duke
parents:
diff changeset
56 // But, our parent class is an ObjectReferenceImpl so we need an Oop
a61af66fc99e Initial load
duke
parents:
diff changeset
57 // for it. JavaThread is a wrapper around a Thread Oop so we get
a61af66fc99e Initial load
duke
parents:
diff changeset
58 // that Oop and give it to our super.
a61af66fc99e Initial load
duke
parents:
diff changeset
59 // We can get it back again by calling ref().
a61af66fc99e Initial load
duke
parents:
diff changeset
60 super(aVm, (Instance)aRef.getThreadObj());
a61af66fc99e Initial load
duke
parents:
diff changeset
61 myJavaThread = aRef;
a61af66fc99e Initial load
duke
parents:
diff changeset
62 }
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64 ThreadReferenceImpl(VirtualMachine vm, Instance oRef) {
a61af66fc99e Initial load
duke
parents:
diff changeset
65 // Instance must be of type java.lang.Thread
a61af66fc99e Initial load
duke
parents:
diff changeset
66 super(vm, oRef);
a61af66fc99e Initial load
duke
parents:
diff changeset
67
a61af66fc99e Initial load
duke
parents:
diff changeset
68 // JavaThread retrieved from java.lang.Thread instance may be null.
a61af66fc99e Initial load
duke
parents:
diff changeset
69 // This is the case for threads not-started and for zombies. Wherever
a61af66fc99e Initial load
duke
parents:
diff changeset
70 // appropriate, check for null instead of resulting in NullPointerException.
a61af66fc99e Initial load
duke
parents:
diff changeset
71 myJavaThread = OopUtilities.threadOopGetJavaThread(oRef);
a61af66fc99e Initial load
duke
parents:
diff changeset
72 }
a61af66fc99e Initial load
duke
parents:
diff changeset
73
a61af66fc99e Initial load
duke
parents:
diff changeset
74 // return value may be null. refer to the comment in constructor.
a61af66fc99e Initial load
duke
parents:
diff changeset
75 JavaThread getJavaThread() {
a61af66fc99e Initial load
duke
parents:
diff changeset
76 return myJavaThread;
a61af66fc99e Initial load
duke
parents:
diff changeset
77 }
a61af66fc99e Initial load
duke
parents:
diff changeset
78
a61af66fc99e Initial load
duke
parents:
diff changeset
79 protected String description() {
a61af66fc99e Initial load
duke
parents:
diff changeset
80 return "ThreadReference " + uniqueID();
a61af66fc99e Initial load
duke
parents:
diff changeset
81 }
a61af66fc99e Initial load
duke
parents:
diff changeset
82
a61af66fc99e Initial load
duke
parents:
diff changeset
83 /**
a61af66fc99e Initial load
duke
parents:
diff changeset
84 * Note that we only cache the name string while suspended because
a61af66fc99e Initial load
duke
parents:
diff changeset
85 * it can change via Thread.setName arbitrarily
a61af66fc99e Initial load
duke
parents:
diff changeset
86 */
a61af66fc99e Initial load
duke
parents:
diff changeset
87 public String name() {
a61af66fc99e Initial load
duke
parents:
diff changeset
88 return OopUtilities.threadOopGetName(ref());
a61af66fc99e Initial load
duke
parents:
diff changeset
89 }
a61af66fc99e Initial load
duke
parents:
diff changeset
90
a61af66fc99e Initial load
duke
parents:
diff changeset
91 public void suspend() {
a61af66fc99e Initial load
duke
parents:
diff changeset
92 vm.throwNotReadOnlyException("ThreadReference.suspend()");
a61af66fc99e Initial load
duke
parents:
diff changeset
93 }
a61af66fc99e Initial load
duke
parents:
diff changeset
94
a61af66fc99e Initial load
duke
parents:
diff changeset
95 public void resume() {
a61af66fc99e Initial load
duke
parents:
diff changeset
96 vm.throwNotReadOnlyException("ThreadReference.resume()");
a61af66fc99e Initial load
duke
parents:
diff changeset
97 }
a61af66fc99e Initial load
duke
parents:
diff changeset
98
a61af66fc99e Initial load
duke
parents:
diff changeset
99 public int suspendCount() {
a61af66fc99e Initial load
duke
parents:
diff changeset
100 // all threads are "suspended" when we attach to process or core.
a61af66fc99e Initial load
duke
parents:
diff changeset
101 // we interpret this as one suspend.
a61af66fc99e Initial load
duke
parents:
diff changeset
102 return 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
103 }
a61af66fc99e Initial load
duke
parents:
diff changeset
104
a61af66fc99e Initial load
duke
parents:
diff changeset
105 public void stop(ObjectReference throwable) throws InvalidTypeException {
a61af66fc99e Initial load
duke
parents:
diff changeset
106 vm.throwNotReadOnlyException("ThreadReference.stop()");
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 void interrupt() {
a61af66fc99e Initial load
duke
parents:
diff changeset
110 vm.throwNotReadOnlyException("ThreadReference.interrupt()");
a61af66fc99e Initial load
duke
parents:
diff changeset
111 }
a61af66fc99e Initial load
duke
parents:
diff changeset
112
a61af66fc99e Initial load
duke
parents:
diff changeset
113 // refer to jvmtiEnv::GetThreadState
a61af66fc99e Initial load
duke
parents:
diff changeset
114 private int jvmtiGetThreadState() {
a61af66fc99e Initial load
duke
parents:
diff changeset
115 // get most state bits
a61af66fc99e Initial load
duke
parents:
diff changeset
116 int state = OopUtilities.threadOopGetThreadStatus(ref());
a61af66fc99e Initial load
duke
parents:
diff changeset
117 // add more state bits
a61af66fc99e Initial load
duke
parents:
diff changeset
118 if (myJavaThread != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
119 JavaThreadState jts = myJavaThread.getThreadState();
a61af66fc99e Initial load
duke
parents:
diff changeset
120 if (myJavaThread.isBeingExtSuspended()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
121 state |= JVMTI_THREAD_STATE_SUSPENDED;
a61af66fc99e Initial load
duke
parents:
diff changeset
122 }
a61af66fc99e Initial load
duke
parents:
diff changeset
123 if (jts == JavaThreadState.IN_NATIVE) {
a61af66fc99e Initial load
duke
parents:
diff changeset
124 state |= JVMTI_THREAD_STATE_IN_NATIVE;
a61af66fc99e Initial load
duke
parents:
diff changeset
125 }
a61af66fc99e Initial load
duke
parents:
diff changeset
126 OSThread osThread = myJavaThread.getOSThread();
a61af66fc99e Initial load
duke
parents:
diff changeset
127 if (osThread != null && osThread.interrupted()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
128 state |= JVMTI_THREAD_STATE_INTERRUPTED;
a61af66fc99e Initial load
duke
parents:
diff changeset
129 }
a61af66fc99e Initial load
duke
parents:
diff changeset
130 }
a61af66fc99e Initial load
duke
parents:
diff changeset
131 return state;
a61af66fc99e Initial load
duke
parents:
diff changeset
132 }
a61af66fc99e Initial load
duke
parents:
diff changeset
133
a61af66fc99e Initial load
duke
parents:
diff changeset
134 public int status() {
a61af66fc99e Initial load
duke
parents:
diff changeset
135 int state = jvmtiGetThreadState();
a61af66fc99e Initial load
duke
parents:
diff changeset
136 int status = THREAD_STATUS_UNKNOWN;
a61af66fc99e Initial load
duke
parents:
diff changeset
137 // refer to map2jdwpThreadStatus in util.c (back-end)
a61af66fc99e Initial load
duke
parents:
diff changeset
138 if (! ((state & JVMTI_THREAD_STATE_ALIVE) != 0) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
139 if ((state & JVMTI_THREAD_STATE_TERMINATED) != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
140 status = THREAD_STATUS_ZOMBIE;
a61af66fc99e Initial load
duke
parents:
diff changeset
141 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
142 status = THREAD_STATUS_NOT_STARTED;
a61af66fc99e Initial load
duke
parents:
diff changeset
143 }
a61af66fc99e Initial load
duke
parents:
diff changeset
144 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
145 if ((state & JVMTI_THREAD_STATE_SLEEPING) != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
146 status = THREAD_STATUS_SLEEPING;
a61af66fc99e Initial load
duke
parents:
diff changeset
147 } else if ((state & JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER) != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
148 status = THREAD_STATUS_MONITOR;
a61af66fc99e Initial load
duke
parents:
diff changeset
149 } else if ((state & JVMTI_THREAD_STATE_WAITING) != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
150 status = THREAD_STATUS_WAIT;
a61af66fc99e Initial load
duke
parents:
diff changeset
151 } else if ((state & JVMTI_THREAD_STATE_RUNNABLE) != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
152 status = THREAD_STATUS_RUNNING;
a61af66fc99e Initial load
duke
parents:
diff changeset
153 }
a61af66fc99e Initial load
duke
parents:
diff changeset
154 }
a61af66fc99e Initial load
duke
parents:
diff changeset
155 return status;
a61af66fc99e Initial load
duke
parents:
diff changeset
156 }
a61af66fc99e Initial load
duke
parents:
diff changeset
157
a61af66fc99e Initial load
duke
parents:
diff changeset
158 public boolean isSuspended() { //fixme jjh
a61af66fc99e Initial load
duke
parents:
diff changeset
159 // If we want to support doing this for a VM which was being
a61af66fc99e Initial load
duke
parents:
diff changeset
160 // debugged, then we need to fix this.
a61af66fc99e Initial load
duke
parents:
diff changeset
161 // In the meantime, we will say all threads are suspended,
a61af66fc99e Initial load
duke
parents:
diff changeset
162 // otherwise, some things won't work, like the jdb 'up' cmd.
a61af66fc99e Initial load
duke
parents:
diff changeset
163 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
164 }
a61af66fc99e Initial load
duke
parents:
diff changeset
165
a61af66fc99e Initial load
duke
parents:
diff changeset
166 public boolean isAtBreakpoint() { //fixme jjh
a61af66fc99e Initial load
duke
parents:
diff changeset
167 // If we want to support doing this for a VM which was being
a61af66fc99e Initial load
duke
parents:
diff changeset
168 // debugged, then we need to fix this.
a61af66fc99e Initial load
duke
parents:
diff changeset
169 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
170 }
a61af66fc99e Initial load
duke
parents:
diff changeset
171
a61af66fc99e Initial load
duke
parents:
diff changeset
172 public ThreadGroupReference threadGroup() {
a61af66fc99e Initial load
duke
parents:
diff changeset
173 return (ThreadGroupReferenceImpl)vm.threadGroupMirror(
a61af66fc99e Initial load
duke
parents:
diff changeset
174 (Instance)OopUtilities.threadOopGetThreadGroup(ref()));
a61af66fc99e Initial load
duke
parents:
diff changeset
175 }
a61af66fc99e Initial load
duke
parents:
diff changeset
176
a61af66fc99e Initial load
duke
parents:
diff changeset
177 public int frameCount() throws IncompatibleThreadStateException { //fixme jjh
a61af66fc99e Initial load
duke
parents:
diff changeset
178 privateFrames(0, -1);
a61af66fc99e Initial load
duke
parents:
diff changeset
179 return frames.size();
a61af66fc99e Initial load
duke
parents:
diff changeset
180 }
a61af66fc99e Initial load
duke
parents:
diff changeset
181
a61af66fc99e Initial load
duke
parents:
diff changeset
182 public List frames() throws IncompatibleThreadStateException {
a61af66fc99e Initial load
duke
parents:
diff changeset
183 return privateFrames(0, -1);
a61af66fc99e Initial load
duke
parents:
diff changeset
184 }
a61af66fc99e Initial load
duke
parents:
diff changeset
185
a61af66fc99e Initial load
duke
parents:
diff changeset
186 public StackFrame frame(int index) throws IncompatibleThreadStateException {
a61af66fc99e Initial load
duke
parents:
diff changeset
187 List list = privateFrames(index, 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
188 return (StackFrame)list.get(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
189 }
a61af66fc99e Initial load
duke
parents:
diff changeset
190
a61af66fc99e Initial load
duke
parents:
diff changeset
191 public List frames(int start, int length)
a61af66fc99e Initial load
duke
parents:
diff changeset
192 throws IncompatibleThreadStateException {
a61af66fc99e Initial load
duke
parents:
diff changeset
193 if (length < 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
194 throw new IndexOutOfBoundsException(
a61af66fc99e Initial load
duke
parents:
diff changeset
195 "length must be greater than or equal to zero");
a61af66fc99e Initial load
duke
parents:
diff changeset
196 }
a61af66fc99e Initial load
duke
parents:
diff changeset
197 return privateFrames(start, length);
a61af66fc99e Initial load
duke
parents:
diff changeset
198 }
a61af66fc99e Initial load
duke
parents:
diff changeset
199
a61af66fc99e Initial load
duke
parents:
diff changeset
200 /**
a61af66fc99e Initial load
duke
parents:
diff changeset
201 * Private version of frames() allows "-1" to specify all
a61af66fc99e Initial load
duke
parents:
diff changeset
202 * remaining frames.
a61af66fc99e Initial load
duke
parents:
diff changeset
203 */
a61af66fc99e Initial load
duke
parents:
diff changeset
204
a61af66fc99e Initial load
duke
parents:
diff changeset
205 private List privateFrames(int start, int length)
a61af66fc99e Initial load
duke
parents:
diff changeset
206 throws IncompatibleThreadStateException {
a61af66fc99e Initial load
duke
parents:
diff changeset
207 if (myJavaThread == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
208 // for zombies and yet-to-be-started threads we need to throw exception
a61af66fc99e Initial load
duke
parents:
diff changeset
209 throw new IncompatibleThreadStateException();
a61af66fc99e Initial load
duke
parents:
diff changeset
210 }
a61af66fc99e Initial load
duke
parents:
diff changeset
211 if (frames == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
212 frames = new ArrayList(10);
a61af66fc99e Initial load
duke
parents:
diff changeset
213 JavaVFrame myvf = myJavaThread.getLastJavaVFrameDbg();
a61af66fc99e Initial load
duke
parents:
diff changeset
214 while (myvf != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
215 StackFrame myFrame = new StackFrameImpl(vm, this, myvf);
a61af66fc99e Initial load
duke
parents:
diff changeset
216 //fixme jjh null should be a Location
a61af66fc99e Initial load
duke
parents:
diff changeset
217 frames.add(myFrame);
a61af66fc99e Initial load
duke
parents:
diff changeset
218 myvf = (JavaVFrame)myvf.javaSender();
a61af66fc99e Initial load
duke
parents:
diff changeset
219 }
a61af66fc99e Initial load
duke
parents:
diff changeset
220 }
a61af66fc99e Initial load
duke
parents:
diff changeset
221
a61af66fc99e Initial load
duke
parents:
diff changeset
222 List retVal;
a61af66fc99e Initial load
duke
parents:
diff changeset
223 if (frames.size() == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
224 retVal = new ArrayList(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
225 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
226 int toIndex = start + length;
a61af66fc99e Initial load
duke
parents:
diff changeset
227 if (length == -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
228 toIndex = frames.size();
a61af66fc99e Initial load
duke
parents:
diff changeset
229 }
a61af66fc99e Initial load
duke
parents:
diff changeset
230 retVal = frames.subList(start, toIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
231 }
a61af66fc99e Initial load
duke
parents:
diff changeset
232 return Collections.unmodifiableList(retVal);
a61af66fc99e Initial load
duke
parents:
diff changeset
233 }
a61af66fc99e Initial load
duke
parents:
diff changeset
234
a61af66fc99e Initial load
duke
parents:
diff changeset
235 // refer to JvmtiEnvBase::get_owned_monitors
a61af66fc99e Initial load
duke
parents:
diff changeset
236 public List ownedMonitors() throws IncompatibleThreadStateException {
a61af66fc99e Initial load
duke
parents:
diff changeset
237 if (vm.canGetOwnedMonitorInfo() == false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
238 throw new UnsupportedOperationException();
a61af66fc99e Initial load
duke
parents:
diff changeset
239 }
a61af66fc99e Initial load
duke
parents:
diff changeset
240
a61af66fc99e Initial load
duke
parents:
diff changeset
241 if (myJavaThread == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
242 throw new IncompatibleThreadStateException();
a61af66fc99e Initial load
duke
parents:
diff changeset
243 }
a61af66fc99e Initial load
duke
parents:
diff changeset
244
a61af66fc99e Initial load
duke
parents:
diff changeset
245 if (ownedMonitors != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
246 return ownedMonitors;
a61af66fc99e Initial load
duke
parents:
diff changeset
247 }
a61af66fc99e Initial load
duke
parents:
diff changeset
248
a61af66fc99e Initial load
duke
parents:
diff changeset
249 ownedMonitorsWithStackDepth();
a61af66fc99e Initial load
duke
parents:
diff changeset
250
a61af66fc99e Initial load
duke
parents:
diff changeset
251 for (Iterator omi = ownedMonitorsInfo.iterator(); omi.hasNext(); ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
252 //FIXME : Change the MonitorInfoImpl cast to com.sun.jdi.MonitorInfo
a61af66fc99e Initial load
duke
parents:
diff changeset
253 // when hotspot start building with jdk1.6.
a61af66fc99e Initial load
duke
parents:
diff changeset
254 ownedMonitors.add(((MonitorInfoImpl)omi.next()).monitor());
a61af66fc99e Initial load
duke
parents:
diff changeset
255 }
a61af66fc99e Initial load
duke
parents:
diff changeset
256
a61af66fc99e Initial load
duke
parents:
diff changeset
257 return ownedMonitors;
a61af66fc99e Initial load
duke
parents:
diff changeset
258 }
a61af66fc99e Initial load
duke
parents:
diff changeset
259
a61af66fc99e Initial load
duke
parents:
diff changeset
260 // new method since 1.6.
a61af66fc99e Initial load
duke
parents:
diff changeset
261 // Real body will be supplied later.
a61af66fc99e Initial load
duke
parents:
diff changeset
262 public List ownedMonitorsAndFrames() throws IncompatibleThreadStateException {
a61af66fc99e Initial load
duke
parents:
diff changeset
263 if (!vm.canGetMonitorFrameInfo()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
264 throw new UnsupportedOperationException(
a61af66fc99e Initial load
duke
parents:
diff changeset
265 "target does not support getting Monitor Frame Info");
a61af66fc99e Initial load
duke
parents:
diff changeset
266 }
a61af66fc99e Initial load
duke
parents:
diff changeset
267
a61af66fc99e Initial load
duke
parents:
diff changeset
268 if (myJavaThread == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
269 throw new IncompatibleThreadStateException();
a61af66fc99e Initial load
duke
parents:
diff changeset
270 }
a61af66fc99e Initial load
duke
parents:
diff changeset
271
a61af66fc99e Initial load
duke
parents:
diff changeset
272 if (ownedMonitorsInfo != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
273 return ownedMonitorsInfo;
a61af66fc99e Initial load
duke
parents:
diff changeset
274 }
a61af66fc99e Initial load
duke
parents:
diff changeset
275
a61af66fc99e Initial load
duke
parents:
diff changeset
276 ownedMonitorsWithStackDepth();
a61af66fc99e Initial load
duke
parents:
diff changeset
277 return ownedMonitorsInfo;
a61af66fc99e Initial load
duke
parents:
diff changeset
278 }
a61af66fc99e Initial load
duke
parents:
diff changeset
279
a61af66fc99e Initial load
duke
parents:
diff changeset
280 private void ownedMonitorsWithStackDepth() {
a61af66fc99e Initial load
duke
parents:
diff changeset
281
a61af66fc99e Initial load
duke
parents:
diff changeset
282 ownedMonitorsInfo = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
283 List lockedObjects = new ArrayList(); // List<OopHandle>
a61af66fc99e Initial load
duke
parents:
diff changeset
284 List stackDepth = new ArrayList(); // List<int>
a61af66fc99e Initial load
duke
parents:
diff changeset
285 ObjectMonitor waitingMonitor = myJavaThread.getCurrentWaitingMonitor();
a61af66fc99e Initial load
duke
parents:
diff changeset
286 ObjectMonitor pendingMonitor = myJavaThread.getCurrentPendingMonitor();
a61af66fc99e Initial load
duke
parents:
diff changeset
287 OopHandle waitingObj = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
288 if (waitingMonitor != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
289 // save object of current wait() call (if any) for later comparison
a61af66fc99e Initial load
duke
parents:
diff changeset
290 waitingObj = waitingMonitor.object();
a61af66fc99e Initial load
duke
parents:
diff changeset
291 }
a61af66fc99e Initial load
duke
parents:
diff changeset
292 OopHandle pendingObj = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
293 if (pendingMonitor != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
294 // save object of current enter() call (if any) for later comparison
a61af66fc99e Initial load
duke
parents:
diff changeset
295 pendingObj = pendingMonitor.object();
a61af66fc99e Initial load
duke
parents:
diff changeset
296 }
a61af66fc99e Initial load
duke
parents:
diff changeset
297
a61af66fc99e Initial load
duke
parents:
diff changeset
298 JavaVFrame frame = myJavaThread.getLastJavaVFrameDbg();
a61af66fc99e Initial load
duke
parents:
diff changeset
299 int depth=0;
a61af66fc99e Initial load
duke
parents:
diff changeset
300 while (frame != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
301 List frameMonitors = frame.getMonitors(); // List<MonitorInfo>
a61af66fc99e Initial load
duke
parents:
diff changeset
302 for (Iterator miItr = frameMonitors.iterator(); miItr.hasNext(); ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
303 sun.jvm.hotspot.runtime.MonitorInfo mi = (sun.jvm.hotspot.runtime.MonitorInfo) miItr.next();
818
b109e761e927 6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents: 0
diff changeset
304 if (mi.eliminated() && frame.isCompiledFrame()) {
b109e761e927 6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents: 0
diff changeset
305 continue; // skip eliminated monitor
b109e761e927 6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents: 0
diff changeset
306 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
307 OopHandle obj = mi.owner();
a61af66fc99e Initial load
duke
parents:
diff changeset
308 if (obj == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
309 // this monitor doesn't have an owning object so skip it
a61af66fc99e Initial load
duke
parents:
diff changeset
310 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
311 }
a61af66fc99e Initial load
duke
parents:
diff changeset
312
a61af66fc99e Initial load
duke
parents:
diff changeset
313 if (obj.equals(waitingObj)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
314 // the thread is waiting on this monitor so it isn't really owned
a61af66fc99e Initial load
duke
parents:
diff changeset
315 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
316 }
a61af66fc99e Initial load
duke
parents:
diff changeset
317
a61af66fc99e Initial load
duke
parents:
diff changeset
318 if (obj.equals(pendingObj)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
319 // the thread is pending on this monitor so it isn't really owned
a61af66fc99e Initial load
duke
parents:
diff changeset
320 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
321 }
a61af66fc99e Initial load
duke
parents:
diff changeset
322
a61af66fc99e Initial load
duke
parents:
diff changeset
323 boolean found = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
324 for (Iterator loItr = lockedObjects.iterator(); loItr.hasNext(); ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
325 // check for recursive locks
a61af66fc99e Initial load
duke
parents:
diff changeset
326 if (obj.equals(loItr.next())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
327 found = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
328 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
329 }
a61af66fc99e Initial load
duke
parents:
diff changeset
330 }
a61af66fc99e Initial load
duke
parents:
diff changeset
331 if (found) {
a61af66fc99e Initial load
duke
parents:
diff changeset
332 // already have this object so don't include it
a61af66fc99e Initial load
duke
parents:
diff changeset
333 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
334 }
a61af66fc99e Initial load
duke
parents:
diff changeset
335 // add the owning object to our list
a61af66fc99e Initial load
duke
parents:
diff changeset
336 lockedObjects.add(obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
337 stackDepth.add(new Integer(depth));
a61af66fc99e Initial load
duke
parents:
diff changeset
338 }
a61af66fc99e Initial load
duke
parents:
diff changeset
339 frame = (JavaVFrame) frame.javaSender();
a61af66fc99e Initial load
duke
parents:
diff changeset
340 depth++;
a61af66fc99e Initial load
duke
parents:
diff changeset
341 }
a61af66fc99e Initial load
duke
parents:
diff changeset
342
a61af66fc99e Initial load
duke
parents:
diff changeset
343 // now convert List<OopHandle> to List<ObjectReference>
a61af66fc99e Initial load
duke
parents:
diff changeset
344 ObjectHeap heap = vm.saObjectHeap();
a61af66fc99e Initial load
duke
parents:
diff changeset
345 Iterator stk = stackDepth.iterator();
a61af66fc99e Initial load
duke
parents:
diff changeset
346 for (Iterator loItr = lockedObjects.iterator(); loItr.hasNext(); ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
347 Oop obj = heap.newOop((OopHandle)loItr.next());
a61af66fc99e Initial load
duke
parents:
diff changeset
348 ownedMonitorsInfo.add(new MonitorInfoImpl(vm, vm.objectMirror(obj), this,
a61af66fc99e Initial load
duke
parents:
diff changeset
349 ((Integer)stk.next()).intValue()));
a61af66fc99e Initial load
duke
parents:
diff changeset
350 }
a61af66fc99e Initial load
duke
parents:
diff changeset
351 }
a61af66fc99e Initial load
duke
parents:
diff changeset
352
a61af66fc99e Initial load
duke
parents:
diff changeset
353 // refer to JvmtiEnvBase::get_current_contended_monitor
a61af66fc99e Initial load
duke
parents:
diff changeset
354 public ObjectReference currentContendedMonitor()
a61af66fc99e Initial load
duke
parents:
diff changeset
355 throws IncompatibleThreadStateException {
a61af66fc99e Initial load
duke
parents:
diff changeset
356 if (vm.canGetCurrentContendedMonitor() == false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
357 throw new UnsupportedOperationException();
a61af66fc99e Initial load
duke
parents:
diff changeset
358 }
a61af66fc99e Initial load
duke
parents:
diff changeset
359
a61af66fc99e Initial load
duke
parents:
diff changeset
360 if (myJavaThread == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
361 throw new IncompatibleThreadStateException();
a61af66fc99e Initial load
duke
parents:
diff changeset
362 }
a61af66fc99e Initial load
duke
parents:
diff changeset
363 ObjectMonitor mon = myJavaThread.getCurrentWaitingMonitor();
a61af66fc99e Initial load
duke
parents:
diff changeset
364 if (mon == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
365 // thread is not doing an Object.wait() call
a61af66fc99e Initial load
duke
parents:
diff changeset
366 mon = myJavaThread.getCurrentPendingMonitor();
a61af66fc99e Initial load
duke
parents:
diff changeset
367 if (mon != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
368 OopHandle handle = mon.object();
a61af66fc99e Initial load
duke
parents:
diff changeset
369 // If obj == NULL, then ObjectMonitor is raw which doesn't count
a61af66fc99e Initial load
duke
parents:
diff changeset
370 // as contended for this API
a61af66fc99e Initial load
duke
parents:
diff changeset
371 return vm.objectMirror(vm.saObjectHeap().newOop(handle));
a61af66fc99e Initial load
duke
parents:
diff changeset
372 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
373 // no contended ObjectMonitor
a61af66fc99e Initial load
duke
parents:
diff changeset
374 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
375 }
a61af66fc99e Initial load
duke
parents:
diff changeset
376 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
377 // thread is doing an Object.wait() call
a61af66fc99e Initial load
duke
parents:
diff changeset
378 OopHandle handle = mon.object();
a61af66fc99e Initial load
duke
parents:
diff changeset
379 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
380 Assert.that(handle != null, "Object.wait() should have an object");
a61af66fc99e Initial load
duke
parents:
diff changeset
381 }
a61af66fc99e Initial load
duke
parents:
diff changeset
382 Oop obj = vm.saObjectHeap().newOop(handle);
a61af66fc99e Initial load
duke
parents:
diff changeset
383 return vm.objectMirror(obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
384 }
a61af66fc99e Initial load
duke
parents:
diff changeset
385 }
a61af66fc99e Initial load
duke
parents:
diff changeset
386
a61af66fc99e Initial load
duke
parents:
diff changeset
387
a61af66fc99e Initial load
duke
parents:
diff changeset
388 public void popFrames(StackFrame frame) throws IncompatibleThreadStateException {
a61af66fc99e Initial load
duke
parents:
diff changeset
389 vm.throwNotReadOnlyException("ThreadReference.popFrames()");
a61af66fc99e Initial load
duke
parents:
diff changeset
390 }
a61af66fc99e Initial load
duke
parents:
diff changeset
391
a61af66fc99e Initial load
duke
parents:
diff changeset
392 public void forceEarlyReturn(Value returnValue) throws IncompatibleThreadStateException {
a61af66fc99e Initial load
duke
parents:
diff changeset
393 vm.throwNotReadOnlyException("ThreadReference.forceEarlyReturn()");
a61af66fc99e Initial load
duke
parents:
diff changeset
394 }
a61af66fc99e Initial load
duke
parents:
diff changeset
395
a61af66fc99e Initial load
duke
parents:
diff changeset
396 public String toString() {
a61af66fc99e Initial load
duke
parents:
diff changeset
397 return "instance of " + referenceType().name() +
a61af66fc99e Initial load
duke
parents:
diff changeset
398 "(name='" + name() + "', " + "id=" + uniqueID() + ")";
a61af66fc99e Initial load
duke
parents:
diff changeset
399 }
a61af66fc99e Initial load
duke
parents:
diff changeset
400 }