From afbf57b3345f8f09874da649237a90bcb7155761 Mon Sep 17 00:00:00 2001 From: Fabio Niephaus Date: Mon, 29 Nov 2021 16:15:55 +0100 Subject: [PATCH] Report loop counts in interpreter and first tier --- .../trufflesqueak/nodes/ExecuteBytecodeNode.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/ExecuteBytecodeNode.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/ExecuteBytecodeNode.java index f986114c4..59a86f14f 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/ExecuteBytecodeNode.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/ExecuteBytecodeNode.java @@ -90,7 +90,11 @@ public Object execute(final VirtualFrame frame, final int startPC) { private Object interpretBytecode(final VirtualFrame frame, final int startPC) { CompilerAsserts.partialEvaluationConstant(bytecodeNodes.length); int pc = startPC; - int backJumpCounter = 0; + /* + * Maintain backJumpCounter in an int[] so that the compiler does not confuse it with the + * basicBlockIndex because both are constant within the loop. + */ + final int[] backJumpCounter = new int[1]; Object returnValue = null; bytecode_loop: while (pc != LOCAL_RETURN_PC) { CompilerAsserts.partialEvaluationConstant(pc); @@ -121,8 +125,8 @@ private Object interpretBytecode(final VirtualFrame frame, final int startPC) { } } else if (node instanceof UnconditionalJumpNode) { final int successor = ((UnconditionalJumpNode) node).getSuccessorIndex(); - if (CompilerDirectives.inInterpreter() && successor <= pc && backJumpCounter < Integer.MAX_VALUE) { - backJumpCounter++; + if (CompilerDirectives.hasNextTier() && successor <= pc) { + backJumpCounter[0]++; } pc = successor; continue bytecode_loop; @@ -139,8 +143,9 @@ private Object interpretBytecode(final VirtualFrame frame, final int startPC) { } assert returnValue != null && !FrameAccess.hasModifiedSender(frame); FrameAccess.terminate(frame); - if (backJumpCounter != 0) { - LoopNode.reportLoopCount(this, backJumpCounter > 0 ? backJumpCounter : Integer.MAX_VALUE); + // 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); } return returnValue; }