`

Java内存管理-Permanent Space

阅读更多

VM 的Permanent generation space,实际上就是方法区,存储了下面两种类型的数据:

 

1.Class的节本信息

Package Name
Super class package name
Class or interface
Type modifiers
Super inferface package name

 

2.其它信息

The constant pool for the type
Field information
Method information
All class (static) variables declared
in the type, except constants
A reference to class ClassLoader
A reference to class Class

 

其中constant pool包含以下信息:

literal strings

注:如String s="abc",这样的字面值,是从pool中取的,如果取不到会在池中存储一份,如果另外有个变量String t=“abc”,它首先会在pool中拿,如果能拿到,则不会新创建一份,String.intern方法也一样,因此用intern方法要特别注意,容易导致perm space out of memory
 final variable values

如final s = “”;
 class names
 method names
String.intern();

 

另外要注意,在默认情况下,perm space是可以被垃圾收集的(除了CMS垃圾收集器之外),不再使用的class将会被unload,用参数-Xnoclassgc可以设置让perm space不卸载不再使用的class。

 

一般GC算法也是会照顾permanent generation的,每次permanent generation满了要做扩展前都会触发一次FULL GC,除非设置了-Xnoclassgc。 

       另外如果使用CMS(ConcMarkSweep GC)算法的话,开了-XX:+UseConcMarkSweepGC标志,默认情况下就是不会扫描permanent generation的,需要同时打开下面两个标志位才能让CMS GC扫描permanent generation。
-XX:+CMSPermGenSweepingEnabled
-XX:+CMSClassUnloadingEnabled 

       只针对SUN的JVM有效。

0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics