Re: com php-src: fix CG(empty_string) init in ZTS: Zend/zend.c
| From: | Dmitry Stogov | Date: | Fri, 19 Sep 2014 10:43:07 +0000 |
| Subject: | Re: com php-src: fix CG(empty_string) init in ZTS: Zend/zend.c | ||
| References: | 1 2 | Groups: | php.cvs |
| Request: | Send a blank email to php-cvs+get-81768@lists.php.net to get a copy of this message | ||
I know :)
Interned strings in PHP5 were implemented as characters allocated in one
single buffer.
Adding new strings into this buffer from different threads would require
synchronization (locks).
In PHP7 this implementation was changed. So it's probably must be possible
to use interned strings in ZTS now.
If we use separate HashTables for interned strings in different threads we
may share some common part of predefined interned strings and have new
interned strings in each thread independently. I'm not sure if it'll work
well with opcache, because it substitutes interned strings handling
mechanism to use shared memory. May be it'll work out of the box.
BTW: I'm not interested in implementing this myself.
Also, if we really like ZTS, may be PHP7 is the time to switch to native
TLS and remove all these TSRMLS macros.
Even if it won't allow to run ZTS on some platforms, it won't be the end of
the world, because ZTS is not really widely used now.
I won't be able to work on it actively, but I may provide some help.
Thanks. Dmitry.
On Fri, Sep 19, 2014 at 12:34 AM, Nikita Popov <nikita.ppv@gmail.com> wrote:
> On Thu, Sep 18, 2014 at 5:14 PM, Anatol Belski <ab@php.net> wrote:
>
> > Commit: e8b497ad8eb74273f7f44ae7e515e7a5e95b50f7
> > Author: Anatol Belski <ab@php.net> Thu, 18 Sep 2014 16:45:50
> > +0200
> > Parents: f162b3f736f07ad868abec6ea8b44a91e77d4069
> > Branches: master
> >
> > Link:
> >
> wC
> @ˆ¢Â›L-ôîêÑ#http://git.php.net/?p=php-src.git;a=commitdiff;h=e8b497ad8eb74273f7f44ae7e515e7a5e95b50f7
> >
> > Log:
> > fix CG(empty_string) init in ZTS
> >
> > Changed paths:
> > M Zend/zend.c
> >
> >
> > Diff:
> > diff --git a/Zend/zend.c b/Zend/zend.c
> > index 46719b4..6a53179 100644
> > --- a/Zend/zend.c
> > +++ b/Zend/zend.c
> > @@ -120,6 +120,7 @@ static HashTable *global_class_table = NULL;
> > static HashTable *global_constants_table = NULL;
> > static HashTable *global_auto_globals_table = NULL;
> > static HashTable *global_persistent_list = NULL;
> > +static zend_string *default_empty_string = NULL;
> > #endif
> >
> > ZEND_API zend_utility_values zend_uv;
> > @@ -514,6 +515,15 @@ static void
> > compiler_globals_ctor(zend_compiler_globals *compiler_globals TSRMLS
> > compiler_globals->static_members_table = NULL;
> > }
> > compiler_globals->script_encoding_list = NULL;
> > +
> > +#ifdef ZTS
> > + compiler_globals->empty_string = zend_string_alloc(sizeof("")-1,
> > 1);
> > + compiler_globals->empty_string->val[0] = '\000';
> > + zend_string_hash_val(compiler_globals->empty_string);
> > + compiler_globals->empty_string->gc.u.v.flags |= IS_STR_INTERNED;
> > +
> > + memset(compiler_globals->one_char_string, 0,
> > sizeof(compiler_globals->one_char_string));
> > +#endif
> > }
> > /* }}} */
> >
> > @@ -538,6 +548,10 @@ static void
> > compiler_globals_dtor(zend_compiler_globals *compiler_globals TSRMLS
> > pefree((char*)compiler_globals->script_encoding_list, 1);
> > }
> > compiler_globals->last_static_member = 0;
> > +
> > +#ifdef ZTS
> > + free(compiler_globals->empty_string);
> > +#endif
> > }
> > /* }}} */
> >
>
> What does this fix and how does it relate to the initialization done in
> zend_interned_strings_init?
>
> Btw, does anyone know why we don't use interned strings in ZTS?
>
> Nikita
>