2
|
1 |
/*
|
|
2 |
* Copyright 1998-2005 Sun Microsystems, Inc. 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. Sun designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Sun in the LICENSE file that accompanied this code.
|
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
23 |
* have any questions.
|
|
24 |
*/
|
|
25 |
|
|
26 |
package com.sun.tools.jdi;
|
|
27 |
|
|
28 |
import com.sun.jdi.*;
|
|
29 |
import com.sun.jdi.request.BreakpointRequest;
|
|
30 |
import java.util.*;
|
|
31 |
import java.lang.ref.WeakReference;
|
|
32 |
|
|
33 |
public class ThreadReferenceImpl extends ObjectReferenceImpl
|
|
34 |
implements ThreadReference, VMListener {
|
|
35 |
static final int SUSPEND_STATUS_SUSPENDED = 0x1;
|
|
36 |
static final int SUSPEND_STATUS_BREAK = 0x2;
|
|
37 |
|
|
38 |
private ThreadGroupReference threadGroup;
|
|
39 |
private int suspendedZombieCount = 0;
|
|
40 |
|
|
41 |
// This is cached only while the VM is suspended
|
|
42 |
private static class Cache extends ObjectReferenceImpl.Cache {
|
|
43 |
String name = null;
|
|
44 |
JDWP.ThreadReference.Status status = null;
|
|
45 |
List<StackFrame> frames = null;
|
|
46 |
int framesStart = -1;
|
|
47 |
int framesLength = 0;
|
|
48 |
int frameCount = -1;
|
|
49 |
List<ObjectReference> ownedMonitors = null;
|
|
50 |
List<MonitorInfo> ownedMonitorsInfo = null;
|
|
51 |
ObjectReference contendedMonitor = null;
|
|
52 |
boolean triedCurrentContended = false;
|
|
53 |
}
|
|
54 |
|
|
55 |
protected ObjectReferenceImpl.Cache newCache() {
|
|
56 |
return new Cache();
|
|
57 |
}
|
|
58 |
|
|
59 |
// Listeners - synchronized on vm.state()
|
|
60 |
private List<WeakReference<ThreadListener>> listeners = new ArrayList<WeakReference<ThreadListener>>();
|
|
61 |
|
|
62 |
ThreadReferenceImpl(VirtualMachine aVm, long aRef) {
|
|
63 |
super(aVm,aRef);
|
|
64 |
vm.state().addListener(this);
|
|
65 |
}
|
|
66 |
|
|
67 |
protected String description() {
|
|
68 |
return "ThreadReference " + uniqueID();
|
|
69 |
}
|
|
70 |
|
|
71 |
/*
|
|
72 |
* VMListener implementation
|
|
73 |
*/
|
|
74 |
public boolean vmNotSuspended(VMAction action) {
|
|
75 |
synchronized (vm.state()) {
|
|
76 |
processThreadAction(new ThreadAction(this,
|
|
77 |
ThreadAction.THREAD_RESUMABLE));
|
|
78 |
}
|
|
79 |
return super.vmNotSuspended(action);
|
|
80 |
}
|
|
81 |
|
|
82 |
/**
|
|
83 |
* Note that we only cache the name string while suspended because
|
|
84 |
* it can change via Thread.setName arbitrarily
|
|
85 |
*/
|
|
86 |
public String name() {
|
|
87 |
String name = null;
|
|
88 |
try {
|
|
89 |
Cache local = (Cache)getCache();
|
|
90 |
|
|
91 |
if (local != null) {
|
|
92 |
name = local.name;
|
|
93 |
}
|
|
94 |
if (name == null) {
|
|
95 |
name = JDWP.ThreadReference.Name.process(vm, this)
|
|
96 |
.threadName;
|
|
97 |
if (local != null) {
|
|
98 |
local.name = name;
|
|
99 |
}
|
|
100 |
}
|
|
101 |
} catch (JDWPException exc) {
|
|
102 |
throw exc.toJDIException();
|
|
103 |
}
|
|
104 |
return name;
|
|
105 |
}
|
|
106 |
|
|
107 |
/*
|
|
108 |
* Sends a command to the back end which is defined to do an
|
|
109 |
* implicit vm-wide resume.
|
|
110 |
*/
|
|
111 |
PacketStream sendResumingCommand(CommandSender sender) {
|
|
112 |
synchronized (vm.state()) {
|
|
113 |
processThreadAction(new ThreadAction(this,
|
|
114 |
ThreadAction.THREAD_RESUMABLE));
|
|
115 |
return sender.send();
|
|
116 |
}
|
|
117 |
}
|
|
118 |
|
|
119 |
public void suspend() {
|
|
120 |
try {
|
|
121 |
JDWP.ThreadReference.Suspend.process(vm, this);
|
|
122 |
} catch (JDWPException exc) {
|
|
123 |
throw exc.toJDIException();
|
|
124 |
}
|
|
125 |
// Don't consider the thread suspended yet. On reply, notifySuspend()
|
|
126 |
// will be called.
|
|
127 |
}
|
|
128 |
|
|
129 |
public void resume() {
|
|
130 |
/*
|
|
131 |
* If it's a zombie, we can just update internal state without
|
|
132 |
* going to back end.
|
|
133 |
*/
|
|
134 |
if (suspendedZombieCount > 0) {
|
|
135 |
suspendedZombieCount--;
|
|
136 |
return;
|
|
137 |
}
|
|
138 |
|
|
139 |
PacketStream stream;
|
|
140 |
synchronized (vm.state()) {
|
|
141 |
processThreadAction(new ThreadAction(this,
|
|
142 |
ThreadAction.THREAD_RESUMABLE));
|
|
143 |
stream = JDWP.ThreadReference.Resume.enqueueCommand(vm, this);
|
|
144 |
}
|
|
145 |
try {
|
|
146 |
JDWP.ThreadReference.Resume.waitForReply(vm, stream);
|
|
147 |
} catch (JDWPException exc) {
|
|
148 |
throw exc.toJDIException();
|
|
149 |
}
|
|
150 |
}
|
|
151 |
|
|
152 |
public int suspendCount() {
|
|
153 |
/*
|
|
154 |
* If it's a zombie, we maintain the count in the front end.
|
|
155 |
*/
|
|
156 |
if (suspendedZombieCount > 0) {
|
|
157 |
return suspendedZombieCount;
|
|
158 |
}
|
|
159 |
|
|
160 |
try {
|
|
161 |
return JDWP.ThreadReference.SuspendCount.process(vm, this).suspendCount;
|
|
162 |
} catch (JDWPException exc) {
|
|
163 |
throw exc.toJDIException();
|
|
164 |
}
|
|
165 |
}
|
|
166 |
|
|
167 |
public void stop(ObjectReference throwable) throws InvalidTypeException {
|
|
168 |
validateMirror(throwable);
|
|
169 |
// Verify that the given object is a Throwable instance
|
|
170 |
List list = vm.classesByName("java.lang.Throwable");
|
|
171 |
ClassTypeImpl throwableClass = (ClassTypeImpl)list.get(0);
|
|
172 |
if ((throwable == null) ||
|
|
173 |
!throwableClass.isAssignableFrom(throwable)) {
|
|
174 |
throw new InvalidTypeException("Not an instance of Throwable");
|
|
175 |
}
|
|
176 |
|
|
177 |
try {
|
|
178 |
JDWP.ThreadReference.Stop.process(vm, this,
|
|
179 |
(ObjectReferenceImpl)throwable);
|
|
180 |
} catch (JDWPException exc) {
|
|
181 |
throw exc.toJDIException();
|
|
182 |
}
|
|
183 |
}
|
|
184 |
|
|
185 |
public void interrupt() {
|
|
186 |
try {
|
|
187 |
JDWP.ThreadReference.Interrupt.process(vm, this);
|
|
188 |
} catch (JDWPException exc) {
|
|
189 |
throw exc.toJDIException();
|
|
190 |
}
|
|
191 |
}
|
|
192 |
|
|
193 |
private JDWP.ThreadReference.Status jdwpStatus() {
|
|
194 |
JDWP.ThreadReference.Status status = null;
|
|
195 |
try {
|
|
196 |
Cache local = (Cache)getCache();
|
|
197 |
|
|
198 |
if (local != null) {
|
|
199 |
status = local.status;
|
|
200 |
}
|
|
201 |
if (status == null) {
|
|
202 |
status = JDWP.ThreadReference.Status.process(vm, this);
|
|
203 |
if (local != null) {
|
|
204 |
local.status = status;
|
|
205 |
}
|
|
206 |
}
|
|
207 |
} catch (JDWPException exc) {
|
|
208 |
throw exc.toJDIException();
|
|
209 |
}
|
|
210 |
return status;
|
|
211 |
}
|
|
212 |
|
|
213 |
public int status() {
|
|
214 |
return jdwpStatus().threadStatus;
|
|
215 |
}
|
|
216 |
|
|
217 |
public boolean isSuspended() {
|
|
218 |
return ((suspendedZombieCount > 0) ||
|
|
219 |
((jdwpStatus().suspendStatus & SUSPEND_STATUS_SUSPENDED) != 0));
|
|
220 |
}
|
|
221 |
|
|
222 |
public boolean isAtBreakpoint() {
|
|
223 |
/*
|
|
224 |
* TO DO: This fails to take filters into account.
|
|
225 |
*/
|
|
226 |
try {
|
|
227 |
StackFrame frame = frame(0);
|
|
228 |
Location location = frame.location();
|
|
229 |
List requests = vm.eventRequestManager().breakpointRequests();
|
|
230 |
Iterator iter = requests.iterator();
|
|
231 |
while (iter.hasNext()) {
|
|
232 |
BreakpointRequest request = (BreakpointRequest)iter.next();
|
|
233 |
if (location.equals(request.location())) {
|
|
234 |
return true;
|
|
235 |
}
|
|
236 |
}
|
|
237 |
return false;
|
|
238 |
} catch (IndexOutOfBoundsException iobe) {
|
|
239 |
return false; // no frames on stack => not at breakpoint
|
|
240 |
} catch (IncompatibleThreadStateException itse) {
|
|
241 |
// Per the javadoc, not suspended => return false
|
|
242 |
return false;
|
|
243 |
}
|
|
244 |
}
|
|
245 |
|
|
246 |
public ThreadGroupReference threadGroup() {
|
|
247 |
/*
|
|
248 |
* Thread group can't change, so it's cached more conventionally
|
|
249 |
* than other things in this class.
|
|
250 |
*/
|
|
251 |
if (threadGroup == null) {
|
|
252 |
try {
|
|
253 |
threadGroup = JDWP.ThreadReference.ThreadGroup.
|
|
254 |
process(vm, this).group;
|
|
255 |
} catch (JDWPException exc) {
|
|
256 |
throw exc.toJDIException();
|
|
257 |
}
|
|
258 |
}
|
|
259 |
return threadGroup;
|
|
260 |
}
|
|
261 |
|
|
262 |
public int frameCount() throws IncompatibleThreadStateException {
|
|
263 |
int frameCount = -1;
|
|
264 |
try {
|
|
265 |
Cache local = (Cache)getCache();
|
|
266 |
|
|
267 |
if (local != null) {
|
|
268 |
frameCount = local.frameCount;
|
|
269 |
}
|
|
270 |
if (frameCount == -1) {
|
|
271 |
frameCount = JDWP.ThreadReference.FrameCount
|
|
272 |
.process(vm, this).frameCount;
|
|
273 |
if (local != null) {
|
|
274 |
local.frameCount = frameCount;
|
|
275 |
}
|
|
276 |
}
|
|
277 |
} catch (JDWPException exc) {
|
|
278 |
switch (exc.errorCode()) {
|
|
279 |
case JDWP.Error.THREAD_NOT_SUSPENDED:
|
|
280 |
case JDWP.Error.INVALID_THREAD: /* zombie */
|
|
281 |
throw new IncompatibleThreadStateException();
|
|
282 |
default:
|
|
283 |
throw exc.toJDIException();
|
|
284 |
}
|
|
285 |
}
|
|
286 |
return frameCount;
|
|
287 |
}
|
|
288 |
|
|
289 |
public List<StackFrame> frames() throws IncompatibleThreadStateException {
|
|
290 |
return privateFrames(0, -1);
|
|
291 |
}
|
|
292 |
|
|
293 |
public StackFrame frame(int index) throws IncompatibleThreadStateException {
|
|
294 |
List list = privateFrames(index, 1);
|
|
295 |
return (StackFrame)list.get(0);
|
|
296 |
}
|
|
297 |
|
|
298 |
/**
|
|
299 |
* Is the requested subrange within what has been retrieved?
|
|
300 |
* local is known to be non-null
|
|
301 |
*/
|
|
302 |
private boolean isSubrange(Cache local,
|
|
303 |
int start, int length, List frames) {
|
|
304 |
if (start < local.framesStart) {
|
|
305 |
return false;
|
|
306 |
}
|
|
307 |
if (length == -1) {
|
|
308 |
return (local.framesLength == -1);
|
|
309 |
}
|
|
310 |
if (local.framesLength == -1) {
|
|
311 |
if ((start + length) > (local.framesStart + frames.size())) {
|
|
312 |
throw new IndexOutOfBoundsException();
|
|
313 |
}
|
|
314 |
return true;
|
|
315 |
}
|
|
316 |
return ((start + length) <= (local.framesStart + local.framesLength));
|
|
317 |
}
|
|
318 |
|
|
319 |
public List<StackFrame> frames(int start, int length)
|
|
320 |
throws IncompatibleThreadStateException {
|
|
321 |
if (length < 0) {
|
|
322 |
throw new IndexOutOfBoundsException(
|
|
323 |
"length must be greater than or equal to zero");
|
|
324 |
}
|
|
325 |
return privateFrames(start, length);
|
|
326 |
}
|
|
327 |
|
|
328 |
/**
|
|
329 |
* Private version of frames() allows "-1" to specify all
|
|
330 |
* remaining frames.
|
|
331 |
*/
|
|
332 |
private List<StackFrame> privateFrames(int start, int length)
|
|
333 |
throws IncompatibleThreadStateException {
|
|
334 |
List<StackFrame> frames = null;
|
|
335 |
try {
|
|
336 |
Cache local = (Cache)getCache();
|
|
337 |
|
|
338 |
if (local != null) {
|
|
339 |
frames = local.frames;
|
|
340 |
}
|
|
341 |
if (frames == null || !isSubrange(local, start, length, frames)) {
|
|
342 |
JDWP.ThreadReference.Frames.Frame[] jdwpFrames
|
|
343 |
= JDWP.ThreadReference.Frames.
|
|
344 |
process(vm, this, start, length).frames;
|
|
345 |
int count = jdwpFrames.length;
|
|
346 |
frames = new ArrayList<StackFrame>(count);
|
|
347 |
|
|
348 |
// Lock must be held while creating stack frames.
|
|
349 |
// so that a resume will not resume a partially
|
|
350 |
// created stack.
|
|
351 |
synchronized (vm.state()) {
|
|
352 |
for (int i = 0; i<count; i++) {
|
|
353 |
if (jdwpFrames[i].location == null) {
|
|
354 |
throw new InternalException("Invalid frame location");
|
|
355 |
}
|
|
356 |
StackFrame frame = new StackFrameImpl(vm, this,
|
|
357 |
jdwpFrames[i].frameID,
|
|
358 |
jdwpFrames[i].location);
|
|
359 |
// Add to the frame list
|
|
360 |
frames.add(frame);
|
|
361 |
}
|
|
362 |
}
|
|
363 |
if (local != null) {
|
|
364 |
local.frames = frames;
|
|
365 |
local.framesStart = start;
|
|
366 |
local.framesLength = length;
|
|
367 |
}
|
|
368 |
} else {
|
|
369 |
int fromIndex = start - local.framesStart;
|
|
370 |
int toIndex;
|
|
371 |
if (length == -1) {
|
|
372 |
toIndex = frames.size() - fromIndex;
|
|
373 |
} else {
|
|
374 |
toIndex = fromIndex + length;
|
|
375 |
}
|
|
376 |
frames = frames.subList(fromIndex, toIndex);
|
|
377 |
}
|
|
378 |
} catch (JDWPException exc) {
|
|
379 |
switch (exc.errorCode()) {
|
|
380 |
case JDWP.Error.THREAD_NOT_SUSPENDED:
|
|
381 |
case JDWP.Error.INVALID_THREAD: /* zombie */
|
|
382 |
throw new IncompatibleThreadStateException();
|
|
383 |
default:
|
|
384 |
throw exc.toJDIException();
|
|
385 |
}
|
|
386 |
}
|
|
387 |
return Collections.unmodifiableList(frames);
|
|
388 |
}
|
|
389 |
|
|
390 |
public List<ObjectReference> ownedMonitors() throws IncompatibleThreadStateException {
|
|
391 |
List<ObjectReference> monitors = null;
|
|
392 |
try {
|
|
393 |
Cache local = (Cache)getCache();
|
|
394 |
|
|
395 |
if (local != null) {
|
|
396 |
monitors = local.ownedMonitors;
|
|
397 |
}
|
|
398 |
if (monitors == null) {
|
|
399 |
monitors = Arrays.asList(
|
|
400 |
(ObjectReference[])JDWP.ThreadReference.OwnedMonitors.
|
|
401 |
process(vm, this).owned);
|
|
402 |
if (local != null) {
|
|
403 |
local.ownedMonitors = monitors;
|
|
404 |
if ((vm.traceFlags & vm.TRACE_OBJREFS) != 0) {
|
|
405 |
vm.printTrace(description() +
|
|
406 |
" temporarily caching owned monitors"+
|
|
407 |
" (count = " + monitors.size() + ")");
|
|
408 |
}
|
|
409 |
}
|
|
410 |
}
|
|
411 |
} catch (JDWPException exc) {
|
|
412 |
switch (exc.errorCode()) {
|
|
413 |
case JDWP.Error.THREAD_NOT_SUSPENDED:
|
|
414 |
case JDWP.Error.INVALID_THREAD: /* zombie */
|
|
415 |
throw new IncompatibleThreadStateException();
|
|
416 |
default:
|
|
417 |
throw exc.toJDIException();
|
|
418 |
}
|
|
419 |
}
|
|
420 |
return monitors;
|
|
421 |
}
|
|
422 |
|
|
423 |
public ObjectReference currentContendedMonitor()
|
|
424 |
throws IncompatibleThreadStateException {
|
|
425 |
ObjectReference monitor = null;
|
|
426 |
try {
|
|
427 |
Cache local = (Cache)getCache();
|
|
428 |
|
|
429 |
if (local != null && local.triedCurrentContended) {
|
|
430 |
monitor = local.contendedMonitor;
|
|
431 |
} else {
|
|
432 |
monitor = JDWP.ThreadReference.CurrentContendedMonitor.
|
|
433 |
process(vm, this).monitor;
|
|
434 |
if (local != null) {
|
|
435 |
local.triedCurrentContended = true;
|
|
436 |
local.contendedMonitor = monitor;
|
|
437 |
if ((monitor != null) &&
|
|
438 |
((vm.traceFlags & vm.TRACE_OBJREFS) != 0)) {
|
|
439 |
vm.printTrace(description() +
|
|
440 |
" temporarily caching contended monitor"+
|
|
441 |
" (id = " + monitor.uniqueID() + ")");
|
|
442 |
}
|
|
443 |
}
|
|
444 |
}
|
|
445 |
} catch (JDWPException exc) {
|
|
446 |
switch (exc.errorCode()) {
|
|
447 |
case JDWP.Error.INVALID_THREAD: /* zombie */
|
|
448 |
throw new IncompatibleThreadStateException();
|
|
449 |
default:
|
|
450 |
throw exc.toJDIException();
|
|
451 |
}
|
|
452 |
}
|
|
453 |
return monitor;
|
|
454 |
}
|
|
455 |
|
|
456 |
public List<MonitorInfo> ownedMonitorsAndFrames() throws IncompatibleThreadStateException {
|
|
457 |
List<MonitorInfo> monitors = null;
|
|
458 |
try {
|
|
459 |
Cache local = (Cache)getCache();
|
|
460 |
|
|
461 |
if (local != null) {
|
|
462 |
monitors = local.ownedMonitorsInfo;
|
|
463 |
}
|
|
464 |
if (monitors == null) {
|
|
465 |
JDWP.ThreadReference.OwnedMonitorsStackDepthInfo.monitor[] minfo;
|
|
466 |
minfo = JDWP.ThreadReference.OwnedMonitorsStackDepthInfo.process(vm, this).owned;
|
|
467 |
|
|
468 |
monitors = new ArrayList<MonitorInfo>(minfo.length);
|
|
469 |
|
|
470 |
for (int i=0; i < minfo.length; i++) {
|
|
471 |
JDWP.ThreadReference.OwnedMonitorsStackDepthInfo.monitor mi =
|
|
472 |
minfo[i];
|
|
473 |
MonitorInfo mon = new MonitorInfoImpl(vm, minfo[i].monitor, this, minfo[i].stack_depth);
|
|
474 |
monitors.add(mon);
|
|
475 |
}
|
|
476 |
|
|
477 |
if (local != null) {
|
|
478 |
local.ownedMonitorsInfo = monitors;
|
|
479 |
if ((vm.traceFlags & vm.TRACE_OBJREFS) != 0) {
|
|
480 |
vm.printTrace(description() +
|
|
481 |
" temporarily caching owned monitors"+
|
|
482 |
" (count = " + monitors.size() + ")");
|
|
483 |
}
|
|
484 |
}
|
|
485 |
|
|
486 |
}
|
|
487 |
} catch (JDWPException exc) {
|
|
488 |
switch (exc.errorCode()) {
|
|
489 |
case JDWP.Error.THREAD_NOT_SUSPENDED:
|
|
490 |
case JDWP.Error.INVALID_THREAD: /* zombie */
|
|
491 |
throw new IncompatibleThreadStateException();
|
|
492 |
default:
|
|
493 |
throw exc.toJDIException();
|
|
494 |
}
|
|
495 |
}
|
|
496 |
return monitors;
|
|
497 |
}
|
|
498 |
|
|
499 |
public void popFrames(StackFrame frame) throws IncompatibleThreadStateException {
|
|
500 |
// Note that interface-wise this functionality belongs
|
|
501 |
// here in ThreadReference, but implementation-wise it
|
|
502 |
// belongs in StackFrame, so we just forward it.
|
|
503 |
if (!frame.thread().equals(this)) {
|
|
504 |
throw new IllegalArgumentException("frame does not belong to this thread");
|
|
505 |
}
|
|
506 |
if (!vm.canPopFrames()) {
|
|
507 |
throw new UnsupportedOperationException(
|
|
508 |
"target does not support popping frames");
|
|
509 |
}
|
|
510 |
((StackFrameImpl)frame).pop();
|
|
511 |
}
|
|
512 |
|
|
513 |
public void forceEarlyReturn(Value returnValue) throws InvalidTypeException,
|
|
514 |
ClassNotLoadedException,
|
|
515 |
IncompatibleThreadStateException {
|
|
516 |
if (!vm.canForceEarlyReturn()) {
|
|
517 |
throw new UnsupportedOperationException(
|
|
518 |
"target does not support the forcing of a method to return early");
|
|
519 |
}
|
|
520 |
|
|
521 |
validateMirrorOrNull(returnValue);
|
|
522 |
|
|
523 |
StackFrameImpl sf;
|
|
524 |
try {
|
|
525 |
sf = (StackFrameImpl)frame(0);
|
|
526 |
} catch (IndexOutOfBoundsException exc) {
|
|
527 |
throw new InvalidStackFrameException("No more frames on the stack");
|
|
528 |
}
|
|
529 |
sf.validateStackFrame();
|
|
530 |
MethodImpl meth = (MethodImpl)sf.location().method();
|
|
531 |
ValueImpl convertedValue = ValueImpl.prepareForAssignment(returnValue,
|
|
532 |
meth.getReturnValueContainer());
|
|
533 |
|
|
534 |
try {
|
|
535 |
JDWP.ThreadReference.ForceEarlyReturn.process(vm, this, convertedValue);
|
|
536 |
} catch (JDWPException exc) {
|
|
537 |
switch (exc.errorCode()) {
|
|
538 |
case JDWP.Error.OPAQUE_FRAME:
|
|
539 |
throw new NativeMethodException();
|
|
540 |
case JDWP.Error.THREAD_NOT_SUSPENDED:
|
|
541 |
throw new IncompatibleThreadStateException(
|
|
542 |
"Thread not suspended");
|
|
543 |
case JDWP.Error.THREAD_NOT_ALIVE:
|
|
544 |
throw new IncompatibleThreadStateException(
|
|
545 |
"Thread has not started or has finished");
|
|
546 |
case JDWP.Error.NO_MORE_FRAMES:
|
|
547 |
throw new InvalidStackFrameException(
|
|
548 |
"No more frames on the stack");
|
|
549 |
default:
|
|
550 |
throw exc.toJDIException();
|
|
551 |
}
|
|
552 |
}
|
|
553 |
}
|
|
554 |
|
|
555 |
public String toString() {
|
|
556 |
return "instance of " + referenceType().name() +
|
|
557 |
"(name='" + name() + "', " + "id=" + uniqueID() + ")";
|
|
558 |
}
|
|
559 |
|
|
560 |
byte typeValueKey() {
|
|
561 |
return JDWP.Tag.THREAD;
|
|
562 |
}
|
|
563 |
|
|
564 |
void addListener(ThreadListener listener) {
|
|
565 |
synchronized (vm.state()) {
|
|
566 |
listeners.add(new WeakReference<ThreadListener>(listener));
|
|
567 |
}
|
|
568 |
}
|
|
569 |
|
|
570 |
void removeListener(ThreadListener listener) {
|
|
571 |
synchronized (vm.state()) {
|
|
572 |
Iterator iter = listeners.iterator();
|
|
573 |
while (iter.hasNext()) {
|
|
574 |
WeakReference ref = (WeakReference)iter.next();
|
|
575 |
if (listener.equals(ref.get())) {
|
|
576 |
iter.remove();
|
|
577 |
break;
|
|
578 |
}
|
|
579 |
}
|
|
580 |
}
|
|
581 |
}
|
|
582 |
|
|
583 |
/**
|
|
584 |
* Propagate the the thread state change information
|
|
585 |
* to registered listeners.
|
|
586 |
* Must be entered while synchronized on vm.state()
|
|
587 |
*/
|
|
588 |
private void processThreadAction(ThreadAction action) {
|
|
589 |
synchronized (vm.state()) {
|
|
590 |
Iterator iter = listeners.iterator();
|
|
591 |
while (iter.hasNext()) {
|
|
592 |
WeakReference ref = (WeakReference)iter.next();
|
|
593 |
ThreadListener listener = (ThreadListener)ref.get();
|
|
594 |
if (listener != null) {
|
|
595 |
switch (action.id()) {
|
|
596 |
case ThreadAction.THREAD_RESUMABLE:
|
|
597 |
if (!listener.threadResumable(action)) {
|
|
598 |
iter.remove();
|
|
599 |
}
|
|
600 |
break;
|
|
601 |
}
|
|
602 |
} else {
|
|
603 |
// Listener is unreachable; clean up
|
|
604 |
iter.remove();
|
|
605 |
}
|
|
606 |
}
|
|
607 |
}
|
|
608 |
}
|
|
609 |
}
|