Imported GNU Classpath 0.90
[official-gcc.git] / libjava / gnu / classpath / jdwp / VMVirtualMachine.java
blobac81d956994c20610895e542ecfb902f01d56363
1 /* VMVirtualMachine.java -- A reference implementation of a JDWP virtual
2 machine
4 Copyright (C) 2005, 2006 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.InvalidMethodException;
46 import gnu.classpath.jdwp.exception.JdwpException;
47 import gnu.classpath.jdwp.util.MethodResult;
48 import java.lang.reflect.Method;
49 import java.nio.ByteBuffer;
50 import java.util.ArrayList;
51 import java.util.Iterator;
53 /**
54 * A virtual machine according to JDWP.
56 * @author Keith Seitz <keiths@redhat.com>
58 public class VMVirtualMachine
60 /**
61 * Suspend a thread
63 * @param thread the thread to suspend
65 public static void suspendThread (Thread thread) { }
67 /**
68 * Suspend all threads
70 public static void suspendAllThreads ()
71 throws JdwpException
73 // Our JDWP thread group -- don't suspend any of those threads
74 Thread current = Thread.currentThread ();
75 ThreadGroup jdwpGroup = Jdwp.getDefault().getJdwpThreadGroup();
77 // Find the root ThreadGroup
78 ThreadGroup group = jdwpGroup;
79 ThreadGroup parent = group.getParent ();
80 while (parent != null)
82 group = parent;
83 parent = group.getParent ();
86 // Get all the threads in the system
87 int num = group.activeCount ();
88 Thread[] threads = new Thread[num];
89 group.enumerate (threads);
91 for (int i = 0; i < num; ++i)
93 Thread t = threads[i];
94 if (t != null)
96 if (t.getThreadGroup () == jdwpGroup || t == current)
98 // Don't suspend the current thread or any JDWP thread
99 continue;
101 else
102 suspendThread (t);
106 // Now suspend the current thread
107 if (current.getThreadGroup() != jdwpGroup)
108 suspendThread (current);
112 * Resume a thread. A thread must be resumed as many times
113 * as it has been suspended.
115 * @param thread the thread to resume
117 public static void resumeThread (Thread thread) { }
120 * Resume all threads. This simply decrements the thread's
121 * suspend count. It can not be used to force the application
122 * to run.
124 public static void resumeAllThreads ()
125 throws JdwpException
127 // Our JDWP thread group -- don't resume
128 Thread current = Thread.currentThread ();
129 ThreadGroup jdwpGroup = current.getThreadGroup ();
131 // Find the root ThreadGroup
132 ThreadGroup group = jdwpGroup;
133 ThreadGroup parent = group.getParent ();
134 while (parent != null)
136 group = parent;
137 parent = group.getParent ();
140 // Get all the threads in the system
141 int num = group.activeCount ();
142 Thread[] threads = new Thread[num];
143 group.enumerate (threads);
145 for (int i = 0; i < num; ++i)
147 Thread t = threads[i];
148 if (t != null)
150 if (t.getThreadGroup () == jdwpGroup || t == current)
152 // Don't resume the current thread or any JDWP thread
153 continue;
155 else
156 resumeThread (t);
162 * Get the suspend count for a give thread
164 * @param thread the thread whose suspend count is desired
165 * @return the number of times the thread has been suspended
167 public static int getSuspendCount (Thread thread) { return -1; }
170 * Returns a count of the number of loaded classes in the VM
172 public static int getAllLoadedClassesCount () { return -1; }
175 * Returns an iterator over all the loaded classes in the VM
177 public static Iterator getAllLoadedClasses () { return null; }
180 * Returns the status of the given class
182 * @param clazz the class whose status is desired
183 * @return a flag containing the class's status
184 * @see JdwpConstants.ClassStatus
186 public static int getClassStatus (Class clazz) { return -1; }
189 * Returns all of the methods defined in the given class. This
190 * includes all methods, constructors, and class initializers.
192 * @param klass the class whose methods are desired
193 * @return an array of virtual machine methods
195 public static VMMethod[] getAllClassMethods (Class klass)
196 { return null; }
199 * A factory method for getting valid virtual machine methods
200 * which may be passed to/from the debugger.
202 * @param klass the class in which the method is defined
203 * @param id the ID of the desired method
204 * @return the desired internal representation of the method
205 * @throws InvalidMethodException if the method is not defined
206 * in the class
207 * @throws JdwpException for any other error
209 public static VMMethod getClassMethod(Class klass, long id)
210 { return null; }
213 * Returns the thread's call stack
215 * @param thread thread for which to get call stack
216 * @param start index of first frame to return
217 * @param length number of frames to return (-1 for all frames)
218 * @return a list of frames
220 public static ArrayList getFrames (Thread thread, int strart,
221 int length)
222 { return null; }
225 * Returns the frame for a given thread with the frame ID in
226 * the buffer
228 * I don't like this.
230 * @param thread the frame's thread
231 * @param bb buffer containing the frame's ID
232 * @return the desired frame
234 public static VMFrame getFrame (Thread thread, ByteBuffer bb)
235 { return null; }
238 * Returns the number of frames in the thread's stack
240 * @param thread the thread for which to get a frame count
241 * @return the number of frames in the thread's stack
243 public static int getFrameCount (Thread thread)
244 { return -1; }
248 * Returns the status of a thread
250 * @param thread the thread for which to get status
251 * @return integer status of the thread
252 * @see JdwpConstants.ThreadStatus
254 public static int getThreadStatus (Thread thread)
255 { return -1; }
258 * Returns a list of all classes which this class loader has been
259 * requested to load
261 * @param cl the class loader
262 * @return a list of all visible classes
264 public static ArrayList getLoadRequests (ClassLoader cl)
265 { return null; }
268 * Executes a method in the virtual machine
270 * @param obj instance in which to invoke method (null for static)
271 * @param thread the thread in which to invoke the method
272 * @param clazz the class in which the method is defined
273 * @param method the method to invoke
274 * @param values arguments to pass to method
275 * @param nonVirtual "otherwise, normal virtual invoke
276 * (instance methods only) "
277 * @return a result object containing the results of the invocation
279 public static MethodResult executeMethod (Object obj, Thread thread,
280 Class clazz, Method method,
281 Object[] values,
282 boolean nonVirtual)
283 { return null; }
286 * "Returns the name of source file in which a reference type was declared"
288 * @param clazz the class for which to return a source file
289 * @return a string containing the source file name; "no path information
290 * for the file is included"
292 public static String getSourceFile (Class clazz)
293 { return null; }
296 * Register a request from the debugger
298 * Virtual machines have two options. Either do nothing and allow
299 * the event manager to take care of the request (useful for broadcast-type
300 * events like class prepare/load/unload, thread start/end, etc.)
301 * or do some internal work to set up the event notification (useful for
302 * execution-related events like breakpoints, single-stepping, etc.).
304 public static void registerEvent (EventRequest request)
308 * Unregisters the given request
310 * @param request the request to unregister
312 public static void unregisterEvent (EventRequest request)
317 * Clear all events of the given kind
319 * @param kind the type of events to clear
321 public static void clearEvents (byte kind) { }