Skip to content

Commit

Permalink
WIP - reuse thread-local jumps
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Dec 5, 2023
1 parent 8e20695 commit c4c331b
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions core/src/main/java/org/jruby/ir/runtime/IRReturnJump.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,31 @@
import org.jruby.runtime.DynamicScope;

public class IRReturnJump extends IRJump implements Unrescuable {
public final StaticScope returnScope;
public final DynamicScope methodToReturnFrom;
public final Object returnValue;
public StaticScope returnScope;
public DynamicScope methodToReturnFrom;
public Object returnValue;

private static final ThreadLocal<IRReturnJump> RETURN_JUMP = new ThreadLocal<>();

private IRReturnJump(StaticScope returnScope, DynamicScope scopeToReturnFrom, Object rv) {
this.methodToReturnFrom = scopeToReturnFrom;
this.returnScope = returnScope;
this.returnValue = rv;
reset(returnScope, scopeToReturnFrom, rv);
}

public static IRReturnJump create(StaticScope returnScope, DynamicScope scopeToReturnFrom, Object rv) {
return new IRReturnJump(returnScope, scopeToReturnFrom, rv);
IRReturnJump jump = RETURN_JUMP.get();
if (jump == null) {
RETURN_JUMP.set(jump = new IRReturnJump(returnScope, scopeToReturnFrom, rv));
} else {
jump.reset(returnScope, scopeToReturnFrom, rv);
}

return jump;
}

private void reset(StaticScope returnScope, DynamicScope scopeToReturnFrom, Object rv) {
this.methodToReturnFrom = scopeToReturnFrom;
this.returnScope = returnScope;
this.returnValue = rv;
}

public boolean isReturnToScope(DynamicScope scope) {
Expand Down

0 comments on commit c4c331b

Please sign in to comment.