Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Remove active bytecode size check and let JVM fail.
We will likely want to reinstate this later, since very large
methods will never JIT and will run slower as bytecode than as IR.
  • Loading branch information
headius committed Oct 13, 2014
1 parent 98c943f commit 54aafc4
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions core/src/main/java/org/jruby/compiler/JITCompiler.java
Expand Up @@ -207,16 +207,23 @@ public void run() {

String key = SexpMaker.sha1(method.getIRMethod());
JVMVisitor visitor = new JVMVisitor();
JITClassGenerator generator = new JITClassGenerator(className, methodName, key, runtime, method, counts, visitor);
JITClassGenerator generator = new JITClassGenerator(className, methodName, key, runtime, method, visitor);

generator.compile();

// FIXME: reinstate active bytecode size check
// At this point we still need to reinstate the bytecode size check, to ensure we're not loading code
// that's so big that JVMs won't even try to compile it. Removed the check because with the new IR JIT
// bytecode counts often include all nested scopes, even if they'd be different methods. We need a new
// mechanism of getting all method sizes.
Class sourceClass = visitor.defineFromBytecode(method.getIRMethod(), generator.bytecode(), new OneShotClassLoader(runtime.getJRubyClassLoader()));

if (sourceClass == null) {
// class could not be found nor generated; give up on JIT and bail out
counts.failCount.incrementAndGet();
return;
} else {
generator.updateCounters(counts);
}

// successfully got back a jitted method
Expand Down Expand Up @@ -291,7 +298,7 @@ public static String getHashForBytes(byte[] bytes) {
}

public static class JITClassGenerator {
public JITClassGenerator(String className, String methodName, String key, Ruby ruby, InterpretedIRMethod method, JITCounts counts, JVMVisitor visitor) {
public JITClassGenerator(String className, String methodName, String key, Ruby ruby, InterpretedIRMethod method, JVMVisitor visitor) {
this.packageName = JITCompiler.RUBY_JIT_PREFIX;
if (RubyInstanceConfig.JAVA_VERSION == Opcodes.V1_7 || Options.COMPILE_INVOKEDYNAMIC.load() == true) {
// Some versions of Java 7 seems to have a bug that leaks definitions across cousin classloaders
Expand All @@ -309,7 +316,6 @@ public JITClassGenerator(String className, String methodName, String key, Ruby r
this.name = this.className.replaceAll("/", ".");
this.methodName = methodName;
this.ruby = ruby;
this.counts = counts;
this.method = method;
this.visitor = visitor;
}
Expand All @@ -327,12 +333,12 @@ protected void compile() {
// CON FIXME: Really should clone scope before passes in any case
bytecode = visitor.compileToBytecode(method.getIRMethod());

if (bytecode.length > Options.JIT_MAXSIZE.load()) {
throw new NotCompilableException("bytecode size " + bytecode.length + " too large in " + method.getIRMethod());
}
compileTime = System.nanoTime() - start;
}

void updateCounters(JITCounts counts) {
counts.compiledCount.incrementAndGet();
counts.compileTime.addAndGet(System.nanoTime() - start);
counts.compileTime.addAndGet(compileTime);
counts.codeSize.addAndGet(bytecode.length);
counts.averageCompileTime.set(counts.compileTime.get() / counts.compiledCount.get());
counts.averageCodeSize.set(counts.codeSize.get() / counts.compiledCount.get());
Expand Down Expand Up @@ -364,12 +370,12 @@ public String toString() {
private final String packageName;
private final String className;
private final String methodName;
private final JITCounts counts;
private final String digestString;
private final InterpretedIRMethod method;
private final JVMVisitor visitor;

private byte[] bytecode;
private long compileTime;
private String name;
}

Expand Down

0 comments on commit 54aafc4

Please sign in to comment.