Fix Clone::clone graph aliases and DESTROY timing

Đang mở
#2,159 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
28/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
java, perl
Lĩnh vực
backend

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

area:cpan-port area:memory area:runtime bug

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:

  1. In the REFERENCE branch, deepClone stores and looks up a clone using scalar.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.
  2. The HASHREFERENCE and ARRAYREFERENCE branches create fresh clones with newHash.createReference() and newArray.createReference(). Those methods set localBindingExists for named aggregate references. Fresh clone aggregates have no named backing variable; the corresponding createAnonymousReference() methods deliberately leave that flag clear so DESTROY can run when the last owner is released. A focused scope probe confirms the cloned hash's DESTROY is 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 legacy require 't/…' paths under modern Perl.
  • PerlOnJava JVM and interpreter: t/dclone.t fails test 4; t/06refcnt.t fails tests 6–9. Both focused probes above reproduce on both backends.
  • The focused PerlOnJava runs used launcher build b9c9a5f54d0dfa6367c85148d064d9f6d1fa8a89 on Darwin arm64, Java 24.0.2. The repository checkout was at 506371c13.
  • 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 DESTROY timing.
  • 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.
Ngôn ngữ chính
Perl
Star
67
Fork
8
Merge trung bình
4 giờ 36 phút
Pull request đã merge (30 ngày)
123

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của fglock/PerlOnJava

Tất cả issue của fglock/PerlOnJava

Issue tương tự

Thêm issue về Perl

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.