Course web page for Fall 2021.
The language Lvec
Racket:
exp ::= ...
| (vector exp+) create a tuple
| (vector-ref exp int) read the nth element
| (vector-set! exp int exp) write to the nth element
Python:
exp ::= ...
| ( exp , ... ) create a tuple
| exp [ exp ] read the nth element
Python tuples do not support writing, they are immutable.
Racket example:
(let ([t (vector 40 #t (vector 2))])
(if (vector-ref t 1)
(+ (vector-ref t 0)
(vector-ref (vector-ref t 2) 0))
44))
==>
42
Python example:
t = (40, True, (2,))
print( t[0] + t[2][0] if t[1] else 44 )
==>
42
(let ([t1 (vector 3 7)])
(let ([t2 t1])
(let ([_ (vector-set! t2 0 42)])
(vector-ref t1 0))))
==>
42
(let ([v (vector (vector 44))])
(let ([x (let ([w (vector 42)])
(let ([_ (vector-set! v 0 w)])
0))])
(+ x (vector-ref (vector-ref v 0) 0))))
===>
42
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)