Changeset 2647
- Timestamp:
- 10/12/07 15:59:51 (1 year ago)
- Files:
-
- trunk/lib/common/tango/core/Memory.d (modified) (2 diffs)
- trunk/lib/gc/basic/gc.d (modified) (1 diff)
- trunk/lib/gc/basic/gcx.d (modified) (4 diffs)
- trunk/lib/gc/stub/gc.d (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/common/tango/core/Memory.d
r2404 r2647 29 29 extern (C) void gc_free( void* p ); 30 30 31 extern (C) void* gc_addrOf( void* p ); 31 32 extern (C) size_t gc_sizeOf( void* p ); 32 33 … … 277 278 278 279 /** 280 * Returns the base address of the memory block containing p. This value 281 * is useful to determine whether p is an interior pointer, and the result 282 * may be passed to routines such as sizeOf which may otherwise fail. If p 283 * references memory not originally allocated by this garbage collector, if 284 * p is null, or if the garbage collector does not support this operation, 285 * null will be returned. 286 * 287 * Params: 288 * p = A pointer to the root or the interior of a valid memory block or to 289 * null. 290 * 291 * Returns: 292 * The base address of the memory block referenced by p or null on error. 293 */ 294 static void* addrOf( void* p ) 295 { 296 return gc_addrOf( p ); 297 } 298 299 300 /** 279 301 * Returns the true size of the memory block referenced by p. This value 280 302 * represents the maximum number of bytes for which a call to realloc may trunk/lib/gc/basic/gc.d
r2464 r2647 127 127 } 128 128 129 extern (C) void* gc_addrOf( void* p ) 130 { 131 return _gc.addrOf( p ); 132 } 133 129 134 extern (C) size_t gc_sizeOf( void* p ) 130 135 { trunk/lib/gc/basic/gcx.d
r2463 r2647 866 866 867 867 /** 868 * Determine the base address of the block containing p. If p is not a gc 869 * allocated pointer, return null. 870 */ 871 void* addrOf(void *p) 872 { 873 if (!p) 874 { 875 return null; 876 } 877 878 if (!thread_needLock()) 879 { 880 return addrOfNoSync(p); 881 } 882 else synchronized (gcLock) 883 { 884 return addrOfNoSync(p); 885 } 886 } 887 888 889 // 890 // 891 // 892 void* addrOfNoSync(void *p) 893 { 894 if (!p) 895 { 896 return null; 897 } 898 899 return gcx.findBase(p); 900 } 901 902 903 /** 868 904 * Determine the allocated size of pointer p. If p is an interior pointer 869 905 * or not a gc allocated pointer, return 0. … … 1527 1563 break; 1528 1564 } 1565 } 1566 } 1567 return null; 1568 } 1569 1570 1571 /** 1572 * Find base address of block containing pointer p. 1573 * Returns null if not a gc'd pointer 1574 */ 1575 void* findBase(void *p) 1576 { 1577 Pool *pool; 1578 1579 pool = findPool(p); 1580 if (pool) 1581 { 1582 size_t offset = cast(size_t)(p - pool.baseAddr); 1583 uint pn = offset / PAGESIZE; 1584 Bins bin = cast(Bins)pool.pagetable[pn]; 1585 1586 // Adjust bit to be at start of allocated memory block 1587 if (bin <= B_PAGE) 1588 { 1589 return pool.baseAddr + (offset & notbinsize[bin]); 1590 } 1591 else if (bin == B_PAGEPLUS) 1592 { 1593 do 1594 { --pn, offset -= PAGESIZE; 1595 } while (cast(Bins)pool.pagetable[pn] == B_PAGEPLUS); 1596 1597 return pool.baseAddr + (offset & (offset.max ^ (PAGESIZE-1))); 1598 } 1599 else 1600 { 1601 // we are in a B_FREE or B_UNCOMMITTED page 1602 return null; 1529 1603 } 1530 1604 } … … 1836 1910 if (pool) 1837 1911 { 1838 size_t offset = cast( uint)(p - pool.baseAddr);1912 size_t offset = cast(size_t)(p - pool.baseAddr); 1839 1913 uint biti; 1840 1914 uint pn = offset / PAGESIZE; … … 2405 2479 pool = findPool(p); 2406 2480 assert(pool); 2407 size_t offset = cast( uint)(p - pool.baseAddr);2481 size_t offset = cast(size_t)(p - pool.baseAddr); 2408 2482 uint biti; 2409 2483 uint pn = offset / PAGESIZE; trunk/lib/gc/stub/gc.d
r2494 r2647 114 114 } 115 115 116 extern (C) void* gc_addrOf( void* p ) 117 { 118 return null; 119 } 120 116 121 extern (C) size_t gc_sizeOf( void* p ) 117 122 {












