Skip to content

Fix GH-17770: allow opcache.file_cache writes when JIT is enabled#21219

Open
gregharmon wants to merge 2 commits intophp:masterfrom
gregharmon:codex/gh-17770-file-cache-jit
Open

Fix GH-17770: allow opcache.file_cache writes when JIT is enabled#21219
gregharmon wants to merge 2 commits intophp:masterfrom
gregharmon:codex/gh-17770-file-cache-jit

Conversation

@gregharmon
Copy link

Summary

zend_file_cache_script_store() had an explicit JIT guard that returned FAILURE whenever JIT_G(on) was true, which prevented second-level file cache writes under JIT.

This change removes that behavior and allows opcache.file_cache writes with JIT enabled.

Details

  • ext/opcache/zend_file_cache.c
    • In zend_file_cache_script_store(), stop unconditionally failing when JIT is enabled.
    • Keep behavior safe by temporarily setting JIT_G(on)=0 during file-cache serialization/write and restoring it on all exits.
    • Re-normalize opcode handlers before serialization (ZEND_VM_SET_OPCODE_HANDLER) so runtime JIT handlers are not serialized into file cache payloads.

This preserves the intended model: file cache stores OPcache bytecode/metadata only; JIT machine code is not persisted and is rebuilt at runtime as usual.

Tests

Added regression test:

  • ext/opcache/tests/gh17770_jit_file_cache_write.phpt

The test enables JIT + file cache, compiles a temp script, and asserts that at least one file is written under opcache.file_cache.

Local runs:

make test TESTS=ext/opcache/tests/gh17770_jit_file_cache_write.phpt
make test TESTS='ext/opcache/tests/gh17770_jit_file_cache_write.phpt ext/opcache/tests/gh16979_check_file_cache_function.phpt ext/opcache/tests/bug71443.phpt ext/opcache/tests/bug76275.phpt ext/opcache/tests/bug78189.phpt'

Results: new test passes; focused file-cache subset passes (with bug78189 skipped on non-Windows).

@gregharmon
Copy link
Author

Addressed the Windows CI failure in the new GH-17770 regression test.

Update in ext/opcache/tests/gh17770_jit_file_cache_write.phpt:

  • Switched opcache.file_cache to a quoted dedicated path: {PWD}/gh17770_cache
  • Pre-creates that directory in --SKIPIF--
  • Keeps the test hermetic by cleaning the dedicated cache directory in --CLEAN--
  • Uses opcache_is_script_cached_in_file_cache() for direct script-level assertion

This keeps the regression intent unchanged while avoiding startup/path issues on Windows workers.

@dstogov
Copy link
Member

dstogov commented Feb 16, 2026

This preserves the intended model: file cache stores OPcache bytecode/metadata only; JIT machine code is not persisted and is rebuilt at runtime as usual.

JIT compilation takes time. And it's not going to be profitable in case we re-do it on each request.
I suppose, file_cache without JIT should be faster when with JIT.

Probably, this change may be helpful for some cases - e.g rare opcache resets, but it's probably not a big problem to recompile php from sources. In case of often resets, enabling JIT will probably increase CPU load and for file_cache_only increase it significantly.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants