[BACK]Return to gc.texi CVS log [TXT][DIR] Up to [local] / OpenXM / src / asir-doc / int-parts

Annotation of OpenXM/src/asir-doc/int-parts/gc.texi, Revision 1.3

1.3     ! noro        1: @comment $OpenXM: OpenXM/src/asir-doc/int-parts/gc.texi,v 1.2 2003/04/19 10:36:28 noro Exp $
1.2       noro        2: \JP @chapter $B%a%b%j4IM}(B
                      3: \EG @chapter Memory management
1.1       noro        4:
1.2       noro        5: \JP @section $B%a%b%j4IM}5!9=(B
                      6: \EG @section Machinery for memory management
1.1       noro        7:
1.2       noro        8: \BJP
1.1       noro        9: @code{risa} $B$K$*$1$k%a%b%j4IM}$O(B, [Boehm,Weiser] $B$K$h$k$b$N$rMQ$$$F$$$k(B.
                     10: $B$3$N%a%b%j4IM}5!9=$NFCD'$O(B, $B%?%0IU$1$rI,MW$H$;$:(B, $B<+F0E*$K%,!<%Y%C%8%3%l(B
                     11: $B%/%7%g%s(B(GC) $B$r9T$J$&$3$H$G$"$k(B. $B=>$C$F%f!<%6$OI,MW$JNN0h$r<h$j$C$Q$J$7(B
                     12: $B$K$7$F$h$$(B. $B7gE@$H$7$F$O(B, $B0l2s$N(B GC $B$G$9$Y$F$N%,!<%Y%C%8$r2s<}$G$-$k$H$O(B
                     13: $B$+$.$i$J$$$3$H$H(B, $B%3%s%Q%/%7%g%s$r9T$J$o$J$$$3$H$G$"$k$,(B, $B<BMQ>e==J,$J5!(B
                     14: $BG=$r;}$D(B. $B%a%b%j3d$jEv$F4o$K8=$l$k%^%/%m$O$9$Y$F$3$N%a%b%j4IM}$N$b$H$G%a(B
                     15: $B%b%j$N3d$jEv$F$r9T$J$C$F$$$k(B. GC $B$O(B, $B$=$N;~E@$K$*$1$k(B, $B%9%?%C%/(B, $B%l%8%9(B
                     16: $B%?(B, $B@EE*NN0h$+$i%^!<%-%s%0$r;O$a(B, $B$3$l$K$h$jE~C#$G$-$J$$NN0h$r$9$Y$F2s<}(B
                     17: $B$9$k(B. $B%3%s%Q%$%i$N:GE,2=$K$h$j(B, $B:G=iNN0h$N@hF,$r;X$7$F$$$?%]%$%s%?$,(B, $BNN(B
                     18: $B0h$NFbIt$r;X$7$F$$$k>l9g$K$b(B, GC $B@5$7$/$=$NNN0h$,;HMQCf$HH=CG$9$k(B.
                     19:
                     20: $BCm0U$9$Y$-$3$H$O(B, $BDL>o$N(B @code{malloc()} $B$K$h$j3d$jEv$F$i$l$?NN0hFb$O%9(B
                     21: $B%-%c%s$5$l$J$$$3$H$G$"$k(B. $B$h$C$F(B, @code{malloc()} $B$O(B, $B$=$NB>$N(B C $B$N%i%$(B
                     22: $B%V%i%j$NCf$+$i8F$P$l$k>l9g$r=|$$$F;HMQ$OHr$1$J$1$l$P$J$i$J$$(B. $B$^$?(B, $B0l$D(B
                     23: $B$NNN0h$O(B, $BJ#?t$NNN0h$+$i;2>H$5$l$F$$$k2DG=@-$,$"$k$?$a(B, $B%f!<%6$,3+J|$9$k(B
                     24: $B$3$H$O4m81$G$"$k(B. $B$?$@$7(B, $B:n6HMQ$N%P%C%U%!$J$I(B, $BL@$i$+$KB>$+$i$N;2>H$,$J(B
                     25: $B$$$b$N$K4X$7$F$O3+J|$7$F9=$o$J$$(B. $B%a%b%j4IM}4X78$N<g$JH!?t$O<!$NDL$j(B.
1.2       noro       26: \E
                     27: \BEG
                     28: \E
1.1       noro       29:
1.2       noro       30: \BJP
1.1       noro       31: @example
                     32: void GC_init()
                     33: $B=i4|2=%k!<%A%s(B. $B5/F0;~$K<B9T$9$k(B.
                     34:
                     35: void *GC_malloc(int n)
                     36: n bytes $B$NNN0h$r3d$jEv$F$k(B. $BNN0h$O(B 0 $B$G=i4|2=$5$l$k(B.
                     37:
                     38: void *GC_malloc_atomic(int n)
                     39: $B%]%$%s%?$r4^$`$3$H$,$J$$$HJ]>Z$5$l$k(B n bytes $B$NNN0h$r3d$jEv$F$k(B.
                     40:
                     41: GC_free(void *p)
                     42: p $B$N;X$9NN0h$r3+J|$9$k(B. Risa $B$G$O(B, $B$"$kNN0h$,$I$3$+$i$I$N0L;X$5$l$F$$$k(B
                     43: $B$+0lHL$K$OH=CG$G$-$J$$$N$G(B, $BDL>o$O$3$N4X?t$,;HMQ$5$l$k$3$H$O$J$$(B.
                     44: $B4X?tFb$G3d$jEv$F$?%P%C%U%!$N3+J|$J$I$KMQ$$$k$3$H$O$G$-$k(B.
                     45: @end example
                     46: @noindent
                     47: $BDL>o$O(B @code{GC_malloc()} $B$r;HMQ$9$k$,(B, $BB?G\D9?tMQ$NNN0h$J$I(B, $BFbIt$K%]%$(B
                     48: $B%s%?$r4^$^$J$$$3$H$,J,$+$C$F$$$kNN0hMQ$K(B @code{GC_malloc_atomic()} $B$,MQ(B
                     49: $B0U$5$l$F$$$k(B. GC $B%k!<%A%s$O(B, @code{GC_malloc_atomic()} $B$K$h$j3d$jEv$F$i(B
                     50: $B$l$?NN0h$NFbIt$O%9%-%c%s$7$J$$$N$G(B, GC $B$N8zN($,NI$/$J$k(B.
1.3     ! noro       51:
        !            52: $B$J$*(B, version 7 $B0J9_$N(B GC $B$rMQ$$$F$$$k>l9g(B, $B$3$l$i$N4X?t$rD>@\8F$S=P$7$F(B
        !            53: $B$O$$$1$J$$(B. $BI,$:A08e=hM}$D$-$N4X?t(B (@code{Risa_}$B$r$D$1$?$b$N(B)$B$r8F$S=P$9$3$H(B.
1.2       noro       54: \E
                     55: \BEG
                     56: @example
                     57: void GC_init()
1.1       noro       58:
1.2       noro       59: void *GC_malloc(int n)
                     60:
                     61: void *GC_malloc_atomic(int n)
                     62:
                     63: GC_free(void *p)
                     64: @end example
                     65: @noindent
                     66: \E
1.1       noro       67:
1.2       noro       68: \JP @section Risa $B$K$*$1$k%a%b%j$N;HMQ(B
                     69: \EG @section Usage of memory in Risa
1.1       noro       70:
1.2       noro       71: \BJP
1.1       noro       72: Risa $B$K$*$1$k3F1i;;4X?t$K$D$$$F6&DL$N?6Iq$$$H$7$F(B, $B7k2L$H$7$F@8@.$5$l$k(B
                     73: object $B$NFbIt$G(B, $BF~NO$G$"$k(B object $B$N3FIt$X$N;2>H$,9T$o$l$F$$$k2DG=@-(B
                     74: $B$,$"$k(B, $B$H$$$&$3$H$,$"$k(B.
                     75:
                     76: $B<!$NNc$O(B, $BB?9`<0$N2C;;4X?t$G$"$k(B. $B$3$NCf$G(B, $BNc$($P@hF,$N9`$N<!?t$,0[$J$k(B
                     77: $B>l9g$K$O(B, $B78?t(B($B$X$N%]%$%s%?(B)$B$,$=$N$^$^7k2L$K%3%T!<$5$l$F$$$k(B. $B$^$?(B,
                     78: $B0z?t$N0lJ}$N<!?t78?t%j%9%H$NKvHx$^$G$?$I$C$?;~$K(B, $B0lJ}$N<!?t78?t%j%9%H$,(B
                     79: $B;D$C$F$$$k>l9g$K$O(B, $B$=$N;D$j$,$=$N$^$^7k2L$N<!?t78?t%j%9%H$K$D$J$,$l$k(B.
1.2       noro       80: \E
                     81: \BEG
                     82: \E
1.1       noro       83:
                     84: @example
                     85: #include "ca.h"
                     86:
                     87: void addp(vl,p1,p2,pr)
                     88: VL vl;
                     89: P p1,p2,*pr;
                     90: @{
                     91:   DCP dc1,dc2,dcr0,dcr;
                     92:   V v1,v2;
                     93:   P t;
                     94:
                     95:   if ( !p1 )
                     96:     *pr = p2;
                     97:   else if ( !p2 )
                     98:     *pr = p1;
                     99:   else if ( NUM(p1) )
                    100:     if ( NUM(p2) )
                    101:       addnum(vl,p1,p2,pr);
                    102:     else
                    103:       addpq(p2,p1,pr);
                    104:   else if ( NUM(p2) )
                    105:     addpq(p1,p2,pr);
                    106:   else if ( ( v1 = VR(p1) ) ==  ( v2 = VR(p2) ) ) @{
                    107:     for ( dc1 = DC(p1), dc2 = DC(p2), dcr0 = 0; dc1 && dc2; )
                    108:       switch ( cmpq(DEG(dc1),DEG(dc2)) ) @{
                    109:         case 0:
                    110:           addp(vl,COEF(dc1),COEF(dc2),&t);
                    111:           if ( t )  @{
                    112:             NEXTDC(dcr0,dcr); DEG(dcr) = DEG(dc1); COEF(dcr) = t;
                    113:           @}
                    114:           dc1 = NEXT(dc1); dc2 = NEXT(dc2); break;
                    115:         case 1:
                    116:           NEXTDC(dcr0,dcr); DEG(dcr) = DEG(dc1); COEF(dcr) = COEF(dc1);
                    117:           dc1 = NEXT(dc1); break;
                    118:         case -1:
                    119:           NEXTDC(dcr0,dcr); DEG(dcr) = DEG(dc2); COEF(dcr) = COEF(dc2);
                    120:           dc2 = NEXT(dc2); break;
                    121:       @}
                    122:     if ( !dcr0 )
                    123:       if ( dc1 )
                    124:         dcr0 = dc1;
                    125:       else if ( dc2 )
                    126:         dcr0 = dc2;
                    127:       else @{
                    128:         *pr = 0;
                    129:         return;
                    130:       @}
                    131:     else
                    132:       if ( dc1 )
                    133:         NEXT(dcr) = dc1;
                    134:       else if ( dc2 )
                    135:         NEXT(dcr) = dc2;
                    136:       else
                    137:         NEXT(dcr) = 0;
                    138:     MKP(v1,dcr0,*pr);
                    139:   @} else @{
                    140:     while ( v1 != VR(vl) && v2 != VR(vl) )
                    141:       vl = NEXT(vl);
                    142:     if ( v1 == VR(vl) )
                    143:       addptoc(vl,p1,p2,pr);
                    144:     else
                    145:       addptoc(vl,p2,p1,pr);
                    146:   @}
                    147: @}
                    148: @end example
                    149:
1.2       noro      150: \BJP
1.1       noro      151: $B$3$N$h$&$K(B, Risa $B$N1i;;4X?t$G$O(B, $B0l8+ITMW$K$J$C$?Cf4VE*$J7k2L$G$b(B, $B$=$N(B
                    152: $BItJ,<0$,:G=*7k2L$KMQ$$$i$l$F$$$k$3$H$,$"$k$?$a(B, $BCm0U$,I,MW$G$"$k(B. $BFC$K(B,
                    153: $BG[Ns$r=q$-49$($kI,MW$,$"$k>l9g$J$I$K$O(B, $BG[Ns$=$N$b$N$r?7$7$/@8@.$7$F(B, $B@.(B
                    154: $BJ,$r%3%T!<$7$F$+$iMQ$$$kI,MW$,$"$k(B.
1.2       noro      155: \E
                    156: \BEG
                    157: \E
1.3     ! noro      158:
        !           159: \JP @section GC version 7 $B$K4X$9$kCm0U(B
        !           160: \EG @section Notices on GC version 7
        !           161:
        !           162: \BJP
        !           163: version 6 $B$^$G$N(B Boehm GC $B$K$*$$$F$O(B, GC $B$KF~$kA0$K$9$Y$F$N(B signal $B$r%^%9%/$7(B,
        !           164: $B=P$?$"$H%^%9%/$r%/%j%"$9$k(B, $B$H$$$&A`:n$r<+F0E*$K9T$C$F$$$?(B. $B7k2L$H$7$F(B,
        !           165: GC $BCf$K<u$1$?(B signal $B$OJ]N1$5$l(B, GC $BCf$K(B signal $B$K$h$jBg0hC&=P$9$k$H$$$&4m81$O$J$/(B,
        !           166: $B$^$?(B, GC $BCf$N(B signal $B$O(B GC $B8e$K3N<B$K=hM}$9$k$3$H$,$G$-$?(B.
        !           167:
        !           168: $B$7$+$7(B, version 7 $B$K$*$$$F$O$3$N;EAH$_$,GQ;_$5$l$?(B. $B$3$N7k2L(B, $BNc$($P(B, GC $BCf$K(B SIGINT $B$,(B
        !           169: $B=hM}$5$l$F$7$^$&$H(B, $B%a%b%j4IM}$N%F!<%V%k$,GK2u$5$l(B, $B$=$l0J9_M=4|$;$L>uBV$K$J$k2DG=@-(B
        !           170: $B$,$"$k(B. $B<B:](B, $BBg0hJQ?t$KJ];}$5$l$F$$$k%G!<%?$,;2>H$G$-$J$/$J$C$?$j(B, $B=q$-49$o$C$?$j$H$$$&(B
        !           171: $B$3$H$,5/$-$?(B.
        !           172:
        !           173: $B$3$l$KBP$9$kBP=hK!$H$7$F(B, @code{GC_malloc()} $B$J$I$N3d$jEv$F4X?t$rD>@\8F$S=P$5$:(B, $B$3$l$i$KBP$9$k(B
        !           174: $BA08e=hM}$r9T$&4X?t$r8F$S=P$9$h$&$K$7$?(B. $BNc$($P(B @code{GC_malloc()} $B$KBP$9$k4X?t$O<!$N$h$&$K$J$k(B.
        !           175:
        !           176: @example
        !           177: int in_gc, caught_intr;
        !           178:
        !           179: void *Risa_GC_malloc(size_t d)
        !           180: @{
        !           181:   void *ret;
        !           182:
        !           183:   in_gc = 1;
        !           184:   ret = (void *)GC_malloc(d);
        !           185:   in_gc = 0;
        !           186:   if ( caught_intr ) @{ caught_intr = 0; int_handler(); @}
        !           187:   if ( !ret )
        !           188:     error("GC_malloc : failed to allocate memory");
        !           189:   return ret;
        !           190: @}
        !           191: @end example
        !           192: @code{in_gc} $B$,(B 1 $B$N$H$-(B, GC $BCf$G$"$k$3$H<($9(B.
        !           193: $B$^$?(B, @code{caught_intr} $B$,(B 1 $B$N$H$-(B, @code{in_gc}$B$,(B1 $B$N4V$K(B SIGINT $B$r<u$1$?$3$H$rI=$9(B.
        !           194: $B$3$N>l9g(B, SIGINT handler $B$G$"$k(B @code{int_handler()}
        !           195: $B$G$O(B, $BC1$K(B @code{caught_intr} $B$r(B 1 $B$K$7$F2?$b$;$:$K(B return $B$9$k(B.
        !           196: @example
        !           197: extern int ox_int_received, critical_when_signal;
        !           198: extern int in_gc, caught_intr;
        !           199:
        !           200: void int_handler(int sig)
        !           201: @{
        !           202:   extern NODE PVSS;
        !           203:   NODE t;
        !           204:
        !           205:
        !           206:   if ( do_file ) @{
        !           207:     ExitAsir();
        !           208:   @}
        !           209:   if ( critical_when_signal ) @{
        !           210:     ox_int_received = 1;
        !           211:     return;
        !           212:   @}
        !           213:   if ( in_gc ) @{
        !           214:     caught_intr = 1;
        !           215:     return;
        !           216:   @}
        !           217:   ...
        !           218: @end example
        !           219: GC $BCf$K(B SIGINT $B$,$"$C$?>l9g(B, @code{in_gc}$B$,(B 0 $B$H$J$C$?$"$H$K(B,
        !           220: @code{caught_intr} $B$r(B0 $B$K$7$F(B SIGINT $B=hM}4X?t(B @code{int_handler()} $B$r8F(B
        !           221: $B$S=P$9(B. $B$3$N$h$&$K$9$k$3$H$G(B, version 6 $B$HF1MM$K(B, GC $BFb$G<u$1$?(B SIGINT
        !           222: $B$N=hM}$NJ]N1$*$h$S(B GC$B8e$N=hM}$r9T$&$3$H$,$G$-$k(B.
        !           223:
        !           224: $B$J$*(B, OX server $B$H$7$FF0:nCf$K$O(B SIGINT $B$NB>$K(B
        !           225: SIGUSR1 $B$r<u$1<h$k2DG=@-$,$"$k(B. $B$3$N>l9g(B,
        !           226: $BCfCG$G$-$J$$(B OX $BDL?.4X?t$NA08e$G(B@code{begin_critical()},
        !           227: @code{end_critical()}$B$,<B9T$5$l(B, @code{ciritical_when_signal},
        !           228: @code{ox_usr1_sent} $B$K$h$j(BSIGUSR1 $B=hM}$NJ]N1$,<B8=$5$l$F$$$k(B.
        !           229:
        !           230: @example
        !           231: int ox_usr1_sent, ox_int_received, critical_when_signal;
        !           232: void ox_usr1_handler(int sig)
        !           233: @{
        !           234:   NODE t;
        !           235:
        !           236:   signal(SIGUSR1,ox_usr1_handler);
        !           237:   if ( critical_when_signal ) @{
        !           238:     fprintf(stderr,"usr1 : critical\n");
        !           239:     ox_usr1_sent = 1;
        !           240:   @} else @{
        !           241:     ox_flushing = 1;
        !           242:     ...
        !           243:     ox_resetenv("usr1 : return to toplevel by SIGUSR1");
        !           244:   @}
        !           245: @}
        !           246:
        !           247: void begin_critical() @{
        !           248:   critical_when_signal = 1;
        !           249: @}
        !           250:
        !           251: void end_critical() @{
        !           252:   critical_when_signal = 0;
        !           253:   if ( ox_usr1_sent ) @{
        !           254:     ox_usr1_sent = 0;
        !           255:   ox_usr1_handler(SIGUSR1);
        !           256:   @}
        !           257:   if ( ox_int_received ) @{
        !           258:     ox_int_received = 0; int_handler(SIGINT);
        !           259:   @}
        !           260: @}
        !           261: @end example
        !           262: @noindent
        !           263: $B$3$N>l9g(B, OX server $BFb$G$N(B GC $BCf$K<u$1<h$C$?(B SIGINT $B$r$I$&$9$k$+$H$$$&(B
        !           264: $BLdBj$,@8$:$k(B. $B$3$l$K$D$$$F$O(B, OX server $BFb$G$N(B GC $BCf$K<u$1<h$C$?(B
        !           265: SIGINT $B$O(B @code{ox_int_received} $B$K5-O?$9$k$@$1$H$9$k(B.
        !           266: (@code{int_handler()} $BFb$G(B, @code{in_gc} $B$h$j@h$K(B
        !           267: @code{critical_when_signal} $B$r8+$F$$$k$3$H$KCm0U(B.)
        !           268: $B7k2L$H$7$F(B, $BBP1~(B
        !           269: $B$9$k(B @code{int_handler()} $B$N=hM}$O(B, $B<!$K(B @code{end_critical()} $B$,8F$P$l$?$H(B
        !           270: $B$-$K$D$$$G$K<B9T$5$l$k$3$H$K$J$j(B, $BB(1~@-$,$J$/$J$k$,(B, SIGINT $B$O(B $B<jF0$G(B
        !           271: $B$N$_Aw$i$l$k$N$G(B, $B$3$NE@$O5$$K$9$kI,MW$O$J$$(B.
        !           272:
        !           273: $BA08e=hM}$D$-$N%a%b%j3d$jEv$F4X?t(B @samp{parse/gc_risa.c} $B$GDj5A$5$l$F$$$k(B.
        !           274: @example
        !           275: void *Risa_GC_malloc(size_t d)
        !           276: void *Risa_GC_malloc_atomic(size_t d)
        !           277: void *GC_malloc_atomic(int n)
        !           278: void *Risa_GC_malloc_atomic_ignore_off_page(size_t d)
        !           279: void *Risa_GC_realloc(void *p,size_t d)
        !           280: void Risa_GC_free(void *p)
        !           281: @end example
        !           282: $B$=$l$>$l(B, @code{Risa_} $B$,$J$$4X?t$KBP1~$7$F$$$k(B.
        !           283: $B$^$?(B, @samp{include/ca.h}$BFb$N%a%b%j3d$jEv$F4XO"%^%/%m$b(B, $B$9$Y$F(B
        !           284: $B$3$l$i$NA08e=hM}$D$-4X?t$r8F$V$h$&$KJQ99$7$?(B.
        !           285: \E
        !           286: \BEG
        !           287: \E

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>