public void compileAndLoadFile(String filename, InputStream in, boolean wrap) {
InputStream readStream = in;
try {
Script script = null;
ScriptAndCode scriptAndCode = null;
String className = null;
try {
// read full contents of file, hash it, and try to load that class first
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int num;
while ((num = in.read(buffer)) > -1) {
baos.write(buffer, 0, num);
}
buffer = baos.toByteArray();
String hash = JITCompiler.getHashForBytes(buffer);
className = JITCompiler.RUBY_JIT_PREFIX + ".FILE_" + hash;
// FIXME: duplicated from ClassCache
Class contents;
try {
contents = jrubyClassLoader.loadClass(className);
if (RubyInstanceConfig.JIT_LOADING_DEBUG) {
LOG.info("found jitted code for " + filename + " at class: " + className);
}
script = (Script)contents.newInstance();
readStream = new ByteArrayInputStream(buffer);
} catch (ClassNotFoundException cnfe) {
if (RubyInstanceConfig.JIT_LOADING_DEBUG) {
LOG.info("no jitted code in classloader for file " + filename + " at class: " + className);
}
} catch (InstantiationException ie) {
if (RubyInstanceConfig.JIT_LOADING_DEBUG) {
LOG.info("jitted code could not be instantiated for file " + filename + " at class: " + className);
}
} catch (IllegalAccessException iae) {
if (RubyInstanceConfig.JIT_LOADING_DEBUG) {
LOG.info("jitted code could not be instantiated for file " + filename + " at class: " + className);
}
}
} catch (IOException ioe) {
// TODO: log something?
}
// script was not found in cache above, so proceed to compile
Node scriptNode = parseFile(readStream, filename, null);
if (script == null) {
scriptAndCode = tryCompile(scriptNode, new JRubyClassLoader(jrubyClassLoader));
if (scriptAndCode != null) script = scriptAndCode.script();
}
if (script == null) {
failForcedCompile(scriptNode);