Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: b8f508471d48
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 206517751112
Choose a head ref
  • 3 commits
  • 5 files changed
  • 2 contributors

Commits on Oct 7, 2014

  1. Copy the full SHA
    c47d195 View commit details
  2. Copy the full SHA
    dd46304 View commit details
  3. Copy the full SHA
    2065177 View commit details
21 changes: 14 additions & 7 deletions core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
@@ -39,6 +39,7 @@
***** END LICENSE BLOCK *****/
package org.jruby;

import org.objectweb.asm.util.TraceClassVisitor;
import jnr.constants.Constant;
import jnr.constants.ConstantSet;
import jnr.constants.platform.Errno;
@@ -51,6 +52,7 @@
import org.jruby.ast.RootNode;
import org.jruby.ast.executable.RuntimeCache;
import org.jruby.ast.executable.Script;
import org.jruby.ast.executable.ScriptAndCode;
import org.jruby.common.IRubyWarnings.ID;
import org.jruby.common.RubyWarnings;
import org.jruby.compiler.JITCompiler;
@@ -136,6 +138,7 @@
import org.jruby.util.io.SelectorPool;
import org.jruby.util.log.Logger;
import org.jruby.util.log.LoggerFactory;
import org.objectweb.asm.ClassReader;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -144,6 +147,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.lang.ref.WeakReference;
import java.net.BindException;
import java.net.MalformedURLException;
@@ -712,13 +716,13 @@ public IRubyObject runNormally(Node scriptNode, boolean unused) {
* @return The result of executing the script
*/
public IRubyObject runNormally(Node scriptNode) {
Script script = null;
ScriptAndCode scriptAndCode = null;
boolean compile = getInstanceConfig().getCompileMode().shouldPrecompileCLI();
if (compile || config.isShowBytecode()) {
// IR JIT does not handle all scripts yet, so let those that fail run in interpreter instead
// FIXME: restore error once JIT should handle everything
try {
script = tryCompile(scriptNode, new JRubyClassLoader(getJRubyClassLoader()));
scriptAndCode = tryCompile(scriptNode, new JRubyClassLoader(getJRubyClassLoader()));
if (Options.JIT_LOGGING.load()) {
LOG.info("done compiling target script: " + scriptNode.getPosition().getFile());
}
@@ -732,12 +736,15 @@ public IRubyObject runNormally(Node scriptNode) {
}
}

if (script != null) {
if (scriptAndCode != null) {
if (config.isShowBytecode()) {
TraceClassVisitor tracer = new TraceClassVisitor(new PrintWriter(System.err));
ClassReader reader = new ClassReader(scriptAndCode.bytecode());
reader.accept(tracer, 0);
return getNil();
}

return runScript(script);
return runScript(scriptAndCode.script());
} else {
// FIXME: temporarily allowing JIT to fail for $0 and fall back on interpreter
// failForcedCompile(scriptNode);
@@ -755,7 +762,7 @@ public IRubyObject runNormally(Node scriptNode) {
* @return an instance of the successfully-compiled Script, or null.
*/
public Script tryCompile(Node node) {
return tryCompile(node, new JRubyClassLoader(getJRubyClassLoader()));
return tryCompile(node, new JRubyClassLoader(getJRubyClassLoader())).script();
}

private void failForcedCompile(Node scriptNode) throws RaiseException {
@@ -771,7 +778,7 @@ private void handeCompileError(Node node, Throwable t) {
}
}

private Script tryCompile(Node node, JRubyClassLoader classLoader) {
private ScriptAndCode tryCompile(Node node, JRubyClassLoader classLoader) {
return Compiler.getInstance().execute(this, node, classLoader);
}

@@ -2888,7 +2895,7 @@ public void compileAndLoadFile(String filename, InputStream in, boolean wrap) {
// script was not found in cache above, so proceed to compile
Node scriptNode = parseFile(readStream, filename, null);
if (script == null) {
script = tryCompile(scriptNode, new JRubyClassLoader(jrubyClassLoader));
script = tryCompile(scriptNode, new JRubyClassLoader(jrubyClassLoader)).script();
}

if (script == null) {
24 changes: 24 additions & 0 deletions core/src/main/java/org/jruby/ast/executable/ScriptAndCode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.jruby.ast.executable;

import java.util.Arrays;

/**
* Represents an executable Script object and the bytecode that goes with it.
*/
public class ScriptAndCode {
private final byte[] bytecode;
private final Script script;

public ScriptAndCode(byte[] bytecode, Script script) {
this.bytecode = bytecode;
this.script = script;
}

public byte[] bytecode() {
return Arrays.copyOf(bytecode, bytecode.length);
}

public Script script() {
return script;
}
}
12 changes: 8 additions & 4 deletions core/src/main/java/org/jruby/ir/Compiler.java
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@
import org.jruby.RubyModule;
import org.jruby.ast.executable.AbstractScript;
import org.jruby.ast.executable.Script;
import org.jruby.ast.executable.ScriptAndCode;
import org.jruby.exceptions.JumpException;
import org.jruby.ir.targets.JVMVisitor;
import org.jruby.parser.StaticScope;
@@ -20,7 +21,7 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Compiler extends IRTranslator<Script, JRubyClassLoader> {
public class Compiler extends IRTranslator<ScriptAndCode, JRubyClassLoader> {

// Compiler is singleton
private Compiler() {}
@@ -35,9 +36,10 @@ public static Compiler getInstance() {
}

@Override
protected Script execute(final Ruby runtime, final IRScope scope, JRubyClassLoader classLoader) {
protected ScriptAndCode execute(final Ruby runtime, final IRScope scope, JRubyClassLoader classLoader) {
final JVMVisitor visitor = new JVMVisitor();
final Class compiled = visitor.compile(scope, classLoader);
final byte[] bytecode = visitor.compileToBytecode(scope);
final Class compiled = visitor.defineFromBytecode(scope, bytecode, classLoader);
final StaticScope staticScope = scope.getStaticScope();
final IRubyObject runtimeTopSelf = runtime.getTopSelf();
staticScope.setModule(runtimeTopSelf.getMetaClass());
@@ -51,7 +53,7 @@ protected Script execute(final Ruby runtime, final IRScope scope, JRubyClassLoad
}
final Method compiledMethod = _compiledMethod;

return new AbstractScript() {
Script script = new AbstractScript() {
@Override
public IRubyObject __file__(ThreadContext context, IRubyObject self, IRubyObject[] args, Block block) {
try {
@@ -79,6 +81,8 @@ public IRubyObject load(ThreadContext context, IRubyObject self, boolean wrap) {
}
};

return new ScriptAndCode(bytecode, script);

}

}
Original file line number Diff line number Diff line change
@@ -163,7 +163,7 @@ public Object execute(IRScope scope, Object... data) {

@Override
public Object previouslyRun(IRScope scope) {
return scope.hasExplicitCallProtocol();
return scope.hasExplicitCallProtocol() ? new Object() : null;
}

@Override
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ public Object execute(IRScope s, Object... data) {

@Override
public Object previouslyRun(IRScope scope) {
return scope.hasHasOptimizedTemporaryVariables();
return scope.hasHasOptimizedTemporaryVariables() ? new Object() : null;
}

@Override