官方调优建议:https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/
一、堆分配
Default Arrangement of Generations, Except for Parallel Collector and G1
Arrangement of Generations in the Parallel Collector
Heap Division by G1
二、垃圾回收中用到的算法
1.Root Searching 根可达算法
FollowReferences(jvmtiEnv* env, jint heap_filter, jclass klass, jobject initial_object, const jvmtiHeapCallbacks* callbacks, const void* user_data)
This function initiates a traversal over the objects that are directly and indirectly reachable from the specified object or, if initial_object
is not specified, all objects reachable from the heap roots.The heap root are the set of system classes, JNI globals, references from thread stacks, and other objects used as roots for the purposes of garbage collection.
引用自https://docs.oracle.com/javase/8/docs/platform/jvmti/jvmti.html
通过其他渠道获取的说法为,如下情况的对象可以作为GC Roots:
2.mark-sweep
容易产生碎片,多用于老年代
3.copying
会产生空间浪费,多用于新生代
4.mark-compact
需要移动对象,效率相对较低,多用于老年代
5.三色标记
黑色:根对象,或者该对象与它的子对象都被扫描过。
灰色:对本身被扫描,但是还没扫描完该对象的子对象。
白色:未被扫描对象,如果扫描完所有对象之后,最终为白色的为不可达对象,既垃圾对象。
三色标记的问题,如果在标记过程中引用关系发生变化,会导致白色对象漏标,被错误回收。
解决方案:CMS采用了Increamental Update 当白色对象被黑色对象引用时,重新将黑色对象标记为灰色,让collector重新扫描
G1采用了SATB(snapshot at the beginning),维护一个快照表,将被删除的引用放到GC的堆栈中,保证还能被gc扫描到。
三、常见垃圾回收器
1. Serial
2. Parrallel Scavenge
3. ParNew
4. SerialOld
5. ParallelOld
6. ConcurrentMarkSweep
三色标记 + Incremental Update
7. G1
三色标记 + SATB+CSet+RSet+Card Table
8. ZGC
ColoredPointers + LoadBarrier
四、常见垃圾回收器组合参数设定(1.8)
HotSpot会根据计算及配置和JDK版本自动选择收集器
-XX:+UseSerialGC = Serial New (DefNew) + Serial Old
-XX:+UseConc(urrent)MarkSweepGC = ParNew + CMS + Serial Old
-XX:+UseParallelGC = Parallel Scavenge + Serial Old(1.8默认) 高吞吐量
-XX:+UseParallelOldGC = Parallel Scavenge + Parallel Old
-XX:+UseG1GC = G1 低停顿
原文:https://www.cnblogs.com/macbk/p/13624500.html