[armedbear-cvs] r12921 - in branches/invokedynamic/abcl: . src/org/armedbear/lisp
Alessio Stalla
astalla at common-lisp.net
Sat Sep 25 00:36:30 UTC 2010
Author: astalla
Date: Fri Sep 24 20:36:29 2010
New Revision: 12921
Log:
preliminary test of invokedynamic (Java only, no compiler integration)
Modified:
branches/invokedynamic/abcl/build.xml
branches/invokedynamic/abcl/src/org/armedbear/lisp/Function.java
branches/invokedynamic/abcl/src/org/armedbear/lisp/LispObject.java
branches/invokedynamic/abcl/src/org/armedbear/lisp/Main.java
branches/invokedynamic/abcl/src/org/armedbear/lisp/Symbol.java
Modified: branches/invokedynamic/abcl/build.xml
==============================================================================
--- branches/invokedynamic/abcl/build.xml (original)
+++ branches/invokedynamic/abcl/build.xml Fri Sep 24 20:36:29 2010
@@ -175,7 +175,7 @@
<mkdir dir="${build.classes.dir}"/>
<javac destdir="${build.classes.dir}"
debug="true"
- target="1.5"
+ target="1.7"
includeantruntime="false"
failonerror="true">
<src path="${src.dir}"/>
@@ -246,6 +246,8 @@
inputstring="(handler-case (compile-system :zip nil :quit t :output-path "${abcl.lisp.output}/") (t (x) (progn (format t "~A: ~A~%" (type-of x) x) (exit :status -1))))"
classname="org.armedbear.lisp.Main">
<jvmarg value="-Dabcl.home=${abcl.home.dir}${file.separator}"/>
+ <jvmarg value="-XX:+UnlockExperimentalVMOptions" />
+ <jvmarg value="-XX:+EnableInvokeDynamic" />
<arg value="--noinit"/>
<arg value="--nosystem"/>
<arg value="--eval"/>
Modified: branches/invokedynamic/abcl/src/org/armedbear/lisp/Function.java
==============================================================================
--- branches/invokedynamic/abcl/src/org/armedbear/lisp/Function.java (original)
+++ branches/invokedynamic/abcl/src/org/armedbear/lisp/Function.java Fri Sep 24 20:36:29 2010
@@ -33,6 +33,8 @@
package org.armedbear.lisp;
+import java.dyn.CallSite;
+import java.dyn.MethodType;
import static org.armedbear.lisp.Lisp.*;
public abstract class Function extends Operator
@@ -393,4 +395,10 @@
{
++hotCount;
}
+
+ public static CallSite linkLispFunction(Class caller, String name, MethodType type) {
+ System.out.println("Linking " + name + " " + caller + " " + type);
+ CallSite c = ((Symbol) Lisp.readObjectFromString(name)).addCallSite(type);
+ return c;
+ }
}
Modified: branches/invokedynamic/abcl/src/org/armedbear/lisp/LispObject.java
==============================================================================
--- branches/invokedynamic/abcl/src/org/armedbear/lisp/LispObject.java (original)
+++ branches/invokedynamic/abcl/src/org/armedbear/lisp/LispObject.java Fri Sep 24 20:36:29 2010
@@ -33,8 +33,12 @@
package org.armedbear.lisp;
+import java.dyn.MethodHandle;
+import java.dyn.MethodHandles;
+import java.dyn.MethodType;
import static org.armedbear.lisp.Lisp.*;
import java.util.WeakHashMap;
+import sun.dyn.Access;
public class LispObject //extends Lisp
{
@@ -838,6 +842,18 @@
return type_error(this, Symbol.FUNCTION);
}
+ public MethodHandle asMethodHandle(MethodType type) {
+ /*Class<?>[] params = new Class<?>[type.parameterCount()];
+ if(params.length == 1 && type.parameterType(0).isArray()) {
+ params[0] = LispObject[].class;
+ } else for(int i = 0; i < params.length; i++) {
+ params[i] = LispObject.class;
+ }*/
+ MethodHandle mh = MethodHandles.lookup().findVirtual(getClass(), "execute", type.changeReturnType(LispObject.class));
+ mh = MethodHandles.insertArguments(mh, 0, this);
+ return mh;//MethodType.methodType(LispObject.class, params));
+ }
+
// Used by COMPILE-MULTIPLE-VALUE-CALL.
public LispObject dispatch(LispObject[] args)
{
Modified: branches/invokedynamic/abcl/src/org/armedbear/lisp/Main.java
==============================================================================
--- branches/invokedynamic/abcl/src/org/armedbear/lisp/Main.java (original)
+++ branches/invokedynamic/abcl/src/org/armedbear/lisp/Main.java Fri Sep 24 20:36:29 2010
@@ -33,10 +33,15 @@
package org.armedbear.lisp;
+import java.dyn.InvokeDynamic;
+import java.dyn.Linkage;
+
public final class Main
{
public static final long startTimeMillis = System.currentTimeMillis();
+ static { Linkage.registerBootstrapMethod(Function.class, "linkLispFunction"); }
+
public static void main(final String[] args)
{
// Run the interpreter in a secondary thread so we can control the stack
@@ -51,5 +56,16 @@
}
};
new Thread(null, r, "interpreter", 4194304L).start();
+ try {
+ for(int i = 0; i < 2; i++) {
+ Thread.sleep(5000);
+ InvokeDynamic.<LispObject>#"COMMON-LISP:PRINT"((LispObject) new SimpleString("foo"));
+ InvokeDynamic.<LispObject>#"COMMON-LISP:PRINT"((LispObject) new SimpleString("bar"));
+ InvokeDynamic.<LispObject>#"CL-USER::FOO"((LispObject) new SimpleString("baz"));
+ }
+ } catch(Throwable t) {
+ t.printStackTrace();
+ }
+ //java.dyn.InvokeDynamic.foo(new SimpleString("foo"));
}
}
Modified: branches/invokedynamic/abcl/src/org/armedbear/lisp/Symbol.java
==============================================================================
--- branches/invokedynamic/abcl/src/org/armedbear/lisp/Symbol.java (original)
+++ branches/invokedynamic/abcl/src/org/armedbear/lisp/Symbol.java Fri Sep 24 20:36:29 2010
@@ -33,6 +33,11 @@
package org.armedbear.lisp;
+import java.dyn.CallSite;
+import java.dyn.MethodType;
+import java.util.Collections;
+import java.util.Set;
+import java.util.WeakHashMap;
import static org.armedbear.lisp.Lisp.*;
public class Symbol extends LispObject implements java.io.Serializable
@@ -61,6 +66,7 @@
private transient LispObject function;
private transient LispObject propertyList;
private int flags;
+ private final Set<CallSite> callSites = Collections.newSetFromMap(new WeakHashMap<CallSite, Boolean>()); //Weak, is it correct?
// Construct an uninterned symbol.
public Symbol(String s)
@@ -94,6 +100,15 @@
this.pkg = pkg;
}
+ public CallSite addCallSite(MethodType type) {
+ LispObject f = getSymbolFunctionOrDie();
+ CallSite c = new CallSite(f.asMethodHandle(type));
+ synchronized(callSites) {
+ callSites.add(c);
+ }
+ return c;
+ }
+
@Override
public LispObject typeOf()
{
@@ -404,7 +419,12 @@
public final void setSymbolFunction(LispObject obj)
{
- this.function = obj;
+ synchronized(callSites) {
+ this.function = obj;
+ for(CallSite c : callSites) {
+ c.setTarget(this.function.asMethodHandle(c.getTarget().type()));
+ }
+ }
}
/** See LispObject.getStringValue() */
More information about the armedbear-cvs
mailing list