为什么PermGen的默认大小如此之小? [英] Why is the default size of PermGen so small?

查看:135
本文介绍了为什么PermGen的默认大小如此之小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限制Java JVM上Permgen空间大小的目的是什么?为什么不总是将它设置为最大堆大小?为什么Java默认这么少的64MB?他们是否试图强迫人们通过这样做来注意代码中的permgen问题?

What would be the purpose of limiting the size of the Permgen space on a Java JVM? Why not always set it equal to the max heap size? Why does Java default to such a small number of 64MB? Are they trying to force people to notice permgen issues in their code by doing this?

如果我的应用程序使用85MB的permgen,那么将它设置为96MB可能是安全的,但为什么如果它只是主堆的真正部分呢?允许JVM在堆允许的情况下使用尽可能多的PermGen不是很有效吗?

If my app uses 85MB of permgen, then it might be safe to set it to 96MB but why set it so small if its just really part of the main heap? Wouldn't it be efficient to allow the JVM to use as much PermGen as the heap allows?

推荐答案

从概念上讲,程序员,你可以说永久性一代在很大程度上毫无意义。如果你需要加载一个类或其他永久数据并且还剩下内存空间,那么原则上你也可以将它加载到某个地方而不关心将这些项的集合称为生成。

Conceptually to the programmer, you could argue that a "Permanent Generation" is largely pointless. If you need to load a class or other "permanent" data and there is memory space left, then in principle you may as well just load it somewhere and not care about calling the aggregate of these items a "generation" at all.

然而,理由可能更多:


  • 可能有一个好处(例如,从处理器缓存的角度来看)使所有代码/类元数据在存储空间中靠近在一起,并且为了保证这一点,更容易分配固定大小的区域;

  • 类似,存储代码/类元数据的内存空间可能具有某些特殊属性(特别是,如果可以帮助它,您不希望它被分页到磁盘)并且系统可能无法设置此类属性内存以非常精细的方式,因此在一个(或少数)连续的块或内存空间中将所有特殊对象放在一起更为实际;

  • 具有永久对象一起帮助避免id分割剩余的内存空间,最实际的方法是从一开始就分配一个固定大小的连续内存块。

所以当我看到事情时,大多数时候分配永久代的原因实际上是出于实际的实现原因而不是因为程序员真的非常关心。

So as I see things, most of the time the reason for allocating a permanent "generation" is really for practical implementation reasons than because the programmer really cares terribly much.

另一方面,对于程序员来说情况通常也不是很糟糕:所需的永久生成量通常是可预测的,因此您应该能够以合理的余地分配所需的数量。因此,如果您发现意外地超出了分配范围,这可能是严重错误的信号。

On the other hand, the situation isn't usually terrible for the programmer either: the amount of permanent generation needed is usually predictable, so that you should be able to allocate the required amount with decent leeway. So if you find you are unexpectedly exceeding the allocation, this may well be a signal that "something serious is wrong".

N.B。可能的情况是,PermGen最初设计要解决的一些问题在具有更大处理器缓存的现代64位处理器上并不是那么大的问题。如果在将来的Java版本中将其删除,这可能表明JVM设计人员认为它现在已经达到了目的。

N.B. It is probably the case that some of the issues that the PermGen originally was designed to solve are not such big issues on modern 64-bit processors with larger processor caches. If it is removed in future releases of Java, this is likely a sign that the JVM designers feel it has now "served its purpose".

这篇关于为什么PermGen的默认大小如此之小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