From b43a6aee72ac892e7d25e3fa03d8474a5ed10f17 Mon Sep 17 00:00:00 2001 From: brian Date: Mon, 31 May 2004 18:02:18 -0700 Subject: [PATCH] cleanup runtime compiler, auto lessconstants darcs-hash:20040601010218-24bed-429982ebff46426546bb7dc4cd27c5ce5e615627.gz --- src/org/ibex/nestedvm/ClassFileCompiler.java | 10 +++++++- src/org/ibex/nestedvm/RuntimeCompiler.java | 32 ++++++++++++++++++++------ 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/org/ibex/nestedvm/ClassFileCompiler.java b/src/org/ibex/nestedvm/ClassFileCompiler.java index 0cb9888..e600097 100644 --- a/src/org/ibex/nestedvm/ClassFileCompiler.java +++ b/src/org/ibex/nestedvm/ClassFileCompiler.java @@ -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 diff --git a/src/org/ibex/nestedvm/RuntimeCompiler.java b/src/org/ibex/nestedvm/RuntimeCompiler.java index 2d0a182..f5ae49c 100644 --- a/src/org/ibex/nestedvm/RuntimeCompiler.java +++ b/src/org/ibex/nestedvm/RuntimeCompiler.java @@ -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 { -- 1.7.10.4