navid/haze / dd80043cbfdebf21379913ad485b61a10041969a4e5eed45620594643fb3445f / tests/m0_gc.hz

m0_gc.hz

← tests · 605 bytes · raw · download

// Internal M0 smoke test: ordinary, medium, and large allocation, with
// collections interleaved and the heap verifier enabled.

fn churn(count i32) {
    var i = 0
    for i < count {
        const p = __gc_alloc(64)
        __gc_store(p, 8, p)
        i++
    }
}

fn hold_big() ptr {
    const p = __gc_alloc(10000)
    return p
}

fn main() {
    const keep = hold_big()
    churn(2000)
    __gc_collect()
    __gc_verify()
    if __gc_alive(keep) {
        print("big alive")
    } else {
        print("big dead")
    }
    churn(1000)
    __gc_collect()
    __gc_verify()
    print("churn ok")
}