public class

ThreadReferenceImpl

extends ObjectReferenceImpl
implements ThreadReference EventListener
java.lang.Object
   ↳ com.sun.tools.jdi.ObjectReferenceImpl
     ↳ com.sun.tools.jdi.ThreadReferenceImpl

Summary

[Expand]
Inherited Constants
From interface com.sun.jdi.ObjectReference
From interface com.sun.jdi.ThreadReference
[Expand]
Inherited Fields
From class com.sun.tools.jdi.ObjectReferenceImpl
Public Methods
ObjectReference currentContendedMonitor()
Returns an ObjectReference for the monitor, if any, for which this thread is currently waiting.
void forceEarlyReturn(Value returnValue)
Force a method to return before it reaches a return statement.
StackFrame frame(int index)
Returns the StackFrame at the given index in the thread's current call stack.
int frameCount()
Returns the number of stack frames in the thread's current call stack.
List<StackFrame> frames()
Returns a List containing each StackFrame in the thread's current call stack.
List<StackFrame> frames(int start, int length)
Returns a List containing a range of StackFrame mirrors from the thread's current call stack.
void interrupt()
Interrupts this thread unless the thread has been suspended by the debugger.
boolean isAtBreakpoint()
Determines whether the thread is suspended at a breakpoint.
boolean isSuspended()
Determines whether the thread has been suspended by the the debugger.
String 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.
List<ObjectReference> ownedMonitors()
Returns a List containing an ObjectReference for each monitor owned by the thread.
List<MonitorInfo> ownedMonitorsAndFrames()
Returns a List containing a MonitorInfo object for each monitor owned by the thread.
void popFrames(StackFrame frame)
Pop stack frames.
void resume()
Resumes this thread.
int status()
Returns the thread's status.
void stop(ObjectReference throwable)
Stops this thread with an asynchronous exception.
void suspend()
Suspends this thread.
int suspendCount()
Returns the number of pending suspends for this thread.
ThreadGroupReference threadGroup()
Returns this thread's thread group.
String toString()
Returns a string representation of the object.
boolean vmNotSuspended(VMAction action)
abstract boolean vmSuspended(VMAction action)
Protected Methods
String description()
ObjectReferenceImpl.Cache newCache()
[Expand]
Inherited Methods
From class com.sun.tools.jdi.ObjectReferenceImpl
From class java.lang.Object
From interface com.sun.jdi.Mirror
From interface com.sun.jdi.ObjectReference
From interface com.sun.jdi.ThreadReference
From interface com.sun.jdi.Value

Public Methods

public ObjectReference 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 wait(). The status() method can be used to differentiate between the first two cases and the third.

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

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

public void forceEarlyReturn (Value returnValue)

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.

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 canForceEarlyReturn() to determine if the operation is supported.

Parameters
returnValue the value the method is to return.

public StackFrame frame (int index)

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 the desired frame
Returns

public int 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.

Returns
  • an integer frame count

public List<StackFrame> 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.

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

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

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 the index of the first frame to retrieve. Index 0 represents the current frame.
length the number of frames to retrieve
Returns
  • a List of StackFrame with the current frame first followed by each caller's frame.

public void interrupt ()

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

public boolean isAtBreakpoint ()

Determines whether the thread is suspended at a breakpoint.

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

public boolean isSuspended ()

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

Returns
  • true if the thread is currently suspended; false otherwise.

public String 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.

Returns
  • the string containing the thread name.

public List<ObjectReference> 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 wait().

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

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

public List<MonitorInfo> 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 wait().

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

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

public void popFrames (StackFrame frame)

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.

The specified thread must be suspended.

All StackFrame objects for this thread are invalidated.

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 Stack frame to pop. frame is on this thread's call stack.

public void resume ()

Resumes this thread. If this thread was not previously suspended through suspend() or through 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 resume().

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.

public void stop (ObjectReference throwable)

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

Parameters
throwable the asynchronous exception to throw.

public void suspend ()

Suspends this thread. The thread can be resumed through resume() or resumed with other threads through resume().

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

Suspending single threads with this method has the same dangers as suspend(). 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; the application in the target VM cannot resume the suspended thread through resume().

public int suspendCount ()

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

Returns
  • pending suspend count as an integer

public ThreadGroupReference threadGroup ()

Returns this thread's thread group.

Returns

public String toString ()

Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

 getClass().getName() + '@' + Integer.toHexString(hashCode())
 

Returns
  • a string representation of the object.

public boolean vmNotSuspended (VMAction action)

public abstract boolean vmSuspended (VMAction action)

Protected Methods

protected String description ()

protected ObjectReferenceImpl.Cache newCache ()