Commit graph

242 commits

Author SHA1 Message Date
Bob Weinand
53fa98ecd3
Fix GH-17715: Handle preloaded internal function runtime cache (#17835)
This solely affects the builtin enum functions currently.

Given that these are stored in SHM, we cannot simply hardwire a pointer into the internal function runtime cache on NTS too, but have to use a MAP_PTR (like on ZTS).
Now, by design, the runtime cache of internal functions no longer is reset between requests, hence we need to store them explicitly as static runtime cache.

On NTS builds we cannot trivially move the pointers into CG(internal_run_time_cache) as they're directly stored on the individual functions (on ZTS we could simply iterate the static map_ptrs).
Hence, we have the choice between having opcache managing the internal run_time_cache for its preloaded functions itself or realloc CG(internal_run_time_cache) and iterate through all functions to assign the new address. We choose the latter for simplicity and initial speed.
2025-02-24 14:35:47 +01:00
Christoph M. Becker
5eed224c6c
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  opcache_get_configuration() properly reports jit_prof_threshold
2024-12-09 11:46:51 +01:00
Christoph M. Becker
3702f9783b
opcache_get_configuration() properly reports jit_prof_threshold
The `jit_prof_threshold` is a float, supposed to be in range [0, 1],
and usually very small (the default is 0.005).  Reporting it as int
is meaningless.

Closes GH-17077.
2024-12-09 11:45:16 +01:00
Calvin Buckley
f5f05e886e
Fix regression on systems built without JIT (#16024)
regressing commit: 654b787ee1

This was called if JIT was enabled or not. If not enabled, it'll result
in an undeclared function warning and maybe a bad time in the linker.
Gate the meat of this PHP-side function on if JIT is enabled (but keep
it existing so PHP userland code works with or without JIT, OFC).
2024-09-24 11:38:59 -03:00
Bob Weinand
654b787ee1
Add API to exempt function from being traced in JIT (#15559)
Internally accessible via zend_jit_blacklist_function / externally via opcache_jit_blacklist.
The functionality currently only affects tracing JIT, but may be extended to other JIT modes in future.
2024-09-24 14:20:38 +02:00
Peter Kokot
5d3fab9334
Sync #if/ifdef/defined (#14520)
These are either undefined or defined (to value 1):
- __DragonFly__
- __FreeBSD__
- HAS_MCAST_EXT
- HAVE_GETCWD
- HAVE_GETWD
- HAVE_GLIBC_ICONV
- HAVE_JIT
- HAVE_LCHOWN
- HAVE_NL_LANGINFO
- HAVE_RL_CALLBACK_READ_CHAR
- HAVE_RL_ON_NEW_LINE
- HAVE_SQL_EXTENDED_FETCH
- HAVE_UTIME

Follow up of GH-5526 (-Wundef)
2024-06-11 22:47:05 +02:00
Peter Kokot
84a0da1574
Sync #if/ifdef/defined (#14508)
This syncs CPP macro conditions:
- _WIN32
- _WIN64
- HAVE_ALLOCA_H
- HAVE_ALPHASORT
- HAVE_ARPA_INET_H
- HAVE_CONFIG_H
- HAVE_DIRENT_H
- HAVE_DLFCN_H
- HAVE_GETTIMEOFDAY
- HAVE_LIBDL
- HAVE_POLL_H
- HAVE_PWD_H
- HAVE_SCANDIR
- HAVE_SYS_FILE_H
- HAVE_SYS_PARAM_H
- HAVE_SYS_SOCKET_H
- HAVE_SYS_TIME_H
- HAVE_SYS_TYPES_H
- HAVE_SYS_WAIT_H
- HAVE_UNISTD_H
- PHP_WIN32
- ZEND_WIN32

These are either undefined or defined to 1 in Autotools and Windows.

Follow up of GH-5526 (-Wundef).
2024-06-09 14:23:41 +02:00
Arnaud Le Blanc
1bae61a4d2
Compress interned string table offsets and increase maximum supported buffer size (#13676)
Compress interned string table offsets and increase maximum supported buffer size

The interned string buffer is organized as a header + a hash table + a
zend_string arena. Hash slots point to the arena, but are represented as 32bit
offsets from the buffer, which limits the maximum buffer size to about 4GiB.
However zend_strings are 8-byte aligned in the buffer, so we can compress the
3 lower bits. This allows to increase the maximum supported interned string
buffer size from 4095 MiB to 32767 MiB.
2024-03-19 13:01:30 +01:00
Daniil Gentili
c16ad918ba
Change default method of disabling JIT
https://wiki.php.net/rfc/jit_config_defaults
Closes GH-12678
2024-01-15 09:39:13 +01:00
Dmitry Stogov
1f25dea498 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  memory_consumption must be page aligned
2023-10-23 12:11:01 +03:00
Dmitry Stogov
fed7937d27 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  memory_consumption must be page aligned
2023-10-23 12:10:54 +03:00
Dmitry Stogov
e270ee3008 memory_consumption must be page aligned 2023-10-23 12:10:11 +03:00
Mikhail Galanin
958a25e22e
Add "revalidate" time to opcache scripts list
Closes GH-11816
2023-08-03 10:01:39 +02:00
Ilija Tovilo
b2dbf0a2c6
Remove opcache.consistency_checks
This feature has been broken at least since the tracing JIT and inheritance
cache have been introduced. The attempted fix (GH-10798) was too complex. We
have thus decided to remove this feature for now.

Closes GH-11832
2023-08-02 19:22:30 +02:00
Niels Dossche
e90c96bc8d Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix GH-11715: opcache.interned_strings_buffer either has no effect or opcache_get_status() / phpinfo() is wrong
2023-07-21 13:10:04 +02:00
Niels Dossche
404f1d3700 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-11715: opcache.interned_strings_buffer either has no effect or opcache_get_status() / phpinfo() is wrong
2023-07-21 13:09:44 +02:00
Niels Dossche
ee3f932390 Fix GH-11715: opcache.interned_strings_buffer either has no effect or opcache_get_status() / phpinfo() is wrong
There are a couple of oddities.

1) The interned strings buffer comprises the whole hashtable
   datastructure.
   Therefore, it seems that the interned strings buffer size is the size of
   only said table. However, in the current code it also includes the size
   of the zend_accel_shared_globals.

2) ZCSG(interned_strings).end is computed starting from the accelerator
   globals struct itself. I would expect it to start from the part where
   the interned strings table starts.

3) When computing the used size, it is done using
   ZCSG(interned_strings).end - ZCSG(interned_strings).start. However,
   this does not include the uin32_t slots array because
   ZCSG(interned_strings).start pointers after that array.

This patch corrrects these 3 points.

Closes GH-11717.
2023-07-21 13:04:53 +02:00
Sara
0e5ac62f4e
Add configuration opcache.jit_max_trace_length (#11173)
Max length of a single trace. A long trace generates long JITTed
code, which influences the performance slightly.
opcache.jit_max_trace_length range is [4,1024], the default value
is 1024.


Reviewed-by:   Su, Tao   <tao.su@intel.com>

Signed-off-by: Wang, Xue <xue1.wang@intel.com>
2023-05-02 18:47:13 +03:00
Niels Dossche
b39ff334a3 Merge branch 'PHP-8.2'
* PHP-8.2:
  Re-add some CTE functions that were removed from being CTE by a mistake
  Fix GH-8065: opcache.consistency_checks > 0 causes segfaults in PHP >= 8.1.5 in fpm context
  Fix GH-8646: Memory leak PHP FPM 8.1
2023-03-07 20:36:41 +01:00
Niels Dossche
7682868dd1 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-8065: opcache.consistency_checks > 0 causes segfaults in PHP >= 8.1.5 in fpm context
  Fix GH-8646: Memory leak PHP FPM 8.1
2023-03-07 20:26:57 +01:00
Niels Dossche
85df512a12 Fix GH-8065: opcache.consistency_checks > 0 causes segfaults in PHP >= 8.1.5 in fpm context
Disable opcache.consistency_checks.

This feature does not work right now and leads to memory leaks and other
problems. For analysis and discussion see GH-8065. In GH-10624 it was
decided to disable the feature to prevent problems for end users.
If end users which to get some consistency guarantees, they can rely on
opcache.protect_memory.

Closes GH-10798.
2023-03-07 20:17:55 +01:00
Niels Dossche
821fc55a68
Implement GH-9826: Make class_alias() work with internal classes (#10483)
We can't increase the refcount of internal classes during request time.
To work around this problem we simply don't refcount aliases anymore and
add a check in the destruction to skip aliases entirely.
There were also some checks which checked for an alias implicitly by
comparing the refcount, these have been replaced by checking the type of
the zval instead.
2023-02-22 11:47:32 +01:00
Arnaud Le Blanc
479b47c6f0 Merge branch 'PHP-8.2'
* PHP-8.2:
  [ci skip] NEWS
  [ci skip] NEWS
  Fix overflow check in OnUpdateMemoryConsumption (#10456)
  Prevent dtor of generator in suspended fiber (#10462)
2023-01-27 19:40:16 +01:00
Arnaud Le Blanc
6c22dea3c1 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  [ci skip] NEWS
  Fix overflow check in OnUpdateMemoryConsumption (#10456)
  Prevent dtor of generator in suspended fiber (#10462)
2023-01-27 19:37:01 +01:00
Niels Dossche
d7de73b551
Fix overflow check in OnUpdateMemoryConsumption (#10456)
memsize is a signed long, therefore the check against the
(*un*signed long maximum) / 1024² will allow too large values. This check worked
correctly in d4b3f89c53 where it checked against the maximum signed
value, but was broken in 003346c450. Fix it by changing ZEND_ULONG_MAX
to ZEND_LONG_MAX.
2023-01-27 19:33:58 +01:00
Mikhail Galanin
9bea5f443b Add "Start time", "Last restart time" and "Last force restart time" to phpinfo()
for opcache.

Closes GH-9475.
2022-09-05 17:54:47 +01:00
Arnaud Le Blanc
fb242f41ba
Fix high opcache.interned_strings_buffer causing shm corruption (#9260) 2022-09-03 11:23:10 +02:00
Christoph M. Becker
9313cd899e
Don't enforce 64 hit counter on Windows
There is no particular need to have a 64bit hit counter on Windows.

Closes GH-9367.
2022-08-22 17:49:30 +02:00
Arnaud Le Blanc
efc8f0ebf8
Deprecate zend_atol() / add zend_ini_parse_quantity() (#7951)
Add zend_ini_parse_quantity() and deprecate zend_atol(), zend_atoi()

zend_atol() and zend_atoi() don't just do number parsing.
They also check for a 'K', 'M', or 'G' at the end of the string,
and multiply the parsed value out accordingly.

Unfortunately, they ignore any other non-numerics between the
numeric component and the last character in the string.
This means that numbers such as the following are both valid
and non-intuitive in their final output.

* "123KMG" is interpreted as "123G" -> 132070244352
* "123G " is interpreted as "123 " -> 123
* "123GB" is interpreted as "123B" -> 123
* "123 I like tacos." is also interpreted as "123." -> 123

Currently, in php-src these functions are used only for parsing ini values.

In this change we deprecate zend_atol(), zend_atoi(), and introduce a new
function with the same behavior, but with the ability to report invalid inputs
to the caller. The function's name also makes the behavior less unexpected:
zend_ini_parse_quantity().

Co-authored-by: Sara Golemon <pollita@php.net>
2022-06-17 14:12:53 +02:00
George Peter Banyard
926407f224
Fix some MSAN complaints under Clang (#8553) 2022-05-13 23:30:20 +01:00
Tony Su
2c4b9e995a
[JIT] Print out more meaningful warning message
* [JIT] Print out more meaningful warning message

When the setting value is out of range for jit_hot_loop, jit_hot_func,
jit_hot_return, and jit_hot_side_exit, current PHP only prints out
warning message like:
    Warning: Invalid "opcache.jit_hot_loop" setting.
    Should be between 0 and 256 in Unknown on line 0

With this small patch, PHP can print out more meaningful information,
and tell user default value will be used and correct value range, like
    Warning: Invalid "opcache.jit_hot_loop" setting; using default value instead.
    Should be between 0 and 255 in Unknown on line 0

This patch has been verified on my local machine.

Signed-off-by: Su, Tao <tao.su@intel.com>

Co-authored-by: Michael Voříšek <mvorisek@mvorisek.cz>
Co-authored-by: Christoph M. Becker <cmbecker69@gmx.de>

Closes GH-7955.
2022-01-18 11:41:50 +01:00
Dmitry Stogov
90b7bde615 Use more compact representation for packed arrays.
- for packed arrays we store just an array of zvals without keys.
- the elements of packed array are accessible throuf as ht->arPacked[i]
  instead of ht->arData[i]
- in addition to general ZEND_HASH_FOREACH_* macros, we introduced similar
  familied for packed (ZEND_HASH_PACKED_FORECH_*) and real hashes
  (ZEND_HASH_MAP_FOREACH_*)
- introduced an additional family of macros to access elements of array
  (packed or real hashes) ZEND_ARRAY_ELEMET_SIZE, ZEND_ARRAY_ELEMET_EX,
  ZEND_ARRAY_ELEMET, ZEND_ARRAY_NEXT_ELEMENT, ZEND_ARRAY_PREV_ELEMENT
- zend_hash_minmax() prototype was changed to compare only values

Because of smaller data set, this patch may show performance improvement
on some apps and benchmarks that use packed arrays. (~1% on PHP-Parser)

TODO:
    - sapi/phpdbg needs special support for packed arrays (WATCH_ON_BUCKET).
    - zend_hash_sort_ex() may require converting packed arrays to hash.
2021-11-03 15:18:26 +03: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
George Peter Banyard
09efad615b
Use zend_string_equals_(literal_)ci() API more often
Also drive-by usage of zend_ini_parse_bool()

Closes GH-6844
2021-04-09 02:34:50 +01:00
Dmitry Stogov
8ed8cf86a9 Use zend_string* instead of char* 2021-03-22 14:56:16 +03:00
Dmitry Stogov
c732ab400a Change Zend Stream API to use zend_string* instead of char*.
This allows to eliminate re-calculation of string lenght and hash value.
See the detailed list of changes in UPGRADING.INTERNALS.
2021-03-16 20:31:36 +03:00
Dmitry Stogov
4b59071844 Switch to new ZPP 2021-03-04 02:11:21 +03:00
Dmitry Stogov
ac7e967b67 Reduce ZPP API overhead 2021-02-20 13:59:29 +03:00
Nikita Popov
3e01f5afb1 Replace zend_bool uses with bool
We're starting to see a mix between uses of zend_bool and bool.
Replace all usages with the standard bool type everywhere.

Of course, zend_bool is retained as an alias.
2021-01-15 12:33:06 +01:00
Nikita Popov
0571f09424 Rename opcache.jit_max_loops_unroll to opcache.jit_max_loop_unrolls 2020-11-02 12:25:21 +01:00
Benjamin Eberlei
53ef244923 Add opcache.jit=tracing|function values, make on/yes/true synonym for tracing. 2020-08-04 10:15:22 +02:00
Dmitry Stogov
8a42f357bf Replace ZEND_JIT_TRACE_MAX_EXIT_COUNTERS constant by opcache.jit_max_exit_counters configuration directive 2020-07-28 11:18:18 +03:00
Nikita Popov
eb04cb5f20 Move checks after zpp in opcache_is_script_cached() 2020-07-22 10:52:50 +02:00
Max Semenik
2b5de6f839
Remove proto comments from C files
Closes GH-5758
2020-07-06 21:13:34 +02:00
Dmitry Stogov
e9f295ac84 Tracing JIT support for megamorphic calls 2020-06-09 23:33:22 +03:00
Christoph M. Becker
d23cd354c0 Fix #79665: ini_get() and opcache_get_configuration() inconsistency
Overriding the given INI values in modifier callbacks is not possible,
so instead of enforcing "normalized" internal values, we just reject
the attempted changes.
2020-06-03 11:07:25 +02:00
Dmitry Stogov
efbe96166d Split "opcache.jit_max_recursion_unroll" into "opcache.jit_max_recursive_calls" and "opcache.jit_max_recursive_returns".
It's possible to disable recording of "recursive return loops" setting opcache.jit_max_recursive_returns to 0.
2020-05-28 12:28:05 +03:00
Dmitry Stogov
2dfd6cd373 Allow counter settings to be "zero" to disable corresponding counter 2020-05-21 01:06:50 +03:00
Nikita Popov
0a74da385d Add support for replaying warnings in opcache
If opcache.record_warnings is enabled, opcache will record
compilation warnings and replay them when the file is included
again. The primary use case I have in mind for this is automated
testing of the opcache file cache.

This resolves bug #76535.
2020-05-20 11:20:21 +02:00
Dmitry Stogov
928c796290 Make number of root and side traces configurable 2020-05-20 01:40:01 +03:00