Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libjava / classpath / gnu / classpath / jdwp / processor / ThreadReferenceCommandSet.java
blob559e405b65a342465fb7d906fb3354f253b315e0
1 /* ThreadReferenceCommandSet.java -- class to implement the ThreadReference
2 Command Set Copyright (C) 2005 Free Software Foundation
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 terms of your choice, provided that you also meet, for each linked
32 independent module, the terms and conditions of the license of that
33 module. An independent module is a module which is not derived from
34 or based on this library. If you modify this library, you may extend
35 this exception to your version of the library, but you are not
36 obligated to do so. If you do not wish to do so, delete this
37 exception statement from your version. */
40 package gnu.classpath.jdwp.processor;
42 import gnu.classpath.jdwp.JdwpConstants;
43 import gnu.classpath.jdwp.VMFrame;
44 import gnu.classpath.jdwp.VMVirtualMachine;
45 import gnu.classpath.jdwp.exception.InvalidObjectException;
46 import gnu.classpath.jdwp.exception.JdwpException;
47 import gnu.classpath.jdwp.exception.JdwpInternalErrorException;
48 import gnu.classpath.jdwp.exception.NotImplementedException;
49 import gnu.classpath.jdwp.id.ObjectId;
50 import gnu.classpath.jdwp.id.ThreadId;
51 import gnu.classpath.jdwp.util.JdwpString;
52 import gnu.classpath.jdwp.util.Location;
54 import java.io.DataOutputStream;
55 import java.io.IOException;
56 import java.nio.ByteBuffer;
57 import java.util.ArrayList;
59 /**
60 * A class representing the ThreadReference Command Set.
62 * @author Aaron Luchko <aluchko@redhat.com>
64 public class ThreadReferenceCommandSet
65 extends CommandSet
67 public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command)
68 throws JdwpException
70 try
72 switch (command)
74 case JdwpConstants.CommandSet.ThreadReference.NAME:
75 executeName(bb, os);
76 break;
77 case JdwpConstants.CommandSet.ThreadReference.SUSPEND:
78 executeSuspend(bb, os);
79 break;
80 case JdwpConstants.CommandSet.ThreadReference.RESUME:
81 executeResume(bb, os);
82 break;
83 case JdwpConstants.CommandSet.ThreadReference.STATUS:
84 executeStatus(bb, os);
85 break;
86 case JdwpConstants.CommandSet.ThreadReference.THREAD_GROUP:
87 executeThreadGroup(bb, os);
88 break;
89 case JdwpConstants.CommandSet.ThreadReference.FRAMES:
90 executeFrames(bb, os);
91 break;
92 case JdwpConstants.CommandSet.ThreadReference.FRAME_COUNT:
93 executeFrameCount(bb, os);
94 break;
95 case JdwpConstants.CommandSet.ThreadReference.OWNED_MONITORS:
96 executeOwnedMonitors(bb, os);
97 break;
98 case JdwpConstants.CommandSet.ThreadReference.CURRENT_CONTENDED_MONITOR:
99 executeCurrentContendedMonitor(bb, os);
100 break;
101 case JdwpConstants.CommandSet.ThreadReference.STOP:
102 executeStop(bb, os);
103 break;
104 case JdwpConstants.CommandSet.ThreadReference.INTERRUPT:
105 executeInterrupt(bb, os);
106 break;
107 case JdwpConstants.CommandSet.ThreadReference.SUSPEND_COUNT:
108 executeSuspendCount(bb, os);
109 break;
110 default:
111 throw new NotImplementedException("Command " + command +
112 " not found in Thread Reference Command Set.");
115 catch (IOException ex)
117 // The DataOutputStream we're using isn't talking to a socket at all
118 // So if we throw an IOException we're in serious trouble
119 throw new JdwpInternalErrorException(ex);
122 return false;
125 private void executeName(ByteBuffer bb, DataOutputStream os)
126 throws JdwpException, IOException
128 ThreadId tid = (ThreadId) idMan.readObjectId(bb);
129 Thread thread = tid.getThread();
130 JdwpString.writeString(os, thread.getName());
133 private void executeSuspend(ByteBuffer bb, DataOutputStream os)
134 throws JdwpException, IOException
136 ThreadId tid = (ThreadId) idMan.readObjectId(bb);
137 Thread thread = tid.getThread();
138 VMVirtualMachine.suspendThread(thread);
141 private void executeResume(ByteBuffer bb, DataOutputStream os)
142 throws JdwpException, IOException
144 ThreadId tid = (ThreadId) idMan.readObjectId(bb);
145 Thread thread = tid.getThread();
146 VMVirtualMachine.suspendThread(thread);
149 private void executeStatus(ByteBuffer bb, DataOutputStream os)
150 throws JdwpException, IOException
152 ThreadId tid = (ThreadId) idMan.readObjectId(bb);
153 Thread thread = tid.getThread();
154 int threadStatus = VMVirtualMachine.getThreadStatus(thread);
155 // There's only one possible SuspendStatus...
156 int suspendStatus = JdwpConstants.SuspendStatus.SUSPENDED;
158 os.writeInt(threadStatus);
159 os.writeInt(suspendStatus);
162 private void executeThreadGroup(ByteBuffer bb, DataOutputStream os)
163 throws JdwpException, IOException
165 ThreadId tid = (ThreadId) idMan.readObjectId(bb);
166 Thread thread = tid.getThread();
167 ThreadGroup group = thread.getThreadGroup();
168 ObjectId groupId = idMan.getObjectId(group);
169 groupId.write(os);
172 private void executeFrames(ByteBuffer bb, DataOutputStream os)
173 throws JdwpException, IOException
175 ThreadId tid = (ThreadId) idMan.readObjectId(bb);
176 Thread thread = tid.getThread();
177 int startFrame = bb.getInt();
178 int length = bb.getInt();
180 ArrayList frames = VMVirtualMachine.getFrames(thread, startFrame, length);
181 os.writeInt(frames.size());
182 for (int i = 0; i < frames.size(); i++)
184 VMFrame frame = (VMFrame) frames.get(i);
185 os.writeLong(frame.getId());
186 Location loc = frame.getLocation();
187 loc.write(os);
191 private void executeFrameCount(ByteBuffer bb, DataOutputStream os)
192 throws JdwpException, IOException
194 ThreadId tid = (ThreadId) idMan.readObjectId(bb);
195 Thread thread = tid.getThread();
197 int frameCount = VMVirtualMachine.getFrameCount(thread);
198 os.writeInt(frameCount);
201 private void executeOwnedMonitors(ByteBuffer bb, DataOutputStream os)
202 throws JdwpException
204 // This command is optional, determined by VirtualMachines CapabilitiesNew
205 // so we'll leave it till later to implement
206 throw new NotImplementedException(
207 "Command OwnedMonitors not implemented.");
210 private void executeCurrentContendedMonitor(ByteBuffer bb,
211 DataOutputStream os)
212 throws JdwpException
214 // This command is optional, determined by VirtualMachines CapabilitiesNew
215 // so we'll leave it till later to implement
216 throw new NotImplementedException(
217 "Command CurrentContentedMonitors not implemented.");
220 private void executeStop(ByteBuffer bb, DataOutputStream os)
221 throws JdwpException, IOException
223 ThreadId tid = (ThreadId) idMan.readObjectId(bb);
224 Thread thread = tid.getThread();
225 ObjectId exception = idMan.readObjectId(bb);
226 Throwable throwable = (Throwable) exception.getObject();
227 thread.stop (throwable);
230 private void executeInterrupt(ByteBuffer bb, DataOutputStream os)
231 throws JdwpException, IOException
233 ThreadId tid = (ThreadId) idMan.readObjectId(bb);
234 Thread thread = tid.getThread();
235 thread.interrupt();
238 private void executeSuspendCount(ByteBuffer bb, DataOutputStream os)
239 throws JdwpException, IOException
241 ThreadId tid = (ThreadId) idMan.readObjectId(bb);
242 Thread thread = tid.getThread();
243 int suspendCount = VMVirtualMachine.getSuspendCount(thread);
244 os.writeInt(suspendCount);