JVM-GC总结

作者: 老生住长亭 | 来源:发表于2018-05-02 20:45 被阅读2次

Four types of garbage collector available in Java.

  1. Serial Garbage Collector (-XX:+UseSerialGC)
  2. Parallel Garbage Collector (-XX:+UseParallelGC)
  3. CMS Garbage Collector (-XX:+UseConcMarkSweepGC)
  4. G1 Garbage Collector (–XX:+UseG1GC)
a6e93294-5c41-4a13-943c-f57c2e9b1493.jpg
  1. Serial Garbage Collector(-XX:+UseSerialGC)
    This garbage collector only uses for the very small application that easily runs on the single core CPU.It's holding all threads of an application during garbage collection.It is created only for single-threaded applications and this only use single thread for garbage collection.When it is doing garbage collection then it freezes all threads of an application.This is not suitable for multiple user application if We will use this then will drop the performance of application significantly.

2.Parallel Garbage Collector(-XX:+UseParallelGC)
This garbage collector is also freeze all threads of the application during garbage collection process but unlike serial garbage collector, this uses multiple threads for garbage collection.It is default collector of JVM. It is also known as throughput GC. The garbage collector is suited best for those applications that can bear application pauses .

  1. CMS Garbage Collector(-XX:+UseConcMarkSweepGC)
    This garbage collector uses multiple threads(“concurrent”) at the same time to scan the heap memory and mark in that available for eviction(“mark”) and then sweep the marked instances (“sweep”). This garbage collector is entered stop the world mode only in two cases
    1.During marking the referenced objects in the old generation space.
    2.Any change in heap memory in parallel with doing the garbage collection
    STW time of CMS garbage collector is very short.

  2. G1 Garbage Collector(–XX:+UseG1GC)
    This garbage collector introduced in JDK 7 update 4 was designed to better support larger heap size application.It uses multiple threads to scan through the heap that it divides into different regions and size of the region depend on heap size of the application.This garbage collector scans that region first that contains maximum available garbage object that is reason giving it its name (Garbage first). G1 also does compact the free heap space just after garbage collection.
    In Java 8, some improvements are done in the G1 garbage collector.Using -XX:+UseStringDeduplication JVM argument using with the G1 garbage collector. This helps to remove duplicate strings values to a single value to a single char[] array.this is introduced in Java 8 u 20.

JVM结构:

3631975667-54f7c08e5bf91_articlex.png

JVM = 类加载器 classloader + 执行引擎 execution engine + 运行时数据区域 runtime data area
classloader 把硬盘上的class 文件加载到JVM中的运行时数据区域, 但是它不负责这个类文件能否执行,而这个是 执行引擎 负责的。

Heap组成

3486491155-54f7c0a9eddd5_articlex.png

相关文章

  • JVM-GC总结

    Four types of garbage collector available in Java. Serial...

  • JVM-GC总结

    参考自:JVM内存管理------GC简介 - 左潇龙 - 博客园 Java垃圾回收机制 - zsug...

  • 【 转】Java中的垃圾回收机制

    原文地址:https://yemengying.com/2016/05/13/jvm-GC/【 译】Java中的垃...

  • JVM-GC

    1. 分代 依据:大多数新分配对象的存活时间很短(很少的对象存活时间长)、存活时间久的对象很少引用存活时间短的对象...

  • JVM-GC

    https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-2...

  • jvm-GC详解

    0.jvm如何判断对象已死 可达性分析法:如下图所示,从GC Roots节点开始找寻引用链,一旦发现对象不可达,例...

  • JVM-GC基础

    基本的垃圾回收算法 引用计数(Reference Counting) 增加一个引用,引用计数加1,去掉一个引用,引...

  • JVM-GC基础

    GC基础 by shihang.mai 1. 引用类型 1.1 StrongReference强引用 回收时间:垃...

  • JVM-GC(2)

    JVM-GC(2) 垃圾收集器 CMS收集器 CMS收集器是一种以获取最短回收停顿时间为目标的收集器。CMS收集器...

  • JVM-GC(1)

    JVM-GC(1) 分代收集理论 分代收集建立在两个分代假说之上: 弱分代假说:绝大多是对象都是朝生夕灭的/大多数...

网友评论

    本文标题:JVM-GC总结

    本文链接:https://www.haomeiwen.com/subject/lrqhrftx.html