-
Notifications
You must be signed in to change notification settings - Fork 8k
Implement acyclic object tracking #17130
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
Draft
iluuu1994
wants to merge
9
commits into
php:master
Choose a base branch
from
iluuu1994:acyclic-object-tracking
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.
+294
−64
Draft
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f855458
Implement acyclic object tracking
iluuu1994 fc13fb6
tmp
iluuu1994 1e06e3b
Fix weakmap
iluuu1994 4e5fca5
Fix dynamic property case added in unserializer
iluuu1994 84b4d70
Remove unnecessary gc_check_possible_root()
iluuu1994 cb82014
Use GC_{ADD,DEL}_FLAGS() helper macros
iluuu1994 d445bf1
Fix missing reference unwrap before gc_possible_root() call in JIT
iluuu1994 e3f4882
Also exclude simple stateless closures
iluuu1994 aabc161
Fix test for opcache
iluuu1994 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
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,107 @@ | ||
| --TEST-- | ||
| GC 051: Acyclic objects are not added to GC buffer | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| function test($x) { | ||
| assert($x); // Prevent inlining | ||
| } | ||
|
|
||
| enum E { | ||
| case A; | ||
| case B; | ||
| case C; | ||
| } | ||
|
|
||
| #[AllowDynamicProperties] | ||
| class AcyclicC { | ||
| public int $a; | ||
| public string $b; | ||
| } | ||
|
|
||
| class CyclicC { | ||
| public array $a; | ||
| } | ||
|
|
||
| echo "Enums\n"; | ||
| test(E::A); | ||
| test(E::B); | ||
| test(E::C); | ||
| var_dump(gc_status()['roots']); | ||
|
|
||
| echo "Acyclic object\n"; | ||
| $o = new AcyclicC; | ||
| test($o); | ||
| var_dump(gc_status()['roots']); | ||
| unset($o); | ||
|
|
||
| echo "Cyclic object\n"; | ||
| $o = new CyclicC; | ||
| test($o); | ||
| var_dump(gc_status()['roots']); | ||
| unset($o); | ||
|
|
||
| echo "Acyclic object with dynamic properties\n"; | ||
| $o = new AcyclicC; | ||
| $o->dyn = 42; | ||
| test($o); | ||
| var_dump(gc_status()['roots']); | ||
| unset($o); | ||
|
|
||
| echo "Stateless closure\n"; | ||
| $o = static function () {}; | ||
| test($o); | ||
| var_dump(gc_status()['roots']); | ||
| unset($o); | ||
|
|
||
| echo "Closure with bindings\n"; | ||
| $x = []; | ||
| $o = static function () use ($x) {}; | ||
| unset($x); | ||
| test($o); | ||
| var_dump(gc_status()['roots']); | ||
| unset($o); | ||
|
|
||
| echo "Closure with static vars\n"; | ||
| $o = static function () { | ||
| static $x; | ||
| }; | ||
| test($o); | ||
| var_dump(gc_status()['roots']); | ||
| unset($o); | ||
|
|
||
| echo "Non-static closure\n"; | ||
| $o = function () {}; | ||
| test($o); | ||
| var_dump(gc_status()['roots']); | ||
| unset($o); | ||
|
|
||
| echo "Generator\n"; | ||
| $c = static function () { yield; }; // Not collectable | ||
| test($c); | ||
| $o = $c(); // Collectable | ||
| test($o); | ||
| var_dump(gc_status()['roots']); | ||
| unset($o); | ||
| unset($c); | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| Enums | ||
| int(0) | ||
| Acyclic object | ||
| int(0) | ||
| Cyclic object | ||
| int(1) | ||
| Acyclic object with dynamic properties | ||
| int(1) | ||
| Stateless closure | ||
| int(0) | ||
| Closure with bindings | ||
| int(1) | ||
| Closure with static vars | ||
| int(1) | ||
| Non-static closure | ||
| int(1) | ||
| Generator | ||
| int(1) |
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
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.
We should also mark classes with custom
get_propertieshandler as potentially cyclic, as this is called byzend_std_get_gc.Otherwise this looks right to me, as objects with std
get_gcandget_propertiescan not expose anything other than standard properties to the GC.Lazy objects need to take care of updating
GC_NOT_COLLECTABLE: RemoveGC_NOT_COLLECTABLEinzend_object_make_lazy()when the initializer is cyclic or may have a ref to the object itself, and add it again inzend_lazy_object_init().