Changeset 12306


Ignore:
Timestamp:
12/25/09 21:52:23 (14 years ago)
Author:
ehuelsmann
Message:

Land fast-boot-preloading branch on trunk.

Note: things to do include

  1. Applying the same strategy to macro functions
  2. Applying the same strategy to functions which get loaded during

EVAL-WHEN when compiling

Location:
trunk/abcl/src/org/armedbear/lisp
Files:
7 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/abcl/src/org/armedbear/lisp/Autoload.java

    r12288 r12306  
    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
  • trunk/abcl/src/org/armedbear/lisp/CompiledClosure.java

    r12288 r12306  
    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);
  • trunk/abcl/src/org/armedbear/lisp/Lisp.java

    r12298 r12306  
    289289            throw c;
    290290          }
    291         catch (Throwable t)
     291        catch (Throwable t) // ControlTransfer handled above
    292292          {
    293293            Debug.trace(t);
     
    12051205
    12061206  {
     1207      byte[] bytes = readFunctionBytes(namestring);
     1208      if (bytes != null)
     1209        return loadClassBytes(bytes);
     1210
     1211      return null;
     1212  }
     1213
     1214  public static final byte[] readFunctionBytes(final String namestring)
     1215  {
    12071216    final LispThread thread = LispThread.currentThread();
    12081217    final boolean absolute = Utilities.isFilenameAbsolute(namestring);
     
    12771286                                long size = entry.getSize();
    12781287                                InputStream in = zipFile.getInputStream(entry);
    1279                                 LispObject obj = loadCompiledFunction(in, (int) size);
    1280                                 return obj != null ? obj : NIL;
     1288                                return readFunctionBytes(in, (int) size);
    12811289                              }
    12821290                            else
     
    12861294                                  = defaultPathname.name.getStringValue()
    12871295                                  + "." +  "abcl";//defaultPathname.type.getStringValue();
    1288                                 byte in[]
    1289                                   = Utilities
    1290                                   .getZippedZipEntryAsByteArray(zipFile,
     1296                                return Utilities
     1297                                  .getZippedZipEntryAsByteArray(zipFile,
    12911298                                                                entryName,
    12921299                                                                namestring);
    1293                                 LispObject o = loadCompiledFunction(in);
    1294                                 return o != null ? o : NIL;
    12951300                              }
    12961301                          }
     
    13021307                  }
    13031308              }
     1309            catch (VerifyError e)
     1310              {
     1311                error(new LispError("Class verification failed: " +
     1312                                    e.getMessage()));
     1313                return null; // not reached
     1314              }
    13041315            catch (IOException e)
    13051316              {
     
    13071318              }
    13081319          }
    1309         return error(new LispError("Unable to load " + namestring));
     1320        error(new LispError("Unable to load " + namestring));
     1321        return null; // not reached
    13101322      }
    13111323    Pathname pathname = new Pathname(namestring);
     
    13141326      {
    13151327        // The .cls file exists.
    1316         LispObject obj = null;
    1317         try {
    1318             obj = loadCompiledFunction(new FileInputStream(file),
    1319                                        (int) file.length());
     1328        try
     1329          {
     1330            byte[] bytes = readFunctionBytes(new FileInputStream(file),
     1331                                             (int) file.length());
     1332            // FIXME close stream!
     1333            if (bytes != null)
     1334              return bytes;
     1335          }
     1336        catch (FileNotFoundException fnf) {
     1337            error(new LispError("Unable to load " + pathname.writeToString()
     1338                                + ": " + fnf.getMessage()));
     1339            return null; // not reached
    13201340        }
    1321         catch (FileNotFoundException e) {
    1322             return error(new LispError("Unable to load " +
    1323                          pathname.writeToString() + ": Not found."));
     1341        return null; // not reached
     1342      }
     1343    try
     1344      {
     1345        LispObject loadTruename = Symbol.LOAD_TRUENAME.symbolValue(thread);
     1346        String zipFileName = ((Pathname)loadTruename).getNamestring();
     1347        ZipFile zipFile = ZipCache.getZip(zipFileName);
     1348        try
     1349          {
     1350            ZipEntry entry = zipFile.getEntry(namestring);
     1351            if (entry != null)
     1352              {
     1353                byte[] bytes = readFunctionBytes(zipFile.getInputStream(entry),
     1354                                                 (int) entry.getSize());
     1355                if (bytes != null)
     1356                  return bytes;
     1357                Debug.trace("Unable to load " + namestring);
     1358                error(new LispError("Unable to load " + namestring));
     1359                return null; // not reached
     1360              }
     1361          }
     1362        finally
     1363          {
     1364            ZipCache.removeZip(zipFile.getName());
     1365          }
     1366      }
     1367    catch (IOException t)
     1368      {
     1369        Debug.trace(t);
     1370      }
     1371    error(new FileError("File not found: " + namestring,
     1372                        new Pathname(namestring)));
     1373    return null; // not reached
     1374  }
     1375
     1376    public static final Function makeCompiledFunctionFromClass(Class<?> c) {
     1377      try {
     1378  if (c != null) {
     1379      Function obj = (Function)c.newInstance();
     1380      return obj;
     1381        } else {
     1382            return null;
    13241383        }
    1325         // FIXME close stream!
    1326         if (obj != null)
    1327           return obj;
    1328         return error(new LispError("Unable to load " +
    1329                                     pathname.writeToString()));
    1330       }
    1331     LispObject loadTruename = Symbol.LOAD_TRUENAME.symbolValue(thread);
    1332     String zipFileName = ((Pathname)loadTruename).getNamestring();
    1333     ZipFile zipFile = null;
     1384      }
     1385      catch (InstantiationException e) {} // ### FIXME
     1386      catch (IllegalAccessException e) {} // ### FIXME
     1387
     1388      return null;
     1389    }
     1390
     1391
     1392  public static final LispObject loadCompiledFunction(InputStream in, int size)
     1393  {
     1394      byte[] bytes = readFunctionBytes(in, size);
     1395      if (bytes != null)
     1396        return loadClassBytes(bytes);
     1397      else
     1398        return error(new FileError("Can't read file off stream."));
     1399  }
     1400
     1401
     1402
     1403  private static final byte[] readFunctionBytes(InputStream in, int size)
     1404  {
    13341405    try
    13351406      {
    1336         zipFile = ZipCache.getZip(zipFileName);
    1337         ZipEntry entry = zipFile.getEntry(namestring);
    1338         if (entry != null)
    1339           {
    1340             LispObject obj = null;
    1341             try {
    1342                 obj = loadCompiledFunction(zipFile.getInputStream(entry),
    1343                                                   (int) entry.getSize());
    1344             }
    1345             catch (IOException ignore) { };
    1346             if (obj != null)
    1347               return obj;
    1348             Debug.trace("Unable to load " + namestring);
    1349             return error(new LispError("Unable to load " + namestring));
    1350           }
    1351       }
    1352     catch (IOException ignore) {
    1353         //ignore IOException from ZipCache.getZip()
    1354     }
    1355     finally
    1356       {
    1357         try {
    1358             ZipCache.removeZip(zipFile.getName());
    1359         }
    1360         catch (IOException ignore) { } // ignore
    1361       }
    1362     return error(new FileError("File not found: " + namestring,
    1363                                 new Pathname(namestring)));
    1364   }
    1365 
    1366     public static final LispObject makeCompiledFunctionFromClass(Class<?> c) {
    1367   if (c != null)
    1368         try {
    1369             return (LispObject)c.newInstance();
    1370         }
    1371         catch (InstantiationException ignore) {
    1372             // ignore
    1373         }
    1374         catch (IllegalAccessException ignore) {
    1375             // ignore
    1376         }
    1377     return null;
    1378     }
    1379 
    1380   private static final LispObject loadCompiledFunction(InputStream in, int size)
    1381   {
    1382     byte[] bytes = new byte[size];
    1383     int bytesRemaining = size;
    1384     int bytesRead = 0;
    1385     try {
     1407        byte[] bytes = new byte[size];
     1408        int bytesRemaining = size;
     1409        int bytesRead = 0;
    13861410        while (bytesRemaining > 0)
    13871411          {
     
    13931417          }
    13941418        in.close();
     1419        if (bytesRemaining > 0)
     1420          Debug.trace("bytesRemaining = " + bytesRemaining);
     1421
     1422        return bytes;
     1423      }
     1424    catch (IOException t)
     1425      {
     1426        Debug.trace(t); // FIXME: call error()?
     1427      }
     1428    return null;
     1429  }
     1430
     1431    public static final Function loadClassBytes(byte[] bytes)
     1432    {
     1433      return loadClassBytes(bytes, new JavaClassLoader());
    13951434    }
    1396     catch (IOException e) {
    1397         return null; // fixme: return an error?
    1398     }
    1399     if (bytesRemaining > 0)
    1400       Debug.trace("bytesRemaining = " + bytesRemaining);
    1401 
    1402     return loadCompiledFunction(bytes);
    1403   }
    1404 
    1405     public static final LispObject loadCompiledFunction(byte[] bytes) {
    1406         return loadCompiledFunction(bytes, new JavaClassLoader());
    1407     }
    1408 
    1409     public static final LispObject loadCompiledFunction(byte[] bytes, JavaClassLoader cl) {
     1435
     1436    public static final Function loadClassBytes(byte[] bytes,
     1437                                                JavaClassLoader cl)
     1438    {
    14101439        Class<?> c = cl.loadClassFromByteArray(null, bytes, 0, bytes.length);
    1411         LispObject obj = makeCompiledFunctionFromClass(c);
    1412         if (obj instanceof Function) {
    1413             ((Function)obj).setClassBytes(bytes);
    1414         }
    1415         return obj;
     1440  Function obj = makeCompiledFunctionFromClass(c);
     1441  if (obj != null) {
     1442      obj.setClassBytes(bytes);
     1443  }
     1444  return obj;
    14161445    }
    14171446
     
    24432472    exportSpecial("*AUTOLOAD-VERBOSE*", PACKAGE_EXT, NIL);
    24442473
     2474  // ### *preloading-cache*
     2475 public static final Symbol AUTOLOADING_CACHE =
     2476   internSpecial("*AUTOLOADING-CACHE*", PACKAGE_SYS, NIL);
     2477
    24452478  // ### *compile-file-type*
    24462479  public static final String COMPILE_FILE_TYPE = "abcl";
  • trunk/abcl/src/org/armedbear/lisp/Load.java

    r12298 r12306  
    4545import java.net.URL;
    4646import java.net.URLDecoder;
     47import java.util.Hashtable;
    4748import java.util.zip.ZipEntry;
    4849import java.util.zip.ZipException;
     
    607608        try {
    608609            thread.bindSpecial(_FASL_ANONYMOUS_PACKAGE_, new Package());
     610            thread.bindSpecial(AUTOLOADING_CACHE,
     611                               AutoloadedFunctionProxy.makePreloadingContext());
    609612            while (true) {
    610613                LispObject obj = in.faslRead(false, EOF, true, thread);
  • trunk/abcl/src/org/armedbear/lisp/Symbol.java

    r12298 r12306  
    30153015  public static final Symbol FSET =
    30163016    PACKAGE_SYS.addInternalSymbol("FSET");
     3017  public static final Symbol FUNCTION_PRELOAD =
     3018    PACKAGE_SYS.addInternalSymbol("FUNCTION-PRELOAD");
    30173019  public static final Symbol INSTANCE =
    30183020    PACKAGE_SYS.addInternalSymbol("INSTANCE");
    30193021  public static final Symbol MACROEXPAND_MACRO =
    30203022    PACKAGE_SYS.addInternalSymbol("MACROEXPAND-MACRO");
     3023  public static final Symbol MAKE_FUNCTION_PRELOADING_CONTEXT =
     3024    PACKAGE_SYS.addInternalSymbol("MAKE-FUNCTION-PRELOADING-CONTEXT");
    30213025  public static final Symbol NAME =
    30223026    PACKAGE_SYS.addInternalSymbol("NAME");
     
    30273031  public static final Symbol OPERATION =
    30283032    PACKAGE_SYS.addInternalSymbol("OPERATION");
     3033  public static final Symbol PROXY_PRELOADED_FUNCTION =
     3034    PACKAGE_SYS.addInternalSymbol("PROXY-PRELOADED-FUNCTION");
    30293035  public static final Symbol _SOURCE =
    30303036    PACKAGE_SYS.addInternalSymbol("%SOURCE");
  • trunk/abcl/src/org/armedbear/lisp/compile-file.lisp

    r12229 r12306  
    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*
  • trunk/abcl/src/org/armedbear/lisp/compiler-pass2.lisp

    r12272 r12306  
    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.