This commit is contained in:
schrom01 2022-12-19 22:25:39 +01:00
parent d1d82dcd2d
commit 56f40f57ae
1 changed files with 18 additions and 6 deletions

View File

@ -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,25 +120,37 @@ 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");
}