Browse Source

processor: apply reference handling on opcode caching. reverted [196] [199] [220] and refix for #36

git-svn-id: svn://svn.lighttpd.net/xcache/trunk@233 c26eb9a1-5813-0410-bd6c-c2e55f420ca7
1.2
Xuefer 15 years ago
parent
commit
22ddb4c0ac
  1. 75
      processor/head.m4
  2. 2
      processor/main.m4
  3. 10
      processor/processor.m4
  4. 2
      xcache-test.ini
  5. 4
      xcache.c
  6. 2
      xcache.h

75
processor/head.m4

@ -61,6 +61,7 @@ struct _xc_processor_t {
HashTable strings;
HashTable zvalptrs;
zend_bool reference; /* enable if to deal with reference */
zend_bool have_references;
const xc_entry_t *xce_src;
const xc_entry_t *xce_dst;
const zend_class_entry *cache_ce;
@ -260,49 +261,7 @@ dnl FIXME: handle common.function_name here
}
}
/* }}} */
static int xc_hash_static_member_check(xc_processor_t *processor, Bucket *b TSRMLS_DC) /* {{{ */
{
const zend_class_entry *src = processor->active_class_entry_src;
if (src->parent) {
zval **parentzv;
if (zend_u_hash_quick_find(CE_STATIC_MEMBERS(src->parent), BUCKET_KEY_TYPE(b), ZSTR(BUCKET_KEY_S(b)), b->nKeyLength, b->h, (void **) &parentzv) == SUCCESS) {
zval **zv = (zval **) b->pData;
if (*parentzv == *zv) {
return ZEND_HASH_APPLY_REMOVE;
}
}
}
return ZEND_HASH_APPLY_KEEP;
}
/* }}} */
/* fix static members on restore */
static void inherit_static_prop(zval **p) /* {{{ */
{
/* already set */
#if 0
(*p)->refcount++;
(*p)->is_ref = 1;
#endif
}
/* }}} */
static void xc_fix_static_members(xc_processor_t *processor, zend_class_entry *dst TSRMLS_DC) /* {{{ */
{
zend_hash_merge(&dst->default_static_members, &dst->parent->default_static_members, (void (*)(void *)) inherit_static_prop, NULL, sizeof(zval *), 0);
}
/* }}} */
#endif
int xc_hash_reset_zval_refcount_applyer(void *pDest TSRMLS_DC) /* {{{ */
{
zval **zv = (zval **) pDest;
ZVAL_REFCOUNT(*zv) = 1;
return ZEND_HASH_APPLY_KEEP;
}
/* }}} */
static void xc_hash_reset_zval_refcount(HashTable *hash TSRMLS_DC) /* {{{ */
{
zend_hash_apply(hash, xc_hash_reset_zval_refcount_applyer TSRMLS_CC);
}
/* }}} */
/* {{{ call op_array ctor handler */
extern zend_bool xc_have_op_array_ctor;
static void xc_zend_extension_op_array_ctor_handler(zend_extension *extension, zend_op_array *op_array TSRMLS_DC)
@ -319,9 +278,7 @@ xc_entry_t *xc_processor_store_xc_entry_t(xc_entry_t *src TSRMLS_DC) {
xc_processor_t processor;
memset(&processor, 0, sizeof(processor));
if (src->type == XC_TYPE_VAR) {
processor.reference = 1;
}
processor.reference = 1;
IFASSERT(`xc_stack_init(&processor.allocsizes);')
@ -342,6 +299,7 @@ xc_entry_t *xc_processor_store_xc_entry_t(xc_entry_t *src TSRMLS_DC) {
zend_hash_destroy(&processor.strings);
}
src->size = processor.size;
src->have_references = processor.have_references;
IFASSERT(`xc_stack_reverse(&processor.allocsizes);')
/* store {{{ */
@ -393,23 +351,36 @@ xc_entry_t *xc_processor_restore_xc_entry_t(xc_entry_t *dst, const xc_entry_t *s
memset(&processor, 0, sizeof(processor));
processor.readonly_protection = readonly_protection;
if (src->have_references) {
processor.reference = 1;
}
if (processor.reference) {
zend_hash_init(&processor.zvalptrs, 0, NULL, NULL, 0);
}
xc_restore_xc_entry_t(&processor, dst, src TSRMLS_CC);
if (processor.reference) {
zend_hash_destroy(&processor.zvalptrs);
}
return dst;
}
/* }}} */
/* export: zval *xc_processor_restore_zval(zval *dst, const zval *src TSRMLS_DC); :export {{{ */
zval *xc_processor_restore_zval(zval *dst, const zval *src TSRMLS_DC) {
/* export: zval *xc_processor_restore_zval(zval *dst, const zval *src, zend_bool have_references TSRMLS_DC); :export {{{ */
zval *xc_processor_restore_zval(zval *dst, const zval *src, zend_bool have_references TSRMLS_DC) {
xc_processor_t processor;
memset(&processor, 0, sizeof(processor));
processor.reference = 1;
processor.reference = have_references;
zend_hash_init(&processor.zvalptrs, 0, NULL, NULL, 0);
dnl fprintf(stderr, "mark[%p] = %p\n", src, dst);
zend_hash_add(&processor.zvalptrs, (char *)src, sizeof(src), (void*)&dst, sizeof(dst), NULL);
if (processor.reference) {
zend_hash_init(&processor.zvalptrs, 0, NULL, NULL, 0);
dnl fprintf(stderr, "mark[%p] = %p\n", src, dst);
zend_hash_add(&processor.zvalptrs, (char *)src, sizeof(src), (void*)&dst, sizeof(dst), NULL);
}
xc_restore_zval(&processor, dst, src TSRMLS_CC);
zend_hash_destroy(&processor.zvalptrs);
if (processor.reference) {
zend_hash_destroy(&processor.zvalptrs);
}
return dst;
}

2
processor/main.m4

@ -10,6 +10,8 @@ define(`REDEF', `undefine(`$1') define(`$1', `$2')')
define(`ONCE', `ifdef(`ONCE $1', `', `define(`ONCE $1')$1')')
define(`m4_errprint', `ONCE(`errprint(`$1
')')')
define(`ZEND_STRS', `($1), (sizeof($1))')
define(`ZEND_STRL', `($1), (sizeof($1) - 1)')
dnl ============
define(`INDENT', `xc_dprint_indent(indent);')
dnl }}}

10
processor/processor.m4

@ -66,7 +66,6 @@ DEF_STRUCT_P_FUNC(`zend_brk_cont_element', , `
')
dnl }}}
DEF_HASH_TABLE_FUNC(`HashTable_zval_ptr', `zval_ptr')
DEF_HASH_TABLE_FUNC(`HashTable_zval_ptr_static_member_check', `zval_ptr', , `xc_hash_static_member_check(processor, BUCKET TSRMLS_CC)')
#ifdef HAVE_XCACHE_CONSTANT
DEF_HASH_TABLE_FUNC(`HashTable_zend_constant', `zend_constant')
#endif
@ -167,6 +166,7 @@ DEF_STRUCT_P_FUNC(`zval_ptr', , `dnl {{{
/* *dst is updated */
dnl fprintf(stderr, "*dst is set to %p\n", dst[0]);
')
IFCALCSTORE(`processor->have_references = 1;')
IFSTORE(`assert(xc_is_shm(dst[0]));')
IFRESTORE(`assert(!xc_is_shm(dst[0]));')
break;
@ -299,21 +299,18 @@ DEF_STRUCT_P_FUNC(`zend_class_entry', , `dnl {{{
#endif
STRUCT(HashTable, default_properties, HashTable_zval_ptr)
IFSTORE(`xc_hash_reset_zval_refcount(&dst->default_properties TSRMLS_CC);')
IFCOPY(`dst->builtin_functions = src->builtin_functions;')
DONE(builtin_functions)
#ifdef ZEND_ENGINE_2
STRUCT(HashTable, properties_info, HashTable_zend_property_info)
# ifdef ZEND_ENGINE_2_1
STRUCT(HashTable, default_static_members, IFCALCSTORE(HashTable_zval_ptr_static_member_check, HashTable_zval_ptr))
STRUCT(HashTable, default_static_members, HashTable_zval_ptr)
IFCOPY(`dst->static_members = &dst->default_static_members;')
IFRESTORE(`if (dst->parent) xc_fix_static_members(processor, dst TSRMLS_CC);')
DONE(static_members)
# else
STRUCT_P(HashTable, static_members, IFCALCSTORE(HashTable_zval_ptr_static_member_check, HashTable_zval_ptr))
STRUCT_P(HashTable, static_members, HashTable_zval_ptr)
# endif
STRUCT(HashTable, constants_table, HashTable_zval_ptr)
IFSTORE(`xc_hash_reset_zval_refcount(&dst->constants_table TSRMLS_CC);')
dnl runtime binding: ADD_INTERFACE will deal with it
IFRESTORE(`
@ -814,6 +811,7 @@ DEF_STRUCT_P_FUNC(`xc_entry_t', , `
')
DONE(data)
dnl }}}
DISPATCH(zend_bool, have_references)
')
dnl }}}
dnl ====================================================

2
xcache-test.ini

@ -5,7 +5,7 @@ zend_extension_debug_ts=./modules/xcache.so
zend_extension_debug=./modules/xcache.so
zend_extension_ts=./modules/xcache.so
zend_extension=./modules/xcache.so
xcache.cacher = On
xcache.cacher = Off
xcache.test=1
xcache.size = 1M
xcache.count = 1

4
xcache.c

@ -1672,7 +1672,7 @@ PHP_FUNCTION(xcache_get)
stored_xce = xc_entry_find_dmz(&xce TSRMLS_CC);
if (stored_xce) {
if (XG(request_time) <= stored_xce->ctime + stored_xce->ttl) {
xc_processor_restore_zval(return_value, stored_xce->data.var->value TSRMLS_CC);
xc_processor_restore_zval(return_value, stored_xce->data.var->value, stored_xce->have_references TSRMLS_CC);
/* return */
break;
}
@ -1829,7 +1829,7 @@ static inline void xc_var_inc_dec(int inc, INTERNAL_FUNCTION_PARAMETERS) /* {{{
#ifdef DEBUG
fprintf(stderr, "incdec: notlong\n");
#endif
xc_processor_restore_zval(&oldzval, stored_xce->data.var->value TSRMLS_CC);
xc_processor_restore_zval(&oldzval, stored_xce->data.var->value, stored_xce->have_references TSRMLS_CC);
convert_to_long(&oldzval);
value = Z_LVAL(oldzval);
zval_dtor(&oldzval);

2
xcache.h

@ -248,6 +248,8 @@ struct _xc_entry_t {
xc_entry_data_php_t *php;
xc_entry_data_var_t *var;
} data;
zend_bool have_references;
};
/* }}} */

Loading…
Cancel
Save