Project

General

Profile

Feature #3322 ยป cow2.patch

Dan42 (Daniel DeLorme), 05/21/2010 08:55 AM

View differences:

gc.c (working copy)
280 280
    void *membase;
281 281
    RVALUE *slot;
282 282
    size_t limit;
283
    int leaked;
283 284
};
284 285

  
285 286
#define HEAP_MIN_SLOTS 10000
......
485 486

  
486 487
/*
487 488
 *  call-seq:
489
 *    GC.leak                 -> nil
490
 *
491
 *  marks all heaps as leaked and all objects with FL_MARK
492
 *  to prevent GC from touching that memory (COW-friendly)
493
 */
494

  
495
static VALUE
496
gc_leak(VALUE self)
497
{
498
    rb_objspace_t *objspace = &rb_objspace;
499
    RVALUE *p, *pend;
500
    size_t i;
501

  
502
    garbage_collect(objspace);
503
    for (i = 0; i < heaps_used; i++) {
504
        p = heaps[i].slot; pend = p + heaps[i].limit;
505
        while (p < pend) {
506
            if ((p->as.basic.flags != 0) &&
507
                !(p->as.basic.flags & FL_MARK)) {
508
              p->as.basic.flags |= FL_MARK;
509
            }
510
            p++;
511
        }
512
        heaps[i].leaked = TRUE;
513
    }
514
    freelist = NULL;
515
    return Qnil;
516
}
517

  
518
/*
519
 *  call-seq:
520
 *    GC.unleak                 -> nil
521
 *
522
 *  set currently leaked heaps to be reclaimed on next GC
523
 */
524

  
525
static VALUE
526
gc_unleak(VALUE self)
527
{
528
    rb_objspace_t *objspace = &rb_objspace;
529
    size_t i;
530

  
531
    for (i = 0; i < heaps_used; i++) {
532
        heaps[i].leaked = FALSE;
533
    }
534
    garbage_collect(objspace);
535
    return Qnil;
536
}
537

  
538
/*
539
 *  call-seq:
488 540
 *    GC.stress                 -> true or false
489 541
 *
490 542
 *  returns current status of GC stress mode.
......
938 990
    heaps[hi].membase = membase;
939 991
    heaps[hi].slot = p;
940 992
    heaps[hi].limit = objs;
993
    heaps[hi].leaked = FALSE;
941 994
    pend = p + objs;
942 995
    if (lomem == 0 || lomem > p) lomem = p;
943 996
    if (himem < pend) himem = pend;
......
1874 1927
	RVALUE *final = final_list;
1875 1928
	int deferred;
1876 1929

  
1930
	if (heaps[i].leaked) continue;
1877 1931
	p = heaps[i].slot; pend = p + heaps[i].limit;
1878 1932
	while (p < pend) {
1879 1933
	    if (!(p->as.basic.flags & FL_MARK)) {
......
3178 3232
    rb_define_singleton_method(rb_mGC, "start", rb_gc_start, 0);
3179 3233
    rb_define_singleton_method(rb_mGC, "enable", rb_gc_enable, 0);
3180 3234
    rb_define_singleton_method(rb_mGC, "disable", rb_gc_disable, 0);
3235
    rb_define_singleton_method(rb_mGC, "leak", gc_leak, 0);
3236
    rb_define_singleton_method(rb_mGC, "unleak", gc_unleak, 0);
3181 3237
    rb_define_singleton_method(rb_mGC, "stress", gc_stress_get, 0);
3182 3238
    rb_define_singleton_method(rb_mGC, "stress=", gc_stress_set, 1);
3183 3239
    rb_define_singleton_method(rb_mGC, "count", gc_count, 0);