JVM
- Executes Java bytecode
- Provides platform independence
- Manages memory automatically
- Handles garbage collection
- Runs Java applications
Just in Time compiler
- Compiles bytecode into native
- Optimizes frequently executed methods
- Improves runtime performance
- Runs during program execution
- Reduces repeated interpretation
Heap Memory
- Stores object instances
- Shared among all threads
- Managed by garbage collector
- Created during JVM startup
- Supports dynamic memory allocation
mutator
- Application thread creating objects
- Runs alongside garbage collector
- Modifies heap objects
- Consumes allocated memory
collector
- Reclaims unused heap objects
- Runs garbage collection process
- Manages memory cleanup
- Works with mutator threads
- Improves memory utilization
Garbage Collector
- Reclaims unused heap memory
- Removes unreachable objects
- Prevents memory leaks
- Runs automatically by JVM
- Reduces manual memory management
Memory Leaks
- Unused objects still referenced
- Garbage collector cannot reclaim
- Heap memory gradually grows
- Causes OutOfMemoryError eventually
- Remove unnecessary object references
Serial Garbage Collector
- Uses single GC thread
- Stops all application threads
- Simple, low-overhead collector
- Best for small heaps
- Unsuitable for large applications
Young Generation
- Stores newly created objects
- Collected frequently by GC
- Contains Eden and Survivor
- Most objects die quickly
- Fast garbage collection
Survivor
- Stores surviving young objects
- Located in Young Generation
- Contains S0 and S1
- Objects age after GC
- Promoted after threshold
Old Generation
- Stores long-lived objects
- Receives promoted objects
- Collected less frequently
- Uses major garbage collection
- Larger than Young Generation
Parallel Garbage Collector
- Uses multiple GC threads
- Stops application during collection
- Maximizes garbage collection throughput
- Suitable for multi-core CPUs
- Default before Java 9
Concurrent Mark Sweep Garbage collector
- Runs alongside application threads
- Minimises pause times
- Performs concurrent collection
- Improves application responsiveness
CMS phases
Initial Mark: Briefly pauses application threads to identify root objects.
Concurrent Mark: Traverses the object graph while the application is still running.
Remark: Pauses the application briefly to finalize marking updates.
Concurrent Sweep: Reclaims unreachable objects concurrently.
Concurrent Reset: Prepares the data structures for the next cycle.
fragmentation
- Free memory becomes scattered
- Small gaps remain unused
- Large allocations may fail
- Occurs after object deletion
- Compaction removes fragmentation
Garbage First Garbage Collector
- Heap divided into regions
- Collects highest garbage first
- Reduces pause times
- Performs concurrent background marking
- Default since Java 9
tuning of serial garbage collector
- Set initial heap size
- Set maximum heap size
- Adjust Young Generation size
- Enable Serial GC option
- Monitor GC pause times
tuning of parallel garbage collector
- Adjust parallel GC threads
- Set heap size limits
- Tune Young Generation size
- Configure throughput target
- Monitor GC performance logs
tuning of CMS garbage collector
- Set CMS initiating occupancy
- Enable parallel remark phase
- Tune Young Generation size
- Reduce fragmentation frequency
- Monitor concurrent GC logs
tuning of G1 garbage collector
- Set maximum pause target
- Adjust heap region size
- Configure heap size limits
- Tune concurrent GC threads
- Monitor GC pause logs
No comments:
Post a Comment