src/virtual-machines/source-1-with-mark-region-gc.js
// expects hole-size in K
expects hole-size in K
expects hole - size in K
function FREE_REGION() {
  for (I = 0; I < NUMBER_OF_BLOCKS; I = I + 1) {
    if (HEAP[I * BLOCK_SIZE + MARK_SLOT] === UNMARKED) {
      HEAP[I * BLOCK_SIZE + BLOCK_STATE_SLOT] = FREE;
    } else {
      HEAP[I * BLOCK_SIZE + BLOCK_STATE_SLOT] = OCCUPIED;
      for (
        SCAN = HEAP[I * BLOCK_SIZE + FIRST_CHILD_SLOT];
        SCAN < HEAP[I * BLOCK_SIZE + LAST_CHILD_SLOT];
        SCAN = SCAN + LINE_BK_SIZE
      ) {
        if (HEAP[SCAN + LINE_MARK_SLOT] === UNMARKED) {
          HEAP[SCAN + LINE_LIMIT_SLOT] = HEAP[SCAN + LINE_ADDRESS_SLOT];
          HEAP[I * BLOCK_SIZE + BLOCK_STATE_SLOT] = RECYCLABLE;
        } else {}
        HEAP[SCAN + LINE_MARK_SLOT] = UNMARKED;
      }
    }
    HEAP[I * BLOCK_SIZE + MARK_SLOT] = UNMARKED;
  }
  ALLOCATE_TO_RECYCLABLE();
  if (BUMP_HEAD + K > BUMP_TAIL) {
    ALLOCATE_TO_FREE();
  } else {}
}
function FREE_REGION ( ) { for ( I = 0 ; I < NUMBER_OF_BLOCKS ; I = I + 1 ) { if ( HEAP [ I * BLOCK_SIZE + MARK_SLOT ] === UNMARKED ) { HEAP [ I * BLOCK_SIZE + BLOCK_STATE_SLOT ] = FREE ; } else { HEAP [ I * BLOCK_SIZE + BLOCK_STATE_SLOT ] = OCCUPIED ; for ( SCAN = HEAP [ I * BLOCK_SIZE + FIRST_CHILD_SLOT ] ; SCAN < HEAP [ I * BLOCK_SIZE + LAST_CHILD_SLOT ] ; SCAN = SCAN + LINE_BK_SIZE ) { if ( HEAP [ SCAN + LINE_MARK_SLOT ] === UNMARKED ) { HEAP [ SCAN + LINE_LIMIT_SLOT ] = HEAP [ SCAN + LINE_ADDRESS_SLOT ] ; HEAP [ I * BLOCK_SIZE + BLOCK_STATE_SLOT ] = RECYCLABLE ; } else { } HEAP [ SCAN + LINE_MARK_SLOT ] = UNMARKED ; } } HEAP [ I * BLOCK_SIZE + MARK_SLOT ] = UNMARKED ; } ALLOCATE_TO_RECYCLABLE ( ) ; if ( BUMP_HEAD + K > BUMP_TAIL ) { ALLOCATE_TO_FREE ( ) ; } else { } }
expects hole-size in K
expects hole - size in K
// granular collection // free blocks // if block is not MARKED, set state to FREE // assume OCCUPIED // free lines in non-free block // line pseudo node address in SCAN // free line not marked // set block to recyclable // unmark line // unmark whole block // finds a hole of at least k size and allocate new bump head and tail // if hole found still too small, allocate to a free block