~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/ThreadContext.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.util.ArrayList;
 
4
import java.util.HashMap;
 
5
import java.util.Random;
 
6
 
 
7
import org.perl6.nqp.sixmodel.reprs.CallCaptureInstance;
 
8
import org.perl6.nqp.sixmodel.reprs.SCRefInstance;
 
9
import org.perl6.nqp.sixmodel.SixModelObject;
 
10
 
 
11
/**
 
12
 * State of a currently running thread.
 
13
 */
 
14
public class ThreadContext {
 
15
    /**
 
16
     * The global context for the NQP runtime support.
 
17
     */
 
18
    public GlobalContext gc;
 
19
    
 
20
    /**
 
21
     * The current call frame.
 
22
     */
 
23
    public CallFrame curFrame;
 
24
    
 
25
    /**
 
26
     * When we wish to access optional parameters, we need to convey
 
27
     * if there was a value as well as to supply it. However, the JVM
 
28
     * gives no good way to do that (no ref parameters, for example)
 
29
     * short of allocating an object, which is overkill. So we use
 
30
     * this field to convey if the last optional parameter fetched is
 
31
     * valid or not. 
 
32
     */
 
33
    public int lastParameterExisted;
 
34
    
 
35
    /**
 
36
     * Holds just-processed args in the case we have a flattening. 
 
37
     */
 
38
    public Object[] flatArgs;
 
39
    
 
40
    /**
 
41
     * When we wish to look up or bind native or inlined things in an
 
42
     * object, we need a way to pass around some native value. The
 
43
     * following set of slots, along with a flag indicating value
 
44
     * type, provide a way to do that.
 
45
     */
 
46
    public long native_i;
 
47
    public double native_n;
 
48
    public String native_s;
 
49
    public Object native_j;
 
50
    public int native_type;
 
51
    public static final int NATIVE_INT = 1;
 
52
    public static final int NATIVE_NUM = 2;
 
53
    public static final int NATIVE_STR = 3;
 
54
    public static final int NATIVE_JVM_OBJ = 4;
 
55
    
 
56
    /**
 
57
     * The current unwind exception.
 
58
     */
 
59
    public UnwindException unwinder;
 
60
    
 
61
    /**
 
62
     * Stack of handlers we're currently in.
 
63
     */
 
64
    public ArrayList<HandlerInfo> handlers;
 
65
    
 
66
    /**
 
67
     * The current lexotic we're throwing.
 
68
     */
 
69
    public LexoticException theLexotic;
 
70
    
 
71
    /**
 
72
     * The currently saved capture for custom processing.
 
73
     */
 
74
    public CallCaptureInstance savedCC;
 
75
    
 
76
    /**
 
77
     * The currently set dispatcher, for the next interested call to take.
 
78
     */
 
79
    public SixModelObject currentDispatcher;
 
80
    
 
81
    /**
 
82
     * Serialization context write barrier disabled depth (anything non-zero
 
83
     * means disabled).
 
84
     */
 
85
    public int scwbDisableDepth;
 
86
    
 
87
    /**
 
88
     * Any serialization contexts we are compiling; null if none.
 
89
     */
 
90
    public ArrayList<SCRefInstance> compilingSCs;
 
91
 
 
92
    /**
 
93
     * A dummy frame into which return values are set when there is no real caller.
 
94
     */
 
95
    public CallFrame dummyCaller;
 
96
 
 
97
    Object hllThreadData;
 
98
    ContextKey<?,?> hllThreadKey;
 
99
    HashMap<ContextKey<?,?>, Object> hllThreadAll;
 
100
 
 
101
    Object hllGlobalData;
 
102
    ContextKey<?,?> hllGlobalKey;
 
103
    HashMap<ContextKey<?,?>, Object> hllGlobalAllCache;
 
104
 
 
105
    Random random;
 
106
 
 
107
    // odds and ends for nqp
 
108
    ArrayList<Integer> fates = new ArrayList<Integer>(), curst = new ArrayList<Integer>(), nextst = new ArrayList<Integer>();
 
109
 
 
110
    public ThreadContext(GlobalContext gc) {
 
111
        this.gc = gc;
 
112
        this.theLexotic = new LexoticException();
 
113
        this.unwinder = new UnwindException();
 
114
        this.handlers = new ArrayList<HandlerInfo>();
 
115
        this.hllThreadAll = new HashMap<ContextKey<?,?>, Object>();
 
116
        this.hllGlobalAllCache = new HashMap<ContextKey<?,?>, Object>();
 
117
        this.random = new Random();
 
118
        if (gc.CallCapture != null) {
 
119
            savedCC = (CallCaptureInstance)gc.CallCapture.st.REPR.allocate(this, gc.CallCapture.st);
 
120
        }
 
121
        this.dummyCaller = new CallFrame();
 
122
    }
 
123
 
 
124
    public CallFrame resultFrame() {
 
125
        return curFrame != null ? curFrame : dummyCaller;
 
126
    }
 
127
}