-
Notifications
You must be signed in to change notification settings - Fork 8.1k
[RFC] OPcache Static Cache Implementation #22052
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zeriyoshi
wants to merge
40
commits into
php:master
Choose a base branch
from
colopl:opcache_static_cache_impl
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
00977da
[RFC] OPcache Static Cache Implementation
zeriyoshi 029c458
fix: remove benchmark PHPT
zeriyoshi 572e288
fix: trying fix windows build
zeriyoshi 62e15f8
fix: re fix windows build
zeriyoshi 6256193
fix: regenerate func info
zeriyoshi d09edba
fix: add test CONFLICTS
zeriyoshi 4236efe
chore: revert unnecessary changes
zeriyoshi 2485440
chore: revert unnecessary chang for JIT
zeriyoshi 3154dc2
fix: opcache is currently always bundled
zeriyoshi aa9bb2d
chore: add licence header to test helpers
zeriyoshi f6b3435
fix: trying fix to conflicted test failure
zeriyoshi db02275
fix: move mutation test to under fpm tests
zeriyoshi 3076549
fix: RFC 1.1
zeriyoshi 4a7b085
fix
zeriyoshi 941f18e
Rename OPcache static cache persistent backend to pinned
zeriyoshi 4110009
trying rshutdown graph compaction
zeriyoshi 479a741
fix realloc
zeriyoshi 70e2bef
fix: opcache static cache hooks
zeriyoshi 853893e
fix: invalid opcache SHM initialization
zeriyoshi 5acf427
refactor and fixes
zeriyoshi c50d7d3
refactor and regenerate func_infos
zeriyoshi a8e9e44
zend_atomic: fix argument order
zeriyoshi bd4847c
fix: Windows implementations
zeriyoshi b3e913e
fix: MSVC build error
zeriyoshi 781d761
refactor and behavior changes
zeriyoshi c6e94c4
fix API
zeriyoshi 26788d0
fix: update func infos
zeriyoshi 63c594a
fix tests
zeriyoshi 586648f
refactor and add tests
zeriyoshi bfa571d
security: pool separation and security option
zeriyoshi 74e576d
test: add more tests
zeriyoshi db28e1c
2.0.0
zeriyoshi 2fc3b65
fix: regenerate zend_func_infos.h
zeriyoshi 11240f5
fix: Windows build
zeriyoshi 3f0ebc4
3.0.0 new API design, more performance improvements
zeriyoshi c29db11
fix: repeat test require cache reset
zeriyoshi 1a99a96
Apply Nicolas's static cache improvements
zeriyoshi 37dd563
fix: regression of request-local ordinary-object clone path
zeriyoshi 665b739
fix: memory management and zts build issue
zeriyoshi 982a5f4
feat: improve API
zeriyoshi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| --TEST-- | ||
| ASSIGN_OBJ_REF tracks object mutations before freeing operands | ||
| --SKIPIF-- | ||
| <?php | ||
| $zendDir = dirname(__DIR__); | ||
| if (!is_file($zendDir . '/zend_vm_def.h') || !is_file($zendDir . '/zend_vm_execute.h')) { | ||
| die('skip source tree required'); | ||
| } | ||
| ?> | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| function assertAssignObjRefTrackingOrder(string $section, string $label): bool | ||
| { | ||
| $trackPos = strpos($section, 'ZEND_MAYBE_TRACK_OBJECT_MUTATION(zobj);'); | ||
| $freeNeedles = [ | ||
| 'FREE_OP1();', | ||
| 'FREE_OP2();', | ||
| 'FREE_OP_DATA();', | ||
| 'zval_ptr_dtor_nogc(EX_VAR(opline->op1.var));', | ||
| 'zval_ptr_dtor_nogc(EX_VAR(opline->op2.var));', | ||
| 'zval_ptr_dtor_nogc(EX_VAR((opline+1)->op1.var));', | ||
| ]; | ||
| $freePositions = []; | ||
|
|
||
| foreach ($freeNeedles as $needle) { | ||
| $pos = strpos($section, $needle); | ||
| if ($pos !== false) { | ||
| $freePositions[] = $pos; | ||
| } | ||
| } | ||
|
|
||
| if ($trackPos === false) { | ||
| throw new RuntimeException($label . ' is missing the expected ASSIGN_OBJ_REF sequence'); | ||
| } | ||
|
|
||
| if ($freePositions === []) { | ||
| return false; | ||
| } | ||
|
|
||
| if ($trackPos > min($freePositions)) { | ||
| throw new RuntimeException($label . ' tracks object mutation after freeing operands'); | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| $zendDir = dirname(__DIR__); | ||
|
|
||
| $vmDef = file_get_contents($zendDir . '/zend_vm_def.h'); | ||
| $defStart = strpos($vmDef, 'ZEND_VM_HANDLER(32, ZEND_ASSIGN_OBJ_REF'); | ||
| $defEnd = strpos($vmDef, 'ZEND_VM_HANDLER(33, ZEND_ASSIGN_STATIC_PROP_REF'); | ||
| if ($defStart === false || $defEnd === false) { | ||
| throw new RuntimeException('Unable to locate ZEND_ASSIGN_OBJ_REF in zend_vm_def.h'); | ||
| } | ||
|
|
||
| if (!assertAssignObjRefTrackingOrder(substr($vmDef, $defStart, $defEnd - $defStart), 'zend_vm_def.h')) { | ||
| throw new RuntimeException('zend_vm_def.h ASSIGN_OBJ_REF unexpectedly has no operand frees'); | ||
| } | ||
|
|
||
| $vmExecute = file_get_contents($zendDir . '/zend_vm_execute.h'); | ||
| $sections = preg_split('/(?=static ZEND_OPCODE_HANDLER_RET )/', $vmExecute); | ||
| $checked = 0; | ||
|
|
||
| foreach ($sections as $section) { | ||
| $headerEnd = strpos($section, "\n"); | ||
| $label = $headerEnd === false ? 'zend_vm_execute.h ASSIGN_OBJ_REF handler' : trim(substr($section, 0, $headerEnd)); | ||
| if (!preg_match('/\bZEND_ASSIGN_OBJ_REF_[A-Z0-9_]+_HANDLER\b/', $label)) { | ||
| continue; | ||
| } | ||
|
|
||
| if (assertAssignObjRefTrackingOrder($section, $label)) { | ||
| $checked++; | ||
| } | ||
| } | ||
|
|
||
| if ($checked === 0) { | ||
| throw new RuntimeException('Unable to locate generated ZEND_ASSIGN_OBJ_REF handlers in zend_vm_execute.h'); | ||
| } | ||
|
|
||
| echo "OK\n"; | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| OK |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| --TEST-- | ||
| OPcache static cache init hooks are request guarded | ||
| --SKIPIF-- | ||
| <?php | ||
| $zendDir = dirname(__DIR__); | ||
| foreach (['zend_object_handlers.c', 'zend_vm_def.h', 'zend_vm_execute.h'] as $file) { | ||
| if (!is_file($zendDir . '/' . $file)) { | ||
| die('skip source tree required'); | ||
| } | ||
| } | ||
| ?> | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| function requireGuardedHook(string $source, string $file, string $hook, int $minimum): void | ||
| { | ||
| $unguarded = 'UNEXPECTED(' . $hook . ' != NULL)'; | ||
| if (str_contains($source, $unguarded)) { | ||
| throw new RuntimeException($file . ' calls ' . $hook . ' without the request guard'); | ||
| } | ||
|
|
||
| $pattern = '/EG\\(static_cache_class_access_active\\) &&\\s+' . preg_quote($hook, '/') . ' != NULL\\)\\s*\\)?\\s*\\{\\s+' . preg_quote($hook, '/') . '\\(/s'; | ||
| if (preg_match_all($pattern, $source) < $minimum) { | ||
| throw new RuntimeException($file . ' is missing the guarded ' . $hook . ' calls'); | ||
| } | ||
| } | ||
|
|
||
| $zendDir = dirname(__DIR__); | ||
|
|
||
| requireGuardedHook( | ||
| file_get_contents($zendDir . '/zend_object_handlers.c'), | ||
| 'zend_object_handlers.c', | ||
| 'zend_class_init_statics_hook', | ||
| 1 | ||
| ); | ||
|
|
||
| foreach (['zend_vm_def.h' => 2, 'zend_vm_execute.h' => 4] as $file => $minimum) { | ||
| requireGuardedHook( | ||
| file_get_contents($zendDir . '/' . $file), | ||
| $file, | ||
| 'zend_function_init_statics_hook', | ||
| $minimum | ||
| ); | ||
| } | ||
|
|
||
| echo "OK\n"; | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| OK |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| --TEST-- | ||
| Tracked mutation hooks are called through defensive helpers | ||
| --SKIPIF-- | ||
| <?php | ||
| $zendDir = dirname(__DIR__); | ||
| foreach (['zend_execute.h', 'zend_execute.c', 'zend_vm_def.h', 'zend_vm_execute.h'] as $file) { | ||
| if (!is_file($zendDir . '/' . $file)) { | ||
| die('skip source tree required'); | ||
| } | ||
| } | ||
| ?> | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| function sourceSection(string $source, string $start, string $end, string $label): string | ||
| { | ||
| $startPos = strpos($source, $start); | ||
| $endPos = strpos($source, $end, $startPos === false ? 0 : $startPos); | ||
|
|
||
| if ($startPos === false || $endPos === false || $endPos <= $startPos) { | ||
| throw new RuntimeException('Unable to locate ' . $label); | ||
| } | ||
|
|
||
| return substr($source, $startPos, $endPos - $startPos); | ||
| } | ||
|
|
||
| $zendDir = dirname(__DIR__); | ||
| $executeH = file_get_contents($zendDir . '/zend_execute.h'); | ||
| $executeC = file_get_contents($zendDir . '/zend_execute.c'); | ||
|
|
||
| if (!str_contains($executeH, 'static zend_always_inline bool zend_maybe_track_hash_mutation(HashTable *ht, bool publish)')) { | ||
| throw new RuntimeException('Missing hash mutation helper'); | ||
| } | ||
|
|
||
| if (!str_contains($executeH, 'zend_tracked_hash_mutation_hook != NULL')) { | ||
| throw new RuntimeException('Hash mutation helper does not guard the hook pointer'); | ||
| } | ||
|
|
||
| foreach (['zend_execute.c', 'zend_vm_def.h', 'zend_vm_execute.h'] as $file) { | ||
| $source = file_get_contents($zendDir . '/' . $file); | ||
| if (str_contains($source, 'zend_tracked_hash_mutation_hook(')) { | ||
| throw new RuntimeException($file . ' calls zend_tracked_hash_mutation_hook() directly'); | ||
| } | ||
| } | ||
|
|
||
| if (!str_contains($executeC, 'zobj != NULL && zend_tracked_object_mutation_hook != NULL && EG(exception) == NULL')) { | ||
| throw new RuntimeException('Object mutation slow path does not guard the hook pointer'); | ||
| } | ||
|
|
||
| if (!str_contains($executeC, 'zobj != NULL && zend_tracked_object_mutation_hook != NULL && EG(exception) == NULL && value != &EG(error_zval)')) { | ||
| throw new RuntimeException('Object mutation with-value slow path does not guard the hook pointer'); | ||
| } | ||
|
|
||
| $assign = sourceSection( | ||
| $executeH, | ||
| 'static zend_always_inline zval* zend_assign_to_variable(', | ||
| 'static zend_always_inline zval* zend_assign_to_variable_ex(', | ||
| 'zend_assign_to_variable()' | ||
| ); | ||
| if (substr_count($assign, 'zend_maybe_track_reference_update(updated_ref);') < 2) { | ||
| throw new RuntimeException('zend_assign_to_variable() does not notify reference updates'); | ||
| } | ||
|
|
||
| $assignEx = sourceSection( | ||
| $executeH, | ||
| 'static zend_always_inline zval* zend_assign_to_variable_ex(', | ||
| 'static zend_always_inline void zend_class_static_update(', | ||
| 'zend_assign_to_variable_ex()' | ||
| ); | ||
| if (substr_count($assignEx, 'zend_maybe_track_reference_update(updated_ref);') < 2) { | ||
| throw new RuntimeException('zend_assign_to_variable_ex() does not notify reference updates'); | ||
| } | ||
|
|
||
| echo "OK\n"; | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| OK |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nits: These arguments are reversed