1. Homepage
  2. Programming
  3. [2021] CS3214 Computer Systems - Exercise 4: Mark-and-Sweep Garbage Collection

[2021] CS3214 Computer Systems - Exercise 4: Mark-and-Sweep Garbage Collection

Engage in a Conversation
CS3214Computer SystemsGarbage CollectionProgramming HelpVirginia TechVirginia Polytechnic Institute and State University

Exercise 4 CourseNana.COM

  CourseNana.COM

Due: Seewebsiteforduedate. Whattosubmit: Seewebsite. CourseNana.COM

The theme of this exercise is automatic memory management and leak detection. Part 3 requires the installation of software on your personal machine. CourseNana.COM

1. Mark-and-Sweep Garbage Collection CourseNana.COM

The first part of the exercise involves a small programming exercise that is intended to deepen your understanding of how a garbage collector works. You are asked to imple- ment a variant of a mark-and-sweep collector using a synthetic heap dump given as input. Ontheheap,therearenobjectsnumbered0...n1withsizess0 ...sn1. Alsogivenare r roots and m pointers, i.e., references stored in objects that refer to other objects. CourseNana.COM

Write a program that performs a mark-and-sweep collection and outputs the total size of the live heap as well as the total amount of memory a mark-and-sweep collector would sweep if this heap were garbage collected. CourseNana.COM

In addition, report the retained heap size for each of the roots. The retained heap size is the additional number of bytes that could be freed if this (and only this) root were removed from the graph and the garbage collection were repeated. Note that removing a root will also remove all of its outgoing edges. CourseNana.COM

We will do this problem programming competition style. Write a program - in any lan- guage you choose1 – that reads a heap description and outputs the size of the live heap and the amount of garbage swept if a garbage collection is performed. Then output the retained heap size for each root in the order in which they are given in the input. CourseNana.COM

As is customary for Unix programs, your program should read from its standard input stream. Each invocation of your program should process a single test case. The first line contains three non-negative 32-bit integers n, m, r such that r n. The second line contains n positive 32-bit integers si that denote the size si of object i. Following that are m lines with tuples i, j for which 0 i, j < n, each of which denotes a pair of object indices. A tuple (i,j) means that object i stores a reference to object j, keeping it alive (provided si is reachable from a root). The description of the references is followed by a single line with r integers denoting the roots of the reachability graph R0 . . . Rr1. Nodes designated as roots do not have incoming edges that point to them. CourseNana.COM

Your program should write to its standard output stream R + 1 lines. On the first, it should output two numbers l s, where l represents the total size of the live heap and s represents the amount of garbage that would be swept if the heap were collected. On the following lines, for each root, it should output how much (additional) memory could be freed if this root were removed, in the order in which the roots appear in the input. In CourseNana.COM

Figure 1: The reachability graph given in the sample input. Roots are shown using double circles. The numbers in parentheses are the sizes of individual nodes. Here, root 9 keeps alive object 8, which keeps 1 and 6 alive, which in turn keep 14. Root 12 keeps object 7 alive from which objects 0, 3, 10, and 11 are reachable. Note that in this example each root spans a different, disjoint subtree. This is not the case in general. Be sure you create test cases for which the sets of nodes that are reachable from each root overlap. CourseNana.COM

other words, compute the size of the additional garbage that would be produced if said root were removed. CourseNana.COM

Sample Input: CourseNana.COM

15 15 2
8 10 27 21 13 35 33 18 33 0 25 36 0 20 13 11 10
6 14
5 14
70
11 7
81
2 11
86
48
12 7
98
13 6
1 14
7 11
03
9 12
CourseNana.COM

Sample Output: CourseNana.COM

197 95 89
108
CourseNana.COM

Figure 1 shows the reachability graph for the sample input/output. CourseNana.COM

We will test your program on additional inputs. Your algorithm should have a complexity  of at most O(R × (m + n)) where R is the number of roots, n is the number of nodes, CourseNana.COM

and m is the number of edges. You should further implement your algorithm under the 2 CourseNana.COM

assumption that the graph is sparse, that is, m n .
Extra credit: Write an algorithm with a complexity of no worse than
O((m + n) × log n) CourseNana.COM

where n is the number of nodes and m is the number of edges. CourseNana.COM

FAQ CourseNana.COM

Can I use graph library X, Y, or Z? CourseNana.COM

You may consult such code for reference, but do not use it directly. Keep in mind that tasks like these are tasks you may be asked during a programming interview where you also would need to be able to produce this code without the aid of aux- iliary libraries. CourseNana.COM

  CourseNana.COM

Get in Touch with Our Experts

WeChat WeChat
Whatsapp WhatsApp
CS3214代写,Computer Systems代写,Garbage Collection代写,Programming Help代写,Virginia Tech代写,Virginia Polytechnic Institute and State University代写,CS3214代编,Computer Systems代编,Garbage Collection代编,Programming Help代编,Virginia Tech代编,Virginia Polytechnic Institute and State University代编,CS3214代考,Computer Systems代考,Garbage Collection代考,Programming Help代考,Virginia Tech代考,Virginia Polytechnic Institute and State University代考,CS3214help,Computer Systemshelp,Garbage Collectionhelp,Programming Helphelp,Virginia Techhelp,Virginia Polytechnic Institute and State Universityhelp,CS3214作业代写,Computer Systems作业代写,Garbage Collection作业代写,Programming Help作业代写,Virginia Tech作业代写,Virginia Polytechnic Institute and State University作业代写,CS3214编程代写,Computer Systems编程代写,Garbage Collection编程代写,Programming Help编程代写,Virginia Tech编程代写,Virginia Polytechnic Institute and State University编程代写,CS3214programming help,Computer Systemsprogramming help,Garbage Collectionprogramming help,Programming Helpprogramming help,Virginia Techprogramming help,Virginia Polytechnic Institute and State Universityprogramming help,CS3214assignment help,Computer Systemsassignment help,Garbage Collectionassignment help,Programming Helpassignment help,Virginia Techassignment help,Virginia Polytechnic Institute and State Universityassignment help,CS3214solution,Computer Systemssolution,Garbage Collectionsolution,Programming Helpsolution,Virginia Techsolution,Virginia Polytechnic Institute and State Universitysolution,