Skip to content

php-in-php: JIT GcCollectCyclesRuntime — route gc_collect_cycles() through CycleCollector PHP not ~1.3k-line LLVM (#1492) #9269

Description

@PurHur

Category

php-in-php

Problem

gc_collect_cycles() VM builtin already delegates to PHPCompiler\VM\CycleCollector from ext/standard/gc_collect_cycles.php, but JIT/AOT still links ~1280 lines of LLVM in lib/JIT/Builtin/GcCollectCyclesRuntime.php + GcCollectCyclesNative.php (__compiler_gc_collect_cycles, destructor lists, hashtable walks). GC semantics should live in PHP (lib/VM/CycleCollector.php) with a thin JIT trampoline — not a parallel native collector.

php-src reference

  • Zend/zend_gc.c — cycle collection, root buffer, destructor ordering
  • ext/standard/info.c — PHP_FUNCTION(gc_collect_cycles)

Repro

<?php
class Node { public ?Node $next = null; public function __destruct() { echo "dtor\n"; } }
$a = new Node; $b = new Node; $a->next = $b; $b->next = $a; unset($a, $b);
echo gc_collect_cycles(), "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php repro.php'
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/jit.php repro.php'

Zend: prints 2 (two nodes collected) and destructor output order per GC flags.
This compiler VM: uses CycleCollector::collect() — JIT must call the same helper.

Scope (this repo)

Area Path Action
VM SSOT lib/VM/CycleCollector.php Keep collector logic here
Stdlib ext/standard/gc_collect_cycles.php, JitGcCollectCycles.php JIT bridge → PHP collector
Delete/shrink lib/JIT/Builtin/GcCollectCyclesRuntime.php, GcCollectCyclesNative.php Remove LLVM collector
gc_status pair lib/JIT/Builtin/GcStatusRuntime.php Coordinate with #9150

Done when (php-src-strict)

  • JIT/AOT gc_collect_cycles() invokes CycleCollector (or shared PHP helper), not LLVM hashtable walk
  • GcCollectCyclesRuntime.php deleted or thin shim; PR cites lines removed from lib/JIT/Builtin/
  • Repro cycle count + destructor behavior matches Zend on VM and JIT
  • test/unit/GcCollectCycles*.php + compliance guards green
  • No new symbols in runtime/*.c

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter GcCollectCycles'
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/jit.php test/compliance/cases/stdlib/gc_collect_cycles_basic.phpt'

Links

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:compilerCompiler / CFG / JITenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-0:FoundationPhase 0 – foundation & DevExphase-2:languagePhase 2 – language features

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions