Skip to content

php-in-php: route JIT memory_get_* through MemoryJitHelper PHP (#9377) - #10930

Merged
PurHur merged 1 commit into
masterfrom
agent/issue-9377-memory-runtime-php
Jun 23, 2026
Merged

PurHur merged 1 commit into
masterfrom
agent/issue-9377-memory-runtime-php

Conversation

@PurHur

@PurHur PurHur commented Jun 23, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add ext/standard/MemoryJitHelper.php as SSOT for JIT/AOT memory_get_usage(), memory_get_peak_usage(), memory_reset_peak_usage(), gc_mem_caches(), and emalloc noteAlloc — delegating to VmMemory, MemoryAccounting, and VmGcStatus.
  • Shrink lib/JIT/Builtin/MemoryRuntime.php from ~360-line RSS/statm/emalloc LLVM monolith to thin ABI bridges (removed /proc/self/statm libc LLVM, peak/current globals, inline gc_mem_caches hashtable math).
  • Simplify ext/standard/JitMemory.php (~50% LOC) to call bridges instead of LLVM peak tracking.

php-src ref: ext/standard/basic_functions.c, ext/standard/php_gc.c

Closes #9377

C/LLVM shrink

  • Deleted from MemoryRuntime.php: emitReadRssBytes (libc open/read/strtol), emitReadEmallocBytes, inline emitNoteAlloc, inline ensureGcMemCaches, __phpc_memory_peak_* / __phpc_memory_current_* globals, ensureLibcForStatm, cstring helper (~200 LLVM lines removed).

Verification

vendor/bin/phpunit test/unit/MemoryRuntimeShrinkTest.php test/unit/JIT/MemoryRuntimeStandaloneTest.php
# OK (6 tests)

php script/check-selfhost-spine-coverage-sync.php
# OK

php script/bootstrap-inventory.php --check
# OK 2952/2952

# Issue repro (VM vs JIT):
php bin/vm.php -r '$a=array_fill(0,5000,str_repeat("x",100));unset($a);var_dump(memory_get_usage(true));var_dump(gc_mem_caches());'
php bin/jit.php -r '$a=array_fill(0,5000,str_repeat("x",100));unset($a);var_dump(memory_get_usage(true));var_dump(gc_mem_caches());'
# Both emit int gc_mem_caches values; RSS may differ slightly by timing.

Made with Cursor

Replace MemoryRuntime RSS/statm LLVM and emalloc globals with thin bridges
to compiled MemoryJitHelper delegating to VmMemory/MemoryAccounting/VmGcStatus.
Shrinks JitMemory peak-tracking LLVM; adds shrink guards and spine entry.

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant