Changeset 15363
- Timestamp:
- 08/06/20 16:03:15 (3 years ago)
- Location:
- trunk/abcl
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/abcl/abcl.asd
r15341 r15363 58 58 (:file "runtime-class") 59 59 #+abcl 60 (:file "package-local-nicknames-tests"))))) 60 (:file "package-local-nicknames-tests") 61 #+abcl 62 (:file "closure-serialization"))))) 61 63 62 64 ;;; FIXME Currently requires ACBL-CONTRIB and QUICKLISP-ABCL to be -
trunk/abcl/src/org/armedbear/lisp/Function.java
r15361 r15363 195 195 196 196 public final LispObject getClassBytes() { 197 198 199 200 201 202 if(c instanceof FaslClassLoader) {203 final LispThread thread = LispThread.currentThread(); 204 SpecialBindingsMark mark = thread.markSpecialBindings(); 205 try { 206 thread.bindSpecial(Symbol.LOAD_TRUENAME, loadedFrom); 207 return new JavaObject(((FaslClassLoader) c).getFunctionClassBytes(this));208 209 210 211 212 213 214 215 216 } finally { 217 thread.resetSpecialBindings(mark); 218 } 219 220 221 222 197 LispObject o = getf(propertyList, Symbol.CLASS_BYTES, NIL); 198 if(o != NIL) { 199 return o; 200 } else { 201 ClassLoader c = getClass().getClassLoader(); 202 if(c instanceof JavaClassLoader) { 203 final LispThread thread = LispThread.currentThread(); 204 SpecialBindingsMark mark = thread.markSpecialBindings(); 205 try { 206 thread.bindSpecial(Symbol.LOAD_TRUENAME, loadedFrom); 207 return new JavaObject(((JavaClassLoader) c).getFunctionClassBytes(this)); 208 } catch(Throwable t) { 209 //This is because unfortunately getFunctionClassBytes uses 210 //Debug.assertTrue(false) to signal errors 211 if(t instanceof ControlTransfer) { 212 throw (ControlTransfer) t; 213 } else { 214 return NIL; 215 } 216 } finally { 217 thread.resetSpecialBindings(mark); 218 } 219 } else { 220 return NIL; 221 } 222 } 223 223 } 224 224 … … 402 402 } 403 403 404 public static class ObjectInputStreamWithClassLoader extends ObjectInputStream { 405 private final ClassLoader classLoader; 406 public ObjectInputStreamWithClassLoader(InputStream in, ClassLoader classLoader) throws IOException { 407 super(in); 408 this.classLoader = classLoader; 409 } 410 411 @Override 412 protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException { 413 return Class.forName(desc.getName(), false, classLoader); 414 } 415 } 416 404 417 public static class SerializedLocalFunction implements Serializable { 405 418 final LispObject className; … … 408 421 409 422 public SerializedLocalFunction(Function function) { 410 this.className = JavaObject.getInstance(function.getClass().getName());423 this.className = new SimpleString(function.getClass().getName()); 411 424 this.classBytes = function.getClassBytes(); 412 425 serializingClosure.set(true); … … 425 438 MemoryClassLoader loader = new MemoryClassLoader(); 426 439 MemoryClassLoader.PUT_MEMORY_FUNCTION.execute(JavaObject.getInstance(loader), className, classBytes); 427 Thread thread = Thread.currentThread();428 ClassLoader oldLoader = thread.getContextClassLoader();429 440 try { 430 thread.setContextClassLoader(loader);431 return new ObjectInputStream (new ByteArrayInputStream(serializedFunction)).readObject();441 ByteArrayInputStream in = new ByteArrayInputStream(serializedFunction); 442 return new ObjectInputStreamWithClassLoader(in, loader).readObject(); 432 443 } catch (Exception e) { 433 444 InvalidObjectException ex = new InvalidObjectException("Could not read the serialized function back"); 434 445 ex.initCause(e); 435 446 throw ex; 436 } finally {437 thread.setContextClassLoader(oldLoader);438 447 } 439 448 } … … 445 454 if(shouldSerializeByName()) { 446 455 return new SerializedNamedFunction((Symbol) getLambdaName()); 447 } else if(serializingClosure.get() != null) { 456 } else if(getClassBytes() == NIL || serializingClosure.get() != null) { 457 return this; 458 } else { 448 459 return new SerializedLocalFunction(this); 449 } else {450 return this;451 460 } 452 461 } -
trunk/abcl/src/org/armedbear/lisp/JavaObject.java
r15234 r15363 36 36 import static org.armedbear.lisp.Lisp.*; 37 37 38 import java.io.Serializable; 38 39 import java.lang.reflect.Array; 39 40 import java.lang.reflect.Field; … … 41 42 import java.util.*; 42 43 43 public final class JavaObject extends LispObject {44 public final class JavaObject extends LispObject implements Serializable { 44 45 final Object obj; 45 46 private final Class<?> intendedClass;
Note: See TracChangeset
for help on using the changeset viewer.