Style:Mac
Series:Java
Since:2018-09-10
End:2018-09-10
Total Hours:1
Degree Of Diffculty:5
Degree Of Mastery:5
Practical Level:5
Desired Goal:5
Archieve Goal:3
Gerneral Evaluation:3
Writer:kingdelee
Related Links:
http://www.cnblogs.com/kingdelee/
http://yunjiechao-163-com.iteye.com/blog/2386423
https://blog.csdn.net/unei66/article/details/26477629
https://blog.csdn.net/hengyunabc/article/details/26898657
1.需要下载编译,如果编译失败,可以下载已经编译好的
https://www.chrisnewland.com/updated-instructions-for-building-hsdis-on-osx-417
最终要将 hsdis-amd64.dylib
/Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home/jre/lib/server
public class DynamicDispatch { // static abstract class Human {
// protected abstract void sayHello();
// } static class Human {
protected void sayHello(){
System.out.println("hello");
}
} static class Man extends Human {
@Override
protected void sayHello() {
System.out.println("man say hello");
}
} static class Woman extends Human {
@Override
protected void sayHello() {
System.out.println("woman say hello");
}
} public static void main(String[] args) {
Human man = new Man();
Human woman = new Woman();
man.sayHello();
woman.sayHello();
man = new Woman();
man.sayHello();
}
}
用如下命令行可以更多地了解内联优化的实际情况以及优化发生的级别:
java -XX:+PrintCompilation -XX:+UnlockDiagnosticVMOptions -XX:+PrintInlining -XX:+TieredCompilation DynamicDispatch
查看JIT生成的汇编代码
-XX:+UnlockDiagnosticVMOptions -XX:+PrintAssembly
如果只查看某个方法产生的汇编代码,可以使用命令:
https://zeroturnaround.com/rebellabs/why-it-rocks-to-finally-understand-java-jit-with-jitwatch/
-XX:+UnlockDiagnosticVMOptions-XX:+PrintAssembly