is garbage collection algorithm in java "vendor implemented?"
-
Do you mean can it differ between different JVMs? I would expect the answer is yes, but to confirm, see if the Garbage Collection method is described in the JLS. I suspect it isn't though.Noon Silk– Noon Silk2009-08-30 06:16:20 +00:00Commented Aug 30, 2009 at 6:16
-
In order to allow conservative collectors, there isn't really any constraints that can be placed on the collector (other than, for instance, not collecting objects that are not garbage). Having no GC is valid.Tom Hawtin - tackline– Tom Hawtin - tackline2009-08-30 06:22:51 +00:00Commented Aug 30, 2009 at 6:22
-
Yep. Why do you care, may we ask...?Alex Martelli– Alex Martelli2009-08-30 06:32:56 +00:00Commented Aug 30, 2009 at 6:32
5 Answers
From the introduction paragraph to Chapter 3 of the Java Virtual Machine Specification:
For example, the memory layout of run-time data areas, the garbage-collection algorithm used, and any internal optimization of the Java virtual machine instructions (for example, translating them into machine code) are left to the discretion of the implementor. [emphasis mine]
Comments
Yes. The Java VM Spec's don't say anything specific about garbage collection. Each vendor has their own implementation for performing GC. In fact, each vendor will have multiple GC policies that can be best chosen for a particular task.
Example A GC tuned for throughput may not be good for real-time systems since they will have erratic (and often longer) pause times which are not predictable. Non-predictability is a killer for real-time application.
Some GC's such as the ones from Oracle and IBM are very tunable and can be tune based on your application's run-time memory characteristics.
The internals of GC are not too complicated at a higher level. Many algorithms that began in the early days of LISP are still in use today.
Read this (http://nd.edu/~dthain/courses/cse40243/spring2006/gc-survey.pdf "GC Introduction") for a good introduction to Garbage Collection at a moderately high-level.