From b5f94a9a184b62e0a3cc246aa225bea8631dc7e2 Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Tue, 21 May 2024 16:24:34 +0900 Subject: [PATCH] Only arity 0 print accesses $_ We can reduce this deoptimization to when print is called with no arguments. Other forms do not need access to $_. --- .../src/main/java/org/jruby/ir/instructions/CallBase.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/core/src/main/java/org/jruby/ir/instructions/CallBase.java b/core/src/main/java/org/jruby/ir/instructions/CallBase.java index 010513a9259..4076abca3e2 100644 --- a/core/src/main/java/org/jruby/ir/instructions/CallBase.java +++ b/core/src/main/java/org/jruby/ir/instructions/CallBase.java @@ -470,6 +470,14 @@ private void captureFrameReadsAndWrites() { frameWrites = ALL; } } else { + // special cases + if (getId().equals("print") && argsCount != 0) { + // only arity 0 print requirest access to LASTLINE + frameReads = Collections.EMPTY_SET; + frameWrites = Collections.EMPTY_SET; + return; + } + frameReads = MethodIndex.METHOD_FRAME_READS.getOrDefault(getId(), Collections.EMPTY_SET); frameWrites = MethodIndex.METHOD_FRAME_WRITES.getOrDefault(getId(), Collections.EMPTY_SET); }