Changeset 851 in svn


Ignore:
Timestamp:
2012-03-27T18:07:50+02:00 (3 years ago)
Author:
Xuefer
Message:

more readability cache property. reduce memory footprint for data caching

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/xcache.tpl.php

    r689 r851  
    212212            $size     = size($entry['size']);
    213213            if ($isphp) {
    214                 $sourcesize  = size($entry['sourcesize']);
     214                $file_size   = size($entry['file_size']);
    215215                $phprefcount = number_format($entry['phprefcount']);
    216216            }
     
    246246                echo <<<ENTRY
    247247                <td int="{$entry['phprefcount']}">{$phprefcount}</td>
    248                 <td int="{$entry['sourcesize']}">{$sourcesize}</td>
     248                <td int="{$entry['file_size']}">{$file_size}</td>
    249249                <td int="{$entry['mtime']}">{$mtime}</td>
    250250ENTRY;
    251                 if (isset($entry['inode'])) {
     251                if (isset($entry['file_inode'])) {
    252252                    echo <<<ENTRY
    253                     <td int="{$entry['device']}">{$entry['device']}</td>
    254                     <td int="{$entry['inode']}">{$entry['inode']}</td>
     253                    <td int="{$entry['file_device']}">{$entry['file_device']}</td>
     254                    <td int="{$entry['file_inode']}">{$entry['file_inode']}</td>
    255255ENTRY;
    256256                }
  • trunk/processor/head.m4

    r846 r851  
    8282    zend_bool reference; /* enable if to deal with reference */
    8383    zend_bool have_references;
    84     const xc_entry_t *entry_src;
    85     const xc_entry_t *entry_dst;
     84    const xc_entry_php_t *entry_php_src;
     85    const xc_entry_php_t *entry_php_dst;
    8686    const xc_entry_data_php_t *php_src;
    8787    const xc_entry_data_php_t *php_dst;
     
    396396    memset(&processor, 0, sizeof(processor));
    397397    processor.reference = 1;
    398     processor.cache = src->cache;
     398    processor.cache = src->ifelse(`$1', `xc_entry_php_t', entry.)cache;
    399399
    400400    IFASSERT(`xc_stack_init(&processor.allocsizes);')
     
    416416        zend_hash_destroy(&processor.strings);
    417417    }
    418     src->size = processor.size;
    419     ifelse(`$1', `xc_entry_t', `
    420         src->data.var->have_references = processor.have_references;
    421     ', `
    422         src->have_references = processor.have_references;
    423     ')
     418    src->ifelse(`$1', `xc_entry_php_t', entry.)size = processor.size;
     419    ifelse(
     420        `$1', `xc_entry_t', `src->data.var.have_references = processor.have_references;',
     421        `$1', `xc_entry_data_php_t', `src->have_references = processor.have_references;'
     422    )
    424423
    425424    IFASSERT(`xc_stack_reverse(&processor.allocsizes);')
     
    469468')
    470469DEFINE_STORE_API(`xc_entry_t')
     470DEFINE_STORE_API(`xc_entry_php_t')
    471471DEFINE_STORE_API(`xc_entry_data_php_t')
    472 /* export: xc_entry_t *xc_processor_restore_xc_entry_t(xc_entry_t *dst, const xc_entry_t *src TSRMLS_DC); :export {{{ */
    473 xc_entry_t *xc_processor_restore_xc_entry_t(xc_entry_t *dst, const xc_entry_t *src TSRMLS_DC) {
     472/* export: xc_entry_php_t *xc_processor_restore_xc_entry_php_t(xc_entry_php_t *dst, const xc_entry_php_t *src TSRMLS_DC); :export {{{ */
     473xc_entry_php_t *xc_processor_restore_xc_entry_php_t(xc_entry_php_t *dst, const xc_entry_php_t *src TSRMLS_DC) {
    474474    xc_processor_t processor;
    475475
    476476    memset(&processor, 0, sizeof(processor));
    477     xc_restore_xc_entry_t(&processor, dst, src TSRMLS_CC);
     477    xc_restore_xc_entry_php_t(&processor, dst, src TSRMLS_CC);
    478478
    479479    return dst;
    480480}
    481481/* }}} */
    482 /* export: xc_entry_data_php_t *xc_processor_restore_xc_entry_data_php_t(const xc_entry_t *xce, xc_entry_data_php_t *dst, const xc_entry_data_php_t *src, zend_bool readonly_protection TSRMLS_DC); :export {{{ */
    483 xc_entry_data_php_t *xc_processor_restore_xc_entry_data_php_t(const xc_entry_t *xce, xc_entry_data_php_t *dst, const xc_entry_data_php_t *src, zend_bool readonly_protection TSRMLS_DC) {
     482/* export: xc_entry_data_php_t *xc_processor_restore_xc_entry_data_php_t(const xc_entry_php_t *xce, xc_entry_data_php_t *dst, const xc_entry_data_php_t *src, zend_bool readonly_protection TSRMLS_DC); :export {{{ */
     483xc_entry_data_php_t *xc_processor_restore_xc_entry_data_php_t(const xc_entry_php_t *xce, xc_entry_data_php_t *dst, const xc_entry_data_php_t *src, zend_bool readonly_protection TSRMLS_DC) {
    484484    xc_processor_t processor;
    485485
     
    490490        processor.reference = 1;
    491491    }
    492     processor.entry_src = xce;
     492    processor.entry_php_src = xce;
    493493
    494494    if (processor.reference) {
     
    499499        zend_hash_destroy(&processor.zvalptrs);
    500500    }
     501    return dst;
     502}
     503/* }}} */
     504/* export: xc_entry_t *xc_processor_restore_xc_entry_t(xc_entry_t *dst, const xc_entry_t *src TSRMLS_DC); :export {{{ */
     505xc_entry_t *xc_processor_restore_xc_entry_t(xc_entry_t *dst, const xc_entry_t *src TSRMLS_DC) {
     506    xc_processor_t processor;
     507
     508    memset(&processor, 0, sizeof(processor));
     509    xc_restore_xc_entry_t(&processor, dst, src TSRMLS_CC);
     510
    501511    return dst;
    502512}
     
    522532}
    523533/* }}} */
    524 /* export: void xc_dprint(xc_entry_t *src, int indent TSRMLS_DC); :export {{{ */
     534/* export: void xc_dprint(xc_entry_php_t *src, int indent TSRMLS_DC); :export {{{ */
    525535#ifdef HAVE_XCACHE_DPRINT
    526 void xc_dprint(xc_entry_t *src, int indent TSRMLS_DC) {
     536void xc_dprint(xc_entry_php_t *src, int indent TSRMLS_DC) {
    527537    IFDPRINT(`INDENT()`'fprintf(stderr, "xc_entry_t:src");')
    528538    xc_dprint_xc_entry_t(src, indent TSRMLS_CC);
  • trunk/processor/main.m4

    r844 r851  
    253253EXPORT(`xc_funcinfo_t')
    254254EXPORT(`xc_entry_t')
     255EXPORT(`xc_entry_php_t')
    255256EXPORT(`xc_entry_data_php_t')
    256257EXPORT(`zval')
  • trunk/processor/processor.m4

    r846 r851  
    431431#   ifdef ZEND_ENGINE_2_4
    432432    DISABLECHECK(`
    433     IFRESTORE(`dst->info.user.filename = processor->entry_src->filepath;', `PROC_STRING(info.user.filename)')
     433    IFRESTORE(`dst->info.user.filename = processor->entry_php_src->filepath;', `PROC_STRING(info.user.filename)')
    434434    PROCESS(zend_uint, info.user.line_start)
    435435    PROCESS(zend_uint, info.user.line_end)
     
    439439    DONE(info)
    440440#   else
    441     IFRESTORE(`dst->filename = processor->entry_src->filepath;DONE(filename)', `PROC_STRING(filename)')
     441    IFRESTORE(`dst->filename = processor->entry_php_src->filepath;DONE(filename)', `PROC_STRING(filename)')
    442442    PROCESS(zend_uint, line_start)
    443443    PROCESS(zend_uint, line_end)
     
    709709        gc_arg_info = 1;
    710710#endif
    711         dst->filename = processor->entry_src->filepath;
     711        dst->filename = processor->entry_php_src->filepath;
    712712#ifdef ZEND_ENGINE_2_4
    713713        if (src->literals /* || op_array_info->literalsinfo_cnt */) {
     
    886886#endif
    887887
    888     IFRESTORE(`dst->filename = processor->entry_src->filepath;DONE(filename)', `PROC_STRING(filename)')
     888    IFRESTORE(`dst->filename = processor->entry_php_src->filepath;DONE(filename)', `PROC_STRING(filename)')
    889889#ifdef IS_UNICODE
    890890    IFRESTORE(`
     
    914914#endif
    915915    } while (0);
    916     IFRESTORE(`xc_fix_op_array_info(processor->entry_src, processor->php_src, dst, shallow_copy, op_array_info TSRMLS_CC);')
     916    IFRESTORE(`xc_fix_op_array_info(processor->entry_php_src, processor->php_src, dst, shallow_copy, op_array_info TSRMLS_CC);')
    917917
    918918#ifdef ZEND_ENGINE_2
     
    10741074    PROCESS(zend_ulong, refcount)
    10751075
    1076     PROCESS(size_t, sourcesize)
     1076    PROCESS(size_t, file_size)
    10771077    PROCESS(zend_ulong, hits)
    10781078    PROCESS(size_t, size)
     
    11271127dnl }}}
    11281128DEF_STRUCT_P_FUNC(`xc_entry_t', , `dnl {{{
     1129    PROCESS(xc_hash_value_t, hvalue)
     1130    /* skip */
     1131    DONE(next)
     1132    COPY(cache)
    11291133    PROCESS(xc_entry_type_t, type)
    11301134    PROCESS(size_t, size)
    1131 
    1132     PROCESS(xc_hash_value_t, hvalue)
    1133     COPY(cache)
    1134     /* skip */
    1135     DONE(next)
    1136 
    1137     IFSTORE(`dst->refcount = 0; DONE(refcount)', `PROCESS(long, refcount)')
    11381135
    11391136    PROCESS(time_t, ctime)
     
    11761173
    11771174        case XC_TYPE_VAR:
    1178             STRUCT_P(xc_entry_data_var_t, data.var)
     1175            STRUCT(xc_entry_data_var_t, data.var)
    11791176            break;
    11801177
     
    11851182    DONE(data)
    11861183    dnl }}}
    1187     PROCESS(time_t, mtime)
     1184')
     1185dnl }}}
     1186DEF_STRUCT_P_FUNC(`xc_entry_php_t', , `dnl {{{
     1187    STRUCT(xc_entry_t, entry)
     1188
     1189    IFSTORE(`dst->refcount = 0; DONE(refcount)', `PROCESS(long, refcount)')
     1190    PROCESS(time_t, file_mtime)
    11881191#ifdef HAVE_INODE
    1189     PROCESS(int, device)
    1190     PROCESS(int, inode)
    1191 #endif
    1192 
    1193     if (src->type == XC_TYPE_PHP) {
     1192    PROCESS(int, file_device)
     1193    PROCESS(int, file_inode)
     1194#endif
     1195
     1196    if (src->entry.type == XC_TYPE_PHP) {
    11941197        PROCESS(int, filepath_len)
    11951198        IFRESTORE(`COPY(filepath)', `PROC_STRING_L(filepath, filepath_len)')
  • trunk/xcache.c

    r848 r851  
    145145{
    146146    xc_entry_data_php_t *p;
    147     for (p = php->cache->phps[php->hvalue]; p; p = p->next) {
     147    for (p = php->cache->phps[php->hvalue]; p; p = (xc_entry_data_php_t *) p->next) {
    148148        if (memcmp(&php->md5.digest, &p->md5.digest, sizeof(php->md5.digest)) == 0) {
    149149            p->hits ++;
     
    182182/* }}} */
    183183
    184 static inline int xc_entry_equal_dmz(xc_entry_t *a, xc_entry_t *b) /* {{{ */
     184static inline int xc_entry_equal_dmz(const xc_entry_t *entry1, const xc_entry_t *entry2) /* {{{ */
    185185{
    186186    /* this function isn't required but can be in dmz */
    187187
    188     if (a->type != b->type) {
     188    if (entry1->type != entry2->type) {
    189189        return 0;
    190190    }
    191     switch (a->type) {
     191    switch (entry1->type) {
    192192        case XC_TYPE_PHP:
    193193#ifdef HAVE_INODE
    194             do {
    195                 if (a->inode) {
    196                     return a->inode == b->inode
    197                         && a->device == b->device;
     194            {
     195                const xc_entry_php_t *php_entry1 = (const xc_entry_php_t *) entry1;
     196                const xc_entry_php_t *php_entry2 = (const xc_entry_php_t *) entry2;
     197                if (php_entry1->file_inode) {
     198                    return php_entry1->file_inode == php_entry2->file_inode
     199                        && php_entry1->file_device == php_entry2->file_device;
    198200                }
    199             } while(0);
     201            }
    200202#endif
    201203            /* fall */
     
    204206            do {
    205207#ifdef IS_UNICODE
    206                 if (a->name_type == IS_UNICODE) {
    207                     if (a->name.ustr.len != b->name.ustr.len) {
     208                if (entry1->name_type == IS_UNICODE) {
     209                    if (entry1->name.ustr.len != entry2->name.ustr.len) {
    208210                        return 0;
    209211                    }
    210                     return memcmp(a->name.ustr.val, b->name.ustr.val, (a->name.ustr.len + 1) * sizeof(UChar)) == 0;
     212                    return memcmp(entry1->name.ustr.val, entry2->name.ustr.val, (entry1->name.ustr.len + 1) * sizeof(UChar)) == 0;
    211213                }
    212214#endif
    213                 if (a->name.str.len != b->name.str.len) {
     215                if (entry1->name.str.len != entry2->name.str.len) {
    214216                    return 0;
    215217                }
    216                 return memcmp(a->name.str.val, b->name.str.val, a->name.str.len + 1) == 0;
     218                return memcmp(entry1->name.str.val, entry2->name.str.val, entry1->name.str.len + 1) == 0;
    217219
    218220            } while(0);
     
    275277    xce->ctime = XG(request_time);
    276278    xce->atime = XG(request_time);
    277     stored_xce = xc_processor_store_xc_entry_t(xce TSRMLS_CC);
     279    stored_xce = xce->type == XC_TYPE_PHP
     280        ? (xc_entry_t *) xc_processor_store_xc_entry_php_t((xc_entry_php_t *) xce TSRMLS_CC)
     281        : xc_processor_store_xc_entry_t(xce TSRMLS_CC);
    278282    if (stored_xce) {
    279283        xc_entry_add_dmz(stored_xce);
     
    286290}
    287291/* }}} */
     292static xc_entry_php_t *xc_entry_php_store_dmz(xc_entry_php_t *xce TSRMLS_DC) /* {{{ */
     293{
     294    return (xc_entry_php_t *) xc_entry_store_dmz((xc_entry_t *) xce TSRMLS_CC);
     295}
     296/* }}} */
    288297static void xc_entry_free_real_dmz(volatile xc_entry_t *xce) /* {{{ */
    289298{
     
    297306{
    298307    xce->cache->entries_count --;
    299     if (xce->refcount == 0) {
     308    if ((xce->type == XC_TYPE_PHP ? ((xc_entry_php_t *) xce)->refcount : 0) == 0) {
    300309        xc_entry_free_real_dmz(xce);
    301310    }
     
    329338    for (p = xce->cache->entries[xce->hvalue]; p; p = p->next) {
    330339        if (xc_entry_equal_dmz(xce, p)) {
    331             if (p->type == XC_TYPE_VAR || /* PHP */ (p->mtime == xce->mtime && p->data.php->sourcesize == xce->data.php->sourcesize)) {
     340            zend_bool fresh;
     341            switch (p->type) {
     342            case XC_TYPE_PHP:
     343                {
     344                    xc_entry_php_t *p_php = (xc_entry_php_t *) p;
     345                    xc_entry_php_t *xce_php = (xc_entry_php_t *) xce;
     346                    fresh = p_php->file_mtime == xce_php->file_mtime && p->data.php->file_size == xce->data.php->file_size;
     347                    break;
     348                }
     349
     350            case XC_TYPE_VAR:
     351                fresh = 1;
     352                break;
     353
     354            default:
     355                assert(0);
     356            }
     357
     358            if (fresh) {
    332359                p->hits ++;
    333360                p->atime = XG(request_time);
    334361                return p;
    335362            }
    336             else {
    337                 xc_entry_remove_dmz(p TSRMLS_CC);
    338                 return NULL;
    339             }
     363
     364            xc_entry_remove_dmz(p TSRMLS_CC);
     365            return NULL;
    340366        }
    341367    }
     
    343369}
    344370/* }}} */
    345 static void xc_entry_hold_php_dmz(xc_entry_t *xce TSRMLS_DC) /* {{{ */
    346 {
    347     TRACE("hold %s", xce->name.str.val);
     371static void xc_entry_hold_php_dmz(xc_entry_php_t *xce TSRMLS_DC) /* {{{ */
     372{
     373    TRACE("hold %s", xce->entry.name.str.val);
    348374    xce->refcount ++;
    349     xc_stack_push(&XG(php_holds)[xce->cache->cacheid], (void *)xce);
     375    xc_stack_push(&XG(php_holds)[xce->entry.cache->cacheid], (void *)xce);
    350376}
    351377/* }}} */
     
    500526    pp = &cache->deletes;
    501527    for (p = *pp; p; p = *pp) {
     528        xc_entry_php_t *entry = (xc_entry_php_t *) p;
    502529        if (XG(request_time) - p->dtime > 3600) {
    503             p->refcount = 0;
     530            entry->refcount = 0;
    504531            /* issue warning here */
    505532        }
    506         if (p->refcount == 0) {
     533        if (entry->refcount == 0) {
    507534            /* unlink */
    508535            *pp = p->next;
     
    622649}
    623650/* }}} */
    624 static void xc_fillentry_dmz(xc_entry_t *entry, int del, zval *list TSRMLS_DC) /* {{{ */
     651static void xc_fillentry_dmz(const xc_entry_t *entry, int del, zval *list TSRMLS_DC) /* {{{ */
    625652{
    626653    zval* ei;
    627     xc_entry_data_php_t *php;
    628     xc_entry_data_var_t *var;
     654    const xc_entry_data_php_t *php;
     655    const xc_entry_data_var_t *var;
     656    xc_entry_php_t *entry_php = (xc_entry_php_t *) entry;
    629657
    630658    ALLOC_INIT_ZVAL(ei);
    631659    array_init(ei);
    632660
    633     add_assoc_long_ex(ei, ZEND_STRS("refcount"), entry->refcount);
     661    add_assoc_long_ex(ei, ZEND_STRS("refcount"), entry_php->refcount);
    634662    add_assoc_long_ex(ei, ZEND_STRS("hits"),     entry->hits);
    635663    add_assoc_long_ex(ei, ZEND_STRS("ctime"),    entry->ctime);
     
    664692            add_assoc_long_ex(ei, ZEND_STRS("size"),          entry->size + php->size);
    665693            add_assoc_long_ex(ei, ZEND_STRS("phprefcount"),   php->refcount);
    666             add_assoc_long_ex(ei, ZEND_STRS("sourcesize"),    php->sourcesize);
     694            add_assoc_long_ex(ei, ZEND_STRS("file_size"),     php->file_size);
    667695#ifdef HAVE_INODE
    668             add_assoc_long_ex(ei, ZEND_STRS("device"),        entry->device);
    669             add_assoc_long_ex(ei, ZEND_STRS("inode"),         entry->inode);
    670 #endif
    671             add_assoc_long_ex(ei, ZEND_STRS("mtime"),         entry->mtime);
     696            add_assoc_long_ex(ei, ZEND_STRS("file_device"),   entry_php->file_device);
     697            add_assoc_long_ex(ei, ZEND_STRS("file_inode"),    entry_php->file_inode);
     698#endif
     699            add_assoc_long_ex(ei, ZEND_STRS("file_mtime"),    entry_php->file_mtime);
    672700
    673701#ifdef HAVE_XCACHE_CONSTANT
     
    682710
    683711        case XC_TYPE_VAR:
    684             var = entry->data.var;
     712            var = &entry->data.var;
    685713            add_assoc_long_ex(ei, ZEND_STRS("size"),          entry->size);
    686714            break;
     
    718746/* }}} */
    719747
    720 static zend_op_array *xc_entry_install(xc_entry_t *xce, zend_file_handle *h TSRMLS_DC) /* {{{ */
     748static zend_op_array *xc_entry_install(xc_entry_php_t *xce, zend_file_handle *h TSRMLS_DC) /* {{{ */
    721749{
    722750    zend_uint i;
    723     xc_entry_data_php_t *p = xce->data.php;
     751    xc_entry_data_php_t *p = xce->entry.data.php;
    724752    zend_op_array *old_active_op_array = CG(active_op_array);
    725753#ifndef ZEND_ENGINE_2
     
    735763    for (i = 0; i < p->constinfo_cnt; i ++) {
    736764        xc_constinfo_t *ci = &p->constinfos[i];
    737         xc_install_constant(xce->name.str.val, &ci->constant,
     765        xc_install_constant(xce->entry.name.str.val, &ci->constant,
    738766                UNISW(0, ci->type), ci->key, ci->key_size, ci->h TSRMLS_CC);
    739767    }
     
    743771    for (i = 0; i < p->funcinfo_cnt; i ++) {
    744772        xc_funcinfo_t  *fi = &p->funcinfos[i];
    745         xc_install_function(xce->name.str.val, &fi->func,
     773        xc_install_function(xce->entry.name.str.val, &fi->func,
    746774                UNISW(0, fi->type), fi->key, fi->key_size, fi->h TSRMLS_CC);
    747775    }
     
    761789#endif
    762790#ifdef ZEND_COMPILE_DELAYED_BINDING
    763         xc_install_class(xce->name.str.val, &ci->cest, -1,
     791        xc_install_class(xce->entry.name.str.val, &ci->cest, -1,
    764792                UNISW(0, ci->type), ci->key, ci->key_size, ci->h TSRMLS_CC);
    765793#else
    766         xc_install_class(xce->name.str.val, &ci->cest, ci->oplineno,
     794        xc_install_class(xce->entry.name.str.val, &ci->cest, ci->oplineno,
    767795                UNISW(0, ci->type), ci->key, ci->key_size, ci->h TSRMLS_CC);
    768796#endif
     
    787815
    788816    i = 1;
    789     zend_hash_add(&EG(included_files), xce->name.str.val, xce->name.str.len+1, (void *)&i, sizeof(int), NULL);
     817    zend_hash_add(&EG(included_files), xce->entry.name.str.val, xce->entry.name.str.len+1, (void *)&i, sizeof(int), NULL);
    790818    if (h) {
    791819        zend_llist_add_element(&CG(open_files), h);
     
    816844                    xce = (xc_entry_t*) xc_stack_pop(s);
    817845                    TRACE("unhold %s", xce->name.str.val);
    818                     xce->refcount --;
    819                     assert(xce->refcount >= 0);
     846                    ((xc_entry_php_t *) xce)->refcount ++;
     847                    assert(((xc_entry_php_t *) xce)->refcount >= 0);
    820848                }
    821849            } LEAVE_LOCK(cache);
     
    885913/* }}} */
    886914
     915#if 0 /* {{{ note about php hashing */
     916the folling note is written in the form of "got = from"
     917
     918TODO: open_basedir
     919
     920opened_path = stat || zend_compile_file
     921
     922phphashid = inode ? inode : hash(basename)
     923md5key = md5(relativepath)
     924md5hashid = hash(md5key)
     925cachehashid = multislot ? hash(basename) : hash(phphashid)
     926
     927cached = phphashid -> md5key -> cachedmd5info -> cachedphp
     928cachedphp = [phphashid, fullpath]
     929restoredphp = [fullpath, phphashid]
     930
     931#endif /* }}} */
     932
    887933#define HASH(i) (i)
    888934#define HASH_ZSTR_L(t, s, l) HASH(zend_u_inline_hash_func((t), (s), ((l) + 1) * sizeof(UChar)))
     
    907953}
    908954/* }}} */
    909 #define xc_entry_hash_var xc_entry_hash_name
    910 static inline xc_hash_value_t xc_entry_hash_php(xc_entry_t *xce TSRMLS_DC) /* {{{ */
    911 {
    912 #ifdef HAVE_INODE
    913     if (xce->inode) {
    914         return HASH(xce->device + xce->inode);
    915     }
    916 #endif
    917     return xc_entry_hash_name(xce TSRMLS_CC);
    918 }
    919 /* }}} */
    920 static inline xc_hash_value_t xc_entry_hash_php_basename(xc_entry_t *xce TSRMLS_DC) /* {{{ */
     955static inline xc_hash_value_t xc_entry_hash_php_basename(xc_entry_php_t *xce TSRMLS_DC) /* {{{ */
    921956{
    922957#ifdef IS_UNICODE
    923     if (UG(unicode) && xce->name_type == IS_UNICODE) {
     958    if (UG(unicode) && xce->entry.name_type == IS_UNICODE) {
    924959        zstr basename;
    925960        size_t basename_len;
    926         php_u_basename(xce->name.ustr.val, xce->name.ustr.len, NULL, 0, &basename.u, &basename_len TSRMLS_CC);
     961        php_u_basename(xce->entry.name.ustr.val, xce->entry.name.ustr.len, NULL, 0, &basename.u, &basename_len TSRMLS_CC);
    927962        return HASH_ZSTR_L(IS_UNICODE, basename, basename_len);
    928963    }
     
    934969        size_t basename_len;
    935970#ifdef ZEND_ENGINE_2
    936         php_basename(xce->name.str.val, xce->name.str.len, "", 0, &basename, &basename_len TSRMLS_CC);
     971        php_basename(xce->entry.name.str.val, xce->entry.name.str.len, "", 0, &basename, &basename_len TSRMLS_CC);
    937972#else
    938         basename = php_basename(xce->name.str.val, xce->name.str.len, "", 0);
     973        basename = php_basename(xce->entry.name.str.val, xce->entry.name.str.len, "", 0);
    939974        basename_len = strlen(basename);
    940975#endif
     
    945980}
    946981/* }}} */
    947 static void xc_entry_free_key_php(xc_entry_t *xce TSRMLS_DC) /* {{{ */
     982#define xc_entry_hash_var xc_entry_hash_name
     983static inline xc_hash_value_t xc_entry_hash_php(xc_entry_php_t *xce TSRMLS_DC) /* {{{ */
     984{
     985    return
     986#ifdef HAVE_INODE
     987        xce->file_inode ? HASH(xce->file_device + xce->file_inode) :
     988#endif
     989        xc_entry_hash_php_basename(xce TSRMLS_CC);
     990}
     991/* }}} */
     992static void xc_entry_free_key_php(xc_entry_php_t *xce TSRMLS_DC) /* {{{ */
    948993{
    949994#define X_FREE(var) do {\
     
    9621007/* }}} */
    9631008
    964 static int xc_entry_init_key_php(xc_entry_t *xce, const char *filename TSRMLS_DC) /* {{{ */
     1009static int xc_entry_init_key_php(xc_entry_php_t *xce, const char *filename TSRMLS_DC) /* {{{ */
    9651010{
    9661011    char opened_path_buffer[MAXPATHLEN];
     
    10271072        }
    10281073
    1029         xce->mtime        = pbuf->st_mtime;
     1074        xce->file_mtime   = pbuf->st_mtime;
    10301075#ifdef HAVE_INODE
    1031         xce->device       = pbuf->st_dev;
    1032         xce->inode        = pbuf->st_ino;
    1033 #endif
    1034         xce->data.php->sourcesize = pbuf->st_size;
     1076        xce->file_device  = pbuf->st_dev;
     1077        xce->file_inode   = pbuf->st_ino;
     1078#endif
     1079        xce->entry.data.php->file_size = pbuf->st_size;
    10351080    }
    10361081    else { /* XG(inode) */
    1037         xce->mtime        = 0;
     1082        xce->file_mtime   = 0;
    10381083#ifdef HAVE_INODE
    1039         xce->device       = 0;
    1040         xce->inode        = 0;
    1041 #endif
    1042         xce->data.php->sourcesize = 0;
     1084        xce->file_device  = 0;
     1085        xce->file_inode   = 0;
     1086#endif
     1087        xce->entry.data.php->file_size = 0;
    10431088    }
    10441089
    10451090#ifdef HAVE_INODE
    1046     if (!xce->inode)
     1091    if (!xce->file_inode)
    10471092#endif
    10481093    {
     
    10551100    }
    10561101
    1057     UNISW(NOTHING, xce->name_type = IS_STRING;)
    1058     xce->name.str.val = (char *) filename;
    1059     xce->name.str.len = strlen(filename);
     1102    UNISW(NOTHING, xce->entry.name_type = IS_STRING;)
     1103    xce->entry.name.str.val = (char *) filename;
     1104    xce->entry.name.str.len = strlen(filename);
    10601105
    10611106    cacheid = xc_php_hcache.size > 1 ? xc_hash_fold(xc_entry_hash_php_basename(xce TSRMLS_CC), &xc_php_hcache) : 0;
    1062     xce->cache = xc_php_caches[cacheid];
    1063     xce->hvalue = xc_hash_fold(xc_entry_hash_php(xce TSRMLS_CC), &xc_php_hentry);
    1064     xce->type = XC_TYPE_PHP;
     1107    xce->entry.cache = xc_php_caches[cacheid];
     1108    xce->entry.hvalue = xc_hash_fold(xc_entry_hash_php(xce TSRMLS_CC), &xc_php_hentry);
     1109    xce->entry.type = XC_TYPE_PHP;
    10651110    xce->filepath  = NULL;
    10661111    xce->dirpath   = NULL;
     
    10781123}
    10791124/* }}} */
    1080 static int xc_entry_init_key_php_md5(xc_entry_data_php_t *php, xc_entry_t *xce TSRMLS_DC) /* {{{ */
     1125static int xc_entry_init_key_php_md5(xc_entry_data_php_t *php, xc_entry_php_t *xce TSRMLS_DC) /* {{{ */
    10811126{
    10821127    unsigned char   buf[1024];
     
    10861131    ulong           old_rsid = EG(regular_list).nNextFreeElement;
    10871132
    1088     stream = php_stream_open_wrapper(xce->name.str.val, "rb", USE_PATH | REPORT_ERRORS | ENFORCE_SAFE_MODE | STREAM_DISABLE_OPEN_BASEDIR, NULL);
     1133    stream = php_stream_open_wrapper(xce->entry.name.str.val, "rb", USE_PATH | REPORT_ERRORS | ENFORCE_SAFE_MODE | STREAM_DISABLE_OPEN_BASEDIR, NULL);
    10891134    if (!stream) {
    10901135        return FAILURE;
     
    11061151    }
    11071152
    1108     php->cache  = xce->cache;
     1153    php->cache  = xce->entry.cache;
    11091154    php->hvalue = (xc_php_hash_md5(php TSRMLS_CC) & php->cache->hphp->mask);
    11101155#ifdef XCACHE_DEBUG
     
    11191164}
    11201165/* }}} */
    1121 static void xc_entry_init_key_php_entry(xc_entry_t *xce, ZEND_24(const) char *filepath TSRMLS_DC) /* {{{*/
     1166static void xc_entry_init_key_php_entry(xc_entry_php_t *xce, ZEND_24(const) char *filepath TSRMLS_DC) /* {{{*/
    11221167{
    11231168    xce->filepath     = filepath;
     
    11781223} xc_const_usage_t;
    11791224/* }}} */
    1180 static void xc_collect_op_array_info(xc_entry_t *xce, xc_entry_data_php_t *php, xc_const_usage_t *usage, xc_op_array_info_t *op_array_info, zend_op_array *op_array TSRMLS_DC) /* {{{ */
     1225static void xc_collect_op_array_info(xc_entry_php_t *xce, xc_entry_data_php_t *php, xc_const_usage_t *usage, xc_op_array_info_t *op_array_info, zend_op_array *op_array TSRMLS_DC) /* {{{ */
    11811226{
    11821227    int i;
     
    12771322}
    12781323/* }}} */
    1279 void xc_fix_op_array_info(const xc_entry_t *xce, const xc_entry_data_php_t *php, zend_op_array *op_array, int shallow_copy, const xc_op_array_info_t *op_array_info TSRMLS_DC) /* {{{ */
     1324void xc_fix_op_array_info(const xc_entry_php_t *xce, const xc_entry_data_php_t *php, zend_op_array *op_array, int shallow_copy, const xc_op_array_info_t *op_array_info TSRMLS_DC) /* {{{ */
    12801325{
    12811326    int i;
     
    14681513}
    14691514/* }}} */
    1470 static zend_op_array *xc_compile_php(xc_entry_t *xce, xc_entry_data_php_t *php, zend_file_handle *h, int type TSRMLS_DC) /* {{{ */
     1515static zend_op_array *xc_compile_php(xc_entry_php_t *xce, xc_entry_data_php_t *php, zend_file_handle *h, int type TSRMLS_DC) /* {{{ */
    14711516{
    14721517    zend_op_array *op_array;
     
    17011746}
    17021747/* }}} */
    1703 static zend_op_array *xc_compile_restore(xc_entry_t *stored_xce, zend_file_handle *h TSRMLS_DC) /* {{{ */
     1748static zend_op_array *xc_compile_restore(xc_entry_php_t *stored_xce, zend_file_handle *h TSRMLS_DC) /* {{{ */
    17041749{
    17051750    zend_op_array *op_array;
    1706     xc_entry_t xce;
     1751    xc_entry_php_t xce;
    17071752    xc_entry_data_php_t php;
    17081753    zend_bool catched;
    17091754
    17101755    CG(in_compilation)    = 1;
    1711     CG(compiled_filename) = stored_xce->name.str.val;
     1756    CG(compiled_filename) = stored_xce->entry.name.str.val;
    17121757    CG(zend_lineno)       = 0;
    1713     TRACE("restoring %s", stored_xce->name.str.val);
    1714     xc_processor_restore_xc_entry_t(&xce, stored_xce TSRMLS_CC);
    1715     xc_processor_restore_xc_entry_data_php_t(stored_xce, &php, xce.data.php, xc_readonly_protection TSRMLS_CC);
    1716     xce.data.php = &php;
     1758    TRACE("restoring %s", stored_xce->entry.name.str.val);
     1759    xc_processor_restore_xc_entry_php_t(&xce, stored_xce TSRMLS_CC);
     1760    xc_processor_restore_xc_entry_data_php_t(stored_xce, &php, xce.entry.data.php, xc_readonly_protection TSRMLS_CC);
     1761    xce.entry.data.php = &php;
    17171762#ifdef SHOW_DPRINT
    17181763    xc_dprint(&xce, 0 TSRMLS_CC);
     
    17531798}
    17541799/* }}} */
    1755 static zend_op_array *xc_compile_file_ex(xc_entry_t *xce, zend_file_handle *h, int type TSRMLS_DC) /* {{{ */
     1800static zend_op_array *xc_compile_file_ex(xc_entry_php_t *xce, zend_file_handle *h, int type TSRMLS_DC) /* {{{ */
    17561801{
    17571802    zend_op_array *op_array;
    1758     xc_entry_t *stored_xce;
     1803    xc_entry_php_t *stored_xce;
    17591804    xc_entry_data_php_t *stored_php;
    1760     xc_cache_t *cache = xce->cache;
     1805    xc_cache_t *cache = xce->entry.cache;
    17611806    zend_bool gaveup = 0;
    17621807    zend_bool catched = 0;
     
    17731818    stored_php = NULL;
    17741819    ENTER_LOCK_EX(cache) {
    1775         stored_xce = xc_entry_find_dmz(xce TSRMLS_CC);
     1820        stored_xce = (xc_entry_php_t *) xc_entry_find_dmz((xc_entry_t *) xce TSRMLS_CC);
    17761821        if (stored_xce) {
    17771822            xc_cache_hit_dmz(cache TSRMLS_CC);
     
    17841829            TRACE("miss %s", xce->name.str.val);
    17851830
    1786             if (xc_entry_init_key_php_md5(xce->data.php, xce TSRMLS_CC) != SUCCESS) {
     1831            if (xc_entry_init_key_php_md5(xce->entry.data.php, xce TSRMLS_CC) != SUCCESS) {
    17871832                gaveup = 1;
    17881833                break;
    17891834            }
    17901835
    1791             stored_php = xc_php_find_dmz(xce->data.php TSRMLS_CC);
     1836            stored_php = xc_php_find_dmz(xce->entry.data.php TSRMLS_CC);
    17921837
    17931838            /* miss but compiling */
     
    18291874        newlycompiled = 0;
    18301875        xc_entry_init_key_php_entry(xce, h->opened_path ? h->opened_path : h->filename TSRMLS_CC);
    1831         xce->data.php = stored_php;
     1876        xce->entry.data.php = stored_php;
    18321877    }
    18331878    else {
     
    18381883
    18391884#ifdef HAVE_XCACHE_CONSTANT
    1840         xce->data.php->constinfos  = NULL;
    1841 #endif
    1842         xce->data.php->funcinfos   = NULL;
    1843         xce->data.php->classinfos  = NULL;
     1885        xce->entry.data.php->constinfos  = NULL;
     1886#endif
     1887        xce->entry.data.php->funcinfos   = NULL;
     1888        xce->entry.data.php->classinfos  = NULL;
    18441889#ifdef ZEND_ENGINE_2_1
    1845         xce->data.php->autoglobals = NULL;
    1846 #endif
    1847 
    1848         memset(&xce->data.php->op_array_info, 0, sizeof(xce->data.php->op_array_info));
     1890        xce->entry.data.php->autoglobals = NULL;
     1891#endif
     1892
     1893        memset(&xce->entry.data.php->op_array_info, 0, sizeof(xce->entry.data.php->op_array_info));
    18491894
    18501895        zend_try {
    1851             op_array = xc_compile_php(xce, xce->data.php, h, type TSRMLS_CC);
     1896            op_array = xc_compile_php(xce, xce->entry.data.php, h, type TSRMLS_CC);
    18521897        } zend_catch {
    18531898            catched = 1;
     
    18591904
    18601905        /* not cachable */
    1861         if (!xce->data.php->op_array) {
     1906        if (!xce->entry.data.php->op_array) {
    18621907            cache->compiling = 0;
    18631908            /* it's not cachable, but don't scare the users with high misses */
     
    18741919     * WARNING: this code is required to be after compile
    18751920     */
    1876     if (xce->inode) {
     1921    if (xce->file_inode) {
    18771922        const char *filename = h->opened_path ? h->opened_path : h->filename;
    1878         if (xce->name.str.val != filename) {
    1879             xce->name.str.val = (char *) filename;
    1880             xce->name.str.len = strlen(filename);
     1923        if (xce->entry.name.str.val != filename) {
     1924            xce->entry.name.str.val = (char *) filename;
     1925            xce->entry.name.str.len = strlen(filename);
    18811926        }
    18821927    }
     
    18901935        /* php_store */
    18911936        if (newlycompiled) {
    1892             stored_php = xc_php_store_dmz(xce->data.php TSRMLS_CC);
     1937            stored_php = xc_php_store_dmz(xce->entry.data.php TSRMLS_CC);
    18931938            if (!stored_php) {
    18941939                /* error */
     
    18981943        /* entry_store */
    18991944        xc_php_addref_dmz(stored_php);
    1900         stored_xce = xc_entry_store_dmz(xce TSRMLS_CC);
     1945        stored_xce = xc_entry_php_store_dmz(xce TSRMLS_CC);
    19011946        if (stored_xce) {
    1902             stored_xce->data.php = stored_php;
     1947            stored_xce->entry.data.php = stored_php;
    19031948        }
    19041949        else {
     
    19161961
    19171962    if (newlycompiled) {
    1918         xc_free_php(xce->data.php TSRMLS_CC);
     1963        xc_free_php(xce->entry.data.php TSRMLS_CC);
    19191964    }
    19201965
     
    19471992err_aftersandbox:
    19481993    if (newlycompiled) {
    1949         xc_free_php(xce->data.php TSRMLS_CC);
     1994        xc_free_php(xce->entry.data.php TSRMLS_CC);
    19501995        xc_sandbox_free(&sandbox, XC_NoInstall TSRMLS_CC);
    19511996    }
     
    19622007{
    19632008    zend_op_array *op_array;
    1964     xc_entry_t xce;
     2009    xc_entry_php_t xce;
    19652010    xc_entry_data_php_t php;
    19662011    const char *filename;
     
    19762021    /* {{{ entry_init_key */
    19772022    filename = h->opened_path ? h->opened_path : h->filename;
    1978     xce.data.php = &php;
     2023    xce.entry.data.php = &php;
    19792024    if (xc_entry_init_key_php(&xce, filename TSRMLS_CC) != SUCCESS) {
    19802025        TRACE("failed to init key for %s", filename);
     
    26562701{
    26572702    xc_entry_t xce, *stored_xce;
    2658     xc_entry_data_var_t var;
    26592703    zval *name;
    26602704    int found = 0;
     
    26682712        return;
    26692713    }
    2670     xce.data.var = &var;
    26712714    xc_entry_init_key_var(&xce, name TSRMLS_CC);
    26722715
     
    26762719            if (!VAR_ENTRY_EXPIRED(stored_xce)) {
    26772720                found = 1;
    2678                 xc_processor_restore_zval(return_value, stored_xce->data.var->value, stored_xce->data.var->have_references TSRMLS_CC);
     2721                xc_processor_restore_zval(return_value, stored_xce->data.var.value, stored_xce->data.var.have_references TSRMLS_CC);
    26792722                /* return */
    26802723                break;
     
    27002743{
    27012744    xc_entry_t xce, *stored_xce;
    2702     xc_entry_data_var_t var;
    27032745    zval *name;
    27042746    zval *value;
     
    27192761    }
    27202762
    2721     xce.data.var = &var;
    27222763    xc_entry_init_key_var(&xce, name TSRMLS_CC);
    27232764
     
    27272768            xc_entry_remove_dmz(stored_xce TSRMLS_CC);
    27282769        }
    2729         var.value = value;
     2770        xce.data.var.value = value;
    27302771        RETVAL_BOOL(xc_entry_store_dmz(&xce TSRMLS_CC) != NULL ? 1 : 0);
    27312772    } LEAVE_LOCK(xce.cache);
     
    27372778{
    27382779    xc_entry_t xce, *stored_xce;
    2739     xc_entry_data_var_t var;
    27402780    zval *name;
    27412781    int found = 0;
     
    27492789        return;
    27502790    }
    2751     xce.data.var = &var;
    27522791    xc_entry_init_key_var(&xce, name TSRMLS_CC);
    27532792
     
    27812820{
    27822821    xc_entry_t xce, *stored_xce;
    2783     xc_entry_data_var_t var;
    27842822    zval *name;
    27852823
     
    27922830        return;
    27932831    }
    2794     xce.data.var = &var;
    27952832    xc_entry_init_key_var(&xce, name TSRMLS_CC);
    27962833
     
    28432880{
    28442881    xc_entry_t xce, *stored_xce;
    2845     xc_entry_data_var_t var, *stored_var;
    28462882    zval *name;
    28472883    long count = 1;
     
    28642900    }
    28652901
    2866     xce.data.var = &var;
    28672902    xc_entry_init_key_var(&xce, name TSRMLS_CC);
    28682903
     
    28792914            else {
    28802915                /* do it in place */
    2881                 stored_var = stored_xce->data.var;
     2916                xc_entry_data_var_t *stored_var = &stored_xce->data.var;
    28822917                if (Z_TYPE_P(stored_var->value) == IS_LONG) {
    28832918                    zval *zv;
     
    28952930                else {
    28962931                    TRACE("%s", "incdec: notlong");
    2897                     xc_processor_restore_zval(&oldzval, stored_xce->data.var->value, stored_xce->data.var->have_references TSRMLS_CC);
     2932                    xc_processor_restore_zval(&oldzval, stored_xce->data.var.value, stored_xce->data.var.have_references TSRMLS_CC);
    28982933                    convert_to_long(&oldzval);
    28992934                    value = Z_LVAL(oldzval);
     
    29082943        value += (inc == 1 ? count : - count);
    29092944        RETVAL_LONG(value);
    2910         var.value = return_value;
     2945        stored_xce->data.var.value = return_value;
    29112946
    29122947        if (stored_xce) {
  • trunk/xcache.h

    r846 r851  
    262262    zend_ulong errors;
    263263    xc_lock_t  *lck;
    264     xc_shm_t   *shm; /* to which shm contains us */
    265     xc_mem_t   *mem; /* to which mem contains us */
     264    xc_shm_t   *shm; /* which shm contains us */
     265    xc_mem_t   *mem; /* which mem contains us */
    266266
    267267    xc_entry_t **entries;
     
    369369/* {{{ xc_entry_data_php_t */
    370370struct _xc_entry_data_php_t {
    371     xc_hash_value_t hvalue; /* hash of md5 */
     371    xc_hash_value_t      hvalue;
    372372    xc_entry_data_php_t *next;
    373     xc_cache_t *cache;      /* which cache it's on */
     373    xc_cache_t          *cache;
    374374
    375375    xc_md5sum_t md5;        /* md5sum of the source */
    376376    zend_ulong  refcount;   /* count of entries referencing to this data */
    377377
    378     size_t sourcesize;
     378    size_t     file_size;
    379379    zend_ulong hits;        /* hits of this php */
    380380    size_t     size;
     
    420420/* {{{ xc_entry_t */
    421421struct _xc_entry_t {
     422    xc_hash_value_t hvalue;
     423    xc_entry_t     *next;
     424    xc_cache_t     *cache;
     425
    422426    xc_entry_type_t type;
    423     xc_hash_value_t hvalue;
    424     xc_entry_t *next;
    425     xc_cache_t *cache;      /* which cache it's on */
    426 
    427     size_t     size;
    428     zend_ulong refcount;    /* count of instances holding this entry */
     427    size_t          size;
     428
     429    time_t     ctime;           /* creation ctime of this entry */
     430    time_t     atime;           /*   access atime of this entry */
     431    time_t     dtime;           /*  deletion time of this entry */
    429432    zend_ulong hits;
    430     time_t     ctime;           /* the ctime of this entry */
    431     time_t     atime;           /* the atime of this entry */
    432     time_t     dtime;           /* the deletion time of this entry */
    433     long       ttl;             /* ttl of time entry, var only */
     433    long       ttl;
    434434
    435435#ifdef IS_UNICODE
     
    440440    union {
    441441        xc_entry_data_php_t *php;
    442         xc_entry_data_var_t *var;
     442        xc_entry_data_var_t var;
    443443    } data;
    444 
    445     time_t mtime;           /* the mtime of origin source file */
     444};
     445
     446typedef struct {
     447    xc_entry_t entry;
     448
     449    zend_ulong refcount;    /* count of php instances holding this entry */
     450    time_t file_mtime;
    446451#ifdef HAVE_INODE
    447     int device;             /* the filesystem device */
    448     int inode;              /* the filesystem inode */
    449 #endif
    450 
    451     /* php only */
     452    int file_device;
     453    int file_inode;
     454#endif
     455
    452456    int    filepath_len;
    453457    ZEND_24(const) char *filepath;
     
    455459    char  *dirpath;
    456460#ifdef IS_UNICODE
     461    int    ufilepath_len;
    457462    UChar *ufilepath;
    458     int    ufilepath_len;
     463    int    udirpath_len;
    459464    UChar *udirpath;
    460     int    udirpath_len;
    461 #endif
    462 
    463 };
     465#endif
     466} xc_entry_php_t;
    464467/* }}} */
    465468
     
    480483/* }}} */
    481484void xc_gc_add_op_array(xc_gc_op_array_t *gc_op_array TSRMLS_DC);
    482 void xc_fix_op_array_info(const xc_entry_t *xce, const xc_entry_data_php_t *php, zend_op_array *op_array, int shallow_copy, const xc_op_array_info_t *op_array_info TSRMLS_DC);
     485void xc_fix_op_array_info(const xc_entry_php_t *xce, const xc_entry_data_php_t *php, zend_op_array *op_array, int shallow_copy, const xc_op_array_info_t *op_array_info TSRMLS_DC);
    483486
    484487#endif /* __XCACHE_H */
Note: See TracChangeset for help on using the changeset viewer.