1
0
mirror of https://github.com/php/php-src.git synced 2026-04-19 22:11:12 +02:00
Commit Graph

3854 Commits

Author SHA1 Message Date
Dmitry Stogov
c28751c69c Merge branch 'PHP-8.0'
* PHP-8.0:
  Fixed bug #80802: (zend_jit_fetch_indirect_var assert failure with tracing JIT)
2021-03-02 00:01:01 +03:00
Dmitry Stogov
957cb13a49 Fixed bug #80802: (zend_jit_fetch_indirect_var assert failure with tracing JIT) 2021-03-01 23:57:20 +03:00
Nikita Popov
47a2e5c785 Reference dynamic functions through dynamic_defs
Currently, dynamically declared functions and closures are inserted
into the function table under a runtime definition key, and then later
possibly renamed. When opcache is not used and a file containing a
closure is repeatedly included, this leads to a very large memory leak,
as the no longer needed closure declarations will never be freed
(https://bugs.php.net/bug.php?id=76982).

With this patch, dynamic functions are instead stored in a
dynamic_func_defs member on the op_array, which opcodes reference
by index. When the parent op_array is destroyed, the dynamic_func_defs
it contains are also destroyed (unless they are stilled used elsewhere,
e.g. because they have been bound, or are used by a live closure). This
resolves the fundamental part of the leak, though doesn't completely
fix it yet due to some arena allocations.

The main non-obvious change here is to static variable handling:
We can't destroy static_variables_ptr in destroy_op_array, as e.g.
that would clear the static variables in a dynamic function when
the op_array containing it is destroyed. Static variable destruction
is separated out for this reason (we already do static variable
destruction separately for normal functions, so we only need to
handle main scripts).

Closes GH-5595.
2021-03-01 11:35:54 +01:00
Nikita Popov
23afc62080 Allow pointer to end of memory in IS_UNSERIALIZED()
We already use <= for IS_SERIALIZED(), but the same general
problem can also occur for IS_UNSERIALIZED(). We don't seem to
hit this in practice prior to GH-5595 though.
2021-02-24 11:46:35 +01:00
Dmitry Stogov
ae2ea348dd Merge branch 'PHP-8.0'
* PHP-8.0:
  Fixed bug #80782 (DASM_S_RANGE_VREG on PHP_INT_MIN-1)
2021-02-24 12:20:49 +03:00
Dmitry Stogov
b7fa5268e4 Fixed bug #80782 (DASM_S_RANGE_VREG on PHP_INT_MIN-1) 2021-02-24 12:20:20 +03:00
Nikita Popov
8be711be47 Merge branch 'PHP-8.0'
* PHP-8.0:
  Fixed bug #80786
2021-02-23 10:22:20 +01:00
Nikita Popov
79cf2c56d3 Fixed bug #80786
Don't use r0 as temporary register in math_double_long if it is
already used for a memory result.

This was already done in one branch, but not the other.
2021-02-23 10:22:00 +01:00
Dmitry Stogov
ac7e967b67 Reduce ZPP API overhead 2021-02-20 13:59:29 +03:00
Nikita Popov
5d160e309e Fix static variable behavior with inheritance
When a method is inherited, the static variables will now always
use the initial values, rather than the values at the time of
inheritance. As such, behavior no longer depends on whether
inheritance happens before or after a method has been called.

This is implemented by always keeping static_variables as the
original values, and static_variables_ptr as the modified copy.

Closes GH-6705.
2021-02-18 11:18:19 +01:00
Dmitry Stogov
5c78e87399 Merge branch 'PHP-8.0'
* PHP-8.0:
  Fixed bug #80745 (JIT produces Assert failure and UNKNOWN:0 var_dumps in code involving bitshifts)
2021-02-17 11:51:50 +03:00
Dmitry Stogov
7f68a7afe6 Fixed bug #80745 (JIT produces Assert failure and UNKNOWN:0 var_dumps in code involving bitshifts) 2021-02-17 11:51:13 +03:00
Dmitry Stogov
319f73e06b Merge branch 'PHP-8.0'
* PHP-8.0:
  Fixed bug #80742 (Opcache JIT makes some boolean logic unexpectedly be true)
2021-02-16 20:02:48 +03:00
Dmitry Stogov
fad87a24da Fixed bug #80742 (Opcache JIT makes some boolean logic unexpectedly be true) 2021-02-16 20:02:12 +03:00
Máté Kocsis
bf0f6aaf18 Improve class entry generation
Related to GH-6701
2021-02-16 13:09:56 +01:00
Dmitry Stogov
15f713bd85 Persist class name before methods, because it may be used insted of "self" 2021-02-15 12:33:53 +03:00
Máté Kocsis
af56982a5e Generate class entries from stubs for oci8, odbc, openssl, pcntl, pdo, pgsql
Closes GH-6691
2021-02-14 23:19:21 +01:00
Nikita Popov
f74a02d263 Revert "Implement fetching TLS TCB offset on MacOS"
This reverts commit 1106ff9a0e.

Looks like this sauses segfaults on MacOs ZTS with JIT.
2021-02-12 15:16:05 +01:00
David Carlier
1106ff9a0e Implement fetching TLS TCB offset on MacOS
Tested with php-cgi and wordpress and 1255 for jit settings.

Closes GH-6659.
2021-02-11 15:48:20 +01:00
Dmitry Stogov
dcf389228c Avoid useless SHM data duplication 2021-02-11 16:51:08 +03:00
Nikita Popov
4c088c5da7 Handle warnings during sccp function evaluation
Some upcoming changes like https://wiki.php.net/rfc/deprecate_null_to_scalar_internal_arg
will make it somewhat inconvenient to determine whether a given
function invocation will generate a diagnostic. Rather than trying
to exclude this in advance, call the function with diagnostics
suppressed, and check whether anything was thrown.

This adds a new EG flag that is kept specific to the SCCP use-case.
This does not use the error_cb hook as it is a (non-TLS) global,
and doesn't fully suppress error handling besides.

Test this by removing the in advance checks for implode and array_flip.
2021-02-11 12:36:35 +01:00
Nikita Popov
7215261349 Update func info after password_get_info() change 2021-02-11 11:44:14 +01:00
Dmitry Stogov
b113f7e88e Unserialize op_array->scope before passing to zend_file_cache_unserialize_type().
Don't use scope of closures.
2021-02-10 23:55:59 +03:00
Dmitry Stogov
ef51648185 Use zend_type.ce_cache__ptr for caching class resulution during argument/result type checks 2021-02-10 18:00:00 +03:00
Dmitry Stogov
a8f6d44c1c Fixed map_ptr slot sharing for trait/self 2021-02-10 17:59:11 +03:00
Dmitry Stogov
6aea64c444 Reuse single map_ptr slot for indentical class names 2021-02-10 15:22:09 +03:00
Tyson Andre
d9510342ee Optimize ZEND_COUNT opcodes on arrays in the jit
Avoid the overhead of a call and checking types
when the argument is definitely an array.
Avoid the overhead of gc when `__destruct` won't get called.

This seemed cheap enough to check for in the jit.

Because of https://wiki.php.net/rfc/restrict_globals_usage
we can be sure in the ZEND_COUNT handler that the array count does not have to
be recomputed in php 8.1.

The below example took 0.854 seconds before the optimization,
and 0.564 seconds after the optimization, giving the same result

```php
<?php
/** @jit */
function bench_count(int $n): int {
    $total = 0;
    $arr = [];
    for ($i = 0; $i < $n; $i++) {
        $arr[] = $i;
        $total += count($arr);
    }
    return $total;
}

function main() {
    $n = 1000;
    $iterations = 50000;
    $start = microtime(true);
    $result = 0;
    for ($i = 0; $i < $iterations; $i++) {
        $result += bench_count($n);
    }
    $elapsed = microtime(true) - $start;

    printf("Total for n=%d, iterations=%d = %d, elapsed=%.3f\n", $n, $iterations, $result, $elapsed);
}
main();
```

Before

```asm
mov $0x7feb8cf8a858, %r15
mov $ZEND_COUNT_SPEC_CV_UNUSED_HANDLER, %rax
call *%rax
```

After

```asm
mov 0x70(%r14), %rdi - Copy the count from the `zend_array*` pointer
mov %rdi, (%rax)     - Store the count in the destination's value
mov $0x4, 0x8(%rax)  - Store IS_LONG(4) in the destination's type
```

And add tracing jit support

Closes GH-5584
2021-02-09 16:09:32 -05:00
Dmitry Stogov
4b79dba932 Added Inheritance Cache.
This is a new transparent technology that eliminates overhead of PHP class inheritance.

PHP  classes are compiled and cached (by opcahce) separately, however their "linking" was done at run-time - on each request. The process of "linking" may involve a number of compatibility checks and borrowing methods/properties/constants form parent and traits. This takes significant time, but the result is the same on each request.

Inheritance Cache performs "linking" for unique set of all the depending classes (parent, interfaces, traits, property types, method types involved into compatibility checks) once and stores result in opcache shared memory. As a part of the this patch, I removed limitations for immutable classes (unresolved constants, typed properties and covariant type checks). So now all classes stored in opcache are "immutable". They may be lazily loaded into process memory, if necessary, but this usually occurs just once (on first linking).

The patch shows 8% improvement on Symphony "Hello World" app.
2021-02-09 22:53:57 +03:00
Nikita Popov
ce79d9476c Merge branch 'PHP-8.0'
* PHP-8.0:
  Try SIGTERM before SIGKILL in opcache restart
2021-02-04 17:07:39 +01:00
Nikita Popov
0c6ff5eafa Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  Try SIGTERM before SIGKILL in opcache restart
2021-02-04 17:07:30 +01:00
Nikita Popov
8b7aaad7d6 Try SIGTERM before SIGKILL in opcache restart
SIGTERM is subject to HANDLE_BLOCK_INTERRUPTIONS(), which will
allow code to exit critical sections before it gets terminated.

Closes GH-6493.
2021-02-04 17:07:18 +01:00
David CARLIER
559fc46b9f Fix ubsan warning on macos
Closes GH-6652.
2021-02-01 10:25:00 +01:00
Remi Collet
88c339465e Merge branch 'PHP-8.0'
* PHP-8.0:
  NEWS
  NEWS
  Fix #80682 opcache doesn't honour pcre.jit option
2021-01-28 16:27:00 +01:00
Remi Collet
4a35f4a476 Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  NEWS
  Fix #80682 opcache doesn't honour pcre.jit option
2021-01-28 16:26:26 +01:00
Remi Collet
067f7e4150 Fix #80682 opcache doesn't honour pcre.jit option 2021-01-28 16:24:39 +01:00
Nikita Popov
83be073abe Move optimizer into core
This only moves the files, adjusts the build system, exports APIs
and does minor fixups to make sure the code builds.

This does not yet try to make the optimizer usable independently
of opcache.

Closes GH-6642.
2021-01-28 10:38:25 +01:00
Dmitry Stogov
b6bfb27b8e Merge branch 'PHP-8.0'
* PHP-8.0:
  Fixed observer API and JIT compatibility
2021-01-26 21:31:51 +03:00
Dmitry Stogov
64622979f9 Fixed observer API and JIT compatibility 2021-01-26 21:31:15 +03:00
David CARLIER
4414fd93d0 Distinguishing opcache SHM on stats tools for Mac
Closes GH-6628.
2021-01-26 10:51:33 +01:00
Nikita Popov
7571edc398 Merge branch 'PHP-8.0'
* PHP-8.0:
  Fix opcache phpize build on FreeBSD
  Updated to version 2021.1 (2021a)
2021-01-25 15:11:56 +01:00
Alex Samorukov
527bcb1e2e Fix opcache phpize build on FreeBSD
Closes GH-6589.
2021-01-25 15:10:47 +01:00
Dusk
13c430b1db Add array_is_list(array $array) function
This function tests if an array contains only sequential integer keys. While
list isn't an official type, this usage is consistent with the community usage
of "list" as an annotation type, cf.
https://psalm.dev/docs/annotating_code/type_syntax/array_types/#lists

Rebased and modified version of #4886

- Use .stub.php files
- Add opcache constant evaluation when argument is a constant
- Change from is_list(mixed $value) to array_is_list(array $array)

RFC: https://wiki.php.net/rfc/is_list

Co-Authored-By: Tyson Andre <tysonandre775@hotmail.com>
Co-Authored-By: Dusk <dusk@woofle.net>

Closes GH-6070
2021-01-20 18:53:48 -05:00
Nikita Popov
32cf58f7ba Merge branch 'PHP-8.0'
* PHP-8.0:
  Skip preloading test on windows
2021-01-20 10:09:46 +01:00
Nikita Popov
286c13e1e6 Skip preloading test on windows 2021-01-20 10:09:31 +01:00
Dmitry Stogov
378f870d7c Merge branch 'PHP-8.0'
* PHP-8.0:
  Fixed bug #80634 (write_property handler of internal classes is skipped on preloaded JITted code)
2021-01-20 11:04:30 +03:00
Dmitry Stogov
6288228b56 Fixed bug #80634 (write_property handler of internal classes is skipped on preloaded JITted code) 2021-01-20 11:03:37 +03:00
Nikita Popov
dbe5725ff3 Rename zend-test to zend_test
The extension name should match the name of the ext/ directory,
otherwise it will not get picked up by run-tests. It would be possible
to remap this in run-tests, but I think it's better to rename the
extension to follow the standard format. Other extensions also
use underscore instead of hyphen (e.g. pdo_mysql and not pdo-mysql).
Of course, the ./configure option remains hyphenated.

Closes GH-6613.
2021-01-19 15:28:15 +01:00
Nikita Popov
e422ab2af7 Merge branch 'PHP-8.0'
* PHP-8.0:
  Keep JIT region executable under ZTS
2021-01-19 10:28:42 +01:00
Dylan K. Taylor
872f302b8d Keep JIT region executable under ZTS
When one thread tries to compile a script, another thread may
already be executing JITed code. In this case we can't make the
memory non-executable.

This violates the W^X principle, but doesn't seem to be avoidable
for ZTS builds for now. The same problem does not exist for NTS,
as it's a different process executing there, which has it's own
memory protection mapping.

Closes GH-6595.
2021-01-19 10:25:42 +01:00
Nikita Popov
29cf59895a Merge branch 'PHP-8.0'
* PHP-8.0:
  Observe unused return values in JIT
2021-01-19 10:10:08 +01:00