Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Remove dead jumptarget crud from old runtime
  • Loading branch information
enebo committed Sep 24, 2014
1 parent 084eef9 commit 8d2f6b3
Show file tree
Hide file tree
Showing 8 changed files with 6 additions and 303 deletions.
50 changes: 1 addition & 49 deletions core/src/main/java/org/jruby/RubyProc.java
Expand Up @@ -298,55 +298,7 @@ public IRubyObject call(ThreadContext context, IRubyObject[] args, IRubyObject s
newBlock.getBinding().setSelf(self);
}

int jumpTarget = newBlock.getBinding().getFrame().getJumpTarget();

try {
return newBlock.call(context, args, passedBlock);
} catch (JumpException.BreakJump bj) {
return handleBreakJump(getRuntime(), newBlock, bj, jumpTarget);
} catch (JumpException.ReturnJump rj) {
return handleReturnJump(context, rj, jumpTarget);
} catch (JumpException.RetryJump rj) {
return handleRetryJump(getRuntime(), rj);
}
}

private IRubyObject handleBreakJump(Ruby runtime, Block newBlock, JumpException.BreakJump bj, int jumpTarget) {
switch(newBlock.type) {
case LAMBDA:
if (bj.getTarget() == jumpTarget) return (IRubyObject) bj.getValue();

throw runtime.newLocalJumpError(RubyLocalJumpError.Reason.BREAK, (IRubyObject)bj.getValue(), "unexpected break");
case PROC:
if (newBlock.isEscaped()) throw runtime.newLocalJumpError(RubyLocalJumpError.Reason.BREAK, (IRubyObject)bj.getValue(), "break from proc-closure");
}

throw bj;
}

private IRubyObject handleReturnJump(ThreadContext context, JumpException.ReturnJump rj, int jumpTarget) {
int target = rj.getTarget();

// lambda always just returns the value
if (target == jumpTarget && isLambda()) return (IRubyObject) rj.getValue();

// returns can't propagate out of threads. rethrow to let thread handle it
if (isThread()) throw rj;

// If the block-receiving method is not still active and the original
// enclosing frame is no longer on the stack, it's a bad return.
// FIXME: this is not very efficient for cases where it won't error
if (target == jumpTarget && !context.isJumpTargetAlive(target, 0)) {
throw context.runtime.newLocalJumpError(RubyLocalJumpError.Reason.RETURN,
(IRubyObject) rj.getValue(), "unexpected return");
}

// otherwise, let it propagate
throw rj;
}

private IRubyObject handleRetryJump(Ruby runtime, JumpException.RetryJump rj) {
throw runtime.newLocalJumpError(RubyLocalJumpError.Reason.RETRY, (IRubyObject)rj.getValue(), "retry not supported outside rescue");
return newBlock.call(context, args, passedBlock);
}

