Task 1
This commit is contained in:
parent
d1d82dcd2d
commit
56f40f57ae
|
@ -6,7 +6,7 @@ import java.util.LinkedList;
|
|||
import java.util.List;
|
||||
|
||||
public class Storage {
|
||||
public static boolean generationalGCActive = false; // in Aufgabe 2 verwendet
|
||||
public static boolean generationalGCActive = true; // in Aufgabe 2 verwendet
|
||||
public static StringBuffer log = new StringBuffer();
|
||||
private static List<Collectable> root;
|
||||
private static List<Collectable> youngHeap;
|
||||
|
@ -120,26 +120,38 @@ public class Storage {
|
|||
}
|
||||
|
||||
private static void mark(Collectable cObject) {
|
||||
// TODO Aufgabe 13.1
|
||||
if (!cObject.isMarked()) {
|
||||
cObject.setMark(true);
|
||||
getRefs(cObject).forEach(ref -> mark(ref));
|
||||
}
|
||||
}
|
||||
|
||||
private static void sweep() {
|
||||
// TODO Aufgabe 13.1 und Aufgabe 13.2
|
||||
private static void sweep(List<Collectable> heap) {
|
||||
heap.removeIf(obj -> !obj.isMarked());
|
||||
heap.forEach(obj -> obj.setMark(false));
|
||||
//oldHeap.addAll(youngHeap);
|
||||
//youngHeap.clear();
|
||||
}
|
||||
|
||||
public static void gc() {
|
||||
getRoot().forEach(root -> mark(root));
|
||||
if (generationalGCActive) {
|
||||
if (youngGenerationOnly) {
|
||||
log.append("\nCollector start young generation only\n");
|
||||
sweep(youngHeap);
|
||||
youngGenerationOnly = false;
|
||||
} else {
|
||||
log.append("\nCollector start young and old generation\n");
|
||||
sweep(youngHeap);
|
||||
sweep(oldHeap);
|
||||
youngGenerationOnly = true;
|
||||
}
|
||||
} else {
|
||||
log.append("\nCollector start\n");
|
||||
sweep(youngHeap);
|
||||
}
|
||||
|
||||
// TODO Aufgabe 13.1 und Aufgabe 13.2
|
||||
|
||||
log.append("Collector end\n");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue