Merge from mainline
[official-gcc.git] / libjava / classpath / vm / reference / gnu / classpath / jdwp / VMVirtualMachine.java
blobaa285cb58a68f8114f2c8abddfe65fabafcba70c
1 /* VMVirtualMachine.java -- A reference implementation of a JDWP virtual
2 machine
4 Copyright (C) 2005 Free Software Foundation
6 This file is part of GNU Classpath.
8 GNU Classpath is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
13 GNU Classpath is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Classpath; see the file COPYING. If not, write to the
20 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 02110-1301 USA.
23 Linking this library statically or dynamically with other modules is
24 making a combined work based on this library. Thus, the terms and
25 conditions of the GNU General Public License cover the whole
26 combination.
28 As a special exception, the copyright holders of this library give you
29 permission to link this library with independent modules to produce an
30 executable, regardless of the license terms of these independent
31 modules, and to copy and distribute the resulting executable under
32 terms of your choice, provided that you also meet, for each linked
33 terms of your choice, provided that you also meet, for each linked
34 independent module, the terms and conditions of the license of that
35 module. An independent module is a module which is not derived from
36 or based on this library. If you modify this library, you may extend
37 this exception to your version of the library, but you are not
38 obligated to do so. If you do not wish to do so, delete this
39 exception statement from your version. */
42 package gnu.classpath.jdwp;
44 import gnu.classpath.jdwp.event.EventRequest;
45 import gnu.classpath.jdwp.exception.JdwpException;
46 import gnu.classpath.jdwp.exception.InvalidClassException;
47 import gnu.classpath.jdwp.exception.InvalidObjectException;
48 import gnu.classpath.jdwp.id.ObjectId;
49 import gnu.classpath.jdwp.id.ReferenceTypeId;
50 import gnu.classpath.jdwp.util.LineTable;
51 import gnu.classpath.jdwp.util.MethodResult;
52 import gnu.classpath.jdwp.util.VariableTable;
54 import java.io.IOException;
55 import java.lang.reflect.Method;
56 import java.nio.ByteBuffer;
57 import java.util.ArrayList;
58 import java.util.Iterator;
60 /**
61 * A virtual machine according to JDWP.
63 * @author Keith Seitz <keiths@redhat.com>
65 public class VMVirtualMachine
67 /**
68 * Suspend a thread
70 * @param thread the thread to suspend
72 public static native void suspendThread (Thread thread)
73 throws JdwpException;
75 /**
76 * Suspend all threads
78 public static void suspendAllThreads ()
79 throws JdwpException
81 // Our JDWP thread group -- don't suspend any of those threads
82 Thread current = Thread.currentThread ();
83 ThreadGroup jdwpGroup = current.getThreadGroup ();
85 // Find the root ThreadGroup
86 ThreadGroup group = jdwpGroup;
87 ThreadGroup parent = group.getParent ();
88 while (parent != null)
90 group = parent;
91 parent = group.getParent ();
94 // Get all the threads in the system
95 int num = group.activeCount ();
96 Thread[] threads = new Thread[num];
97 group.enumerate (threads);
99 for (int i = 0; i < num; ++i)
101 Thread t = threads[i];
102 if (t != null)
104 if (t.getThreadGroup () == jdwpGroup || t == current)
106 // Don't suspend the current thread or any JDWP thread
107 continue;
109 else
110 suspendThread (t);
114 // Now suspend the current thread
115 suspendThread (current);
119 * Resume a thread. A thread must be resumed as many times
120 * as it has been suspended.
122 * @param thread the thread to resume
124 public static native void resumeThread (Thread thread)
125 throws JdwpException;
128 * Resume all threads. This simply decrements the thread's
129 * suspend count. It can not be used to force the application
130 * to run.
132 public static void resumeAllThreads ()
133 throws JdwpException
135 // Our JDWP thread group -- don't resume
136 Thread current = Thread.currentThread ();
137 ThreadGroup jdwpGroup = current.getThreadGroup ();
139 // Find the root ThreadGroup
140 ThreadGroup group = jdwpGroup;
141 ThreadGroup parent = group.getParent ();
142 while (parent != null)
144 group = parent;
145 parent = group.getParent ();
148 // Get all the threads in the system
149 int num = group.activeCount ();
150 Thread[] threads = new Thread[num];
151 group.enumerate (threads);
153 for (int i = 0; i < num; ++i)
155 Thread t = threads[i];
156 if (t != null)
158 if (t.getThreadGroup () == jdwpGroup || t == current)
160 // Don't resume the current thread or any JDWP thread
161 continue;
163 else
164 resumeThread (t);
170 * Get the suspend count for a give thread
172 * @param thread the thread whose suspend count is desired
173 * @return the number of times the thread has been suspended
175 public static native int getSuspendCount (Thread thread)
176 throws JdwpException;
179 * Returns a count of the number of loaded classes in the VM
181 public static native int getAllLoadedClassesCount ()
182 throws JdwpException;
185 * Returns an iterator over all the loaded classes in the VM
187 public static native Iterator getAllLoadedClasses ()
188 throws JdwpException;
191 * Returns the status of the given class
193 * @param clazz the class whose status is desired
194 * @return a flag containing the class's status
195 * @see JdwpConstants.ClassStatus
197 public static native int getClassStatus (Class clazz)
198 throws JdwpException;
202 * Returns the thread's call stack
204 * @param thread thread for which to get call stack
205 * @param start index of first frame to return
206 * @param length number of frames to return (-1 for all frames)
207 * @return a list of frames
209 public static native ArrayList getFrames (Thread thread, int strart,
210 int length)
211 throws JdwpException;
214 * Returns the frame for a given thread with the frame ID in
215 * the buffer
217 * I don't like this.
219 * @param thread the frame's thread
220 * @param bb buffer containing the frame's ID
221 * @return the desired frame
223 public static native VMFrame getFrame (Thread thread, ByteBuffer bb)
224 throws JdwpException;
227 * Returns the number of frames in the thread's stack
229 * @param thread the thread for which to get a frame count
230 * @return the number of frames in the thread's stack
232 public static native int getFrameCount (Thread thread)
233 throws JdwpException;
237 * Returns the status of a thread
239 * @param thread the thread for which to get status
240 * @return integer status of the thread
241 * @see JdwpConstants.ThreadStatus
243 public static native int getThreadStatus (Thread thread)
244 throws JdwpException;
247 * Returns a list of all classes which this class loader has been
248 * requested to load
250 * @param cl the class loader
251 * @return a list of all visible classes
253 public static native ArrayList getLoadRequests (ClassLoader cl)
254 throws JdwpException;
257 * Executes a method in the virtual machine
259 * @param obj instance in which to invoke method (null for static)
260 * @param thread the thread in which to invoke the method
261 * @param clazz the class in which the method is defined
262 * @param method the method to invoke
263 * @param values arguments to pass to method
264 * @param nonVirtual "otherwise, normal virtual invoke
265 * (instance methods only) "
266 * @return a result object containing the results of the invocation
268 public static native MethodResult executeMethod (Object obj, Thread thread,
269 Class clazz, Method method,
270 Object[] values,
271 boolean nonVirtual)
272 throws JdwpException;
275 * "Returns variable information for the method. The variable table
276 * includes arguments and locals declared within the method. For instance
277 * methods, the "this" reference is included in the table. Also, synthetic
278 * variables may be present."
280 * @param clazz the class in which the method is defined
281 * @param method the method for which variable information is desired
282 * @return a result object containing the information
284 public static native VariableTable getVarTable (Class clazz, Method method)
285 throws JdwpException;
288 * "Returns line number information for the method, if present. The line
289 * table maps source line numbers to the initial code index of the line.
290 * The line table is ordered by code index (from lowest to highest). The
291 * line number information is constant unless a new class definition is
292 * installed using RedefineClasses."
294 * @param clazz the class in which the method is defined
295 * @param method the method whose line table is desired
296 * @return a result object containing the line table
298 public static native LineTable getLineTable (Class clazz, Method method)
299 throws JdwpException;
302 * "Returns the name of source file in which a reference type was declared"
304 * @param clazz the class for which to return a source file
305 * @return a string containing the source file name; "no path information
306 * for the file is included"
308 public static native String getSourceFile (Class clazz)
309 throws JdwpException;
312 * Register a request from the debugger
314 * Virtual machines have two options. Either do nothing and allow
315 * the event manager to take care of the request (useful for broadcast-type
316 * events like class prepare/load/unload, thread start/end, etc.)
317 * or do some internal work to set up the event notification (useful for
318 * execution-related events like breakpoints, single-stepping, etc.).
320 public static native void registerEvent (EventRequest request)
321 throws JdwpException;
324 * Unregisters the given request
326 * @param request the request to unregister
328 public static native void unregisterEvent (EventRequest request)
329 throws JdwpException;
333 * Clear all events of the given kind
335 * @param kind the type of events to clear
337 public static native void clearEvents (byte kind)
338 throws JdwpException;