Fix Clone::clone graph aliases and DESTROY timing
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
Start with the REFERENCE, HASHREFERENCE and ARRAYREFERENCE branches of deepClone in the Java Clone implementation, and check that src/main/perl/lib/Clone.pm loads it. Run the graph probe (t/dump.pl) and the unblessed-hash DESTROY probe on both backends to reproduce. Done means the shared-referent and cycle probe matches system Perl, cloned objects are destroyed before END, and t/dclone.t and t/06refcnt.t pass. Coordinate owner-tracking changes with #2043.
由索引模型根据 Issue 内容生成。
描述
Summary
Clone::Any 1.01 fails under PerlOnJava because its preferred Clone::clone provider does not preserve a scalar-reference graph and does not release a cloned object at lexical scope exit. Both failures reproduce on the JVM and bytecode interpreter; system Perl passes the distribution suite and the focused reproductions.
CPAN random tester run: 20261120-195805-13340 (Clone-Any--from--Clone-Any). The archived run failed t/06refcnt.t and t/dclone.t. The distribution is pure Perl and has no XS/native prerequisite. Its required Devel::UseAnyFunc dependency is pure Perl.
Reproduction
With Clone-Any 1.01 and its dependency installed, run the graph probe from the distribution root:
use Clone::Any qw(clone);
require './t/dump.pl';
my $value = 'x';
my $shared = \$value;
my $input = [$shared, \$value];
my $copy = clone($input);
print main::dump($input) eq main::dump($copy) ? "same\n" : "different\n";
Expected output is same. Perl 5.42.2 prints same; PerlOnJava prints different on both backends. This is a reduced form of t/dclone.t test 4.
The lifetime failure reduces to cloning an unblessed hash, then blessing both values into a class with DESTROY before leaving scope:
use Clone::Any qw(clone);
package Probe;
sub DESTROY { my $self = shift; print "DESTROY $self->{name}\n" }
package main;
{
my $source = { name => 'source' };
my $copy = clone($source);
$copy->{name} = 'copy';
bless $source, 'Probe';
bless $copy, 'Probe';
}
print "END\n";
Expected system-Perl ordering is both DESTROY lines before END. PerlOnJava destroys source before END but delays copy until global destruction. The same pattern accounts for t/06refcnt.t tests 6–9, which fail on both PerlOnJava backends.
Cause
Clone::Any tries Clone::clone before its other providers. PerlOnJava's src/main/perl/lib/Clone.pm sees Clone::clone as defined after XSLoader::load, so it does not load Clone::PP; the active provider is the Java org.perlonjava.runtime.perlmodule.Clone implementation. On the reproducing launcher, Clone/PP.pm is absent from %INC.
Two concrete defects are visible in Clone.java:
- In the
REFERENCEbranch,deepClonestores and looks up a clone usingscalar.value, which is the referent node, and maps it to a reference wrapper. Repeated references to that referent can therefore return the same wrapper for distinct input reference nodes. The reduced graph probe demonstrates the resulting structural mismatch. The cache needs to preserve Perl reference graph edges while still reconnecting cycles and shared referents. - The HASHREFERENCE and ARRAYREFERENCE branches create fresh clones with
newHash.createReference()andnewArray.createReference(). Those methods setlocalBindingExistsfor named aggregate references. Fresh clone aggregates have no named backing variable; the correspondingcreateAnonymousReference()methods deliberately leave that flag clear soDESTROYcan run when the last owner is released. A focused scope probe confirms the cloned hash'sDESTROYis delayed until global destruction.
The ARRAYREFERENCE branch also appends cloned elements directly to newArray.elements, unlike the HASHREFERENCE branch's newHash.put(...). Audit this path for owner-slot acquisition and release so cloned arrays preserve element lifetimes as well as graph structure.
Evidence
- System Perl 5.42.2: full suite passes, 7 files / 40 tests.
PERL5OPT=-I.is required for this 2003 test suite's legacyrequire 't/…'paths under modern Perl. - PerlOnJava JVM and interpreter:
t/dclone.tfails test 4;t/06refcnt.tfails tests 6–9. Both focused probes above reproduce on both backends. - The focused PerlOnJava runs used launcher build
b9c9a5f54d0dfa6367c85148d064d9f6d1fa8a89on Darwin arm64, Java 24.0.2. The repository checkout was at506371c13. - Duplicate search found no existing Clone-specific issue. The ownership behavior is adjacent to the active work in #2043; coordinate changes to owner tracking with that effort, while keeping this graph-cloning defect independently testable.
Acceptance criteria
- Add project-owned system-Perl-validated regressions for the reduced graph case and cloned-object
DESTROYtiming. - Fix reference-graph caching so the cloned structure matches Perl for shared scalar referents, cycles, and repeated references.
- Use anonymous-reference creation semantics for newly cloned aggregates and correctly account for cloned array element owner slots.
- Pass the focused regressions on JVM and interpreter, then pass Clone-Any 1.01 unchanged on system Perl and both PerlOnJava backends.
- 主要语言
- Perl
- 星标
- 67
- 派生
- 8
- 平均合并
- 4 小时 36 分钟
- 30 天内合并 PR
- 123
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
fglock/PerlOnJava 的其他 Issue
-
area:runtime bug
难度 2/5 1-3 小时 新手友好度 72/100
fglock/PerlOnJava#2164 ·
维护者通常 1 天内回复
-
area:cpan-port bug
难度 2/5 1-3 小时 新手友好度 70/100
fglock/PerlOnJava#2153 ·
维护者通常 1 天内回复
-
area:cpan-port area:parser bug
难度 2/5 1-3 小时 新手友好度 68/100
fglock/PerlOnJava#2137 ·
维护者通常 1 天内回复
-
area:backend area:cpan-port area:runtime bug
难度 2/5 1-3 小时 新手友好度 76/100
fglock/PerlOnJava#2071 ·
维护者通常 1 天内回复
-
area:runtime documentation enhancement
难度 2/5 1-3 小时 新手友好度 72/100
fglock/PerlOnJava#1579 ·
维护者通常 1 天内回复
查看 fglock/PerlOnJava 的全部 Issue
相似的 Issue
-
Dev-output directory preparation accepts file-valued lib/include paths and fails on dangling links未关闭team-cli
难度 2/5 1-3 小时 新手友好度 70/100
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 66/100
-
难度 1/5 1 小时以内 新手友好度 93/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 73/100
inverse-inc/packetfence#9728 ·
维护者通常 1 天内回复
-
fix(char-create): show the real reason a character is refused可能已有人在做 @baphomello 于 1 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 84/100
维护者通常 1 天内回复