当前位置:网站首页>What is the JVM runtime data area and the JMM memory model
What is the JVM runtime data area and the JMM memory model
2022-08-01 17:59:00 【Yisuyun】
What is the JVM runtime data area and JMM memory model
This article "What is the JVM runtime data area and the JMM memory model?" Most people do not understand the knowledge points, so the editor summarizes the following content for you, the content is detailed, and the steps are clear, has a certain reference value. I hope you can gain something after reading this article. Let's take a look at this article "What is the JVM runtime data area and the JMM memory model".
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): Store class template objects, it is an area shared by threads, on disk, generally not GC
Heap space:The area shared by threads, the main position for object creation and GC
Virtual machine stack: The thread is private, 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 methods run
Dynamic linking: point to the method template object, implement method rewriting 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 thread context switch process
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 of private memory with 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 serves two purposes:
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 is always immediately available to other threads.
Disable instruction reordering optimization.
There are four types of memory barrier instructions available in the JVM:
loadload:Between two read operations
storestore:Between two writes
loadstore:Between read and write operations
storelosd:Between writes and reads
The above is about the content of the article "What is the JVM runtime data area and the JMM memory model?" I believe everyone has a certain understanding. I hope the content shared by the editor will be helpful to you.If you want to know more related knowledge content, please pay attention to the Yisu Cloud Industry Information Channel.
边栏推荐
猜你喜欢
随机推荐
变量交换;复合赋值;增递减运算符
CodeTON Round 2 (Div. 1 + Div. 2, Rated, Prizes!) 题解
[供应链·案例篇]石油和天然气行业的数字化转型用例
【Day_10 0428】密码强度等级
数字化采购管理系统开发:精细化采购业务流程管理,赋能企业实现“阳光采购”
【Day_09 0427】 另类加法
QPalette调色板、框架色彩填充
云原生全景图详解
【Day_08 0426】两种排序方法
极化微波成像概述
Shell nl命令详解(显示行号、读取文件)
QT basic functions, signals, slots
SQL的索引详细介绍
直播系统聊天技术(八):vivo直播系统中IM消息模块的架构实践
Basic image processing in opencv
【翻译】CNCF培养的OpenMetrics成为一个孵化项目
Are online account opening commissions reliable? Is online account opening safe?
移动端吸顶方案
SQL的ROUND函数用法及其实例
SRM供应商管理系统如何助力口腔护理企业实现采购战略的转型升级