22.jvm内存结构部分——方法区_定义

接下来我们学习jvm内存结构中方法区的部分。
那方法区呢从名字上看,它似乎跟我们类的方法信息有关,确实如此,但是还不够完整。
网上对这个方法区的定义也是不太清晰。那下面我们来看一个最权威的定义。 


那这里呢我给出了一个链接,这个链接呢是我们jvm 规范中对方法区的定义。 

Chapter 2. The Structure of the Java Virtual Machine 【2.5.4 Method Area】

2.5.4. Method Area

The Java Virtual Machine has a method area that is shared among all Java Virtual Machine threads(这个方法区是所有java虚拟机线程共享的区). The method area is analogous to the storage area for compiled code of a conventional language or analogous to the "text" segment in an operating system process. It stores per-class structures such as the run-time constant pool, field and method data, and the code for methods and constructors, including the special methods (§2.9) used in class and instance initialization and interface initialization.(它存储了跟类的结构相关的一些信息都有哪些呢?

run-time constant pool 运行时常量池

field 成员变量

method data 方法数据

code for methods and constructors 成员方法以及构造器方法,它们的代码部分包括一些什么special methods,就是它的一些特殊方法。特殊方法主要是指我们类的构造器。)

The method area is created on virtual machine start-up(方法区在虚拟机启动时被创建. Although the method area is logically part of the heap(方法区逻辑上是堆的组成部分, simple implementations may choose not to either garbage collect or compact it. This specification does not mandate the location of the method area or the policies used to manage compiled code. (并不强制这个方法区的位置)The method area may be of a fixed size or may be expanded as required by the computation and may be contracted if a larger method area becomes unnecessary. The memory for the method area does not need to be contiguous.

A Java Virtual Machine implementation may provide the programmer or the user control over the initial size of the method area, as well as, in the case of a varying-size method area, control over the maximum and minimum method area size.

The following exceptional condition is associated with the method area:

  • If memory in the method area cannot be made available to satisfy an allocation request, the Java Virtual Machine throws an OutOfMemoryError.

 方法区逻辑上是堆的组成部分,并不强制这个方法区的位置。补充说明:

比如说我们的这个oracle 的HotSpot虚拟机,它在jdk8以前它的实现叫做永久代.这个永久代就是使用了堆内存的一部分作为方法区。但是到了jdk1.8以后,它将永久代移除了,换了一个实现,这个实现叫做元空间元空间用的就不是堆的内存,用的是本地内存,也就是操作系统的内存。

所以不同的实现,它的这个方法区域的所处的位置有所不同。

其他非HotSpot版本的虚拟机也有好多没有把方法区放在堆中。

If memory in the method area cannot be made available to satisfy an allocation request, the Java Virtual Machine throws an OutOfMemoryError.

方法区的内存溢出的一个定义:这个方法区如果申请内存时发现不足了,它也会让我们的虚拟机抛一个OutOfMemoryError。方法区也会导致一个内存溢出的错误


那我们下面呢我们看一张图,帮助大家更好的理解这个方法区。

 这里给出了还是oracle hotspot 虚拟机,它在1.6的一个内存结构中,方法区大概的结构以及1.8中方法区的一个结构。

1.6jvm 呢我们看有堆,还有Method Area(概念) PermGen 永久代(实现)。

永久代包含了:类的信息(Class[filed、method、构造器等等),类加载器,运行时常量池(串池:StringTable)

1.8jvm 中 method Area由本地内存中的Metaspace(元空间实现),这个区并不由jvm管理,

它仍然包含,类的信息,类加载器,常量池,但串池stringTable是放在jvm的堆中

上一篇:21.jvm内存结构部分——堆_内存诊断_jvisualvm_tgbyhn31的博客-CSDN博客

下一篇:23.jvm内存结构部分——方法区_内存溢出1_tgbyhn31的博客-CSDN博客

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值