????? ???? ??? ???????? ?? ??????? ???? ???? ??????? ??????? ??????? ????? ?? ???? ???? ???????. ??? ???, ????? ????, ?????? ?????? ?????? ??????. ?????? ?????? ???? ????? ???? ?????? ??? ??????? ????? LD_PRELOAD ????-GC ???? ??? ?????? ?????? ?????. ??? ??? ???? ????? ?? Solaris (SPARC).
???????? ???? ??? 32-bit ?????? ????, ?? ?? ????? ???? ????? 64-bitness ?????? ????? ????:
./configure --enable-gc-debug --enable-redirect-malloc --enable-cplusplus CXXFLAGS='-m64' CFLAGS='-m64'
??, of course
make
??? ?????? ??????. ??? ???? ????? ????? ????? ???? ??????? 10 ????? ??????, ???? ???? ?????? ???, ??? ????? ??? ??? ?????? ?? GC ?? ??? ????? ????? ????? ????? ???? ????? ?????? ????? ??????:
#include <stdio.h> #include <stdlib.h> #include <unistd.h> int main(int argc, const char **argv) { printf("Inside main(), argc = %d...\n", argc); int limit = 1000000; if (argv[1] != NULL) limit = atoi(argv[1]); int amount = 0; int amount_total = 0; int n_allocs = 0; // Feed srand with the seed value srand (time(NULL)); while (1) { // We don't want to eat the entire memory :) if (amount_total >= limit) { printf("Amount limit %d exceeded, total amt = %d, # of allocs = %d. Stop.\n", limit, amount_total, n_allocs); break; } amount = rand() % limit; usleep(100000); printf("\nAllocating another block of size %d...\n", amount); char * p = new char[amount]; n_allocs++; p[0] = 0xAB; printf("Writing value to address 0x%x...\n", ?? '); // Stupid condition :) bool b_delete = (amount % 2 == 0); if (b_delete) { printf(" ! Amount %d is even, deleting pointer...\n", amount); delete p; } else amount_total += amount; } }
????? ?? ????????? ????? ?? GC ???? ????? - while memory usage exhibits sustainable growth without it...
raiks@solaris11_sparc$: ./a.out raiks@solaris11_sparc$: prstat -c -p $(pgrep a.out) 30 5611 raiks 4696K 3304K sleep 56 0 0:00:00 0.0% a.out/1 5611 raiks 7256K 5864K sleep 56 0 0:00:00 0.0% a.out/1 5611 raiks 11M 10M sleep 56 0 0:00:00 0.0% a.out/1 5611 raiks 15M 14M sleep 56 0 0:00:00 0.0% a.out/1 5611 raiks 15M 14M sleep 56 0 0:00:00 0.0% a.out/1 5611 raiks 19M 18M sleep 56 0 0:00:00 0.0% a.out/1 5611 raiks 19M 19M sleep 56 0 0:00:00 0.0% a.out/1 <...>
... ?? ???? ???? ???? ?????? ????? ????? GC:
raiks@solaris11_sparc$: (export LD_PRELOAD_64=./gc/.libs/libgc.so;\ export GC_PRINT_STATS=1;./a.out) raiks@solaris11_sparc$: prstat -c -p $(pgrep a.out) 30 9389 raiks 5480K 4112K sleep 59 0 0:00:00 0.0% a.out/1 9389 raiks 5656K 4288K sleep 59 0 0:00:00 0.0% a.out/1 9389 raiks 5656K 4288K sleep 59 0 0:00:00 0.0% a.out/1 9389 raiks 5656K 4288K sleep 59 0 0:00:00 0.0% a.out/1 9389 raiks 5720K 4352K sleep 59 0 0:00:00 0.0% a.out/1 9389 raiks 5720K 4352K sleep 59 0 0:00:00 0.0% a.out/1 <...>
?? ??? ?? ????? ?? GC:
--> Marking for collection 20 after 373280 allocated bytes Collection 19 reclaimed 372240 bytes ---> heapsize = 606208 bytes World-stopped marking took 10 msecs (3 in average) Heap contains 158592 pointer-containing + 0 pointer-free reachable bytes 0 finalization table entries; 0 disappearing links alive 0 objects are eligible for immediate finalization; 0 links cleared Finalize plus initiate sweep took 0 + 0 msecs Complete collection took 10 msecs Allocating another block of size 26417... Allocating another block of size 3197... Allocating another block of size 29137... <...> Initiating full world-stop collection!
GC_PRINT_STATS ???? ???? ?????? ??????????. ??? ????? ?????, ??? ????? ?? ?? ??????? subshell ??? ??? ?? ???? GC ?????? ?????? ?????????? ???? ?? ????? ???? ????? ?????? ??????? :)
???? ?? ?????? GC_FIND_LEAK variable; ????? ?? GC ???? ??? ???? ????? ??? ????? ??? ???:
kptkon1@fragmkondappd5$: (export LD_PRELOAD_64=./gc/.libs/libgc.so;\ export GC_FIND_LEAK=1;./a.out 100000) Leaked composite object at ffffffff7e313830 (unknown:0, sz=1911, NORMAL) Leaked composite object at ffffffff7e20b030 (unknown:0, sz=23779, NORMAL) Leaked composite object at ffffffff7e206030 (unknown:0, sz=18767, NORMAL) <...>
? '?: ????? ????? ??? ????? ??? DBX - ?? ???? ??? ?? ???? (?? ??):
kptkon1@fragmkondappd5$: dbx (dbx) export LD_PRELOAD_64=./gc/.libs/libgc.so (dbx) debug a.out Reading libgc.so.1.0.3 Reading libdl.so.1 (dbx) run Running: a.out (process id 25017) signal SEGV (no mapping at the fault address) (fault address is just beyond end of stack) in GC_find_limit_with_bound at 0xffffffff7f42222c 0xffffffff7f42222c: GC_find_limit_with_bound+0x0134: ldsb [%l0], %l0