Skip to content

php-in-php: JIT MemoryRuntime — route memory_get_usage()/gc_mem_caches() through VmMemory PHP not LLVM RSS/emalloc globals (#1492) #9377

Closed

Description

@PurHur

Category

php-in-php | stdlib

Problem

memory_get_usage(), memory_get_peak_usage(), and gc_mem_caches() JIT/AOT lowering lives in lib/JIT/Builtin/MemoryRuntime.php (~300 lines LLVM): module globals for emalloc peaks, RSS reads via __phpc_memory_read_rss_bytes, and __phpc_gc_mem_caches. VM semantics already live in ext/standard/VmMemory.php (PHP).

This duplicates php-src memory accounting in LLVM instead of calling the existing PHP implementation through the JIT helper bridge pattern (Utf8JitHelper, HrtimeJitHelper, …). Blocks shrinking JIT surface and keeps VM/JIT divergence risk (#9333, #9336).

php-src reference

  • ext/standard/basic_functions.c — PHP_FUNCTION(memory_get_usage), memory_get_peak_usage
  • ext/standard/php_gc.c — PHP_FUNCTION(gc_mem_caches)
  • Stubs: ext/standard/basic_functions.stub.php — enum MemoryUsage: int

Repro (today: VM works; issue is LLVM duplication + parity guards)

<?php
declare(strict_types=1);
$a = array_fill(0, 5000, str_repeat('x', 100));
unset($a);
var_dump(memory_get_usage(true));
var_dump(gc_mem_caches()); // VM returns 0 today — #9333

Commands

./script/docker-exec.sh php bin/vm.php repro.php
./script/docker-exec.sh php bin/jit.php repro.php   # uses MemoryRuntime LLVM

Scope (this repo)

  • Delete/shrink: lib/JIT/Builtin/MemoryRuntime.php LLVM bodies (__phpc_memory_*, __phpc_gc_mem_caches)
  • Route through: ext/standard/VmMemory.php via compiled helper (MemoryJitHelper or reuse VmMemory static entrypoints)
  • Touch: ext/standard/memory_get_usage.php, memory_get_peak_usage.php, gc_mem_caches.php, lib/JIT/Builtin/MemoryUsageJit.php
  • Do not add new logic in runtime/*.c — thin ABI trampoline only if unavoidable

Done when (php-src-strict)

Refs: #1492, #3134, #5377, #9333, #9336

Activity

  1. added
    enhancementNew feature or request
    phase-4:stdlibPhase 4 – stdlib for web apps
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Jun 18, 2026
  2. PurHur commented on Jun 23, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Runtime → PHP — batch (issues #9377, #9134)

  3. PurHur commented on Jun 23, 2026

    @PurHur
    OwnerAuthor

    Merged via #10930.

    Verification:

    • vendor/bin/phpunit test/unit/MemoryRuntimeShrinkTest.php test/unit/JIT/MemoryRuntimeStandaloneTest.php — OK
    • php script/bootstrap-inventory.php --check — OK 2952/2952
    • Issue repro: VM/JIT memory_get_usage(true) + gc_mem_caches() both run; ~200 LLVM lines removed from MemoryRuntime (RSS/statm libc, emalloc globals).
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-4:stdlibPhase 4 – stdlib for web appsstdlib

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions