2362N/A * Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * An object that currently exists in the target VM. An ObjectReference 0N/A * mirrors only the object itself and is not specific to any 0N/A * {@link Field} or {@link LocalVariable} to which it is currently 0N/A * assigned. An ObjectReference can 0N/A * have 0 or more references from field(s) and/or variable(s). 0N/A * Any method on <code>ObjectReference</code> which directly or 0N/A * indirectly takes <code>ObjectReference</code> as an parameter may throw 0N/A * {@link com.sun.jdi.VMDisconnectedException} if the target VM is 0N/A * disconnected and the {@link com.sun.jdi.event.VMDisconnectEvent} has been or is 0N/A * available to be read from the {@link com.sun.jdi.event.EventQueue}. 0N/A * Any method on <code>ObjectReference</code> which directly or 0N/A * indirectly takes <code>ObjectReference</code> as an parameter may throw 0N/A * {@link com.sun.jdi.VMOutOfMemoryException} if the target VM has run out of memory. 0N/A * Any method on <code>ObjectReference</code> or which directly or indirectly takes 0N/A * <code>ObjectReference</code> as parameter may throw 0N/A * {@link com.sun.jdi.ObjectCollectedException} if the mirrored object has been 0N/A * garbage collected. 0N/A * @author Robert Field 0N/A * @author Gordon Hirsch 0N/A * @author James McIlree 0N/A * Gets the {@link ReferenceType} that mirrors the type 0N/A * of this object. The type may be a subclass or implementor of the 0N/A * declared type of any field or variable which currently holds it. 0N/A * For example, right after the following statement. 0N/A * <code>Object obj = new String("Hello, world!");</code> 0N/A * The ReferenceType of obj will mirror java.lang.String and not 0N/A * The type of an object never changes, so this method will 0N/A * always return the same ReferenceType over the lifetime of the 0N/A * The returned ReferenceType will be a {@link ClassType} or 0N/A * {@link ArrayType} and never an {@link InterfaceType}. 0N/A * @return the {@link ReferenceType} for this object. 0N/A * Gets the value of a given instance or static field in this object. 0N/A * The Field must be valid for this ObjectReference; 0N/A * that is, it must be from 0N/A * the mirrored object's class or a superclass of that class. 0N/A * @param sig the field containing the requested value 0N/A * @return the {@link Value} of the instance field. 0N/A * @throws java.lang.IllegalArgumentException if the field is not valid for 0N/A * this object's class. 0N/A * Gets the value of multiple instance and/or static fields in this object. 0N/A * The Fields must be valid for this ObjectReference; 0N/A * that is, they must be from 0N/A * the mirrored object's class or a superclass of that class. 0N/A * @param fields a list of {@link Field} objects containing the 0N/A * @return a Map of the requested {@link Field} objects with 0N/A * their {@link Value}. 0N/A * @throws java.lang.IllegalArgumentException if any field is not valid for 0N/A * this object's class. 0N/A * Sets the value of a given instance or static field in this object. 0N/A * The {@link Field} must be valid for this ObjectReference; that is, 0N/A * it must be from the mirrored object's class or a superclass of that class. 0N/A * If static, the field must not be final. 0N/A * Object values must be assignment compatible with the field type 0N/A * (This implies that the field type must be loaded through the 0N/A * enclosing class's class loader). Primitive values must be 0N/A * either assignment compatible with the field type or must be 0N/A * convertible to the field type without loss of information. 4008N/A * <cite>The Java™ Language Specification</cite> 0N/A * for more information on assignment 0N/A * @param field the field containing the requested value 0N/A * @param value the new value to assign 0N/A * @throws java.lang.IllegalArgumentException if the field is not valid for 0N/A * this object's class. 0N/A * @throws InvalidTypeException if the value's type does not match 0N/A * @throws ClassNotLoadedException if 'value' is not null, and the field 0N/A * type has not yet been loaded through the appropriate class loader. 0N/A * @throws VMCannotBeModifiedException if the VirtualMachine is read-only - see {@link VirtualMachine#canBeModified()}. 0N/A /** Perform method invocation with only the invoking thread resumed */ 0N/A /** Perform non-virtual method invocation */ 0N/A * Invokes the specified {@link Method} on this object in the 0N/A * specified method can be defined in this object's class, 0N/A * in a superclass of this object's class, or in an interface 0N/A * implemented by this object. The method may be a static method 0N/A * or an instance method, but not a static initializer or constructor. 0N/A * Use {@link ClassType#newInstance} to create a new object and 0N/A * run its constructor. 0N/A * The method invocation will occur in the specified thread. 0N/A * Method invocation can occur only if the specified thread 0N/A * has been suspended by an event which occurred in that thread. 0N/A * Method invocation is not supported 0N/A * when the target VM has been suspended through 0N/A * {@link VirtualMachine#suspend} or when the specified thread 0N/A * is suspended through {@link ThreadReference#suspend}. 0N/A * The specified method is invoked with the arguments in the specified 0N/A * argument list. The method invocation is synchronous; this method 0N/A * does not return until the invoked method returns in the target VM. 0N/A * If the invoked method throws an exception, this method 0N/A * will throw an {@link InvocationException} which contains 0N/A * a mirror to the exception object thrown. 0N/A * Object arguments must be assignment compatible with the argument type 0N/A * (This implies that the argument type must be loaded through the 0N/A * enclosing class's class loader). Primitive arguments must be 0N/A * either assignment compatible with the argument type or must be 0N/A * convertible to the argument type without loss of information. 0N/A * If the method being called accepts a variable number of arguments, 0N/A * then the last argument type is an array of some component type. 0N/A * The argument in the matching position can be omitted, or can be null, 0N/A * an array of the same component type, or an argument of the 0N/A * component type followed by any number of other arguments of the same 0N/A * type. If the argument is omitted, then a 0 length array of the 0N/A * component type is passed. The component type can be a primitive type. 0N/A * Autoboxing is not supported. 4008N/A * <cite>The Java™ Language Specification</cite> 0N/A * for more information on assignment compatibility. 0N/A * By default, the method is invoked using dynamic lookup as 4008N/A * documented in section 15.12.4.4 of 4008N/A * <cite>The Java™ Language Specification</cite> 0N/A * in particular, overriding based on the runtime type of the object 0N/A * mirrored by this {@link ObjectReference} will occur. This 0N/A * behavior can be changed by specifying the 0N/A * {@link #INVOKE_NONVIRTUAL} bit flag in the <code>options</code> 0N/A * argument. If this flag is set, the specified method is invoked 0N/A * whether or not it is overridden for this object's runtime type. 0N/A * The method, in this case, must not belong to an interface and 0N/A * must not be abstract. This option is useful for performing method 0N/A * invocations like those done with the <code>super</code> keyword in 0N/A * the Java programming language. 0N/A * By default, all threads in the target VM are resumed while 0N/A * the method is being invoked if they were previously 0N/A * suspended by an event or by {@link VirtualMachine#suspend} or 0N/A * {@link ThreadReference#suspend}. This is done to prevent the deadlocks 0N/A * that will occur if any of the threads own monitors 0N/A * that will be needed by the invoked method. 0N/A * Note, however, that this implicit resume acts exactly like 0N/A * {@link ThreadReference#resume}, so if the thread's suspend 0N/A * count is greater than 1, it will remain in a suspended state 0N/A * during the invocation and thus a deadlock could still occur. 0N/A * By default, when the invocation completes, 0N/A * all threads in the target VM are suspended, regardless their state 0N/A * before the invocation. 0N/A * It is possible that 0N/A * breakpoints or other events might occur during the invocation. 0N/A * This can cause deadlocks as described above. It can also cause a deadlock 0N/A * if invokeMethod is called from the client's event handler thread. In this 0N/A * case, this thread will be waiting for the invokeMethod to complete and 0N/A * won't read the EventSet that comes in for the new event. If this 0N/A * new EventSet is SUSPEND_ALL, then a deadlock will occur because no 0N/A * one will resume the EventSet. To avoid this, all EventRequests should 0N/A * be disabled before doing the invokeMethod, or the invokeMethod should 0N/A * not be done from the client's event handler thread. 0N/A * The resumption of other threads during the invocation can be prevented 0N/A * by specifying the {@link #INVOKE_SINGLE_THREADED} 0N/A * bit flag in the <code>options</code> argument; however, 0N/A * there is no protection against or recovery from the deadlocks 0N/A * described above, so this option should be used with great caution. 0N/A * Only the specified thread will be resumed (as described for all 0N/A * threads above). Upon completion of a single threaded invoke, the invoking thread 0N/A * will be suspended once again. Note that any threads started during 0N/A * the single threaded invocation will not be suspended when the 0N/A * invocation completes. 0N/A * If the target VM is disconnected during the invoke (for example, through 0N/A * {@link VirtualMachine#dispose}) the method invocation continues. 0N/A * @param thread the thread in which to invoke. 0N/A * @param method the {@link Method} to invoke. 0N/A * @param arguments the list of {@link Value} arguments bound to the 0N/A * invoked method. Values from the list are assigned to arguments 0N/A * in the order they appear in the method signature. 0N/A * @param options the integer bit flag options. 0N/A * @return a {@link Value} mirror of the invoked method's return value. 0N/A * @throws java.lang.IllegalArgumentException if the method is not 0N/A * a member of this object's class, if the size of the argument list 0N/A * does not match the number of declared arguemnts for the method, 0N/A * if the method is a constructor or static intializer, or 0N/A * if {@link #INVOKE_NONVIRTUAL} is specified and the method is 0N/A * either abstract or an interface member. 0N/A * @throws {@link InvalidTypeException} if any argument in the 0N/A * argument list is not assignable to the corresponding method argument 0N/A * @throws ClassNotLoadedException if any argument type has not yet been loaded 0N/A * through the appropriate class loader. 0N/A * @throws IncompatibleThreadStateException if the specified thread has not 0N/A * been suspended by an event. 0N/A * @throws InvocationException if the method invocation resulted in 0N/A * an exception in the target VM. 0N/A * @throws InvalidTypeException If the arguments do not meet this requirement -- 0N/A * Object arguments must be assignment compatible with the argument 0N/A * type. This implies that the argument type must be 0N/A * loaded through the enclosing class's class loader. 0N/A * Primitive arguments must be either assignment compatible with the 0N/A * argument type or must be convertible to the argument type without loss 0N/A * of information. See JLS section 5.2 for more information on assignment 0N/A * @throws VMCannotBeModifiedException if the VirtualMachine is read-only - see {@link VirtualMachine#canBeModified()}. 0N/A * Prevents garbage collection for this object. By default all 0N/A * {@link ObjectReference} values returned by JDI may be collected 0N/A * at any time the target VM is running. A call to this method 0N/A * guarantees that the object will not be collected. 0N/A * {@link #enableCollection} can be used to allow collection once 0N/A * Calls to this method are counted. Every call to this method 0N/A * requires a corresponding call to {@link #enableCollection} before 0N/A * garbage collection is re-enabled. 0N/A * Note that while the target VM is suspended, no garbage collection 0N/A * will occur because all threads are suspended. The typical 0N/A * examination of variables, fields, and arrays during the suspension 0N/A * is safe without explicitly disabling garbage collection. 0N/A * This method should be used sparingly, as it alters the 0N/A * pattern of garbage collection in the target VM and, 0N/A * consequently, may result in application behavior under the 0N/A * debugger that differs from its non-debugged behavior. 0N/A * @throws VMCannotBeModifiedException if the VirtualMachine is read-only 0N/A * -see {@link VirtualMachine#canBeModified()}. 0N/A * Permits garbage collection for this object. By default all 0N/A * {@link ObjectReference} values returned by JDI may be collected 0N/A * at any time the target VM is running. A call to this method 0N/A * is necessary only if garbage collection was previously disabled 0N/A * with {@link #disableCollection}. 0N/A * @throws VMCannotBeModifiedException if the VirtualMachine is read-only 0N/A * -see {@link VirtualMachine#canBeModified()}. 0N/A * Determines if this object has been garbage collected in the target 0N/A * @return <code>true</code> if this {@link ObjectReference} has been collected; 0N/A * <code>false</code> otherwise. 0N/A * @throws VMCannotBeModifiedException if the VirtualMachine is read-only 0N/A * -see {@link VirtualMachine#canBeModified()}. 0N/A * Returns a unique identifier for this ObjectReference. 0N/A * It is guaranteed to be unique among all 0N/A * ObjectReferences from the same VM that have not yet been disposed. 0N/A * The guarantee applies as long 0N/A * as this ObjectReference has not yet been disposed. 0N/A * @return a long unique ID 0N/A * Returns a List containing a {@link ThreadReference} for 0N/A * each thread currently waiting for this object's monitor. 0N/A * See {@link ThreadReference#currentContendedMonitor} for 0N/A * information about when a thread is considered to be waiting 0N/A * Not all target VMs support this operation. See 0N/A * VirtualMachine#canGetMonitorInfo to determine if the 0N/A * operation is supported. 0N/A * @return a List of {@link ThreadReference} objects. The list 0N/A * has zero length if no threads are waiting for the monitor. 0N/A * @throws java.lang.UnsupportedOperationException if the 0N/A * target VM does not support this operation. 0N/A * @throws IncompatibleThreadStateException if any 0N/A * waiting thread is not suspended 0N/A * Returns an {@link ThreadReference} for the thread, if any, 0N/A * which currently owns this object's monitor. 0N/A * See {@link ThreadReference#ownedMonitors} for a definition 0N/A * Not all target VMs support this operation. See 0N/A * VirtualMachine#canGetMonitorInfo to determine if the 0N/A * operation is supported. 0N/A * @return the {@link ThreadReference} which currently owns the 0N/A * monitor, or null if it is unowned. 0N/A * @throws java.lang.UnsupportedOperationException if the 0N/A * target VM does not support this operation. 0N/A * @throws IncompatibleThreadStateException if the owning thread is 0N/A * not suspended in the target VM 0N/A * Returns the number times this object's monitor has been 0N/A * entered by the current owning thread. 0N/A * See {@link ThreadReference#ownedMonitors} for a definition 0N/A * Not all target VMs support this operation. See 0N/A * VirtualMachine#canGetMonitorInfo to determine if the 0N/A * operation is supported. 0N/A * @see #owningThread 0N/A * @return the integer count of the number of entries. 0N/A * @throws java.lang.UnsupportedOperationException if the 0N/A * target VM does not support this operation. 0N/A * @throws IncompatibleThreadStateException if the owning thread is 0N/A * not suspended in the target VM 0N/A * Returns objects that directly reference this object. 0N/A * Only objects that are reachable for the purposes of garbage collection 0N/A * are returned. Note that an object can also be referenced in other ways, 0N/A * such as from a local variable in a stack frame, or from a JNI global 0N/A * reference. Such non-object referrers are not returned by this method. 0N/A * Not all target virtual machines support this operation. 0N/A * Use {@link VirtualMachine#canGetInstanceInfo()} 0N/A * to determine if the operation is supported. 0N/A * @see VirtualMachine#instanceCounts(List) 0N/A * @see ReferenceType#instances(long) 0N/A * @param maxReferrers The maximum number of referring objects to return. 0N/A * Must be non-negative. If zero, all referring 0N/A * objects are returned. 0N/A * @return a of List of {@link ObjectReference} objects. If there are 0N/A * no objects that reference this object, a zero-length list is returned.. 0N/A * @throws java.lang.UnsupportedOperationException if 0N/A * the target virtual machine does not support this 0N/A * {@link VirtualMachine#canGetInstanceInfo() canGetInstanceInfo()} 0N/A * @throws java.lang.IllegalArgumentException if maxReferrers is less 0N/A * Compares the specified Object with this ObjectReference for equality. 0N/A * @return true if the Object is an ObjectReference, if the 0N/A * ObjectReferences belong to the same VM, and if applying the 0N/A * "==" operator on the mirrored objects in that VM evaluates to true. 0N/A * Returns the hash code value for this ObjectReference. 0N/A * @return the integer hash code