Skip to content

Commit f314fc7

Browse files
committed
[truffle] Implement Decoder/ConcBlockingQueue/ConditionVariable/ReentrantMutex reprs
1 parent 0a33ab1 commit f314fc7

File tree

9 files changed

+159
-3
lines changed

9 files changed

+159
-3
lines changed

src/vm/jvm/runtime/org/perl6/nqp/truffle/sixmodel/REPRRegistry.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,31 @@
33
import java.util.ArrayList;
44
import java.util.HashMap;
55

6-
import org.perl6.nqp.truffle.sixmodel.reprs.P6opaque;
6+
import org.perl6.nqp.truffle.sixmodel.reprs.ConditionVariable;
7+
import org.perl6.nqp.truffle.sixmodel.reprs.ConcBlockingQueue;
8+
import org.perl6.nqp.truffle.sixmodel.reprs.Decoder;
9+
import org.perl6.nqp.truffle.sixmodel.reprs.KnowHOWAttribute;
10+
import org.perl6.nqp.truffle.sixmodel.reprs.KnowHOWREPR;
711
import org.perl6.nqp.truffle.sixmodel.reprs.P6int;
812
import org.perl6.nqp.truffle.sixmodel.reprs.P6num;
13+
import org.perl6.nqp.truffle.sixmodel.reprs.P6opaque;
914
import org.perl6.nqp.truffle.sixmodel.reprs.P6str;
10-
import org.perl6.nqp.truffle.sixmodel.reprs.KnowHOWREPR;
11-
import org.perl6.nqp.truffle.sixmodel.reprs.KnowHOWAttribute;
15+
import org.perl6.nqp.truffle.sixmodel.reprs.ReentrantMutex;
1216
import org.perl6.nqp.truffle.sixmodel.reprs.Uninstantiable;
1317

