Skip to content

php-in-php: memory_get_usage()/memory_get_peak_usage() — delete phpc_memory.c (~66 lines), ext/standard/VmMemory.php #5377

Closed

Description

@PurHur

Category

php-in-php

Problem

memory_get_usage() / memory_get_peak_usage() VM builtins exist (ext/standard/memory_get_usage.php, ext/standard/VmMemory.php) but JIT/AOT link lib/AOT/runtime/phpc_memory.c (~66 lines) which reads mallinfo() directly. Self-host should use one PHP implementation (libc via thin FFI or existing VmMemory) and delete the C duplicate.

php-src reference

Repro

<?php
$a = str_repeat('x', 10000);
echo memory_get_usage(), "\n";
echo memory_get_peak_usage(), "\n";
echo memory_get_usage(true), "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php repro.php
php bin/vm.php repro.php
php bin/jit.php repro.php
'
Check Expected
Values increase after allocation yes
$real_usage=true ≥ $real_usage=false yes (Zend shape)
JIT vs VM same order of magnitude; no C-only path

Scope (this repo)

Module Path
Delete C lib/AOT/runtime/phpc_memory.c (~66 lines)
JIT ext/standard/JitMemory.php → delegate to VmMemory
VM consolidate peak tracking in ext/standard/VmMemory.php
Tests test/compliance/cases/stdlib/memory_get_usage_jit.phpt

Done when

  • phpc_memory.c deleted; JIT/AOT call PHP helper
  • Repro monotonicity matches Zend on VM + JIT
  • PR notes ~66 lines removed from lib/AOT/runtime/
  • ./script/ci-fast.sh --filter memory_get_usage green

Links

Activity

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

    @PurHur
    OwnerAuthor

    claim: PHP Runtime → PHP — starting this run.

  3. PurHur commented on Jun 4, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Runtime → PHP — continuing MemoryRuntime migration (cherry-pick + verify + merge).

  4. PurHur commented on Jun 4, 2026

    @PurHur
    OwnerAuthor

    Merged via #5577.

    Verification: MemoryRuntimeStandaloneTest OK; VM memory_get_usage / parity_memory_reset_peak_usage repro green; phpc_memory.c removed from lib/AOT/Linker.php.

    C shrink: deleted lib/AOT/runtime/phpc_memory.c (77 lines) + lib/JIT/Builtin/StringMemory.php (186 lines bitcode glue).

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 / JITarea:vmVirtual machineenhancementNew 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 apps

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions