Reputation: 809
I was going through link Java - available garbage collection algorithms to understand available JVM garbage collection algorithm and got confused.
As per my understanding there will be some standard GC algorithm which different JVM vendors implement to create garbage collector.
Now please help me to understand whether below are algorithm or implementation of algorithm:
What I think these are types of garbage collectors which implements some specific algorithm (name of algorithms which I don't know).
Also I was going through white paper published on http://www.oracle.com/technetwork/java/javase/tech/memorymanagement-whitepaper-1-150020.pdf regarding JVM garbage collection but unable to get clear difference between garbage collection algorithm and garbage collector.
Some where document mentioned "Young Generation Garbage Collection Algorithm/ Old Generation Garbage Collection Algorithm".
Does it mean Serial Garbage Collector (type of garbage collector) uses "young generation garbage collection algorithm" as well as "old generation garbage collection algorithm" to do GC on young and old generation area respectively.
Please help me to get clear understanding of type of algorithm and type of garbage collector.
Upvotes: 2
Views: 2150
Reputation: 43097
What I think these are types of garbage collectors which implements some specific algorithm (name of algorithms which I don't know).
The ones you listed usually are used as names for specific GC implementations in context of Oracle HotSpot JVM, with all the implementation-specific details, tuning options etc. and other real-world oddities they entail. Of course they are also based on abstract algorithms, which may share their names or could be described in some scientific publications glossing over details and just modelling their theoretic behavior.
The distinction is not always so clear-cut. A serial GC is the most primitive algorithm: mark-sweep, stop-the-world, single-threaded. Depending on the JVM it may or may not be compacting. If I recall correctly older android VMs didn't compact in their serial GC implementation.
So really, the nomenclature is context-specific. If you're reading a research paper about a parallel, compacting, concurrent, pauseless collector it does not refer to hotspot's throughput (parallel old gen), parallel scavenge (parallel young generation) or parnew (young generation collector cooperating with CMS for old gen) collector just because the word parallel is mentioned. If you read, maybe a blog post, describing performance characteristics of specific GCs with actual measurements they probably refer to the hotspot implementations.
Here's a list of hotspot's collectors and their relations, subject to change due to pending JEPs
Upvotes: 2
Reputation: 481
Uff let me try to explain this somehow :)
The garbage collector can have different algorithms - such as Mark&Sweep, Mark&Compact, Reference Counting, etc - (usally decided by how performant your system is and also the scope of your application). Applications create objects on the heap. Since most of these objects die young, the heap will be separated into two main regions: Young generation and Old generation. Objects will always land first in the young geneartion. There you have algorithms which will then promote some of the objects into old generation. Because handling the objects in the old generation usally takes a lot of performance, the target is to let objects die as young as possible. (This is explained really basic - Young genearation is also divided into Eden and Survivor Space - so I try to give a simple overview).
So the garbage collector uses different algorithms for the different geneartions (young and old). Furthermore you don't only separate by algorithms but also by how they are executed: Serial, Parallel,Concurrent...etc.
Serial
Means the garbage colletor is running in serial mode. Serial mode will be used if you only have on core. If you use serial, the garbage collector stops the world (stw phase) and clears the objects on the heap. This can reduce performance of your application.
Parallel
The garbage colletor is running in a parallel mode. This mode uses the advantage of multi core systems. So the task to clean the heap is run in threads. This way the garbage collector needs less time to clear the heap. But you will still have stw-phases but they take less time.
CMS - Concurrent
This garbage colletor runs in a concurrent mode. So in some phases of the garbage collector, the tasks run next to the application. For example Concurrent Mark & Swepp:
Initial Mark Phase - Serial
Mark Phase - Concurrent
Remark Phase - Parallel
Sweep Phase - Concurrent
In the concurrent phases you won't have STW Phases.
G1
Is a special garbage colletor developed by SUN (or was it IBM?). Currently all algorithms have Stop-The-World - Phases. With G1 they tried to say how long these Phases will take. This is a really complicated algorithm but also with this, it is not possible to say how long the stw phase will take.
Upvotes: 4