-
Notifications
You must be signed in to change notification settings - Fork 8.1k
re-enable JIT for ZTS builds on Apple Silicon #22712
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
base: master
Are you sure you want to change the base?
Changes from all commits
807e29d
f7021f3
e883ad7
8f51da2
20fc5c6
c626ddf
8624eb4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -17,6 +17,13 @@ | |||||||||||||||||||
| #ifndef HAVE_JIT_H | ||||||||||||||||||||
| #define HAVE_JIT_H | ||||||||||||||||||||
|
|
||||||||||||||||||||
| #if defined(__APPLE__) && defined(__aarch64__) && defined(ZTS) | ||||||||||||||||||||
| # ifndef HAVE_PTHREAD_JIT_WRITE_PROTECT_NP | ||||||||||||||||||||
| # error "Apple Silicon ZTS JIT requires pthread_jit_write_protect_np()" | ||||||||||||||||||||
| # endif | ||||||||||||||||||||
| # define ZEND_JIT_USE_APPLE_MAP_JIT 1 | ||||||||||||||||||||
| #endif | ||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be feasible to unify all
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Technically the split could be done for all macOS builds, but the protection path cannot be unified.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes sense. Can we merge the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice finding, I cleaned it up in 8f51da2 . I also change the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for the changes. There are also cases where we call php-src/ext/opcache/jit/zend_jit.c Lines 3528 to 3536 in 8f51da2
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did a bit of research and found that those where added in #8382 and adjusted in #9371. They are effectively obsolete: Apple Silicon ZTS now takes the dedicated |
||||||||||||||||||||
|
|
||||||||||||||||||||
| #if defined(__x86_64__) || defined(i386) || defined(ZEND_WIN32) | ||||||||||||||||||||
| # define ZEND_JIT_TARGET_X86 1 | ||||||||||||||||||||
| # define ZEND_JIT_TARGET_ARM64 0 | ||||||||||||||||||||
|
|
||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| --TEST-- | ||
| GH-13400: JIT code generated after fork is visible to the parent | ||
| --DESCRIPTION-- | ||
| OPcache metadata and generated JIT code are shared by forked workers, so the | ||
| JIT mapping and its allocation pointer must remain shared after fork. This test | ||
| records the available JIT space before forking and makes only the child call a | ||
| function often enough to generate code. The parent then verifies that it sees | ||
| the reduced free space and can execute the generated function. | ||
|
|
||
| Without shared inheritance, a private JIT mapping becomes copy-on-write in the | ||
| child. The parent's free-space check would print bool(false), while shared | ||
| OPcache metadata could point the parent at code bytes that exist only in the | ||
| child and cause a crash instead of printing int(42). A startup-only test would | ||
| not detect this failure in fork-based SAPIs such as FPM or Apache. | ||
| --EXTENSIONS-- | ||
| opcache | ||
| pcntl | ||
| --INI-- | ||
| opcache.enable=1 | ||
| opcache.enable_cli=1 | ||
| opcache.file_update_protection=0 | ||
| opcache.jit=tracing | ||
| opcache.jit_buffer_size=16M | ||
| opcache.jit_hot_func=1 | ||
| --SKIPIF-- | ||
| <?php | ||
| if (!function_exists('pcntl_fork')) die('skip pcntl_fork() not available'); | ||
| if (!(opcache_get_status()['jit']['on'] ?? false)) die('skip JIT is not available'); | ||
| ?> | ||
| --FILE-- | ||
| <?php | ||
| function value(): int { | ||
| return 42; | ||
| } | ||
|
|
||
| $bufferFree = opcache_get_status()['jit']['buffer_free']; | ||
| $pid = pcntl_fork(); | ||
| if ($pid === 0) { | ||
| for ($i = 0; $i < 100; $i++) { | ||
| value(); | ||
| } | ||
| exit(0); | ||
| } | ||
| if ($pid === -1) { | ||
| echo "pcntl_fork() failed\n"; | ||
| exit(1); | ||
| } | ||
|
|
||
| pcntl_waitpid($pid, $status); | ||
| var_dump(opcache_get_status()['jit']['buffer_free'] < $bufferFree); | ||
| var_dump(value()); | ||
| ?> | ||
| --EXPECT-- | ||
| bool(true) | ||
| int(42) |
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.
I don't understand this change, could you comment on why this is necessary?