Changeset 12921


Ignore:
Timestamp:
09/25/10 00:36:29 (11 years ago)
Author:
astalla
Message:

preliminary test of invokedynamic (Java only, no compiler integration)

Location:
branches/invokedynamic/abcl
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/invokedynamic/abcl/build.xml

    r12901 r12921  
    176176      <javac destdir="${build.classes.dir}"
    177177       debug="true"
    178        target="1.5"
     178       target="1.7"
    179179             includeantruntime="false"
    180180       failonerror="true">
     
    247247      classname="org.armedbear.lisp.Main">
    248248        <jvmarg value="-Dabcl.home=${abcl.home.dir}${file.separator}"/>
     249  <jvmarg value="-XX:+UnlockExperimentalVMOptions" />
     250  <jvmarg value="-XX:+EnableInvokeDynamic" />
    249251  <arg value="--noinit"/>
    250252        <arg value="--nosystem"/>
  • branches/invokedynamic/abcl/src/org/armedbear/lisp/Function.java

    r12826 r12921  
    3434package org.armedbear.lisp;
    3535
     36import java.dyn.CallSite;
     37import java.dyn.MethodType;
    3638import static org.armedbear.lisp.Lisp.*;
    3739
     
    394396        ++hotCount;
    395397    }
     398
     399    public static CallSite linkLispFunction(Class caller, String name, MethodType type) {
     400        System.out.println("Linking " + name + " " + caller + " " + type);
     401        CallSite c = ((Symbol) Lisp.readObjectFromString(name)).addCallSite(type);
     402        return c;
     403    }
    396404}
  • branches/invokedynamic/abcl/src/org/armedbear/lisp/LispObject.java

    r12826 r12921  
    3434package org.armedbear.lisp;
    3535
     36import java.dyn.MethodHandle;
     37import java.dyn.MethodHandles;
     38import java.dyn.MethodType;
    3639import static org.armedbear.lisp.Lisp.*;
    3740import java.util.WeakHashMap;
     41import sun.dyn.Access;
    3842
    3943public class LispObject //extends Lisp
     
    839843  }
    840844
     845  public MethodHandle asMethodHandle(MethodType type) {
     846    /*Class<?>[] params = new Class<?>[type.parameterCount()];
     847    if(params.length == 1 && type.parameterType(0).isArray()) {
     848      params[0] = LispObject[].class;
     849    } else for(int i = 0; i < params.length; i++) {
     850      params[i] = LispObject.class;
     851    }*/
     852    MethodHandle mh = MethodHandles.lookup().findVirtual(getClass(), "execute", type.changeReturnType(LispObject.class));
     853    mh = MethodHandles.insertArguments(mh, 0, this);
     854    return mh;//MethodType.methodType(LispObject.class, params));
     855  }
     856
    841857  // Used by COMPILE-MULTIPLE-VALUE-CALL.
    842858  public LispObject dispatch(LispObject[] args)
  • branches/invokedynamic/abcl/src/org/armedbear/lisp/Main.java

    r11391 r12921  
    3434package org.armedbear.lisp;
    3535
     36import java.dyn.InvokeDynamic;
     37import java.dyn.Linkage;
     38
    3639public final class Main
    3740{
    3841  public static final long startTimeMillis = System.currentTimeMillis();
     42
     43  static { Linkage.registerBootstrapMethod(Function.class, "linkLispFunction"); }
    3944
    4045  public static void main(final String[] args)
     
    5257      };
    5358    new Thread(null, r, "interpreter", 4194304L).start();
     59    try {
     60        for(int i = 0; i < 2; i++) {
     61          Thread.sleep(5000);
     62          InvokeDynamic.<LispObject>#"COMMON-LISP:PRINT"((LispObject) new SimpleString("foo"));
     63          InvokeDynamic.<LispObject>#"COMMON-LISP:PRINT"((LispObject) new SimpleString("bar"));
     64          InvokeDynamic.<LispObject>#"CL-USER::FOO"((LispObject) new SimpleString("baz"));
     65        }
     66    } catch(Throwable t) {
     67      t.printStackTrace();
     68    }
     69    //java.dyn.InvokeDynamic.foo(new SimpleString("foo"));
    5470  }
    5571}
  • branches/invokedynamic/abcl/src/org/armedbear/lisp/Symbol.java

    r12749 r12921  
    3434package org.armedbear.lisp;
    3535
     36import java.dyn.CallSite;
     37import java.dyn.MethodType;
     38import java.util.Collections;
     39import java.util.Set;
     40import java.util.WeakHashMap;
    3641import static org.armedbear.lisp.Lisp.*;
    3742
     
    6267  private transient LispObject propertyList;
    6368  private int flags;
     69  private final Set<CallSite> callSites = Collections.newSetFromMap(new WeakHashMap<CallSite, Boolean>()); //Weak, is it correct?
    6470
    6571  // Construct an uninterned symbol.
     
    9399    this.hash = hash;
    94100    this.pkg = pkg;
     101  }
     102
     103  public CallSite addCallSite(MethodType type) {
     104    LispObject f = getSymbolFunctionOrDie();
     105    CallSite c = new CallSite(f.asMethodHandle(type));
     106    synchronized(callSites) {
     107      callSites.add(c);
     108    }
     109    return c;
    95110  }
    96111
     
    405420  public final void setSymbolFunction(LispObject obj)
    406421  {
    407     this.function = obj;
     422    synchronized(callSites) {
     423      this.function = obj;
     424      for(CallSite c : callSites) {
     425        c.setTarget(this.function.asMethodHandle(c.getTarget().type()));
     426      }
     427    }
    408428  }
    409429
Note: See TracChangeset for help on using the changeset viewer.