Commit graph

202 commits

Author SHA1 Message Date
Saki Takamachi
462fd4dffe
Small change SIMD codes (#18626)
* use zend_simd.h in zend_accelerator_util_funcs.c

* use zend_simd.h in mbstring

* Remove unnecessary SSE3 includes
2025-05-26 16:32:27 +09:00
Ilija Tovilo
cd8ee4dad1
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix lineno in function redeclaration error
2024-10-22 15:06:06 +02:00
Ilija Tovilo
381e020edb
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix lineno in function redeclaration error
2024-10-22 15:05:29 +02:00
Ilija Tovilo
de7ef3fa66
Fix lineno in function redeclaration error
We were previously using the lineno of the first instruction, rather than the
start of the function itself.

Fixes GH-16509
Closes GH-16531
2024-10-22 15:04:20 +02:00
Ilija Tovilo
1c30c5e707
Print location on class redeclaration
Fixes GH-13950
Closes GH-13999
2024-04-30 14:34:43 +02:00
Ilija Tovilo
692cea5cbc
Use zend_error_noreturn for E_ERROR consistently
To be clear, these already don't return. zend_error_noreturn just hints at this
fact through the ZEND_NORETURN attribute.

Closes GH-12204
2023-09-14 11:44:55 +02:00
Ilija Tovilo
0600f513b3
Implement delayed early binding for classes without parents
Normally, we add classes without parents (and no interfaces or traits) directly
to the class map, early binding the class. However, if the same class has
already been registered, we would instead just add a ZEND_DECLARE_CLASS
instruction and let the handler throw a duplicate class declaration exception.

However, with opcache, if on the next request the files are included in the
opposite order, we won't perform early binding. To fix this, create a
ZEND_DECLARE_CLASS_DELAYED instruction instead and handle classes without
parents accordingly, skipping any linking for classes that are already linked in
delayed early binding.

Fixes GH-8846
2023-05-15 10:25:33 +02:00
Ilija Tovilo
e0af7c332d
Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix delayed early binding class redeclaration error
2023-05-12 19:29:27 +02:00
Ilija Tovilo
e3499130f1
Fix delayed early binding class redeclaration error
If we bind the class to the runtime slot even if we're not the ones who have
performed early binding we'll miss the redeclaration error in the
ZEND_DECLARE_CLASS_DELAYED handler.

Closes GH-11226
2023-05-12 19:29:04 +02:00
Niels Dossche
722fbd01a3
Implement an SSE2 accelerated version of zend_adler32 (#10507)
When benchmarking the file cache of opcache on index.php from a dummy
WordPress install, I noticed that 36.42% of the time was spent in
zend_adler32 to verify the checksums of the files. Callgrind reported
that 332,731,216 instructions were executed during that run and average
time to execute the index file was around 91ms.

This patch implements an SSE2 accelerated version of zend_adler32, which
reduces the number of instructions executed on that bench to
248,600,983, which is a reduction of ~25%. There is also a decrease in
wallclock time measurable: around 10ms. Now only 16.05% of the time is
spent computing checksums.

The benchmark tests were performed using Callgrind, and time for the
wallclock time. These tests were executed multiple times and their
results were averaged. The WordPress install only contains two
almost-blank posts.
2023-02-05 15:58:39 +00:00
Jorg Adam Sowa
77ee92a50c
Remove unnecessary usage of CONST_CS
Closes GH-9685.
2022-11-28 17:12:07 +01:00
Ilija Tovilo
6622c54c53
Fix class link observer with file_cache_only=1
Previously, notify would only get called on classes with CE_CACHE.
However, during compilation class names are non-permanent which won't
get a CE_CACHE and thus wouldn't not get notified.

Closes GH-9550
2022-09-16 14:15:05 +02:00
Dmitry Stogov
7f74a30018
Reduce observer overhead when restoring script from opcache (#9413)
* Reduce observer overhead when restoring script from opcache

* typo

* Split loops to keep notifications in case of redeclaration errors
2022-08-25 19:49:16 +03:00
Bob Weinand
396b2aab85 Wrap observer notify functions into inlined enabled checks
Signed-off-by: Bob Weinand <bobwei9@hotmail.com>
2022-08-23 15:22:22 +02:00
Bob Weinand
bf427b732a Add an API to observe functions and classes being linked
To observe when the functions and classes start being officially available to the user

Signed-off-by: Bob Weinand <bobwei9@hotmail.com>
2022-08-23 15:22:22 +02:00
Arnaud Le Blanc
a69708382a
Extended map_ptr before copying class table (#9188)
Fixes GH-9164
2022-08-01 19:21:34 +02:00
Dmitry Stogov
d56ec0a624 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fixed bug #81607 (CE_CACHE allocation with concurrent access)
2021-11-17 18:25:00 +03:00
Dmitry Stogov
76548e5093 Fixed bug #81607 (CE_CACHE allocation with concurrent access) 2021-11-17 18:23:36 +03:00
Nikita Popov
89007f67d4 Fix delayed early bind if class already exists
We should not try to perform a delayed early bind if the class has
already been declared. This matches the behavior of an ordinary
early bind.
2021-10-14 14:29:22 +02:00
Dmitry Stogov
ddaf64b56c Avoid non-immutable map_ptr indirection 2021-10-14 12:16:18 +03:00
Nikita Popov
c19977d054 Fix delayed early binding with optimization
It's possible for delayed early binding opcodes to get optimized
away if they are "unreachable". However, we still need to attempt
early binding for them. (In some cases we also corrupt the early
binding list outright during optimization, which is how I got here.)

Fix this by storing information about delayed early binding
independently of DECLARE_CLASS_DELAYED opcodes, so early binding is
performed even after the opcode has been dropped.
2021-09-29 18:00:20 +02:00
Nikita Popov
ccff3d93c3 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix func/class name use after free on opcache OOM condition
2021-09-14 12:03:22 +02:00
Nikita Popov
e7de9b2091 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix func/class name use after free on opcache OOM condition
2021-09-14 12:03:03 +02:00
Nikita Popov
10e9f6b340 Fix func/class name use after free on opcache OOM condition
This can occur on opcache OOM conditions, where the function/class
names are not interned and the script does not get cached. In
that case the functions/classes get transferred from the persistent
script to the global tables, without incrementing the key refcount.
To mirror that, we should also not try to free the keys when freeing
the persistent script. For this by setting the number of elements
to zero, which will free only the hashtable structure itself.
2021-09-14 12:00:44 +02:00
Nikita Popov
d9e5c6b0b3 Free recorded warnings if script not cached 2021-09-14 11:04:35 +02:00
Levi Morrison
ae8647d9d3
Remove leading underscore for _zend_hash_find_known_hash (#7260)
Convert zend_hash_find_ex(..., 1) to zend_hash_find_known_hash(...)
Convert zend_hash_find_ex(..., 0) to zend_hash_find(...)

Also add serializable changes to UPGRADING.INTERNALS summary
2021-07-20 17:07:17 -06:00
KsaR
01b3fc03c3
Update http->https in license (#6945)
1. Update: http://www.php.net/license/3_01.txt to https, as there is anyway server header "Location:" to https.
2. Update few license 3.0 to 3.01 as 3.0 states "php 5.1.1, 4.1.1, and earlier".
3. In some license comments is "at through the world-wide-web" while most is without "at", so deleted.
4. fixed indentation in some files before |
2021-05-06 12:16:35 +02:00
Dmitry Stogov
0fc3818cc5 Initialize fast class cache 2021-04-13 15:54:02 +03:00
Dmitry Stogov
65859fe17e Inheritance cache optimization 2021-03-11 13:42:35 +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
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
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
Dmitry Stogov
b3bbb8fe3b Mark classes cached by opcache by ZEND_ACC_CACHED flag and prevent useless copying and desrpoying of immutable data. 2021-01-19 11:55:09 +03:00
Dmitry Stogov
aa16aee51c Cleanup:
- ZCG(bind_hash) is not used anymore
- zend_accel_function_hash_copy() and zend_accel_function_hash_copy_from_shm() are the same
- zend_accel_class_hash_copy() and zend_accel_class_hash_copy_from_shm() are almost the same
2021-01-12 08:54:09 +03:00
Nikita Popov
1314ccbf8c Cache __unserialize() instead of unserialize()
We should use these cache slots for the new object serialization
mechanism rather than the old one.
2020-06-26 10:54:40 +02:00
Dmitry Stogov
95248491af Prefer already cached version of the script 2020-05-20 23:04:34 +03:00
Nikita Popov
bd1977282c Use zend_type inside type lists
Instead of having a completely independent encoding for type list
entries. This is going to use more memory, but I'm not particularly
concerned about that, as type unions that contain multiple classes
should be uncommon. On the other hand, this allows us to treat
top-level types and types inside lists mostly the same.

A new ZEND_TYPE_FOREACH macros allows to transparently treat list
and non-list types the same way. I'm not using it everywhere it could be
used for now, just the places that seemed most obvious.

Of course, this will make any future type system changes much simpler,
as it will not be necessary to duplicate all logic two times.
2020-01-17 09:37:54 +01:00
Nikita Popov
aadd5e69e0 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #78986
2019-12-18 11:41:11 +01:00
Nikita Popov
bd4fce4f6f Fixed bug #78986
Don't assume that handlers live in the arena, they may also be in
SHM.
2019-12-18 11:40:58 +01:00
Nikita Popov
a40a69fdd0 Merge branch 'PHP-7.4'
* PHP-7.4:
  Introduce extra counter to avoid RTD key collisions
2019-12-13 11:05:41 +01:00
Nikita Popov
0f2cdbf214 Introduce extra counter to avoid RTD key collisions
Also generate a fatal error if a collision occurs in zend_compile.

This is not perfect, because collisions might still be introduced
via opcache, if one file is included multiple times during a request,
invalidate in the meantime and recompiled by different processes.

This still needs to be addressed, but this patch fixes the much
more common case of collisions occuring when opcache is not used.

Fixes bug #78903.
2019-12-13 11:04:44 +01:00
Nikita Popov
999e32b65a Implement union types
According to RFC: https://wiki.php.net/rfc/union_types_v2

The type representation now makes use of both the pointer payload
and the type mask at the same time. Additionall, zend_type_list is
introduced as a new kind of pointer payload, which is used to store
multiple class types. Each of the class types is a tagged pointer,
which may be either a class name or class entry. The latter is only
used for typed properties, while arguments/returns will instead use
cache slots. A type list can contain a mix of both names and CEs at
the same time, as not all classes may be resolvable.

One thing this is missing is support for union types in arginfo
and stubs, which I want to handle separately.

I've also dropped the special object code from the JIT implementation
for now -- I plan to add this back in a different form at a later time.
For now I did not want to include non-trivial JIT changes together
with large functional changes.

Another possible piece of follow-up work is to implement "iterable"
as an internal alias for "array|Traversable". I believe this will
eliminate quite a few special-cases that had to be implemented.

Closes GH-4838.
2019-11-08 15:15:48 +01:00
Nikita Popov
ac4e0f0852 Make zend_type a 2-field struct
We now store the pointer payload and the type mask separately. This
is in preparation for union types, where we will be using both at
the same time.

To avoid increasing the size of arginfo structures, the
pass_by_reference and is_variadic fields are now stored as part of
the type_mask (8-bit are reserved for custom use).

Different types of pointer payloads are distinguished based on bits
in the type_mask.
2019-11-08 15:15:48 +01:00
Nikita Popov
f1848a4b3f Fix bug #78226: Don't call __set() on uninitialized typed properties
Assigning to an uninitialized typed property will no longer trigger
a call to __set(). However, calls to __set() are still triggered if
the property is explicitly unset().

This gives us both the behavior people generally expect, and still
allows ORMs to do lazy initialization by unsetting properties.

For PHP 8, we should fine a way to forbid unsetting of declared
properties entirely, and provide a different way to achieve lazy
initialization.
2019-10-25 16:31:45 +02:00
Joe Watkins
042e3b227e
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fix checksum calculation for opcache
2019-10-14 16:50:23 +02:00
Joe Watkins
22ac57b064
Merge branch 'PHP-7.2' into PHP-7.3
* PHP-7.2:
  Fix checksum calculation for opcache
2019-10-14 16:49:48 +02:00
Mitch Hagstrand
e2a6bf482f
Fix checksum calculation for opcache 2019-10-14 16:46:42 +02:00
Nikita Popov
c8af6a7fa7 Don't use fast_memcpy under msan 2019-07-01 11:14:23 +02:00
Peter Kokot
bebcdcc745 Remove legacy AC_CHECK_TYPE calls for uint and ulong
The AC_CHECK_TYPE was refactored in more recent versions of Autoconf
and the call with two arguments is obsolete and not recommended anymore.

This patch also refactors some leftovers of using ulong and uint which
are not standard nor common usages of types in C.

The ulong can be used as zend_ulong and uint usage is actually
`unsigned int`.

The usage of HAVE_ULONG removed since it is not used in current code
base.

Legacy edgecase for some legacy HPUX systems removed:
- sys/stream.h header is not checked and the HAVE_SYS_STREAM_H is
  not defined with current build system.

- flags are unsigned int
- max_allowed_packet changed to unsigned int
2019-03-06 22:49:16 +01:00
Dmitry Stogov
da919a8b65 Remove copyright years. 2019-02-05 10:33:28 +03:00