"In-depth understanding of virtual machine" reading notes-memory allocation and recycling strategy

Memory allocation and recycling strategy

  • Overview
    • The objects are mainly distributed in the Eden district of the new generation.
    • If the local thread buffer (tlab) is started, the priority is allocated according to the thread.
    • A few large objects will be allocated directly in the old generation.
    • The allocation rules are not fixed, and mainly depend on the combination of the garbage collector and related parameter settings.
  • -XX:+PrintGCDetails
    • Print GC information
  • Objects are allocated first in Eden
    • When Eden is not continuous enough to allocate objects, Minor GC is triggered to transfer the living Eden objects and Survivor objects to another Survivor.
    • If the Survivor space is not enough for storage, it will be transferred to the old generation in advance through the allocation guarantee mechanism.
  • Large objects go directly into the old generation
    • Large objects: objects that require a lot of continuous memory space.
    • -XX:PretenureSizeThreshold=xxx(byte)
      • Set the threshold for large objects. Making objects larger than this setting is worth assigning directly in the old generation.
      • The purpose is to avoid a lot of memory copying between the Eden area and the two Survivor areas.
      • Only supports Serial and ParNew
  • Long-lived objects enter the old age
    • Object age counter
    • When the subject first Minor Gc and moves into Survivor, the subject's age is set to 1.
    • After every Minor Gc experience in Survivor, age +1;
    • When the age increases to a certain level (default 15), then promoted to the old age
    • -XX:MaxTenuringThreshold
  • Dynamic object age determination
    • If the sum of the size of all objects in the Survivor space of the same age is greater than half of the Survivor space, then all objects greater than or equal to the age directly enter the old age.
  • Space allocation guarantee
    • Before Minor GC, the virtual machine checked whether the largest contiguous space available in the old generation was larger than the size of all objects in the new generation or the average size of previous promotions.
    • If it is greater, it is judged to perform Minor GC, otherwise Full GC
    • Before 1.6, the beginning was to check the size of all objects in the new generation. If it passed, then Minor GC was directly used. If it does not pass, it is judged whether the setting value of HandlePromotionFailure allows the guarantee to fail. If allowed, Minor GC will be performed only if it is judged to be greater than the average size of previous generations. Otherwise the parameter is not allowed or the size is not allowed then Full GC
Published 24 original articles · praised 0 · visits 101

Guess you like

Origin blog.csdn.net/jiangxiayouyu/article/details/105614254