org.jikesrvm.scheduler.greenthreads
Class GreenThread

java.lang.Object
  extended by org.jikesrvm.scheduler.RVMThread
      extended by org.jikesrvm.scheduler.greenthreads.GreenThread
Direct Known Subclasses:
CollectorThread, CompilationThread, ConcurrentCollectorThread, IdleThread, Organizer, OSROrganizerThread, Scheduler.ThreadModel

public class GreenThread
extends RVMThread

A green thread's Java execution context


Nested Class Summary
 
Nested classes/interfaces inherited from class org.jikesrvm.scheduler.RVMThread
RVMThread.State
 
Field Summary
 int chosenProcessorId
          ID of processor to run this thread (cycles for load balance)
private  GreenThread next
          This thread's successor on a queue.
private  boolean osrParkingPermit
          Parking permit for OSR.
private static ProcessorLock osrParkLock
          Lock used for handling parking and unparking for OSR.
 GreenProcessor processorAffinity
          Virtual processor that this thread wants to run on (null --> any processor is ok).
private  int suspendPending
          Should this thread be suspended the next time it is considered for scheduling?
private static Offset suspendPendingOffset
          Offset of the lock field controlling the suspending of a thread
 ThreadProxy threadProxy
          A thread proxy.
(package private)  ThreadEventWaitData waitData
          Object specifying the event the thread is waiting for.
 
Fields inherited from class org.jikesrvm.scheduler.RVMThread
BACKEDGE, beingDispatched, bridgeInstructions, cachedFreeLock, causeOfThreadDeath, contextRegisters, daemon, EPILOGUE, feedlet, fooFPOffset, interrupted, isWaitingForOsr, jniEnv, NATIVE_EPILOGUE, NATIVE_PROLOGUE, onStackReplacementEvent, OSROPT, PROLOGUE, proxyInterruptException, requesting_osr, stackLimit, state, throwInterruptWhenScheduled, trace, tsFPOffset, waitCount, waitObject, wakeupNanoTime
 
Constructor Summary
  GreenThread(byte[] stack, String name)
          Create a thread with the given stack and name.
protected GreenThread(byte[] stack, Thread thread, String name, boolean daemon, boolean system, int priority)
          Create a thread.
  GreenThread(String name)
          Create a thread with default stack and with the given name.
  GreenThread(Thread thread, long stacksize, String name, boolean daemon, int priority)
          Create a thread with ... called by java.lang.VMThread.create.
 
Method Summary
 void block(ThreadQueue entering, ProcessorLock mutex)
          Thread is blocked on a heavyweight lock
 GreenThread getNext()
          Get the next element after this thread in a thread queue
 String getThreadState()
          Give a string of information on how a thread is set to be scheduled
static void ioWaitImpl(ThreadIOWaitData waitData)
          Put given thread onto the IO wait queue.
(package private)  boolean isQueueable()
          Is this thread suitable for putting on a queue?
protected  void killInternal()
          Thread model dependent part of stopping/interrupting a thread
(package private) static void morph()
           
(package private) static void morph(boolean timerTick)
          Current thread has been placed onto some queue.
protected  void notifyAllInternal(Object o, Lock lock)
          Support for Java Object.notify() synchronization primitive.
protected  void notifyInternal(Object o, Lock lock)
          Support for Java Object.notify() synchronization primitive.
 void osrPark()
          Park the thread for OSR.
 void osrUnpark()
          Unpark the thread from OSR.
static void processWaitImpl(ThreadProcessWaitData waitData, VMProcess process)
          Put given thread onto the process wait queue.
protected  void registerThreadInternal()
          Update internal state of Thread and Scheduler to indicate that a thread is about to start
protected  void resumeInternal()
          Thread model dependent part of thread resumption
 void schedule()
          Put this thread on ready queue for subsequent execution on a future timeslice.
 void setNext(GreenThread next)
          Set the next element after this thread in a thread queue
private  boolean sleepImpl(ThreadProxy proxy)
          Uninterruptible portion of going to sleep
