Skip to content

php-in-php: JIT ObOutputRuntime — route ob_* stack through VmObOutput PHP not ~1k-line LLVM (#1492) #9268

Description

@PurHur

Category

php-in-php

Problem

Output buffering (ob_start, ob_get_contents, ob_end_flush, implicit flush, echo into active buffer) is implemented twice: VM uses ext/standard/VmOb.php / VmObOutput.php, while JIT/AOT embeds ~1050 lines of LLVM stack management in lib/JIT/Builtin/ObOutputRuntime.php (__phpc_ob_* globals, libc fwrite, buffer caps). This is classic PHP-in-PHP debt — behavior belongs in ext/standard, not a second C-like runtime in LLVM IR.

php-src reference

  • ext/standard/output.cphp_ob_* stack, handlers, flush
  • main/output.c — SAPI output layer interaction

Repro (VM vs JIT must match)

<?php
ob_start();
echo 'hello';
$buf = ob_get_contents();
ob_end_clean();
var_dump($buf);
echo ob_get_level(), "\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: string(5) "hello", level 0.
Done when: identical on VM and JIT/AOT after migration.

Nested buffers + ob_implicit_flush smoke:

<?php
ob_start(); ob_start(); echo 'x'; var_dump(ob_get_level()); ob_end_flush(); ob_end_flush();

Scope (this repo)

Area Path Action
Stdlib SSOT ext/standard/VmOb.php, VmObOutput.php, ob_*.php Single ob stack implementation
JIT bridge ext/standard/JitOb*.php (extend) Route JIT calls to PHP helpers
Delete/shrink lib/JIT/Builtin/ObOutputRuntime.php, ObOutput.php Remove LLVM ob stack
Echo lowering lib/JIT.php ob echo paths Call PHP bridge instead of __phpc_ob_echo_*
Related lib/JIT/Builtin/ObGzhandlerJitRuntime.php Pairs with #9091 (handler callback)

Do not reintroduce lib/AOT/runtime/phpc_ob.c logic — shrink C, grow PHP.

Done when (php-src-strict)

  • JIT/AOT ob stack uses the same PHP state machine as VM (VmObOutput)
  • ObOutputRuntime.php deleted or <50-line ABI shim; PR cites lines removed
  • Repro scripts match Zend on VM + JIT + AOT
  • Existing ob_* compliance PHPTs green on JIT/AOT
  • make bootstrap-selfhost-vm-driver-execute-probe still green if echo/ob touched on spine

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter Ob'
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/jit.php test/compliance/cases/stdlib/ob_start_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-4:stdlibPhase 4 – stdlib for web apps

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions