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: 30c523057b66
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: a312c6e1c7e9
Choose a head ref
  • 3 commits
  • 9 files changed
  • 1 contributor

Commits on Jul 3, 2015

  1. Copy the full SHA
    bc9a5be View commit details
  2. Copy the full SHA
    3c936bd View commit details
  3. Copy the full SHA
    a312c6e View commit details
139 changes: 51 additions & 88 deletions core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
@@ -818,39 +818,23 @@ public IRubyObject runScript(Script script, boolean wrap) {
throw new UnsupportedOperationException();
}

ThreadContext context = getCurrentContext();

try {
return script.load(context, getTopSelf(), wrap);
} catch (JumpException.ReturnJump rj) {
return (IRubyObject) rj.getValue();
}
return script.load(getCurrentContext(), getTopSelf(), wrap);
}

/**
* This is used for the "gets" loop, and we bypass 'load' to use an
* already-prepared, already-pushed scope for the script body.
*/
public IRubyObject runScriptBody(Script script) {
ThreadContext context = getCurrentContext();

try {
return script.__file__(context, getTopSelf(), Block.NULL_BLOCK);
} catch (JumpException.ReturnJump rj) {
return (IRubyObject) rj.getValue();
}
return script.__file__(getCurrentContext(), getTopSelf(), Block.NULL_BLOCK);
}

public IRubyObject runInterpreter(ThreadContext context, ParseResult parseResult, IRubyObject self) {
if (getInstanceConfig().getCompileMode() == CompileMode.TRUFFLE) {
throw new UnsupportedOperationException();
}

try {
return Interpreter.getInstance().execute(this, parseResult, self);
} catch (JumpException.ReturnJump rj) {
return (IRubyObject) rj.getValue();
}
return Interpreter.getInstance().execute(this, parseResult, self);
}

public IRubyObject runInterpreter(ThreadContext context, Node rootNode, IRubyObject self) {
@@ -862,13 +846,7 @@ public IRubyObject runInterpreter(ThreadContext context, Node rootNode, IRubyObj
getTruffleContext().execute((RootNode) rootNode);
return getNil();
} else {
try {

// FIXME: retrieve from IRManager unless lifus does it later
return Interpreter.getInstance().execute(this, rootNode, self);
} catch (JumpException.ReturnJump rj) {
return (IRubyObject) rj.getValue();
}
return Interpreter.getInstance().execute(this, rootNode, self);
}
}

@@ -2921,8 +2899,6 @@ public void loadFile(String scriptName, InputStream in, boolean wrap) {
}

runInterpreter(context, parseResult, self);
} catch (JumpException.ReturnJump rj) {
return;
} finally {
context.postNodeEval();
ThreadContext.popBacktrace(context);
@@ -2932,65 +2908,61 @@ public void loadFile(String scriptName, InputStream in, boolean wrap) {
public void compileAndLoadFile(String filename, InputStream in, boolean wrap) {
InputStream readStream = in;

Script script = null;
ScriptAndCode scriptAndCode = null;
String className = null;

try {
Script script = null;
ScriptAndCode scriptAndCode = null;
String className = null;
// 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 {
// 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);
contents = jrubyClassLoader.loadClass(className);
if (RubyInstanceConfig.JIT_LOADING_DEBUG) {
LOG.info("found jitted code for " + filename + " at class: " + className);
}
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);
}
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?
}
} catch (IOException ioe) {
// TODO: log something?
}

// script was not found in cache above, so proceed to compile
RootNode scriptNode = (RootNode) parseFile(readStream, filename, null);
if (script == null) {
scriptAndCode = tryCompile(scriptNode, new ClassDefiningJRubyClassLoader(jrubyClassLoader));
if (scriptAndCode != null) script = scriptAndCode.script();
}
// script was not found in cache above, so proceed to compile
RootNode scriptNode = (RootNode) parseFile(readStream, filename, null);
if (script == null) {
scriptAndCode = tryCompile(scriptNode, new ClassDefiningJRubyClassLoader(jrubyClassLoader));
if (scriptAndCode != null) script = scriptAndCode.script();
}

if (script == null) {
failForcedCompile(scriptNode);
if (script == null) {
failForcedCompile(scriptNode);

runInterpreter(scriptNode);
} else {
runScript(script, wrap);
}
} catch (JumpException.ReturnJump rj) {
return;
runInterpreter(scriptNode);
} else {
runScript(script, wrap);
}
}

@@ -2999,14 +2971,7 @@ public void loadScript(Script script) {
}

public void loadScript(Script script, boolean wrap) {
IRubyObject self = getTopSelf();
ThreadContext context = getCurrentContext();

try {
script.load(context, self, wrap);
} catch (JumpException.ReturnJump rj) {
return;
}
script.load(getCurrentContext(), getTopSelf(), wrap);
}

