Implement simple serial mark-sweep based Garbage Collector on NXJ 0.5 on memory.c sources, work in progress in forked project https://github.com/eahumada/b2fJ
It is a classic mark and sweep implementation. The garbage collection triggers automaticly only after runing out of memory or by a java gc method invocation. Thus, if a program is a "well behaving" one, the garbage collector remains dormant. It consumes about 1000 bytes of code and about 1800 bytes of ram. Although the algorithm used is simple, it's pretty fast. A typical single gc run should take no more then 10 ms to complete. Besides, the presence of garbage collector does not impair the speed of program execution. There is no reference tracing on writes and no stack or object size increase. Potential problems: long linked list may cause processor stack overflow due to recursion.
This code should be able to run without issues with infinite iterations on the 8-bit machines:
public static void main(String[] args) throws InterruptedException {
int i=0;
try {
while (true) {
Integer integer = new Integer(i);
String output="Strings:"+helloWorld+"->"+String.valueOf(i);
out.println(output);
i++;
}
} catch(Throwable e) {
out.println('*');
out.println(i);
throw e;
}
}