Changeset 12297


Ignore:
Timestamp:
12/08/09 21:46:36 (13 years ago)
Author:
ehuelsmann
Message:

Implement preloader functionality which allows delaying reflection of compiled function classes.

Location:
branches/fast-boot-preloading/abcl/src/org/armedbear/lisp
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • branches/fast-boot-preloading/abcl/src/org/armedbear/lisp/Autoload.java

    r12288 r12297  
    665665        autoload(PACKAGE_SYS, "zip", "zip", true);
    666666
     667        autoload(PACKAGE_SYS, "proxy-preloaded-function",
     668                 "AutoloadedFunctionProxy", false);
     669        autoload(PACKAGE_SYS, "make-function-preloading-context",
     670                 "AutoloadedFunctionProxy", false);
     671        autoload(PACKAGE_SYS, "function-preload",
     672                 "AutoloadedFunctionProxy", false);
     673
    667674        autoload(Symbol.COPY_LIST, "copy_list");
    668675
  • branches/fast-boot-preloading/abcl/src/org/armedbear/lisp/CompiledClosure.java

    r12288 r12297  
    220220      else if (arg instanceof AbstractString)
    221221        namestring = arg.getStringValue();
    222       if (namestring != null)
    223         return loadCompiledFunction(namestring);
     222      if (namestring != null) {
     223          //    Debug.trace("autoloading preloaded ... " + namestring);
     224        return AutoloadedFunctionProxy.loadPreloadedFunction(namestring);
     225      }
    224226      if(arg instanceof JavaObject) {
    225227    try {
    226         return loadCompiledFunction((byte[]) arg.javaInstance(byte[].class));
     228        return loadClassBytes((byte[]) arg.javaInstance(byte[].class));
    227229    } catch(Throwable t) {
    228230        Debug.trace(t);
  • branches/fast-boot-preloading/abcl/src/org/armedbear/lisp/Lisp.java

    r12288 r12297  
    12251225
    12261226  {
     1227    try {
     1228      byte[] bytes = readFunctionBytes(namestring);
     1229      if (bytes != null)
     1230        return loadClassBytes(bytes);
     1231    }
     1232    catch (VerifyError e)
     1233    {
     1234      return error(new LispError("Class verification failed: " +
     1235                                 e.getMessage()));
     1236    }
     1237    catch (Throwable t)
     1238      {
     1239        Debug.trace(t);
     1240      }
     1241    return error(new FileError("File not found: " + namestring,
     1242                                new Pathname(namestring)));
     1243  }
     1244
     1245  public static final byte[] readFunctionBytes(final String namestring)
     1246  {
    12271247    final LispThread thread = LispThread.currentThread();
    12281248    final boolean absolute = Utilities.isFilenameAbsolute(namestring);
     
    12971317                                long size = entry.getSize();
    12981318                                InputStream in = zipFile.getInputStream(entry);
    1299                                 LispObject obj = loadCompiledFunction(in, (int) size);
    1300                                 return obj != null ? obj : NIL;
     1319                                return readFunctionBytes(in, (int) size);
    13011320                              }
    13021321                            else
     
    13061325                                  = defaultPathname.name.getStringValue()
    13071326                                  + "." +  "abcl";//defaultPathname.type.getStringValue();
    1308                                 byte in[]
    1309                                   = Utilities
    1310                                   .getZippedZipEntryAsByteArray(zipFile,
     1327                                return Utilities
     1328                                  .getZippedZipEntryAsByteArray(zipFile,
    13111329                                                                entryName,
    13121330                                                                namestring);
    1313                                 LispObject o = loadCompiledFunction(in);
    1314                                 return o != null ? o : NIL;
    13151331                              }
    13161332                          }
     
    13241340            catch (VerifyError e)
    13251341              {
    1326                 return error(new LispError("Class verification failed: " +
    1327                                             e.getMessage()));
     1342                error(new LispError("Class verification failed: " +
     1343                                    e.getMessage()));
     1344                return null; // not reached
    13281345              }
    13291346            catch (IOException e)
     
    13361353              }
    13371354          }
    1338         return error(new LispError("Unable to load " + namestring));
     1355        error(new LispError("Unable to load " + namestring));
     1356        return null; // not reached
    13391357      }
    13401358    Pathname pathname = new Pathname(namestring);
     
    13451363        try
    13461364          {
    1347             LispObject obj = loadCompiledFunction(new FileInputStream(file),
    1348                                                   (int) file.length());
     1365            byte[] bytes = readFunctionBytes(new FileInputStream(file),
     1366                                             (int) file.length());
    13491367            // FIXME close stream!
    1350             if (obj != null)
    1351               return obj;
     1368            if (bytes != null)
     1369              return bytes;
    13521370          }
    13531371        catch (VerifyError e)
    13541372          {
    1355             return error(new LispError("Class verification failed: " +
    1356                                         e.getMessage()));
     1373            error(new LispError("Class verification failed: " +
     1374                                e.getMessage()));
     1375            return null; // not reached
    13571376          }
    13581377        catch (Throwable t)
     
    13601379            Debug.trace(t);
    13611380          }
    1362         return error(new LispError("Unable to load " +
    1363                                     pathname.writeToString()));
     1381        error(new LispError("Unable to load " + pathname.writeToString()));
     1382        return null; // not reached
    13641383      }
    13651384    try
     
    13731392            if (entry != null)
    13741393              {
    1375                 LispObject obj = loadCompiledFunction(zipFile.getInputStream(entry),
    1376                                                       (int) entry.getSize());
    1377                 if (obj != null)
    1378                   return obj;
     1394                byte[] bytes = readFunctionBytes(zipFile.getInputStream(entry),
     1395                                                 (int) entry.getSize());
     1396                if (bytes != null)
     1397                  return bytes;
    13791398                Debug.trace("Unable to load " + namestring);
    1380                 return error(new LispError("Unable to load " + namestring));
     1399                error(new LispError("Unable to load " + namestring));
     1400                return null; // not reached
    13811401              }
    13821402          }
     
    13901410        Debug.trace(t);
    13911411      }
    1392     return error(new FileError("File not found: " + namestring,
    1393                                 new Pathname(namestring)));
    1394   }
    1395 
    1396     public static final LispObject makeCompiledFunctionFromClass(Class<?> c)
    1397   throws Exception {
     1412    error(new FileError("File not found: " + namestring,
     1413                        new Pathname(namestring)));
     1414    return null; // not reached
     1415  }
     1416
     1417    public static final Function makeCompiledFunctionFromClass(Class<?> c) {
     1418      try {
    13981419  if (c != null) {
    1399       LispObject obj = (LispObject)c.newInstance();
     1420      Function obj = (Function)c.newInstance();
    14001421      return obj;
    14011422        } else {
    14021423            return null;
    14031424        }
     1425      }
     1426      catch (InstantiationException e) {} // ### FIXME
     1427      catch (IllegalAccessException e) {} // ### FIXME
     1428
     1429      return null;
    14041430    }
    14051431
    1406   private static final LispObject loadCompiledFunction(InputStream in, int size)
     1432
     1433  public static final LispObject loadCompiledFunction(InputStream in, int size)
     1434  {
     1435    try {
     1436      byte[] bytes = readFunctionBytes(in, size);
     1437      if (bytes != null)
     1438        return loadClassBytes(bytes);
     1439    }
     1440    catch (VerifyError e)
     1441    {
     1442      return error(new LispError("Class verification failed: " +
     1443                                 e.getMessage()));
     1444    }
     1445    catch (Throwable t)
     1446      {
     1447        Debug.trace(t);
     1448      }
     1449    return error(new FileError("Can't read file off stream."));
     1450  }
     1451
     1452
     1453
     1454  private static final byte[] readFunctionBytes(InputStream in, int size)
    14071455  {
    14081456    try
     
    14231471          Debug.trace("bytesRemaining = " + bytesRemaining);
    14241472
    1425         return loadCompiledFunction(bytes);
     1473        return bytes;
    14261474      }
    14271475    catch (Throwable t)
     
    14321480  }
    14331481
    1434     public static final LispObject loadCompiledFunction(byte[] bytes) throws Throwable {
    1435   return loadCompiledFunction(bytes, new JavaClassLoader());
     1482    public static final Function loadClassBytes(byte[] bytes)
     1483        throws Throwable
     1484    {
     1485  return loadClassBytes(bytes, new JavaClassLoader());
    14361486    }
    14371487
    1438     public static final LispObject loadCompiledFunction(byte[] bytes, JavaClassLoader cl) throws Throwable {
     1488    public static final Function loadClassBytes(byte[] bytes,
     1489                                                JavaClassLoader cl)
     1490        throws Throwable
     1491    {
    14391492        Class<?> c = cl.loadClassFromByteArray(null, bytes, 0, bytes.length);
    1440   LispObject obj = makeCompiledFunctionFromClass(c);
    1441   if (obj instanceof Function) {
    1442       ((Function)obj).setClassBytes(bytes);
     1493  Function obj = makeCompiledFunctionFromClass(c);
     1494  if (obj != null) {
     1495      obj.setClassBytes(bytes);
    14431496  }
    14441497  return obj;
     
    24722525    exportSpecial("*AUTOLOAD-VERBOSE*", PACKAGE_EXT, NIL);
    24732526
     2527  // ### *preloading-cache*
     2528 public static final Symbol AUTOLOADING_CACHE =
     2529   internSpecial("*AUTOLOADING-CACHE*", PACKAGE_SYS, NIL);
     2530
    24742531  // ### *compile-file-type*
    24752532  public static final String COMPILE_FILE_TYPE = "abcl";
  • branches/fast-boot-preloading/abcl/src/org/armedbear/lisp/Load.java

    r12290 r12297  
    4545import java.net.URL;
    4646import java.net.URLDecoder;
     47import java.util.Hashtable;
    4748import java.util.zip.ZipEntry;
    4849import java.util.zip.ZipException;
     
    609610        try {
    610611            thread.bindSpecial(_FASL_ANONYMOUS_PACKAGE_, new Package());
     612            thread.bindSpecial(AUTOLOADING_CACHE,
     613                               AutoloadedFunctionProxy.makePreloadingContext());
    611614            while (true) {
    612615                LispObject obj = in.faslRead(false, EOF, true, thread);
  • branches/fast-boot-preloading/abcl/src/org/armedbear/lisp/Symbol.java

    r12288 r12297  
    30313031  public static final Symbol FSET =
    30323032    PACKAGE_SYS.addInternalSymbol("FSET");
     3033  public static final Symbol FUNCTION_PRELOAD =
     3034    PACKAGE_SYS.addInternalSymbol("FUNCTION-PRELOAD");
    30333035  public static final Symbol INSTANCE =
    30343036    PACKAGE_SYS.addInternalSymbol("INSTANCE");
    30353037  public static final Symbol MACROEXPAND_MACRO =
    30363038    PACKAGE_SYS.addInternalSymbol("MACROEXPAND-MACRO");
     3039  public static final Symbol MAKE_FUNCTION_PRELOADING_CONTEXT =
     3040    PACKAGE_SYS.addInternalSymbol("MAKE-FUNCTION-PRELOADING-CONTEXT");
    30373041  public static final Symbol NAME =
    30383042    PACKAGE_SYS.addInternalSymbol("NAME");
     
    30433047  public static final Symbol OPERATION =
    30443048    PACKAGE_SYS.addInternalSymbol("OPERATION");
     3049  public static final Symbol PROXY_PRELOADED_FUNCTION =
     3050    PACKAGE_SYS.addInternalSymbol("PROXY-PRELOADED-FUNCTION");
    30453051  public static final Symbol _SOURCE =
    30463052    PACKAGE_SYS.addInternalSymbol("%SOURCE");
  • branches/fast-boot-preloading/abcl/src/org/armedbear/lisp/compile-file.lisp

    r12229 r12297  
    161161                      (setf form
    162162                            `(fset ',name
    163                                    (load-compiled-function ,(file-namestring classfile))
     163                                   (proxy-preloaded-function ',name ,(file-namestring classfile))
    164164                                   ,*source-position*
    165165                                   ',lambda-list
     
    485485         (temp-file (merge-pathnames (make-pathname :type (concatenate 'string type "-tmp"))
    486486                                     output-file))
     487         (temp-file2 (merge-pathnames (make-pathname :type (concatenate 'string type "-tmp2"))
     488                                     output-file))
    487489         (warnings-p nil)
    488490         (failure-p nil))
     
    511513              (jvm::with-saved-compiler-policy
    512514                  (jvm::with-file-compilation
    513                       (write "; -*- Mode: Lisp -*-" :escape nil :stream out)
    514                     (%stream-terpri out)
    515                     (let ((*package* (find-package '#:cl)))
    516                       (write (list 'init-fasl :version *fasl-version*)
    517                              :stream out)
    518                       (%stream-terpri out)
    519                       (write (list 'setq '*source* *compile-file-truename*)
    520                              :stream out)
    521                       (%stream-terpri out))
    522515                    (handler-bind ((style-warning #'(lambda (c)
    523516                                                      (setf warnings-p t)
     
    545538                    (dolist (name *fbound-names*)
    546539                      (fmakunbound name)))))))
    547         (rename-file temp-file output-file)
     540        (with-open-file (in temp-file :direction :input)
     541          (with-open-file (out temp-file2 :direction :output
     542                               :if-does-not-exist :create
     543                               :if-exists :supersede)
     544            ;; write header
     545            (write "; -*- Mode: Lisp -*-" :escape nil :stream out)
     546            (%stream-terpri out)
     547            (let ((*package* (find-package '#:cl))
     548                  (count-sym (gensym)))
     549              (write (list 'init-fasl :version *fasl-version*)
     550                     :stream out)
     551              (%stream-terpri out)
     552              (write (list 'setq '*source* *compile-file-truename*)
     553                     :stream out)
     554              (%stream-terpri out)
     555              (dump-form `(dotimes (,count-sym ,*class-number*)
     556                            (function-preload
     557                             (%format nil "~A-~D.cls" ,(pathname-name output-file)
     558                                      (1+ ,count-sym)))) out)
     559              (%stream-terpri out))
     560
     561
     562            ;; copy remaining content
     563            (loop for line = (read-line in nil :eof)
     564               while (not (eq line :eof))
     565               do (write-line line out))))
     566        (delete-file temp-file)
     567        (rename-file temp-file2 output-file)
    548568
    549569        (when *compile-file-zip*
  • branches/fast-boot-preloading/abcl/src/org/armedbear/lisp/compiler-pass2.lisp

    r12272 r12297  
    20712071     (declare-field g +lisp-object+ +field-access-default+)
    20722072     (emit 'ldc (pool-string (file-namestring pathname)))
    2073      (emit-invokestatic +lisp-class+ "loadCompiledFunction"
     2073     (emit-invokestatic "org/armedbear/lisp/AutoloadedFunctionProxy" "loadPreloadedFunction"
    20742074      (list +java-string+) +lisp-object+)
    20752075     (emit 'putstatic *this-class* g +lisp-object+)
Note: See TracChangeset for help on using the changeset viewer.