HSDIS对volatile的浅析

HSDIS有什么用?用来看汇编,有用么? 答案是有用的。

举个最简单的例子,volatile,是java关键字,那在汇编层面是如何做的呢?

示例代码:

import java.util.*;

public class VolatileTest {
public volatile long value = 0;

public static void main(String[] args) {

VolatileTest t = new VolatileTest();

t.value = 3;

System.out.println("value is: " + t.value);

}
}


编译
root@ubuntu:~/Downloads# javac VolatileTest.java 


运行
root@ubuntu:~/Downloads# java -Xcomp  -server -XX:+UnlockDiagnosticVMOptions -XX:+PrintAssembly -XX:+DebugNonSafepoints VolatileTest > disass.log 


查看disass.log,寻找相关的汇编代码:

0x00007f8f9446d688: lock addl $0x0,(%rsp)     ;*putfield value
; - VolatileTest::<init>@6 (line 4)


结合putfield value 和 bytecode, 可以知道这条指令就是 对value的赋值操作。

看见了什么? [b]lock[/b]


[b]补充:[/b]


关于lock,可以参考64-ia-32-architectures-software-developer-manual

截取2段:

Intel 64 and IA-32 processors provide a LOCK# signal that is asserted automatically during certain critical memory operations to lock the system bus or equivalent link. While this output signal is asserted, requests from other processors or bus agents for control of the bus are blocked. 


To explicitly force the LOCK semantics, software can use the LOCK prefix with the following instructions when they are used to modify a memory location.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值