1
package org.perl6.nqp.runtime;
3
import java.util.ArrayList;
4
import java.util.HashMap;
5
import java.util.Random;
7
import org.perl6.nqp.sixmodel.reprs.CallCaptureInstance;
8
import org.perl6.nqp.sixmodel.reprs.SCRefInstance;
9
import org.perl6.nqp.sixmodel.SixModelObject;
12
* State of a currently running thread.
14
public class ThreadContext {
16
* The global context for the NQP runtime support.
18
public GlobalContext gc;
21
* The current call frame.
23
public CallFrame curFrame;
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
33
public int lastParameterExisted;
36
* Holds just-processed args in the case we have a flattening.
38
public Object[] flatArgs;
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.
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;
57
* The current unwind exception.
59
public UnwindException unwinder;
62
* Stack of handlers we're currently in.
64
public ArrayList<HandlerInfo> handlers;
67
* The current lexotic we're throwing.
69
public LexoticException theLexotic;
72
* The currently saved capture for custom processing.
74
public CallCaptureInstance savedCC;
77
* The currently set dispatcher, for the next interested call to take.
79
public SixModelObject currentDispatcher;
82
* Serialization context write barrier disabled depth (anything non-zero
85
public int scwbDisableDepth;
88
* Any serialization contexts we are compiling; null if none.
90
public ArrayList<SCRefInstance> compilingSCs;
93
* A dummy frame into which return values are set when there is no real caller.
95
public CallFrame dummyCaller;
98
ContextKey<?,?> hllThreadKey;
99
HashMap<ContextKey<?,?>, Object> hllThreadAll;
101
Object hllGlobalData;
102
ContextKey<?,?> hllGlobalKey;
103
HashMap<ContextKey<?,?>, Object> hllGlobalAllCache;
107
// odds and ends for nqp
108
ArrayList<Integer> fates = new ArrayList<Integer>(), curst = new ArrayList<Integer>(), nextst = new ArrayList<Integer>();
110
public ThreadContext(GlobalContext 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);
121
this.dummyCaller = new CallFrame();
124
public CallFrame resultFrame() {
125
return curFrame != null ? curFrame : dummyCaller;