0N/A/*
2362N/A * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage com.sun.tools.jdi;
0N/A
0N/Aimport com.sun.jdi.*;
0N/Aimport com.sun.jdi.request.BreakpointRequest;
0N/Aimport java.util.*;
0N/Aimport java.lang.ref.WeakReference;
0N/A
0N/Apublic class ThreadReferenceImpl extends ObjectReferenceImpl
0N/A implements ThreadReference, VMListener {
0N/A static final int SUSPEND_STATUS_SUSPENDED = 0x1;
0N/A static final int SUSPEND_STATUS_BREAK = 0x2;
0N/A
0N/A private int suspendedZombieCount = 0;
0N/A
409N/A /*
409N/A * Some objects can only be created while a thread is suspended and are valid
409N/A * only while the thread remains suspended. Examples are StackFrameImpl
409N/A * and MonitorInfoImpl. When the thread resumes, these objects have to be
409N/A * marked as invalid so that their methods can throw
409N/A * InvalidStackFrameException if they are called. To do this, such objects
409N/A * register themselves as listeners of the associated thread. When the
409N/A * thread is resumed, its listeners are notified and mark themselves
409N/A * invalid.
409N/A * Also, note that ThreadReferenceImpl itself caches some info that
409N/A * is valid only as long as the thread is suspended. When the thread
409N/A * is resumed, that cache must be purged.
409N/A * Lastly, note that ThreadReferenceImpl and its super, ObjectReferenceImpl
409N/A * cache some info that is only valid as long as the entire VM is suspended.
409N/A * If _any_ thread is resumed, this cache must be purged. To handle this,
409N/A * both ThreadReferenceImpl and ObjectReferenceImpl register themselves as
409N/A * VMListeners so that they get notified when all threads are suspended and
409N/A * when any thread is resumed.
409N/A */
409N/A
409N/A // This is cached for the life of the thread
409N/A private ThreadGroupReference threadGroup;
409N/A
409N/A // This is cached only while this one thread is suspended. Each time
650N/A // the thread is resumed, we abandon the current cache object and
650N/A // create a new intialized one.
409N/A private static class LocalCache {
0N/A JDWP.ThreadReference.Status status = null;
0N/A List<StackFrame> frames = null;
0N/A int framesStart = -1;
0N/A int framesLength = 0;
0N/A int frameCount = -1;
0N/A List<ObjectReference> ownedMonitors = null;
0N/A List<MonitorInfo> ownedMonitorsInfo = null;
0N/A ObjectReference contendedMonitor = null;
0N/A boolean triedCurrentContended = false;
0N/A }
0N/A
650N/A /*
650N/A * The localCache instance var is set by resetLocalCache to an initialized
650N/A * object as shown above. This occurs when the ThreadReference
650N/A * object is created, and when the mirrored thread is resumed.
650N/A * The fields are then filled in by the relevant methods as they
650N/A * are called. A problem can occur if resetLocalCache is called
650N/A * (ie, a resume() is executed) at certain points in the execution
650N/A * of some of these methods - see 6751643. To avoid this, each
650N/A * method that wants to use this cache must make a local copy of
650N/A * this variable and use that. This means that each invocation of
650N/A * these methods will use a copy of the cache object that was in
650N/A * effect at the point that the copy was made; if a racy resume
650N/A * occurs, it won't affect the method's local copy. This means that
650N/A * the values returned by these calls may not match the state of
650N/A * the debuggee at the time the caller gets the values. EG,
650N/A * frameCount() is called and comes up with 5 frames. But before
650N/A * it returns this, a resume of the debuggee thread is executed in a
650N/A * different debugger thread. The thread is resumed and running at
650N/A * the time that the value 5 is returned. Or even worse, the thread
650N/A * could be suspended again and have a different number of frames, eg, 24,
650N/A * but this call will still return 5.
650N/A */
409N/A private LocalCache localCache;
409N/A
409N/A private void resetLocalCache() {
409N/A localCache = new LocalCache();
409N/A }
409N/A
409N/A // This is cached only while all threads in the VM are suspended
409N/A // Yes, someone could change the name of a thread while it is suspended.
409N/A private static class Cache extends ObjectReferenceImpl.Cache {
409N/A String name = null;
409N/A }
0N/A protected ObjectReferenceImpl.Cache newCache() {
0N/A return new Cache();
0N/A }
0N/A
0N/A // Listeners - synchronized on vm.state()
0N/A private List<WeakReference<ThreadListener>> listeners = new ArrayList<WeakReference<ThreadListener>>();
0N/A
409N/A
0N/A ThreadReferenceImpl(VirtualMachine aVm, long aRef) {
0N/A super(aVm,aRef);
409N/A resetLocalCache();
0N/A vm.state().addListener(this);
0N/A }
0N/A
0N/A protected String description() {
0N/A return "ThreadReference " + uniqueID();
0N/A }
0N/A
0N/A /*
0N/A * VMListener implementation
0N/A */
0N/A public boolean vmNotSuspended(VMAction action) {
409N/A if (action.resumingThread() == null) {
409N/A // all threads are being resumed
409N/A synchronized (vm.state()) {
409N/A processThreadAction(new ThreadAction(this,
409N/A ThreadAction.THREAD_RESUMABLE));
409N/A }
409N/A
0N/A }
409N/A
409N/A /*
409N/A * Othewise, only one thread is being resumed:
409N/A * if it is us,
409N/A * we have already done our processThreadAction to notify our
409N/A * listeners when we processed the resume.
409N/A * if it is not us,
409N/A * we don't want to notify our listeners
409N/A * because we are not being resumed.
409N/A */
0N/A return super.vmNotSuspended(action);
0N/A }
0N/A
0N/A /**
650N/A * Note that we only cache the name string while the entire VM is suspended
650N/A * because the name can change via Thread.setName arbitrarily while this
650N/A * thread is running.
0N/A */
0N/A public String name() {
0N/A String name = null;
0N/A try {
0N/A Cache local = (Cache)getCache();
0N/A
0N/A if (local != null) {
0N/A name = local.name;
0N/A }
0N/A if (name == null) {
0N/A name = JDWP.ThreadReference.Name.process(vm, this)
0N/A .threadName;
0N/A if (local != null) {
0N/A local.name = name;
0N/A }
0N/A }
0N/A } catch (JDWPException exc) {
0N/A throw exc.toJDIException();
0N/A }
0N/A return name;
0N/A }
0N/A
0N/A /*
0N/A * Sends a command to the back end which is defined to do an
0N/A * implicit vm-wide resume.
0N/A */
0N/A PacketStream sendResumingCommand(CommandSender sender) {
0N/A synchronized (vm.state()) {
0N/A processThreadAction(new ThreadAction(this,
0N/A ThreadAction.THREAD_RESUMABLE));
0N/A return sender.send();
0N/A }
0N/A }
0N/A
0N/A public void suspend() {
0N/A try {
0N/A JDWP.ThreadReference.Suspend.process(vm, this);
0N/A } catch (JDWPException exc) {
0N/A throw exc.toJDIException();
0N/A }
0N/A // Don't consider the thread suspended yet. On reply, notifySuspend()
0N/A // will be called.
0N/A }
0N/A
0N/A public void resume() {
0N/A /*
0N/A * If it's a zombie, we can just update internal state without
0N/A * going to back end.
0N/A */
0N/A if (suspendedZombieCount > 0) {
0N/A suspendedZombieCount--;
0N/A return;
0N/A }
0N/A
0N/A PacketStream stream;
0N/A synchronized (vm.state()) {
0N/A processThreadAction(new ThreadAction(this,
0N/A ThreadAction.THREAD_RESUMABLE));
0N/A stream = JDWP.ThreadReference.Resume.enqueueCommand(vm, this);
0N/A }
0N/A try {
0N/A JDWP.ThreadReference.Resume.waitForReply(vm, stream);
0N/A } catch (JDWPException exc) {
0N/A throw exc.toJDIException();
0N/A }
0N/A }
0N/A
0N/A public int suspendCount() {
0N/A /*
0N/A * If it's a zombie, we maintain the count in the front end.
0N/A */
0N/A if (suspendedZombieCount > 0) {
0N/A return suspendedZombieCount;
0N/A }
0N/A
0N/A try {
0N/A return JDWP.ThreadReference.SuspendCount.process(vm, this).suspendCount;
0N/A } catch (JDWPException exc) {
0N/A throw exc.toJDIException();
0N/A }
0N/A }
0N/A
0N/A public void stop(ObjectReference throwable) throws InvalidTypeException {
0N/A validateMirror(throwable);
0N/A // Verify that the given object is a Throwable instance
0N/A List list = vm.classesByName("java.lang.Throwable");
0N/A ClassTypeImpl throwableClass = (ClassTypeImpl)list.get(0);
0N/A if ((throwable == null) ||
0N/A !throwableClass.isAssignableFrom(throwable)) {
0N/A throw new InvalidTypeException("Not an instance of Throwable");
0N/A }
0N/A
0N/A try {
0N/A JDWP.ThreadReference.Stop.process(vm, this,
0N/A (ObjectReferenceImpl)throwable);
0N/A } catch (JDWPException exc) {
0N/A throw exc.toJDIException();
0N/A }
0N/A }
0N/A
0N/A public void interrupt() {
0N/A try {
0N/A JDWP.ThreadReference.Interrupt.process(vm, this);
0N/A } catch (JDWPException exc) {
0N/A throw exc.toJDIException();
0N/A }
0N/A }
0N/A
0N/A private JDWP.ThreadReference.Status jdwpStatus() {
650N/A LocalCache snapshot = localCache;
650N/A JDWP.ThreadReference.Status myStatus = snapshot.status;
0N/A try {
409N/A if (myStatus == null) {
409N/A myStatus = JDWP.ThreadReference.Status.process(vm, this);
409N/A if ((myStatus.suspendStatus & SUSPEND_STATUS_SUSPENDED) != 0) {
409N/A // thread is suspended, we can cache the status.
650N/A snapshot.status = myStatus;
0N/A }
0N/A }
409N/A } catch (JDWPException exc) {
0N/A throw exc.toJDIException();
0N/A }
650N/A return myStatus;
0N/A }
0N/A
0N/A public int status() {
0N/A return jdwpStatus().threadStatus;
0N/A }
0N/A
0N/A public boolean isSuspended() {
0N/A return ((suspendedZombieCount > 0) ||
0N/A ((jdwpStatus().suspendStatus & SUSPEND_STATUS_SUSPENDED) != 0));
0N/A }
0N/A
0N/A public boolean isAtBreakpoint() {
0N/A /*
0N/A * TO DO: This fails to take filters into account.
0N/A */
0N/A try {
0N/A StackFrame frame = frame(0);
0N/A Location location = frame.location();
0N/A List requests = vm.eventRequestManager().breakpointRequests();
0N/A Iterator iter = requests.iterator();
0N/A while (iter.hasNext()) {
0N/A BreakpointRequest request = (BreakpointRequest)iter.next();
0N/A if (location.equals(request.location())) {
0N/A return true;
0N/A }
0N/A }
0N/A return false;
0N/A } catch (IndexOutOfBoundsException iobe) {
0N/A return false; // no frames on stack => not at breakpoint
0N/A } catch (IncompatibleThreadStateException itse) {
0N/A // Per the javadoc, not suspended => return false
0N/A return false;
0N/A }
0N/A }
0N/A
0N/A public ThreadGroupReference threadGroup() {
0N/A /*
409N/A * Thread group can't change, so it's cached once and for all.
0N/A */
0N/A if (threadGroup == null) {
0N/A try {
0N/A threadGroup = JDWP.ThreadReference.ThreadGroup.
0N/A process(vm, this).group;
0N/A } catch (JDWPException exc) {
0N/A throw exc.toJDIException();
0N/A }
0N/A }
0N/A return threadGroup;
0N/A }
0N/A
0N/A public int frameCount() throws IncompatibleThreadStateException {
650N/A LocalCache snapshot = localCache;
0N/A try {
650N/A if (snapshot.frameCount == -1) {
650N/A snapshot.frameCount = JDWP.ThreadReference.FrameCount
0N/A .process(vm, this).frameCount;
0N/A }
0N/A } catch (JDWPException exc) {
0N/A switch (exc.errorCode()) {
0N/A case JDWP.Error.THREAD_NOT_SUSPENDED:
0N/A case JDWP.Error.INVALID_THREAD: /* zombie */
0N/A throw new IncompatibleThreadStateException();
0N/A default:
0N/A throw exc.toJDIException();
0N/A }
0N/A }
650N/A return snapshot.frameCount;
0N/A }
0N/A
0N/A public List<StackFrame> frames() throws IncompatibleThreadStateException {
0N/A return privateFrames(0, -1);
0N/A }
0N/A
0N/A public StackFrame frame(int index) throws IncompatibleThreadStateException {
0N/A List list = privateFrames(index, 1);
0N/A return (StackFrame)list.get(0);
0N/A }
0N/A
0N/A /**
0N/A * Is the requested subrange within what has been retrieved?
409N/A * local is known to be non-null. Should only be called from
409N/A * a sync method.
0N/A */
650N/A private boolean isSubrange(LocalCache snapshot,
409N/A int start, int length) {
650N/A if (start < snapshot.framesStart) {
0N/A return false;
0N/A }
0N/A if (length == -1) {
650N/A return (snapshot.framesLength == -1);
0N/A }
650N/A if (snapshot.framesLength == -1) {
650N/A if ((start + length) > (snapshot.framesStart +
650N/A snapshot.frames.size())) {
0N/A throw new IndexOutOfBoundsException();
0N/A }
0N/A return true;
0N/A }
650N/A return ((start + length) <= (snapshot.framesStart + snapshot.framesLength));
0N/A }
0N/A
0N/A public List<StackFrame> frames(int start, int length)
0N/A throws IncompatibleThreadStateException {
0N/A if (length < 0) {
0N/A throw new IndexOutOfBoundsException(
0N/A "length must be greater than or equal to zero");
0N/A }
0N/A return privateFrames(start, length);
0N/A }
0N/A
0N/A /**
0N/A * Private version of frames() allows "-1" to specify all
0N/A * remaining frames.
0N/A */
409N/A synchronized private List<StackFrame> privateFrames(int start, int length)
0N/A throws IncompatibleThreadStateException {
409N/A
409N/A // Lock must be held while creating stack frames so if that two threads
409N/A // do this at the same time, one won't clobber the subset created by the other.
650N/A LocalCache snapshot = localCache;
0N/A try {
650N/A if (snapshot.frames == null || !isSubrange(snapshot, start, length)) {
0N/A JDWP.ThreadReference.Frames.Frame[] jdwpFrames
0N/A = JDWP.ThreadReference.Frames.
409N/A process(vm, this, start, length).frames;
0N/A int count = jdwpFrames.length;
650N/A snapshot.frames = new ArrayList<StackFrame>(count);
0N/A
409N/A for (int i = 0; i<count; i++) {
409N/A if (jdwpFrames[i].location == null) {
409N/A throw new InternalException("Invalid frame location");
0N/A }
409N/A StackFrame frame = new StackFrameImpl(vm, this,
409N/A jdwpFrames[i].frameID,
409N/A jdwpFrames[i].location);
409N/A // Add to the frame list
650N/A snapshot.frames.add(frame);
0N/A }
650N/A snapshot.framesStart = start;
650N/A snapshot.framesLength = length;
650N/A return Collections.unmodifiableList(snapshot.frames);
0N/A } else {
650N/A int fromIndex = start - snapshot.framesStart;
0N/A int toIndex;
0N/A if (length == -1) {
650N/A toIndex = snapshot.frames.size() - fromIndex;
0N/A } else {
0N/A toIndex = fromIndex + length;
0N/A }
650N/A return Collections.unmodifiableList(snapshot.frames.subList(fromIndex, toIndex));
0N/A }
0N/A } catch (JDWPException exc) {
0N/A switch (exc.errorCode()) {
0N/A case JDWP.Error.THREAD_NOT_SUSPENDED:
0N/A case JDWP.Error.INVALID_THREAD: /* zombie */
0N/A throw new IncompatibleThreadStateException();
0N/A default:
0N/A throw exc.toJDIException();
0N/A }
0N/A }
0N/A }
0N/A
0N/A public List<ObjectReference> ownedMonitors() throws IncompatibleThreadStateException {
650N/A LocalCache snapshot = localCache;
0N/A try {
650N/A if (snapshot.ownedMonitors == null) {
650N/A snapshot.ownedMonitors = Arrays.asList(
0N/A (ObjectReference[])JDWP.ThreadReference.OwnedMonitors.
0N/A process(vm, this).owned);
409N/A if ((vm.traceFlags & vm.TRACE_OBJREFS) != 0) {
409N/A vm.printTrace(description() +
409N/A " temporarily caching owned monitors"+
650N/A " (count = " + snapshot.ownedMonitors.size() + ")");
0N/A }
0N/A }
0N/A } catch (JDWPException exc) {
0N/A switch (exc.errorCode()) {
0N/A case JDWP.Error.THREAD_NOT_SUSPENDED:
0N/A case JDWP.Error.INVALID_THREAD: /* zombie */
0N/A throw new IncompatibleThreadStateException();
0N/A default:
0N/A throw exc.toJDIException();
0N/A }
0N/A }
650N/A return snapshot.ownedMonitors;
0N/A }
0N/A
0N/A public ObjectReference currentContendedMonitor()
0N/A throws IncompatibleThreadStateException {
650N/A LocalCache snapshot = localCache;
0N/A try {
650N/A if (snapshot.contendedMonitor == null &&
650N/A !snapshot.triedCurrentContended) {
650N/A snapshot.contendedMonitor = JDWP.ThreadReference.CurrentContendedMonitor.
0N/A process(vm, this).monitor;
650N/A snapshot.triedCurrentContended = true;
650N/A if ((snapshot.contendedMonitor != null) &&
409N/A ((vm.traceFlags & vm.TRACE_OBJREFS) != 0)) {
409N/A vm.printTrace(description() +
409N/A " temporarily caching contended monitor"+
650N/A " (id = " + snapshot.contendedMonitor.uniqueID() + ")");
0N/A }
0N/A }
0N/A } catch (JDWPException exc) {
0N/A switch (exc.errorCode()) {
650N/A case JDWP.Error.THREAD_NOT_SUSPENDED:
0N/A case JDWP.Error.INVALID_THREAD: /* zombie */
0N/A throw new IncompatibleThreadStateException();
0N/A default:
0N/A throw exc.toJDIException();
0N/A }
0N/A }
650N/A return snapshot.contendedMonitor;
0N/A }
0N/A
0N/A public List<MonitorInfo> ownedMonitorsAndFrames() throws IncompatibleThreadStateException {
650N/A LocalCache snapshot = localCache;
0N/A try {
650N/A if (snapshot.ownedMonitorsInfo == null) {
0N/A JDWP.ThreadReference.OwnedMonitorsStackDepthInfo.monitor[] minfo;
0N/A minfo = JDWP.ThreadReference.OwnedMonitorsStackDepthInfo.process(vm, this).owned;
0N/A
650N/A snapshot.ownedMonitorsInfo = new ArrayList<MonitorInfo>(minfo.length);
0N/A
0N/A for (int i=0; i < minfo.length; i++) {
0N/A JDWP.ThreadReference.OwnedMonitorsStackDepthInfo.monitor mi =
0N/A minfo[i];
0N/A MonitorInfo mon = new MonitorInfoImpl(vm, minfo[i].monitor, this, minfo[i].stack_depth);
650N/A snapshot.ownedMonitorsInfo.add(mon);
0N/A }
0N/A
409N/A if ((vm.traceFlags & vm.TRACE_OBJREFS) != 0) {
409N/A vm.printTrace(description() +
409N/A " temporarily caching owned monitors"+
650N/A " (count = " + snapshot.ownedMonitorsInfo.size() + ")");
0N/A }
0N/A }
0N/A
0N/A } catch (JDWPException exc) {
0N/A switch (exc.errorCode()) {
0N/A case JDWP.Error.THREAD_NOT_SUSPENDED:
0N/A case JDWP.Error.INVALID_THREAD: /* zombie */
0N/A throw new IncompatibleThreadStateException();
0N/A default:
0N/A throw exc.toJDIException();
0N/A }
0N/A }
650N/A return snapshot.ownedMonitorsInfo;
0N/A }
0N/A
0N/A public void popFrames(StackFrame frame) throws IncompatibleThreadStateException {
0N/A // Note that interface-wise this functionality belongs
0N/A // here in ThreadReference, but implementation-wise it
0N/A // belongs in StackFrame, so we just forward it.
0N/A if (!frame.thread().equals(this)) {
0N/A throw new IllegalArgumentException("frame does not belong to this thread");
0N/A }
0N/A if (!vm.canPopFrames()) {
0N/A throw new UnsupportedOperationException(
0N/A "target does not support popping frames");
0N/A }
0N/A ((StackFrameImpl)frame).pop();
0N/A }
0N/A
0N/A public void forceEarlyReturn(Value returnValue) throws InvalidTypeException,
409N/A ClassNotLoadedException,
0N/A IncompatibleThreadStateException {
0N/A if (!vm.canForceEarlyReturn()) {
0N/A throw new UnsupportedOperationException(
0N/A "target does not support the forcing of a method to return early");
0N/A }
0N/A
0N/A validateMirrorOrNull(returnValue);
0N/A
0N/A StackFrameImpl sf;
0N/A try {
0N/A sf = (StackFrameImpl)frame(0);
0N/A } catch (IndexOutOfBoundsException exc) {
0N/A throw new InvalidStackFrameException("No more frames on the stack");
0N/A }
0N/A sf.validateStackFrame();
0N/A MethodImpl meth = (MethodImpl)sf.location().method();
0N/A ValueImpl convertedValue = ValueImpl.prepareForAssignment(returnValue,
0N/A meth.getReturnValueContainer());
0N/A
0N/A try {
0N/A JDWP.ThreadReference.ForceEarlyReturn.process(vm, this, convertedValue);
0N/A } catch (JDWPException exc) {
0N/A switch (exc.errorCode()) {
0N/A case JDWP.Error.OPAQUE_FRAME:
0N/A throw new NativeMethodException();
0N/A case JDWP.Error.THREAD_NOT_SUSPENDED:
0N/A throw new IncompatibleThreadStateException(
0N/A "Thread not suspended");
0N/A case JDWP.Error.THREAD_NOT_ALIVE:
0N/A throw new IncompatibleThreadStateException(
0N/A "Thread has not started or has finished");
0N/A case JDWP.Error.NO_MORE_FRAMES:
0N/A throw new InvalidStackFrameException(
0N/A "No more frames on the stack");
0N/A default:
0N/A throw exc.toJDIException();
0N/A }
0N/A }
0N/A }
0N/A
0N/A public String toString() {
0N/A return "instance of " + referenceType().name() +
0N/A "(name='" + name() + "', " + "id=" + uniqueID() + ")";
0N/A }
0N/A
0N/A byte typeValueKey() {
0N/A return JDWP.Tag.THREAD;
0N/A }
0N/A
0N/A void addListener(ThreadListener listener) {
0N/A synchronized (vm.state()) {
0N/A listeners.add(new WeakReference<ThreadListener>(listener));
0N/A }
0N/A }
0N/A
0N/A void removeListener(ThreadListener listener) {
0N/A synchronized (vm.state()) {
0N/A Iterator iter = listeners.iterator();
0N/A while (iter.hasNext()) {
0N/A WeakReference ref = (WeakReference)iter.next();
0N/A if (listener.equals(ref.get())) {
0N/A iter.remove();
0N/A break;
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Propagate the the thread state change information
0N/A * to registered listeners.
0N/A * Must be entered while synchronized on vm.state()
0N/A */
0N/A private void processThreadAction(ThreadAction action) {
0N/A synchronized (vm.state()) {
0N/A Iterator iter = listeners.iterator();
0N/A while (iter.hasNext()) {
0N/A WeakReference ref = (WeakReference)iter.next();
0N/A ThreadListener listener = (ThreadListener)ref.get();
0N/A if (listener != null) {
0N/A switch (action.id()) {
0N/A case ThreadAction.THREAD_RESUMABLE:
0N/A if (!listener.threadResumable(action)) {
0N/A iter.remove();
0N/A }
0N/A break;
0N/A }
0N/A } else {
0N/A // Listener is unreachable; clean up
0N/A iter.remove();
0N/A }
0N/A }
409N/A
409N/A // Discard our local cache
409N/A resetLocalCache();
0N/A }
0N/A }
0N/A}