|
@@ -3849,22 +3849,53 @@ must therefore perform automatic garbage collection.
|
|
\section{Garbage Collection}
|
|
\section{Garbage Collection}
|
|
\label{sec:GC}
|
|
\label{sec:GC}
|
|
|
|
|
|
|
|
+Here we study a relatively simple algorithm for garbage collection
|
|
|
|
+that is the basis of the state-of-the-art generational garbage
|
|
|
|
+collectors~\citep{Lieberman:1983aa,Ungar:1984aa,Jones:1996aa,Detlefs:2004aa,Dybvig:2006aa}. In
|
|
|
|
+particular, we describe a two-space copying
|
|
|
|
+collector~\citep{Wilson:1992fk} that uses Cheney's algorithm to
|
|
|
|
+perform the
|
|
|
|
+copy~\citep{Cheney:1970aa}. Figure~\ref{fig:copying-collector} gives a
|
|
|
|
+coarse-grained depiction of what happens in a two-space collector,
|
|
|
|
+showing two time steps, prior to garbage collection on the top and
|
|
|
|
+after garbage collection on the bottom. In a two-space collector, the
|
|
|
|
+heap is segmented into two parts, the FromSpace and the
|
|
|
|
+ToSpace. Initial, all allocations go to the FromSpace. As you can see,
|
|
|
|
+prior to garbage collection all of the allocated objects are in the
|
|
|
|
+FromSpace.
|
|
|
|
+
|
|
|
|
+A running program has direct access to registers and the procedure
|
|
|
|
+call stack, and those may contain pointers into the heap. Those
|
|
|
|
+pointers are called the \emph{root set}. In
|
|
|
|
+Figure~\ref{fig:copying-collector} there are three pointers in the
|
|
|
|
+root set, one in a register and two on the stack. The goal of the
|
|
|
|
+garbage collector is to 1) preserve all objects that are reachable
|
|
|
|
+from the root set via a path of pointers, i.e., the \emph{live}
|
|
|
|
+objects and 2) reclaim the storage of everything else, i.e., the
|
|
|
|
+\emph{garbage}. A copying collector accomplished this by copying all
|
|
|
|
+of the live objects into the ToSpace and then performs a slight of
|
|
|
|
+hand, treating the ToSpace as the new FromSpace and the old FromSpace
|
|
|
|
+as the new ToSpace. In the bottom of
|
|
|
|
+Figure~\ref{fig:copying-collector} you can see the result of the copy.
|
|
|
|
+All of the live objects have been copied to the ToSpace in such a way
|
|
|
|
+that preserves the pointer relationships. For example, the pointer in
|
|
|
|
+the register still points to a 2-tuple whose first element is a
|
|
|
|
+3-tuple and second element is a 2-tuple.
|
|
|
|
|
|
\begin{figure}[tbp]
|
|
\begin{figure}[tbp]
|
|
-\includegraphics[width=0.5\textwidth]{CopyingCollector}
|
|
|
|
-\includegraphics[width=0.5\textwidth]{CopyCollector2}
|
|
|
|
|
|
+\centering
|
|
|
|
+\includegraphics[width=0.9\textwidth]{CopyingCollector} \\
|
|
|
|
+\includegraphics[width=0.9\textwidth]{CopyCollector2}
|
|
\caption{A copying collector in action.}
|
|
\caption{A copying collector in action.}
|
|
\label{fig:copying-collector}
|
|
\label{fig:copying-collector}
|
|
\end{figure}
|
|
\end{figure}
|
|
|
|
|
|
-\cite{Wilson:1992fk}
|
|
|
|
|
|
|
|
-Figure~\ref{fig:copying-collector}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-\section{Integrating Garbage Collection}
|
|
|
|
-\label{sec:integratng-GC}
|
|
|
|
|
|
+\section{Compiler Integration}
|
|
|
|
+\label{sec:compiler-integration}
|
|
|
|
|
|
|
|
|
|
|
|
|