Skip to content

Commit

Permalink
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
@@ -3121,6 +3121,26 @@ public IRubyObject pushExitBlock(RubyProc proc) {
return proc;
}

/**
* It is possible for looping or repeated execution to encounter the same END
* block multiple times. Rather than store extra runtime state we will just
* make sure it is not already registered. at_exit by contrast can push the
* same block many times (and should use pushExistBlock).
*/
public void pushEndBlock(RubyProc proc) {
if (alreadyRegisteredEndBlock(proc) != null) return;
pushExitBlock(proc);
}

private RubyProc alreadyRegisteredEndBlock(RubyProc newProc) {
Block block = newProc.getBlock();

for (RubyProc proc: atExitBlocks) {
if (block.equals(proc.getBlock())) return proc;
}
return null;
}

// use this for JRuby-internal finalizers
public void addInternalFinalizer(Finalizable finalizer) {
synchronized (internalFinalizersMutex) {
Original file line number Diff line number Diff line change
@@ -1555,7 +1555,7 @@ public static RaiseException newRequiredKeywordArgumentError(ThreadContext conte

@JIT
public static void pushExitBlock(ThreadContext context, Block blk) {
context.runtime.pushExitBlock(context.runtime.newProc(Block.Type.LAMBDA, blk));
context.runtime.pushEndBlock(context.runtime.newProc(Block.Type.LAMBDA, blk));
}

@JIT

0 comments on commit 154275c

Please sign in to comment.