APIdia Launch Partner
Top Inners Fields Constructors Methods
com.sun.tools.jdi

public Class ThreadReferenceImpl

extends ObjectReferenceImpl
implements ThreadReference
Class Inheritance
All Implemented Interfaces
com.sun.jdi.ThreadReference, com.sun.jdi.ObjectReference, com.sun.jdi.Value, com.sun.jdi.Mirror
Imports
java.lang.ref.WeakReference, java.util.ArrayList, .Arrays, .Collections, .Iterator, .List, com.sun.jdi.ClassNotLoadedException, .IncompatibleThreadStateException, .InternalException, .InvalidStackFrameException, .InvalidTypeException, .Location, .MonitorInfo, .NativeMethodException, .ObjectReference, .OpaqueFrameException, .ReferenceType, .StackFrame, .ThreadGroupReference, .ThreadReference, .Value, .VirtualMachine, com.sun.jdi.request.BreakpointRequest

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class

Field Summary

Modifier and TypeField and Description
private volatile boolean
private volatile boolean
private List<WeakReference<ThreadListener>>
private ThreadReferenceImpl.LocalCache
pack-priv static final int
pack-priv static final int
private int
private ThreadGroupReference
Inherited from com.sun.tools.jdi.ObjectReferenceImpl:
addedListenerref

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv void
public ObjectReference
currentContendedMonitor()

Implements com.sun.jdi.ThreadReference.currentContendedMonitor.

Returns an ObjectReference for the monitor, if any, for which this thread is currently waiting.

protected String
public void
forceEarlyReturn(Value returnValue)

Implements com.sun.jdi.ThreadReference.forceEarlyReturn.

Force a method to return before it reaches a return statement.

public StackFrame
frame(int index)

Implements com.sun.jdi.ThreadReference.frame.

Returns the StackFrame at the given index in the thread's current call stack.

public int
frameCount()

Implements com.sun.jdi.ThreadReference.frameCount.

Returns the number of stack frames in the thread's current call stack.

public List<StackFrame>
frames()

Implements com.sun.jdi.ThreadReference.frames.

Returns a List containing each StackFrame in the thread's current call stack.

public List<StackFrame>
frames(int start, int length)

Implements com.sun.jdi.ThreadReference.frames.

Returns a List containing a range of StackFrame mirrors from the thread's current call stack.

public void
interrupt()

Implements com.sun.jdi.ThreadReference.interrupt.

Interrupts this thread unless the thread has been suspended by the debugger.

public boolean
isAtBreakpoint()

Implements com.sun.jdi.ThreadReference.isAtBreakpoint.

Determines whether the thread is suspended at a breakpoint.

private boolean
isSubrange(ThreadReferenceImpl.LocalCache snapshot, int start, int length)

Is the requested subrange within what has been retrieved?

public boolean
isSuspended()

Implements com.sun.jdi.ThreadReference.isSuspended.

Determines whether the thread has been suspended by the the debugger.

public boolean
isVirtual()

Overrides default com.sun.jdi.ThreadReference.isVirtual.

Returns true if the thread is a virtual thread.

private JDWP.ThreadReference.Status
public String
name()

Implements com.sun.jdi.ThreadReference.name.

Note that we only cache the name string while the entire VM is suspended because the name can change via Thread.setName arbitrarily while this thread is running.

protected ObjectReferenceImpl.Cache
public List<ObjectReference>
ownedMonitors()

Implements com.sun.jdi.ThreadReference.ownedMonitors.

Returns a List containing an ObjectReference for each monitor owned by the thread.

public List<MonitorInfo>
ownedMonitorsAndFrames()

Implements com.sun.jdi.ThreadReference.ownedMonitorsAndFrames.

Returns a List containing a MonitorInfo object for each monitor owned by the thread.

public void
popFrames(StackFrame frame)

Implements com.sun.jdi.ThreadReference.popFrames.

Pop stack frames.

private synchronized List<StackFrame>
privateFrames(int start, int length)

Private version of frames() allows "-1" to specify all remaining frames.

private void
processThreadAction(ThreadAction action)

Propagate the thread state change information to registered listeners.

private void
public void
resume()

Implements com.sun.jdi.ThreadReference.resume.

Resumes this thread.

pack-priv PacketStream
public int
status()

Implements com.sun.jdi.ThreadReference.status.