/**
@@ -3027,8 +2992,6 @@ public void loadExtension(String extName, BasicLibraryService extension, boolean
extension.basicLoad(this);
} catch (IOException ioe) {
throw newIOErrorFromException(ioe);
} catch (JumpException.ReturnJump rj) {
return;
} finally {
context.postNodeEval();
}
6 changes: 0 additions & 6 deletions core/src/main/java/org/jruby/RubyBasicObject.java
Original file line number Diff line number Diff line change
@@ -1700,9 +1700,6 @@ protected IRubyObject yieldUnder(final ThreadContext context, RubyModule under,
IRubyObject valueInYield = RubyArray.newArrayNoCopy(context.runtime, args);
return setupBlock(block, evalType).yieldArray(context, valueInYield, this); // context.getRubyClass());
}
//TODO: Should next and return also catch here?
} catch (JumpException.BreakJump bj) {
return (IRubyObject) bj.getValue();
} finally {
block.getBinding().setVisibility(savedVisibility);
block.getBinding().setSelf(savedBindingSelf);
@@ -1736,9 +1733,6 @@ protected IRubyObject yieldUnder(final ThreadContext context, RubyModule under,

try {
return setupBlock(block, evalType).yieldNonArray(context, this, this); //, context.getRubyClass());
//TODO: Should next and return also catch here?
} catch (JumpException.BreakJump bj) {
return (IRubyObject) bj.getValue();
} finally {
block.getBinding().setVisibility(savedVisibility);
block.getBinding().setSelf(savedBindingSelf);
13 changes: 1 addition & 12 deletions core/src/main/java/org/jruby/embed/bsf/JRubyEngine.java
Original file line number Diff line number Diff line change
@@ -46,7 +46,6 @@
import org.apache.bsf.BSFManager;
import org.apache.bsf.util.BSFEngineImpl;
import org.apache.bsf.util.BSFFunctions;
import org.jruby.CompatVersion;
import org.jruby.Ruby;
import org.jruby.RubyObject;
import org.jruby.embed.EmbedRubyObjectAdapter;
@@ -57,7 +56,6 @@
import org.jruby.embed.util.SystemPropertyCatcher;
import org.jruby.embed.variable.BiVariable;
import org.jruby.embed.variable.VariableInterceptor;
import org.jruby.exceptions.JumpException;
import org.jruby.exceptions.RaiseException;
import org.jruby.internal.runtime.GlobalVariable;
import org.jruby.javasupport.Java;
@@ -214,16 +212,7 @@ public void handleException(BSFException bsfExcptn) {
*/
private static void printException(Ruby runtime, Exception exception) {
assert exception != null;
if (exception instanceof RaiseException) {
JumpException je = (JumpException)exception;
if (je instanceof RaiseException) {
runtime.printError(((RaiseException)je).getException());
} else if (je instanceof JumpException.BreakJump) {
runtime.getErrorStream().println("break without block.");
} else if (je instanceof JumpException.ReturnJump) {
runtime.getErrorStream().println("return without block.");
}
}
if (exception instanceof RaiseException) runtime.printError(((RaiseException)exception).getException());
}

private static class FunctionsGlobalVariable implements IAccessor {
6 changes: 1 addition & 5 deletions core/src/main/java/org/jruby/exceptions/JumpException.java
Original file line number Diff line number Diff line change
@@ -82,13 +82,9 @@ public RaiseException buildException(Ruby runtime) {
}
}

public static class BreakJump extends FlowControlException { public BreakJump(int t, Object v) { super(Reason.BREAK, t, v); } }
public static class NextJump extends FlowControlException { public NextJump(Object v) { super(Reason.NEXT, 0, v); } }
public static class RedoJump extends FlowControlException { public RedoJump() {super(Reason.REDO); } }
public static class SpecialJump extends FlowControlException { public SpecialJump() {super(Reason.NOREASON); } }
public static final SpecialJump SPECIAL_JUMP = new SpecialJump();
public static class ReturnJump extends FlowControlException { public ReturnJump(int t, Object v) { super(Reason.RETURN, t, v); }}


