Project

General

Profile

Feature #3322 ยป cow.patch

Dan42 (Daniel DeLorme), 05/20/2010 05:58 PM

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

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

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

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

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

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