当前位置:网站首页>What is in the method area - class file, class file constant pool, runtime constant pool
What is in the method area - class file, class file constant pool, runtime constant pool
2022-06-26 10:13:00 【ZZ learn java well】
Recently, I have been troubled by something stored in the method area ?
1. Stored in method area class Document information and class What is the relationship between file constant pool .
2.class What is the relationship between file constant pool and runtime constant pool .
The method area stores the class information , Constants and static variables , That is, the data after the class is compiled . This statement is actually no problem , It's just too general . To be more specific, the method area stores the version of the class , Field , Method , Interfaces and constant pools . Literal and symbol references are stored in the constant pool .
Symbol references include :1. The fully qualified name of the class ,2. Field name and properties ,3. Method name and properties .
The following picture is the method area I drew ,class file information ,class Relationship between file constant pool and runtime constant pool

The following diagram is used to represent the method area class What does the file information include :

You can see in the method area class File information includes : magic number , Version number , Constant pool , class , Parent class and interface array , Field , Method and other information , In fact, the class also includes the information of fields and methods .
The chart below is class The type of data stored in the file
| type | name | Number |
| u4 | magic | 1 |
| u2 | minor_version | 1 |
| u2 | major_version | 1 |
| u2 | constant_pool_count | 1 |
| cp_info | constant_pool | constant_pool_count - 1 |
| u2 | access_flags | 1 |
| u2 | this_class | 1 |
| u2 | super_class | 1 |
| u2 | interfaces_count | 1 |
| u2 | interfaces | interfaces_count |
| u2 | fields_count | 1 |
| field_info | fields | fields_count |
| u2 | methods_count | 1 |
| method_info | methods | methods_count |
| u2 | attribute_count | 1 |
| attribute_info | attributes | attributes_count |
The following figure shows the contents stored in the constant pool :

Use one class Actually decompile the file
Here is the original java Code
[java] view plain copy
- public class TestInt {
- private String str = "hello";
- void printInt(){
- System.out.println(65535);
- }
- }
After decompiling, you get class The file is as follows

You can see the decompiled class The contents of the document can correspond to the above . That's the answer class Document and class File constant pool relationship
class Relationship and difference between file constant pool and runtime constant pool
class The file constant pool stores when class The file is java Some literal and symbolic references stored in the method area after the virtual machine is loaded , Literal quantities include strings , Constants of basic types .
The runtime constant pool is when class After the file is loaded ,java Virtual opportunity will class The contents of the file constant pool are transferred to the runtime constant pool , stay class Some symbolic references of the file constant pool will be transformed into direct references , For example, static methods or private methods of a class , Instance construction method , Parent class method , This is because these methods cannot be overridden by other versions , So you can turn the symbol reference into a direct reference when loading , Some of the other methods turn a symbolic reference into a direct reference when the method is called for the first time .
summary :
The method area stores class File information and runtime constant pool ,class File information includes class information and class File constant pool .
The contents of the runtime constant pool are except class Outside the contents of the file constant pool , Will also class The symbolic reference in the file constant pool is transformed into a direct reference , Moreover, the contents of the constant pool can be added dynamically at runtime . For example, call String Of intern Method can string The value of is added to String In constant pool , here String The constant pool is contained in the runtime constant pool , But in jdk1.8 after , take String The constant pool is put in the heap .
边栏推荐
- Basic grammar of C language -- pointer (character, one-dimensional array) learning
- Basic string operations in C
- LeetCode 0710. Random numbers in the blacklist - preprocessing implementation o (1) value
- 动态库连接 - 符号冲突 - 全局符号介入
- c语言语法基础之——函数定义学习
- 测试须知——常见接口协议解析
- The basis of C language grammar -- pointer (multidimensional array, function, summary) learning
- My creation anniversary
- logback
- 自动化测试——pytest本身及第三方模块介绍及使用
猜你喜欢

Detailed explanation of winsorflow quantum installation process

【LeetCode】59. Spiral matrix II

字符串常量池、class常量池和运行时常量池

DAY 3 数组,前置后置,字符空间,关键词和地址指针

软件测试---如何选择合适的正交表

Detailed explanation of the network security competition questions (2) of the 2021 national vocational college skills competition (secondary vocational group)

如何更改微信小程序二维码物料颜色

This new change of go 1.16 needs to be adapted: the changes of go get and go install

【Leetcode】76. 最小覆盖子串

WIN10系统实现Redis主从复制
随机推荐
How do technicians send notifications?
【Leetcode】76. 最小覆盖子串
Leetcode basic calculator 224 227. follow up 394
自动化测试——关于unitest与pytest初始化共存问题
Day 3 array, pre post, character space, keyword and address pointer
Redis notes (16) - info instructions and command line tools (view memory, status, number of client connections, monitoring server, scan large keys, sampling server, execute batch commands, etc.)
Mysql database operation commands (constantly updated)
Internationalization configuration
Cmake / set command
Leetcode connected to rainwater series 42 (one dimension) 407 (2D)
c语言语法基础之——函数嵌套、递归 小程序斐波那契之和、阶乘
Detailed explanation of the network security competition questions (2) of the 2021 national vocational college skills competition (secondary vocational group)
The basis of C language grammar -- function nesting, Fibonacci sum of recursive applet and factorial
字符串常量池、class常量池和运行时常量池
首批12家企业入驻!广州首个集中展销老字号产品专柜开张
Redis notes (14) - persistence and data recovery (data persistence RDB and AOF, data recovery, mixed persistence)
Win10安装tensorflow-quantum过程详解
The basis of C language grammar -- factoring by function applet
2021 national vocational college skills competition (secondary vocational group) network security competition questions (1) detailed analysis tutorial
Control setting layout in linear layout_ Gravity doesn't work?