GC basics
1. What is garbage
C language application memory: malloc, free
C++: new、delete
Java: new, automatic recycling
Automatic memory recovery is simple in programming, and the system is not prone to errors. Manually releasing memory can easily cause two types of problems:
- Forget to recycle
- Multiple recycling
2. How to locate garbage
- Reference count
- Root reachability algorithm
3. Common garbage collection algorithms
Mark removal : discontinuous position, resulting in memory fragmentation
Copy algorithm : no memory fragmentation, waste of space
Mark compression : no memory fragmentation, low efficiency
4. JVM memory generation model (used for generational garbage collection algorithm)
Generational garbage collection process
- Model used by some garbage collectors
- New Generation + Old Generation + Permanent Generation (1.7)/ Metaspace (1.8) Metaspace
- Permanent Generation Metadata-Class
- The permanent generation must specify the size limit, the metadata can be set or not, and there is no upper limit (limited by physical memory)
- String constant 1.7-permanent generation, 1.8-heap
- MethodArea logical concept-permanent generation, metadata
- Cenozoic = Eden + 2 suvivor areas
- After minor_gc is reclaimed, most of the objects will be reclaimed, and the living objects enter s0
- Minor_gc again, the living object enters s1 from eden + s0
- Minor_gc again, the living object enters s0 from eden + s1
- Old enough to enter the old age (Parallel 15 times, CMS 6 times)
- The suvivor area can’t fit, and it goes straight to the old age
- Old age
- Diehard
- The old age is full of Major_gc, Full GC
- GC tuning
- Minimize Full GC
- Minor GC = YGC; Young GC Minor GC; insufficient Eden area
- Major GC = FGC; Old space is insufficient, System.gc()
5. Common garbage collectors
- Serial Young generation single-threaded serial recovery
- Parallel Scavenge referred to as PS Young generation multi-threaded parallel recycling
- ParNew young generation with parallel recycling of CMS
- Serial Old Single-threaded serial recycling
- Parallel Old Multi-threaded parallel recycling
- ConcurrentMarkSweep old low multi-threaded concurrent, garbage collection and application running at the same time, reducing STW time (200ms)
- G1(10ms)
- ZGC (1ms) can be used with C++ PK
- Shenandoah
- Eplison
JDK1.8 default garbage collector: Parallel Scavenge + Parallel Old
6. The first step of JVM tuning is to understand the garbage collector combination in the production environment
- JVM command line parameter reference: https://docs.oracle.com/javase/8/docs/technotes/tools/unix/java.html
- JVM parameter classification:
- Standard:-At the beginning, all HotSpot support
- Non-standard:-At the beginning, specific versions of HotSpot support specific commands
- Unstable: Start with -XX, the next version may be cancelled
- Commonly used:
- -XX:+PrintFlagsFinal setting value (final effective value)
- -XX:+PrintFlagsInitial default value
- -XX:+PrintCommandLineFlags command line parameters
Reference materials:
- Garbage collector: https://blogs.oracle.com/jonthecollector/our-collectors
- JVM command line parameter reference: https://docs.oracle.com/javase/8/docs/technotes/tools/unix/java.html
At the end of the article, I recommend some popular technical blog links :
- JAVA related deep technical blog link
- Flink related technical blog links
- Spark core technology link
- Design Pattern-Deepin Technology Blog Link
- Machine learning-deep technology blog link
- Hadoop related technical blog links
- Super dry goods-Flink mind map, it took about 3 weeks to compile and proofread
- Deepen the core principles of JAVA JVM to solve various online faults [with case]
- Please talk about your understanding of volatile? --A recent "hardcore contest" between Xiao Lizi and the interviewer
- Talk about RPC communication, an interview question that is often asked. Source code + notes, package understanding
- In-depth talk about Java garbage collection mechanism [with schematic diagram and tuning method]
Welcome to scan the QR code below or search the public account "Big Data Senior Architect", we will push more and timely information to you, welcome to communicate!