Returns the thread's status.

public void
stop(ObjectReference throwable)

Implements com.sun.jdi.ThreadReference.stop.

Stops this thread with an asynchronous exception.

public void
suspend()

Implements com.sun.jdi.ThreadReference.suspend.

Suspends this thread.

public int
suspendCount()

Implements com.sun.jdi.ThreadReference.suspendCount.

Returns the number of pending suspends for this thread.

public ThreadGroupReference
threadGroup()

Implements com.sun.jdi.ThreadReference.threadGroup.

Returns this thread's thread group.

public String
toString()

Overrides com.sun.tools.jdi.ObjectReferenceImpl.toString.

Implements com.sun.jdi.Mirror.toString.

Returns a String describing this mirror

pack-priv byte
public boolean
Inherited from com.sun.tools.jdi.ObjectReferenceImpl:
disableCollectionenableCollectionentryCountequalsgetCachegetValuegetValueshashCodeinvokableReferenceTypeinvokeMethodisClassObjectisCollectedjdwpMonitorInfoowningThreadprepareForAssignmentTorefreferenceTypereferringObjectssendInvokeCommandsetValuetypeuniqueIDvalidateAssignmentvalidateClassMethodInvocationvalidateIfaceMethodInvocationvalidateMethodInvocationvmSuspendedwaitingThreads

Field Detail

isVirtualback to summary
private volatile boolean isVirtual
isVirtualCachedback to summary
private volatile boolean isVirtualCached
listenersback to summary
private List<WeakReference<ThreadListener>> listeners
localCacheback to summary
private ThreadReferenceImpl.LocalCache localCache
SUSPEND_STATUS_BREAKback to summary
pack-priv static final int SUSPEND_STATUS_BREAK
SUSPEND_STATUS_SUSPENDEDback to summary
pack-priv static final int SUSPEND_STATUS_SUSPENDED
suspendedZombieCountback to summary
private int suspendedZombieCount
threadGroupback to summary
private ThreadGroupReference threadGroup

Constructor Detail

ThreadReferenceImplback to summary
pack-priv ThreadReferenceImpl(VirtualMachine aVm, long aRef)

Method Detail

addListenerback to summary
pack-priv void addListener(ThreadListener listener)
currentContendedMonitorback to summary
public ObjectReference currentContendedMonitor() throws IncompatibleThreadStateException

Implements com.sun.jdi.ThreadReference.currentContendedMonitor.

Doc from com.sun.jdi.ThreadReference.currentContendedMonitor.

Returns an ObjectReference for the monitor, if any, for which this thread is currently waiting. The thread can be waiting for a monitor through entry into a synchronized method, the synchronized statement, or Object#wait waiting to re-enter the monitor after being notified, interrupted, or timed-out.

Not all target virtual machines support this operation. Use VirtualMachine#canGetCurrentContendedMonitor() to determine if the operation is supported.

Exceptions
IncompatibleThreadStateException:
if the thread is not suspended in the target VM
descriptionback to summary
protected String description()

Overrides com.sun.tools.jdi.ObjectReferenceImpl.description.

forceEarlyReturnback to summary
public void forceEarlyReturn(Value returnValue) throws InvalidTypeException, ClassNotLoadedException, IncompatibleThreadStateException

Implements com.sun.jdi.ThreadReference.forceEarlyReturn.

Doc from com.sun.jdi.ThreadReference.forceEarlyReturn.

Force a method to return before it reaches a return statement.

The method which will return early is referred to as the called method. The called method is the current method (as defined by the Frames section in the Java Virtual Machine Specification) for the specified thread at the time this method is called.

The thread must be suspended. The return occurs when execution of Java programming language code is resumed on this thread. Between the call to this method and resumption of thread execution, the state of the stack is undefined.

This method may be used to force a return from the current frame of a virtual thread when it is suspended at an event. An implementation may support forcing a return from the current frame of a suspended virtual thread in other cases.

No further instructions are executed in the called method. Specifically, finally blocks are not executed.

Note

this can cause inconsistent states in the application.

A lock acquired by calling the called method (if it is a synchronized method) and locks acquired by entering synchronized blocks within the called method are released.

Note

this does not apply to native locks or java.util.concurrent.locks locks.

Events, such as MethodExit, are generated as they would be in a normal return.

