当前位置:网站首页>JMM memory model
JMM memory model
2022-07-18 05:18:00 【Qingdong】
JMM Memory model
order
since:2019 year 9 month 2 Japan 9:11
auth: Hadi
update: 2021 year 5 month 16 Japan 22:36
Reference resources :
https://blog.csdn.net/lxm55913153/article/details/79208126
JMM
Java Memory model Java Memort Model Referred to as JMM.
JMM Defined java How virtual machines work in memory , It is a logical structure .
JMM It defines the visibility of shared variables between multiple threads and synchronizes shared variables when necessary .
JMM Operation type
JMM In order to share data , The operations on variables are divided into the following 8 class :
- read
Read data from main memory . - load
Write the data in the main memory into the working memory ( A child thread ) - use
Read data from working memory to calculate - assign
Re write the calculated value into the working memory - store
Write the data of working memory back to main memory - write
take store The written variable is assigned to the variable location in the main memory - lock
Lock the main memory variables , Identify that the variable is in thread exclusive state - unlock
Unlock the main memory variable , After unlocking, other threads can lock the variable
Please refer to the following flow chart for the specific process :
PS: The operations in the red box are also carried out in the main memory .
Main memory main memory, Local memory local memory
local memory It doesn't really exist , Just an abstract concept , Covering caching , Write buffer , Registers and other hardware and compiler optimizations .
Competition and bus locking
Competition
If multiple threads share an object , And multiple threads modify this object at the same time , Then there will be competition . Here's the picture :
Two threads are working on a variable at the same time ++ The operation of , Then it may cause the retrieval to be 1, When it is written back to the main memory, it is written as 1, Cause loss once add operation .
Bus yoke
For the occurrence of the above situation , We can operate lock The operation of , It will lead to low performance , Not efficient .
Cpu Read data from main memory to cache , This data will be locked on the bus ,
So other Cpu Can't read or write this data , Until this Cpu After using the data lock, others Cpu To read the data
MESI Cache consistency protocol
Multiple Cpu Read the same data from main memory to their respective cache , When one of them Cpu Modified the data in the cache , The data will be synchronized back to main memory immediately , Other Cpu Through the bus sniffing mechanism, we can sense the change of data and invalidate the data in our own cache , And data re read、load.
Volatile How cache visibility is implemented
The underlying implementation is mainly through assembly lock Prefix instruction , It locks the cache of this memory area ( Cache row locking ) And write back to main memory .
stay IA-32 Architecture software developer's Manual for lock Interpretation of instructions :
- The data of the current processor cache line will be written back to the system memory immediately .
- This write back operation will cause other CPU Invalid data cached in memory address (MESI agreement )

Java Program assembly code view
-server -Xcomp -XX:+UnlockDiagnosticVMOptions -XX:+PrintAssembly -XX:CompileCommand=compileonly,*VolatileVisibilityTest,prepareData
边栏推荐
猜你喜欢

在Salesforce中基于SAML 2.0搭建SSO并启用JIT User Provisioning(SF Orgs间 / SF Org与Experience Cloud间 / 其他IdP)

Core examination points for information system project managers (VII) software architecture style

Cool dog music interface is amazingly open

The 9th Blue Bridge Cup group B provincial tournament.

Salesforce中實施Campaign Influence模型注意事項

【综合笔试题】难度 2/5,递归运用及前缀和优化

1 start. S analysis

xstream解析xml的时候报错AbstractReflectionConverter$UnknownFieldException

nifi ListSFTP等代理设置

Salesforce中使用LWC本地开发
随机推荐
Information system project manager 10 days before the exam limit sprint + answer (10): summary of comprehensive knowledge
Salesforce email sent to spam mailbox or SF email processing method not received (dkim - New CNAME version)
E-commerce platform background management system --- > system detailed design (order management module)
Uni app call function
Core examination points for information system project managers (VII) software architecture style
E-commerce platform background management system -- > operation method description
The difference between sx126x and sx127x
Figure 1: four directions and three strategies for digital transformation of state-owned enterprises
Information system project manager core examination site (IX) organizational structure type
Nifi cluster construction and necessary related configurations
信息系统项目管理师必背核心考点(十)信息系统规划
Core examination sites for information system project managers (VI) layering of OSI protocol, mapping + real questions
阿里云架构师马颂:云上高性能计算助力基因测序
在Salesforce Validation Rule中使用Vlookup方法
ORACLE在修改主键时出现ORA-00955报错解决方法
信息系统项目管理师必背核心考点(一)国家信息化体系六要素
rv的使用
Sx1268 chip Manual Chapter 13 translation
超强ping工具
The 15th day of zero basic Lua --- finally, I'll summarize it