Skip to content

Commit f6d227e

Browse files
committed
Implemented preloading RFC: https://wiki.php.net/rfc/preload.
Squashed commit of the following: commit 106c815 Author: Dmitry Stogov <[email protected]> Date: Wed Nov 14 16:36:44 2018 +0300 Added NEWS entry commit 1dacd5e Merge: d516139 ba99aa1 Author: Dmitry Stogov <[email protected]> Date: Wed Nov 14 16:33:37 2018 +0300 Merge branch 'master' into preload * master: Fixed issues related to optimization and persitence of classes linked with interfaces, traits or internal classes. Added possiblity to avoid signal handlers reinitialization on each request. commit d516139 Author: Dmitry Stogov <[email protected]> Date: Wed Nov 14 16:13:15 2018 +0300 Override opcache.preload for testing commit 162b154 Merge: 45fdd03 8bda225 Author: Dmitry Stogov <[email protected]> Date: Wed Nov 14 15:38:09 2018 +0300 Merge branch 'master' into preload * master: (34 commits) Eliminate useless $this related check Eliminate useless $this related checks Replace zend_parse_method_parameters() by zend_parse_parameters() and avoid useless checks. Replace getThis() by EX(This), when additional check is not necessary. Fixed tests Validate length on socket_write Fix compilation on x32 Fix #77141: Signedness issue in SOAP when precision=-1 Support SQLite3 @name notation Remove lexer files generated by RE2C Update libmagic.patch [ci skip] Update libmagic.patch [ci skip] Fork test with pcre.jit=0 Rework magic data Fix regex Fix regex Rework magic data Sync one more upstream libmagic piece Suppress already used warning Ignore getaddrinfo failed message ... commit 45fdd03 Author: Dmitry Stogov <[email protected]> Date: Fri Nov 9 13:07:03 2018 +0300 Properly resolve magic method of preloaded classes inherited from internal ones. commit 34645ae Author: Dmitry Stogov <[email protected]> Date: Thu Nov 8 15:29:17 2018 +0300 Don't preload constants defined during preload script excution. commit cef0d67 Author: Dmitry Stogov <[email protected]> Date: Wed Nov 7 15:56:54 2018 +0300 Support for class aliasses commit 08ffc9a Author: Dmitry Stogov <[email protected]> Date: Wed Nov 7 15:34:39 2018 +0300 Resolve constants only in linked classes commit 8d3429c Author: Dmitry Stogov <[email protected]> Date: Tue Nov 6 11:56:39 2018 +0300 Fixed preloading of references to internal classes. commit 7ae3a47 Merge: 9b0a53e 049f239 Author: Dmitry Stogov <[email protected]> Date: Tue Nov 6 11:37:15 2018 +0300 Merge branch 'master' into preload * master: Update NEWS [ci skip] Update NEWS [ci skip] Update libmagic.patch [ci skip] Update libmagic.patch [ci skip] Declare function proto in header Declare function proto in header Fix #76825: Undefined symbols ___cpuid_count NEWS Fix: #77110 undefined symbol zend_string_equal_val in C++ build Fix #77105: Use position:sticky for <th> in `phpinfo()` Implement handling for JIT recognition when cross compiling Backport 7f5f460 for 7.2 Fix #76348: WSDL_CACHE_MEMORY causes Segmentation fault Rework places in libmagic regarding previous CVE-2014-3538 fixes Change the way JIT availability is checked Fix a test for ldap extension Fixed bug #77092 Future-proof email addresses commit 9b0a53e Author: Dmitry Stogov <[email protected]> Date: Fri Nov 2 14:54:44 2018 +0300 We don't need preload_restart() here commit 0bd17bd Author: Dmitry Stogov <[email protected]> Date: Fri Nov 2 14:44:30 2018 +0300 EG(*) may be not initializd at this point - use CG(*). commit b610467 Merge: 3a9d90f 67e0138 Author: Dmitry Stogov <[email protected]> Date: Fri Nov 2 11:33:37 2018 +0300 Merge branch 'master' into preload * master: Future-proof email addresses... Update email addresses. We're still @zend, but future proofing it... commit 3a9d90f Author: Dmitry Stogov <[email protected]> Date: Thu Nov 1 15:19:48 2018 +0300 Fexed resolution of method clones commit aea85c6 Author: Dmitry Stogov <[email protected]> Date: Thu Nov 1 11:45:50 2018 +0300 Prevent inlining of method copied from trait commit 36b644f Merge: 7a20781 b91690c Author: Dmitry Stogov <[email protected]> Date: Thu Nov 1 10:56:02 2018 +0300 Merge branch 'master' into preload * master: Fix stray newline that caused this test to fail Fix session tests that fail if error_log is set This test needs to log to stdout Fix error condition Fixed bug #77081 ftruncate() changes seek pointer in c mode Fix and improve test case commit 7a20781 Author: Dmitry Stogov <[email protected]> Date: Wed Oct 31 00:52:46 2018 +0300 Added test commit 4a57b5d Author: Dmitry Stogov <[email protected]> Date: Wed Oct 31 00:50:21 2018 +0300 Fixed preloading of classes linked with traits commit 68c4f99 Author: Dmitry Stogov <[email protected]> Date: Tue Oct 30 16:25:14 2018 +0300 Added test commit 38ab7ef Merge: eb6e2c5 bf38e6c Author: Dmitry Stogov <[email protected]> Date: Tue Oct 30 16:14:39 2018 +0300 Merge branch 'master' into preload * master: Keep original value of "prototype" commit eb6e2c5 Merge: 5620495 2fefa8c Author: Dmitry Stogov <[email protected]> Date: Tue Oct 30 15:35:39 2018 +0300 Merge branch 'master' into preload * master: Call function_add_ref() in proper place Updated to version 2018.7 (2018g) Updated to version 2018.7 (2018g) Updated to version 2018.7 (2018g) Reslove inherited op_array references once afrer all optimizations. commit 5620495 Merge: e806cb7 4828fb7 Author: Dmitry Stogov <[email protected]> Date: Tue Oct 30 10:29:49 2018 +0300 Merge branch 'master' into preload * master: [ci skip] Update NEWS [ci skip] Update NEWS [ci skip] Update NEWS fix bug #77079 Add missing null initialization Remove redundant mbfl_string_init calls Use zend_string for mbstring last encoding cache commit e806cb7 Author: Dmitry Stogov <[email protected]> Date: Mon Oct 29 22:32:15 2018 +0300 Fixed double-free commit 2f697ef Author: Dmitry Stogov <[email protected]> Date: Mon Oct 29 22:07:32 2018 +0300 typo commit c559f22 Merge: 310631c ea2e678 Author: Dmitry Stogov <[email protected]> Date: Mon Oct 29 21:59:27 2018 +0300 Merge branch 'master' into preload * master: Stop Apache if PHP wasn't started successful. Execute zend_post_startup() with module_initialized flag set. Removed dead code Fix mb_strrpos() with encoding passed as 3rd param commit 310631c Author: Dmitry Stogov <[email protected]> Date: Mon Oct 29 16:48:42 2018 +0300 Stop Apache if PHP wasn't started successful. commit 0a24d7b Author: Dmitry Stogov <[email protected]> Date: Mon Oct 29 16:25:49 2018 +0300 Avoid use-after-free in main thread commit 17a3cb4 Author: Dmitry Stogov <[email protected]> Date: Mon Oct 29 15:25:17 2018 +0300 Execute zend_post_startup() with module_initialized flag set. commit 6d4b22c Author: Dmitry Stogov <[email protected]> Date: Mon Oct 29 14:12:20 2018 +0300 Override SAPI.ub_write and SAPI.flush for preloading commit 386c9d3 Merge: d7fbb4d 359f19e Author: Dmitry Stogov <[email protected]> Date: Mon Oct 29 13:49:24 2018 +0300 Merge branch 'master' into preload * master: Optimize substr() edge-case conditions [ci skip] Update UPGRADING Fix #71592: External entity processing never fails Add TIDY_TAG_* constants supported by libtidy 5 Add is_iterable to opcache Optimizer commit d7fbb4d Author: Dmitry Stogov <[email protected]> Date: Fri Oct 26 13:11:54 2018 +0300 Restore preload state if it was already loaded in another process. commit 0fe9ea1 Author: Dmitry Stogov <[email protected]> Date: Fri Oct 26 12:29:06 2018 +0300 Removed dead code commit 3a2d1bc Author: Dmitry Stogov <[email protected]> Date: Fri Oct 26 00:19:40 2018 +0300 Support for builds without ZEND_SIGNALS commit e6b76ec Merge: 4531fbf 68694c9 Author: Dmitry Stogov <[email protected]> Date: Thu Oct 25 23:43:25 2018 +0300 Merge branch 'master' into preload * master: Don't wrap php_module_shutdown() with zend_try. executor_globals are released in ZTS build, and this leads to crash. [ci skip] Fix indentation in UPGRADING. commit 4531fbf Author: Dmitry Stogov <[email protected]> Date: Thu Oct 25 22:44:49 2018 +0300 Disable linking and preloading of classes those parent or one of interface or trait is an internal class. commit a594a61 Author: Dmitry Stogov <[email protected]> Date: Thu Oct 25 22:30:51 2018 +0300 Cleanup - remove useless ZCSG(saved_map_ptr_last) - move preloaded classes/functions clean-up code back into better place commit ab9a40f Author: Dmitry Stogov <[email protected]> Date: Thu Oct 25 20:52:51 2018 +0300 Added support for preloaded classes/functions in ZTS build commit e3c65db Merge: 4f57c1e 33e777a Author: Dmitry Stogov <[email protected]> Date: Thu Oct 25 20:52:26 2018 +0300 Merge branch 'master' into preload * master: Improved shared interned strings handling. The previous implementation worked incorrectly in ZTS build. It changed strings only in function/class tables of one thread. Now all threads gets the same shared interned strings. Also, on shutdown, we don't try to replace SHM interned strings back to process strings, but delay dettachment of SHM instead. Don't use request heap at shutdown Don't optimize function if inference failed Fixed bug #77058 Improve "narrowing" error message bump versions commit 4f57c1e Author: Dmitry Stogov <[email protected]> Date: Thu Oct 25 15:29:58 2018 +0300 Cleanup (move preload_shutdown() call to better place) commit 26587a9 Author: Dmitry Stogov <[email protected]> Date: Thu Oct 25 14:30:51 2018 +0300 eol commit d70cb10 Author: Dmitry Stogov <[email protected]> Date: Thu Oct 25 14:30:20 2018 +0300 cleanup commit aabe685 Merge: d9fc51b 40808ac Author: Dmitry Stogov <[email protected]> Date: Thu Oct 25 12:42:51 2018 +0300 Merge branch 'master' into preload * master: Remove unused var Remove ext/json parser files generated by bison Fix run-tests.php for running phpdbg and certain test sections Normalize .gitignore commit d9fc51b Merge: b5ffba0 b6ef899 Author: Dmitry Stogov <[email protected]> Date: Wed Oct 24 15:59:24 2018 +0300 Merge branch 'master' into preload * master: Fixed reseting of interned strings buffer. commit b5ffba0 Merge: e4a7ef0 a404383 Author: Dmitry Stogov <[email protected]> Date: Wed Oct 24 12:46:28 2018 +0300 Merge branch 'master' into preload * master: Fixed build in directory different from source commit e4a7ef0 Merge: 811f20a d1e14e2 Author: Dmitry Stogov <[email protected]> Date: Wed Oct 24 11:59:43 2018 +0300 Merge branch 'master' into preload * master: (29 commits) Make php_plain_files_wrapper to be writable (workaround for swoole) Remove phpdbg parser files generated by bison Fix conflicts in phpdbg parser Refetetch function name on exceptional path to allow better code on fast code path. fix typo in sysvsem.c Fixed bug #50675 bump to 7.2.13-dev [ci skip] Update NEWS wrt. php-7.3.0RC4 tagging Inlining in the most frequently used code paths Fixed test failurs introduced by 9c144e0 Use persistent strings only for persistent connections Fix accessibility checks for dynamic properties Updated to version 2018.6 (2018f) Updated to version 2018.6 (2018f) Updated to version 2018.6 (2018f) Fix arginfo and clean up fpm_get_status Defragment two Zend related Makefile fragments together [ci skip] Remove automake and aclocal in comments Fix #75282: xmlrpc_encode_request() crashes Fix tests for ICU 63.1 ... commit 811f20a Author: Dmitry Stogov <[email protected]> Date: Mon Oct 22 14:10:49 2018 +0300 Added information about preloading to opcache_get_status() commit 093e8b1 Author: Dmitry Stogov <[email protected]> Date: Fri Oct 19 13:46:23 2018 +0300 Added warning message commit a2ba970 Author: Dmitry Stogov <[email protected]> Date: Fri Oct 19 13:35:40 2018 +0300 Added test commit b67e283 Author: Dmitry Stogov <[email protected]> Date: Fri Oct 19 13:33:12 2018 +0300 Don't preload functions declared at run-time. commit b0139dc Merge: a609520 3fe698b Author: Dmitry Stogov <[email protected]> Date: Fri Oct 19 13:23:14 2018 +0300 Merge branch 'master' into preload * master: Mark "top-level" functions. Don't initialize static_member_tables during start-up, when inherit internal classes. [ci skip] Update NEWS [ci skip] Update NEWS [ci skip] Update NEWS Fix #77035: The phpize and ./configure create redundant .deps file Remove outdated PEAR artefacts Fix tests/output/bug74815.phpt generating errors.log Revert "Use C++ symbols, when C++11 or upper is compiled" Use C++ symbols, when C++11 or upper is compiled Added new line Remove stamp-h Move all testing docs to qa.php.net Fix a typo in UPGRADING.INTERNALS Fix test when it's run on another drive [ci skip] Update UPGRADING wrt. tidyp support Fixed incorrect reallocation Fix #77027: tidy::getOptDoc() not available on Windows Run CI tests under opcache.protect_memory=1 commit a609520 Merge: ac8f45f b6ac50f Author: Dmitry Stogov <[email protected]> Date: Wed Oct 17 17:01:05 2018 +0300 Merge branch 'master' into preload * master: Fixed comment Micro optimizations Mark "top-level" classes commit ac8f45f Merge: 632b30b d57cd36 Author: Dmitry Stogov <[email protected]> Date: Wed Oct 17 15:53:41 2018 +0300 Merge branch 'master' into preload * master: Immutable clases and op_arrays. commit 632b30b Merge: d33908a cd0c36c Author: Dmitry Stogov <[email protected]> Date: Wed Oct 17 15:04:43 2018 +0300 Merge branch 'immutable' into preload * immutable: Remove the "auto" encoding Fixed bug #77025 Add vtbls for EUC-TW encoding commit cd0c36c Merge: 4740dab ad6738e Author: Dmitry Stogov <[email protected]> Date: Wed Oct 17 14:43:38 2018 +0300 Merge branch 'master' into immutable * master: Remove the "auto" encoding Fixed bug #77025 Add vtbls for EUC-TW encoding commit d33908a Merge: 21e0beb 4740dab Author: Dmitry Stogov <[email protected]> Date: Wed Oct 17 14:14:23 2018 +0300 Merge branch 'immutable' into preload * immutable: Reverted back ce->iterator_funcs_ptr. Initialize ce->iterator_funcs_ptr fields in immutable classes. commit 4740dab Author: Dmitry Stogov <[email protected]> Date: Wed Oct 17 14:12:28 2018 +0300 Reverted back ce->iterator_funcs_ptr. Initialize ce->iterator_funcs_ptr fields in immutable classes. commit 21e0beb Merge: c78277a ad7a78b Author: Dmitry Stogov <[email protected]> Date: Wed Oct 17 12:29:59 2018 +0300 Merge branch 'immutable' into preload * immutable: Added comment Added type cast Moved static class members initialization into the proper place. Removed redundand assertion Removed duplicate code Hide offset encoding magic in ZEND_MAP_PTR_IS_OFFSET(), ZEND_MAP_PTR_OFFSET2PTR() and ZEND_MAP_PTR_PTR2OFFSET() macros. typo Remove unused variable makefile_am_files Classify object handlers are required/optional Add support for getting SKIP_TAGSTART and SKIP_WHITE options Remove some obsolete config_vars.mk occurrences Remove bsd_converted from .gitignore Remove configuration parser and scanners ignores Remove obsolete buildconf.stamp from .gitignore [ci skip] Add magicdata.patch exception to .gitignore Remove outdated ext/spl/examples items from .gitignore Remove unused test.inc in ext/iconv/tests commit ad7a78b Author: Dmitry Stogov <[email protected]> Date: Wed Oct 17 11:46:30 2018 +0300 Added comment commit 0276ea5 Author: Dmitry Stogov <[email protected]> Date: Wed Oct 17 11:42:43 2018 +0300 Added type cast commit c63fc5d Author: Dmitry Stogov <[email protected]> Date: Wed Oct 17 11:36:51 2018 +0300 Moved static class members initialization into the proper place. commit b945548 Author: Dmitry Stogov <[email protected]> Date: Wed Oct 17 11:21:03 2018 +0300 Removed redundand assertion commit d5a4108 Author: Dmitry Stogov <[email protected]> Date: Wed Oct 17 11:19:13 2018 +0300 Removed duplicate code commit 8dadca8 Author: Dmitry Stogov <[email protected]> Date: Wed Oct 17 11:05:43 2018 +0300 Hide offset encoding magic in ZEND_MAP_PTR_IS_OFFSET(), ZEND_MAP_PTR_OFFSET2PTR() and ZEND_MAP_PTR_PTR2OFFSET() macros. commit 9ef07c8 Author: Dmitry Stogov <[email protected]> Date: Wed Oct 17 10:48:29 2018 +0300 typo commit a06f0f3 Merge: 9409958 3412345 Author: Dmitry Stogov <[email protected]> Date: Wed Oct 17 10:47:07 2018 +0300 Merge branch 'master' into immutable * master: Remove unused variable makefile_am_files Classify object handlers are required/optional Add support for getting SKIP_TAGSTART and SKIP_WHITE options Remove some obsolete config_vars.mk occurrences Remove bsd_converted from .gitignore Remove configuration parser and scanners ignores Remove obsolete buildconf.stamp from .gitignore [ci skip] Add magicdata.patch exception to .gitignore Remove outdated ext/spl/examples items from .gitignore Remove unused test.inc in ext/iconv/tests commit c78277a Author: Dmitry Stogov <[email protected]> Date: Tue Oct 16 17:25:35 2018 +0300 Preloadsing support for opcache restart commit f76a955 Author: Dmitry Stogov <[email protected]> Date: Tue Oct 16 13:52:36 2018 +0300 Fixed incorrect signal handlers overriding commit 0810ce0 Author: Dmitry Stogov <[email protected]> Date: Mon Oct 15 23:38:48 2018 +0300 An attempt to implemnt "preloading" ability. commit 9409958 Author: Dmitry Stogov <[email protected]> Date: Mon Oct 15 23:34:01 2018 +0300 Immutable clases and op_arrays
1 parent ba99aa1 commit f6d227e

