Fix interpreter parity: \&{expr}, caller(), and use with ExportLevel#353
Closed
fglock wants to merge 14 commits into
Closed
Fix interpreter parity: \&{expr}, caller(), and use with ExportLevel#353fglock wants to merge 14 commits into
fglock wants to merge 14 commits into
Conversation
…ly, not REFERENCE
The interpreter was wrapping backslash-ampersand-{expr} results in CREATE_REF, causing
*{$name} = backslash-ampersand-{$func} to pass REFERENCE->CODE to RuntimeGlob.set().
This broke Time::HiRes import because the glob CODE slot received a constant sub
instead of the actual code reference.
The JVM backend uses RuntimeCode.createCodeReference() which returns type=CODE
directly. Now the interpreter matches: backslash-ampersand-{expr} compiles to just
CODE_DEREF_NONSTRICT without CREATE_REF wrapping.
Generated with [Devin](https://cli.devin.ai/docs)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…{keys}
Added BlockNode handling alongside OperatorNode for hash slice assignment.
This enables patterns like @{$hash_ref}{qw(a b)} = (1, 2) which are used
by Exporter/Heavy.pm and other CPAN modules.
Generated with [Devin](https://cli.devin.ai/docs)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1. Hash slice assignment with block dereference @{$ref}{keys}:
Added BlockNode handling alongside OperatorNode for hash slice assignment.
This enables patterns like @{$hash_ref}{qw(a b)} = (1, 2) which are used
by Exporter/Heavy.pm.
2. Defensive null check in superMethod for SUPER:: resolution:
When currentSub is null (no __SUB__ set), fall back to InterpreterState.currentPackage.
This prevents NPE when SUPER::method is called from contexts without __SUB__.
Note: Full fix for Getopt::Long SUPER::import still pending - requires investigation
of __SUB__ initialization for subroutines in loaded .pm modules.
Generated with [Devin](https://cli.devin.ai/docs)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Two issues were causing caller() to return incorrect package/line info in interpreter mode: 1. InterpreterState.getPcStack() returned PCs in oldest-first order, but getStack() returns frames in newest-first order. Fixed by reversing the iteration order in getPcStack(). 2. ExceptionFormatter was using CallerStack[interpreterFrameIndex] but CallerStack stores CALL SITES, not execution positions. For frame N, we need CallerStack[N-1] because CallerStack[M] stores the call site of the Mth call, which is the execution position of frame M+1. This fixes caller(0) and caller(1) returning incorrect line numbers when called from subroutines loaded via require/use. Generated with [Devin](https://cli.devin.ai/docs) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
The parseUseDeclaration CallerStack entry was being accessed with the wrong index when modules like Getopt::Long use $Exporter::ExportLevel. The issue: CallerStack contains entries from both parseUseDeclaration (pushed first) and interpreter CALL_SUB/CALL_METHOD (pushed later). When building the stack trace, parseUseDeclaration handling used callerStackIndex=0, but the actual entry was at a higher index after accounting for interpreter frames. The fix: Use Math.max(interpreterFrameIndex - 1, callerStackIndex) to find the correct CallerStack entry for parseUseDeclaration. This fixes use Getopt::Long and similar modules that rely on $Exporter::ExportLevel to determine the target package for exports. Generated with [Devin](https://cli.devin.ai/docs) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
The previous change introduced a regression where caller() in
signature default values would return the wrong package when
called from an eval with a package statement.
Test case: eval("package T121::Z; ::t121()") where sub t121 has
signature ($a = caller). Expected: T121::Z, was returning: main
The issue was the change to use CallerStack[interpreterFrameIndex-1]
for frames > 0. This was incorrect because:
- CallerStack[N] contains the call site info for the Nth call
- For interpreterFrameIndex=0, we need CallerStack[0] (the most
recent call site), not null
Reverted to using CallerStack[interpreterFrameIndex] directly,
which correctly returns T121::Z for the innermost interpreter frame.
The parseUseDeclaration fix for Exporter is retained separately.
Fixes regression in op/signatures.t test 217.
Generated with [Devin](https://cli.devin.ai/docs)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
- Update all skill files to use dynamic JAR path (build/libs/perlonjava-*.jar) instead of hardcoded target/perlonjava-3.0.0.jar - Use ./jperl wrapper script in examples instead of direct java -jar - Fix profile-perlonjava paths (PerlOnJava2 -> PerlOnJava) - Add interpreter profiling documentation - Fix git stash warning consistency (never use stash) Generated with [Devin](https://cli.devin.ai/docs) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
- Add emoji warning icons to match other skill files - Remove contradictory 'commit or stash' instruction Generated with [Devin](https://cli.devin.ai/docs) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Profile analysis of benchmark_closure.pl in interpreter mode: - Identified ThreadLocal lookup overhead in CALL opcode - CallerStack push/pop on every call even when caller() unused - Deep call chain indirection for subroutine dispatch - TreeMap lookup for line numbers Optimization plan with 4 phases documented. Generated with [Devin](https://cli.devin.ai/docs) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…erence - Cache InterpreterState.currentPackage.get() at start of execute() - Reuse cached RuntimeScalar for SET_PACKAGE opcode - Avoid repeated ThreadLocal lookups in CALL_SUB opcodes No measurable speedup on benchmark_closure.pl, but cleaner code. Profile shows ~10% of time in getCallSiteInfo + getSourceLocationAccurate for caller() support - Phase 2 target. Generated with [Devin](https://cli.devin.ai/docs) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Defer caller() info computation until actually needed: - Add CallerStack.pushLazy() with lambda-based resolution - CALL_SUB/CALL_METHOD now push lazy entries - Line number computation only happens when caller() is called - pop() skips resolution for unneeded entries Benchmark improvement: 127s -> 103s = ~19% speedup on benchmark_closure.pl Generated with [Devin](https://cli.devin.ai/docs) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
- Add fast path in CALL_SUB for InterpretedCode: call execute() directly - Bypass RuntimeCode.apply() indirection chain for interpreter-to-interpreter calls - Pass null for subroutineName to enable InterpreterFrame caching - Apply same optimization to TAILCALL handling Small improvement (~2%) combined with previous optimizations. Generated with [Devin](https://cli.devin.ai/docs) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
- InterpretedCode.getRegisters() caches register arrays per-code-object - Uses ThreadLocal for thread safety with recursion detection - Recursive calls fallback to fresh allocation (no contention) - BytecodeInterpreter.execute() releases registers in finally block Benchmark: 97s from 101s baseline (4% improvement from allocation reduction) Generated with [Devin](https://cli.devin.ai/docs) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Total improvement: 127s → 97s (~24% speedup) - Phase 3: Inline apply path (2% speedup) - Phase 4: Register pooling (4% speedup) Generated with [Devin](https://cli.devin.ai/docs) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR includes interpreter parity fixes and performance optimizations.
Interpreter Parity Fixes
\&{expr}to return CODE type directly - interpreter was wrapping in REFERENCE typecaller()stack trace ordering - InterpreterState.getPcStack() returned wrong ordercaller()for use statements with$Exporter::ExportLevelInterpreter Performance Optimizations (~19% speedup)
CallerStack.pushLazy()with lambda-based resolutionSkill File Updates
target/perlonjava-3.0.0.jarto dynamic pathsTest plan
./jperl --interpreter -e 'use Time::HiRes "time"; print time()'returns numeric timestamp./jperl --interpreter -e 'use Getopt::Long; GetOptions("v" => \my $v); print "OK"'workscaller(N)returns identical values in interpreter and JVM modesmakepasses all unit testsGenerated with Devin