OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libjava/] [classpath/] [gnu/] [classpath/] [jdwp/] [processor/] [ThreadReferenceCommandSet.java] - Blame information for rev 14

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 jlechner
/* ThreadReferenceCommandSet.java -- class to implement the ThreadReference
2
   Command Set Copyright (C) 2005 Free Software Foundation
3
 
4
This file is part of GNU Classpath.
5
 
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.
10
 
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.
15
 
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.
20
 
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.
25
 
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. */
38
 
39
 
40
package gnu.classpath.jdwp.processor;
41
 
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;
53
 
54
import java.io.DataOutputStream;
55
import java.io.IOException;
56
import java.nio.ByteBuffer;
57
import java.util.ArrayList;
58
 
59
/**
60
 * A class representing the ThreadReference Command Set.
61
 *
62
 * @author Aaron Luchko <aluchko@redhat.com>
63
 */
64
public class ThreadReferenceCommandSet
65
  extends CommandSet
66
{
67
  public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command)
68
      throws JdwpException
69
  {
70
    try
71
      {
72
        switch (command)
73
          {
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.");
113
          }
114
      }
115
    catch (IOException ex)
116
      {
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);
120
      }
121
 
122
    return false;
123
  }
124
 
125
  private void executeName(ByteBuffer bb, DataOutputStream os)
126
      throws JdwpException, IOException
127
  {
128
    ThreadId tid = (ThreadId) idMan.readObjectId(bb);
129
    Thread thread = tid.getThread();
130
    JdwpString.writeString(os, thread.getName());
131
  }
132
 
133
  private void executeSuspend(ByteBuffer bb, DataOutputStream os)
134
      throws JdwpException, IOException
135
  {
136
    ThreadId tid = (ThreadId) idMan.readObjectId(bb);
137
    Thread thread = tid.getThread();
138
    VMVirtualMachine.suspendThread(thread);
139
  }
140
 
141
  private void executeResume(ByteBuffer bb, DataOutputStream os)
142
      throws JdwpException, IOException
143
  {
144
    ThreadId tid = (ThreadId) idMan.readObjectId(bb);
145
    Thread thread = tid.getThread();
146
    VMVirtualMachine.suspendThread(thread);
147
  }
148
 
149
  private void executeStatus(ByteBuffer bb, DataOutputStream os)
150
      throws JdwpException, IOException
151
  {
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;
157
 
158
    os.writeInt(threadStatus);
159
    os.writeInt(suspendStatus);
160
  }
161
 
162
  private void executeThreadGroup(ByteBuffer bb, DataOutputStream os)
163
      throws JdwpException, IOException
164
  {
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);
170
  }
171
 
172
  private void executeFrames(ByteBuffer bb, DataOutputStream os)
173
      throws JdwpException, IOException
174
  {
175
    ThreadId tid = (ThreadId) idMan.readObjectId(bb);
176
    Thread thread = tid.getThread();
177
    int startFrame = bb.getInt();
178
    int length = bb.getInt();
179
 
180
    ArrayList frames = VMVirtualMachine.getFrames(thread, startFrame, length);
181
    os.writeInt(frames.size());
182
    for (int i = 0; i < frames.size(); i++)
183
      {
184
        VMFrame frame = (VMFrame) frames.get(i);
185
        os.writeLong(frame.getId());
186
        Location loc = frame.getLocation();
187
        loc.write(os);
188
      }
189
  }
190
 
191
  private void executeFrameCount(ByteBuffer bb, DataOutputStream os)
192
      throws JdwpException, IOException
193
  {
194
    ThreadId tid = (ThreadId) idMan.readObjectId(bb);
195
    Thread thread = tid.getThread();
196
 
197
    int frameCount = VMVirtualMachine.getFrameCount(thread);
198
    os.writeInt(frameCount);
199
  }
200
 
201
  private void executeOwnedMonitors(ByteBuffer bb, DataOutputStream os)
202
      throws JdwpException
203
  {
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.");
208
  }
209
 
210
  private void executeCurrentContendedMonitor(ByteBuffer bb,
211
                                              DataOutputStream os)
212
      throws JdwpException
213
  {
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.");
218
  }
219
 
220
  private void executeStop(ByteBuffer bb, DataOutputStream os)
221
      throws JdwpException, IOException
222
  {
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);
228
  }
229
 
230
  private void executeInterrupt(ByteBuffer bb, DataOutputStream os)
231
      throws JdwpException, IOException
232
  {
233
    ThreadId tid = (ThreadId) idMan.readObjectId(bb);
234
    Thread thread = tid.getThread();
235
    thread.interrupt();
236
  }
237
 
238
  private void executeSuspendCount(ByteBuffer bb, DataOutputStream os)
239
      throws JdwpException, IOException
240
  {
241
    ThreadId tid = (ThreadId) idMan.readObjectId(bb);
242
    Thread thread = tid.getThread();
243
    int suspendCount = VMVirtualMachine.getSuspendCount(thread);
244
    os.writeInt(suspendCount);
245
  }
246
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.