Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| " 2013 FRC Java API "
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.sun.squawk
Class VMThread

    java.lang.Object
      com.sun.squawk.VMThread

All Implemented Interfaces:
  GlobalStaticFields

    public final class VMThread

extends Object
implements GlobalStaticFields

The Squawk implementation of threads.

See Also:
  `Monitor`

Field Summary
`static int` | `MAX_PRIORITY` The maximum priority that a user thread can have.
`static int` | `MAX_SYS_PRIORITY` The maximum priority that a system thread can have.
`static int` | `MIN_PRIORITY` The minimum priority that a thread can have.
`static int` | `NORM_PRIORITY` The default priority that is assigned to a thread.

Constructor Summary
`VMThread(Thread apiThread, String name)` Allocates a new `VMThread` object to support a given API Thread instance.

Method Summary
`static int` | `activeCount()` Returns the current number of active threads in the VM.
`static VMThread` | `asVMThread(Thread thread)`
`void` | `clearBreakpoint()` Clears the object used to report a breakpoint hit.
`void` | `clearStep()` Removes the object (if any) that is keeping this thread in single stepping mode.
`static VMThread` | `currentThread()` Returns a reference to the currently executing thread object.
`Thread` | `getAPIThread()`
`static int` | `getContendedMontorEnterCount()` Return the number of times that a thread was blocked trying to synchronize on an object.
`int` | `getDebuggerSuspendCount()` Gets the value of the debugger suspension counter for this thread.
`int` | `getErrno()` Return the system errno value from the last time a native function was called.
`ExecutionPoint` | `getEventExecutionPoint()` Gets the method and frame context of this thread at which a debugger event occurred.
`int` | `getInternalStatus()` Gets the combined values for `state` and `queue`.
`Isolate` | `getIsolate()` Gets the isolate of the thread.
`static int` | `getMaxStackSize()` Return size of the largest stack ever allocated, in words.
`static int` | `getMonitorsAllocatedCount()` Return the number of monitors allocated.
`String` | `getName()` Gets the name of this thread.
`int` | `getPriority()` Returns this thread's priority.
`static Thread[]` | `getRunnableThreads()`
`static int` | `getStacksAllocatedCount()` Return the number of stacks allocated.
`Debugger.SingleStep` | `getStep()`
`static SystemEvents` | `getSystemEvents()` Handler for OS events...
`int` | `getThreadNumber()` Gets the number of this thread which is only guaranteed to be unique within this thread's isolate.
`static int` | `getThreadsAllocatedCount()` Return the number of Thread objects allocated during the lifetime of this JVM.
`static int` | `getThreadSwitchCount()` Return count of thread context switching.
`static long` | `getTotalWaitTime()`
`void` | `interrupt()` Interrupts this thread.
`boolean` | `isAlive()` Tests if this thread is alive.
`boolean` | `isDaemon()` Gets the daemon state of the thread.
`boolean` | `isServiceThread()` Determines if this thread is the service thread.
`void` | `join()` Waits for this thread to die.
`static void` | `monitorNotify(Object object, boolean notifyAll)` Notify an object.
`static void` | `monitorWait(Object object, long delta)` Wait for an object to be notified.
`void` | `printStackTrace(PrintStream stream)` Print a stack trace for this thread.
`void` | `printState(PrintStream out)` Print thread state one one line.
`int` | `resumeForDebugger(boolean forDetach)` Decreases the suspension count of this thread.
`void` | `setDaemon(boolean value)` Sets the daemon state of the thread.
`void` | `setName(String name)` Sets the name of this thread.
`void` | `setPriority(int newPriority)` Changes the priority of this thread.
`void` | `setStep(Debugger.SingleStep step)` Sets the object that will put this thread into single stepping mode the next time it is scheduled to run.
`void` | `setSystemPriority(int newPriority)` Changes the priority of this thread.
`static void` | `signalOSEvent(int event)` Restart a thread blocked on an event.
`static void` | `sleep(long millis)` Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds.
`void` | `start()` Causes this thread to begin execution; the Java Virtual Machine calls the `run` method of this thread.
`int` | `suspendForDebugger()` Increases the suspension count of this thread.
`String` | `toString()` Returns a string representation of this thread, including a unique number that identifies the thread and the thread's priority.
`static void` | `waitForOSEvent(int event)` Block a thread waiting for an event.
`static void` | `yield()` Causes the currently executing thread object to temporarily pause and allow other threads to execute.

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### MIN_PRIORITY

    public static final int MIN_PRIORITY

  The minimum priority that a thread can have.

  See Also:
    Constant Field Values

### NORM_PRIORITY

    public static final int NORM_PRIORITY

  The default priority that is assigned to a thread.

  See Also:
    Constant Field Values

### MAX_PRIORITY

    public static final int MAX_PRIORITY

  The maximum priority that a user thread can have.

  See Also:
    Constant Field Values

### MAX_SYS_PRIORITY

    public static final int MAX_SYS_PRIORITY

  The maximum priority that a system thread can have.

  See Also:
    Constant Field Values

