Skip to content

Commit c170512

Browse files
committed
Use ZEND_FUNC_JIT_ON_HOT_TRACE flag
Signed-off-by: Bob Weinand <[email protected]>
1 parent 5aacb99 commit c170512

File tree

5 files changed

+38
-32
lines changed

5 files changed

+38
-32
lines changed

ext/opcache/jit/zend_jit_trace.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7658,21 +7658,18 @@ static void zend_jit_blacklist_root_trace(const zend_op *opline, size_t offset)
76587658

76597659
ZEND_EXT_API void zend_jit_blacklist_function(zend_op_array *op_array) {
76607660
zend_jit_op_array_trace_extension *jit_extension = (zend_jit_op_array_trace_extension *)ZEND_FUNC_INFO(op_array);
7661-
if (!jit_extension) {
7661+
if (!jit_extension || !(jit_extension->func_info.flags & ZEND_JIT_ON_HOT_TRACE)) {
76627662
return;
76637663
}
76647664

7665-
zend_jit_stop_persistent_op_array(op_array);
7665+
zend_shared_alloc_lock();
7666+
SHM_UNPROTECT();
76667667

7667-
// First not-skipped op
7668-
zend_op *opline = op_array->opcodes;
7669-
if (!(op_array->fn_flags & ZEND_ACC_HAS_TYPE_HINTS)) {
7670-
while (opline->opcode == ZEND_RECV || opline->opcode == ZEND_RECV_INIT) {
7671-
opline++;
7672-
}
7673-
}
7668+
zend_jit_stop_persistent_op_array(op_array);
7669+
jit_extension->func_info.flags &= ~ZEND_FUNC_JIT_ON_HOT_TRACE;
76747670

7675-
zend_jit_blacklist_root_trace(opline, jit_extension->offset);
7671+
SHM_PROTECT();
7672+
zend_shared_alloc_unlock();
76767673
}
76777674

76787675
static bool zend_jit_trace_is_bad_root(const zend_op *opline, zend_jit_trace_stop stop, size_t offset)

ext/opcache/jit/zend_jit_vm_helpers.c

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -515,24 +515,14 @@ static int zend_jit_trace_record_fake_init_call_ex(zend_execute_data *call, zend
515515
if (func->type == ZEND_USER_FUNCTION) {
516516
jit_extension =
517517
(zend_jit_op_array_trace_extension*)ZEND_FUNC_INFO(&func->op_array);
518-
if (func->op_array.fn_flags & ZEND_ACC_CLOSURE) {
519-
if (UNEXPECTED(!jit_extension
520-
|| !(jit_extension->func_info.flags & ZEND_FUNC_JIT_ON_HOT_TRACE)
521-
|| (func->op_array.fn_flags & ZEND_ACC_FAKE_CLOSURE))) {
522-
return -1;
523-
}
524-
func = (zend_function*)jit_extension->op_array;
525-
}
526-
// First not-skipped op
527-
zend_op *opline = func->op_array.opcodes;
528-
if (!(func->op_array.fn_flags & ZEND_ACC_HAS_TYPE_HINTS)) {
529-
while (opline->opcode == ZEND_RECV || opline->opcode == ZEND_RECV_INIT) {
530-
opline++;
531-
}
532-
}
533-
if (jit_extension && ZEND_OP_TRACE_INFO(opline, jit_extension->offset)->trace_flags & ZEND_JIT_TRACE_BLACKLISTED) {
518+
if (UNEXPECTED(!jit_extension
519+
|| !(jit_extension->func_info.flags & ZEND_FUNC_JIT_ON_HOT_TRACE)
520+
|| (func->op_array.fn_flags & ZEND_ACC_FAKE_CLOSURE))) {
534521
return -1;
535522
}
523+
if (func->op_array.fn_flags & ZEND_ACC_CLOSURE) {
524+
func = (zend_function*)jit_extension->op_array;
525+
}
536526
}
537527
if (is_megamorphic == ZEND_JIT_EXIT_POLYMORPHISM
538528
/* TODO: use more accurate check ??? */
@@ -988,11 +978,6 @@ zend_jit_trace_stop ZEND_FASTCALL zend_jit_trace_execute(zend_execute_data *ex,
988978
break;
989979
}
990980

991-
if (jit_extension && ZEND_OP_TRACE_INFO(opline, offset)->trace_flags & ZEND_JIT_TRACE_BLACKLISTED) {
992-
stop = ZEND_JIT_TRACE_STOP_BLACK_LIST;
993-
break;
994-
}
995-
996981
TRACE_RECORD(ZEND_JIT_TRACE_ENTER,
997982
EX(return_value) != NULL ? ZEND_JIT_TRACE_RETURN_VALUE_USED : 0,
998983
op_array);

ext/opcache/opcache.stub.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ function opcache_compile_file(string $filename): bool {}
1414

1515
function opcache_invalidate(string $filename, bool $force = false): bool {}
1616

17+
function opcache_jit_blacklist(Closure $closure): void {}
18+
1719
/**
1820
* @return array<string, mixed>|false
1921
* @refcount 1

ext/opcache/opcache_arginfo.h

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/opcache/zend_accelerator_module.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "php.h"
2525
#include "ZendAccelerator.h"
2626
#include "zend_API.h"
27+
#include "zend_closures.h"
2728
#include "zend_shared_alloc.h"
2829
#include "zend_accelerator_blacklist.h"
2930
#include "php_ini.h"
@@ -924,6 +925,21 @@ ZEND_FUNCTION(opcache_invalidate)
924925
}
925926
}
926927

928+
/* {{{ Prevents JIT on function. Call it before the first invocation of the given function. */
929+
ZEND_FUNCTION(opcache_jit_blacklist)
930+
{
931+
zend_object *closure;
932+
933+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &closure, zend_ce_closure) == FAILURE) {
934+
RETURN_THROWS();
935+
}
936+
937+
const zend_function *func = zend_get_closure_method_def(closure);
938+
if (ZEND_USER_CODE(func->type)) {
939+
zend_jit_blacklist_function((zend_op_array *)&func->op_array);
940+
}
941+
}
942+
927943
ZEND_FUNCTION(opcache_compile_file)
928944
{
929945
zend_string *script_name;

0 commit comments

Comments
 (0)