Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 495730f

Browse filesBrowse files
committed
[F] 图片
1 parent 6cbcb87 commit 495730f
Copy full SHA for 495730f

File tree

Expand file treeCollapse file tree

5 files changed

+6
-4
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

5 files changed

+6
-4
lines changed
Open diff view settings
Collapse file

‎README.md‎

Copy file name to clipboardExpand all lines: README.md
+2Lines changed: 2 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ SpringCloud源码
7474
- [一篇文章快速深入学习ThreadLocal](https://github.com/coderbruis/JavaSourceLearning/blob/master/note/JDK/%E4%B8%80%E7%AF%87%E6%96%87%E7%AB%A0%E5%BF%AB%E9%80%9F%E6%B7%B1%E5%85%A5%E5%AD%A6%E4%B9%A0ThreadLocal.md)
7575
- [深入学习Java volatile关键字](https://github.com/coderbruis/JavaSourceLearning/blob/master/note/JDK/%E6%B7%B1%E5%85%A5%E5%AD%A6%E4%B9%A0Java%20volatile%E5%85%B3%E9%94%AE%E5%AD%97.md)
7676
- [深入学习Thread底层原理](https://github.com/coderbruis/JavaSourceCodeLearning/blob/master/note/JDK/%E6%B7%B1%E5%85%A5%E5%AD%A6%E4%B9%A0Thread%E5%BA%95%E5%B1%82%E6%BA%90%E7%A0%81.md)
77+
- [深入学习JDK1.7、8 HashMap扩容原理]()
7778

7879
- Spring源码学习
7980
- Spring版本:5.2.1.RELEASE
@@ -135,6 +136,7 @@ SpringCloud源码
135136
- Netty底层源码解析-FastThreadLocal原理分析
136137
- Netty底层源码解析-内存分配原理分析
137138
- Netty底层源码解析-RocketMQ底层使用到的Netty
139+
- [Netty底层的优化总结]()
138140
- [实战+原理效果更佳!强烈推荐闪电侠大佬实战课:《Netty 入门与实战:仿写微信 IM 即时通讯系统》](https://juejin.cn/book/6844733738119593991)
139141

140142
Netty实战课相关点位于:Spring-Netty,com/bruis/learnnetty/im包下,有需要的读者可前往查看。
Collapse file

‎note/JDK/深入学习Java volatile关键字.md‎

Copy file name to clipboardExpand all lines: note/JDK/深入学习Java volatile关键字.md
+4-4Lines changed: 4 additions & 4 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Lock引起的将当前处理器缓存该变量的数据写回到系统内存中
5151
5252
每个处理器通过嗅探在总线上传播的数据来检查自己缓存的值是否过期,当处理器发现自己缓存行对于数据的内存地址被修改了,就会将当前缓存行设置为无效。当处理器对这个数据进行修改操作时,会重新从系统内存中读取该数据到处理器缓存中。
5353

54-
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-bTawJOHf-1596181331575)(https://note.youdao.com/yws/api/personal/file/AA87E3ABBEDB4A37B69D8E75B5ED12C1?method=download&shareKey=f9788b07ab72368f3613b2744614eecf)]
54+
![volatile-01](https://github.com/coderbruis/JavaSourceCodeLearning/blob/master/note/images/JDK/volatile-01.png)
5555

5656
为了实现volatile的内存语义,编译期在生成字节码时会对使用volatile关键字修饰的变量进行处理,在字节码文件里对应位置生成一个Lock前缀指令,Lock前缀指令实际上相当于一个内存屏障(也成内存栅栏),它确保指令重排序时不会把其后面的指令排到内存屏障之前的位置,也不会把前面的指令排到内存屏障的后面;即在执行到内存屏障这句指令时,在它前面的操作已经全部完成。
5757

@@ -117,12 +117,12 @@ volatile读之后的操作不会被编译器重排序到volatile读之前。
117117
2. 在每个volatile写操作后插入StoreLoad屏障
118118
3. 在每个volatile读前面插入一个LoadLoad屏障
119119
4. 在每个volatile读后面插入一个LoadStore屏障
120-
121-
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Z1N3KBZj-1596181331583)(https://note.youdao.com/yws/api/personal/file/E11087F8FD5B4673ABD8C58F6F8DA232?method=download&shareKey=cf78d935c04cb11b039399e1d4825b74)]
120+
121+
![volatile-02](https://github.com/coderbruis/JavaSourceCodeLearning/blob/master/note/images/JDK/volatile-02.png)
122122
- StoreStore屏障可以保证在volatile写之前,所有的普通写操作已经对所有处理器可见,StoreStore屏障保障了在volatile写之前所有的普通写操作已经刷新到主存。
123123
- StoreLoad屏障避免volatile写与下面有可能出现的volatile读/写操作重排。因为编译器无法准确判断一个volatile写后面是否需要插入一个StoreLoad屏障(写之后直接就return了,这时其实没必要加StoreLoad屏障),为了能实现volatile的正确内存语意,JVM采取了保守的策略。在每个volatile写之后或每个volatile读之前加上一个StoreLoad屏障,而大多数场景是一个线程写volatile变量多个线程去读volatile变量,同一时刻读的线程数量其实远大于写的线程数量。选择在volatile写后面加入StoreLoad屏障将大大提升执行效率(上面已经说了StoreLoad屏障的开销是很大的)。
124124

125-
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-pRcUS5Mm-1596181331589)(https://note.youdao.com/yws/api/personal/file/2A92B2D468A345F6A55C75249A89845A?method=download&shareKey=ac99a6bcd169bf4bcda8b0fbd33e0003)]
125+
![volatile-03](https://github.com/coderbruis/JavaSourceCodeLearning/blob/master/note/images/JDK/volatile-03.png)
126126
- LoadLoad屏障保证了volatile读不会与下面的普通读发生重排
127127
- LoadStore屏障保证了volatile读不回与下面的普通写发生重排。
128128

Collapse file

‎note/images/JDK/volatile-01.png‎

Copy file name to clipboard
126 KB
  • Display the source diff
  • Display the rich diff
Loading
Collapse file

‎note/images/JDK/volatile-02.png‎

Copy file name to clipboard
82.2 KB
  • Display the source diff
  • Display the rich diff
Loading
Collapse file

‎note/images/JDK/volatile-03.png‎

Copy file name to clipboard
88.7 KB
  • Display the source diff
  • Display the rich diff
Loading

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.