@JRubyMethod(name = "arity")
Expand Down
28 changes: 0 additions & 28 deletions core/src/main/java/org/jruby/runtime/Frame.java
Expand Up @@ -81,9 +81,6 @@ public final class Frame {
/** The current visibility for anything defined under this frame */
private Visibility visibility = Visibility.PUBLIC;

/** The target for non-local jumps, like return from a block */
private int jumpTarget;

/** backref **/
private IRubyObject backRef;

Expand Down Expand Up @@ -112,15 +109,11 @@ private Frame(Frame frame) {
this.klazz = frame.klazz;
this.block = frame.block;
this.visibility = frame.visibility;
this.jumpTarget = frame.jumpTarget;
}

/**
* Update the frame with just filename and line, used for top-level frames
* and method.
*
* @param fileName The file where the calling method is located
* @param line The line number in the calling method where the call is made
*/
public void updateFrame() {
updateFrame(null, null, null, Block.NULL_BLOCK, 0);
Expand All @@ -131,8 +124,6 @@ public void updateFrame() {
* show up correctly in call stacks.
*
* @param name The name of the method being called
* @param fileName The file of the calling method
* @param line The line number of the call to this method
*/
public void updateFrame(String name) {
this.name = name;
Expand All @@ -152,7 +143,6 @@ public void updateFrame(Frame frame) {
this.klazz = frame.klazz;
this.block = frame.block;
this.visibility = frame.visibility;
this.jumpTarget = frame.jumpTarget;
}

/**
Expand All @@ -162,8 +152,6 @@ public void updateFrame(Frame frame) {
* @param self The 'self' for the method
* @param name The name under which the method is being invoked
* @param block The block passed to the method
* @param fileName The filename of the calling method
* @param line The line number where the call is being made
* @param jumpTarget The target for non-local jumps (return in block)
*/
public void updateFrame(RubyModule klazz, IRubyObject self, String name,
Expand All @@ -175,25 +163,18 @@ public void updateFrame(RubyModule klazz, IRubyObject self, String name,
this.klazz = klazz;
this.block = block;
this.visibility = Visibility.PUBLIC;
this.jumpTarget = jumpTarget;
}

/**
* Update the frame based on the given values.
*
* @param klazz The class against which the method is being called
* @param self The 'self' for the method
* @param name The name under which the method is being invoked
* @param block The block passed to the method
* @param fileName The filename of the calling method
* @param line The line number where the call is being made
* @param jumpTarget The target for non-local jumps (return in block)
*/
public void updateFrameForEval(IRubyObject self, int jumpTarget) {
this.self = self;
this.name = null;
this.visibility = Visibility.PRIVATE;
this.jumpTarget = jumpTarget;
}

/**
Expand Down Expand Up @@ -231,15 +212,6 @@ public Frame duplicateForBacktrace() {
return backtraceFrame;
}

/**
* Get the jump target for non-local returns in this frame.
*
* @return The jump target for non-local returns
*/
public int getJumpTarget() {
return jumpTarget;
}

/**
* Return class that we are calling against
*
Expand Down
44 changes: 0 additions & 44 deletions core/src/main/java/org/jruby/runtime/Helpers.java
Expand Up @@ -830,29 +830,6 @@ public static void handleArgumentSizes(ThreadContext context, Ruby runtime, int
}
}

/**
* If it's Redo, Next, or Break, rethrow it as a normal exception for while to handle
* @param re
* @param context
*/
public static Throwable unwrapRedoNextBreakOrJustLocalJump(RaiseException re, ThreadContext context) {
RubyException exception = re.getException();
if (context.runtime.getLocalJumpError().isInstance(exception)) {
RubyLocalJumpError jumpError = (RubyLocalJumpError)re.getException();

switch (jumpError.getReason()) {
case REDO:
return JumpException.REDO_JUMP;
case NEXT:
if (jumpError.exit_value().isNil()) throw JumpException.NEXT_JUMP;
return new JumpException.NextJump(jumpError.exit_value());
case BREAK:
return new JumpException.BreakJump(context.getFrameJumpTarget(), jumpError.exit_value());
}
}
return re;
}

public static String getLocalJumpTypeOrRethrow(RaiseException re) {
RubyException exception = re.getException();
Ruby runtime = exception.getRuntime();
Expand Down Expand Up @@ -980,27 +957,6 @@ public static IRubyObject[] appendToObjectArray(IRubyObject[] array, IRubyObject
return newArray;
}

public static JumpException.ReturnJump returnJump(IRubyObject result, ThreadContext context) {
return context.returnJump(result);
}

public static IRubyObject throwReturnJump(IRubyObject result, ThreadContext context) {
throw context.returnJump(result);
}

public static IRubyObject breakJumpInWhile(JumpException.BreakJump bj, ThreadContext context) {
// JRUBY-530, while case
if (bj.getTarget() == context.getFrameJumpTarget()) {
return (IRubyObject) bj.getValue();
}

throw bj;
}

public static IRubyObject breakJump(ThreadContext context, IRubyObject value) {
throw new JumpException.BreakJump(context.getFrameJumpTarget(), value);
}

public static IRubyObject breakLocalJumpError(Ruby runtime, IRubyObject value) {
throw runtime.newLocalJumpError(RubyLocalJumpError.Reason.BREAK, value, "unexpected break");
}
Expand Down
24 changes: 0 additions & 24 deletions core/src/main/java/org/jruby/runtime/ThreadContext.java
Expand Up @@ -207,10 +207,6 @@ public IRubyObject setErrorInfo(IRubyObject errorInfo) {
return errorInfo;
}

public ReturnJump returnJump(IRubyObject value) {
return new ReturnJump(getFrameJumpTarget(), value);
}

/**
* Returns the lastCallStatus.
* @return LastCallStatus
Expand Down Expand Up @@ -533,22 +529,6 @@ public static void popBacktrace(ThreadContext context) {
context.backtraceIndex--;
}

/**
* Search the frame stack for the given JumpTarget. Return true if it is
* found and false otherwise. Skip the given number of frames before
* beginning the search.
*
* @param target The JumpTarget to search for
* @param skipFrames The number of frames to skip before searching
* @return
*/
public boolean isJumpTargetAlive(int target, int skipFrames) {
for (int i = frameIndex - skipFrames; i >= 0; i--) {
if (frameStack[i].getJumpTarget() == target) return true;
}
return false;
}

/**
* Check if a static scope is present on the call stack.
* This is the IR equivalent of isJumpTargetAlive
Expand All @@ -573,10 +553,6 @@ public IRubyObject getFrameSelf() {
return getCurrentFrame().getSelf();
}

public int getFrameJumpTarget() {
return getCurrentFrame().getJumpTarget();
}

public RubyModule getFrameKlazz() {
return getCurrentFrame().getKlazz();
}
Expand Down
27 changes: 0 additions & 27 deletions core/src/main/java/org/jruby/runtime/callsite/CachingCallSite.java
Expand Up @@ -88,10 +88,6 @@ public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject s
public IRubyObject callIter(ThreadContext context, IRubyObject caller, IRubyObject self, IRubyObject[] args, Block block) {
try {
return callBlock(context, caller, self, args, block);
} catch (JumpException.BreakJump bj) {
return handleBreakJump(context, bj);
} catch (JumpException.RetryJump rj) {
throw retryJumpError(context);
} finally {
block.escape();
}
Expand Down Expand Up @@ -152,10 +148,6 @@ public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject s
public IRubyObject callIter(ThreadContext context, IRubyObject caller, IRubyObject self, Block block) {
try {
return callBlock(context, caller, self, block);
} catch (JumpException.BreakJump bj) {
return handleBreakJump(context, bj);
} catch (JumpException.RetryJump rj) {
throw retryJumpError(context);
} finally {
block.escape();
}
Expand Down Expand Up @@ -186,10 +178,6 @@ public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject s
public IRubyObject callIter(ThreadContext context, IRubyObject caller, IRubyObject self, IRubyObject arg1, Block block) {
try {
return callBlock(context, caller, self, arg1, block);
} catch (JumpException.BreakJump bj) {
return handleBreakJump(context, bj);
} catch (JumpException.RetryJump rj) {
throw retryJumpError(context);
} finally {
block.escape();
}
Expand Down Expand Up @@ -220,10 +208,6 @@ public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject s
public IRubyObject callIter(ThreadContext context, IRubyObject caller, IRubyObject self, IRubyObject arg1, IRubyObject arg2, Block block) {
try {
return callBlock(context, caller, self, arg1, arg2, block);
} catch (JumpException.BreakJump bj) {
return handleBreakJump(context, bj);
} catch (JumpException.RetryJump rj) {
throw retryJumpError(context);
} finally {
block.escape();
}
Expand Down Expand Up @@ -254,10 +238,6 @@ public IRubyObject call(ThreadContext context, IRubyObject caller, IRubyObject s
public IRubyObject callIter(ThreadContext context, IRubyObject caller, IRubyObject self, IRubyObject arg1, IRubyObject arg2, IRubyObject arg3, Block block) {
try {
return callBlock(context, caller, self, arg1, arg2, arg3, block);
} catch (JumpException.BreakJump bj) {
return handleBreakJump(context, bj);
} catch (JumpException.RetryJump rj) {
throw retryJumpError(context);
} finally {
block.escape();
}
Expand Down Expand Up @@ -434,13 +414,6 @@ private static RubyClass pollAndGetClass(ThreadContext context, IRubyObject self
return selfType;
}

private static IRubyObject handleBreakJump(ThreadContext context, BreakJump bj) throws BreakJump {
if (context.getFrameJumpTarget() == bj.getTarget()) {
return (IRubyObject) bj.getValue();
}
throw bj;
}

private static RaiseException retryJumpError(ThreadContext context) {
return context.runtime.newLocalJumpError(RubyLocalJumpError.Reason.RETRY, context.runtime.getNil(), "retry outside of rescue not supported");
}
Expand Down

0 comments on commit 8d2f6b3

Please sign in to comment.