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