 |
Changeset 2648
- 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
| r2647 |
r2648 |
|
| 29 | 29 | extern (C) void gc_free( void* p ); |
|---|
| 30 | 30 | |
|---|
| 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 ); |
|---|
| 33 | 42 | |
|---|
| 34 | 43 | extern (C) void gc_addRoot( void* p ); |
|---|
| … | … | |
| 93 | 102 | NO_MOVE = 0b0000_0100 /// Do not move this memory block on collect. |
|---|
| 94 | 103 | } |
|---|
| | 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; |
|---|
| 95 | 116 | |
|---|
| 96 | 117 | |
|---|
| … | … | |
| 318 | 339 | |
|---|
| 319 | 340 | /** |
|---|
| | 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 | /** |
|---|
| 320 | 362 | * Adds the memory address referenced by p to an internal list of roots to |
|---|
| 321 | 363 | * be scanned during a collection. If p is null, no operation is |
|---|
| r2647 |
r2648 |
|
| 137 | 137 | } |
|---|
| 138 | 138 | |
|---|
| | 139 | extern (C) BlkInfo gc_query( void* p ) |
|---|
| | 140 | { |
|---|
| | 141 | return _gc.query( p ); |
|---|
| | 142 | } |
|---|
| | 143 | |
|---|
| 139 | 144 | extern (C) void gc_addRoot( void* p ) |
|---|
| 140 | 145 | { |
|---|
| r2647 |
r2648 |
|
| 75 | 75 | NO_MOVE = 0b0000_0100, |
|---|
| 76 | 76 | ALL_BITS = 0b1111_1111 |
|---|
| | 77 | } |
|---|
| | 78 | |
|---|
| | 79 | struct BlkInfo |
|---|
| | 80 | { |
|---|
| | 81 | void* base; |
|---|
| | 82 | size_t size; |
|---|
| | 83 | uint attr; |
|---|
| 77 | 84 | } |
|---|
| 78 | 85 | |
|---|
| … | … | |
| 971 | 978 | |
|---|
| 972 | 979 | /** |
|---|
| | 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 | /** |
|---|
| 973 | 1018 | * Verify that pointer p: |
|---|
| 974 | 1019 | * 1) belongs to this memory pool |
|---|
| … | … | |
| 1640 | 1685 | } |
|---|
| 1641 | 1686 | 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; |
|---|
| 1642 | 1751 | } |
|---|
| 1643 | 1752 | |
|---|
| r2647 |
r2648 |
|
| 30 | 30 | } |
|---|
| 31 | 31 | |
|---|
| | 32 | struct BlkInfo |
|---|
| | 33 | { |
|---|
| | 34 | void* base; |
|---|
| | 35 | size_t size; |
|---|
| | 36 | uint attr; |
|---|
| | 37 | } |
|---|
| 32 | 38 | |
|---|
| 33 | 39 | extern (C) void thread_init(); |
|---|
| … | … | |
| 124 | 130 | } |
|---|
| 125 | 131 | |
|---|
| | 132 | extern (C) BlkInfo gc_query( void* p ) |
|---|
| | 133 | { |
|---|
| | 134 | return BlkInfo.init |
|---|
| | 135 | } |
|---|
| | 136 | |
|---|
| 126 | 137 | extern (C) void gc_addRoot( void* p ) |
|---|
| 127 | 138 | { |
|---|
Download in other formats:
|
 |
 |
|
 |
Copyright © 2006-2008 Tango. All Rights Reserved. | Page Width:
Static or
Dynamic