12 files changed

+1167
-4
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ PHP NEWS
2222
. Changed default of $variant parameter of idn_to_ascii() and idn_to_utf8().
2323
(cmb)
2424

25+
- Opcache:
26+
. Implemented preloading RFC: https://wiki.php.net/rfc/preload. (Dmitry)
27+
2528
- PDO_OCI:
2629
. Implemented FR #76908 (PDO_OCI getColumnMeta() not implemented).
2730
(Valentin Collet, Chris Jones, Remi)

Zend/zend.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,8 +566,13 @@ static void auto_global_dtor(zval *zv) /* {{{ */
566566
static void function_copy_ctor(zval *zv) /* {{{ */
567567
{
568568
zend_function *old_func = Z_FUNC_P(zv);
569-
zend_function *func = pemalloc(sizeof(zend_internal_function), 1);
569+
zend_function *func;
570570

571+
if (old_func->type == ZEND_USER_FUNCTION) {
572+
ZEND_ASSERT(old_func->op_array.fn_flags & ZEND_ACC_IMMUTABLE);
573+
return;
574+
}
575+
func = pemalloc(sizeof(zend_internal_function), 1);
571576
Z_FUNC_P(zv) = func;
572577
memcpy(func, old_func, sizeof(zend_internal_function));
573578
function_add_ref(func);
@@ -977,14 +982,17 @@ int zend_post_startup(void) /* {{{ */
977982

978983
zend_destroy_rsrc_list(&EG(persistent_list));
979984
free(compiler_globals->function_table);
985+
compiler_globals->function_table = NULL;
980986
free(compiler_globals->class_table);
987+
compiler_globals->class_table = NULL;
981988
if ((script_encoding_list = (zend_encoding **)compiler_globals->script_encoding_list)) {
982989
compiler_globals_ctor(compiler_globals);
983990
compiler_globals->script_encoding_list = (const zend_encoding **)script_encoding_list;
984991
} else {
985992
compiler_globals_ctor(compiler_globals);
986993
}
987994
free(EG(zend_constants));
995+
EG(zend_constants) = NULL;
988996

989997
executor_globals_ctor(executor_globals);
990998
global_persistent_list = &EG(persistent_list);

Zend/zend_execute_API.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,13 +340,56 @@ void shutdown_executor(void) /* {{{ */
340340
destroy_op_array(&func->op_array);
341341
zend_string_release_ex(key, 0);
342342
} ZEND_HASH_FOREACH_END_DEL();
343+
344+
/* Cleanup preloaded immutable functions */
345+
ZEND_HASH_REVERSE_FOREACH_VAL(EG(function_table), zv) {
346+
zend_op_array *op_array = Z_PTR_P(zv);
347+
if (op_array->type == ZEND_INTERNAL_FUNCTION) {
348+
break;
349+
}
350+
ZEND_ASSERT(op_array->fn_flags & ZEND_ACC_IMMUTABLE);
351+
if (op_array->static_variables) {
352+
HashTable *ht = ZEND_MAP_PTR_GET(op_array->static_variables_ptr);
353+
if (ht) {
354+
ZEND_ASSERT(GC_REFCOUNT(ht) == 1);
355+
zend_array_destroy(ht);
356+
}
357+
}
358+
} ZEND_HASH_FOREACH_END();
359+
343360
ZEND_HASH_REVERSE_FOREACH_STR_KEY_VAL(EG(class_table), key, zv) {
344361
if (_idx == EG(persistent_classes_count)) {
345362
break;
346363
}
347364
destroy_zend_class(zv);
348365
zend_string_release_ex(key, 0);
349366
} ZEND_HASH_FOREACH_END_DEL();
367+
368+
/* Cleanup preloaded immutable classes */
369+
ZEND_HASH_REVERSE_FOREACH_VAL(EG(class_table), zv) {
370+
zend_class_entry *ce = Z_PTR_P(zv);
371+
if (ce->type == ZEND_INTERNAL_CLASS) {
372+
break;
373+
}
374+
ZEND_ASSERT(ce->ce_flags & ZEND_ACC_IMMUTABLE);
375+
if (ce->default_static_members_count) {
376+
zend_cleanup_internal_class_data(ce);
377+
}
378+
if (ce->ce_flags & ZEND_HAS_STATIC_IN_METHODS) {
379+
zend_op_array *op_array;
380+
ZEND_HASH_FOREACH_PTR(&ce->function_table, op_array) {
381+
if (op_array->type == ZEND_USER_FUNCTION) {
382+
if (op_array->static_variables) {
383+
HashTable *ht = ZEND_MAP_PTR_GET(op_array->static_variables_ptr);
384+
if (ht) {
385+
ZEND_ASSERT(GC_REFCOUNT(ht) == 1);
386+
zend_array_destroy(ht);
387+
}
388+
}
389+
}
390+
} ZEND_HASH_FOREACH_END();
391+
}
392+
} ZEND_HASH_FOREACH_END();
350393
}
351394

352395
zend_cleanup_internal_classes();

Zend/zend_opcode.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,9 @@ void zend_class_add_ref(zval *zv)
362362
{
363363
zend_class_entry *ce = Z_PTR_P(zv);
364364

365-
ce->refcount++;
365+
if (!(ce->ce_flags & ZEND_ACC_IMMUTABLE)) {
366+
ce->refcount++;
367+
}
366368
}
367369

368370
ZEND_API void destroy_op_array(zend_op_array *op_array)

0 commit comments

Comments
 (0)