G1垃圾回收器是JDK 7中Java HotSpot VM新引入的垃圾回收器,用于替代HotSpot低延迟的并行标记清除垃圾回收器。
G1是一个server端垃圾回收器。
目前G1仍然是一个试验产品,使用下列参数开启G1回收器:
-XX:+UnlockExperimentalVMOptions -XX:+UseG1GC
设置一个GC暂停间隔:
-XX:MaxGCPauseMillis =50 (停顿间隔50ms)
JDK8: Metaspace
In JDK 8, classes metadata is now stored in the native heap and this space is called Metaspace. There are some new flags added for Metaspace in JDK 8:
-XX:MetaspaceSize= where is the initial amount of space(the initial high-water-mark) allocated for class metadata (in bytes) that may induce a garbage collection to unload classes. The amount is approximate. After the high-water-mark is first reached, the next high-water-mark is managed by the garbage collector
-XX:MaxMetaspaceSize= where is the maximum amount of space to be allocated for class metadata (in bytes). This flag can be used to limit the amount of space allocated for class metadata. This value is approximate. By default there is no limit set.
-XX:MinMetaspaceFreeRatio= where is the minimum percentage of class metadata capacity free after a GC to avoid an increase in the amount of space (high-water-mark) allocated for class metadata that will induce a garbage collection.
-XX:MaxMetaspaceFreeRatio= where is the maximum percentage of class metadata capacity free after a GC to avoid a reduction in the amount of space (high-water-mark) allocated for class metadata that will induce a garbage collection.
参考文献:
About G1 Garbage Collector, Permanent Generation and Metaspace