1418
public class REPRRegistry {
1519
private static REPR create(String name, STable stable) {
1620
switch (name) {
21+
case "ConcBlockingQueue": return new ConcBlockingQueue(stable);
22+
case "ConditionVariable": return new ConditionVariable(stable);
23+
case "Decoder": return new Decoder(stable);
1724
case "KnowHOWAttribute": return new KnowHOWAttribute(stable);
1825
case "KnowHOWREPR": return new KnowHOWREPR(stable);
1926
case "P6int": return new P6int(stable);
2027
case "P6num": return new P6num(stable);
2128
case "P6opaque": return new P6opaque(stable);
2229
case "P6str": return new P6str(stable);
30+
case "ReentrantMutex": return new ReentrantMutex(stable);
2331
case "Uninstantiable": return new Uninstantiable();
2432
default: throw new RuntimeException("No REPR " + name);
2533
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package org.perl6.nqp.truffle.sixmodel.reprs;
2+
import org.perl6.nqp.truffle.sixmodel.SerializationReader;
3+
import org.perl6.nqp.truffle.sixmodel.STable;
4+
5+
6+
public class ConcBlockingQueue extends FixedSizeObjectREPR {
7+
public ConcBlockingQueue(STable stable) {
8+
super(stable);
9+
}
10+
11+
public Object allocate() {
12+
return new ConcBlockingQueueInstance(stable);
13+
}
14+
15+
public Object deserializeStub() {
16+
throw new RuntimeException("Cannot deserialize a concurrent blocking queue");
17+
}
18+
19+
public void deserializeFinish(SerializationReader reader, Object obj) {
20+
throw new RuntimeException("Cannot deserialize a concurrent blocking queue");
21+
}
22+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.perl6.nqp.truffle.sixmodel.reprs;
2+
3+
import java.util.concurrent.LinkedBlockingQueue;
4+
import org.perl6.nqp.truffle.sixmodel.STable;
5+
6+
public class ConcBlockingQueueInstance extends FixedSizeObject {
7+
public LinkedBlockingQueue<Object> queue;
8+
9+
public ConcBlockingQueueInstance(STable stable) {
10+
super(stable);
11+
queue = new LinkedBlockingQueue<Object>();
12+
}
13+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.perl6.nqp.truffle.sixmodel.reprs;
2+
import org.perl6.nqp.truffle.sixmodel.SerializationReader;
3+
import org.perl6.nqp.truffle.sixmodel.STable;
4+
5+
6+
public class ConditionVariable extends FixedSizeObjectREPR {
7+
public ConditionVariable(STable stable) {
8+
super(stable);
9+
}
10+
11+
public Object allocate() {
12+
throw new RuntimeException("Cannot create a condition variable directly");
13+
}
14+
15+
16+
public Object deserializeStub() {
17+
throw new RuntimeException("Cannot deserialize a lock");
18+
}
19+
20+
public void deserializeFinish(SerializationReader reader, Object obj) {
21+
throw new RuntimeException("Cannot deserialize a lock");
22+
}
23+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.perl6.nqp.truffle.sixmodel.reprs;
2+
3+
import java.util.concurrent.locks.Condition;
4+
import org.perl6.nqp.truffle.sixmodel.STable;
5+
6+
public class ConditionVariableInstance extends FixedSizeObject {
7+
public Condition condvar;
8+
9+
public ConditionVariableInstance(STable stable) {
10+
super(stable);
11+
}
12+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package org.perl6.nqp.truffle.sixmodel.reprs;
2+
import org.perl6.nqp.truffle.sixmodel.SerializationReader;
3+
import org.perl6.nqp.truffle.sixmodel.STable;
4+
5+
6+
public class Decoder extends FixedSizeObjectREPR {
7+
public Decoder(STable stable) {
8+
super(stable);
9+
}
10+
11+
public Object allocate() {
12+
return new DecoderInstance(stable);
13+
}
14+
15+
public Object deserializeStub() {
16+
throw new RuntimeException("Cannot deserialize a Decoder");
17+
}
18+
19+
public void deserializeFinish(SerializationReader reader, Object obj) {
20+
throw new RuntimeException("Cannot deserialize a Decoder");
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package org.perl6.nqp.truffle.sixmodel.reprs;
2+
3+
import java.nio.ByteBuffer;
4+
import java.nio.CharBuffer;
5+
import java.nio.charset.Charset;
6+
import java.nio.charset.CharsetDecoder;
7+
import java.util.ArrayList;
8+
import java.util.List;
9+
10+
import org.perl6.nqp.truffle.sixmodel.STable;
11+
12+
public class DecoderInstance extends FixedSizeObject {
13+
private Charset charset;
14+
private CharsetDecoder decoder;
15+
private List<ByteBuffer> toDecode;
16+
private List<CharBuffer> decoded;
17+
private List<String> lineSeps;
18+
19+
public DecoderInstance(STable stable) {
20+
super(stable);
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package org.perl6.nqp.truffle.sixmodel.reprs;
2+
import org.perl6.nqp.truffle.sixmodel.SerializationReader;
3+
import org.perl6.nqp.truffle.sixmodel.STable;
4+
5+
6+
public class ReentrantMutex extends FixedSizeObjectREPR {
7+
public ReentrantMutex(STable stable) {
8+
super(stable);
9+
}
10+
11+
public Object allocate() {
12+
return new ReentrantMutexInstance(stable);
13+
}
14+
15+
public Object deserializeStub() {
16+
return new ReentrantMutexInstance(stable);
17+
}
18+
19+
public void deserializeFinish(SerializationReader reader, Object obj) {
20+
/* Already did it all in deserializeStub. */
21+
}
22+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.perl6.nqp.truffle.sixmodel.reprs;
2+
3+
import java.util.concurrent.locks.ReentrantLock;
4+
import org.perl6.nqp.truffle.sixmodel.STable;
5+
6+
public class ReentrantMutexInstance extends FixedSizeObject {
7+
public ReentrantLock lock;
8+
public ReentrantMutexInstance(STable stable) {
9+
super(stable);
10+
lock = new ReentrantLock();
11+
}
12+
}

0 commit comments

Comments
 (0)