简体   繁体   English

JVM -Xmn 内存

[英]JVM -Xmn memory

My jvm memory allocation scheme.我的 jvm 内存分配方案。

-Xms2048m -Xmx2048m -Xmn1536m -Xms2048m -Xmx2048m -Xmn1536m

The official recommendation is that the young generation is 3/8 of the heap memory.官方推荐年轻代是堆内存的3/8。

if the memory allocated by my -Xmn is small or large.如果我的 -Xmn 分配的内存是小还是大。 What effect will it have?它会产生什么影响?

The size of the young generation will determine the time between minor GCs.年轻代的大小将决定次要 GC 之间的时间。 Objects are allocated in the Eden space using a simple pointer bumping approach, which is very fast (for multiple threads it is a bit more complicated by having thread local allocation blocks to eliminate the issue of contention).使用简单的指针碰撞方法在 Eden 空间中分配对象,这种方法非常快(对于多线程来说,通过使用线程本地分配块来消除争用问题会稍微复杂一些)。 The bigger your Eden space, the longer your application can create objects before the allocation pointer(s) reach the end of the address space. Eden 空间越大,应用程序在分配指针到达地址空间末尾之前创建对象的时间就越长。

When no more objects can be allocated in Eden space, a minor GC is performed that copies live objects from Eden to a survivor space and promotes objects that have reached the tenuring threshold to the old generation.当 Eden 空间中没有更多对象可以分配时,会执行一次次要 GC,将活动对象从 Eden 复制到幸存者空间,并将已达到年限阈值的对象提升到老年代。 Most objects are very short-lived (the weak generational hypothesis) so, typically, only a small number of objects need to be copied.大多数对象的生命周期都很短(弱世代假设),因此,通常只需要复制少量对象。 Making your Eden space larger will also mean more objects have a chance to be dereferenced and you will end up placing a lower load on the old generation.使你的 Eden 空间更大也意味着更多的对象有机会被取消引用,你最终会给老年代带来更低的负载。

The 3/8 advice is good for a wide range of applications. 3/8 建议适用于广泛的应用。 Obviously, for different applications, you may tune this up or down to fit the memory usage profile.显然,对于不同的应用程序,您可以向上或向下调整以适应内存使用情况。 One important rule to follow though is to keep the young generation less than 50% of the heap space (ie the young generation should always be smaller than the old generation).但要遵循的一个重要规则是保持年轻代小于堆空间的 50%(即年轻代应始终小于年老代)。 The reason for this is that, if not, the collector will run a major GC every time a minor GC is run.这样做的原因是,如果没有,收集器将在每次运行次要 GC 时运行一次主要 GC。 This is because the collector needs to ensure there is enough space in the old gen to promote objects from the young gen.这是因为收集器需要确保老一代中有足够的空间来提升年轻代中的对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM