-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Add API to exempt function from being traced in JIT #15559
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
Changes from all commits
e0a40f4
d4fdaa6
8e067ce
e9bb403
4349069
498f6ae
6e90810
ef5500f
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 |
---|---|---|
|
@@ -7656,6 +7656,24 @@ static void zend_jit_blacklist_root_trace(const zend_op *opline, size_t offset) | |
zend_shared_alloc_unlock(); | ||
} | ||
|
||
ZEND_EXT_API void zend_jit_blacklist_function(zend_op_array *op_array) { | ||
zend_jit_op_array_trace_extension *jit_extension = (zend_jit_op_array_trace_extension *)ZEND_FUNC_INFO(op_array); | ||
if (!jit_extension || !(jit_extension->func_info.flags & ZEND_FUNC_JIT_ON_HOT_TRACE)) { | ||
return; | ||
} | ||
|
||
zend_shared_alloc_lock(); | ||
SHM_UNPROTECT(); | ||
Comment on lines
+7665
to
+7666
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.
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'm copying the logic from zend_jit_blacklist_root_trace where it's first alloc_lock, then SHM_UNPROTECT? 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. OK. This is not a big problem. |
||
zend_jit_unprotect(); | ||
|
||
zend_jit_stop_persistent_op_array(op_array); | ||
jit_extension->func_info.flags &= ~ZEND_FUNC_JIT_ON_HOT_TRACE; | ||
|
||
zend_jit_protect(); | ||
SHM_PROTECT(); | ||
zend_shared_alloc_unlock(); | ||
} | ||
|
||
static bool zend_jit_trace_is_bad_root(const zend_op *opline, zend_jit_trace_stop stop, size_t offset) | ||
{ | ||
const zend_op **cache_opline = JIT_G(bad_root_cache_opline); | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--TEST-- | ||
Basic usage of opcache_jit_blacklist() | ||
--INI-- | ||
opcache.enable=1 | ||
opcache.enable_cli=1 | ||
opcache.file_update_protection=0 | ||
opcache.protect_memory=1 | ||
opcache.jit=tracing | ||
--EXTENSIONS-- | ||
opcache | ||
--FILE-- | ||
<?php | ||
function foo() { | ||
$x = 1; | ||
$x += 0; | ||
++$x; | ||
var_dump($x); | ||
} | ||
opcache_jit_blacklist(foo(...)); | ||
foo(); | ||
?> | ||
--EXPECT-- | ||
int(2) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
#include "php.h" | ||
#include "ZendAccelerator.h" | ||
#include "zend_API.h" | ||
#include "zend_closures.h" | ||
#include "zend_shared_alloc.h" | ||
#include "zend_accelerator_blacklist.h" | ||
#include "php_ini.h" | ||
|
@@ -924,6 +925,21 @@ ZEND_FUNCTION(opcache_invalidate) | |
} | ||
} | ||
|
||
/* {{{ Prevents JIT on function. Call it before the first invocation of the given function. */ | ||
ZEND_FUNCTION(opcache_jit_blacklist) | ||
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. It would be good to have a least one test for this function. There is a big question about usability of this API. 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. It can be called, but not really tested for its functionality, unless you have a way how to check whether a function is actually executed under jit without looking at it in gdb. 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. Oh, sorry, my mistake. I forgot about automatic registration through |
||
{ | ||
zval *closure; | ||
|
||
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &closure, zend_ce_closure) == FAILURE) { | ||
RETURN_THROWS(); | ||
} | ||
|
||
const zend_function *func = zend_get_closure_method_def(Z_OBJ_P(closure)); | ||
if (ZEND_USER_CODE(func->type)) { | ||
zend_jit_blacklist_function((zend_op_array *)&func->op_array); | ||
} | ||
} | ||
|
||
ZEND_FUNCTION(opcache_compile_file) | ||
{ | ||
zend_string *script_name; | ||
|
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.
Make a normal API not a yet another hack for your observer.
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 what you mean? What would "a normal API" look like?
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.
opcache_jit_blacklist()
function (similaropcache_invalidate
) or use "no-jit" PHP attribute, etc