Changeset 518
- Timestamp:
- 01/18/11 07:04:30 (14 years ago)
- Files:
-
- trunk/src/gc/gcx.d (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/gc/gcx.d
r517 r518 2204 2204 uint changes = 0; 2205 2205 2206 2206 //printf("marking range: %p -> %p\n", pbot, ptop); 2207 2207 for (; p1 < p2; p1++) 2208 2208 { 2209 2209 auto p = cast(byte *)(*p1); 2210 2210 2211 2211 //if (log) debug(PRINTF) printf("\tmark %p\n", p); 2212 2212 if (p >= minAddr && p < maxAddr) 2213 2213 { 2214 if ((cast(size_t)p & ~ (PAGESIZE-1)) == pcache)2214 if ((cast(size_t)p & ~cast(size_t)(PAGESIZE-1)) == pcache) 2215 2215 continue; 2216 2216 2217 2217 auto pool = findPool(p); 2218 2218 if (pool) 2219 2219 { 2220 2220 size_t offset = cast(size_t)(p - pool.baseAddr); 2221 2221 size_t biti = void; 2222 2222 size_t pn = offset / PAGESIZE; 2223 2223 Bins bin = cast(Bins)pool.pagetable[pn]; 2224 2224 … … 2228 2228 if (bin < B_PAGE) 2229 2229 { 2230 2230 biti = (offset & notbinsize[bin]) >> 4; 2231 2231 //debug(PRINTF) printf("\t\tbiti = x%x\n", biti); 2232 2232 } 2233 2233 else if (bin == B_PAGE) 2234 2234 { 2235 2235 biti = (offset & notbinsize[bin]) >> 4; 2236 2236 //debug(PRINTF) printf("\t\tbiti = x%x\n", biti); 2237 2237 2238 pcache = cast(size_t)p & ~ (PAGESIZE-1);2238 pcache = cast(size_t)p & ~cast(size_t)(PAGESIZE-1); 2239 2239 } 2240 2240 else if (bin == B_PAGEPLUS) 2241 2241 { 2242 2242 do 2243 2243 { --pn; 2244 2244 } while (cast(Bins)pool.pagetable[pn] == B_PAGEPLUS); 2245 2245 biti = pn * (PAGESIZE / 16); 2246 2246 2247 pcache = cast(size_t)p & ~ (PAGESIZE-1);2247 pcache = cast(size_t)p & ~cast(size_t)(PAGESIZE-1); 2248 2248 } 2249 2249 else 2250 2250 { 2251 2251 // Don't mark bits in B_FREE or B_UNCOMMITTED pages 2252 2252 continue; 2253 2253 } 2254 2254 2255 2255 //debug(PRINTF) printf("\t\tmark(x%x) = %d\n", biti, pool.mark.test(biti)); 2256 2256 if (!pool.mark.testSet(biti)) 2257 2257 { … … 2445 2445 while (anychanges) 2446 2446 { 2447 2447 debug(COLLECT_PRINTF) printf("\t\tpass\n"); 2448 2448 anychanges = 0; 2449 2449 for (n = 0; n < npools; n++) 2450 2450 { 2451 2451 pool = pooltable[n]; 2452 2452 2453 2453 auto bbase = pool.scan.base(); 2454 2454 auto btop = bbase + pool.scan.nwords; 2455 //printf("\t\tn = %d, bbase = %p, btop = %p\n", n, bbase, btop); 2455 2456 for (auto b = bbase; b < btop;) 2456 2457 { 2457 2458 auto bitm = *b; 2458 2459 if (!bitm) 2459 2460 { b++; 2460 2461 continue; 2461 2462 } 2462 2463 *b = 0; 2463 2464 2464 auto o = pool.baseAddr + (b - bbase) * 32* 16;2465 auto o = pool.baseAddr + (b - bbase) * (typeof(bitm).sizeof*8) * 16; 2465 2466 if (!(bitm & 0xFFFF)) 2466 2467 { 2467 2468 bitm >>= 16; 2468 2469 o += 16 * 16; 2469 2470 } 2470 2471 if (!(bitm & 0xFF)) 2471 2472 { 2472 2473 bitm >>= 8; 2473 2474 o += 8 * 16; 2474 2475 } … … 2805 2806 GC.file = null; 2806 2807 2807 2808 current.push(log); 2808 2809 //debug(PRINTF) printf("-log_malloc()\n"); 2809 2810 } 2810 2811 2811 2812 2812 2813 void log_free(void *p) 2813 2814 { 2814 2815 //debug(PRINTF) printf("+log_free(%p)\n", p); 2815 size_t i; 2816 2817 i = current.find(p); 2816 auto i = current.find(p); 2818 2817 if (i == OPFAIL) 2819 2818 { 2820 2819 debug(PRINTF) printf("free'ing unallocated memory %p\n", p); 2821 2820 } 2822 2821 else 2823 2822 current.remove(i); 2824 2823 //debug(PRINTF) printf("-log_free()\n"); 2825 2824 } 2826 2825 2827 2826 2828 2827 void log_collect() 2829 2828 { 2830 2829 //debug(PRINTF) printf("+log_collect()\n"); 2831 2830 // Print everything in current that is not in prev 2832 2831 2833 2832 debug(PRINTF) printf("New pointers this cycle: --------------------------------\n"); 2834 2833 size_t used = 0; 2835 2834 for (size_t i = 0; i < current.dim; i++) 2836 2835 { 2837 size_t j; 2838 2839 j = prev.find(current.data[i].p); 2836 auto j = prev.find(current.data[i].p); 2840 2837 if (j == OPFAIL) 2841 2838 current.data[i].print(); 2842 2839 else 2843 2840 used++; 2844 2841 } 2845 2842 2846 2843 debug(PRINTF) printf("All roots this cycle: --------------------------------\n"); 2847 2844 for (size_t i = 0; i < current.dim; i++) 2848 2845 { 2849 void *p; 2850 size_t j; 2851 2852 p = current.data[i].p; 2846 void* p = current.data[i].p; 2853 2847 if (!findPool(current.data[i].parent)) 2854 2848 { 2855 j = prev.find(current.data[i].p);2849 auto j = prev.find(current.data[i].p); 2856 2850 if (j == OPFAIL) 2857 2851 debug(PRINTF) printf("N"); 2858 2852 else 2859 2853 debug(PRINTF) printf(" ");; 2860 2854 current.data[i].print(); 2861 2855 } 2862 2856 } 2863 2857 2864 2858 debug(PRINTF) printf("Used = %d-------------------------------------------------\n", used); 2865 2859 prev.copy(¤t); 2866 2860 2867 2861 debug(PRINTF) printf("-log_collect()\n"); 2868 2862 } 2869 2863 2870 2864 2871 2865 void log_parent(void *p, void *parent) 2872 2866 { 2873 2867 //debug(PRINTF) printf("+log_parent()\n"); 2874 size_t i; 2875 2876 i = current.find(p); 2868 auto i = current.find(p); 2877 2869 if (i == OPFAIL) 2878 2870 { 2879 2871 debug(PRINTF) printf("parent'ing unallocated memory %p, parent = %p\n", p, parent); 2880 2872 Pool *pool; 2881 2873 pool = findPool(p); 2882 2874 assert(pool); 2883 2875 size_t offset = cast(size_t)(p - pool.baseAddr); 2884 2876 size_t biti; 2885 2877 size_t pn = offset / PAGESIZE; 2886 2878 Bins bin = cast(Bins)pool.pagetable[pn];
