Skip to content

Commit 4ce5d2e

Browse files
committed
Add known strings for jit autoglobals
We always create interned strings for all autoglobals anyway, so we might as well add known strings to make them more widely usable.
1 parent ce4afd5 commit 4ce5d2e

File tree

14 files changed

+40
-75
lines changed

14 files changed

+40
-75
lines changed

Zend/zend_string.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,9 @@ EMPTY_SWITCH_DEFAULT_CASE()
557557
_(ZEND_STR_FROM, "from") \
558558
_(ZEND_STR_TRYFROM, "tryFrom") \
559559
_(ZEND_STR_TRYFROM_LOWERCASE, "tryfrom") \
560+
_(ZEND_STR_AUTOGLOBAL_SERVER, "_SERVER") \
561+
_(ZEND_STR_AUTOGLOBAL_ENV, "_ENV") \
562+
_(ZEND_STR_AUTOGLOBAL_REQUEST, "_REQUEST") \
560563

561564

562565
typedef enum _zend_known_string_id {

ext/filter/filter.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,13 +476,13 @@ static zval *php_filter_get_storage(zend_long arg)/* {{{ */
476476
break;
477477
case PARSE_SERVER:
478478
if (PG(auto_globals_jit)) {
479-
zend_is_auto_global_str(ZEND_STRL("_SERVER"));
479+
zend_is_auto_global(ZSTR_KNOWN(ZEND_STR_AUTOGLOBAL_SERVER));
480480
}
481481
array_ptr = &IF_G(server_array);
482482
break;
483483
case PARSE_ENV:
484484
if (PG(auto_globals_jit)) {
485-
zend_is_auto_global_str(ZEND_STRL("_ENV"));
485+
zend_is_auto_global(ZSTR_KNOWN(ZEND_STR_AUTOGLOBAL_ENV));
486486
}
487487
array_ptr = !Z_ISUNDEF(IF_G(env_array)) ? &IF_G(env_array) : &PG(http_globals)[TRACK_VARS_ENV];
488488
break;

ext/opcache/ZendAccelerator.c

Lines changed: 19 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,56 +1653,37 @@ static zend_persistent_script *cache_script_in_shared_memory(zend_persistent_scr
16531653
return new_persistent_script;
16541654
}
16551655

1656-
static const struct jit_auto_global_info
1657-
{
1658-
const char *name;
1659-
size_t len;
1660-
} jit_auto_globals_info[] = {
1661-
{ "_SERVER", sizeof("_SERVER")-1},
1662-
{ "_ENV", sizeof("_ENV")-1},
1663-
{ "_REQUEST", sizeof("_REQUEST")-1},
1664-
};
1665-
1666-
static zend_string *jit_auto_globals_str[4];
1656+
#define ZEND_AUTOGLOBAL_MASK_SERVER (1 << 0)
1657+
#define ZEND_AUTOGLOBAL_MASK_ENV (1 << 1)
1658+
#define ZEND_AUTOGLOBAL_MASK_REQUEST (1 << 2)
16671659

16681660
static int zend_accel_get_auto_globals(void)
16691661
{
1670-
int i, ag_size = (sizeof(jit_auto_globals_info) / sizeof(jit_auto_globals_info[0]));
1671-
int n = 1;
16721662
int mask = 0;
1673-
1674-
for (i = 0; i < ag_size ; i++) {
1675-
if (zend_hash_exists(&EG(symbol_table), jit_auto_globals_str[i])) {
1676-
mask |= n;
1677-
}
1678-
n += n;
1663+
if (zend_hash_exists(&EG(symbol_table), ZSTR_KNOWN(ZEND_STR_AUTOGLOBAL_SERVER))) {
1664+
mask |= ZEND_AUTOGLOBAL_MASK_SERVER;
1665+
}
1666+
if (zend_hash_exists(&EG(symbol_table), ZSTR_KNOWN(ZEND_STR_AUTOGLOBAL_ENV))) {
1667+
mask |= ZEND_AUTOGLOBAL_MASK_ENV;
1668+
}
1669+
if (zend_hash_exists(&EG(symbol_table), ZSTR_KNOWN(ZEND_STR_AUTOGLOBAL_REQUEST))) {
1670+
mask |= ZEND_AUTOGLOBAL_MASK_REQUEST;
16791671
}
16801672
return mask;
16811673
}
16821674

16831675
static void zend_accel_set_auto_globals(int mask)
16841676
{
1685-
int i, ag_size = (sizeof(jit_auto_globals_info) / sizeof(jit_auto_globals_info[0]));
1686-
int n = 1;
1687-
1688-
for (i = 0; i < ag_size ; i++) {
1689-
if (mask & n) {
1690-
ZCG(auto_globals_mask) |= n;
1691-
zend_is_auto_global(jit_auto_globals_str[i]);
1692-
}
1693-
n += n;
1677+
if (mask & ZEND_AUTOGLOBAL_MASK_SERVER) {
1678+
zend_is_auto_global(ZSTR_KNOWN(ZEND_STR_AUTOGLOBAL_SERVER));
16941679
}
1695-
}
1696-
1697-
static void zend_accel_init_auto_globals(void)
1698-
{
1699-
int i, ag_size = (sizeof(jit_auto_globals_info) / sizeof(jit_auto_globals_info[0]));
1700-
1701-
for (i = 0; i < ag_size ; i++) {
1702-
jit_auto_globals_str[i] = zend_string_init(jit_auto_globals_info[i].name, jit_auto_globals_info[i].len, 1);
1703-
zend_string_hash_val(jit_auto_globals_str[i]);
1704-
jit_auto_globals_str[i] = accel_new_interned_string(jit_auto_globals_str[i]);
1680+
if (mask & ZEND_AUTOGLOBAL_MASK_ENV) {
1681+
zend_is_auto_global(ZSTR_KNOWN(ZEND_STR_AUTOGLOBAL_ENV));
1682+
}
1683+
if (mask & ZEND_AUTOGLOBAL_MASK_REQUEST) {
1684+
zend_is_auto_global(ZSTR_KNOWN(ZEND_STR_AUTOGLOBAL_REQUEST));
17051685
}
1686+
ZCG(auto_globals_mask) |= mask;
17061687
}
17071688

17081689
static void persistent_error_cb(int type, const char *error_filename, const uint32_t error_lineno, zend_string *message) {
@@ -3266,7 +3247,6 @@ static zend_result accel_post_startup(void)
32663247
zend_shared_alloc_lock();
32673248
file_cache_only = 1;
32683249
fallback_process = 1;
3269-
zend_accel_init_auto_globals();
32703250
zend_shared_alloc_unlock();
32713251
goto file_cache_fallback;
32723252
break;
@@ -3278,9 +3258,6 @@ static zend_result accel_post_startup(void)
32783258
/* remember the last restart time in the process memory */
32793259
ZCG(last_restart_time) = ZCSG(last_restart_time);
32803260

3281-
/* Init auto-global strings */
3282-
zend_accel_init_auto_globals();
3283-
32843261
zend_shared_alloc_lock();
32853262
#ifdef HAVE_JIT
32863263
if (JIT_G(enabled)) {
@@ -3306,9 +3283,6 @@ static zend_result accel_post_startup(void)
33063283
JIT_G(on) = 0;
33073284
#endif
33083285
accel_shared_globals = calloc(1, sizeof(zend_accel_shared_globals));
3309-
3310-
/* Init auto-global strings */
3311-
zend_accel_init_auto_globals();
33123286
}
33133287
#if ENABLE_FILE_CACHE_FALLBACK
33143288
file_cache_fallback:

ext/session/session.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1572,7 +1572,7 @@ PHPAPI int php_session_start(void) /* {{{ */
15721572
/* Check the REQUEST_URI symbol for a string of the form
15731573
* '<session-name>=<session-id>' to allow URLs of the form
15741574
* http://yoursite/<session-name>=<session-id>/script.php */
1575-
if (!PS(id) && zend_is_auto_global_str("_SERVER", sizeof("_SERVER") - 1) == SUCCESS &&
1575+
if (!PS(id) && zend_is_auto_global(ZSTR_KNOWN(ZEND_STR_AUTOGLOBAL_SERVER)) == SUCCESS &&
15761576
(data = zend_hash_str_find(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER]), "REQUEST_URI", sizeof("REQUEST_URI") - 1)) &&
15771577
Z_TYPE_P(data) == IS_STRING &&
15781578
(p = strstr(Z_STRVAL_P(data), PS(session_name))) &&

ext/soap/soap.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,7 +1267,7 @@ PHP_METHOD(SoapServer, handle)
12671267
if (SG(request_info).request_body && 0 == php_stream_rewind(SG(request_info).request_body)) {
12681268
zval *server_vars, *encoding;
12691269
php_stream_filter *zf = NULL;
1270-
zend_string *server = zend_string_init("_SERVER", sizeof("_SERVER") - 1, 0);
1270+
zend_string *server = ZSTR_KNOWN(ZEND_STR_AUTOGLOBAL_SERVER);
12711271

12721272
zend_is_auto_global(server);
12731273
if ((server_vars = zend_hash_find(&EG(symbol_table), server)) != NULL &&
@@ -1291,16 +1291,13 @@ PHP_METHOD(SoapServer, handle)
12911291
php_stream_filter_append(&SG(request_info).request_body->readfilters, zf);
12921292
} else {
12931293
php_error_docref(NULL, E_WARNING,"Can't uncompress compressed request");
1294-
zend_string_release_ex(server, 0);
12951294
return;
12961295
}
12971296
} else {
12981297
php_error_docref(NULL, E_WARNING,"Request is compressed with unknown compression '%s'",Z_STRVAL_P(encoding));
1299-
zend_string_release_ex(server, 0);
13001298
return;
13011299
}
13021300
}
1303-
zend_string_release_ex(server, 0);
13041301

13051302
doc_request = soap_xmlParseFile("php://input");
13061303

@@ -1756,7 +1753,7 @@ static void soap_server_fault_ex(sdlFunctionPtr function, zval* fault, soapHeade
17561753

17571754
xmlDocDumpMemory(doc_return, &buf, &size);
17581755

1759-
if ((Z_TYPE(PG(http_globals)[TRACK_VARS_SERVER]) == IS_ARRAY || zend_is_auto_global_str(ZEND_STRL("_SERVER"))) &&
1756+
if ((Z_TYPE(PG(http_globals)[TRACK_VARS_SERVER]) == IS_ARRAY || zend_is_auto_global(ZSTR_KNOWN(ZEND_STR_AUTOGLOBAL_SERVER))) &&
17601757
(agent_name = zend_hash_str_find(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER]), "HTTP_USER_AGENT", sizeof("HTTP_USER_AGENT")-1)) != NULL &&
17611758
Z_TYPE_P(agent_name) == IS_STRING) {
17621759
if (strncmp(Z_STRVAL_P(agent_name), "Shockwave Flash", sizeof("Shockwave Flash")-1) == 0) {

ext/standard/basic_functions.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,7 @@ PHP_FUNCTION(getopt)
10541054
/* Get argv from the global symbol table. We calculate argc ourselves
10551055
* in order to be on the safe side, even though it is also available
10561056
* from the symbol table. */
1057-
if ((Z_TYPE(PG(http_globals)[TRACK_VARS_SERVER]) == IS_ARRAY || zend_is_auto_global_str(ZEND_STRL("_SERVER"))) &&
1057+
if ((Z_TYPE(PG(http_globals)[TRACK_VARS_SERVER]) == IS_ARRAY || zend_is_auto_global(ZSTR_KNOWN(ZEND_STR_AUTOGLOBAL_SERVER))) &&
10581058
((args = zend_hash_find_ex_ind(Z_ARRVAL_P(&PG(http_globals)[TRACK_VARS_SERVER]), ZSTR_KNOWN(ZEND_STR_ARGV), 1)) != NULL ||
10591059
(args = zend_hash_find_ex_ind(&EG(symbol_table), ZSTR_KNOWN(ZEND_STR_ARGV), 1)) != NULL)
10601060
) {

ext/standard/browscap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ PHP_FUNCTION(get_browser)
710710
if (agent_name == NULL) {
711711
zval *http_user_agent = NULL;
712712
if (Z_TYPE(PG(http_globals)[TRACK_VARS_SERVER]) == IS_ARRAY
713-
|| zend_is_auto_global_str(ZEND_STRL("_SERVER"))) {
713+
|| zend_is_auto_global(ZSTR_KNOWN(ZEND_STR_AUTOGLOBAL_SERVER))) {
714714
http_user_agent = zend_hash_str_find(
715715
Z_ARRVAL_P(&PG(http_globals)[TRACK_VARS_SERVER]),
716716
"HTTP_USER_AGENT", sizeof("HTTP_USER_AGENT")-1);

ext/standard/url_scanner_ex.re

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ static int check_http_host(char *target)
352352
zend_string *host_tmp;
353353
char *colon;
354354

355-
if ((tmp = zend_hash_str_find(&EG(symbol_table), ZEND_STRL("_SERVER"))) &&
355+
if ((tmp = zend_hash_find(&EG(symbol_table), ZSTR_KNOWN(ZEND_STR_AUTOGLOBAL_SERVER))) &&
356356
Z_TYPE_P(tmp) == IS_ARRAY &&
357357
(host = zend_hash_str_find(Z_ARRVAL_P(tmp), ZEND_STRL("HTTP_HOST"))) &&
358358
Z_TYPE_P(host) == IS_STRING) {

ext/zlib/zlib.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ static int php_zlib_output_encoding(void)
154154
zval *enc;
155155

156156
if (!ZLIBG(compression_coding)) {
157-
if ((Z_TYPE(PG(http_globals)[TRACK_VARS_SERVER]) == IS_ARRAY || zend_is_auto_global_str(ZEND_STRL("_SERVER"))) &&
157+
if ((Z_TYPE(PG(http_globals)[TRACK_VARS_SERVER]) == IS_ARRAY || zend_is_auto_global(ZSTR_KNOWN(ZEND_STR_AUTOGLOBAL_SERVER))) &&
158158
(enc = zend_hash_str_find(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER]), "HTTP_ACCEPT_ENCODING", sizeof("HTTP_ACCEPT_ENCODING") - 1))) {
159159
convert_to_string(enc);
160160
if (strstr(Z_STRVAL_P(enc), "gzip")) {

main/php_variables.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -906,8 +906,8 @@ void php_startup_auto_globals(void)
906906
zend_register_auto_global(zend_string_init_interned("_GET", sizeof("_GET")-1, 1), 0, php_auto_globals_create_get);
907907
zend_register_auto_global(zend_string_init_interned("_POST", sizeof("_POST")-1, 1), 0, php_auto_globals_create_post);
908908
zend_register_auto_global(zend_string_init_interned("_COOKIE", sizeof("_COOKIE")-1, 1), 0, php_auto_globals_create_cookie);
909-
zend_register_auto_global(zend_string_init_interned("_SERVER", sizeof("_SERVER")-1, 1), PG(auto_globals_jit), php_auto_globals_create_server);
910-
zend_register_auto_global(zend_string_init_interned("_ENV", sizeof("_ENV")-1, 1), PG(auto_globals_jit), php_auto_globals_create_env);
911-
zend_register_auto_global(zend_string_init_interned("_REQUEST", sizeof("_REQUEST")-1, 1), PG(auto_globals_jit), php_auto_globals_create_request);
909+
zend_register_auto_global(ZSTR_KNOWN(ZEND_STR_AUTOGLOBAL_SERVER), PG(auto_globals_jit), php_auto_globals_create_server);
910+
zend_register_auto_global(ZSTR_KNOWN(ZEND_STR_AUTOGLOBAL_ENV), PG(auto_globals_jit), php_auto_globals_create_env);
911+
zend_register_auto_global(ZSTR_KNOWN(ZEND_STR_AUTOGLOBAL_REQUEST), PG(auto_globals_jit), php_auto_globals_create_request);
912912
zend_register_auto_global(zend_string_init_interned("_FILES", sizeof("_FILES")-1, 1), 0, php_auto_globals_create_files);
913913
}

sapi/cgi/cgi_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ static void cgi_php_import_environment_variables(zval *array_ptr)
663663
{
664664
if (PG(variables_order) && (strchr(PG(variables_order),'E') || strchr(PG(variables_order),'e'))) {
665665
if (Z_TYPE(PG(http_globals)[TRACK_VARS_ENV]) != IS_ARRAY) {
666-
zend_is_auto_global_str("_ENV", sizeof("_ENV")-1);
666+
zend_is_auto_global(ZSTR_KNOWN(ZEND_STR_AUTOGLOBAL_ENV));
667667
}
668668

669669
if (Z_TYPE(PG(http_globals)[TRACK_VARS_ENV]) == IS_ARRAY &&

sapi/cli/php_cli.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@ static int do_cli(int argc, char **argv) /* {{{ */
956956
}
957957
}
958958

959-
zend_is_auto_global_str(ZEND_STRL("_SERVER"));
959+
zend_is_auto_global(ZSTR_KNOWN(ZEND_STR_AUTOGLOBAL_SERVER));
960960

961961
PG(during_request_startup) = 0;
962962
switch (behavior) {

sapi/phpdbg/phpdbg_wait.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ void phpdbg_webdata_decompress(char *msg, int len) {
136136
if ((zvp = zend_hash_str_find(ht, ZEND_STRL("GLOBALS"))) && Z_TYPE_P(zvp) == IS_ARRAY) {
137137
{
138138
zval *srv;
139-
if ((srv = zend_hash_str_find(Z_ARRVAL_P(zvp), ZEND_STRL("_SERVER"))) && Z_TYPE_P(srv) == IS_ARRAY) {
139+
if ((srv = zend_hash_find(Z_ARRVAL_P(zvp), ZSTR_KNOWN(ZEND_STR_AUTOGLOBAL_SERVER))) && Z_TYPE_P(srv) == IS_ARRAY) {
140140
zval *script;
141141
if ((script = zend_hash_str_find(Z_ARRVAL_P(srv), ZEND_STRL("SCRIPT_FILENAME"))) && Z_TYPE_P(script) == IS_STRING) {
142142
phpdbg_param_t param;

sapi/phpdbg/phpdbg_webdata_transfer.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,6 @@
1717
#include "phpdbg_webdata_transfer.h"
1818
#include "ext/standard/php_var.h"
1919

20-
static int phpdbg_is_auto_global(char *name, int len) {
21-
int ret;
22-
zend_string *str = zend_string_init(name, len, 0);
23-
ret = zend_is_auto_global(str);
24-
zend_string_free(str);
25-
return ret;
26-
}
27-
2820
PHPDBG_API void phpdbg_webdata_compress(char **msg, size_t *len) {
2921
zval array;
3022
HashTable *ht;
@@ -35,11 +27,10 @@ PHPDBG_API void phpdbg_webdata_compress(char **msg, size_t *len) {
3527

3628
/* fetch superglobals */
3729
{
38-
phpdbg_is_auto_global(ZEND_STRL("GLOBALS"));
3930
/* might be JIT */
40-
phpdbg_is_auto_global(ZEND_STRL("_ENV"));
41-
phpdbg_is_auto_global(ZEND_STRL("_SERVER"));
42-
phpdbg_is_auto_global(ZEND_STRL("_REQUEST"));
31+
zend_is_auto_global(ZSTR_KNOWN(ZEND_STR_AUTOGLOBAL_ENV));
32+
zend_is_auto_global(ZSTR_KNOWN(ZEND_STR_AUTOGLOBAL_SERVER));
33+
zend_is_auto_global(ZSTR_KNOWN(ZEND_STR_AUTOGLOBAL_REQUEST));
4334
array_init(&zv[1]);
4435
zend_hash_copy(Z_ARRVAL(zv[1]), &EG(symbol_table), NULL);
4536
Z_ARRVAL(zv[1])->pDestructor = NULL; /* we're operating on a copy! Don't double free zvals */

0 commit comments

Comments
 (0)