Constructor Detail

### VMThread

    public VMThread(Thread apiThread,
                    String name)

  Allocates a new `VMThread` object to support a given API Thread instance.

  This constructor should only be called from a java.lang.Thread constructor.

  Parameters:
    `apiThread` - the API thread instance supported by this VM thread
    `name` - the thread name, or null. If null, thread name generated from threadNumber.

Method Detail

### getThreadsAllocatedCount

    public static int getThreadsAllocatedCount()

  Return the number of Thread objects allocated during the lifetime of this JVM.

  Returns:
    threads allocated

### getContendedMontorEnterCount

    public static int getContendedMontorEnterCount()

  Return the number of times that a thread was blocked trying to synchronize on an object. Note that this counts the initial contention. A thread may be released to aquire the lock, but another thread (potentially higher priority) runs first, and actually acquires the lock. The first thread will then have to wait again.

  Returns:
    monitor contention count

### getMonitorsAllocatedCount

    public static int getMonitorsAllocatedCount()

  Return the number of monitors allocated. Often, uncontended locking is handled by the interpreter in the pendingMonitors cache. But if the cache is full, or there is contention, or Object.wait() is used, or a thread is switched out while holding a virtual monitor, then a real monitor has to be allocated for an object. It is possible for the monitor for an object to come and go, so there is the possibility of "monitor object thrashing".

  Returns:
    number of monitors allocated

### getThreadSwitchCount

    public static int getThreadSwitchCount()

  Return count of thread context switching. This does not include system-level switches that occur for GC, exception throwing, etc.

  Returns:
    user-level thread switches

### currentThread

    public static VMThread currentThread()

  Returns a reference to the currently executing thread object.

  Returns:
    the currently executing thread

### setDaemon

    public void setDaemon(boolean value)

  Sets the daemon state of the thread. If this thread is alive, an IllegalThreadStateException is thrown.

  Parameters:
    `value` - if true, set thread as a daemon

### isDaemon

    public boolean isDaemon()

  Gets the daemon state of the thread.

  Returns:
    true if thread is a daemon thread

### sleep

    public static void sleep(long millis)
                      throws InterruptedException

  Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds. The thread does not lose ownership of any monitors.

  Parameters:
    `millis` - the length of time to sleep in milliseconds.
  Throws:
    `InterruptedException` - if another thread has interrupted the current thread. The interrupted status of the current thread is cleared when this exception is thrown.
  See Also:
    `Object.notify()`

### yield

    public static void yield()

  Causes the currently executing thread object to temporarily pause and allow other threads to execute.

### start

    public void start()

  Causes this thread to begin execution; the Java Virtual Machine calls the `run` method of this thread.

  The result is that two threads are running concurrently: the current thread (which returns from the call to the `start` method) and the other thread (which executes its `run` method).

  Throws:
    `IllegalThreadStateException` - if the thread was already started.
  See Also:
    `Thread.run()`

### isAlive

    public final boolean isAlive()

  Tests if this thread is alive. A thread is alive if it has been started and has not yet died.

  Returns:
    `true` if this thread is alive; `false` otherwise.

### setPriority

    public final void setPriority(int newPriority)

  Changes the priority of this thread.

  Parameters:
    `newPriority` - priority to set this thread to
  Throws:
    `IllegalArgumentException` - If the priority is not in the range `MIN_PRIORITY` to `MAX_PRIORITY`.
  See Also:
    `getPriority()`, `Thread.getPriority()`, `Thread.MAX_PRIORITY`, `Thread.MIN_PRIORITY`

### setSystemPriority

    public final void setSystemPriority(int newPriority)

  Changes the priority of this thread. Allows setting priority to "system" levels.

  Parameters:
    `newPriority` - priority to set this thread to
  Throws:
    `IllegalArgumentException` - If the priority is not in the range `MIN_PRIORITY` to `MAX_SYS_PRIORITY`.
  See Also:
    `getPriority()`, `Thread.getPriority()`, `Thread.MAX_PRIORITY`, `Thread.MIN_PRIORITY`

### getPriority

    public final int getPriority()

  Returns this thread's priority.

  Returns:
    this thread's name.
  See Also:
    `setPriority(int)`, `Thread.setPriority(int)`

### activeCount

    public static int activeCount()

  Returns the current number of active threads in the VM.

  Returns:
    the current number of active threads

### join

    public final void join()
                    throws InterruptedException

  Waits for this thread to die.

  Throws:
    `InterruptedException` - if another thread has interrupted the current thread. The interrupted status of the current thread is cleared when this exception is thrown.

### getName

    public final String getName()

  Gets the name of this thread. If `setName(java.lang.String)` has never been called for this thread, the return value will be of the from "Thread-" where 'n' is a unique numeric identifier for this thread.

  Returns:
    thread name in standard format

### setName

    public final void setName(String name)

  Sets the name of this thread.

  Parameters:
    `name` - the new name for this thread

### toString

    public String toString()

  Returns a string representation of this thread, including a unique number that identifies the thread and the thread's priority.

  Overrides:
    `toString` in class `Object`
  Returns:
    a string representation of this thread.

