Garbage collection process is run by a daemon thread, processing involves
Mark: To mark objects as reachable/unreachable
Delete/Sweep: To delete unreachable objects from heap space
Compacting: Making allocation contagious & fragmented
GL Logging: -verbose: gc, --XX:+PrintGCDetails, -Xloggc:gc.log (NOT much overhead, but useful if GC is suspect)
Heap space is divided as follows
Serial: Works with single thread, pauses the app, to be used where pause time matters less
Concurrent: Called as CMS (Concurrent Mark Sweep) using multiple threads along with the app. To be used where there is more memory, short pause time acceptable (for mark/remark only) and the app has resources (CPU) to share with GC.
Parallel: Uses multiple CPUs for GC, does not kick until heap is full/near-full. Pauses the app when it runs. To be used when there is less memory, less CPUs and the app can accept pauses.
G1 (Garbage First): Partitions the heap space into equal-sized regions. It ‘marks’ all the regions and then collects in ‘mostly empty’ areas, freeing up space. To be used where there is high memory, high CPU. It is combination of concurrent & parallel
No comments:
Post a Comment