Skip to content

Commit cbe688d

Browse files
committed
Add tracing jit support
1 parent 71cc1f1 commit cbe688d

File tree

4 files changed

+31
-6
lines changed

4 files changed

+31
-6
lines changed

ext/opcache/jit/zend_jit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3215,7 +3215,7 @@ static int zend_jit(const zend_op_array *op_array, zend_ssa *ssa, const zend_op
32153215
if ((op1_info & (MAY_BE_UNDEF|MAY_BE_ANY|MAY_BE_REF)) != MAY_BE_ARRAY) {
32163216
break;
32173217
}
3218-
if (!zend_jit_count(&dasm_state, opline, op1_info, OP1_REG_ADDR())) {
3218+
if (!zend_jit_count(&dasm_state, opline, op1_info, OP1_REG_ADDR(), zend_may_throw(opline, ssa_op, op_array, ssa))) {
32193219
goto jit_failure;
32203220
}
32213221
goto done;

ext/opcache/jit/zend_jit_trace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5521,7 +5521,7 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
55215521
break;
55225522
}
55235523
}
5524-
if (!zend_jit_count(&dasm_state, opline, op1_info, op1_addr)) {
5524+
if (!zend_jit_count(&dasm_state, opline, op1_info, op1_addr, zend_may_throw(opline, ssa_op, op_array, ssa))) {
55255525
goto jit_failure;
55265526
}
55275527
goto done;

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14249,13 +14249,11 @@ static int zend_jit_strlen(dasm_State **Dst, const zend_op *opline, uint32_t op1
1424914249
return 1;
1425014250
}
1425114251

14252-
static int zend_jit_count(dasm_State **Dst, const zend_op *opline, uint32_t op1_info, zend_jit_addr op1_addr)
14252+
static int zend_jit_count(dasm_State **Dst, const zend_op *opline, uint32_t op1_info, zend_jit_addr op1_addr, int may_throw)
1425314253
{
1425414254
zend_jit_addr res_addr = RES_ADDR();
1425514255

1425614256
if (opline->op1_type == IS_CONST) {
14257-
return 0;
14258-
/*
1425914257
zval *zv;
1426014258
zend_long count;
1426114259

@@ -14265,7 +14263,6 @@ static int zend_jit_count(dasm_State **Dst, const zend_op *opline, uint32_t op1_
1426514263

1426614264
| SET_ZVAL_LVAL res_addr, count
1426714265
| SET_ZVAL_TYPE_INFO res_addr, IS_LONG
14268-
*/
1426914266
} else {
1427014267
ZEND_ASSERT((op1_info & (MAY_BE_UNDEF|MAY_BE_ANY|MAY_BE_REF)) == MAY_BE_ARRAY);
1427114268
// Note: See the implementation of ZEND_COUNT in Zend/zend_vm_def.h - arrays do not contain IS_UNDEF starting in php 8.1+.
@@ -14277,6 +14274,10 @@ static int zend_jit_count(dasm_State **Dst, const zend_op *opline, uint32_t op1_
1427714274
| SET_ZVAL_TYPE_INFO res_addr, IS_LONG
1427814275
| FREE_OP opline->op1_type, opline->op1, op1_info, 0, opline
1427914276
}
14277+
14278+
if (may_throw) {
14279+
return zend_jit_check_exception(Dst);
14280+
}
1428014281
return 1;
1428114282
}
1428214283

ext/opcache/tests/jit/count_001.phpt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ opcache.jit_buffer_size=1M
1010
<?php require_once('skipif.inc'); ?>
1111
--FILE--
1212
<?php
13+
class ThrowsInDestructor {
14+
public function __destruct() {
15+
throw new RuntimeException("In destructor");
16+
}
17+
}
1318
class C {
1419
public static function create_array(int $i): array {
1520
return array_fill(0, $i, new stdClass());
@@ -29,10 +34,24 @@ class C {
2934
public static function count_ref(array &$ref): int {
3035
return count($ref);
3136
}
37+
38+
public static function count_throws(): int {
39+
$result = count([new ThrowsInDestructor()]);
40+
echo "Unreachable\n";
41+
return $result;
42+
}
3243
}
3344
C::foo();
3445
$x = ['x', 'y', 'z', 'a', new stdClass()];
3546
echo C::count_ref($x), "\n";
47+
for ($i = 0; $i < 5; $i++) {
48+
try {
49+
echo C::count_throws(), "\n";
50+
} catch (RuntimeException $e) {
51+
printf("Caught %s\n", $e->getMessage());
52+
}
53+
}
54+
3655
--EXPECT--
3756
0
3857
1
@@ -42,3 +61,8 @@ echo C::count_ref($x), "\n";
4261
3
4362
4
4463
5
64+
Caught In destructor
65+
Caught In destructor
66+
Caught In destructor
67+
Caught In destructor
68+
Caught In destructor

0 commit comments

Comments
 (0)