元空间和运行时常量池

Posted juniorma

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了元空间和运行时常量池相关的知识,希望对你有一定的参考价值。

元空间是方法区的实现

方法区是什么呢?

  从java虚拟机规范9里摘抄的

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 used in class and interface initialization and in
instance initialization 

包括了如下的几个部分

  1 运行时常量池

  2 字段和方法数据

  3 方法和构造方法的字节码

而关于运行时常量池

A run-time constant pool is a per-class or per-interface run-time representation
of the constant_pool table in a class file (§4.4). It contains several kinds of
constants, ranging from numeric literals known at compile-time to method and field
references that must be resolved at run-time. The run-time constant pool serves a
function similar to that of a symbol table for a conventional programming language,
although it contains a wider range of data than a typical symbol table.
Each run-time constant pool is allocated from the Java Virtual Machine‘s method
area (§2.5.4). The run-time constant pool for a class or interface is constructed
when the class or interface is created (§5.3) by the Java Virtual Machine.
The following exceptional condition is associated with the construction of the runtime constant pool for a class or interface:
? When creating a class or interface, if the construction of the run-time constant
pool requires more memory than can be made available in the method area of the
Java Virtual Machine, the Java Virtual Machine throws an OutOfMemoryError.
See §5 (Loading, Linking, and Initializing) for information about the construction of the
run-time constant pool.

翻译过来就是,运行时常量池是class文件里常量池的运行时代表(run-time representation) 实在不知道怎么翻译好,各位理解就行了。

numeric literals数字字面量。

method and field references that must be resolved at run-time 方法和字段的引用只有在运行时才能解析,很好理解不到jvm里没法知道代码所在地址

 

以上是关于元空间和运行时常量池的主要内容,如果未能解决你的问题,请参考以下文章

Jave运行时常量池是啥意思?

第二章:方法区和运行时常量池溢出

JVM09_方法区

JVM笔记3-java内存区域之运行时常量池

jvm 常量池

Java 运行时常量池