X-Git-Url: http://git.megacz.com/?p=nestedvm.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fnestedvm%2FRuntimeCompiler.java;h=fabc21b1e4009022e395ca52d8bafd38aa9a9b24;hp=325224203a90051535e918afc2bacac514a6e1d2;hb=b11e7c6c29f2b5f7b0828bf93eb741c4a30ec411;hpb=ab9be117467f7459965c61e49749b333678b6e4c diff --git a/src/org/ibex/nestedvm/RuntimeCompiler.java b/src/org/ibex/nestedvm/RuntimeCompiler.java index 3252242..fabc21b 100644 --- a/src/org/ibex/nestedvm/RuntimeCompiler.java +++ b/src/org/ibex/nestedvm/RuntimeCompiler.java @@ -1,35 +1,48 @@ +// Copyright 2000-2005 the Contributors, as shown in the revision logs. +// Licensed under the Apache License 2.0 ("the License"). +// You may not use this file except in compliance with the License. + package org.ibex.nestedvm; import java.io.*; import org.ibex.nestedvm.util.*; -// FEATURE: This need a lot of work to support binaries spanned across many classes +// 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++; + 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,sourceName,null); + } catch(Compiler.Exn e) { + if(e.getMessage() != null || e.getMessage().indexOf("constant pool full") != -1) + bytecode = runCompiler(data,className,extraoptions,sourceName,"lessconstants"); + else + throw e; } - String className = "nextedvm.runtimecompiled_" + id; - System.err.println("RuntimeCompiler: Building " + className); - String options = "nosupportcall"; - if(extraoptions != null) options += "," + extraoptions; + return new SingleClassLoader().fromBytes(className,bytecode); + } + + private static byte[] runCompiler(Seekable data, String name, String options, String sourceName, 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"); + c.setSource(sourceName); + 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 { @@ -50,7 +63,7 @@ public class RuntimeCompiler { System.err.println("Usage: RuntimeCompiler mipsbinary"); System.exit(1); } - UnixRuntime r = (UnixRuntime) compile(new Seekable.File(args[0])).newInstance(); + UnixRuntime r = (UnixRuntime) compile(new Seekable.File(args[0]),"unixruntime").newInstance(); System.err.println("Instansiated: "+ r); System.exit(UnixRuntime.runAndExec(r,args)); }