src/runtime/alloc.c
/// Moves to the next open line, starting at `local_alloc.end`.
/// Returns true if it found one, false if it exhausted the current block.
Moves to the next open line, starting at `local_alloc.end`.
Returns true if it found one, false if it exhausted the current block.
Moves to the next open line starting at ` local_alloc . end ` . Returns true if it found one false if it exhausted the current block .
static bool next_line() {
    if (!local_alloc.block)
        return false;
    uint32_t block_idx = (local_alloc.block - all_blocks[0].start) / BLOCK_SIZE;
    void* block_ptr = local_alloc.block;
    void* next_ptr = local_alloc.end;
    uint32_t line_idx = (next_ptr - block_ptr) / LINE_SIZE - 1;
    uint64_t* lines = all_blocks[block_idx].line_mark;
    bool found = false;
    while (next_ptr > block_ptr) {
        if (!bitset_get(lines, line_idx)) {
            if (!found) {
                found = true;
                local_alloc.ptr = next_ptr;
            }
            memset(next_ptr-LINE_SIZE, 0, LINE_SIZE);
        } else if (found) {
            local_alloc.end = next_ptr;
            return true;
        }
        next_ptr -= LINE_SIZE;
        line_idx--;
    }
    if (found) {
        local_alloc.end = block_ptr;
        return true;
    } else {
        return false;
    }
}
static bool next_line ( ) { if ( ! local_alloc . block ) return false ; uint32_t block_idx = ( local_alloc . block - all_blocks [ 0 ] . start ) / BLOCK_SIZE ; void * block_ptr = local_alloc . block ; void * next_ptr = local_alloc . end ; uint32_t line_idx = ( next_ptr - block_ptr ) / LINE_SIZE - 1 ; uint64_t * lines = all_blocks [ block_idx ] . line_mark ; bool found = false ; while ( next_ptr > block_ptr ) { if ( ! bitset_get ( lines , line_idx ) ) { if ( ! found ) { found = true ; local_alloc . ptr = next_ptr ; } memset ( next_ptr - LINE_SIZE , 0 , LINE_SIZE ) ; } else if ( found ) { local_alloc . end = next_ptr ; return true ; } next_ptr -= LINE_SIZE ; line_idx -- ; } if ( found ) { local_alloc . end = block_ptr ; return true ; } else { return false ; } }
Moves to the next open line, starting at `local_alloc.end`.
Moves to the next open line starting at ` local_alloc . end ` .
// Search for an open line // next_ptr points to the low end of an occupied line // line_idx points to the line below next_ptr - `next_ptr` is the end of line `line_idx` // If `next_ptr == block_ptr`, then we're past the end of the block // Zero-initialize the line to make sure the GC never sees old data if it runs before stores to the region