Package kilim
Class Fiber
java.lang.Object
kilim.Fiber
This class serves as a context to manage and store the continuation stack.
The actual capture of the closure is done in the Weaver-transformed code.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionThe current frame's state (local vars and elements of the operand stack that will be needed when the Fiber is resumed.(package private) boolean(package private) booleanprivate intstatic final intstatic final intprivate static final Statestatic final intstatic final intintThe "program counter", kept equal to stateStack[iStack].pc and is used to jump to the appropriate place in the code while rewinding the code, and also to inform the weaved code inside an exception handler which pausable method (if at all) was being invoked when that exception was thrown.private State[] -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal Fiberbegin()(package private) voiddown()(package private) static voidds()final booleanend()end() is the last up().private State[]ensureSize(int newsize) Called by the weaved code while rewinding the stack.getState()booleanisDone()static voidpause()static voidvoidreset()voidvoidCalled by the generated code before pausing and unwinding its stack frame.private static voidstateToString(StringBuilder sb, State s) task()(package private) voidtoString()intup()intupEx()In the normal (non-exception) scheme of things, the iStack is incremented by down() on the way down and decremented by a corresponding up() when returning or pausing.voidwrongPC()static voidyield()yield cooperatively to the next task waiting to use the threadstatic voidyield cooperatively to the next task waiting to use the thread
-
Field Details
-
curState
The current frame's state (local vars and elements of the operand stack that will be needed when the Fiber is resumed. It is always kept equal to stateStack[iStack] if iStack is in the (0..stateStack.length-1) range, and null otherwise. This is used by the generated code to avoid having to manipulate stateStack in the generated code, and to isolate all stack manipulations to up() and down(). -
pc
public int pcThe "program counter", kept equal to stateStack[iStack].pc and is used to jump to the appropriate place in the code while rewinding the code, and also to inform the weaved code inside an exception handler which pausable method (if at all) was being invoked when that exception was thrown. The value 0 refers to normal operation; control transfers to the beginning of the original (pre-weaved) code. A value of n indicates a direct jump into the nth pausable method (after restoring the appropriate state). Accessed by generated code (hence public). -
stateStack
-
iStack
private int iStack -
isPausing
boolean isPausing -
isDone
boolean isDone -
task
-
PAUSE_STATE
-
NOT_PAUSING__NO_STATE
public static final int NOT_PAUSING__NO_STATE- See Also:
-
NOT_PAUSING__HAS_STATE
public static final int NOT_PAUSING__HAS_STATE- See Also:
-
PAUSING__NO_STATE
public static final int PAUSING__NO_STATE- See Also:
-
PAUSING__HAS_STATE
public static final int PAUSING__HAS_STATE- See Also:
-
-
Constructor Details
-
Fiber
-
-
Method Details
-
task
-
isDone
public boolean isDone() -
pause
- Throws:
Pausable
-
reset
public void reset() -
yield
yield cooperatively to the next task waiting to use the thread- Throws:
Pausable
-
yield
yield cooperatively to the next task waiting to use the thread -
pause
-
up
public int up() -
begin
-
end
public final boolean end()end() is the last up(). returns true if the fiber is not pausing. -
down
-
ds
static void ds() -
upEx
public int upEx()In the normal (non-exception) scheme of things, the iStack is incremented by down() on the way down and decremented by a corresponding up() when returning or pausing. If, however, an exception is thrown, we lose track of where we are in the hierarchy. We recalibrate iStack by creating a dummy exception and comparing it to the stack depth of an exception taken earlier. This is done in scheduler.getStackDepth(); A sample stack trace of the dummy exception looks as followsat kilim.Fiber.upEx(Fiber.java:250) at kilim.test.ex.ExCatch.normalCatch(ExCatch.java) at kilim.test.ex.ExCatch.test(ExCatch.java) at kilim.test.ex.ExCatch.execute(ExCatch.java) at kilim.Task.runExecute(Task.java) at kilim.WorkerThread.run(WorkerThread.java:11)
We have to figure out the stack depth (iStack) of the method that caught the exception and called upEx ("normalCatch" here). The call stack below runExecute may be owned by the scheduler, which may permit more than one task to build up on the stack. For this reason, we let the scheduler tell us the depth of upEx below the task's execute().- Returns:
- Fiber.pc (note: in contrast up() returns status)
-
getCallee
Called by the weaved code while rewinding the stack. If we are about to call a virtual pausable method, we need an object reference on which to call that method. The next state has that information in state.self -
setCallee
-
ensureSize
-
setState
Called by the generated code before pausing and unwinding its stack frame.- Parameters:
state-
-
getState
-
togglePause
void togglePause() -
toString
-
wrongPC
public void wrongPC() -
stateToString
-
clearPausing
void clearPausing()
-