Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Changeset 2648

Show
Ignore:
Timestamp:
10/12/07 16:54:18 (1 year ago)
Author:
sean
Message:

Added gc_query(p) to obtain aggregate info about the block containing p. Related to ticket #557.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/common/tango/core/Memory.d

    r2647 r2648  
    2929    extern (C) void   gc_free( void* p ); 
    3030 
    31     extern (C) void*  gc_addrOf( void* p ); 
    32     extern (C) size_t gc_sizeOf( void* p ); 
     31    extern (C) void*   gc_addrOf( void* p ); 
     32    extern (C) size_t  gc_sizeOf( void* p ); 
     33 
     34    struct BlkInfo_ 
     35    { 
     36        void*  base; 
     37        size_t size; 
     38        uint   attr; 
     39    } 
     40 
     41    extern (C) BlkInfo_ gc_query( void* p ); 
    3342 
    3443    extern (C) void gc_addRoot( void* p ); 
     
    93102        NO_MOVE  = 0b0000_0100  /// Do not move this memory block on collect. 
    94103    } 
     104 
     105 
     106    /** 
     107     * Contains aggregate information about a block of managed memory.  The 
     108     * purpose of this struct is to support a more efficient query style in 
     109     * instances where detailed information is needed. 
     110     * 
     111     * base = A pointer to the base of the block in question. 
     112     * size = The size of the block, calculated from base. 
     113     * attr = Attribute bits set on the memory block. 
     114     */ 
     115    alias BlkInfo_ BlkInfo; 
    95116 
    96117 
     
    318339 
    319340    /** 
     341     * Returns aggregate information about the memory block containing p.  If p 
     342     * references memory not originally allocated by this garbage collector, if 
     343     * p is null, or if the garbage collector does not support this operation, 
     344     * BlkInfo.init will be returned.  Typically, support for this operation 
     345     * is dependent on support for addrOf. 
     346     * 
     347     * Params: 
     348     *  p = A pointer to the root or the interior of a valid memory block or to 
     349     *      null. 
     350     * 
     351     * Returns: 
     352     *  Information regarding the memory block referenced by p or BlkInfo.init 
     353     *  on error. 
     354     */ 
     355    static BlkInfo query( void* p ) 
     356    { 
     357        return gc_query( p ); 
     358    } 
     359 
     360 
     361    /** 
    320362     * Adds the memory address referenced by p to an internal list of roots to 
    321363     * be scanned during a collection.  If p is null, no operation is 
  • trunk/lib/gc/basic/gc.d

    r2647 r2648  
    137137} 
    138138 
     139extern (C) BlkInfo gc_query( void* p ) 
     140{ 
     141    return _gc.query( p ); 
     142} 
     143 
    139144extern (C) void gc_addRoot( void* p ) 
    140145{ 
  • trunk/lib/gc/basic/gcx.d

    r2647 r2648  
    7575        NO_MOVE  = 0b0000_0100, 
    7676        ALL_BITS = 0b1111_1111 
     77    } 
     78 
     79    struct BlkInfo 
     80    { 
     81        void*  base; 
     82        size_t size; 
     83        uint   attr; 
    7784    } 
    7885 
     
    971978 
    972979    /** 
     980     * Determine the base address of the block containing p.  If p is not a gc 
     981     * allocated pointer, return null. 
     982     */ 
     983    BlkInfo query(void *p) 
     984    { 
     985        if (!p) 
     986        { 
     987            BlkInfo i; 
     988            return  i; 
     989        } 
     990 
     991        if (!thread_needLock()) 
     992        { 
     993            return queryNoSync(p); 
     994        } 
     995        else synchronized (gcLock) 
     996        { 
     997            return queryNoSync(p); 
     998        } 
     999    } 
     1000 
     1001 
     1002    // 
     1003    // 
     1004    // 
     1005    BlkInfo queryNoSync(void *p) 
     1006    { 
     1007        if (!p) 
     1008        { 
     1009            BlkInfo i; 
     1010            return  i; 
     1011        } 
     1012 
     1013        return gcx.getInfo(p); 
     1014    } 
     1015 
     1016 
     1017    /** 
    9731018     * Verify that pointer p: 
    9741019     *  1) belongs to this memory pool 
     
    16401685        } 
    16411686        return size; 
     1687    } 
     1688 
     1689 
     1690    /** 
     1691     * 
     1692     */ 
     1693    BlkInfo getInfo(void* p) 
     1694    { 
     1695        Pool *pool; 
     1696        BlkInfo info; 
     1697 
     1698        pool = findPool(p); 
     1699        if (pool) 
     1700        { 
     1701            size_t offset = cast(size_t)(p - pool.baseAddr); 
     1702            uint pn = offset / PAGESIZE; 
     1703            Bins bin = cast(Bins)pool.pagetable[pn]; 
     1704 
     1705            //////////////////////////////////////////////////////////////////// 
     1706            // findAddr 
     1707            //////////////////////////////////////////////////////////////////// 
     1708 
     1709            if (bin <= B_PAGE) 
     1710            { 
     1711                info.base = pool.baseAddr + (offset & notbinsize[bin]); 
     1712            } 
     1713            else if (bin == B_PAGEPLUS) 
     1714            { 
     1715                do 
     1716                {   --pn, offset -= PAGESIZE; 
     1717                } while (cast(Bins)pool.pagetable[pn] == B_PAGEPLUS); 
     1718 
     1719                info.base = pool.baseAddr + (offset & (offset.max ^ (PAGESIZE-1))); 
     1720 
     1721                // fix bin for use by size calc below 
     1722                bin = cast(Bins)pool.pagetable[pn]; 
     1723            } 
     1724 
     1725            //////////////////////////////////////////////////////////////////// 
     1726            // findSize 
     1727            //////////////////////////////////////////////////////////////////// 
     1728 
     1729            info.size = binsize[bin]; 
     1730            if (bin == B_PAGE) 
     1731            {   uint npages = pool.ncommitted; 
     1732                ubyte* pt; 
     1733                uint i; 
     1734 
     1735                pt = &pool.pagetable[0]; 
     1736                for (i = pn + 1; i < npages; i++) 
     1737                { 
     1738                    if (pt[i] != B_PAGEPLUS) 
     1739                        break; 
     1740                } 
     1741                info.size = (i - pn) * PAGESIZE; 
     1742            } 
     1743 
     1744            //////////////////////////////////////////////////////////////////// 
     1745            // getBits 
     1746            //////////////////////////////////////////////////////////////////// 
     1747 
     1748            info.attr = getBits(pool, offset / 16); 
     1749        } 
     1750        return info; 
    16421751    } 
    16431752 
  • trunk/lib/gc/stub/gc.d

    r2647 r2648  
    3030    } 
    3131 
     32    struct BlkInfo 
     33    { 
     34        void*  base; 
     35        size_t size; 
     36        uint   attr; 
     37    } 
    3238 
    3339    extern (C) void thread_init(); 
     
    124130} 
    125131 
     132extern (C) BlkInfo gc_query( void* p ) 
     133{ 
     134    return BlkInfo.init 
     135} 
     136 
    126137extern (C) void gc_addRoot( void* p ) 
    127138{