~ubuntu-branches/ubuntu/vivid/nqp/vivid-proposed

« back to all changes in this revision

Viewing changes to src/vm/jvm/runtime/org/perl6/nqp/runtime/ResumeStatus.java

  • Committer: Package Import Robot
  • Author(s): Alessandro Ghedini
  • Date: 2013-11-01 12:09:18 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20131101120918-kx51sl0sxl3exsxi
Tags: 2013.10-1
* New upstream release
* Bump versioned (Build-)Depends on parrot
* Update patches
* Install new README.pod
* Fix vcs-field-not-canonical
* Do not install rubyish examples
* Do not Depends on parrot-devel anymore
* Add 07_disable-serialization-tests.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.perl6.nqp.runtime;
 
2
 
 
3
import java.lang.invoke.MethodHandle;
 
4
import org.perl6.nqp.sixmodel.SixModelObject;
 
5
 
 
6
/**
 
7
 * Represents a composable continuation.
 
8
 */
 
9
public class ResumeStatus extends SixModelObject {
 
10
    /**
 
11
     * Represents one saved, not-currently-executing execution frame.
 
12
     */
 
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. */
 
23
        public Frame next;
 
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;
 
28
 
 
29
 
 
30
        /** Constructor which sets all fields. */
 
31
        public Frame(MethodHandle method, int resumePoint, Object[] saveSpace, CallFrame callFrame, Frame next) {
 
32
            this.method = method;
 
33
            this.resumePoint = resumePoint;
 
34
            this.saveSpace = saveSpace;
 
35
            this.callFrame = callFrame;
 
36
            this.next = next;
 
37
        }
 
38
 
 
39
        /** Restores a frame to the VM stack. */
 
40
        public void resume() throws Throwable {
 
41
            if (callFrame != null) {
 
42
                callFrame.tc = tc;
 
43
                callFrame.caller = tc.curFrame;
 
44
                tc.curFrame = callFrame;
 
45
            }
 
46
            this.method.invokeExact(this);
 
47
        }
 
48
 
 
49
        /** Restores the next frame, if any. */
 
50
        public void resumeNext() throws Throwable {
 
51
            if (next != null) {
 
52
                next.resume();
 
53
            } else {
 
54
                Ops.invokeDirect(tc, thunk, Ops.emptyCallSite, false, Ops.emptyArgList);
 
55
            }
 
56
        }
 
57
 
 
58
        /** Restores the next frame.  If it suspends, put this frame on the new continuation. */
 
59
        public void resumeNextSave() throws Throwable {
 
60
            try {
 
61
                resumeNext();
 
62
            } catch (SaveStackException sse) {
 
63
                throw sse.pushFrame(resumePoint, method, saveSpace, callFrame);
 
64
            }
 
65
        }
 
66
    }
 
67
 
 
68
    /** The first frame of this continuation.  Subsequent frames can be accessed using {@link Frame#next}. */
 
69
    public Frame top;
 
70
}