1
package org.perl6.nqp.runtime;
3
import java.lang.invoke.MethodHandle;
4
import org.perl6.nqp.sixmodel.SixModelObject;
7
* Represents a composable continuation.
9
public class ResumeStatus extends SixModelObject {
11
* Represents one saved, not-currently-executing execution frame.
13
public static final class Frame {
14
/** Identifies the method that was executing. Signature is (ResumeStatus$Frame)Void. */
15
public final MethodHandle method;
16
/** Identifies the call site within the method. */
17
public final int resumePoint;
18
/** Local variables saved for the method. */
19
public final Object[] saveSpace;
20
/** If present, this frame should be set as the running frame on reentry. */
21
public final CallFrame callFrame;
22
/** The next deeper frame. Don't modify after exposing to the world. */
24
/** Thread context which the frame is being restored on. Only valid during restore. */
25
public transient ThreadContext tc;
26
/** Set during resume to a thunk which is called once the stack is restored. */
27
public transient SixModelObject thunk;
30
/** Constructor which sets all fields. */
31
public Frame(MethodHandle method, int resumePoint, Object[] saveSpace, CallFrame callFrame, Frame next) {
33
this.resumePoint = resumePoint;
34
this.saveSpace = saveSpace;
35
this.callFrame = callFrame;
39
/** Restores a frame to the VM stack. */
40
public void resume() throws Throwable {
41
if (callFrame != null) {
43
callFrame.caller = tc.curFrame;
44
tc.curFrame = callFrame;
46
this.method.invokeExact(this);
49
/** Restores the next frame, if any. */
50
public void resumeNext() throws Throwable {
54
Ops.invokeDirect(tc, thunk, Ops.emptyCallSite, false, Ops.emptyArgList);
58
/** Restores the next frame. If it suspends, put this frame on the new continuation. */
59
public void resumeNextSave() throws Throwable {
62
} catch (SaveStackException sse) {
63
throw sse.pushFrame(resumePoint, method, saveSpace, callFrame);
68
/** The first frame of this continuation. Subsequent frames can be accessed using {@link Frame#next}. */