protected  void sleepInternal(long millis, int ns)
          Thread model dependant sleep
 void start(GreenThreadQueue q)
          Start execution of 'this' by putting it on the given queue.
(package private)  boolean suspendIfPending()
          Suspend thread if a suspend is pending.
protected  void suspendInternal()
          Thread model dependent part of thread suspension
static void timerTickYield(int whereFrom)
          Suspend execution of current thread, in favor of some other thread.
 void unblock()
          Unblock thread from heavyweight lock blocking
private  Throwable waitImpl(Object o, GreenLock l, boolean hasTimeout, long millis, ThreadProxy proxy)
          Unpreemptible portion of waiting
protected  Throwable waitInternal(Object o)
          Support for Java Object.wait() synchronization primitive.
protected  Throwable waitInternal(Object o, long millis)
          Support for Java Object.wait() synchronization primitive.
private  Throwable waitInternal2(Object o, boolean hasTimeout, long millis)
          Combine the two outer waitInternal into one bigger one
static void yield()
          Suspend execution of current thread, in favor of some other thread.
static void yield(AbstractThreadQueue q)
          Suspend execution of current thread in favor of some other thread.
 void yield(AbstractThreadQueue q, ProcessorLock l)
          Suspend execution of current thread in favor of some other thread.
 void yield(ProcessorLock l, RVMThread.State newState)
          Suspend execution of current thread, change its state, and release a lock.
private static void yield(ThreadProxyWaitingQueue q1, ProcessorLock l1, ThreadProxyWakeupQueue q2, ProcessorLock l2)
          For timed wait, suspend execution of current thread in favor of some other thread.
static void yieldpoint(int whereFrom, Address yieldpointServiceMethodFP)
          Process a taken yieldpoint.
 
Methods inherited from class org.jikesrvm.scheduler.RVMThread
changeThreadState, clearDisallowAllocationsByThisThread, clearEmergencyAllocation, clearInterrupted, clearOutOfMemoryError, clearPhysicalAllocationFailed, countStackFrames, dump, dump, dump, dump, dumpAll, dumpWithPadding, emergencyAllocation, endTimedInterval, fixupMovedStack, getCauseOfThreadDeath, getCollectionAttempt, getContextRegisters, getDisableGCDepth, getDisallowAllocationsByThisThread, getExceptionRegisters, getIndex, getJavaLangThread, getJNIEnv, getLockingId, getName, getOutOfMemoryError, getPriority, getStack, getStackLength, getState, getThreadForStackTrace, handleUncaughtException, hasActiveTimedInterval, hasNativeStackFrame, holdsLock, initializeJNIEnv, interrupt, isAlive, isBootThread, isDaemonThread, isDebuggerThread, isGCThread, isIdleThread, isInterrupted, isSystemThread, join, kill, makeDaemon, notify, notifyAll, notifyAllUninterruptible, park, physicalAllocationFailed, postExternalInterrupt, raiseIllegalMonitorStateException, registerThread, reportCollectionAttempt, resetCollectionAttempts, resizeCurrentStack, resume, resumeInterval, run, setDisableGCDepth, setDisallowAllocationsByThisThread, setEmergencyAllocation, setName, setOutOfMemoryError, setPhysicalAllocationFailed, setPriority, setupBootThread, sleep, start, startTimedInterval, suspend, suspendInterval, terminate, toString, unpark, wait, wait, yieldpointFromBackedge, yieldpointFromEpilogue, yieldpointFromPrologue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

suspendPendingOffset

private static final Offset suspendPendingOffset
Offset of the lock field controlling the suspending of a thread


osrParkLock

private static final ProcessorLock osrParkLock
Lock used for handling parking and unparking for OSR. This lock is global, since OSR is serialized anyway.


osrParkingPermit

private boolean osrParkingPermit
Parking permit for OSR.


suspendPending

private volatile int suspendPending
Should this thread be suspended the next time it is considered for scheduling? NB int as we CAS to modify it


