Skip to content

Commit e217b31

Browse files
committed
[truffle] Implement ThreadContext and add support to passing it to ops
1 parent 6167b62 commit e217b31

File tree

13 files changed

+60
-12
lines changed

13 files changed

+60
-12
lines changed

src/vm/jvm/dsl/org/perl6/nqp/dsl/AstBuilder.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
Class hllClass();
2020
Class contextSlotClass();
2121
Class globalContextClass();
22+
Class threadContextClass();
2223

2324
boolean tastToByteCode();
2425
boolean tastToNode();

src/vm/jvm/dsl/org/perl6/nqp/dsl/Processor.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ static class AstTypes {
4242
TypeMirror hllClass;
4343
TypeMirror contextSlotClass;
4444
TypeMirror globalContextClass;
45+
TypeMirror threadContextClass;
4546

4647
AstTypes(AstBuilder annotation) {
4748
try {
@@ -109,6 +110,12 @@ static class AstTypes {
109110
} catch (MirroredTypeException e) {
110111
globalContextClass = e.getTypeMirror();
111112
}
113+
114+
try {
115+
annotation.threadContextClass();
116+
} catch (MirroredTypeException e) {
117+
threadContextClass = e.getTypeMirror();
118+
}
112119
}
113120
}
114121

@@ -173,6 +180,9 @@ private void writeParams(ExecutableElement executableElement, AstTypes astTypes,
173180
} else if (paramType.equals(astTypes.globalContextClass)) {
174181
writer.append("scope.getGlobalContext()");
175182
i--;
183+
} else if (paramType.equals(astTypes.threadContextClass)) {
184+
writer.append("scope.getThreadContext()");
185+
i--;
176186
} else if (global != null) {
177187
writer.append("scope.getGlobalContext()." + param.getSimpleName());
178188
i--;
@@ -296,6 +306,8 @@ private void writeArgumentsToByteCode(ExecutableElement executableElement, AstTy
296306
i--;
297307
} else if (paramType.equals(astTypes.globalContextClass)) {
298308
i--;
309+
} else if (paramType.equals(astTypes.threadContextClass)) {
310+
i--;
299311
} else if (global != null) {
300312
i--;
301313
} else {
@@ -342,6 +354,8 @@ private void writeByteCodeParams(ExecutableElement executableElement, String rea
342354
writer.append("scope.getContextSlot()");
343355
} else if (paramType.equals(astTypes.globalContextClass)) {
344356
writer.append("scope.getGlobalContext()");
357+
} else if (paramType.equals(astTypes.threadContextClass)) {
358+
writer.append("scope.getThreadContext()");
345359
} else if (global != null) {
346360
writer.append("scope.getGlobalContext()." + param.getSimpleName());
347361
} else {

src/vm/jvm/runtime/org/perl6/nqp/truffle/ByteCodeRunner.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
scopeClass = NQPScope.class,
7070
contextSlotClass = FrameSlot.class,
7171
globalContextClass = GlobalContext.class,
72+
threadContextClass = ThreadContext.class,
7273
hllClass = HLL.class,
7374
tastToByteCode = false,
7475
tastToNode = false,
@@ -85,7 +86,7 @@ protected NQPNode[] byteCodeToNodeArray(ByteCodeReader reader, NQPScope scope) {
8586
return nodes;
8687
}
8788

88-
public void runByteCode(GlobalContext globalContext, DynamicContext context, String input) {
89+
public void runByteCode(GlobalContext globalContext, ThreadContext threadContext, DynamicContext context, String input) {
8990
try {
9091
FileInputStream stream = new FileInputStream(input);
9192
FileChannel channel = stream.getChannel();
@@ -104,7 +105,7 @@ public void runByteCode(GlobalContext globalContext, DynamicContext context, Str
104105
long version = reader.readVersion();
105106

106107
FrameDescriptor frameDescriptor = new FrameDescriptor();
107-
RootNode rootNode = new NQPRootNode(null, frameDescriptor, byteCodeToNode(reader, new NQPScopeWithFrame(frameDescriptor, new NQPScopeWithGlobalContext(globalContext))));
108+
RootNode rootNode = new NQPRootNode(null, frameDescriptor, byteCodeToNode(reader, new NQPScopeWithFrame(frameDescriptor, new NQPScopeWithGlobalContext(globalContext, threadContext))));
108109

109110
CallTarget callTarget = Truffle.getRuntime().createCallTarget(rootNode);
110111
callTarget.call(context);

src/vm/jvm/runtime/org/perl6/nqp/truffle/NQPCompUnitScope.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ public GlobalContext getGlobalContext() {
7474
return outer.getGlobalContext();
7575
}
7676

77+
@Override
78+
public ThreadContext getThreadContext() {
79+
return outer.getThreadContext();
80+
}
7781

7882
@Override
7983
public FrameSlot getContextSlot() {

src/vm/jvm/runtime/org/perl6/nqp/truffle/NQPScope.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,5 @@ public FoundLexical findLexical(String name) {
6464
public abstract void addCuid(String cuid, NQPCodeRef codeRef);
6565

6666
public abstract GlobalContext getGlobalContext();
67+
public abstract ThreadContext getThreadContext();
6768
}

src/vm/jvm/runtime/org/perl6/nqp/truffle/NQPScopeWithFrame.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ public GlobalContext getGlobalContext() {
132132
return outer.getGlobalContext();
133133
}
134134

135+
@Override
136+
public ThreadContext getThreadContext() {
137+
return outer.getThreadContext();
138+
}
139+
135140
@Override
136141
public NQPCodeRef getCuid(String cuid) {
137142
return outer.getCuid(cuid);

src/vm/jvm/runtime/org/perl6/nqp/truffle/NQPScopeWithGlobalContext.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,29 @@
33
import com.oracle.truffle.api.frame.FrameSlot;
44
import java.util.HashMap;
55
import org.perl6.nqp.truffle.GlobalContext;
6+
import org.perl6.nqp.truffle.ThreadContext;
67
import com.oracle.truffle.api.frame.FrameSlot;
78
import org.perl6.nqp.truffle.runtime.NQPCodeRef;
89
import org.perl6.nqp.truffle.runtime.HLL;
910

1011
public class NQPScopeWithGlobalContext extends NQPScope {
1112
GlobalContext globalContext;
13+
ThreadContext threadContext;
1214

13-
public NQPScopeWithGlobalContext(GlobalContext globalContext) {
15+
public NQPScopeWithGlobalContext(GlobalContext globalContext, ThreadContext threadContext) {
1416
this.globalContext = globalContext;
17+
this.threadContext = threadContext;
1518
}
1619

1720
@Override
1821
public GlobalContext getGlobalContext() {
1922
return globalContext;
2023
}
2124

25+
@Override
26+
public ThreadContext getThreadContext() {
27+
return threadContext;
28+
}
2229

2330
@Override
2431
public HLL getCurrentHLL() {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.perl6.nqp.truffle;
2+
3+
public class ThreadContext {
4+
/**
5+
* Serialization context write barrier disabled depth (anything non-zero
6+
* means disabled).
7+
*/
8+
public int scwbDisableDepth = 0;
9+
10+
public ThreadContext() {
11+
}
12+
}
13+

src/vm/jvm/runtime/org/perl6/nqp/truffle/adapters/TruffleCompiler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,15 @@
4747
hllClass = HLL.class,
4848
contextSlotClass = FrameSlot.class,
4949
globalContextClass = GlobalContext.class,
50+
threadContextClass = org.perl6.nqp.truffle.ThreadContext.class,
5051
tastToByteCode = true,
5152
tastToNode = true,
5253
byteCodeToNode = false
5354
)
5455
abstract class TruffleCompiler {
5556
public void run(SixModelObject node, ThreadContext tc) {
5657
FrameDescriptor frameDescriptor = new FrameDescriptor();
57-
RootNode rootNode = new NQPRootNode(null, frameDescriptor, tastToNode(node, new NQPScopeWithFrame(frameDescriptor, new NQPScopeWithGlobalContext(new GlobalContext())), tc));
58+
RootNode rootNode = new NQPRootNode(null, frameDescriptor, tastToNode(node, new NQPScopeWithFrame(frameDescriptor, new NQPScopeWithGlobalContext(new GlobalContext(), new org.perl6.nqp.truffle.ThreadContext())), tc));
5859

5960

6061
CallTarget callTarget = Truffle.getRuntime().createCallTarget(rootNode);

src/vm/jvm/runtime/org/perl6/nqp/truffle/nodes/expression/NQPCtxlexpadNode.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ public NQPCtxlexpadNode(NQPNode ctxNode) {
1616

1717
@Override
1818
public Object execute(VirtualFrame frame) {
19-
Object ctx = ctxNode.execute(frame);
20-
System.out.println("ctx: " + ctx);
21-
return ctx;
19+
// TODO - think if we want to do a check here
20+
return ctxNode.execute(frame);
2221
}
2322
}

0 commit comments

Comments
 (0)