JAVA vs C++之速度—
生活随笔
收集整理的這篇文章主要介紹了
JAVA vs C++之速度—
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
讓我們來看看JIT/Hotspot的工作 一般來說,JVM或JAVA的標準API沒有提供讓我們觀察Hotspot工作(產生機器碼)的接口.所以以前我們只能猜測Hotspot在背后究竟做了那些事情,我們寫的JAVA代碼被它弄成什么樣子了. 不過現在好了,Java SE Update N這一系列因為處于開發狀態,為了方便debug,這些JVM提供了一個運行參數:PrintOptoAssembly,你可以通過如下方式: 引用 java -XX:+PrintOptoAssembly -server -cp . Main 運行你的程序,就可以看到這些JAVA程序在編譯為機器語言之后的樣子. Kohsuke Kawaguchi做了一些測試,他在博客深入JAVA生成的機器碼(Deep dive into assembly code from Java)中進行了一些展示與講解.并且他對JVM生成的優化代碼表示贊賞: 引用 All in all, modern JVMs seem pretty good at generating optimal code. In various situations, the resulting assembly code is far from the straight-forward instruction-by-instruction translation. JAVA之父James Gosling在他的博客Hotspot performance中描述了JIT/Hotspot生成的機器碼有以下優點: 引用 ◇ Really aggressive inlining ◇ Even storage allocation & initialization gets inlined - new T() really is as efficient as C's alloca() (and it beats the pants off malloc()) ◇ Careful management of cache prefetching ◇ Deep understanding of variablity between the flavors of x86 machines ◇ Loop unrolling with warmup/cooldown ◇ "theorum proving away" of array index checks (and many other things) ◇ much cleverness with locks
轉載于:https://www.cnblogs.com/wa278/archive/2010/09/03/1817487.html
總結
以上是生活随笔為你收集整理的JAVA vs C++之速度—的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SQL 分组统计并返回当前行
- 下一篇: 深入探讨C++中的引用(转)