憋不住的心里的一个想法,JVM的BYTECODE是完全平台无关的么?
圍繞在心里很長時間的一個問題:JVM的BYTECODE真的是完全平臺無關的么?
就算JVM里指令集,寄存器,堆棧一應俱全。
算法,數據結構都可以完全實現,
但如果JAVA要讀寫文件,那它會不會被JVM在解釋時,翻譯成一個具體的OS的API或是SYSTEM CALL?
因為操作系統在內核態工作,而JVM只是一個軟件,必須工作在用戶態呀。
那BYTECODE是全被JVM直接轉成機器碼執行了?
帶著這個問題,上天入地,都沒有完全冰釋心中疑問。
以下幾個貼子爭論得挺多的。但都沒有一個定論。
誰來解答?
http://bbs.csdn.net/topics/320086053
http://wenwen.soso.com/z/q287138233.htm
http://www.189works.com/article-63310-1.html
http://www.codeproject.com/Articles/30422/How-the-Java-Virtual-Machine-JVM-Works
http://www.powerbot.org/community/topic/940642-question-about-the-jvm/
http://stackoverflow.com/questions/2748910/how-is-java-platform-independent-when-it-needs-jvm-to-run
?
有幾句話,可以注意:
在Java平臺的結構中,可以看出,Java虛擬機(JVM)處在核心的位置,是程序與底層操作系統和硬件無關的關鍵。它的下方是移植接口,移植接口由兩部分組成:適配器和Java操作系統,其中依賴于平臺的部分稱為適配器;JVM通過移植接口在具體的平臺和操作系統上實現;在JVM的上方是Java的基本類庫和擴展類庫以及它們的API,利用JavaAPI編寫的應用程序(application)和小程序(Javaapplet)可以在任何Java平臺上運行而無需考慮底層平臺,就是因為有Java虛擬機(JVM)實現了程序與操作系統的分離,從而實現了Java的平臺無關性。
The Java Virtual Machine is responsible for interpreting Java byte code and translating this into actions or Operating System calls. (這哥哥也不說哪些是直接執行,哪些是系統調用呀。XXXX,關鍵時掉鏈的典型。。)For example, a request to establish a socket connection to a remote machine will involve an Operating System call. Different Operating Systems handle sockets in different ways - but the programmer doesn't need to worry about such details. It is the responsibility of the JVM to handle these translations so that the Operating System and the CPU architecture on which the Java software is running is completely irrelevant to the eveloper.
Java source code is compiled into platform-agnostic bytecode. The host JVM will then interpret (and likely JIT) the bytecode and call the underlying native methods of the OS. So if you're running a JVM on Windows, then yes it will utilise the Win32 API. Likewise if you're running a JVM on Linux, it will make use of Linux's native libraries.
?
You can find many methods in the Java API with the "native" keyword: these are essentially methods which acts as a bridge between the native libraries and Java itself.
PS:
另外,關于操作系統API和SYSTEM CALL的關系,有PPT作注。
總結
以上是生活随笔為你收集整理的憋不住的心里的一个想法,JVM的BYTECODE是完全平台无关的么?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 在RHEL5.0中用YUM解决RPM包的
- 下一篇: 有没有课本讲解的视频网站?就是在书上做笔