### getSystemEvents

    public static SystemEvents getSystemEvents()

  Handler for OS events...

### getDebuggerSuspendCount

    public final int getDebuggerSuspendCount()

  Gets the value of the debugger suspension counter for this thread.

  Returns:
    the suspension count for this thread

### suspendForDebugger

    public final int suspendForDebugger()

  Increases the suspension count of this thread.

  Returns:
    the new suspension count for this thread

### resumeForDebugger

    public final int resumeForDebugger(boolean forDetach)

  Decreases the suspension count of this thread.

  Parameters:
    `forDetach` - if true, the count is set to 0
  Returns:
    the new suspension count for this thread

### getEventExecutionPoint

    public ExecutionPoint getEventExecutionPoint()

  Gets the method and frame context of this thread at which a debugger event occurred.

  Returns:
    null if this thread is not currently reporting an event to the debugger subsystem

### getInternalStatus

    public final int getInternalStatus()

  Gets the combined values for `state` and `queue`.

  Returns:
    the queue in the least significant byte, and the state in the next least significant byte.

### getStep

    public final Debugger.SingleStep getStep()

  Returns:
    Returns the step info object.

### setStep

    public final void setStep(Debugger.SingleStep step)

  Sets the object that will put this thread into single stepping mode the next time it is scheduled to run.

  Parameters:
    `step` - the details of the requested step

### clearStep

    public final void clearStep()

  Removes the object (if any) that is keeping this thread in single stepping mode.

### clearBreakpoint

    public void clearBreakpoint()

  Clears the object used to report a breakpoint hit.

### getIsolate

    public Isolate getIsolate()

  Gets the isolate of the thread.

  Returns:
    the isolate

### getAPIThread

    public Thread getAPIThread()

### asVMThread

    public static VMThread asVMThread(Thread thread)

### isServiceThread

    public boolean isServiceThread()

  Determines if this thread is the service thread.

### getThreadNumber

    public final int getThreadNumber()

  Gets the number of this thread which is only guaranteed to be unique within this thread's isolate.

  Returns:
    an integer identifier for this thread

### getStacksAllocatedCount

    public static int getStacksAllocatedCount()

  Return the number of stacks allocated. Stacks are allocated for each thread, and as more frames are needed, new stacks are created to replace the original stacks (typically at 2x the size of the original stack). The default stack size is about 160 words.

  Returns:
    total number of stacks ever allocated

### getMaxStackSize

    public static int getMaxStackSize()

  Return size of the largest stack ever allocated, in words.

  Returns:
    largest stack size ever allocated

### getTotalWaitTime

    public static long getTotalWaitTime()

### printState

    public void printState(PrintStream out)

  Print thread state one one line. Will print on the stream `out` unless an error occurs while printing on that stream, such as a null stream, or IO error on the stream. If a printing error occurs, this falls back on printing via VM.print(), etc.

  Parameters:
    `out` - the stream to print on.

### printStackTrace

    public void printStackTrace(PrintStream stream)

  Print a stack trace for this thread.

  Will print on the stream `out` unless an error occurs while printing on that stream, such as a null stream, or IO error on the stream. If a printing error occurs, this falls back on printing via VM.print(), etc.

  Parameters:
    `stream` -

### waitForOSEvent

    public static void waitForOSEvent(int event)

  Block a thread waiting for an event.

  Parameters:
    `event` - the event number to wait for

### signalOSEvent

    public static void signalOSEvent(int event)

  Restart a thread blocked on an event.

  Parameters:
    `event` - the event number to unblock

### getErrno

    public int getErrno()

  Return the system errno value from the last time a native function was called.

  Returns:
    zero if no error

### monitorWait

    public static void monitorWait(Object object,
                                   long delta)
                            throws InterruptedException

  Wait for an object to be notified.

  Parameters:
    `object` - the object to wait on
    `delta` - the timeout period
  Throws:
    `InterruptedException` - if another thread has interrupted the current thread. The interrupted status of the current thread is cleared when this exception is thrown.

### monitorNotify

    public static void monitorNotify(Object object,
                                     boolean notifyAll)

  Notify an object.

  Parameters:
    `object` - the object be notified
    `notifyAll` - flag to notify all waiting threads

### interrupt

    public void interrupt()

  Interrupts this thread.

  This method does nothing if the current thread is interrupting itself.

  If this thread is blocked in an invocation of the `Object.wait()`, `Object.wait(long)`, or `Object.wait(long, int)` methods of the class, or of the `Thread.join()`, `Thread#join(long)`, `Thread#join(long, int)`, `Thread.sleep(long)`, or `Thread#sleep(long, int)` methods of this class, then its interrupt status will be cleared and it will receive an `InterruptedException`.

  If none of the previous conditions hold then this thread's interrupt status will be set.

### getRunnableThreads

    public static Thread[] getRunnableThreads()

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| " 2013 FRC Java API "
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

"
For updated information see the Java FRC site
"