1. GC and GC Tuning

Basics 1. GC's
1.1 What is garbage
  1. No references to an object or plurality of objects (circular references)
  2. C language application memory: malloc free
  3. C++: new delete
  4. Java: new automatic recovery
    1. Programming is simple, the system is not error-prone, manual recovery may occur forget recovery (memory leaks) and multiple recovery (recovery of useful data)
1.2 Positioning garbage
  1. Reference counting: reference counting, it will store the reference number of variables on the object when the reference count is 0, considered to be junk, but this program can not find a circular reference
  2. Root up: root searching, with all the static variables, local variables within the thread stack, constant pool, JNI pointer as the root references, along the root of the referenced object can not find the garbage, others are rubbish
1.3 garbage collection algorithm
  1. Clear labeling: memory fragmentation
  2. Copy algorithm: free of debris, waste of space
  3. Compression markers: no debris, no waste of space, but inefficient
1.4 JVM memory generational model
  1. For garbage collection algorithm, can be JVM memory can be divided by generations (generation), this is a generational JVM memory model
  2. + + 'S permanent new generation of old-generation (1.7) / metadata area (Metaspace) (1.8)
    1. Permanent Generation / metadata area: Class object stored clazz, a string constant, MethodArea (logical concept)
    2. Generation permanent must specify the size limit, the metadata may be provided, may not be provided, without limit (limited by the physical memory)
    3. String constants: 1.7 in the permanent generation heap 1.8
    4. MethodArea logical concept - Generation of permanent, metadata
      Here Insert Picture Description
  3. New Generation = Eden + 2 th region suvivor
    1. YGC (Minor GC): the content of the new generation for recycling, since the contents of the new generation is typically recovered off-round, so YGC for copying the recovery algorithm, and the copy algorithm requires additional space, thus creating a survivor
    2. First YGC: Most of the objects are recovered alive into the s0
    3. YGC again: the living objects eden + s0 -> s1
    4. YGC again: eden + s1 -> s0
    5. Old enough: years old
    6. s area fit: fit portions years old
  4. Years old
    1. FGC (Major GC): Full GC, old and full of years will produce FGC, the entire memory is recovered, inefficient and will produce stw (stop-the-world) pause, namely the suspension of all the currently running thread
    2. FGC mark itself using compression algorithms, slower
  5. GC Tuning (Generation): minimize FGC
1.5 Common garbage collector

Here Insert Picture Description

  1. Serial younger generation serial recovery: When eden full, all threads stop working, the garbage collector thread begins execution, after completion of garbage, re-execute the other thread
  2. PS parallel scavenge: the young generation parallel recovery, but for all threads to stop, but start multiple threads for garbage collection
  3. ParNew: the young generation with concurrent recovery of the CMS, the PS same, the difference is, he must be used with CMS, ps not
  4. SerialOld:
  5. ParallelOld:
  6. ConcurrentMarkSweep (CMS) years old concurrent, garbage collection and applications running at the same time, reducing the STW (garbage collection caused the program to stop) time (less than 200ms)
  7. G1(10ms):
  8. ZGC (1ms) :PK C++
  9. Shenandoah:
  10. Eplison: Debugging with jdk

1.8 The default garbage collection: PS + ParallelOld

Tuning 6.JVM first step, the garbage collector to understand the composition of the production

  • JVM command-line arguments Reference: https: //docs.oracle.com/javase/8/docs/technotes/tools/unix/java.html

  • JVM arguments classification

    Standard: - at the beginning, all of the HotSpot support

    Non-standard: -X beginning, a specific version of HotSpot supports a particular command, enter java -X command line you can see what are the -X command

    Unstable: beginning -XX, the next version may be canceled

    -XX: + when PrintCommandLineFlags print start command line parameters

    -XX: + PrintFlagsFinal final parameter value

    -XX: + PrintFlagsInitial default parameter values

    -XX:+UseG1GC

Reference material

  1. https://blogs.oracle.com/
    jonthecollector/our-collectors
  2. https://docs.oracle.com/javase/8/docs/technotes/tools/unix/java.html
  3. http://java.sun.com/javase/technologies/hotspot/vmoptions.jsp
Published 43 original articles · won praise 0 · Views 1369

Guess you like

Origin blog.csdn.net/hanzong110/article/details/104693331