-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Optimize ZEND_COUNT opcodes on arrays in the jit #5584
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
Closed
Closed
Changes from all commits
Commits
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
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,68 @@ | ||
--TEST-- | ||
JIT COUNT: 001 | ||
--INI-- | ||
opcache.enable=1 | ||
opcache.enable_cli=1 | ||
opcache.file_update_protection=0 | ||
opcache.jit_buffer_size=1M | ||
;opcache.jit_debug=1 | ||
--SKIPIF-- | ||
<?php require_once('skipif.inc'); ?> | ||
--FILE-- | ||
<?php | ||
class ThrowsInDestructor { | ||
public function __destruct() { | ||
throw new RuntimeException("In destructor"); | ||
} | ||
} | ||
class C { | ||
public static function create_array(int $i): array { | ||
return array_fill(0, $i, new stdClass()); | ||
} | ||
|
||
public static function foo() { | ||
$x = [self::create_array(5)]; | ||
echo count(self::create_array(0)), "\n"; | ||
echo count(self::create_array(1)), "\n"; | ||
echo count($x[0]), "\n"; | ||
$a = []; | ||
for ($i = 0; $i < 4; $i++) { | ||
$a[] = $i; | ||
echo count($a) . "\n"; | ||
} | ||
} | ||
public static function count_ref(array &$ref): int { | ||
return count($ref); | ||
} | ||
|
||
public static function count_throws(): int { | ||
$result = count([new ThrowsInDestructor()]); | ||
echo "Unreachable\n"; | ||
return $result; | ||
} | ||
} | ||
C::foo(); | ||
$x = ['x', 'y', 'z', 'a', new stdClass()]; | ||
echo C::count_ref($x), "\n"; | ||
for ($i = 0; $i < 5; $i++) { | ||
try { | ||
echo C::count_throws(), "\n"; | ||
} catch (RuntimeException $e) { | ||
printf("Caught %s\n", $e->getMessage()); | ||
} | ||
} | ||
|
||
--EXPECT-- | ||
0 | ||
1 | ||
5 | ||
1 | ||
2 | ||
3 | ||
4 | ||
5 | ||
Caught In destructor | ||
Caught In destructor | ||
Caught In destructor | ||
Caught In destructor | ||
Caught In destructor |
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.
You also need to add it to zend_jit_trace.c for it to be meaningfully useful.
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.
Implemented in zend_jit_trace.c based on the handler for ZEND_STRLEN