blob: 174706fe7d5315494f9932a602b2b036aa2dc00c [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 1998-2006 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26package com.sun.jdi;
27
28import java.util.List;
29
30/**
31 * A mirror of a class in the target VM. A ClassType is a refinement
32 * of {@link ReferenceType} that applies to true classes in the JLS
33 * sense of the definition (not an interface, not an array type). Any
34 * {@link ObjectReference} that mirrors an instance of such a class
35 * will have a ClassType as its type.
36 *
37 * @see ObjectReference
38 *
39 * @author Robert Field
40 * @author Gordon Hirsch
41 * @author James McIlree
42 * @since 1.3
43 */
44public interface ClassType extends ReferenceType {
45 /**
46 * Gets the superclass of this class.
47 *
48 * @return a {@link ClassType} that mirrors the superclass
49 * of this class in the target VM. If no such class exists,
50 * returns null
51 */
52 ClassType superclass();
53
54 /**
55 * Gets the interfaces directly implemented by this class.
56 * Only the interfaces that are declared with the "implements"
57 * keyword in this class are included.
58 *
59 * @return a List of {@link InterfaceType} objects each mirroring
60 * a direct interface this ClassType in the target VM.
61 * If none exist, returns a zero length List.
62 * @throws ClassNotPreparedException if this class not yet been
63 * prepared.
64 */
65 List<InterfaceType> interfaces();
66
67 /**
68 * Gets the interfaces directly and indirectly implemented
69 * by this class. Interfaces returned by {@link ClassType#interfaces}
70 * are returned as well all superinterfaces.
71 *
72 * @return a List of {@link InterfaceType} objects each mirroring
73 * an interface of this ClassType in the target VM.
74 * If none exist, returns a zero length List.
75 * @throws ClassNotPreparedException if this class not yet been
76 * prepared.
77 */
78 List<InterfaceType> allInterfaces();
79
80 /**
81 * Gets the currently loaded, direct subclasses of this class.
82 * No ordering of this list is guaranteed.
83 *
84 * @return a List of {@link ClassType} objects each mirroring a loaded
85 * subclass of this class in the target VM. If no such classes
86 * exist, this method returns a zero-length list.
87 */
88 List<ClassType> subclasses();
89
90 /**
91 * Determine if this class was declared as an enum.
92 * @return <code>true</code> if this class was declared as an enum; false
93 * otherwise.
94 */
95 boolean isEnum();
96
97 /**
98 * Assigns a value to a static field.
99 * The {@link Field} must be valid for this ClassType; that is,
100 * it must be from the mirrored object's class or a superclass of that class.
101 * The field must not be final.
102 * <p>
103 * Object values must be assignment compatible with the field type
104 * (This implies that the field type must be loaded through the
105 * enclosing class's class loader). Primitive values must be
106 * either assignment compatible with the field type or must be
107 * convertible to the field type without loss of information.
108 * See JLS section 5.2 for more information on assignment
109 * compatibility.
110 *
111 * @param field the field to set.
112 * @param value the value to be assigned.
113 * @throws java.lang.IllegalArgumentException if the field is
114 * not static, the field is final, or the field does not exist
115 * in this class.
116 * @throws ClassNotLoadedException if the field type has not yet been loaded
117 * through the appropriate class loader.
118 * @throws InvalidTypeException if the value's type does not match
119 * the field's declared type.
120 * @throws VMCannotBeModifiedException if the VirtualMachine is read-only - see {@link VirtualMachine#canBeModified()}.
121 */
122 void setValue(Field field, Value value)
123 throws InvalidTypeException, ClassNotLoadedException;
124
125 /** Perform method invocation with only the invoking thread resumed */
126 static final int INVOKE_SINGLE_THREADED = 0x1;
127
128 /**
129 * Invokes the specified static {@link Method} in the
130 * target VM. The
131 * specified method can be defined in this class,
132 * or in a superclass.
133 * The method must be a static method
134 * but not a static initializer.
135 * Use {@link ClassType#newInstance} to create a new object and
136 * run its constructor.
137 * <p>
138 * The method invocation will occur in the specified thread.
139 * Method invocation can occur only if the specified thread
140 * has been suspended by an event which occurred in that thread.
141 * Method invocation is not supported
142 * when the target VM has been suspended through
143 * {@link VirtualMachine#suspend} or when the specified thread
144 * is suspended through {@link ThreadReference#suspend}.
145 * <p>
146 * The specified method is invoked with the arguments in the specified
147 * argument list. The method invocation is synchronous; this method
148 * does not return until the invoked method returns in the target VM.
149 * If the invoked method throws an exception, this method will throw
150 * an {@link InvocationException} which contains a mirror to the exception
151 * object thrown.
152 * <p>
153 * Object arguments must be assignment compatible with the argument type
154 * (This implies that the argument type must be loaded through the
155 * enclosing class's class loader). Primitive arguments must be
156 * either assignment compatible with the argument type or must be
157 * convertible to the argument type without loss of information.
158 * If the method being called accepts a variable number of arguments,
159 * then the last argument type is an array of some component type.
160 * The argument in the matching position can be omitted, or can be null,
161 * an array of the same component type, or an argument of the
162 * component type followed by any number of other arguments of the same
163 * type. If the argument is omitted, then a 0 length array of the
164 * component type is passed. The component type can be a primitive type.
165 * Autoboxing is not supported.
166 *
167 * See the <a href="http://java.sun.com/docs/books/jls/">
168 * Java Language Specification</a>.
169 * section
170 * <a href="http://java.sun.com/docs/books/jls/second_edition/html/conversions.doc.html#184206">5.2</a>
171 * for more information on assignment compatibility.
172 * <p>
173 * By default, all threads in the target VM are resumed while
174 * the method is being invoked if they were previously
175 * suspended by an event or by {@link VirtualMachine#suspend} or
176 * {@link ThreadReference#suspend}. This is done to prevent the deadlocks
177 * that will occur if any of the threads own monitors
178 * that will be needed by the invoked method.
179 * Note, however, that this implicit resume acts exactly like
180 * {@link ThreadReference#resume}, so if the thread's suspend
181 * count is greater than 1, it will remain in a suspended state
182 * during the invocation and thus a deadlock could still occur.
183 * By default, when the invocation completes,
184 * all threads in the target VM are suspended, regardless their state
185 * before the invocation.
186 * It is possible that
187 * breakpoints or other events might occur during the invocation.
188 * This can cause deadlocks as described above. It can also cause a deadlock
189 * if invokeMethod is called from the client's event handler thread. In this
190 * case, this thread will be waiting for the invokeMethod to complete and
191 * won't read the EventSet that comes in for the new event. If this
192 * new EventSet is SUSPEND_ALL, then a deadlock will occur because no
193 * one will resume the EventSet. To avoid this, all EventRequests should
194 * be disabled before doing the invokeMethod, or the invokeMethod should
195 * not be done from the client's event handler thread.
196 * <p>
197 * The resumption of other threads during the invocation can be prevented
198 * by specifying the {@link #INVOKE_SINGLE_THREADED}
199 * bit flag in the <code>options</code> argument; however,
200 * there is no protection against or recovery from the deadlocks
201 * described above, so this option should be used with great caution.
202 * Only the specified thread will be resumed (as described for all
203 * threads above). Upon completion of a single threaded invoke, the invoking thread
204 * will be suspended once again. Note that any threads started during
205 * the single threaded invocation will not be suspended when the
206 * invocation completes.
207 * <p>
208 * If the target VM is disconnected during the invoke (for example, through
209 * {@link VirtualMachine#dispose}) the method invocation continues.
210 *
211 * @param thread the thread in which to invoke.
212 * @param method the {@link Method} to invoke.
213 * @param arguments the list of {@link Value} arguments bound to the
214 * invoked method. Values from the list are assigned to arguments
215 * in the order they appear in the method signature.
216 * @param options the integer bit flag options.
217 * @return a {@link Value} mirror of the invoked method's return value.
218 * @throws java.lang.IllegalArgumentException if the method is not
219 * a member of this class or a superclass, if the size of the argument list
220 * does not match the number of declared arguemnts for the method, or
221 * if the method is an initializer, constructor or static intializer.
222 * @throws {@link InvalidTypeException} if any argument in the
223 * argument list is not assignable to the corresponding method argument
224 * type.
225 * @throws ClassNotLoadedException if any argument type has not yet been loaded
226 * through the appropriate class loader.
227 * @throws IncompatibleThreadStateException if the specified thread has not
228 * been suspended by an event.
229 * @throws InvocationException if the method invocation resulted in
230 * an exception in the target VM.
231 * @throws InvalidTypeException If the arguments do not meet this requirement --
232 * Object arguments must be assignment compatible with the argument
233 * type. This implies that the argument type must be
234 * loaded through the enclosing class's class loader.
235 * Primitive arguments must be either assignment compatible with the
236 * argument type or must be convertible to the argument type without loss
237 * of information. See JLS section 5.2 for more information on assignment
238 * compatibility.
239 * @throws VMCannotBeModifiedException if the VirtualMachine is read-only - see {@link VirtualMachine#canBeModified()}.
240 */
241 Value invokeMethod(ThreadReference thread, Method method,
242 List<? extends Value> arguments, int options)
243 throws InvalidTypeException,
244 ClassNotLoadedException,
245 IncompatibleThreadStateException,
246 InvocationException;
247
248 /**
249 * Constructs a new instance of this type, using
250 * the given constructor {@link Method} in the
251 * target VM. The
252 * specified constructor must be defined in this class.
253 * <p>
254 * Instance creation will occur in the specified thread.
255 * Instance creation can occur only if the specified thread
256 * has been suspended by an event which occurred in that thread.
257 * Instance creation is not supported
258 * when the target VM has been suspended through
259 * {@link VirtualMachine#suspend} or when the specified thread
260 * is suspended through {@link ThreadReference#suspend}.
261 * <p>
262 * The specified constructor is invoked with the arguments in the specified
263 * argument list. The invocation is synchronous; this method
264 * does not return until the constructor returns in the target VM.
265 * If the invoked method throws an
266 * exception, this method will throw an {@link InvocationException}
267 * which contains a mirror to the exception object thrown.
268 * <p>
269 * Object arguments must be assignment compatible with the argument type
270 * (This implies that the argument type must be loaded through the
271 * enclosing class's class loader). Primitive arguments must be
272 * either assignment compatible with the argument type or must be
273 * convertible to the argument type without loss of information.
274 * If the method being called accepts a variable number of arguments,
275 * then the last argument type is an array of some component type.
276 * The argument in the matching position can be omitted, or can be null,
277 * an array of the same component type, or an argument of the
278 * component type, followed by any number of other arguments of the same
279 * type. If the argument is omitted, then a 0 length array of the
280 * component type is passed. The component type can be a primitive type.
281 * Autoboxing is not supported.
282 *
283 * See the <a href="http://java.sun.com/docs/books/jls/">
284 * Java Language Specification</a>.
285 * section
286 * <a href="http://java.sun.com/docs/books/jls/second_edition/html/conversions.doc.html#184206">5.2</a>
287 * for more information on assignment compatibility.
288 * <p>
289 * By default, all threads in the target VM are resumed while
290 * the method is being invoked if they were previously
291 * suspended by an event or by {@link VirtualMachine#suspend} or
292 * {@link ThreadReference#suspend}. This is done to prevent the deadlocks
293 * that will occur if any of the threads own monitors
294 * that will be needed by the invoked method. It is possible that
295 * breakpoints or other events might occur during the invocation.
296 * Note, however, that this implicit resume acts exactly like
297 * {@link ThreadReference#resume}, so if the thread's suspend
298 * count is greater than 1, it will remain in a suspended state
299 * during the invocation. By default, when the invocation completes,
300 * all threads in the target VM are suspended, regardless their state
301 * before the invocation.
302 * <p>
303 * The resumption of other threads during the invocation can be prevented
304 * by specifying the {@link #INVOKE_SINGLE_THREADED}
305 * bit flag in the <code>options</code> argument; however,
306 * there is no protection against or recovery from the deadlocks
307 * described above, so this option should be used with great caution.
308 * Only the specified thread will be resumed (as described for all
309 * threads above). Upon completion of a single threaded invoke, the invoking thread
310 * will be suspended once again. Note that any threads started during
311 * the single threaded invocation will not be suspended when the
312 * invocation completes.
313 * <p>
314 * If the target VM is disconnected during the invoke (for example, through
315 * {@link VirtualMachine#dispose}) the method invocation continues.
316 *
317 * @param thread the thread in which to invoke.
318 * @param method the constructor {@link Method} to invoke.
319 * @param arguments the list of {@link Value} arguments bound to the
320 * invoked constructor. Values from the list are assigned to arguments
321 * in the order they appear in the constructor signature.
322 * @param options the integer bit flag options.
323 * @return an {@link ObjectReference} mirror of the newly created
324 * object.
325 * @throws java.lang.IllegalArgumentException if the method is not
326 * a member of this class, if the size of the argument list
327 * does not match the number of declared arguments for the constructor,
328 * or if the method is not a constructor.
329 * @throws {@link InvalidTypeException} if any argument in the
330 * argument list is not assignable to the corresponding method argument
331 * type.
332 * @throws ClassNotLoadedException if any argument type has not yet been loaded
333 * through the appropriate class loader.
334 * @throws IncompatibleThreadStateException if the specified thread has not
335 * been suspended by an event.
336 * @throws InvocationException if the method invocation resulted in
337 * an exception in the target VM.
338 * @throws InvalidTypeException If the arguments do not meet this requirement --
339 * Object arguments must be assignment compatible with the argument
340 * type. This implies that the argument type must be
341 * loaded through the enclosing class's class loader.
342 * Primitive arguments must be either assignment compatible with the
343 * argument type or must be convertible to the argument type without loss
344 * of information. See JLS section 5.2 for more information on assignment
345 * compatibility.
346 * @throws VMCannotBeModifiedException if the VirtualMachine is read-only
347 * - see {@link VirtualMachine#canBeModified()}.
348 */
349 ObjectReference newInstance(ThreadReference thread, Method method,
350 List<? extends Value> arguments, int options)
351 throws InvalidTypeException,
352 ClassNotLoadedException,
353 IncompatibleThreadStateException,
354 InvocationException;
355
356 /**
357 * Returns a the single non-abstract {@link Method} visible from
358 * this class that has the given name and signature.
359 * See {@link ReferenceType#methodsByName(java.lang.String, java.lang.String)}
360 * for information on signature format.
361 * <p>
362 * The returned method (if non-null) is a component of
363 * {@link ClassType}.
364 *
365 * @see ReferenceType#visibleMethods
366 * @see ReferenceType#methodsByName(java.lang.String name)
367 * @see ReferenceType#methodsByName(java.lang.String name, java.lang.String signature)
368 * @param name the name of the method to find.
369 * @param signature the signature of the method to find
370 * @return the {@link Method} that matches the given
371 * name and signature or <code>null</code> if there is no match.
372 * @throws ClassNotPreparedException if methods are not yet available
373 * because the class has not yet been prepared.
374 */
375 Method concreteMethodByName(String name, String signature);
376}