dmiles: classloaders to search their parent/system classloaders first.

Robustifies strategies for loading in non-JVM environments (iKVM/GCJ)
when using the "class" PATHNAME TYPE for bytecode artifacts.
parent 516ea080
......@@ -59,9 +59,16 @@ public class FaslClassLoader extends JavaClassLoader {
* which - in ABCL - is pretty deep, most of the time.
*/
if (name.startsWith(baseName + "_")) {
String internalName = "org/armedbear/lisp/" + name;
String internalName = name.replace(".", "/");
if (!internalName.contains("/")) internalName = "org/armedbear/lisp/" + internalName;
Class<?> c = this.findLoadedClass(internalName);
if (c == null && checkPreCompiledClassLoader) {
c = findPrecompiledClassOrNull(name);
// Oh, we have to return here so we don't become the owning class loader?
if (c != null)
return c;
}
if (c == null) {
c = findClass(name);
}
......@@ -80,8 +87,13 @@ public class FaslClassLoader extends JavaClassLoader {
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
try {
if (checkPreCompiledClassLoader) {
Class<?> c = findPrecompiledClassOrNull(name);
if (c != null)
return c;
}
byte[] b = getFunctionClassBytes(name);
return defineClass(name, b, 0, b.length);
return defineLispClass(name, b, 0, b.length);
} catch(Throwable e) { //TODO handle this better, readFunctionBytes uses Debug.assert() but should return null
e.printStackTrace();
if(e instanceof ControlTransfer) { throw (ControlTransfer) e; }
......@@ -110,27 +122,16 @@ public class FaslClassLoader extends JavaClassLoader {
return null;
}
public byte[] getFunctionClassBytes(String name) {
Pathname pathname = new Pathname(name.substring("org/armedbear/lisp/".length()) + "." + Lisp._COMPILE_FILE_CLASS_EXTENSION_.symbolValue().getStringValue());
return readFunctionBytes(pathname);
}
public byte[] getFunctionClassBytes(Class<?> functionClass) {
return getFunctionClassBytes(functionClass.getName());
}
public byte[] getFunctionClassBytes(Function f) {
byte[] b = getFunctionClassBytes(f.getClass());
f.setClassBytes(b);
return b;
}
public LispObject loadFunction(int fnNumber) {
//Function name is fnIndex + 1
String name = baseName + "_" + (fnNumber + 1);
try {
Function f = (Function) loadClass(name).newInstance();
f.setClassBytes(getFunctionClassBytes(name));
Class clz = loadClass(name);
Function f = (Function) clz.newInstance();
if (clz.getClassLoader() instanceof JavaClassLoader) {
// Don't do this for system classes (though probably dont need this for other classes)
f.setClassBytes(getFunctionClassBytes(name));
}
return f;
} catch(Throwable e) {
if(e instanceof ControlTransfer) { throw (ControlTransfer) e; }
......
This diff is collapsed.
......@@ -78,6 +78,13 @@ public class MemoryClassLoader extends JavaClassLoader {
return c;
}
}
if (checkPreCompiledClassLoader) {
Class<?> c = findPrecompiledClassOrNull(name);
if (c != null) {
return c;
}
}
// Fall through to our super's default handling
return super.loadClass(name, resolve);
......@@ -86,8 +93,13 @@ public class MemoryClassLoader extends JavaClassLoader {
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
try {
if (checkPreCompiledClassLoader) {
Class<?> c = findPrecompiledClassOrNull(name);
if (c != null)
return c;
}
byte[] b = getFunctionClassBytes(name);
return defineClass(name, b, 0, b.length);
return defineLispClass(name, b, 0, b.length);
} catch(Throwable e) { //TODO handle this better, readFunctionBytes uses Debug.assert() but should return null
e.printStackTrace();
if(e instanceof ControlTransfer) { throw (ControlTransfer) e; }
......@@ -96,23 +108,17 @@ public class MemoryClassLoader extends JavaClassLoader {
}
public byte[] getFunctionClassBytes(String name) {
return (byte[])hashtable.get(name).javaInstance();
}
public byte[] getFunctionClassBytes(Class<?> functionClass) {
return getFunctionClassBytes(functionClass.getName());
}
public byte[] getFunctionClassBytes(Function f) {
byte[] b = getFunctionClassBytes(f.getClass());
f.setClassBytes(b);
return b;
if (hashtable.containsKey(name)) {
return (byte[])hashtable.get(name).javaInstance();
}
return super.getFunctionClassBytes(name);
}
public LispObject loadFunction(String name) {
try {
Function f = (Function) loadClass(name).newInstance();
f.setClassBytes(getFunctionClassBytes(name));
Class clz = loadClass(name);
Function f = (Function) clz.newInstance();
getFunctionClassBytes(f); //as a side effect it sets them
return f;
} catch(Throwable e) {
if(e instanceof ControlTransfer) { throw (ControlTransfer) e; }
......@@ -135,29 +141,28 @@ public class MemoryClassLoader extends JavaClassLoader {
private static final Primitive PUT_MEMORY_FUNCTION = new pf_put_memory_function();
private static final class pf_put_memory_function extends Primitive {
pf_put_memory_function() {
pf_put_memory_function() {
super("put-memory-function", PACKAGE_SYS, false, "loader class-name class-bytes");
}
@Override
public LispObject execute(LispObject loader, LispObject className, LispObject classBytes) {
MemoryClassLoader l = (MemoryClassLoader) loader.javaInstance(MemoryClassLoader.class);
return (LispObject)l.hashtable.put(className.getStringValue(), (JavaObject)classBytes);
return (LispObject)l.hashtable.put(className.getStringValue(), (JavaObject)classBytes);
}
};
private static final Primitive GET_MEMORY_FUNCTION = new pf_get_memory_function();
private static final class pf_get_memory_function extends Primitive {
pf_get_memory_function() {
pf_get_memory_function() {
super("get-memory-function", PACKAGE_SYS, false, "loader class-name");
}
@Override
public LispObject execute(LispObject loader, LispObject name) {
MemoryClassLoader l = (MemoryClassLoader) loader.javaInstance(MemoryClassLoader.class);
return l.loadFunction(name.getStringValue());
return l.loadFunction(name.getStringValue());
}
};
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment