工具下载地址
https://github.com/evolvedmicrobe/benchmarks/blob/master/hsdis-amd64.dylib
将工具放到jre/lib目录下,添加JVM参数(VM选项)。
-XX:+UnlockDiagnosticVMOptions -XX:+PrintAssembly -XX:CompileCommand=compileonly,*ReSortDemo.* -server -Xcomp
编写程序,测试volatile的汇编代码
public class ReSortDemo {
public static volatile boolean flag = false;
public static void main(String[] args) {
new Thread(() -> {
while (!flag) ;
System.out.println("flag-->true");
}).start();
new Thread(() -> {
System.out.println("flag-->false");
flag = true;
}).start();
}
}
image.png
我们看到确实使用了lock addl这条汇编指令。











网友评论