next

private GreenThread next
This thread's successor on a queue.


chosenProcessorId

public int chosenProcessorId
ID of processor to run this thread (cycles for load balance)


threadProxy

public ThreadProxy threadProxy
A thread proxy. Either null or an object holding a reference to this class and sitting in two queues. When one queue dequeues the object they nullify the reference to this class in the thread proxy, thereby indicating to the other queue the thread is no longer in their queue.


waitData

ThreadEventWaitData waitData
Object specifying the event the thread is waiting for. E.g., set of file descriptors for an I/O wait.


processorAffinity

public GreenProcessor processorAffinity
Virtual processor that this thread wants to run on (null --> any processor is ok).

Constructor Detail

GreenThread

public GreenThread(String name)
Create a thread with default stack and with the given name.


GreenThread

public GreenThread(byte[] stack,
                   String name)
Create a thread with the given stack and name. Used by CollectorThread and the boot image writer for the boot thread.


GreenThread

public GreenThread(Thread thread,
                   long stacksize,
                   String name,
                   boolean daemon,
                   int priority)
Create a thread with ... called by java.lang.VMThread.create. System thread isn't set.


GreenThread

protected GreenThread(byte[] stack,
                      Thread thread,
                      String name,
                      boolean daemon,
                      boolean system,
                      int priority)
Create a thread.

Method Detail

getNext

public final GreenThread getNext()
Get the next element after this thread in a thread queue


setNext

public final void setNext(GreenThread next)
Set the next element after this thread in a thread queue


registerThreadInternal

protected final void registerThreadInternal()
Update internal state of Thread and Scheduler to indicate that a thread is about to start

Specified by:
registerThreadInternal in class RVMThread

start

public final void start(GreenThreadQueue q)
Start execution of 'this' by putting it on the given queue. Precondition: If the queue is global, caller must have the appropriate mutex.

Parameters:
q - the ThreadQueue on which to enqueue this thread.

block

public final void block(ThreadQueue entering,
                        ProcessorLock mutex)
Thread is blocked on a heavyweight lock

See Also:
Lock.lockHeavy(Object)

unblock

public final void unblock()
Unblock thread from heavyweight lock blocking

See Also:
Lock.unlockHeavy(Object)

yieldpoint

public static void yieldpoint(int whereFrom,
                              Address yieldpointServiceMethodFP)
Process a taken yieldpoint. May result in threadswitch, depending on state of various control flags on the processor object.


timerTickYield

public static void timerTickYield(int whereFrom)
Suspend execution of current thread, in favor of some other thread. Move this thread to a random virtual processor (for minimal load balancing) if this processor has other runnable work.

Parameters:
whereFrom - backedge, prologue, epilogue?

yield

public static void yield()
Suspend execution of current thread, in favor of some other thread.


yield

public final void yield(AbstractThreadQueue q,
                        ProcessorLock l)
Suspend execution of current thread in favor of some other thread.

Parameters:
q - queue to put thread onto
l - lock guarding that queue (currently locked)

yield

public final void yield(ProcessorLock l,
                        RVMThread.State newState)
Suspend execution of current thread, change its state, and release a lock.

Parameters:
l - lock guarding the decision to suspend
newState - state to change to

yield

private static void yield(ThreadProxyWaitingQueue q1,
                          ProcessorLock l1,
                          ThreadProxyWakeupQueue q2,
                          ProcessorLock l2)
For timed wait, suspend execution of current thread in favor of some other thread. Put a proxy for the current thread on a queue waiting a notify, and on a wakeup queue waiting for a timeout.

Parameters:
q1 - the ThreadProxyWaitingQueue upon which to wait for notification
l1 - the ProcessorLock guarding q1 (currently locked)
q2 - the ThreadProxyWakeupQueue upon which to wait for timeout
l2 - the ProcessorLock guarding q2 (currently locked)

morph

static void morph()

morph

static void morph(boolean timerTick)
Current thread has been placed onto some queue. Become another thread.

