当前位置:网站首页>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
边栏推荐
- Do I need to introduce any dependencies to write data to clickhouse using flinksql?
- POJ1287联网题解
- Delphi MDI appliction 文档最大化显示、去掉最大化最小化等按钮
- 静态Pod、Pod创建流程、容器资源限制
- flink sql-client,怎么处理源端与目标增加端,sql-client包括映射表与JOB如
- C语言学习概览(二)
- leetcode-6133:分组的最大数量
- Redis中间件(从搭建到弃坑)
- Custom IP used in PCIE
- Static Pod, Pod Creation Process, Container Resource Limits
猜你喜欢
Prime Ring Problem
七夕来袭——属于程序员的浪漫
leetcode-6132:使数组中所有元素都等于零
Chapter 9 of Huawei Deep Learning Course - Convolutional Neural Network and Case Practice
VSCode插件推荐(Rust环境)
22 Grab the Seat 1 C.Grab the Seat (Geometry + Violence)
华为深度学习课程第九章——卷积神经网络以及案例实践
network basic learning
[Dataset] Dataset summary of various insulators, bird's nests and anti-vibration hammers
leetcode-6135:图中的最长环
随机推荐
Optimal dazzle Oracle database support what kinds of type of the time and date
pytest接口自动化测试框架 | parametrize中ids的用法
[Interview: Concurrency 39: Multithreading: Thread Pool] ThreadPoolExecutor Class - Submit, Stop
USB Protocol (2) Terminology
Prime Ring Problem
Data Analysis 6
微信小程序请求封装
毕业论文写作技巧
Microsoft Azure & NVIDIA IoT developers season I | Azure IoT & NVIDIA Jetson development foundation
【HDLBits 刷题】Circuits(1)Combinational Logic
C语言学习概览(三)
【STM32】入门(一):环境搭建、编译、下载、运行
Gethostbyname \ getaddrinfo DNS domain name IP address is not safe
Static Pod, Pod Creation Process, Container Resource Limits
POJ1287联网题解
pytest接口自动化测试框架 | 单个/多个参数
【MySQL】操作表DML相关语句
zip打包目录所有文件(含隐藏文件/夹)
leetcode-6135:图中的最长环
基于tika实现对文件类型进行判断