Changeset 1558 in svn


Ignore:
Timestamp:
2014-11-10T06:08:07Z (4 years ago)
Author:
Xuefer
Message:

closes #342: object caching

Location:
trunk
Files:
4 added
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/ChangeLog

    r1548 r1558  
    1111   * (WIP) cache to disk
    1212   * fixed #348: added class const support for __FILE__ __DIR__
     13   * closes #342: added support for object caching. handle IS_RESTORCE as interger
    1314 * disassembler, decompiler:
    1415   * PHP_5_6 support
  • trunk/Makefile.frag.deps

    r1556 r1558  
    1919xcache/xc_mutex.lo $(builddir)/xcache/xc_mutex.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_shm.h
    2020xcache/xc_opcode_spec.lo $(builddir)/xcache/xc_opcode_spec.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_const_string.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_opcode_spec.h $(srcdir)/xcache/xc_opcode_spec_def.h $(srcdir)/xcache/xc_shm.h
    21 xcache/xc_processor.lo $(builddir)/xcache/xc_processor.lo: $(XCACHE_PROC_C) $(XCACHE_PROC_H) $(srcdir)/mod_cacher/xc_cache.h $(srcdir)/processor/debug.h $(srcdir)/processor/processor-t.h $(srcdir)/processor/string-helper-t.h $(srcdir)/processor/string-helper.h $(srcdir)/processor/types.h $(srcdir)/util/xc_align.h $(srcdir)/util/xc_trace.h $(srcdir)/util/xc_util.h $(srcdir)/util/xc_vector.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_allocator.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_const_string.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache_globals.h
     21xcache/xc_processor.lo $(builddir)/xcache/xc_processor.lo: $(XCACHE_PROC_C) $(XCACHE_PROC_H) $(srcdir)/mod_cacher/xc_cache.h $(srcdir)/processor/class-helper.h $(srcdir)/processor/debug.h $(srcdir)/processor/processor-t.h $(srcdir)/processor/string-helper-t.h $(srcdir)/processor/string-helper.h $(srcdir)/processor/types.h $(srcdir)/processor/var-helper-t.h $(srcdir)/processor/var-helper.h $(srcdir)/util/xc_align.h $(srcdir)/util/xc_trace.h $(srcdir)/util/xc_util.h $(srcdir)/util/xc_vector.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_allocator.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_const_string.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache_globals.h
    2222xcache/xc_sandbox.lo $(builddir)/xcache/xc_sandbox.lo: $(srcdir)/util/xc_vector.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_sandbox.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache_globals.h
    2323xcache/xc_shm.lo $(builddir)/xcache/xc_shm.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_mutex.h $(srcdir)/xcache/xc_shm.h
  • trunk/NEWS

    r1546 r1558  
    44 * cache defragment, cache to disk
    55 * added class const support for __FILE__ __DIR__
     6 * adds support for object caching
    67 * updated disassembler decompiler support
    78
  • trunk/mod_cacher/xc_cache.h

    r1530 r1558  
    185185#endif
    186186    zval      *value;
     187
     188#ifdef ZEND_ENGINE_2
     189    zend_uint objects_count;
     190    zend_object *objects;
     191#endif
     192    zend_uint class_names_count;
     193    xc_constant_string_t *class_names;
     194
    187195    zend_bool  have_references;
    188196} xc_entry_var_t;
  • trunk/mod_cacher/xc_cacher.c

    r1551 r1558  
    33433343        if (stored_entry_var) {
    33443344            /* return */
    3345             xc_processor_restore_zval(return_value, stored_entry_var->value, stored_entry_var->have_references TSRMLS_CC);
     3345            xc_processor_restore_var(return_value, stored_entry_var TSRMLS_CC);
    33463346            xc_cached_hit_unlocked(cache->cached TSRMLS_CC);
    33473347        }
     
    33823382    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz|l", &name, &value, &entry_var.entry.ttl) == FAILURE) {
    33833383        return;
    3384     }
    3385 
    3386     if (Z_TYPE_P(value) == IS_OBJECT) {
    3387         php_error_docref(NULL TSRMLS_CC, E_ERROR, "Objects cannot be stored in the variable cache. Use serialize before xcache_set");
    3388         RETURN_NULL();
    33893384    }
    33903385
     
    36163611
    36173612            TRACE("%s", "incdec: notlong");
    3618             xc_processor_restore_zval(&oldzval, stored_entry_var->value, stored_entry_var->have_references TSRMLS_CC);
    3619             convert_to_long(&oldzval);
    3620             value = Z_LVAL(oldzval);
    3621             zval_dtor(&oldzval);
     3613            if (stored_entry_var->objects_count) {
     3614                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot convert object to integer");
     3615                value = 0;
     3616            }
     3617            else {
     3618                xc_processor_restore_var(&oldzval, stored_entry_var TSRMLS_CC);
     3619                convert_to_long(&oldzval);
     3620                value = Z_LVAL(oldzval);
     3621                zval_dtor(&oldzval);
     3622            }
    36223623        }
    36233624        else {
  • trunk/processor/class-helper.m4

    r1554 r1558  
    113113/* }}} */
    114114#endif
     115
     116define(`xc_lookup_class', `IFRESTORE(``xc_lookup_class'($@)',``xc_lookup_class' can be use in restore only')')
  • trunk/processor/foot.m4

    r1551 r1558  
    8484dnl }}}
    8585')
    86 DEFINE_STORE_API(`xc_entry_var_t')
    8786DEFINE_STORE_API(`xc_entry_php_t')
    8887DEFINE_STORE_API(`xc_entry_data_php_t')
     88DEFINE_STORE_API(`xc_entry_var_t')
    8989EXPORTED_FUNCTION(`xc_entry_php_t *xc_processor_restore_xc_entry_php_t(xc_entry_php_t *dst, const xc_entry_php_t *src TSRMLS_DC)') dnl {{{
    9090{
     
    119119}
    120120dnl }}}
    121 EXPORTED_FUNCTION(`zval *xc_processor_restore_zval(zval *dst, const zval *src, zend_bool have_references TSRMLS_DC)') dnl {{{
     121EXPORTED_FUNCTION(`zval *xc_processor_restore_var(zval *dst, const xc_entry_var_t *src TSRMLS_DC)') dnl {{{
    122122{
    123123    xc_processor_t processor;
     124    size_t i;
    124125
    125126    memset(&processor, 0, sizeof(processor));
    126     processor.handle_reference = have_references;
     127    processor.handle_reference = src->have_references;
    127128
    128129    if (processor.handle_reference) {
    129130        zend_hash_init(&processor.zvalptrs, 0, NULL, NULL, 0);
    130131        dnl fprintf(stderr, "mark[%p] = %p\n", src, dst);
    131         zend_hash_add(&processor.zvalptrs, (char *)src, sizeof(src), (void*)&dst, sizeof(dst), NULL);
     132        zend_hash_add(&processor.zvalptrs, (char *)src->value, sizeof(src->value), (void *) &dst, sizeof(dst), NULL);
    132133    }
    133     xc_restore_zval(&processor, dst, src TSRMLS_CC);
     134    processor.entry_var_src = src;
     135
     136#ifdef ZEND_ENGINE_2
     137    if (src->objects_count) {
     138        processor.object_handles = emalloc(sizeof(*processor.object_handles) * src->objects_count);
     139        xc_vector_init(zend_object_handle, &processor.objects, 0);
     140        for (i = 0; i < src->objects_count; ++i) {
     141            zend_object *object = emalloc(sizeof(*object));
     142            xc_restore_zend_object(&processor, object, &src->objects[i] TSRMLS_CC);
     143            processor.object_handles[i] = zend_objects_store_put(object, (zend_objects_store_dtor_t) zend_objects_destroy_object, (zend_objects_free_object_storage_t) zend_objects_free_object_storage, NULL TSRMLS_CC);
     144        }
     145    }
     146#endif
     147    xc_restore_zval(&processor, dst, src->value TSRMLS_CC);
    134148    if (processor.handle_reference) {
    135149        zend_hash_destroy(&processor.zvalptrs);
    136150    }
     151
     152#ifdef ZEND_ENGINE_2
     153    if (src->objects_count) {
     154        for (i = 0; i < src->objects_count; ++i) {
     155            zend_objects_store_del_ref_by_handle_ex(processor.object_handles[i], NULL TSRMLS_CC);
     156        }
     157        efree(processor.object_handles);
     158    }
     159#endif
    137160
    138161    return dst;
  • trunk/processor/head.m4

    r1555 r1558  
    5555#include "processor/string-helper.h"
    5656include(__dir__`/string-helper.m4')
     57
     58#include "processor/class-helper.h"
    5759include(__dir__`/class-helper.m4')
     60
     61#include "processor/var-helper.h"
     62include(__dir__`/var-helper.m4')
  • trunk/processor/process.m4

    r1492 r1558  
    7070    , `$1', `xc_hash_value_t',  `PROCESS_SCALAR(`$2', `lu', `$1')'
    7171    , `$1', `last_brk_cont_t',  `PROCESS_SCALAR(`$2', `d', `$1')'
     72    , `$1', `zend_object_handle',`PROCESS_SCALAR(`$2', `d', `$1')'
    7273
    7374    , `$1', `xc_ztstring',       `PROCESS_xc_ztstring(`$2')'
  • trunk/processor/processor-t.h

    r1555 r1558  
    2525
    2626    #include "processor/string-helper-t.h"
     27    #include "processor/var-helper-t.h"
    2728
    2829#ifdef HAVE_XCACHE_TEST
  • trunk/processor/processor.m4

    r1546 r1558  
    119119dnl }}}
    120120#endif
     121DEF_STRUCT_P_FUNC(`zend_object', , `dnl {{{
     122    dnl handle ce
     123    dnl IFCALCSTORE(`
     124    dnl     pushdef(`SRC', `ifelse(`$1', `ce', `src->ce->name', `')')
     125    dnl     pushdef(`DST', `ifelse(`$1', `ce', `(*(char **)&dst->ce)', `')')
     126    dnl     PROC_STRING(`ce')
     127    dnl     popdef(`SRC')
     128    dnl     popdef(`DST')
     129    dnl ', `IFRESTORE(`
     130    dnl     if (!(DST(`ce') = xc_lookup_class((const char *) SRC(`ce') TSRMLS_CC))) {
     131    dnl         DST(`ce') = zend_standard_class_def;
     132    dnl         php_error_docref(NULL TSRMLS_CC, E_WARNING, "Class %s not found when restroing variable", (const char *) SRC(`ce'));
     133    dnl     }
     134    dnl     DONE(`ce')
     135    dnl ', `
     136    dnl     PROCESS(zend_ulong, ce)
     137    dnl ')')
     138    IFCALC(`
     139        xc_var_collect_class(processor, SRC(ce) TSRMLS_CC);
     140        DONE(ce)
     141    ', `IFSTORE(`
     142        DST(ce) = (zend_class_entry *) xc_var_ce_to_index(processor, DST(ce) TSRMLS_CC);
     143        DONE(ce)
     144    ', `IFRESTORE(`
     145        DST(ce) = xc_var_index_to_ec(processor, (size_t) DST(ce) TSRMLS_CC);
     146        DONE(ce)
     147    ', `
     148        PROCESS_SCALAR(ce, %lu, unsigned long)
     149    ')')')
     150
     151    STRUCT_P(HashTable, properties, HashTable_zval_ptr)
     152#ifdef ZEND_ENGINE_2_4
     153    dnl TODO: how to rebuild properties_table
     154    STRUCT_ARRAY(int, ce->default_properties_count, zval_ptr, properties_table)
     155#endif
     156#ifdef ZEND_ENGINE_2
     157    COPYNULL(`guards')
     158#endif
     159')
     160dnl }}}
     161#ifdef ZEND_ENGINE_2
     162DEF_STRUCT_P_FUNC(`zend_object_value', , `dnl {{{
     163    IFCALC(`
     164        xc_var_collect_object(processor, SRC(handle) TSRMLS_CC);
     165        DONE(handle)
     166    ', `IFSTORE(`
     167        DST(handle) = (zend_object_handle) xc_var_store_handle(processor, DST(handle) TSRMLS_CC);
     168        DONE(handle)
     169    ', `IFRESTORE(`
     170        DST(handle) = xc_var_restore_handle(processor, (size_t) DST(handle) TSRMLS_CC);
     171        DONE(handle)
     172    ', `
     173        PROCESS(zend_object_handle, handle)
     174    ')')')
     175    COPY(handlers)
     176')
     177dnl }}}
     178#endif
    121179DEF_STRUCT_P_FUNC(`zval', , `dnl {{{
    122180    IFDASM(`do {
     
    142200        switch ((Z_TYPE_P(SRC()) & IS_CONSTANT_TYPE_MASK)) {
    143201            case IS_LONG:
    144             case IS_RESOURCE:
    145202            case IS_BOOL:
    146203                PROCESS(long, value.lval)
     
    196253
    197254            case IS_OBJECT:
    198                 IFNOTMEMCPY(`IFCOPY(`memcpy(DST(), SRC(), sizeof(SRC()[0]));')')
    199                 dnl STRUCT(value.obj)
    200 #ifndef ZEND_ENGINE_2
    201                 STRUCT_P(zend_class_entry, value.obj.ce)
    202                 STRUCT_P(HashTable, value.obj.properties, HashTable_zval_ptr)
     255#ifdef ZEND_ENGINE_2
     256                STRUCT(zend_object_value, value.obj)
     257#else
     258                STRUCT(zend_object, value.obj)
    203259#endif
    204260                break;
    205261
    206262            default:
    207                 assert(0);
     263                /* IS_RESOURCE */
     264                IFCOPY(`Z_TYPE_P(DST()) = IS_LONG;')
     265                PROCESS(long, value.lval)
     266                break;
    208267        }
    209268        ')
     
    13401399dnl }}}
    13411400DEF_STRUCT_P_FUNC(`xc_entry_var_t', , `dnl {{{
     1401    IFCALCSTORE(`xc_entry_var_t *vsrc = /* const_cast */ (xc_entry_var_t *) src;')
     1402
     1403    dnl restore is done in foot.m4
    13421404    STRUCT(xc_entry_t, entry)
    13431405
     
    13691431    IFDPRINT(`INDENT()`'fprintf(stderr, "zval:value");')
    13701432    STRUCT_P_EX(zval_ptr, DST(`value'), SRC(`value'), `value', `', `&')
     1433
     1434#ifdef ZEND_ENGINE_2
     1435    IFCALC(`
     1436        dnl objects = collect_from(value);
     1437        pushdef(`src', `vsrc')
     1438        SRC(objects_count) = xc_vector_size(&processor->objects);
     1439        SRC(objects) = xc_vector_detach(zend_object, &processor->objects);
     1440        popdef(`src')
     1441        xc_vector_destroy(&processor->objects);
     1442        if (SRC(`objects_count')) {
     1443            xc_vector_init(xc_constant_string_t, &processor->class_names, 0);
     1444            zend_hash_init(&processor->class_name_to_index, 0, NULL, NULL, 0);
     1445        }
     1446    ')
     1447    dnl must be after calc .value
     1448    PROCESS(zend_uint, objects_count)
     1449    STRUCT_ARRAY(zend_uint, objects_count, zend_object, objects)
     1450    IFSTORE(`{
     1451        /* no longer needed */
     1452        if (vsrc->objects_count) {
     1453            efree(vsrc->objects);
     1454            vsrc->objects_count = 0;
     1455            vsrc->objects = NULL;
     1456            zend_hash_destroy(&processor->handle_to_index);
     1457        }
     1458    }')
     1459#endif
     1460
     1461    dnl classe_
     1462    IFCALC(`
     1463        dnl class_names = collect_from(objects);
     1464        pushdef(`src', `vsrc')
     1465        SRC(class_names_count) = xc_vector_size(&processor->class_names);
     1466        SRC(class_names) = xc_vector_detach(xc_constant_string_t, &processor->class_names);
     1467        popdef(`src')
     1468        xc_vector_destroy(&processor->class_names);
     1469    ')
     1470    PROCESS(zend_uint, class_names_count)
     1471    STRUCT_ARRAY(zend_uint, class_names_count, xc_constant_string_t, class_names)
     1472    IFSTORE(`
     1473        /* no longer needed */
     1474        if (vsrc->class_names_count) {
     1475            dnl size_t i;
     1476            dnl for (i = 0; i < vsrc->class_names_count; ++i) {
     1477            dnl     efree(vsrc->class_names[i]);
     1478            dnl }
     1479            efree(vsrc->class_names);
     1480            vsrc->class_names_count = 0;
     1481            vsrc->class_names = NULL;
     1482            zend_hash_destroy(&processor->class_name_to_index);
     1483        }
     1484    ')
     1485
    13711486    PROCESS(zend_bool, have_references)
    13721487    DONE(value)
  • trunk/util/xc_vector.h

    r1551 r1558  
    3939static inline void xc_vector_destroy_impl(xc_vector_t *vector TSRMLS_DC)
    4040{
     41    vector->size = 0;
    4142    if (vector->data) {
    4243        pefree(vector->data, vector->persistent);
     44        vector->data = NULL;
    4345    }
    4446    vector->capacity = 0;
    45     vector->size = 0;
     47    vector->data_size = 0;
    4648}
    4749
     
    4951
    5052#define xc_vector_size(vector) ((vector)->size)
     53#define xc_vector_initialized(vector) ((vector)->data_size != 0)
    5154#define xc_vector_element_ptr_(vector, index) ( \
    5255    (void *) ( \
Note: See TracChangeset for help on using the changeset viewer.