Parameters:
timerTick - timer interrupted if true

yield

public static void yield(AbstractThreadQueue q)
Suspend execution of current thread in favor of some other thread.

Parameters:
q - queue to put thread onto (must be processor-local, ie. not guarded with a lock)

sleepInternal

protected final void sleepInternal(long millis,
                                   int ns)
                            throws InterruptedException
Thread model dependant sleep

Specified by:
sleepInternal in class RVMThread
Parameters:
millis -
ns -
Throws:
InterruptedException

sleepImpl

private boolean sleepImpl(ThreadProxy proxy)
Uninterruptible portion of going to sleep

Returns:
were we interrupted prior to going to sleep

waitInternal

protected final Throwable waitInternal(Object o)
Support for Java Object.wait() synchronization primitive.

Specified by:
waitInternal in class RVMThread
Parameters:
o - the object synchronized on

waitInternal

protected final Throwable waitInternal(Object o,
                                       long millis)
Support for Java Object.wait() synchronization primitive.

Specified by:
waitInternal in class RVMThread
Parameters:
o - the object synchronized on
millis - the number of milliseconds to wait for notification

waitInternal2

private Throwable waitInternal2(Object o,
                                boolean hasTimeout,
                                long millis)
Combine the two outer waitInternal into one bigger one

Parameters:
o - the object to wait upon
hasTimeout - have a timeout ?
millis - timeout value
Returns:
any exceptions created along the way

waitImpl

private Throwable waitImpl(Object o,
                           GreenLock l,
                           boolean hasTimeout,
                           long millis,
                           ThreadProxy proxy)
Unpreemptible portion of waiting


notifyInternal

protected final void notifyInternal(Object o,
                                    Lock lock)
Support for Java Object.notify() synchronization primitive.

Specified by:
notifyInternal in class RVMThread
Parameters:
o - the object synchronized on
lock - the heavy weight lock

notifyAllInternal

protected final void notifyAllInternal(Object o,
                                       Lock lock)
Support for Java Object.notify() synchronization primitive.

Specified by:
notifyAllInternal in class RVMThread
Parameters:
o - the object synchronized on
lock - the heavy weight lock

ioWaitImpl

public static void ioWaitImpl(ThreadIOWaitData waitData)
Put given thread onto the IO wait queue.

Parameters:
waitData - the wait data specifying the file descriptor(s) to wait for.

processWaitImpl

public static void processWaitImpl(ThreadProcessWaitData waitData,
                                   VMProcess process)
Put given thread onto the process wait queue.

Parameters:
waitData - the wait data specifying which process to wait for
process - the Process object associated with the process

killInternal

protected final void killInternal()
Thread model dependent part of stopping/interrupting a thread

Specified by:
killInternal in class RVMThread

suspendInternal

protected final void suspendInternal()
Thread model dependent part of thread suspension

Specified by:
suspendInternal in class RVMThread

resumeInternal

protected final void resumeInternal()
Thread model dependent part of thread resumption

Specified by:
resumeInternal in class RVMThread

suspendIfPending

final boolean suspendIfPending()
Suspend thread if a suspend is pending. Called by processor dispatch loop. Thread will be dequeued and not run if this returns true.

Returns:
whether the thread had a suspend pending

osrPark

public void osrPark()
Park the thread for OSR.

Specified by:
osrPark in class RVMThread

osrUnpark

public void osrUnpark()
Unpark the thread from OSR.

Specified by:
osrUnpark in class RVMThread

schedule

public final void schedule()
Put this thread on ready queue for subsequent execution on a future timeslice. Assumption: Thread.contextRegisters are ready to pick up execution ie. return to a yield or begin thread startup code

Specified by:
schedule in class RVMThread

getThreadState

public String getThreadState()
Give a string of information on how a thread is set to be scheduled

Specified by:
getThreadState in class RVMThread

isQueueable

final boolean isQueueable()
Is this thread suitable for putting on a queue?

Returns:
whether the thread is terminated