Permalink
Browse files

Use new kilim from asm-4.0 branch

Also implement the new R15 line opcode
For now, just ignore; it doesn't do anything yet

Bump version to 0.3
  • Loading branch information...
1 parent 8449498 commit cbc4101298fea2db8182f2c9ff5aacd4b2aa4795 @krestenkrab krestenkrab committed Jun 5, 2012
View
@@ -6,8 +6,8 @@
<classpathentry kind="lib" path="lib/OtpErlang.jar"/>
<classpathentry kind="lib" path="lib/antlr-3.2.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3"/>
- <classpathentry kind="lib" path="lib/kilim-0.6-krab.jar" sourcepath="/kilim-erjang/src"/>
<classpathentry kind="lib" path="lib/js.jar"/>
<classpathentry kind="lib" path="lib/clj-ds.jar"/>
+ <classpathentry kind="lib" path="lib/kilim.jar" sourcepath="/kilim-gburd"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
View
@@ -1,12 +1,12 @@
<?xml version="1.0"?>
<project name="erjang" default="all">
- <property name="erjang.version" value="0.2" />
+ <property name="erjang.version" value="0.3" />
<property file="erjang_cfg.properties" />
<path id="erjang.classpath">
<pathelement location="target/classes/" />
<pathelement location="lib/js.jar" />
- <pathelement location="lib/kilim-0.6-krab.jar" />
+ <pathelement location="lib/kilim.jar" />
<pathelement location="lib/OtpErlang.jar" />
<pathelement location="lib/junit.jar" />
<pathelement location="lib/clj-ds.jar" />
@@ -16,7 +16,7 @@
<path id="erjang.testwovenclasspath">
<pathelement location="target/classes/" />
<pathelement location="target/test-classes/" />
- <pathelement location="lib/kilim-0.6-krab.jar" />
+ <pathelement location="lib/kilim.jar" />
<pathelement location="lib/OtpErlang.jar" />
<pathelement location="lib/clj-ds.jar" />
<pathelement location="lib/junit.jar" />
@@ -60,7 +60,15 @@
<target name="compile" depends="gen-interpreter,create-dirs">
<echo message="Compiling src ===================" />
- <javac debug="true" srcdir="src/main/java" destdir="target/classes" classpathref="erjang.classpath" deprecation="on" debuglevel="lines,vars,source"/>
+ <javac debug="true"
+ srcdir="src/main/java"
+ destdir="target/classes"
+ classpathref="erjang.classpath"
+ deprecation="on"
+ debuglevel="lines,vars,source"
+ source="1.5"
+ target="1.5"
+ includeantruntime="false" />
</target>
<target name="testcompile" depends="compile">
View
4 ej
@@ -7,13 +7,13 @@ EJ_CMD=`which "$0"`
while LINK=`readlink "$EJ_CMD"`; do EJ_CMD=$LINK; done
ERJANG_DIR=`dirname "$EJ_CMD"`
-## -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=8787,server=n,suspend=n \
+## -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y \
exec java \
-server \
-Xmx1g -Xss50m \
-XX:PermSize=128m \
- -jar $ERJANG_DIR/erjang-0.2.jar \
+ -jar $ERJANG_DIR/erjang-0.3.jar \
\
-progname ej \
+A 10 \
View
@@ -1,6 +1,6 @@
-#erjang.otp.root = /usr/local/lib/erlang
-#erjang.erts.version = 5.8.3
-#erjang.otp.version = R14B02
+erjang.otp.root = /usr/local/lib/erlang
+erjang.erts.version = 5.9
+erjang.otp.version = R15B
# erjang.debug.port=true
# erjang.debug.inet=true
View
Binary file not shown.
View
Binary file not shown.
@@ -219,7 +219,7 @@ private static String erlangNameOfMethod(Method method) {
String self_type = EFUN_TYPE.getInternalName() + arity;
- ClassWriter cw = new ClassWriter(true);
+ ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES|ClassWriter.COMPUTE_MAXS);
cw.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC | Opcodes.ACC_ABSTRACT,
self_type, null, EFUN_TYPE.getInternalName(), null);
@@ -286,7 +286,7 @@ public static EFun get_fun_with_handler(String module, String function, int arit
.append(module).append(safe_function)
.append("Handler").append(arity).toString();
- ClassWriter cw = new ClassWriter(true);
+ ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES|ClassWriter.COMPUTE_MAXS);
String super_class_name = EFUN_TYPE.getInternalName() + arity;
cw.visit(Opcodes.V1_4, ACC_PUBLIC, self_type, null,
super_class_name, null);
@@ -554,7 +554,7 @@ private static String make_valid_java_id(CharSequence seq) {
String super_type = EFUN_TYPE.getInternalName() + arity;
String self_type = super_type + "Exported";
- ClassWriter cw = new ClassWriter(true);
+ ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES|ClassWriter.COMPUTE_MAXS);
cw.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC | Opcodes.ACC_ABSTRACT,
self_type, null, super_type, null);
@@ -632,6 +632,7 @@ private static void push_int(MethodVisitor mv, int i) {
public static byte[] weave(byte[] data) {
ClassWeaver w = new ClassWeaver(data, new Compiler.ErjangDetector("/xx/", (Set<String>)Collections.EMPTY_SET));
+ w.weave();
for (ClassInfo ci : w.getClassInfos()) {
// ETuple.dump(ci.className, ci.bytes);
@@ -20,7 +20,6 @@
package erjang;
import erjang.m.erlang.DistEntry;
-import kilim.Mailbox;
import kilim.Pausable;
import kilim.Task;
@@ -0,0 +1,222 @@
+
+
+package erjang;
+
+import kilim.*;
+import java.util.TimerTask;
+
+public class EMailbox extends kilim.Mailbox<EObject> {
+
+ public EMailbox() {
+ super(10, ETask.MAX_MAILBOX_SIZE);
+ }
+
+ public EObject get(long timeout) throws Pausable {
+ if (untilHasMessage(timeout)) {
+ return get();
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * @return non-null message.
+ * @throws Pausable
+ */
+ public void untilHasMessage() throws Pausable{
+ while (hasMessage(Task.getCurrentTask()) == false) {
+ Task.pause(this);
+ }
+ }
+
+ /**
+ * @return non-null message.
+ * @throws Pausable
+ */
+ public boolean untilHasMessage(long timeoutMillis) throws Pausable {
+ final Task t = Task.getCurrentTask();
+ boolean has_msg = hasMessage(t);
+ long begin = System.currentTimeMillis();
+ while (has_msg == false) {
+ TimerTask tt = new TimerTask() {
+ public void run() {
+ EMailbox.this.removeMsgAvailableListener(t);
+ t.onEvent(EMailbox.this, timedOut);
+ }
+ };
+ Task.timer.schedule(tt, timeoutMillis);
+ Task.pause(this);
+ tt.cancel();
+ if (System.currentTimeMillis() - begin > timeoutMillis) {
+ break;
+ }
+ has_msg = hasMessage(t);
+ }
+ return has_msg;
+ }
+
+ /**
+ * @return non-null message.
+ * @throws Pausable
+ */
+ public void untilHasMessages(int num) throws Pausable {
+ while (hasMessages(num, Task.getCurrentTask()) == false) {
+ Task.pause(this);
+ }
+ }
+
+ /**
+ * @return non-null message.
+ * @throws Pausable
+ */
+ public boolean untilHasMessages(int num, long timeoutMillis)
+ throws Pausable {
+ final Task t = Task.getCurrentTask();
+ final long end = System.currentTimeMillis() + timeoutMillis;
+
+ boolean has_msg = hasMessages(num, t);
+ while (has_msg == false) {
+ TimerTask tt = new TimerTask() {
+ public void run() {
+ EMailbox.this.removeMsgAvailableListener(t);
+ t.onEvent(EMailbox.this, timedOut);
+ }
+ };
+ Task.timer.schedule(tt, timeoutMillis);
+ Task.pause(this);
+ if (!tt.cancel()) {
+ removeMsgAvailableListener(t);
+ }
+
+ has_msg = hasMessages(num, t);
+ timeoutMillis = end - System.currentTimeMillis();
+ if (!has_msg && timeoutMillis <= 0) {
+ removeMsgAvailableListener(t);
+ break;
+ }
+ }
+ return has_msg;
+ }
+
+
+
+ /**
+ * Non-blocking, nonpausing "wait-until-message-available".
+ *
+ * @param eo
+ * . If non-null, registers this observer and calls it with a
+ * MessageAvailable event when a put() is done.
+ * @return true's one, or false
+ */
+ public boolean hasMessage(EventSubscriber eo) {
+ boolean has_msg;
+ synchronized (this) {
+ int n = numMsgs;
+ if (n > 0) {
+ has_msg = true;
+ } else {
+ has_msg = false;
+ addMsgAvailableListener(eo);
+ }
+ }
+ return has_msg;
+ }
+
+ public boolean hasMessages(int num, EventSubscriber eo) {
+ boolean has_msg;
+ synchronized (this) {
+ int n = numMsgs;
+ if (n >= num) {
+ has_msg = true;
+ } else {
+ has_msg = false;
+ addMsgAvailableListener(eo);
+ }
+ }
+ return has_msg;
+ }
+
+ private EObject _get(int i) {
+ return (EObject)(msgs()[i]);
+ }
+
+ private int _msg_len() {
+ return msgs().length;
+ }
+
+ /**
+ * Non-blocking, nonpausing peek.
+ * @return buffered message if there's one, or null
+ */
+ public EObject peek() {
+ EObject msg;
+ synchronized(this) {
+ int n = numMsgs;
+ if (n > 0) {
+ int ic = icons;
+ msg = _get(ic);
+ } else {
+ msg = null;
+ }
+ }
+ return msg;
+ }
+
+ /**
+ * Non-blocking, nonpausing peek.
+ *
+ * @return buffered message if there's one, or null
+ */
+ public EObject peek(int idx) {
+ assert idx >= 0 : "negative index";
+ EObject msg;
+ synchronized (this) {
+ int n = numMsgs;
+ if (idx < n) {
+ int ic = icons;
+ msg = _get((ic + idx) % _msg_len());
+
+ assert msg != null : "peeked null message!";
+ } else {
+ msg = null;
+ }
+ }
+ return msg;
+ }
+
+ public EObject remove(final int idx) {
+ assert idx >= 0 : "negative index";
+ EObject msg;
+ synchronized (this) {
+ int n = numMsgs;
+ assert idx < numMsgs;
+ if (idx < n) {
+ int ic = icons;
+ int mlen = _msg_len();
+ msg = _get((ic + idx) % mlen);
+ for (int i = idx; i > 0; i--) {
+ msgs()[(ic + i) % mlen] = msgs()[(ic + i - 1) % mlen];
+ }
+ msgs()[icons] = null;
+ numMsgs -= 1;
+ icons = (icons + 1) % mlen;
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+ return msg;
+ }
+
+
+ public synchronized Object[] messages() {
+ synchronized (this) {
+ Object[] result = new Object[numMsgs];
+ for (int i = 0; i < numMsgs; i++) {
+ result[i] = _get((icons + i) % _msg_len());
+ }
+ return result;
+ }
+
+ }
+
+}
@@ -27,7 +27,6 @@
import java.util.logging.Level;
import java.util.logging.Logger;
-import kilim.Mailbox;
import kilim.Pausable;
import com.trifork.clj_ds.IPersistentSet;
@@ -46,6 +45,11 @@
private static final EAtom am_DOWN = EAtom.intern("DOWN");
private static final EAtom am_process = EAtom.intern("process");
+ int priority;
+
+ public void setPriority(int pri) { priority = pri; }
+ public int getPriority() { return priority; }
+
/**
* @return
*/
@@ -248,8 +252,8 @@ public EObject get_monitored_object(ERef monitor) {
- static final int MAX_MAILBOX_SIZE = 1000;
- protected final Mailbox<EObject> mbox = new Mailbox<EObject>(10, MAX_MAILBOX_SIZE);
+ public static final int MAX_MAILBOX_SIZE = 1000;
+ protected final EMailbox mbox = new EMailbox();
public static final int STATE_INIT = 0; // has not started yet
public static final int STATE_RUNNING = 1; // is live
@@ -382,7 +386,7 @@ public void checkKill() {
/**
* @return
*/
- public Mailbox<EObject> mbox() {
+ public EMailbox mbox() {
return mbox;
}
Oops, something went wrong.

0 comments on commit cbc4101

Please sign in to comment.