Java虚拟机

Java虚拟机内存管理

2018-07-19  本文已影响0人  黄金矿工00七
Java内存区域

详细的描述在下面的文章中都说过,不在赘述
《Java内存区域划分》

Java内存区域划分
这里重点说一下方法区在Java不同版本中的位置以及堆内存的划分。
堆内存划分为新生代、老年代
堆划分

(Java8之前,Java8已经没有了永生代)这里有个坑要说一下,很多人以为永生代也在堆内,这是错误的,为啥嘞,说的简单点,堆为啥要分代,是为了GC(收集垃圾),那你说神仙都长生不老了,你还想让他死,你这不是不讲理,当然神仙也是要计划生育滴,下面在详细讲
第二个坑:认为方法区就是永生代,这也是错误滴,只是用永生代来实现方法区,那我要是用新生代实现,还叫新生代了?

好了,我们来看新生代,有三块区域,Eden(伊甸园)、From Survivor(诺亚方舟一号)、To Survivor(诺亚方舟二号),为啥这么叫呢?他们的比例是8:1:1

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.
(元空间分成多个块,每个块与一个类加载器相关联,每个块存储多个类(该加载器加载的类)的元数据,当类加载器GG时,会释放相关的块空间)
Alternatives(为啥这么做呢,是为了融合Hotspot和JRockit)

上一篇 下一篇

猜你喜欢

热点阅读