Skip to content

Commit

Permalink
Showing 5 changed files with 8 additions and 104 deletions.
29 changes: 1 addition & 28 deletions core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
@@ -819,12 +819,7 @@ private Script tryCompile(Node node, String cachedClassName, JRubyClassLoader cl
String filename = node.getPosition().getFile();
String classname = JavaNameMangler.mangledFilenameForStartupClasspath(filename);

StandardASMCompiler asmCompiler = null;
if (RubyInstanceConfig.JIT_CODE_CACHE != null && cachedClassName != null) {
asmCompiler = new StandardASMCompiler(cachedClassName.replace('.', '/'), filename);
} else {
asmCompiler = new StandardASMCompiler(classname, filename);
}
StandardASMCompiler asmCompiler = new StandardASMCompiler(classname, filename);
ASTCompiler compiler = config.newCompiler();
if (dump) {
compiler.compileRoot(node, asmCompiler, inspector, false, false);
@@ -833,11 +828,6 @@ private Script tryCompile(Node node, String cachedClassName, JRubyClassLoader cl
compiler.compileRoot(node, asmCompiler, inspector, true, false);
}

if (RubyInstanceConfig.JIT_CODE_CACHE != null && cachedClassName != null) {
// save script off to disk
String pathName = cachedClassName.replace('.', '/');
JITCompiler.saveToCodeCache(this, asmCompiler.getClassByteArray(), "ruby/jit", new File(RubyInstanceConfig.JIT_CODE_CACHE, pathName + ".class"));
}
script = (Script)asmCompiler.loadClass(classLoader).newInstance();

// __file__ method expects its scope at 0, so prepare that here
@@ -2616,23 +2606,6 @@ public synchronized JRubyClassLoader getJRubyClassLoader() {
// FIXME: Get rid of laziness and handle restricted access elsewhere
if (!Ruby.isSecurityRestricted() && jrubyClassLoader == null) {
jrubyClassLoader = new JRubyClassLoader(config.getLoader());

// if jit code cache is used, we need to add the cache directory to the classpath
// so the previously generated class files can be reused.
if( config.JIT_CODE_CACHE != null && !config.JIT_CODE_CACHE.trim().isEmpty() ) {
File file = new File( config.JIT_CODE_CACHE );

if( file.exists() == false || file.isDirectory() == false ) {
getWarnings().warning("The jit.codeCache '" + config.JIT_CODE_CACHE + "' directory doesn't exit.");
} else {
try {
URL url = file.toURI().toURL();
jrubyClassLoader.addURL( url );
} catch (MalformedURLException e) {
getWarnings().warning("Unable to add the jit.codeCache '" + config.JIT_CODE_CACHE + "' directory to the classpath." + e.getMessage());
}
}
}
}

return jrubyClassLoader;
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/RubyInstanceConfig.java
Original file line number Diff line number Diff line change
@@ -1814,8 +1814,6 @@ public boolean shouldPrecompileAll() {

public static final boolean JIT_CACHE_ENABLED = Options.JIT_CACHE.load();

public static final String JIT_CODE_CACHE = Options.JIT_CODECACHE.load();

public static final boolean REFLECTED_HANDLES = Options.REFLECTED_HANDLES.load();

public static final boolean NO_UNWRAP_PROCESS_STREAMS = Options.PROCESS_NOUNWRAP.load();
@@ -2030,4 +2028,6 @@ public boolean isBenchmarking() {
@Deprecated public static final boolean INVOKEDYNAMIC_CONSTANTS = invokedynamicCache && Options.INVOKEDYNAMIC_CACHE_CONSTANTS.load();
@Deprecated public static final boolean INVOKEDYNAMIC_LITERALS = invokedynamicCache&& Options.INVOKEDYNAMIC_CACHE_LITERALS.load();
@Deprecated public static final boolean INVOKEDYNAMIC_IVARS = invokedynamicCache&& Options.INVOKEDYNAMIC_CACHE_IVARS.load();

@Deprecated public static final String JIT_CODE_CACHE = "";
}
59 changes: 1 addition & 58 deletions core/src/main/java/org/jruby/compiler/JITCompiler.java
Original file line number Diff line number Diff line change
@@ -96,8 +96,7 @@

public class JITCompiler implements JITCompilerMBean {
private static final Logger LOG = LoggerFactory.getLogger("JITCompiler");

public static final boolean USE_CACHE = true;

public static final String RUBY_JIT_PREFIX = "rubyjit";

public static final String CLASS_METHOD_DELIMITER = "$$";
@@ -321,37 +320,6 @@ public static String getHashForBytes(byte[] bytes) {
throw new RuntimeException(nsae);
}
}

public static void saveToCodeCache(Ruby ruby, byte[] bytecode, String packageName, File cachedClassFile) {
String codeCache = RubyInstanceConfig.JIT_CODE_CACHE;
File codeCacheDir = new File(codeCache);
if (!codeCacheDir.exists()) {
ruby.getWarnings().warn("jruby.jit.codeCache directory " + codeCacheDir + " does not exist");
} else if (!codeCacheDir.isDirectory()) {
ruby.getWarnings().warn("jruby.jit.codeCache directory " + codeCacheDir + " is not a directory");
} else if (!codeCacheDir.canWrite()) {
ruby.getWarnings().warn("jruby.jit.codeCache directory " + codeCacheDir + " is not writable");
} else {
if (!new File(codeCache, packageName).isDirectory()) {
boolean createdDirs = new File(codeCache, packageName).mkdirs();
if (!createdDirs) {
ruby.getWarnings().warn("could not create JIT cache dir: " + new File(codeCache, packageName));
}
}
// write to code cache
FileOutputStream fos = null;
try {
if (RubyInstanceConfig.JIT_LOADING_DEBUG) LOG.info("writing jitted code to to " + cachedClassFile);
fos = new FileOutputStream(cachedClassFile);
fos.write(bytecode);
} catch (Exception e) {
e.printStackTrace();
// ignore
} finally {
try {fos.close();} catch (Exception e) {}
}
}
}

public static class JITClassGenerator implements ClassCache.ClassGenerator {
public JITClassGenerator(String className, String methodName, String key, Ruby ruby, DefaultMethod method, JITCounts counts) {
@@ -384,27 +352,6 @@ public JITClassGenerator(String className, String methodName, String key, Ruby r
protected void compile() {
if (bytecode != null) return;

// check if we have a cached compiled version on disk
String codeCache = RubyInstanceConfig.JIT_CODE_CACHE;
File cachedClassFile = new File(codeCache + "/" + className + ".class");

if (codeCache != null &&
cachedClassFile.exists()) {
FileInputStream fis = null;
try {
if (RubyInstanceConfig.JIT_LOADING_DEBUG) LOG.info("loading cached code from: " + cachedClassFile);
fis = new FileInputStream(cachedClassFile);
bytecode = new byte[(int)fis.getChannel().size()];
fis.read(bytecode);
name = new ClassReader(bytecode).getClassName();
return;
} catch (Exception e) {
// ignore and proceed to compile
} finally {
try {fis.close();} catch (Exception e) {}
}
}

// Time the compilation
long start = System.nanoTime();

@@ -464,10 +411,6 @@ public void call(BodyCompiler context) {
"JITed method size exceeds configured max of " +
ruby.getInstanceConfig().getJitMaxSize());
}

if (codeCache != null) {
JITCompiler.saveToCodeCache(ruby, bytecode, packageName, cachedClassFile);
}

counts.compiledCount.incrementAndGet();
counts.compileTime.addAndGet(System.nanoTime() - start);
16 changes: 1 addition & 15 deletions core/src/main/java/org/jruby/util/ClassCache.java
Original file line number Diff line number Diff line change
@@ -112,23 +112,9 @@ public Class<T> cacheClassByKey(Object key, ClassGenerator classGenerator)
}

protected Class<T> defineClass(ClassGenerator classGenerator) {
// attempt to load from classloaders
String className = classGenerator.name();
Class contents = null;
try {
contents = getClassLoader().loadClass(className);
if (RubyInstanceConfig.JIT_LOADING_DEBUG) {
LOG.debug("found jitted code in classloader: {}", className);
}
} catch (ClassNotFoundException cnfe) {
if (RubyInstanceConfig.JIT_LOADING_DEBUG) {
LOG.debug("no jitted code in classloader for method {} at class: {}", classGenerator, className);
}
// proceed to define in-memory
}
OneShotClassLoader oneShotCL = new OneShotClassLoader(getClassLoader());
classGenerator.generate();
contents = oneShotCL.defineClass(classGenerator.name(), classGenerator.bytecode());
Class contents = oneShotCL.defineClass(classGenerator.name(), classGenerator.bytecode());
classLoadCount.incrementAndGet();

return contents;
4 changes: 3 additions & 1 deletion core/src/main/java/org/jruby/util/cli/Options.java
Original file line number Diff line number Diff line change
@@ -98,7 +98,6 @@ public class Options {
public static final Option<Integer> JIT_LOGEVERY = integer(JIT, "jit.logEvery", 0, "Log a message every n methods JIT compiled.");
public static final Option<String> JIT_EXCLUDE = string(JIT, "jit.exclude", new String[]{"ClsOrMod","ClsOrMod::method_name","-::method_name"}, "", "Exclude methods from JIT. Comma delimited.");
public static final Option<Boolean> JIT_CACHE = bool(JIT, "jit.cache", !COMPILE_INVOKEDYNAMIC.load(), "Cache jitted method in-memory bodies across runtimes and loads.");
public static final Option<String> JIT_CODECACHE = string(JIT, "jit.codeCache", new String[]{"dir"}, "Save jitted methods to <dir> as they're compiled, for future runs.");
public static final Option<Boolean> JIT_DEBUG = bool(JIT, "jit.debug", false, "Log loading of JITed bytecode.");
public static final Option<Boolean> JIT_BACKGROUND = bool(JIT, "jit.background", true, "Run the JIT compiler in a background thread.");

@@ -254,4 +253,7 @@ private static boolean calculateInvokedynamicDefault() {
// We were defaulting on for Java 8 and might again later if JEP 210 helps reduce warmup time.
return false;
}

@Deprecated
public static final Option<String> JIT_CODECACHE = Option.string("jit.codeCache", JIT, new String[]{"dir"}, "Save jitted methods to <dir> as they're compiled, for future runs.");
}

0 comments on commit 1c3cdaa

Please sign in to comment.