JVM中将MethodArea 作为PermannentArea管理的弊端

发布时间:2017-1-24 8:59:44 编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"JVM中将MethodArea 作为PermannentArea管理的弊端",主要涉及到JVM中将MethodArea 作为PermannentArea管理的弊端方面的内容,对于JVM中将MethodArea 作为PermannentArea管理的弊端感兴趣的同学可以参考一下。

在HotSpot JVM的设计中, Method Area部分是用PermanentGeneration 来指代和管理的,PermanentGeneration包含类信息,常量,静态变量,字符串常量池等。 SUN的jvm内存池被划分为以下几个部分: Eden Space (heap) 内存最初从这个线程池分配给大部分对象。 Survivor Space (heap) 用于保存在eden space内存池中经过垃圾回收后没有被回收的对象。 Tenured Generation (heap) 用于保持已经在survivor space内存池中存在了一段时间的对象。 Permanent Generation (non-heap) 保存虚拟机自己的静态(reflective)数据,例如类(class)和方法(method)对象。Java虚拟机共享这些类数据。这个区域被分割为只读的和只写的。 这并不是一个好主意,因为容易引起内存yi'chu'wen'ti溢出问题。永久代有-XX MaxPermSize的上限。 对于HotSpot虚拟机,根据JDK 1.7 的发布信息,已经把原本放在永久代中的字符串常量池移出。 http://openjdk.java.net/jeps/122 说的很清楚: Description Move part of the contents of the permanent generation in Hotspot to the Java heap and the remainder to native memory. Hotspot’s representation of Java classes (referred to here as class meta-data) is currently stored in a portion of the Java heap referred to as the permanent generation. In addition, interned Strings and class static variables are stored in the permanent generation. The permanent generation is managed by Hotspot and must have enough room for all the class meta-data, interned Strings and class statics used by the Java application. Class metadata and statics are allocated in the permanent generation when a class is loaded and are garbage collected from the permanent generation when the class is unloaded. Interned Strings are also garbage collected when the permanent generation is GC’ed. The proposed implementation will allocate class meta-data in native memory and move interned Strings and class statics to the Java heap. Hotspot will explicitly allocate and free the native memory for the class meta-data. Allocation of new class meta-data would be limited by the amount of available native memory rather than fixed by the value of -XX:MaxPermSize, whether the default or specified on the command line. Allocation of native memory for class meta-data will be done in blocks of a size large enough to fit multiple pieces of class meta-data. Each block will be associated with a class loader and all class meta-data loaded by that class loader will be allocated by Hotspot from the block for that class loader. Additional blocks will be allocated for a class loader as needed. The block sizes will vary depending on the behavior of the application. The sizes will be chosen so as to limit internal and external fragmentation. Freeing the space for the class meta-data would be done when the class loader dies by freeing all the blocks associated with the class loader. Class meta-data will not be moved during the life of the class.

上一篇:HDOJ 4725 - The Shortest Path in Nya Graph 构图最短路(priority_queue+dijkstra)