永久区和元空间的区别

一文搞懂JVM之 方法区、永久代、元空间三者的区别 - 知乎

元空间和永久代的区别-腾讯云开发者社区-腾讯云

方法区和永久区/元空间之间的关系 - 简书

  • 方法区(Method Area),是JVM规范中提出的一个(概念),用于存储类信息、常量池、静态变量、JIT编译后的代码等。

The Java Virtual Machine has a method area that is shared among all Java Virtual Machine threads. 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.
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.

  • 永久区,是Hotspot虚拟机内的概念,它是Hotspot虚拟机对方法区的一个具体的实现,在1.8之后,Hotspot将永久区移除。

  • 元空间,上面说到,Hotspot在1.8之后移除了永久区,新的方法区实现就由元空间来负责。

永久区和元空间的区别:

  • 永久区是占用jvm虚拟机的内存;
  • 元空间则是占用本地内存(操作系统的内存),也就是虚拟机之外的内存,极大的减少OOM情况的发生。

永久区和元空间的区别_第1张图片

你可能感兴趣的:(jvm)