Skip to content

[copy_gc & mark_sweep] User Guide

Bryan Loh edited this page Apr 23, 2021 · 1 revision

This is a user guide on the visualisation of these memory management techniques written by Sheikh Umar:

  • Stop-and-Copy Garbage Collection
  • Mark-Sweep Garbage Collection

Before you start

  1. Please familiarise yourself with the Developer Guide on the APIs used for the visualisation of the aforementioned garbage collection techniques via https://github.com/source-academy/modules/wiki/%5Bcopy_gc-&-mark_sweep%5D-Developer-Documentation.

Steps on Visualisation of Garbage Collection Algorithms

  1. Proceed to https://sourceacademy.nus.edu.sg/playground.
  2. Enter your source code on either of the aforementioned garbage collection techniques into the Source Academy playground.
  3. At the top of the program, import the APIs of the respective garbage collection techniques.
  • For the Stop-and-Copy Garbage Collection, declare these APIs:
import { init, initialize_memory, initialise_tag, newCopy, newFlip, newPush, newPop, newAssign, newNew, scanFlip, startFlip } from 'copy_gc';
  • For the Mark-Sweep Garbage Collection, declare these APIs:
import { init, initialize_memory, newAssign, newPush, newPop, newNew, initialise_tag, newGC, newMark, newSweep } from 'mark_sweep';
  1. Enter init() at the end of your source code.
  2. Click 'Run'. If you are running code for Stop-Copy Garbage Collection, please proceed to step 6. If you are running code for Mark-Sweep Garbage Collection, please proceed to step 7.
  3. You will see two heaps denoting the To Space heap and the From Space heap.

image

You may drag the slider or select either the ‘-’ or ‘+’ icon on Current step section to see a step-by-step visualization for the Stop-Copy Garbage Collection. Alternatively, you may click on the ‘^’ icon below the slider to navigate to key steps of the Stop-Copy Garbage Collection. Here is an example of the visualisation for the Scan phase. The green and yellow colours denote where the Scan and Free pointers respectively.

image

  1. You will see the memory at the initialization stage.

image

You may drag the slider or select either the ‘-’ or ‘+’ icon on Current step section to see a step-by-step visualization for the Mark-Sweep Garbage Collection. Alternatively, you may click on the ‘^’ icon below the slider to navigate to key steps of the Mark-Sweep Garbage Collection.

Here is an example of the Mark-Sweep Garbage Collection at the Mark phase:

image

Clone this wiki locally