The called method must be a non-native Java programming language method. Forcing return on a thread with only one frame on the stack causes the thread to exit when resumed.

The value argument is the value that the method is to return. If the return type of the method is void, then value must be a VoidValue. Object values must be assignment compatible with the method return type (This implies that the method return type must be loaded through the enclosing class's class loader). Primitive values must be either assignment compatible with the method return type or must be convertible to the variable type without loss of information. See JLS section 5.2 for more information on assignment compatibility.

Not all target virtual machines support this operation. Use VirtualMachine#canForceEarlyReturn() to determine if the operation is supported.

Exceptions
InvalidTypeException:
if the value's type does not match the method's return type.
ClassNotLoadedException:
if the method's return type has not yet been loaded through the appropriate class loader.
IncompatibleThreadStateException:
if this thread is not suspended.
frameback to summary
public StackFrame frame(int index) throws IncompatibleThreadStateException

Implements com.sun.jdi.ThreadReference.frame.

Doc from com.sun.jdi.ThreadReference.frame.

Returns the StackFrame at the given index in the thread's current call stack. Index 0 retrieves the current frame; higher indices retrieve caller frames. The thread must be suspended (normally through an interruption to the VM) to get this information, and it is only valid until the thread is resumed again.

Exceptions
IncompatibleThreadStateException:
if the thread is not suspended in the target VM
frameCountback to summary
public int frameCount() throws IncompatibleThreadStateException

Implements com.sun.jdi.ThreadReference.frameCount.

Doc from com.sun.jdi.ThreadReference.frameCount.

Returns the number of stack frames in the thread's current call stack. The thread must be suspended (normally through an interruption to the VM) to get this information, and it is only valid until the thread is resumed again.

Exceptions
IncompatibleThreadStateException:
if the thread is not suspended in the target VM
framesback to summary
public List<StackFrame> frames() throws IncompatibleThreadStateException

Implements com.sun.jdi.ThreadReference.frames.

Doc from com.sun.jdi.ThreadReference.frames.

Returns a List containing each StackFrame in the thread's current call stack. The thread must be suspended (normally through an interruption to the VM) to get this information, and it is only valid until the thread is resumed again.

Exceptions
IncompatibleThreadStateException:
if the thread is not suspended in the target VM
framesback to summary
public List<StackFrame> frames(int start, int length) throws IncompatibleThreadStateException

Implements com.sun.jdi.ThreadReference.frames.

Doc from com.sun.jdi.ThreadReference.frames.

Returns a List containing a range of StackFrame mirrors from the thread's current call stack. The thread must be suspended (normally through an interruption to the VM) to get this information, and it is only valid until the thread is resumed again.

Exceptions
IncompatibleThreadStateException:
if the thread is not suspended in the target VM
interruptback to summary
public void interrupt()

Implements com.sun.jdi.ThreadReference.interrupt.

Doc from com.sun.jdi.ThreadReference.interrupt.

Interrupts this thread unless the thread has been suspended by the debugger.

isAtBreakpointback to summary
public boolean isAtBreakpoint()

Implements com.sun.jdi.ThreadReference.isAtBreakpoint.

Doc from com.sun.jdi.ThreadReference.isAtBreakpoint.

Determines whether the thread is suspended at a breakpoint.

isSubrangeback to summary
private boolean isSubrange(ThreadReferenceImpl.LocalCache snapshot, int start, int length)

Is the requested subrange within what has been retrieved? local is known to be non-null. Should only be called from a sync method.

isSuspendedback to summary
public boolean isSuspended()

Implements com.sun.jdi.ThreadReference.isSuspended.

Doc from com.sun.jdi.ThreadReference.isSuspended.

Determines whether the thread has been suspended by the the debugger.

isVirtualback to summary
public boolean isVirtual()

Overrides default com.sun.jdi.ThreadReference.isVirtual.

Doc from com.sun.jdi.ThreadReference.isVirtual.

Returns true if the thread is a virtual thread.

Annotations
@Override
jdwpStatusback to summary
private JDWP.ThreadReference.Status jdwpStatus()
nameback to summary
public String name()

Implements com.sun.jdi.ThreadReference.name.

Note that we only cache the name string while the entire VM is suspended because the name can change via Thread.setName arbitrarily while this thread is running.

newCacheback to summary
protected ObjectReferenceImpl.Cache newCache()

Overrides com.sun.tools.jdi.ObjectReferenceImpl.newCache.

ownedMonitorsback to summary
public List<ObjectReference> ownedMonitors() throws IncompatibleThreadStateException

Implements com.sun.jdi.ThreadReference.ownedMonitors.

Doc from com.sun.jdi.ThreadReference.ownedMonitors.

Returns a List containing an ObjectReference for each monitor owned by the thread. A monitor is owned by a thread if it has been entered (via the synchronized statement or entry into a synchronized method) and has not been relinquished through Object#wait.

Not all target virtual machines support this operation. Use VirtualMachine#canGetOwnedMonitorInfo() to determine if the operation is supported.

Exceptions
IncompatibleThreadStateException:
if the thread is not suspended in the target VM
ownedMonitorsAndFramesback to summary
public List<MonitorInfo> ownedMonitorsAndFrames() throws IncompatibleThreadStateException

Implements com.sun.jdi.ThreadReference.ownedMonitorsAndFrames.

Doc from com.sun.jdi.ThreadReference.ownedMonitorsAndFrames.

Returns a List containing a MonitorInfo object for each monitor owned by the thread. A monitor is owned by a thread if it has been entered (via the synchronized statement or entry into a synchronized method) and has not been relinquished through Object#wait.

Not all target virtual machines support this operation. Use VirtualMachine#canGetMonitorFrameInfo() to determine if the operation is supported.

Exceptions
IncompatibleThreadStateException:
if the thread is not suspended in the target VM
popFramesback to summary
public void popFrames(StackFrame frame) throws IncompatibleThreadStateException

Implements com.sun.jdi.ThreadReference.popFrames.

Doc from com.sun.jdi.ThreadReference.popFrames.

Pop stack frames.

All frames up to and including the frame are popped off the stack. The frame previous to the parameter frame will become the current frame.

After this operation, this thread will be suspended at the invoke instruction of the target method that created frame. The frame's method can be reentered with a step into the instruction.

The operand stack is restored, however, any changes to the arguments that occurred in the called method, remain. For example, if the method foo:

   void foo(int x) {
       System.out.println("Foo: " + x);
       x = 4;
       System.out.println("pop here");
   }
was called with foo(7) and foo is popped at the second println and resumed, it will print: Foo: 4.

Locks acquired by a popped frame are released when it is popped. This applies to synchronized methods that are popped, and to any synchronized blocks within them.

Finally blocks are not executed.

No aspect of state, other than this thread's execution point and locks, is affected by this call. Specifically, the values of fields are unchanged, as are external resources such as I/O streams. Additionally, the target program might be placed in a state that is impossible with normal program flow; for example, order of lock acquisition might be perturbed. Thus the target program may proceed differently than the user would expect.

This thread must be suspended.

All StackFrame objects for this thread are invalidated.

This method may be used to pop frames of a virtual thread when it is suspended at an event. An implementation may support popping the frames of a suspended virtual thread in other cases.

No events are generated by this method.

None of the frames through and including the frame for the caller of frame may be native.

Not all target virtual machines support this operation. Use VirtualMachine.canPopFrames() to determine if the operation is supported.

Exceptions
IncompatibleThreadStateException:
if this thread is not suspended.
privateFramesback to summary
private synchronized List<StackFrame> privateFrames(int start, int length) throws IncompatibleThreadStateException

Private version of frames() allows "-1" to specify all remaining frames.

processThreadActionback to summary
private void processThreadAction(ThreadAction action)

Propagate the thread state change information to registered listeners. Must be entered while synchronized on vm.state()

resetLocalCacheback to summary
private void resetLocalCache()
resumeback to summary
public void resume()

Implements com.sun.jdi.ThreadReference.resume.

Doc from com.sun.jdi.ThreadReference.resume.

Resumes this thread. If this thread was not previously suspended through suspend or through VirtualMachine#suspend, or because of a SUSPEND_ALL or SUSPEND_EVENT_THREAD event, then invoking this method has no effect. Otherwise, the count of pending suspends on this thread is decremented. If it is decremented to 0, the thread will continue to execute.

Note

the normal way to resume from an event related suspension is via EventSet#resume.

sendResumingCommandback to summary
pack-priv PacketStream sendResumingCommand(CommandSender sender)
statusback to summary
public int status()

Implements com.sun.jdi.ThreadReference.status.

Doc from com.sun.jdi.ThreadReference.status.

Returns the thread's status. If the thread is not suspended the thread's current status is returned. If the thread is suspended, the thread's status before the suspension is returned (or THREAD_STATUS_UNKNOWN if this information is not available. isSuspended can be used to determine if the thread has been suspended.

stopback to summary
public void stop(ObjectReference throwable) throws InvalidTypeException

Implements com.sun.jdi.ThreadReference.stop.

Doc from com.sun.jdi.ThreadReference.stop.

Stops this thread with an asynchronous exception. A debugger thread in the target VM will stop this thread with the given java.lang.Throwable object.

This method may be used to send an asynchronous exception to a virtual thread when it is suspended at an event. An implementation may support sending an asynchronous exception to a suspended virtual thread in other cases.

Exceptions
InvalidTypeException:
if throwable is not an instance of java.lang.Throwable in the target VM
suspendback to summary
public void suspend()

Implements com.sun.jdi.ThreadReference.suspend.

Doc from com.sun.jdi.ThreadReference.suspend.

Suspends this thread. The thread can be resumed through resume or resumed with other threads through VirtualMachine#resume.

Suspends of both the virtual machine and individual threads are counted. Before a thread will run again, it must be resumed (through resume or VirtualMachine#resume) the same number of times it has been suspended.

Suspending single threads with this method is inherently deadlock-prone. If the suspended thread holds a monitor needed by another running thread, deadlock is possible in the target VM (at least until the suspended thread is resumed again).

The suspended thread is guaranteed to remain suspended until resumed through one of the JDI resume methods mentioned above.

suspendCountback to summary
public int suspendCount()

Implements com.sun.jdi.ThreadReference.suspendCount.

Doc from com.sun.jdi.ThreadReference.suspendCount.

Returns the number of pending suspends for this thread. See suspend for an explanation of counted suspends.

threadGroupback to summary
public ThreadGroupReference threadGroup()

Implements com.sun.jdi.ThreadReference.threadGroup.

Doc from com.sun.jdi.ThreadReference.threadGroup.

Returns this thread's thread group.

toStringback to summary
public String toString()

Overrides com.sun.tools.jdi.ObjectReferenceImpl.toString.

Implements com.sun.jdi.Mirror.toString.

Doc from com.sun.jdi.Mirror.toString.

Returns a String describing this mirror

typeValueKeyback to summary
pack-priv byte typeValueKey()

Overrides com.sun.tools.jdi.ObjectReferenceImpl.typeValueKey.

vmNotSuspendedback to summary
public boolean vmNotSuspended(VMAction action)

Overrides com.sun.tools.jdi.ObjectReferenceImpl.vmNotSuspended.

Implements com.sun.tools.jdi.VMListener.vmNotSuspended.

com.sun.tools.jdi back to summary

private Class ThreadReferenceImpl.Cache

extends Cache
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv String
Inherited from com.sun.tools.jdi.ObjectReferenceImpl.Cache:
monitorInfo

Constructor Summary

AccessConstructor and Description
private

Field Detail

nameback to summary
pack-priv String name

Constructor Detail

Cacheback to summary
private Cache()
com.sun.tools.jdi back to summary

private Class ThreadReferenceImpl.LocalCache

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv ObjectReference
pack-priv int
pack-priv List<StackFrame>
pack-priv int
pack-priv int
pack-priv List<ObjectReference>
pack-priv List<MonitorInfo>
pack-priv JDWP.ThreadReference.Status
pack-priv boolean

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

contendedMonitorback to summary
pack-priv ObjectReference contendedMonitor
frameCountback to summary
pack-priv int frameCount
framesback to summary
pack-priv List<StackFrame> frames
framesLengthback to summary
pack-priv int framesLength
framesStartback to summary
pack-priv int framesStart
ownedMonitorsback to summary
pack-priv List<ObjectReference> ownedMonitors
ownedMonitorsInfoback to summary
pack-priv List<MonitorInfo> ownedMonitorsInfo
statusback to summary
pack-priv JDWP.ThreadReference.Status status
triedCurrentContendedback to summary
pack-priv boolean triedCurrentContended

Constructor Detail

LocalCacheback to summary
private LocalCache()