Honor $^P subroutine tracing when populating %DB::sub

Open
#2,135 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
31/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
java, perl
Domain
compilers

Research direction

Start in BytecodeCompiler and SubroutineParser where named-sub source registration is gated on DebugState.isDebugMode(), and find where Perl's $^P is stored and mutated so the 0x10 bit can feed that gate. Then check that %DB::sub entries are written with the defining filename, and validate against system Perl with a new focused test before running the unchanged Module-Refresh t/1api.t and t/clear_symtable.t on both the JVM and interpreter backends. Done means those two tests pass and -d debugger tracing still behaves as before.

Written by the indexing model from the issue text.

Description

area:runtime bug

Summary

PerlOnJava does not populate %DB::sub when Perl code enables subroutine source tracing with $^P |= 0x10. Pure-Perl modules such as Module::Refresh rely on this documented Perl behavior to locate and unload subs defined by a changed file. As a result, refreshed modules retain old methods after reload.

Reproduction and evidence

The unchanged Module-Refresh 0.18 test suite passes under system Perl 5.34.1 (4 files, 16 tests). In CPAN random tester run 20261119-133823-51077, PerlOnJava failed 2 of 16 assertions:

  • t/1api.t, test 8: We cleaned out the 'foo' method
  • t/clear_symtable.t, test 4: !Foo->can('bar')

Both failures reproduce on the JVM and interpreter backends in the PerlOnJava checkout at 75525a5dc (2026-11-20), after the symbol-table/method-lookup changes integrated by #1773. The test demonstrates that the old Foo::bar remains callable after Foo.pm is refreshed with a replacement Foo::baz.

A focused diagnostic also sets $^P |= 0x10, loads a file declaring Foo::bar, then inspects %DB::sub: PerlOnJava reports no Foo:: entries while Foo->can('bar') is true. The normal system-Perl run of the complete distribution suite passes.

Environment: macOS 26.7.3, Temurin OpenJDK 24.0.2, system Perl 5.34.1.

Root cause

Module::Refresh sets $^P |= 0x10 in its BEGIN block. Its unload_subs method finds candidate routines by matching each %DB::sub source-location value against the module filename; if no entries match, it cannot remove those routines before require reloads the file.

PerlOnJava currently gates named-sub location registration in BytecodeCompiler and SubroutineParser on DebugState.isDebugMode(). That internal state is enabled by the command-line debugger path, but setting Perl's $^P bit from Perl code does not enable the corresponding subroutine-tracing behavior. Consequently, dynamically loaded modules can compile named subs without registering their source locations in %DB::sub, and Module::Refresh silently leaves old subs installed.

This is related to #1610, which covered stale method lookup after deleting a CODE slot and was integrated in #1773. The current report tracks the separate missing $^P/%DB::sub behavior; the Module::Refresh failures recorded on #1610 still reproduce after that integration.

Expected behavior

When Perl code enables the 0x10 subroutine source-tracing bit in $^P, named subs compiled afterward should appear in %DB::sub with source locations that identify their defining file. Module::Refresh must then be able to remove the previous file's subs, and the refreshed package should expose only the replacement methods.

Acceptance criteria

  • Add a focused project-owned Perl test for enabling $^P bit 0x10 and observing source entries for subsequently compiled named subs; validate its expected behavior with system Perl first.
  • Pass that regression on both JVM and interpreter backends.
  • Pass the unchanged Module-Refresh 0.18 suite on both backends, including t/1api.t and t/clear_symtable.t.
  • Preserve command-line debugger behavior and verify %DB::sub remains consistent when tracing is enabled through $^P rather than -d.
Dominant language
Perl
Stars
67
Forks
8
Avg merge
5h 12m
Merged PRs (30d)
131

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from fglock/PerlOnJava

All issues in fglock/PerlOnJava

Similar issues

More Perl issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.