Web page for IU Compiler Course for Fall 2020
View the Project on GitHub IUCompilerCourse/IU-P423-P523-E313-E513-Fall-2020
Def. The live data are all of the tuples that might be accessed by the program in the future. We can overapproximate this as all of the tuples that are reachable, transitively, from the registers or procedure call stack. We refer to the registers and stack collectively as the root set.
The goal of a garbage collector is to reclaim the data that is not live.
We shall use a 2-space copying collector, using Cheney’s algorithm (BFS) for the copy.
Alternative garbage collection techniques:
Overview of how GC fits into a running program.:
Draw Fig. 5.6. (just the FromSpace)
An implementation of a garbage collector is in runtime.c
.
Add cases for the new expressions. (Fig 5.1)
type ::= ... | (Vector type+) | Void
exp ::= ... | (vector exp+) | (vector-ref exp int)
| (vector-set! exp int exp) | (void)
To help the GC identify vectors (pointers to the heap), wrap every sub-expression with its type. This information will be propagated in the flatten pass to all variables.
(HasType exp type)
Add HasType to the generated code.
Lower vector creation into a call to collect, a call to allocate, and then initialize the memory (see 5.3.1).
Make sure to place the code for sub-expressions prior to the sequence collect-allocate-initialize. Sub-expressions may also call collect, and we can’t have partially constructed vectors during collect!
New forms in the output language:
exp ::=
(Collect int) call the GC and you're going to need `int` bytes
| (Allocate int type) allocate `int` bytes
| (GlobalValue name) access global variables
free_ptr
: the next empty spot in the FromSpacefromspace_end
: the end of the FromSpaceThe new forms Collect, Allocate, GlobalValue should be treated as complex operands.
Add case for HasType.
Adapt case for Prim to make sure the enclosing HasType does not get separated from it.