1 package org.ibex.nestedvm;
5 // FEATURE: This is just a quick hack, it is really ugly and broken
7 // FEATURE: Cache based on org.ibex.util.Cache
8 // FEATURE: Base64 encode some id to form package name
9 // FEATURE: Timestamped cache entries, requests carry minimum timestamp
10 // NOTE: Need to handle binaries spanned accross many classfiles
12 public class ClassLoader extends java.lang.ClassLoader {
13 public Class loadClass(String name, boolean resolve) throws ClassNotFoundException {
15 if(name.startsWith("mips.")) {
16 String path = name.substring(5).replace('.','/') + ".mips";
18 ByteArrayOutputStream bos = new ByteArrayOutputStream();
19 new ClassFileCompiler(path,name,bos).go();
21 byte[] buf = bos.toByteArray();
22 c = defineClass(name,buf,0,buf.length);
23 } catch(IOException e) {
24 throw new ClassNotFoundException(name);
25 } catch(Compiler.Exn e) {
26 throw new ClassNotFoundException(e.getMessage());
29 c = findSystemClass(name);
32 if(c == null) throw new ClassNotFoundException(name);
33 if(resolve) resolveClass(c);
37 public Class classFromBinary(String path) throws ClassNotFoundException {
38 if(!path.endsWith(".mips")) throw new IllegalArgumentException("isn't a .mips");
39 return loadClass("mips." + path.substring(0,path.length()-5).replace('/','.'));
42 public Runtime runtimeFromBinary(String path) throws ClassNotFoundException, IllegalAccessException, InstantiationException {
43 return (Runtime) classFromBinary(path).newInstance();
46 public static void main(String[] args) throws Exception {
47 System.exit(new ClassLoader().runtimeFromBinary(args[0]).run(args));