From: brian Date: Wed, 4 Aug 2004 11:51:24 +0000 (-0700) Subject: include sourcename in runtime compiled binaries, more gc friendly runtime compiler X-Git-Url: http://git.megacz.com/?p=nestedvm.git;a=commitdiff_plain;h=79be771d6242d4ed6831d737c701587e87528572 include sourcename in runtime compiled binaries, more gc friendly runtime compiler darcs-hash:20040804115124-24bed-86aa2c5662d477ae2100ff0908dc3daef5af232e.gz --- diff --git a/src/org/ibex/nestedvm/RuntimeCompiler.java b/src/org/ibex/nestedvm/RuntimeCompiler.java index 443c217..94c7c1b 100644 --- a/src/org/ibex/nestedvm/RuntimeCompiler.java +++ b/src/org/ibex/nestedvm/RuntimeCompiler.java @@ -10,39 +10,30 @@ import org.ibex.nestedvm.util.*; // This need a lot of work to support binaries spanned across many classes public class RuntimeCompiler { - private static SingleClassLoader singleClassLoader; - private static int nextID; - 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 = "nestedvm.runtimecompiled_" + id; - System.err.println("RuntimeCompiler: Building " + className); + public static Class compile(Seekable data, String extraoptions) throws IOException, Compiler.Exn { return compile(data,extraoptions,null); } + + public static Class compile(Seekable data, String extraoptions, String sourceName) throws IOException, Compiler.Exn { + String className = "nestedvm.runtimecompiled"; byte[] bytecode; try { - bytecode = runCompiler(data,className,extraoptions,null); + bytecode = runCompiler(data,className,extraoptions,sourceName,null); } catch(Compiler.Exn e) { if(e.getMessage() != null || e.getMessage().indexOf("constant pool full") != -1) - bytecode = runCompiler(data,className,extraoptions,"lessconstants"); + bytecode = runCompiler(data,className,extraoptions,sourceName,"lessconstants"); else throw e; } - return singleClassLoader.fromBytes(className,bytecode); + return new SingleClassLoader().fromBytes(className,bytecode); } - private static byte[] runCompiler(Seekable data, String name, String options, String moreOptions) throws IOException, Compiler.Exn { + private static byte[] runCompiler(Seekable data, String name, String options, String sourceName, String moreOptions) throws IOException, Compiler.Exn { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { ClassFileCompiler c = new ClassFileCompiler(data,name,baos); c.parseOptions("nosupportcall,maxinsnpermethod=256"); + c.setSource(sourceName); if(options != null) c.parseOptions(options); if(moreOptions != null) c.parseOptions(moreOptions); c.go(); diff --git a/src/org/ibex/nestedvm/UnixRuntime.java b/src/org/ibex/nestedvm/UnixRuntime.java index 71368d8..c88cf24 100644 --- a/src/org/ibex/nestedvm/UnixRuntime.java +++ b/src/org/ibex/nestedvm/UnixRuntime.java @@ -408,7 +408,7 @@ public abstract class UnixRuntime extends Runtime implements Cloneable { static { Method m; try { - m = Class.forName("org.ibex.nestedvm.RuntimeCompiler").getMethod("compile",new Class[]{Seekable.class,String.class}); + m = Class.forName("org.ibex.nestedvm.RuntimeCompiler").getMethod("compile",new Class[]{Seekable.class,String.class,String.class}); } catch(NoSuchMethodException e) { m = null; } catch(ClassNotFoundException e) { @@ -417,14 +417,14 @@ public abstract class UnixRuntime extends Runtime implements Cloneable { runtimeCompilerCompile = m; } - public Class runtimeCompile(Seekable s) throws IOException { + public Class runtimeCompile(Seekable s, String sourceName) throws IOException { if(runtimeCompilerCompile == null) { if(STDERR_DIAG) System.err.println("WARNING: Exec attempted but RuntimeCompiler not found!"); return null; } try { - return (Class) runtimeCompilerCompile.invoke(null,new Object[]{s,"unixruntime"}); + return (Class) runtimeCompilerCompile.invoke(null,new Object[]{s,"unixruntime,maxinsnpermethod=256,lessconstants",sourceName}); } catch(IllegalAccessException e) { e.printStackTrace(); return null; @@ -484,7 +484,9 @@ public abstract class UnixRuntime extends Runtime implements Cloneable { if(n < 4) s.tryReadFully(buf,n,4-n); if(buf[1] != 'E' || buf[2] != 'L' || buf[3] != 'F') return -ENOEXEC; s.seek(0); - Class c = runtimeCompile(s); + if(STDERR_DIAG) System.err.println("Running RuntimeCompiler for " + path); + Class c = runtimeCompile(s,path); + if(STDERR_DIAG) System.err.println("RuntimeCompiler finished for " + path); if(c == null) throw new ErrnoException(ENOEXEC); gs.execCache.put(path,new GlobalState.CacheEnt(mtime,size,c)); return execClass(c,argv,envp);