APIdia Launch Partner
Top Description Fields Methods
com.sun.jdi

public Interface ThreadReference

extends ObjectReference
Known Direct Implementers
com.sun.tools.jdi.ThreadReferenceImpl
Imports
java.util.List, com.sun.jdi.event.EventSet

A thread object from the target VM. A ThreadReference is an ObjectReference with additional access to thread-specific information from the target VM.
Authors
Robert Field, Gordon Hirsch, James McIlree
Since
1.3

Field Summary

Modifier and TypeField and Description
public static final int
THREAD_STATUS_MONITOR

Thread is waiting on a java monitor

public static final int
THREAD_STATUS_NOT_STARTED

Thread has not yet been started

public static final int
THREAD_STATUS_RUNNING

Thread is runnable

public static final int
public static final int
THREAD_STATUS_UNKNOWN

Thread status is unknown

public static final int
public static final int
THREAD_STATUS_ZOMBIE

Thread has completed execution

Inherited from com.sun.jdi.ObjectReference:
INVOKE_NONVIRTUALINVOKE_SINGLE_THREADED

Method Summary

Modifier and TypeMethod and Description
public ObjectReference

Returns:

the ObjectReference corresponding to the contended monitor, or null if it is not waiting for a monitor.
currentContendedMonitor
()

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

public void
forceEarlyReturn(Value
the value the method is to return.
value
)

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

public StackFrame

Returns:

the requested StackFrame
frame
(int
the desired frame
index
)

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

public int

Returns:

an integer frame count
frameCount
()

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

public List<StackFrame>

Returns:

a List of StackFrame with the current frame first followed by each caller's frame.
frames
()

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

public List<StackFrame>

Returns:

a List of StackFrame with the current frame first followed by each caller's frame.
frames
(int
the index of the first frame to retrieve. Index 0 represents the current frame.
start
,
int
the number of frames to retrieve
length
)

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

public void
interrupt()

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

public boolean

Returns:

true if the thread is currently stopped at a breakpoint; false otherwise.
isAtBreakpoint
()

Determines whether the thread is suspended at a breakpoint.

public boolean

Returns:

true if the thread is currently suspended; false otherwise.
isSuspended
()

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

public default boolean

Returns:

true if the thread is a virtual thread
isVirtual
()

Returns true if the thread is a virtual thread.

public String

Returns:

the string containing the thread name.
name
()

Returns the name of this thread.

public List<ObjectReference>

Returns:

a List of ObjectReference objects. The list has zero length if no monitors are owned by this thread.
ownedMonitors
()

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

public List<MonitorInfo>

Returns:

a List of MonitorInfo objects. The list has zero length if no monitors are owned by this thread.
ownedMonitorsAndFrames
()

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

public void
popFrames(StackFrame
Stack frame to pop. frame is on this thread's call stack.
frame
)

Pop stack frames.

public void
resume()

Resumes this thread.

public int
public void
stop(ObjectReference
the asynchronous exception to throw
throwable
)

Stops this thread with an asynchronous exception.

public void
suspend()

Suspends this thread.

public int

Returns:

pending suspend count as an integer
suspendCount
()

Returns the number of pending suspends for this thread.

public ThreadGroupReference

Returns:

a ThreadGroupReference that mirrors this thread's thread group in the target VM.
threadGroup
()

Returns this thread's thread group.

Inherited from com.sun.jdi.ObjectReference:
disableCollectionenableCollectionentryCountequalsgetValuegetValueshashCodeinvokeMethodisCollectedowningThreadreferenceTypereferringObjectssetValueuniqueIDwaitingThreads

Field Detail

THREAD_STATUS_MONITORback to summary
public static final int THREAD_STATUS_MONITOR

Thread is waiting on a java monitor

THREAD_STATUS_NOT_STARTEDback to summary
public static final int THREAD_STATUS_NOT_STARTED

Thread has not yet been started

THREAD_STATUS_RUNNINGback to summary
public static final int THREAD_STATUS_RUNNING

Thread is runnable

THREAD_STATUS_SLEEPINGback to summary
public static final int THREAD_STATUS_SLEEPING

Thread is sleeping - Thread#sleep(long).

THREAD_STATUS_UNKNOWNback to summary
public static final int THREAD_STATUS_UNKNOWN

Thread status is unknown

THREAD_STATUS_WAITback to summary
public static final int THREAD_STATUS_WAIT

Thread is waiting - Object#wait() or java.util.concurrent.locks.LockSupport#park(). A virtual thread that is sleeping in Thread#sleep(long) may have this thread status instead of THREAD_STATUS_SLEEPING.

THREAD_STATUS_ZOMBIEback to summary
public static final int THREAD_STATUS_ZOMBIE

Thread has completed execution

Method Detail

currentContendedMonitorback to summary
public ObjectReference currentContendedMonitor() throws IncompatibleThreadStateException

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.

Returns:ObjectReference

the ObjectReference corresponding to the contended monitor, or null if it is not waiting for a monitor.

Exceptions
IncompatibleThreadStateException:
if the thread is not suspended in the target VM
UnsupportedOperationException:
if the target virtual machine does not support this operation.
forceEarlyReturnback to summary
public void forceEarlyReturn(Value value) throws InvalidTypeException, ClassNotLoadedException, IncompatibleThreadStateException

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.

Parameters
value:Value

