当前位置:网站首页>Method area of JVM
Method area of JVM
2022-06-29 12:22:00 【Java interview 365】
JVM The method area
Java Virtual machine memory region model

** Yellow area :** The area of memory shared by all threads , There will be garbage collection .
** Grey areas :** Thread private does not generate garbage collection .
The method area is part of the runtime data area , So what is the specific purpose of the method area ? What information can be stored in the method area ?
What is the method area
The method area, like the heap, is shared by all threads , In some places, the method area is called Non-Heap( Non heap ), The purpose is to distinguish the method area from the heap memory , stay JDK1.7 Many developers in call the method area the permanent generation , But in essence, the two are not equivalent , Just because HotSpot The virtual machine design team will GC Generational collection extends to the method area , Or use permanent generation to implement method areas , such HotSpot The garbage collector can manage the permanent generation memory just like the heap memory , The rest are not HotSpot There is no concept of permanent generation for virtual machines .
HotSpot Method area evolution
Methods in jdk7 And before , Custom calls it the method area forever , The structure is as follows

stay jdk1.8 Have adopted the Metaspace( Metadata space ) To replace the Perm( The permanent zone ), And separate from the heap space , The structure is as follows

It must be noted that Metaspace( Metadata space ) No longer stored in the heap , Not used JVM The memory space is the memory of the machine , In this way, the metadata is only limited by the local memory size ,OOM There will be no problem .
Why? JDK1.8 The method area needs to be changed from JVM Forever ( Indirect memory ) Move to the meta space ( Direct memory ) Well ?
JVM The permanent generation has a capacity limit , If the storage capacity of such information is limited, it is easy to trigger OOM, And use meta space storage , Limited by local memory size only OOM It's very unlikely that .
Because it's direct memory ,JVM Will be in IO Higher performance in operation , Because it acts directly on the local operating system IO operation , Heap memory does IO operation , First you need to copy the data to direct memory , recycling IO Handle , Direct memory does not require this layer of conversion .
Stack and method area interaction
For example, we often build business objects , With Car Object as an example

When we create a Car After the instance object , Will be in the heap 、 Stack 、 The method area memory space writes data respectively
Car: Is an object template , by Class object , Store in method area .
car: It belongs to reference data , Stored in stack space .
new Car(): You need to make room in the heap , Store in a pile .
What data is stored in the method area
The data stored in the method area is mainly the class information loaded by the class loader , Runtime constant pool, etc .
There are two points to note
Static variables , stay JDK1.8 Previously, static variables were stored in the permanent memory ,JDK1.8 Later, the meta space is used to replace the permanent generation ,== The static variables are transferred from the permanent generation to the heap space ==.
Constant pool , stay JDK1.7 Previously, the runtime constant pool logic included that the string constant pool is stored in the permanent generation ,JDK1.7 Moved the string constant pool to heap memory , Note that there is no mention of the runtime constant pool , That is, the runtime constant pool still exists in the permanent generation ,JDK1.8 Remove the permanent generation and replace it with a meta space , At this time, the runtime constant pool exists in the meta space .
So what does this kind of information include ?

Class information
The full name of the class
The full name of the immediate parent class of the class
The direct implementation interface of class has sequence table
Type identification ( Class or interface )
Class access modifier (public、private wait )
Type constant pool
An ordered collection of constants used by this type , Including direct constants ( character string 、 floating-point 、 integer ), And for other types 、 Field 、 Symbolic reference to method .
Field information
Field type 、 name 、 Access modifiers, etc
Methods information
Class
Method return type 、 Method access modifier 、 Method name and so on
Class variables
References to class loaders
Point to Class Instance reference
Method table
边栏推荐
- Do you think people who learn machinery are terrible?
- & 4 express framework
- Titanium dynamic technology: our Zadig landing Road
- How to obtain method parameter values through WinDbg
- 什么是外链和内链?
- 黑化的蜜雪冰城,凭营销就想抓牢消费者的心?
- Gbase8s database into standard and into raw clauses
- GBase8s数据库与 FOR UPDATE 子句不兼容的语法
- Serving millions of developers, the first techo day Tencent technology open day released 7 "lightweight" products
- What is the main account of Chia Tai futures used for 4 quotation software?
猜你喜欢

什么是外链和内链?

面试突击61:说一下MySQL事务隔离级别?

Artbench: the first class balanced, high-quality, clean annotated and standardized artwork generation data set
![Jerry's configuration of TWS cross pairing [chapter]](/img/35/a041093ce3dab8e2739bbc1466ba29.png)
Jerry's configuration of TWS cross pairing [chapter]

架构实战营第五模块课后作业

一种可解释的几何深度学习模型,用于基于结构的蛋白质结合位点预测

ONES 创始人王颖奇对话《财富》(中文版):中国有没有优秀的软件?

iMile 利用 Zadig 多云环境周部署千次,跨云跨地域持续交付全球业务

&3 在浏览器中查看请求报文和响应报文

Ensure drinking water safety! Panyu Shawan waterway water quality online monitoring system passed the acceptance
随机推荐
【JUC系列】同步工具类之ThreadLocal
一种可解释的几何深度学习模型,用于基于结构的蛋白质结合位点预测
Jerry's about TWS pairing mode configuration [chapter]
Jerry's about TWS channel configuration [chapter]
联想领像 lenovoimage 部分打印机 驱动 PPD 文件
《Go题库·14》WaitGroup的坑
年轻就要醒着拼,年轻就要勇于尝试
Gbase8s database select has order by Clause 2
力扣每日一题-第31天-13.罗马数组转整数
Do you think people who learn machinery are terrible?
The blackened honeysnow ice city wants to grasp the hearts of consumers by marketing?
Jericho's position on initiating the connection back to the opposite ear: 【 chapter 】
ERP编制物料清单 基础
[pbootcms template] composition website / document download website source code
什么是外链和内链?
Intelligent trash can (IV) -- raspberry pie Pico realizes ultrasonic ranging (hc-sr04)
大家有没有觉得学机械的人很可怕?
&4 express框架
《自卑与超越》生活对你应有的意义
【综合案例】信用卡虚拟交易识别