Skip to content

Commit

Permalink
Maintain backJumpCounter in a Counter
Browse files Browse the repository at this point in the history
  • Loading branch information
fniephaus committed Feb 7, 2022
1 parent 9710ec2 commit bdf4726
Showing 1 changed file with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ private Object interpretBytecode(final VirtualFrame frame, final int startPC) {
CompilerAsserts.partialEvaluationConstant(bytecodeNodes.length);
int pc = startPC;
/*
* Maintain backJumpCounter in an int[] so that the compiler does not confuse it with the
* basicBlockIndex because both are constant within the loop.
* Maintain backJumpCounter in a Counter so that the compiler does not confuse it with the
* pc because both are constant within the loop.
*/
final int[] backJumpCounter = new int[1];
final Counter backJumpCounter = new Counter();
Object returnValue = null;
bytecode_loop: while (pc != LOCAL_RETURN_PC) {
CompilerAsserts.partialEvaluationConstant(pc);
Expand Down Expand Up @@ -126,7 +126,7 @@ private Object interpretBytecode(final VirtualFrame frame, final int startPC) {
} else if (node instanceof UnconditionalJumpNode) {
final int successor = ((UnconditionalJumpNode) node).getSuccessorIndex();
if (CompilerDirectives.hasNextTier() && successor <= pc) {
backJumpCounter[0]++;
backJumpCounter.value++;
}
pc = successor;
continue bytecode_loop;
Expand All @@ -144,12 +144,19 @@ private Object interpretBytecode(final VirtualFrame frame, final int startPC) {
assert returnValue != null && !FrameAccess.hasModifiedSender(frame);
FrameAccess.terminate(frame);
// only report non-zero counters to reduce interpreter overhead
if (CompilerDirectives.hasNextTier() && backJumpCounter[0] != 0) {
LoopNode.reportLoopCount(this, backJumpCounter[0] > 0 ? backJumpCounter[0] : Integer.MAX_VALUE);
if (CompilerDirectives.hasNextTier() && backJumpCounter.value != 0) {
LoopNode.reportLoopCount(this, backJumpCounter.value > 0 ? backJumpCounter.value : Integer.MAX_VALUE);
}
return returnValue;
}

/**
* Smaller than int[1], does not kill int[] on write and doesn't need bounds checks.
*/
private static final class Counter {
int value;
}

/*
* Fetch next bytecode and insert AST nodes on demand if enabled.
*/
Expand Down

0 comments on commit bdf4726

Please sign in to comment.