fixed more fixmes/features
[nestedvm.git] / src / org / ibex / nestedvm / RuntimeCompiler.java
index 2aa4305..3252242 100644 (file)
@@ -5,19 +5,27 @@ import java.io.*;
 import org.ibex.nestedvm.util.*;
 
 // FEATURE: This need a lot of work to support binaries spanned across many classes
-public class RuntimeCompiler {          
-    private static final SingleClassLoader singleClassLoader = new SingleClassLoader();
-    // FEATURE: Is it ok if this overflows?
-    private static long nextID = 1;
-    private static synchronized String uniqueID() { return Long.toString(nextID++); }
+public class RuntimeCompiler {  
+    private static SingleClassLoader singleClassLoader;
+    private static int nextID;
     
-    public static Class compile(Seekable data) throws IOException, Compiler.Exn {
-        String className = "nextedvm.runtimecompiled_" + uniqueID();
+    public static Class compile(Seekable data) throws IOException, Compiler.Exn { return compile(data,null); }
+    public static Class compile(Seekable data, String extraoptions) throws IOException, Compiler.Exn {
+        int id;
+        synchronized(RuntimeCompiler.class) {
+            if(nextID == 32 || singleClassLoader == null) {
+                singleClassLoader = new SingleClassLoader();
+                nextID = 0;
+            }
+            id = nextID++;
+        }
+        String className = "nextedvm.runtimecompiled_" + id;
         System.err.println("RuntimeCompiler: Building " + className);
+        String options = "nosupportcall";
+        if(extraoptions != null) options += "," + extraoptions;
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ClassFileCompiler c = new ClassFileCompiler(data,className,baos);
-        // FEATURE: make this Optional, pass options on compile arguments
-        c.parseOptions("unixruntime");
+        c.parseOptions(options);
         c.go();
         baos.close();
         byte[] bytecode = baos.toByteArray();
@@ -26,7 +34,7 @@ public class RuntimeCompiler {
     
     private static class SingleClassLoader extends ClassLoader {
         public Class loadClass(String name, boolean resolve) throws ClassNotFoundException {
-                   System.err.println(this + ": loadClass(\"" + name + "," + resolve + ");");
+            //System.err.println(this + ": loadClass(\"" + name + "," + resolve + ");");
             return super.loadClass(name,resolve);
         }
         public Class fromBytes(String name, byte[] b) { return fromBytes(name,b,0,b.length); }
@@ -38,13 +46,13 @@ public class RuntimeCompiler {
     }
     
     public static void main(String[] args) throws Exception {
-           if(args.length == 0) {
-                   System.err.println("Usage: RuntimeCompiler mipsbinary");
+        if(args.length == 0) {
+            System.err.println("Usage: RuntimeCompiler mipsbinary");
             System.exit(1);
         }
         UnixRuntime r = (UnixRuntime) compile(new Seekable.File(args[0])).newInstance();
         System.err.println("Instansiated: "+ r);
-        System.exit(r.run(args));
+        System.exit(UnixRuntime.runAndExec(r,args));
     }
     
     private RuntimeCompiler() { }