Class: Scrym::Mutator

Inherits:
Object
  • Object
show all
Defined in:
ext/scrym/scrym_ext.c

Class Method Summary collapse

Class Method Details

.collectObject



349
350
351
352
353
354
355
356
357
358
# File 'ext/scrym/scrym_ext.c', line 349

static VALUE
scrym_collect(VALUE self)
{
    while(scrym_expire_chunk());
    global_desc->expired = global_desc->marked;
    global_desc->marked = NULL;
    global_desc->mark_mask = other_mark_part(global_desc->mark_mask);
    scrym_shrink_descriptor_chunk_cache(global_desc);
    return Qnil;
}

.mark(obj) ⇒ Object

—- mark —-



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'ext/scrym/scrym_ext.c', line 187

static VALUE
scrym_mark(VALUE self, VALUE obj)
{
    if (IMMEDIATE_P(obj)) {
        rb_raise(rb_eArgError, "can not accept an immediate value");
        return;
    }
    if (BUILTIN_TYPE(obj) == T_NONE) {
        rb_raise(rb_eArgError, "can not accept an node");
        return;
    }
    if (RBASIC(obj)->flags & global_desc->mark_mask) {
        return;
    }
    scrym_add_descriptor(global_desc, obj);
    RBASIC(obj)->flags |= global_desc->mark_mask;
    return Qnil;
}

.testObject



361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
# File 'ext/scrym/scrym_ext.c', line 361

static VALUE
scrym_test(VALUE self) {
    size_t i;

    {
        puts("scrym_init");
        assert(global_desc->expired == NULL);
        assert(global_desc->marked == NULL);
        assert(global_desc->cache != NULL);
    }

    {
        size_t j;
        puts("scrym_add_descriptor");
        for(i = 0; i < SCRYM_CACHE_MIN; i++) {
            for(j = 0; j < SCRYM_DESCRIPTOR_CHUNK_SIZE; j++) {
                scrym_add_descriptor(global_desc, j);
            }
        }
        for(j = 0; j < SCRYM_DESCRIPTOR_CHUNK_SIZE; j++) {
            assert(global_desc->marked->descriptors[j] == (VALUE)j);
        }
        assert(global_desc->marked->next->next->next != NULL);
        assert(global_desc->marked->next->next->next->descriptors[SCRYM_DESCRIPTOR_CHUNK_SIZE] != SCRYM_DESCRIPTOR_CHUNK_SIZE-1);
        assert(global_desc->marked->next->next->next->next == NULL);
        assert(global_desc->expired == NULL);
        assert(global_desc->cache == NULL);
        assert(global_desc->cache_size == 0);
        assert(global_desc->unused_cache_size == 0);
        global_desc->cache = global_desc->marked;
        global_desc->marked = NULL;
        global_desc->cache_size = SCRYM_CACHE_MIN;
    }

    {
        VALUE str = rb_str_new_cstr("test");
        VALUE str2 = rb_str_new_cstr("test2");
        puts("scrym_collect");
        assert(scrym_expire_chunk() == Qfalse);
        assert((RBASIC(str)->flags & SCRYM_MARK) == 0);

        puts("  scrym_mark1");
        scrym_mark(Qnil, str);
        scrym_mark(Qnil, str);
        assert(global_desc->marked->index == 1);
        assert(RBASIC(str)->flags & global_desc->marked->mark_mask);
        assert(!(RBASIC(str)->flags & other_mark_part(global_desc->marked->mark_mask)));

        puts("  scrym_mark2");
        scrym_mark(Qnil, str2);
        assert(global_desc->marked->index == 2);
        assert(RBASIC(str2)->flags & global_desc->marked->mark_mask);

        puts("  collect1");
        scrym_collect(Qnil);
        scrym_mark(Qnil, str2);

        puts("  collect2");
        scrym_collect(Qnil);
        assert(RBASIC(str)->flags == 0);
        assert(RBASIC(str2)->flags != 0);
        assert(global_desc->marked == NULL);
        assert(global_desc->expired != NULL);

        puts("  collect3");
        scrym_collect(Qnil);
        assert(RBASIC(str2)->flags == 0);
        assert(global_desc->expired == NULL);
        assert(global_desc->cache_size == SCRYM_CACHE_MIN);
    }
}