当前位置:网站首页>jvm-02.有序性保证
jvm-02.有序性保证
2022-06-23 04:19:00 【CaptainCats】
有序性保证
硬件层面有序性保证
指令重排提高了运行效率,但也带来了乱序执行数据不一致的问题,
在硬件层面如何确保有序性?
CPU内存屏障
写屏障sfence
在sfence指令前的写操作必须在sfence后的写操作之前完成
读屏障lfence
在lfence指令前的读操作必须在lfence后的读操作之前完成
混合屏障mfence
在mfence指令前的读写操作必须在mfence后的读写操作之前完成
屏障前后的指令不能重排,这是CPU级别的内存屏障。
原子指令
x86上的"lock"指令,lock…doSth…lock是一条指令,
lock后面跟的是其它指令,
在这条指令的执行过程中,这个内存不能被其它指令修改,来确保执行顺序实现有序性。
Jvm内存屏障
Jvm本身是软件层级,它的内存屏障依赖于硬件来实现,
它将读和写进行两两组合,形成了四种内存屏障:
LoadLoad屏障
对于这样的语句Load1;LoadLoad;load2;
在Load2及后续读取操作执行前,要保证Load1要读取的数据被读取完毕。
StoreStore屏障
对于这样的语句Store1;StoreStore;Store2;
在Store2及后续写入操作执行前,要保证Store1的写入对其它处理器可见。
LoadStore屏障
对于这样的语句Load1;LoadStore;Store2;
在Store2及后续写入操作执行前,要保证Load1要读取的数据被读取完毕。
StoreLoad屏障
对于这样的语句Store1;StoreLoad;load2;
在load2及后续读取操作执行前,要保证Store1的写入对其它处理器可见。
Volatile
在jvm的实现层级上,volatile内存区的读写都加屏障:
在对volatile修饰的变量进行的写操作前面加了StoreStore屏障,后面加了StoreLoad屏障,
在对volatile修饰的变量进行的读操作前面加了LoadLoad屏障,后面加了LoadStore屏障。
Synchronized
Synchronized对应的是C和C++调用了操作系统提供的同步机制,
依赖于硬件CPU,在CPU级别是使用lock指令来实现的。
边栏推荐
- node中操作mongoDB
- Oracle异常
- June 22, 2022: golang multiple choice question, what does the following golang code output? A:3; B:1; C:4; D: Compilation failed. package main import ( “fmt“ ) func mai
- 【owt】owt-client-native-p2p-e2e-test vs2017构建 6:修改脚本自动生成vs工程
- Opencv display image
- Advanced Mathematics (Seventh Edition) Tongji University exercises 1-9 personal solutions
- Wechat applet: elderly blessing short video
- visdom的使用
- TCP/IP 详解(第 2 版) 笔记 / 3 链路层 / 3.3 全双工, 节能, 自动协商机制, 802.1X 流控制 / 3.3.3 链路层流量控制
- Fs2119a Synchronous Boost IC output 3.3V and fs2119b Synchronous Boost IC output 5V
猜你喜欢

Wechat applet: Star Trek spaceship ticket production and generation

Huawei's software and hardware ecosystem has taken shape, fundamentally changing the leading position of the United States in the software and hardware system

Real MySQL interview questions (XXVII) -- Classification of users by RFM analysis method

MySQL面试真题(三十)——贝壳-房产订单分析

新课上线 | 每次 5 分钟,轻松玩转阿里云容器服务!

云原生数据库是未来

Alibaba cloud object storage oss+picgo+typera implements the construction map

What is the reason for the black screen of the computer monitor when the computer is turned on? What should I do about the black screen of the computer monitor

MySQL面试真题(二十二)——表连接后的条件筛选及分组筛选

True MySQL interview question (21) - Finance - overdue loan
随机推荐
Alibaba cloud object storage oss+picgo+typera implements the construction map
Real MySQL interview questions (XXVI) -- didi 2020 written examination questions
True MySQL interview question (24) -- row column exchange
[OWT] OWT client native P2P E2E test vs2017 build 6: modify script automatic generation vs Project
数字藏品如何赋能经济实体?
The author believes that the so-called industrial Internet is a process of deep integration of industry and the Internet
MySQL面试真题(二十五)——常见的分组比较场景
Deploy docker and install MySQL in centos7
ssm项目搭建
ArcTime 制作中英文字幕视频
数字藏品火热背后需要强大的技术团队支持 北方技术团队
vant weapp日历组件性能优化 Calendar 日历添加min-date最小日期页面加载缓慢
树莓派assert初步使用练习
android Handler内存泄露 kotlin内存泄露处理
Wechat applet: Star Trek spaceship ticket production and generation
True question of MySQL interview (29) -- case - finding favorite movies
Behind the hot digital collections, a strong technical team is needed to support the northern technical team
Real MySQL interview question (23) -- pinduoduo ball game analysis
Win11如何开启移动热点?Win11开启移动热点的方法
Oracle exception