Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/com/sun/jdi/ObjectReference.java
38831 views
/*1* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package com.sun.jdi;2627import java.util.List;28import java.util.Map;2930/**31* An object that currently exists in the target VM. An ObjectReference32* mirrors only the object itself and is not specific to any33* {@link Field} or {@link LocalVariable} to which it is currently34* assigned. An ObjectReference can35* have 0 or more references from field(s) and/or variable(s).36* <p>37* Any method on <code>ObjectReference</code> which directly or38* indirectly takes <code>ObjectReference</code> as an parameter may throw39* {@link com.sun.jdi.VMDisconnectedException} if the target VM is40* disconnected and the {@link com.sun.jdi.event.VMDisconnectEvent} has been or is41* available to be read from the {@link com.sun.jdi.event.EventQueue}.42* <p>43* Any method on <code>ObjectReference</code> which directly or44* indirectly takes <code>ObjectReference</code> as an parameter may throw45* {@link com.sun.jdi.VMOutOfMemoryException} if the target VM has run out of memory.46* <p>47* Any method on <code>ObjectReference</code> or which directly or indirectly takes48* <code>ObjectReference</code> as parameter may throw49* {@link com.sun.jdi.ObjectCollectedException} if the mirrored object has been50* garbage collected.51*52* @author Robert Field53* @author Gordon Hirsch54* @author James McIlree55* @since 1.356*/57@jdk.Exported58public interface ObjectReference extends Value {5960/**61* Gets the {@link ReferenceType} that mirrors the type62* of this object. The type may be a subclass or implementor of the63* declared type of any field or variable which currently holds it.64* For example, right after the following statement.65* <p>66* <code>Object obj = new String("Hello, world!");</code>67* <p>68* The ReferenceType of obj will mirror java.lang.String and not69* java.lang.Object.70* <p>71* The type of an object never changes, so this method will72* always return the same ReferenceType over the lifetime of the73* mirrored object.74* <p>75* The returned ReferenceType will be a {@link ClassType} or76* {@link ArrayType} and never an {@link InterfaceType}.77*78* @return the {@link ReferenceType} for this object.79*/80ReferenceType referenceType();8182/**83* Gets the value of a given instance or static field in this object.84* The Field must be valid for this ObjectReference;85* that is, it must be from86* the mirrored object's class or a superclass of that class.87*88* @param sig the field containing the requested value89* @return the {@link Value} of the instance field.90* @throws java.lang.IllegalArgumentException if the field is not valid for91* this object's class.92*/93Value getValue(Field sig);9495/**96* Gets the value of multiple instance and/or static fields in this object.97* The Fields must be valid for this ObjectReference;98* that is, they must be from99* the mirrored object's class or a superclass of that class.100*101* @param fields a list of {@link Field} objects containing the102* requested values.103* @return a Map of the requested {@link Field} objects with104* their {@link Value}.105* @throws java.lang.IllegalArgumentException if any field is not valid for106* this object's class.107*/108Map<Field,Value> getValues(List<? extends Field> fields);109110/**111* Sets the value of a given instance or static field in this object.112* The {@link Field} must be valid for this ObjectReference; that is,113* it must be from the mirrored object's class or a superclass of that class.114* If static, the field must not be final.115* <p>116* Object values must be assignment compatible with the field type117* (This implies that the field type must be loaded through the118* enclosing class's class loader). Primitive values must be119* either assignment compatible with the field type or must be120* convertible to the field type without loss of information.121* See section 5.2 of122* <cite>The Java™ Language Specification</cite>123* for more information on assignment124* compatibility.125*126* @param field the field containing the requested value127* @param value the new value to assign128* @throws java.lang.IllegalArgumentException if the field is not valid for129* this object's class.130* @throws InvalidTypeException if the value's type does not match131* the field's type.132* @throws ClassNotLoadedException if 'value' is not null, and the field133* type has not yet been loaded through the appropriate class loader.134* @throws VMCannotBeModifiedException if the VirtualMachine is read-only - see {@link VirtualMachine#canBeModified()}.135*/136void setValue(Field field, Value value)137throws InvalidTypeException, ClassNotLoadedException;138139/** Perform method invocation with only the invoking thread resumed */140static final int INVOKE_SINGLE_THREADED = 0x1;141/** Perform non-virtual method invocation */142static final int INVOKE_NONVIRTUAL = 0x2;143144/**145* Invokes the specified {@link Method} on this object in the146* target VM. The147* specified method can be defined in this object's class,148* in a superclass of this object's class, or in an interface149* implemented by this object. The method may be a static method150* or an instance method, but not a static initializer or constructor.151* Use {@link ClassType#newInstance} to create a new object and152* run its constructor.153* <p>154* The method invocation will occur in the specified thread.155* Method invocation can occur only if the specified thread156* has been suspended by an event which occurred in that thread.157* Method invocation is not supported158* when the target VM has been suspended through159* {@link VirtualMachine#suspend} or when the specified thread160* is suspended through {@link ThreadReference#suspend}.161* <p>162* The specified method is invoked with the arguments in the specified163* argument list. The method invocation is synchronous; this method164* does not return until the invoked method returns in the target VM.165* If the invoked method throws an exception, this method166* will throw an {@link InvocationException} which contains167* a mirror to the exception object thrown.168* <p>169* Object arguments must be assignment compatible with the argument type170* (This implies that the argument type must be loaded through the171* enclosing class's class loader). Primitive arguments must be172* either assignment compatible with the argument type or must be173* convertible to the argument type without loss of information.174* If the method being called accepts a variable number of arguments,175* then the last argument type is an array of some component type.176* The argument in the matching position can be omitted, or can be null,177* an array of the same component type, or an argument of the178* component type followed by any number of other arguments of the same179* type. If the argument is omitted, then a 0 length array of the180* component type is passed. The component type can be a primitive type.181* Autoboxing is not supported.182*183* See section 5.2 of184* <cite>The Java™ Language Specification</cite>185* for more information on assignment compatibility.186* <p>187* By default, the method is invoked using dynamic lookup as188* documented in section 15.12.4.4 of189* <cite>The Java™ Language Specification</cite>190* in particular, overriding based on the runtime type of the object191* mirrored by this {@link ObjectReference} will occur. This192* behavior can be changed by specifying the193* {@link #INVOKE_NONVIRTUAL} bit flag in the <code>options</code>194* argument. If this flag is set, the specified method is invoked195* whether or not it is overridden for this object's runtime type.196* The method, in this case, must have an implementation, either in a class197* or an interface. This option is useful for performing method invocations198* like those done with the <code>super</code> keyword in the Java programming199* language.200* <p>201* By default, all threads in the target VM are resumed while202* the method is being invoked if they were previously203* suspended by an event or by {@link VirtualMachine#suspend} or204* {@link ThreadReference#suspend}. This is done to prevent the deadlocks205* that will occur if any of the threads own monitors206* that will be needed by the invoked method.207* Note, however, that this implicit resume acts exactly like208* {@link ThreadReference#resume}, so if the thread's suspend209* count is greater than 1, it will remain in a suspended state210* during the invocation and thus a deadlock could still occur.211* By default, when the invocation completes,212* all threads in the target VM are suspended, regardless their state213* before the invocation.214* It is possible that215* breakpoints or other events might occur during the invocation.216* This can cause deadlocks as described above. It can also cause a deadlock217* if invokeMethod is called from the client's event handler thread. In this218* case, this thread will be waiting for the invokeMethod to complete and219* won't read the EventSet that comes in for the new event. If this220* new EventSet is SUSPEND_ALL, then a deadlock will occur because no221* one will resume the EventSet. To avoid this, all EventRequests should222* be disabled before doing the invokeMethod, or the invokeMethod should223* not be done from the client's event handler thread.224* <p>225* The resumption of other threads during the invocation can be prevented226* by specifying the {@link #INVOKE_SINGLE_THREADED}227* bit flag in the <code>options</code> argument; however,228* there is no protection against or recovery from the deadlocks229* described above, so this option should be used with great caution.230* Only the specified thread will be resumed (as described for all231* threads above). Upon completion of a single threaded invoke, the invoking thread232* will be suspended once again. Note that any threads started during233* the single threaded invocation will not be suspended when the234* invocation completes.235* <p>236* If the target VM is disconnected during the invoke (for example, through237* {@link VirtualMachine#dispose}) the method invocation continues.238*239* @param thread the thread in which to invoke.240* @param method the {@link Method} to invoke.241* @param arguments the list of {@link Value} arguments bound to the242* invoked method. Values from the list are assigned to arguments243* in the order they appear in the method signature.244* @param options the integer bit flag options.245* @return a {@link Value} mirror of the invoked method's return value.246* @throws java.lang.IllegalArgumentException if the method is not247* a member of this object's class, if the size of the argument list248* does not match the number of declared arguments for the method,249* if the method is a constructor or static intializer, or250* if {@link #INVOKE_NONVIRTUAL} is specified and the method is251* either abstract or a non-default interface member.252* @throws {@link InvalidTypeException} if any argument in the253* argument list is not assignable to the corresponding method argument254* type.255* @throws ClassNotLoadedException if any argument type has not yet been loaded256* through the appropriate class loader.257* @throws IncompatibleThreadStateException if the specified thread has not258* been suspended by an event.259* @throws InvocationException if the method invocation resulted in260* an exception in the target VM.261* @throws InvalidTypeException If the arguments do not meet this requirement --262* Object arguments must be assignment compatible with the argument263* type. This implies that the argument type must be264* loaded through the enclosing class's class loader.265* Primitive arguments must be either assignment compatible with the266* argument type or must be convertible to the argument type without loss267* of information. See JLS section 5.2 for more information on assignment268* compatibility.269* @throws VMCannotBeModifiedException if the VirtualMachine is read-only - see {@link VirtualMachine#canBeModified()}.270*/271Value invokeMethod(ThreadReference thread, Method method,272List<? extends Value> arguments, int options)273throws InvalidTypeException,274ClassNotLoadedException,275IncompatibleThreadStateException,276InvocationException;277278/**279* Prevents garbage collection for this object. By default all280* {@link ObjectReference} values returned by JDI may be collected281* at any time the target VM is running. A call to this method282* guarantees that the object will not be collected.283* {@link #enableCollection} can be used to allow collection once284* again.285* <p>286* Calls to this method are counted. Every call to this method287* requires a corresponding call to {@link #enableCollection} before288* garbage collection is re-enabled.289* <p>290* Note that while the target VM is suspended, no garbage collection291* will occur because all threads are suspended. The typical292* examination of variables, fields, and arrays during the suspension293* is safe without explicitly disabling garbage collection.294* <p>295* This method should be used sparingly, as it alters the296* pattern of garbage collection in the target VM and,297* consequently, may result in application behavior under the298* debugger that differs from its non-debugged behavior.299* @throws VMCannotBeModifiedException if the VirtualMachine is read-only300* -see {@link VirtualMachine#canBeModified()}.301*/302void disableCollection();303304/**305* Permits garbage collection for this object. By default all306* {@link ObjectReference} values returned by JDI may be collected307* at any time the target VM is running. A call to this method308* is necessary only if garbage collection was previously disabled309* with {@link #disableCollection}.310* @throws VMCannotBeModifiedException if the VirtualMachine is read-only311* -see {@link VirtualMachine#canBeModified()}.312*/313void enableCollection();314315/**316* Determines if this object has been garbage collected in the target317* VM.318*319* @return <code>true</code> if this {@link ObjectReference} has been collected;320* <code>false</code> otherwise.321* @throws VMCannotBeModifiedException if the VirtualMachine is read-only322* -see {@link VirtualMachine#canBeModified()}.323*/324boolean isCollected();325326/**327* Returns a unique identifier for this ObjectReference.328* It is guaranteed to be unique among all329* ObjectReferences from the same VM that have not yet been disposed.330* The guarantee applies as long331* as this ObjectReference has not yet been disposed.332*333* @return a long unique ID334*/335long uniqueID();336337/**338* Returns a List containing a {@link ThreadReference} for339* each thread currently waiting for this object's monitor.340* See {@link ThreadReference#currentContendedMonitor} for341* information about when a thread is considered to be waiting342* for a monitor.343* <p>344* Not all target VMs support this operation. See345* VirtualMachine#canGetMonitorInfo to determine if the346* operation is supported.347*348* @return a List of {@link ThreadReference} objects. The list349* has zero length if no threads are waiting for the monitor.350* @throws java.lang.UnsupportedOperationException if the351* target VM does not support this operation.352* @throws IncompatibleThreadStateException if any353* waiting thread is not suspended354* in the target VM355*/356List<ThreadReference> waitingThreads()357throws IncompatibleThreadStateException;358359/**360* Returns an {@link ThreadReference} for the thread, if any,361* which currently owns this object's monitor.362* See {@link ThreadReference#ownedMonitors} for a definition363* of ownership.364* <p>365* Not all target VMs support this operation. See366* VirtualMachine#canGetMonitorInfo to determine if the367* operation is supported.368*369* @return the {@link ThreadReference} which currently owns the370* monitor, or null if it is unowned.371*372* @throws java.lang.UnsupportedOperationException if the373* target VM does not support this operation.374* @throws IncompatibleThreadStateException if the owning thread is375* not suspended in the target VM376*/377ThreadReference owningThread() throws IncompatibleThreadStateException;378379/**380* Returns the number times this object's monitor has been381* entered by the current owning thread.382* See {@link ThreadReference#ownedMonitors} for a definition383* of ownership.384* <p>385* Not all target VMs support this operation. See386* VirtualMachine#canGetMonitorInfo to determine if the387* operation is supported.388*389* @see #owningThread390* @return the integer count of the number of entries.391*392* @throws java.lang.UnsupportedOperationException if the393* target VM does not support this operation.394* @throws IncompatibleThreadStateException if the owning thread is395* not suspended in the target VM396*/397int entryCount() throws IncompatibleThreadStateException;398399/**400* Returns objects that directly reference this object.401* Only objects that are reachable for the purposes of garbage collection402* are returned. Note that an object can also be referenced in other ways,403* such as from a local variable in a stack frame, or from a JNI global404* reference. Such non-object referrers are not returned by this method.405* <p>406* Not all target virtual machines support this operation.407* Use {@link VirtualMachine#canGetInstanceInfo()}408* to determine if the operation is supported.409*410* @see VirtualMachine#instanceCounts(List)411* @see ReferenceType#instances(long)412413* @param maxReferrers The maximum number of referring objects to return.414* Must be non-negative. If zero, all referring415* objects are returned.416* @return a of List of {@link ObjectReference} objects. If there are417* no objects that reference this object, a zero-length list is returned..418* @throws java.lang.UnsupportedOperationException if419* the target virtual machine does not support this420* operation - see421* {@link VirtualMachine#canGetInstanceInfo() canGetInstanceInfo()}422* @throws java.lang.IllegalArgumentException if maxReferrers is less423* than zero.424* @since 1.6425*/426List<ObjectReference> referringObjects(long maxReferrers);427428429/**430* Compares the specified Object with this ObjectReference for equality.431*432* @return true if the Object is an ObjectReference, if the433* ObjectReferences belong to the same VM, and if applying the434* "==" operator on the mirrored objects in that VM evaluates to true.435*/436boolean equals(Object obj);437438/**439* Returns the hash code value for this ObjectReference.440*441* @return the integer hash code442*/443int hashCode();444}445446447