/**
* Constructor for flow-control-only JumpExceptions.
*/
Original file line number Diff line number Diff line change
@@ -99,8 +99,6 @@ public void run() {
IRubyObject result = proc.call(context, arguments);
if (runtime.hasEventHooks() && runtime.is2_0()) context.trace(RubyEvent.THREAD_END, null, frameClass);
rubyThread.cleanTerminate(result);
} catch (JumpException.ReturnJump rj) {
rubyThread.exceptionRaised(rj.buildException(runtime));
} catch (MainExitException mee) {
// Someone called exit!, so we need to kill the main thread
runtime.getThreadService().getMainThread().kill();
Original file line number Diff line number Diff line change
@@ -33,11 +33,7 @@
import java.lang.reflect.Method;
import java.util.Arrays;
import org.jruby.MetaClass;
import org.jruby.Ruby;
import org.jruby.RubyLocalJumpError;
import org.jruby.RubyModule;
import org.jruby.exceptions.JumpException;
import org.jruby.exceptions.RaiseException;
import org.jruby.runtime.Arity;
import org.jruby.runtime.Block;
import org.jruby.runtime.CallType;
@@ -590,22 +586,4 @@ public MethodData getMethodData() {
public void setNotImplemented(boolean setNotImplemented) {
this.notImplemented = setNotImplemented;
}

protected IRubyObject handleRedo(Ruby runtime) throws RaiseException {
throw runtime.newLocalJumpError(RubyLocalJumpError.Reason.REDO, runtime.getNil(), "unexpected redo");
}

protected IRubyObject handleReturn(ThreadContext context, JumpException.ReturnJump rj, int callNumber) {
if (rj.getTarget() == callNumber) {
return (IRubyObject) rj.getValue();
}
throw rj;
}

protected IRubyObject handleBreak(ThreadContext context, Ruby runtime, JumpException.BreakJump bj, int callNumber) {
if (bj.getTarget() == callNumber) {
throw runtime.newLocalJumpError(RubyLocalJumpError.Reason.BREAK, runtime.getNil(), "unexpected break");
}
throw bj;
}
}
11 changes: 1 addition & 10 deletions core/src/main/java/org/jruby/javasupport/bsf/JRubyEngine.java
Original file line number Diff line number Diff line change
@@ -155,16 +155,7 @@ public void handleException(BSFException bsfExcptn) {
* @param exception An Exception thrown by JRuby
*/
private static void printException(Ruby runtime, Exception exception) {
if (exception instanceof RaiseException) {
JumpException je = (JumpException)exception;
if (je instanceof RaiseException) {
runtime.printError(((RaiseException)je).getException());
} else if (je instanceof JumpException.BreakJump) {
runtime.getErrorStream().println("break without block.");
} else if (je instanceof JumpException.ReturnJump) {
runtime.getErrorStream().println("return without block.");
}
}
if (exception instanceof RaiseException) runtime.printError(((RaiseException) exception).getException());
}

private static class BeanGlobalVariable implements IAccessor {
14 changes: 0 additions & 14 deletions core/src/main/java/org/jruby/runtime/Helpers.java
Original file line number Diff line number Diff line change
@@ -239,20 +239,6 @@ public static final Map<String, String> map(String... keyValues) {
return map;
}

/**
* Should be called on jumps out of blocks. Inspects the jump, returning or rethrowing as appropriate
*/
public static IRubyObject handleBlockJump(ThreadContext context, JumpException.FlowControlException jump, Block.Type type) {
// 'next' and Lambda 'return' are local returns from the block, ending the call or yield
if (jump instanceof JumpException.NextJump
|| (jump instanceof JumpException.ReturnJump && type == Block.Type.LAMBDA)) {
return jump.getValue() == null ? context.runtime.getNil() : (IRubyObject)jump.getValue();
}

// other jumps propagate up
throw jump;
}

public static boolean additionOverflowed(long original, long other, long result) {
return (~(original ^ other) & (original ^ result) & RubyFixnum.SIGN_BIT) != 0;
}
Original file line number Diff line number Diff line change
@@ -1655,27 +1655,6 @@ public static MethodHandle wrapWithFraming(Signature signature, CallConfiguratio
boolean heapScoped = callConfig.scoping() != Scoping.None;
boolean framed = callConfig.framing() != Framing.None;


if (framed || heapScoped) {
nativeTarget = catchException(
nativeTarget,
JumpException.ReturnJump.class,
Binder
.from(nativeTarget.type().insertParameterTypes(0, JumpException.ReturnJump.class))
.permute(0, 1)
.invokeStaticQuiet(lookup(), InvocationLinker.class, "handleReturn"));
}
if (framed) {
nativeTarget = catchException(
nativeTarget,
JumpException.RedoJump.class,
Binder
.from(nativeTarget.type().insertParameterTypes(0, JumpException.RedoJump.class))
.permute(0, 1)
.invokeStaticQuiet(lookup(), InvocationLinker.class, "handleRedo"));
}


// post logic for frame
nativeTarget = Binder
.from(nativeTarget.type())
@@ -1699,10 +1678,6 @@ public static MethodHandle wrapWithFraming(Signature signature, CallConfiguratio
return nativeTarget;
}

public static IRubyObject handleRedo(JumpException.RedoJump rj, ThreadContext context) {
throw context.runtime.newLocalJumpError(RubyLocalJumpError.Reason.REDO, context.runtime.getNil(), "unexpected redo");
}

public static MethodHandle getFramePre(Signature signature, CallConfiguration callConfig, RubyModule implClass, String name, StaticScope scope) {
Signature inbound = signature.asFold(void.class);
SmartBinder binder = SmartBinder