Are ratios between spaces/generations in the Java Heap constant?

前端 未结 3 423
离开以前
离开以前 2020-12-24 10:29

I have read this article about virtual machine garbage collection tuning to understand the java garbage collector better. Each space has a Virtual heap space area

相关标签:
3条回答
  • 2020-12-24 10:36

    I think you are referring to GC Ergonomics and the Adaptive Size Policy

    • a feature of the Hotspost GC that automatically adapts the sizes of the generations at runtime based on the current allocation behavior of the running application.
    • This feature is ON by default and controls/adapts the size of the generations at runtime.
    • in fact, some of the GC parameters will be ignored if you do not disable Adaptive Size policy, eg. -XX:SurvivorRatio=.

    You can disable the Adaptive Size Policy by using the -XX:-UseAdaptiveSizePolicy. Once you disabled the AdaptiveSizePolicy, the GC will respect the initial size of the generations as specified by your startup parameters (e.g. -Xms, -Xmx, -XX:MaxNewSize=,-XX:NewSize=, -XX:SurvivorRatio=) and they will remain constant.

    You can find more on Adaptive Size policy in UseAdaptiveSizePolicy and other jvm opts.

    0 讨论(0)
  • 2020-12-24 10:56

    Edit: I think I may have something wrong. Putting this note here while I investigate, to keep from sending folks down the wrong path!

    Ales0x's answer is great if you are using Parallel Scavenge GC (-XX:+UseParallelGC), but Concurrent Mark-Sweep GC (-XX:+UseConcMarkSweepGC) does not support adaptive sizing.

    With Concurrent Mark-Sweep, the new/young generation size is set based on the initial heap size (unless you specify -XX:NewSize=). The new generation size will not change as the heap grows.

    0 讨论(0)
  • 2020-12-24 10:59

    PermGen vs Young generation ratio is partially maintained by JVM, but to say if ratio is maintained, the answer is No.

    JVM7 has become sufficiently advanced and complicated where we shouldn't predict the allocation of generations inside heap.

    In every GC cycle that JVM runs, it also does metric analysis to learn of current applications in-memory storage behavior. - If more objects are surviving the multiple cycles of GC, then PermGen is reduced and some of the space is allocated to YoungGeneration. Basically No. of objects x number of GC cycles they skip plays a criteria in dynamically adjusting the generation ratio.

    I hope it helps, thanks.

    0 讨论(0)
提交回复
热议问题