the value the method is to return.

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.
UnsupportedOperationException:
if the target virtual machine does not support this operation - see canForceEarlyReturn()
OpaqueFrameException:
if the target VM is unable to force the method to return (e.g. a virtual thread is suspended, but not at an event).
NativeMethodException:
if the frame to be returned from is that of a native method.
InvalidStackFrameException:
if there are no frames.
VMCannotBeModifiedException:
if the VirtualMachine is read-only.
Since
1.6
See Also
VirtualMachine#canBeModified()
frameback to summary
public StackFrame frame(int index) throws IncompatibleThreadStateException

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.

Parameters
index:int

the desired frame

Returns:StackFrame

the requested StackFrame

Exceptions
IncompatibleThreadStateException:
if the thread is not suspended in the target VM
IndexOutOfBoundsException:
if the index is greater than or equal to frameCount or is negative.
frameCountback to summary
public int frameCount() throws IncompatibleThreadStateException

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.

Returns:int

an integer frame count

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

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.

Returns:List<StackFrame>

a List of StackFrame with the current frame first followed by each caller's frame.

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

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.

Parameters
start:int

the index of the first frame to retrieve. Index 0 represents the current frame.

length:int

the number of frames to retrieve

Returns:List<StackFrame>

a List of StackFrame with the current frame first followed by each caller's frame.

Exceptions
IncompatibleThreadStateException:
if the thread is not suspended in the target VM
IndexOutOfBoundsException:
if the specified range is not within the range of stack frame indices. That is, the exception is thrown if any of the following are true:
    start < 0
   start >= frameCount
   length < 0
   (start+length) > frameCount
interruptback to summary
public void interrupt()

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

Exceptions
VMCannotBeModifiedException:
if the VirtualMachine is read-only
See Also
java.lang.Thread#interrupt(), VirtualMachine#canBeModified()
isAtBreakpointback to summary
public boolean isAtBreakpoint()

Determines whether the thread is suspended at a breakpoint.

Returns:boolean

true if the thread is currently stopped at a breakpoint; false otherwise.

isSuspendedback to summary
public boolean isSuspended()

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

Returns:boolean

true if the thread is currently suspended; false otherwise.

isVirtualback to summary
public default boolean isVirtual()

Returns true if the thread is a virtual thread.

Implementation Specification

The default implementation throws UnsupportedOperationException.

Returns:boolean

true if the thread is a virtual thread

Since
21
nameback to summary
public String name()

Returns the name of this thread.

Returns:String

the string containing the thread name.

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

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.

Returns:List<ObjectReference>

a List of ObjectReference objects. The list has zero length if no monitors are owned by this thread.

Exceptions
IncompatibleThreadStateException:
if the thread is not suspended in the target VM
UnsupportedOperationException:
if the target virtual machine does not support this operation.
ownedMonitorsAndFramesback to summary
public List<MonitorInfo> ownedMonitorsAndFrames() throws IncompatibleThreadStateException

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.

Returns:List<MonitorInfo>

a List of MonitorInfo objects. The list has zero length if no monitors are owned by this thread.

Exceptions
IncompatibleThreadStateException:
if the thread is not suspended in the target VM
UnsupportedOperationException:
if the target virtual machine does not support this operation.
Since
1.6
popFramesback to summary
public void popFrames(StackFrame frame) throws IncompatibleThreadStateException

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.

Parameters
frame:StackFrame

Stack frame to pop. frame is on this thread's call stack.

Exceptions
IncompatibleThreadStateException:
if this thread is not suspended.
UnsupportedOperationException:
if the target virtual machine does not support this operation - see VirtualMachine.canPopFrames().
IllegalArgumentException:
if frame is not on this thread's call stack.
OpaqueFrameException:
if the target VM is unable to pop this frame (e.g. a virtual thread is suspended, but not at an event).
NativeMethodException:
if one of the frames that would be popped is that of a native method or if the frame previous to frame is native.
InvalidStackFrameException:
if frame has become invalid. Once this thread is resumed, the stack frame is no longer valid. This exception is also thrown if there are no more frames.
VMCannotBeModifiedException:
if the VirtualMachine is read-only.
Since
1.4
See Also
VirtualMachine#canBeModified()
resumeback to summary
public void 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.

Exceptions
VMCannotBeModifiedException:
if the VirtualMachine is read-only
See Also
VirtualMachine#canBeModified()
statusback to summary
public int 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.

Returns:int

one of THREAD_STATUS_UNKNOWN, THREAD_STATUS_ZOMBIE, THREAD_STATUS_RUNNING, THREAD_STATUS_SLEEPING, THREAD_STATUS_MONITOR, THREAD_STATUS_WAIT, THREAD_STATUS_NOT_STARTED,

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

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.

Parameters
throwable:ObjectReference

the asynchronous exception to throw

Annotations
@SuppressWarnings:javadoc
Exceptions
InvalidTypeException:
if throwable is not an instance of java.lang.Throwable in the target VM
IllegalThreadStateException:
if the thread has terminated, or if the thread is a virtual thread and was not suspended
OpaqueFrameException:
if the thread is a suspended virtual thread and the implementation was unable to throw an asynchronous exception from the thread's current frame
VMCannotBeModifiedException:
if the VirtualMachine is read-only
See Also
VirtualMachine#canBeModified()
suspendback to summary
public void 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.

Annotations
@SuppressWarnings:javadoc
Exceptions
VMCannotBeModifiedException:
if the VirtualMachine is read-only
See Also
VirtualMachine#canBeModified()
suspendCountback to summary
public int suspendCount()

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

Returns:int

pending suspend count as an integer

threadGroupback to summary
public ThreadGroupReference threadGroup()

Returns this thread's thread group.

Returns:ThreadGroupReference

a ThreadGroupReference that mirrors this thread's thread group in the target VM.