cleanup runtime compiler, auto lessconstants
authorbrian <brian@brianweb.net>
Tue, 1 Jun 2004 01:02:18 +0000 (18:02 -0700)
committerbrian <brian@brianweb.net>
Tue, 1 Jun 2004 01:02:18 +0000 (18:02 -0700)
darcs-hash:20040601010218-24bed-429982ebff46426546bb7dc4cd27c5ce5e615627.gz

src/org/ibex/nestedvm/ClassFileCompiler.java
src/org/ibex/nestedvm/RuntimeCompiler.java

index 0cb9888..e600097 100644 (file)
@@ -53,7 +53,15 @@ public class ClassFileCompiler extends Compiler implements CGConst  {
     public void setWarnWriter(PrintStream warn) { this.warn = warn; }
         
     protected void _go() throws Exn, IOException {
-        if(lessConstants) throw new Exn("ClassFileCompiler doesn't support -o lessconstants");
+        try {
+            __go();
+        } catch(ClassGen.Exn e) {
+            e.printStackTrace();
+            throw new Exn("Class generation exception: " + e.toString());
+        }
+    }
+    
+    private void __go() throws Exn, IOException {
         if(!pruneCases) throw new Exn("-o prunecases MUST be enabled for ClassFileCompiler");
 
         // Class
index 2d0a182..f5ae49c 100644 (file)
@@ -21,15 +21,33 @@ public class RuntimeCompiler {
         }
         String className = "nestedvm.runtimecompiled_" + id;
         System.err.println("RuntimeCompiler: Building " + className);
-        String options = "nosupportcall";
-        if(extraoptions != null) options += "," + extraoptions;
+        byte[] bytecode;
+        try {
+            bytecode = runCompiler(data,className,extraoptions,null);
+        } catch(Compiler.Exn e) {
+            if(e.getMessage() != null || e.getMessage().indexOf("constant pool full")  != -1)
+                bytecode = runCompiler(data,className,extraoptions,"lessconstants");
+            else
+                throw e;
+        }
+        return singleClassLoader.fromBytes(className,bytecode);
+    }
+    
+    private static byte[] runCompiler(Seekable data, String name, String options, String moreOptions) throws IOException, Compiler.Exn {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        ClassFileCompiler c = new ClassFileCompiler(data,className,baos);
-        c.parseOptions(options);
-        c.go();
+        
+        try {
+            ClassFileCompiler c = new ClassFileCompiler(data,name,baos);
+            c.parseOptions("nosupportcall,maxinsnpermethod=256");
+            if(options != null) c.parseOptions(options);
+            if(moreOptions != null) c.parseOptions(moreOptions);
+            c.go();
+        } finally {
+            data.seek(0);
+        }
+        
         baos.close();
-        byte[] bytecode = baos.toByteArray();
-        return singleClassLoader.fromBytes(className,bytecode);
+        return baos.toByteArray();        
     }
     
     private static class SingleClassLoader extends ClassLoader {