From 56f40f57aee867c169908b4880f841b915a06167 Mon Sep 17 00:00:00 2001 From: schrom01 Date: Mon, 19 Dec 2022 22:25:39 +0100 Subject: [PATCH] Task 1 --- src/ch/zhaw/ads/Storage.java | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/ch/zhaw/ads/Storage.java b/src/ch/zhaw/ads/Storage.java index 384ca82..4e1fd17 100644 --- a/src/ch/zhaw/ads/Storage.java +++ b/src/ch/zhaw/ads/Storage.java @@ -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 root; private static List 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 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"); } -} +} \ No newline at end of file