当前位置:网站首页>Detailed explanation of JVM runtime data area and JMM memory model
Detailed explanation of JVM runtime data area and JMM memory model
2022-08-01 08:34:00 【Feifei Technology House】
1. JVM runtime data area
The JVM runtime data area can be divided into five blocks: metaspace, heap, virtual machine stack, native method stack, and program counter.

- Metaspace (method area): It stores class template objects and is an area shared by threads. On disk, there is generally no GC
- Heap space: the area shared by threads, the main position for object creation and GC
- Virtual machine stack: private to the thread, the basic unit is the stack frame, each stack frame corresponds to a method, the stack frame is composed as follows
- Local variable table: store method variable information
- Operand stack: the area where the method runs
- Dynamic linking: point to the method template object, and implement method rewriting together with the virtual method table
- Return address: the return address of the method
- Native method stack: thread private, execution area for native methods
- Program counter: thread private, responsible for recording where the thread executes during the process of thread context switching
2. JMM memory model
Hardware memory model

Usually, when the CPU needs to read the main memory, it will read the part of the main memory into the CPU cache or the internal register, and then perform the operation in the register.When the CPU needs to write the result back to main memory, it flushes the value of the internal registers to the cache, and then at some point flushes the value back to main memory.
In a multiprocessor system, each processor has its own cache, and they share the same main memory, so there is a cache coherency problem.In order to solve the problem of consistency, each processor needs to follow some protocols when accessing the cache, and operate according to the protocol when reading and writing. Such protocols include MSI, MESI, etc.
JMM
The JMM memory model divides the content into two parts: thread private memory and main memory. The corresponding relationship with the hardware memory model we mentioned earlier is as follows:

The interaction between private memory and main memory is controlled by the following eight operations:

3. Visible line and volatile keyword
In a nutshell, the volatile keyword prevents instruction reordering in the form of memory barriers to maintain variable ordering and visibility.
A line of code goes through the following stages from execution to execution:

The volatile keyword has the following two functions:
- Guarantees that volatile-modified shared variables are always visible to all threads, that is, when a thread modifies the value of a volatile-modified shared variable, the new value can always be immediately known to other threads.
- Disable instruction reordering optimization.
The JVM provides four types of memory barrier instructions:
- loadload: between two read operations
- storestore: between two writes
- loadstore: between read and write operations
- storelosd: between writes and reads

边栏推荐
猜你喜欢
随机推荐
pytest接口自动化测试框架 | 使用函数返回值的形式传入参数值
pytest接口自动化测试框架 | 集成Allure测试报告
小程序全面屏手势配置案例
【数据集】各类绝缘子、鸟巢及防震锤数据集汇总
Centos install php7.4, build hyperf, forward RDS
HoloView--Customization
mysql查看cpu使用情况
静态Pod、Pod创建流程、容器资源限制
GBase 8s 锁分类
搜索框字符自动补全
Leetcode - 6135: the longest part of the figure
zip打包目录所有文件(含隐藏文件/夹)
Microsoft Azure & NVIDIA IoT 开发者季 I|Azure IoT & NVIDIA Jetson 开发基础
Flink SQL - client, how to deal with the source side and to increase the target, the SQL - client including mapping table and the JOB such as
Classify GBase 8 s lock
ACmix 论文精读,并解析其模型结构
ogg同步oracle到mysql,字段里面可能有需要转义的字符,怎么配置转义?
好的plm软件有哪些?plm软件排行榜
nodetype中值1、2、3分别代表什么意思
codeforces每日5题(均1600)-第二十七天









